| 1 | package WWW::VastAI::API::SSHKeys; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | 10 | our $VERSION = '0.001'; | |||||||||||||||||||||||||||||||||||||||||
| 3 | # ABSTRACT: Account SSH key management for Vast.ai | ||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||
| 5 | 10 | ▶ | use Moo; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | 10 | ▶ | use Carp qw(croak); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | 10 | ▶ | use WWW::VastAI::SSHKey; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 10 | ▶ | use namespace::clean; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||
| 10 | 10 | has client => ( | |||||||||||||||||||||||||||||||||||||||||
| 11 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||
| 12 | required => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 13 | weak_ref => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 14 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||
| 16 | 3 | ▶ | sub _wrap { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_wrap: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 17 | 3 | my ($self, $data) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 18 | 3 | return WWW::VastAI::SSHKey->new( | |||||||||||||||||||||||||||||||||||||||||
| 19 | client => $self->client, | ||||||||||||||||||||||||||||||||||||||||||
| 20 | data => $data, | ||||||||||||||||||||||||||||||||||||||||||
| 21 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 22 | } | ||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||
| 24 | 1 | ▶ | sub list { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
list: called CC=5 SCAR=18.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 25 | 1 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 26 | 1 | my $result = $self->client->request_op('listSSHKeys'); | |||||||||||||||||||||||||||||||||||||||||
| 27 | 1 | ▶ | my $keys = ref $result eq 'HASH' ? ($result->{ssh_keys} || $result->{results} || []) : ($result || []); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition28%2/7
$result->{"ssh_keys"} or $result->{"results"} or []
$result->{"ssh_keys"} or $result->{"results"}
$result or []
MC/DC0%0/2
$result->{"ssh_keys"} or $result->{"results"} or []
$result->{"ssh_keys"}
$result->{"results"}
MC/DC0%0/1
$result or []
$result
Truth table33%1/3
A or B
A= $result->{"ssh_keys"}B= $result->{"results"}
Truth table0%0/2
A
A= $result
| |||||||||||||||||||||||||||||||||||||||||||
| 28 | 1 | return [ map { $self->_wrap($_) } @{$keys} ]; | |||||||||||||||||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||
| 31 | 1 | ▶ | sub create { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
create: called CC=4 SCAR=15.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 32 | 1 | my ($self, $ssh_key) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 33 | 1 | ▶ | croak "ssh key required" unless $ssh_key; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 34 | 1 | my $result = $self->client->request_op('createSSHKey', body => { ssh_key => $ssh_key }); | |||||||||||||||||||||||||||||||||||||||||
| 35 | 1 | ▶ | my $key = ref $result eq 'HASH' ? ($result->{ssh_key} || $result) : $result; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$result->{"ssh_key"} or $result
MC/DC0%0/2
$result->{"ssh_key"} or $result
$result->{"ssh_key"}
$result
Truth table33%1/3
A or B
A= $result->{"ssh_key"}B= $result
| |||||||||||||||||||||||||||||||||||||||||||
| 36 | 1 | return $self->_wrap($key); | |||||||||||||||||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||
| 39 | 1 | ▶ | sub update { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
update: called CC=5 SCAR=17.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 40 | 1 | my ($self, $id, $ssh_key) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 41 | 1 | ▶ | croak "ssh key id required" unless defined $id; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 42 | 1 | ▶ | croak "ssh key required" unless $ssh_key; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||
| 44 | 1 | my $result = $self->client->request_op( | |||||||||||||||||||||||||||||||||||||||||
| 45 | 'updateSSHKey', | ||||||||||||||||||||||||||||||||||||||||||
| 46 | path => { id => $id }, | ||||||||||||||||||||||||||||||||||||||||||
| 47 | body => { ssh_key => $ssh_key }, | ||||||||||||||||||||||||||||||||||||||||||
| 48 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||
| 50 | 1 | ▶ | my $key = ref $result eq 'HASH' ? ($result->{ssh_key} || $result) : $result; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$result->{"ssh_key"} or $result
MC/DC0%0/2
$result->{"ssh_key"} or $result
$result->{"ssh_key"}
$result
Truth table33%1/3
A or B
A= $result->{"ssh_key"}B= $result
| |||||||||||||||||||||||||||||||||||||||||||
| 51 | 1 | return $self->_wrap($key); | |||||||||||||||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||
| 54 | 1 | ▶ | sub delete { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
delete: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 55 | 1 | my ($self, $id) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 56 | 1 | ▶ | croak "ssh key id required" unless defined $id; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 57 | 1 | return $self->client->request_op('deleteSSHKey', path => { id => $id }); | |||||||||||||||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||
| 60 | 10 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||
| 62 | __END__ | ||||||||||||||||||||||||||||||||||||||||||