Docker/API/Secrets.pm

filter: Statementstmt 100% 54 / 54 Branchbran 95.0% 19 / 20 Conditioncond 64.7% 11 / 17 MC/DCmcdc 45.4% 5 / 11 Subroutinesub 100% 14 / 14 Podpod 100% 5 / 5 totaltotal 89.2% 108 / 121 CC 17 SCAR 12.2
CC
17
Cov
92%
update
6.0
create
5.0
inspect
3.3
CRAP 3.4
« Docker/API/Plugins.pm ↑ Summary Docker/Role/Using.pm »
1 package API::Docker::API::Secrets;
2 # ABSTRACT: Docker Engine Secrets API
3 52 our $VERSION = '0.006';
4 52 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 52 with 'API::Docker::Role::Filters', 'API::Docker::Role::Using';
6 52 ▶use API::Docker::Role::Entity::Secret;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 52 ▶use API::Docker::Type::Secret;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 52 ▶use Carp qw( croak );
Subroutine BEGIN: called CC=1 SCAR=0.0
9 52 ▶use MIME::Base64 qw( encode_base64 );
Subroutine BEGIN: called CC=1 SCAR=0.0
10 52 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12  
13 52 has client => (
14 is => 'ro',
15 required => 1,
16 weak_ref => 1,
17 );
18  
19  
20 # The class is the caller's argument, as it is on the resource classes whose
21 # list and inspect really are two definitions -- here both are the swagger's
22 # one `Secret`, and passing it keeps the seam in the same place.
23 #
24 # from_data, not new: this is a daemon response, and the two entry points of
25 # API::Docker::Role::Type read it differently. from_data takes the swagger's
26 # wire names and nothing else, so a key it has not heard of keeps its own
27 # spelling instead of being read as the Perl name of one it has, and a value
28 # that disagrees with the swagger costs its own field rather than the whole
29 # response. `client` is ours rather than the engine's, so it goes beside the
30 # data instead of into it.
31 10 ▶sub _wrap {
Subroutine _wrap: called CC=1 SCAR=0.0
32 10 my ($self, $class, $data) = @_;
33 10 return $class->from_data($data, client => $self->client);
34 }
35  
36 7 ▶sub _wrap_list {
Subroutine _wrap_list: called CC=1 SCAR=0.0
37 7 my ($self, $class, $list) = @_;
38 7 return [ map { $self->_wrap($class, $_) } @$list ];
39 }
40  
41 # The wire field is base64; the public contract is raw bytes. Guarding the
42 # character range here keeps the failure a croak naming this class instead of
43 # MIME::Base64's "Wide character in subroutine entry" from two frames down.
44 5 ▶sub _encode_data {
Subroutine _encode_data: called CC=2 SCAR=6.9
45 5 my ($self, $method, $data) = @_;
46 5 ▶ croak __PACKAGE__ . "->$method Data must be a byte string, not decoded "
Branch: 1 branch
BranchTrueFalseTotal
if $data =~ /[^\x00-\xff]/ 1 4 5
47 . 'characters -- encode it first (Encode::encode_utf8)'
48 if $data =~ /[^\x00-\xff]/;
49 4 return encode_base64($data, '');
50 }
51  
52 8 ▶sub list {
Subroutine list: called CC=3 SCAR=11.0
Pod documented
53 8 my ($self, %opts) = @_;
54 8 my %params;
55 $params{filters} = $self->_normalise_filters($opts{filters})
56 8 ▶ if defined $opts{filters};
Branch: 1 branch
BranchTrueFalseTotal
if defined $opts{"filters"} 2 6 8
57 return $self->_wrap_list('API::Docker::Type::Secret',
58 $self->client->get('/secrets',
59 params => \%params,
60 7 ▶ %{ $self->_request_options },
Condition50%1/2
$self->client->get("/secrets", "params", \%params, %{$self->_request_options;}) // []
l!l
70
MC/DC0%0/1
$self->client->get("/secrets", "params", \%params, %{$self->_request_options;}) // []
$self->client->get("/secrets", "params", \%params, %{$self->_request_options;})
Truth table50%1/2
A
A= $self->client->get("/secrets", "params", \%params, %{$self->_request_options;})
Aresult
11
00
61 ) // []);
62 }
63  
64  
65 7 ▶sub create {
Subroutine create: called CC=5 SCAR=16.1
Pod documented
66 7 my ($self, %spec) = @_;
67 croak __PACKAGE__ . '->create Name required'
68 7 ▶ unless defined $spec{Name} && length $spec{Name};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $spec{"Name"} and length $spec{"Name"} 1 6 7
Condition66%2/3
defined $spec{"Name"} and length $spec{"Name"}
!ll&&!rl&&r
106
MC/DC50%1/2
defined $spec{"Name"} and length $spec{"Name"}
defined $spec{"Name"} length $spec{"Name"}
Truth table66%2/3
A and B
A= defined $spec{"Name"}B= length $spec{"Name"}
ABresult
0X0
100
111
69 croak __PACKAGE__ . '->create Data required'
70 6 ▶ unless defined $spec{Data} && length $spec{Data};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $spec{"Data"} and length $spec{"Data"} 2 4 6
Condition100%3/3
defined $spec{"Data"} and length $spec{"Data"}
!ll&&!rl&&r
114
MC/DC100%2/2
defined $spec{"Data"} and length $spec{"Data"}
defined $spec{"Data"} length $spec{"Data"}
Truth table100%3/3
A and B
A= defined $spec{"Data"}B= length $spec{"Data"}
ABresult
0X0
100
111
71 4 $spec{Data} = $self->_encode_data('create', $spec{Data});
72 3 return $self->client->post('/secrets/create', \%spec);
73 }
74  
75  
76 6 ▶sub inspect {
Subroutine inspect: called CC=3 SCAR=12.0
Pod documented
77 6 my ($self, $id) = @_;
78 6 ▶ croak __PACKAGE__ . '->inspect secret ID or name required'
Branch: 1 branch
BranchTrueFalseTotal
unless defined $id and length $id 0 6 6
Condition33%1/3
defined $id and length $id
!ll&&!rl&&r
006
MC/DC0%0/2
defined $id and length $id
defined $id length $id
Truth table33%1/3
A and B
A= defined $idB= length $id
ABresult
0X0
100
111
79 unless defined $id && length $id;
80 return $self->_wrap('API::Docker::Type::Secret',
81 $self->client->get("/secrets/$id",
82 6 %{ $self->_request_options },
83 ));
84 }
85  
86  
87 8 ▶sub update {
Subroutine update: called CC=6 SCAR=17.9
Pod documented
88 8 my ($self, $id, $version, %spec) = @_;
89 8 ▶ croak __PACKAGE__ . '->update secret ID or name required'
Branch: 1 branch
BranchTrueFalseTotal
unless defined $id and length $id 1 7 8
Condition66%2/3
defined $id and length $id
!ll&&!rl&&r
107
MC/DC50%1/2
defined $id and length $id
defined $id length $id
Truth table66%2/3
A and B
A= defined $idB= length $id
ABresult
0X0
100
111
90 unless defined $id && length $id;
91 7 ▶ croak __PACKAGE__ . '->update requires the current version as its second '
Branch: 1 branch
BranchTrueFalseTotal
unless defined $version 1 6 7
92 . 'argument: the Version.Index from inspect($id), which the daemon uses '
93 . 'as an optimistic-concurrency token and will not accept the update '
94 . 'without'
95 unless defined $version;
96 6 ▶ croak __PACKAGE__ . '->update version must be the numeric Version.Index '
Branch: 1 branch
BranchTrueFalseTotal
unless $version =~ /\A[0-9]+\z/ 1 5 6
97 . "from inspect(\$id), got '$version'"
98 unless $version =~ /\A[0-9]+\z/;
99 $spec{Data} = $self->_encode_data('update', $spec{Data})
100 5 ▶ if defined $spec{Data};
Branch: 1 branch
BranchTrueFalseTotal
if defined $spec{"Data"} 1 4 5
101 5 return $self->client->post("/secrets/$id/update", \%spec,
102 params => { version => $version });
103 }
104  
105  
106 6 ▶sub remove {
Subroutine remove: called CC=3 SCAR=11.0
Pod documented
107 6 my ($self, $id) = @_;
108 6 ▶ croak __PACKAGE__ . '->remove secret ID or name required'
Branch: 1 branch
BranchTrueFalseTotal
unless defined $id and length $id 1 5 6
Condition66%2/3
defined $id and length $id
!ll&&!rl&&r
015
MC/DC50%1/2
defined $id and length $id
defined $id length $id
Truth table66%2/3
A and B
A= defined $idB= length $id
ABresult
0X0
100
111
109 unless defined $id && length $id;
110 return $self->client->delete_request("/secrets/$id",
111 5 %{ $self->_request_options },
112 );
113 }
114  
115  
116  
117 52 1;
118  
119 __END__
« Docker/API/Plugins.pm ↑ Summary Docker/Role/Using.pm »