| 1 | package API::Docker::API::Containers; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | # ABSTRACT: Docker Engine Containers 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 | 'API::Docker::Role::JSONBody'; | ||||||||||||||||||||||||||||||||||||||||||
| 7 | 52 | ▶ | use API::Docker::Error::HTTP; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 52 | ▶ | use API::Docker::Role::Entity::Container; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | 52 | ▶ | use API::Docker::Type::ContainerInspectResponse; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | 52 | ▶ | use API::Docker::Type::ContainerSummary; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | 52 | ▶ | use Carp qw( croak shortmess ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | 52 | ▶ | use JSON::MaybeXS qw( decode_json ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | 52 | ▶ | use MIME::Base64 qw( decode_base64 ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | 52 | ▶ | use Scalar::Util qw( blessed ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 15 | 52 | ▶ | use namespace::clean; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||
| 18 | 52 | has client => ( | |||||||||||||||||||||||||||||||||||||||||
| 19 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||
| 20 | required => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 21 | weak_ref => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 22 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||
| 25 | # The class is the caller's argument rather than a constant of this module: | ||||||||||||||||||||||||||||||||||||||||||
| 26 | # `list` and `inspect` are two definitions in the swagger and therefore two | ||||||||||||||||||||||||||||||||||||||||||
| 27 | # generated classes. Both carry the same convenience methods, composed by | ||||||||||||||||||||||||||||||||||||||||||
| 28 | # API::Docker::Role::Entity::Container -- see "The two container shapes". | ||||||||||||||||||||||||||||||||||||||||||
| 29 | # | ||||||||||||||||||||||||||||||||||||||||||
| 30 | # from_data, not new: this is a daemon response, and the two entry points of | ||||||||||||||||||||||||||||||||||||||||||
| 31 | # API::Docker::Role::Type read it differently. from_data takes the swagger's | ||||||||||||||||||||||||||||||||||||||||||
| 32 | # wire names and nothing else, so a key it has not heard of keeps its own | ||||||||||||||||||||||||||||||||||||||||||
| 33 | # spelling instead of being read as the Perl name of one it has, and a value | ||||||||||||||||||||||||||||||||||||||||||
| 34 | # that disagrees with the swagger costs its own field rather than the whole | ||||||||||||||||||||||||||||||||||||||||||
| 35 | # response. `client` is ours rather than the engine's, so it goes beside the | ||||||||||||||||||||||||||||||||||||||||||
| 36 | # data instead of into it. | ||||||||||||||||||||||||||||||||||||||||||
| 37 | 30 | ▶ | sub _wrap { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_wrap: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 38 | 30 | my ($self, $class, $data) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 39 | 30 | return $class->from_data($data, client => $self->client); | |||||||||||||||||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||
| 42 | 13 | ▶ | sub _wrap_list { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_wrap_list: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 43 | 13 | my ($self, $class, $list) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 44 | 13 | return [ map { $self->_wrap($class, $_) } @$list ]; | |||||||||||||||||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||
| 47 | # A state-change endpoint answers 204 when it changed something and 304 when | ||||||||||||||||||||||||||||||||||||||||||
| 48 | # the container was already in the state asked for. Neither carries a body, so | ||||||||||||||||||||||||||||||||||||||||||
| 49 | # the return value of the request is undef either way and the two are | ||||||||||||||||||||||||||||||||||||||||||
| 50 | # indistinguishable from it. The status comes out through the `response` | ||||||||||||||||||||||||||||||||||||||||||
| 51 | # out-parameter (see API::Docker::Role::HTTP/"Reading the status line and the | ||||||||||||||||||||||||||||||||||||||||||
| 52 | # response headers") and becomes the documented 1/0. | ||||||||||||||||||||||||||||||||||||||||||
| 53 | 39 | ▶ | sub _state_change { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_state_change: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||
| 54 | 39 | my ($self, $path, %opts) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 55 | 39 | my %response; | |||||||||||||||||||||||||||||||||||||||||
| 56 | 39 | $self->client->post($path, undef, %opts, response => \%response); | |||||||||||||||||||||||||||||||||||||||||
| 57 | 39 | ▶ | return 0 if defined $response{status} && $response{status} == 304; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $response{"status"} and $response{"status"} == 304
MC/DC100%2/2
defined $response{"status"} and $response{"status"} == 304
defined $response{"status"}
$response{"status"} == 304
Truth table100%3/3
A and B
A= defined $response{"status"}B= $response{"status"} == 304
| |||||||||||||||||||||||||||||||||||||||||||
| 58 | 32 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||
| 61 | 18 | ▶ | sub list { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
list: called CC=8 SCAR=22.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 62 | 18 | my ($self, %opts) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 63 | 18 | my %params; | |||||||||||||||||||||||||||||||||||||||||
| 64 | 18 | ▶ | $params{all} = $opts{all} ? 1 : 0 if defined $opts{all}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 65 | 18 | ▶ | $params{limit} = $opts{limit} if defined $opts{limit}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 66 | 18 | ▶ | $params{size} = $opts{size} ? 1 : 0 if defined $opts{size}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 67 | $params{filters} = $self->_normalise_filters($opts{filters}) | ||||||||||||||||||||||||||||||||||||||||||
| 68 | 18 | ▶ | if defined $opts{filters}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 69 | my $result = $self->client->get('/containers/json', | ||||||||||||||||||||||||||||||||||||||||||
| 70 | params => \%params, | ||||||||||||||||||||||||||||||||||||||||||
| 71 | 17 | %{ $self->_request_options }, | |||||||||||||||||||||||||||||||||||||||||
| 72 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 73 | 13 | ▶ | return $self->_wrap_list('API::Docker::Type::ContainerSummary', $result // []); | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$result // []
MC/DC0%0/1
$result // []
$result
Truth table50%1/2
A
A= $result
| |||||||||||||||||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||
| 77 | # The booleans of the container create body, from spec/v1.51.yaml: the | ||||||||||||||||||||||||||||||||||||||||||
| 78 | # ContainerConfig flags at the top level, and the HostConfig flags in the | ||||||||||||||||||||||||||||||||||||||||||
| 79 | # nested `HostConfig` object (its own plus the ones it inherits from | ||||||||||||||||||||||||||||||||||||||||||
| 80 | # Resources). The engine rejects a number for any of them, so 1/0 is | ||||||||||||||||||||||||||||||||||||||||||
| 81 | # normalised to a JSON boolean on the way out; a caller may still pass 1/0 or a | ||||||||||||||||||||||||||||||||||||||||||
| 82 | # JSON boolean and it goes out correctly either way. | ||||||||||||||||||||||||||||||||||||||||||
| 83 | 52 | my @CONTAINER_CONFIG_BOOLS = qw( | |||||||||||||||||||||||||||||||||||||||||
| 84 | ArgsEscaped AttachStderr AttachStdin AttachStdout NetworkDisabled | ||||||||||||||||||||||||||||||||||||||||||
| 85 | OpenStdin StdinOnce Tty | ||||||||||||||||||||||||||||||||||||||||||
| 86 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 87 | 52 | my @HOST_CONFIG_BOOLS = qw( | |||||||||||||||||||||||||||||||||||||||||
| 88 | AutoRemove Init OomKillDisable Privileged PublishAllPorts ReadonlyRootfs | ||||||||||||||||||||||||||||||||||||||||||
| 89 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||||||
| 91 | 2 | ▶ | sub create { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
create: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 92 | 2 | my ($self, %config) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 93 | 2 | my %params; | |||||||||||||||||||||||||||||||||||||||||
| 94 | 2 | ▶ | $params{name} = delete $config{name} if defined $config{name}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 95 | 2 | $self->_json_bools(\%config, @CONTAINER_CONFIG_BOOLS); | |||||||||||||||||||||||||||||||||||||||||
| 96 | # Copy the nested HostConfig before touching it -- _json_bools mutates, and | ||||||||||||||||||||||||||||||||||||||||||
| 97 | # the sub-object is still the caller's until this copy replaces it. | ||||||||||||||||||||||||||||||||||||||||||
| 98 | 2 | ▶ | if (ref $config{HostConfig} eq 'HASH') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 99 | 1 | my %host_config = %{ $config{HostConfig} }; | |||||||||||||||||||||||||||||||||||||||||
| 100 | 1 | $self->_json_bools(\%host_config, @HOST_CONFIG_BOOLS); | |||||||||||||||||||||||||||||||||||||||||
| 101 | 1 | $config{HostConfig} = \%host_config; | |||||||||||||||||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||||||||||||||||
| 103 | 2 | my $result = $self->client->post('/containers/create', \%config, params => \%params); | |||||||||||||||||||||||||||||||||||||||||
| 104 | 2 | return $result; | |||||||||||||||||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||||||
| 108 | 23 | ▶ | sub inspect { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
inspect: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 109 | 23 | my ($self, $id) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 110 | 23 | ▶ | croak "Container ID required" unless $id; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 111 | my $result = $self->client->get("/containers/$id/json", | ||||||||||||||||||||||||||||||||||||||||||
| 112 | 22 | %{ $self->_request_options }, | |||||||||||||||||||||||||||||||||||||||||
| 113 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 114 | 21 | return $self->_wrap('API::Docker::Type::ContainerInspectResponse', $result); | |||||||||||||||||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||||||||||
| 118 | 13 | ▶ | sub start { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
start: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 119 | 13 | my ($self, $id) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 120 | 13 | ▶ | croak "Container ID required" unless $id; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 121 | return $self->_state_change("/containers/$id/start", | ||||||||||||||||||||||||||||||||||||||||||
| 122 | 12 | %{ $self->_request_options }, | |||||||||||||||||||||||||||||||||||||||||
| 123 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||||||||||
| 127 | 11 | ▶ | sub stop { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
stop: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 128 | 11 | my ($self, $id, %opts) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 129 | 11 | ▶ | croak "Container ID required" unless $id; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 130 | 10 | my %params; | |||||||||||||||||||||||||||||||||||||||||
| 131 | 10 | ▶ | $params{t} = $opts{timeout} if defined $opts{timeout}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 132 | 10 | ▶ | $params{signal} = $opts{signal} if defined $opts{signal}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 133 | return $self->_state_change("/containers/$id/stop", | ||||||||||||||||||||||||||||||||||||||||||
| 134 | params => \%params, | ||||||||||||||||||||||||||||||||||||||||||
| 135 | 10 | %{ $self->_request_options }, | |||||||||||||||||||||||||||||||||||||||||
| 136 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 137 | } | ||||||||||||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||||||||||||
| 140 | 5 | ▶ | sub restart { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
restart: called CC=3 SCAR=11.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 141 | 5 | my ($self, $id, %opts) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 142 | 5 | ▶ | croak "Container ID required" unless $id; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 143 | 5 | my %params; | |||||||||||||||||||||||||||||||||||||||||
| 144 | 5 | ▶ | $params{t} = $opts{timeout} if defined $opts{timeout}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 145 | return $self->_state_change("/containers/$id/restart", | ||||||||||||||||||||||||||||||||||||||||||
| 146 | params => \%params, | ||||||||||||||||||||||||||||||||||||||||||
| 147 | 5 | %{ $self->_request_options }, | |||||||||||||||||||||||||||||||||||||||||
| 148 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 149 | } | ||||||||||||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||||||||||||
| 152 | 5 | ▶ | sub kill { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
kill: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 153 | 5 | my ($self, $id, %opts) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 154 | 5 | ▶ | croak "Container ID required" unless $id; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 155 | 5 | my %params; | |||||||||||||||||||||||||||||||||||||||||
| 156 | 5 | ▶ | $params{signal} = $opts{signal} if defined $opts{signal}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 157 | return $self->client->post("/containers/$id/kill", undef, | ||||||||||||||||||||||||||||||||||||||||||
| 158 | params => \%params, | ||||||||||||||||||||||||||||||||||||||||||
| 159 | 5 | %{ $self->_request_options }, | |||||||||||||||||||||||||||||||||||||||||
| 160 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 161 | } | ||||||||||||||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||||||||||||
| 164 | 5 | ▶ | sub remove { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
remove: called CC=8 SCAR=24.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 165 | 5 | my ($self, $id, %opts) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 166 | 5 | ▶ | croak "Container ID required" unless $id; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 167 | 5 | my %params; | |||||||||||||||||||||||||||||||||||||||||
| 168 | 5 | ▶ | $params{v} = $opts{volumes} ? 1 : 0 if defined $opts{volumes}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 169 | 5 | ▶ | $params{force} = $opts{force} ? 1 : 0 if defined $opts{force}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 170 | 5 | ▶ | $params{link} = $opts{link} ? 1 : 0 if defined $opts{link}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 171 | return $self->client->delete_request("/containers/$id", | ||||||||||||||||||||||||||||||||||||||||||
| 172 | params => \%params, | ||||||||||||||||||||||||||||||||||||||||||
| 173 | 5 | %{ $self->_request_options }, | |||||||||||||||||||||||||||||||||||||||||
| 174 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 175 | } | ||||||||||||||||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||||||||||||||||
| 178 | 14 | ▶ | sub logs { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
logs: called CC=15 SCAR=31.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 179 | 14 | my ($self, $id, %opts) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 180 | 14 | ▶ | croak "Container ID required" unless $id; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 181 | 14 | my %params; | |||||||||||||||||||||||||||||||||||||||||
| 182 | 14 | ▶ | $params{follow} = $opts{follow} ? 1 : 0 if defined $opts{follow}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 183 | 14 | ▶ | $params{stdout} = defined $opts{stdout} ? ($opts{stdout} ? 1 : 0) : 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 184 | 14 | ▶ | $params{stderr} = defined $opts{stderr} ? ($opts{stderr} ? 1 : 0) : 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 185 | 14 | ▶ | $params{since} = $opts{since} if defined $opts{since}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 186 | 14 | ▶ | $params{until} = $opts{until} if defined $opts{until}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 187 | 14 | ▶ | $params{timestamps} = $opts{timestamps} ? 1 : 0 if defined $opts{timestamps}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 188 | 14 | ▶ | $params{tail} = $opts{tail} if defined $opts{tail}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 189 | # exists, not truth: an unset callback is a caller bug, and quietly falling | ||||||||||||||||||||||||||||||||||||||||||
| 190 | # back to the buffered path for it would answer a follow with a hang. | ||||||||||||||||||||||||||||||||||||||||||
| 191 | return $self->client->stream_frames('GET', "/containers/$id/logs", | ||||||||||||||||||||||||||||||||||||||||||
| 192 | params => \%params, | ||||||||||||||||||||||||||||||||||||||||||
| 193 | defined $opts{tty} ? ( tty => $opts{tty} ) : (), | ||||||||||||||||||||||||||||||||||||||||||
| 194 | 14 | ▶ | %{ $self->_request_options }, | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 195 | 14 | ▶ | exists $opts{on_frame} ? ( on_frame => $opts{on_frame} ) : (), | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 196 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 197 | } | ||||||||||||||||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||||||||||||||||
| 200 | # The guard behind attach's require_running, and a pre-flight check is all it | ||||||||||||||||||||||||||||||||||||||||||
| 201 | # is: it asks the engine what the container is doing now, and the container may | ||||||||||||||||||||||||||||||||||||||||||
| 202 | # still stop between that answer and the attach landing. That race is not | ||||||||||||||||||||||||||||||||||||||||||
| 203 | # closable from a client -- the engine offers no attach-if-running -- and the | ||||||||||||||||||||||||||||||||||||||||||
| 204 | # check earns its round trip anyway, because the condition it tests is exactly | ||||||||||||||||||||||||||||||||||||||||||
| 205 | # the condition that does the damage. Measured on Podman 5.4.2 (API 1.41) and | ||||||||||||||||||||||||||||||||||||||||||
| 206 | # Docker 29.7.2 (API 1.55), one container per row, each exiting with status 4: | ||||||||||||||||||||||||||||||||||||||||||
| 207 | # | ||||||||||||||||||||||||||||||||||||||||||
| 208 | # attach to an ALREADY-EXITED container Podman: status destroyed | ||||||||||||||||||||||||||||||||||||||||||
| 209 | # attach while RUNNING, exits under the call Podman: status intact (4) | ||||||||||||||||||||||||||||||||||||||||||
| 210 | # either of those Docker: status intact (4) | ||||||||||||||||||||||||||||||||||||||||||
| 211 | # | ||||||||||||||||||||||||||||||||||||||||||
| 212 | # So "running at the moment of the call" is the whole of the condition. A | ||||||||||||||||||||||||||||||||||||||||||
| 213 | # container that is still running when attach is sent stays safe even when it | ||||||||||||||||||||||||||||||||||||||||||
| 214 | # exits a millisecond later, which is why the pre-flight answer is worth having | ||||||||||||||||||||||||||||||||||||||||||
| 215 | # despite being one round trip stale. | ||||||||||||||||||||||||||||||||||||||||||
| 216 | # | ||||||||||||||||||||||||||||||||||||||||||
| 217 | # It fails open on anything it does not recognise: a State it cannot read is | ||||||||||||||||||||||||||||||||||||||||||
| 218 | # not evidence that the container is stopped, and a guard that is unsure must | ||||||||||||||||||||||||||||||||||||||||||
| 219 | # not be the thing that breaks a working call. | ||||||||||||||||||||||||||||||||||||||||||
| 220 | 13 | ▶ | sub _assert_container_running { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_assert_container_running: called CC=6 SCAR=18.1
| |||||||||||||||||||||||||||||||||||||||||||
| 221 | 13 | my ($self, $id) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||||||||||||||||
| 223 | # A State the model could not use is one more shape the check does not | ||||||||||||||||||||||||||||||||||||||||||
| 224 | # recognise, and it arrives as one: the generated classes type their fields | ||||||||||||||||||||||||||||||||||||||||||
| 225 | # from the swagger, and a State that is not the object | ||||||||||||||||||||||||||||||||||||||||||
| 226 | # ContainerInspectResponse declares -- the bare status string of the list | ||||||||||||||||||||||||||||||||||||||||||
| 227 | # shape, say -- leaves ->state unset and keeps the raw value in | ||||||||||||||||||||||||||||||||||||||||||
| 228 | # unknown_fields rather than taking the response down with it. So there is | ||||||||||||||||||||||||||||||||||||||||||
| 229 | # nothing to catch here; an error that does reach this line, the daemon's | ||||||||||||||||||||||||||||||||||||||||||
| 230 | # own 404 included, is the caller's and goes up. | ||||||||||||||||||||||||||||||||||||||||||
| 231 | 13 | my $inspected = $self->inspect($id); | |||||||||||||||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||||||||||||||||
| 233 | # An API::Docker::Type::ContainerState, or undef where the daemon sent no | ||||||||||||||||||||||||||||||||||||||||||
| 234 | # State at all -- which is the "does not recognise" case above, not a stopped | ||||||||||||||||||||||||||||||||||||||||||
| 235 | # container. | ||||||||||||||||||||||||||||||||||||||||||
| 236 | 13 | my $state = $inspected->state; | |||||||||||||||||||||||||||||||||||||||||
| 237 | 13 | ▶ | return unless blessed($state) && defined $state->running; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
builtin::blessed($state) and defined $state->running
MC/DC100%2/2
builtin::blessed($state) and defined $state->running
builtin::blessed($state)
defined $state->running
Truth table100%3/3
A and B
A= builtin::blessed($state)B= defined $state->running
| |||||||||||||||||||||||||||||||||||||||||||
| 238 | 10 | ▶ | return if $state->running; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||||||||||||||||
| 240 | 1 | my $status = $state->status; | |||||||||||||||||||||||||||||||||||||||||
| 241 | 1 | ▶ | $status = 'not running' unless defined $status && length $status; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $status and length $status
MC/DC0%0/2
defined $status and length $status
defined $status
length $status
Truth table33%1/3
A and B
A= defined $statusB= length $status
| |||||||||||||||||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||||||||||||||||
| 243 | 1 | croak __PACKAGE__ . '->attach refused: container ' . $id . ' is ' . $status | |||||||||||||||||||||||||||||||||||||||||
| 244 | . '. Attaching to a container that is not running destroys its exit status ' | ||||||||||||||||||||||||||||||||||||||||||
| 245 | . 'on Podman, irrecoverably -- the engine keeps no copy -- and with ' | ||||||||||||||||||||||||||||||||||||||||||
| 246 | . 'stream => 1 never returns on either engine. Read its output with logs() ' | ||||||||||||||||||||||||||||||||||||||||||
| 247 | . 'instead, or pass require_running => 0 to attach anyway'; | ||||||||||||||||||||||||||||||||||||||||||
| 248 | } | ||||||||||||||||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||||||||||||||||
| 250 | 25 | ▶ | sub attach { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
attach: called CC=15 SCAR=27.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 251 | 25 | my ($self, $id, %opts) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 252 | 25 | ▶ | croak "Container ID required" unless $id; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 253 | |||||||||||||||||||||||||||||||||||||||||||
| 254 | # Pre-flight, and deliberately before the request is built: the call itself | ||||||||||||||||||||||||||||||||||||||||||
| 255 | # is what destroys the exit status, so a check made afterwards could only | ||||||||||||||||||||||||||||||||||||||||||
| 256 | # report the loss rather than prevent it. Turned off it costs nothing at all, | ||||||||||||||||||||||||||||||||||||||||||
| 257 | # not even the round trip. | ||||||||||||||||||||||||||||||||||||||||||
| 258 | my $require_running | ||||||||||||||||||||||||||||||||||||||||||
| 259 | 24 | ▶ | = defined $opts{require_running} ? $opts{require_running} : 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 260 | # The pre-flight is a request the caller never wrote, and one that hangs is | ||||||||||||||||||||||||||||||||||||||||||
| 261 | # exactly what a bound was set to prevent -- so it carries the same one. It | ||||||||||||||||||||||||||||||||||||||||||
| 262 | # does that by itself here: the check runs on $self, which is the clone | ||||||||||||||||||||||||||||||||||||||||||
| 263 | # ->using returned when there was one (karr k74). | ||||||||||||||||||||||||||||||||||||||||||
| 264 | 24 | ▶ | $self->_assert_container_running($id) if $require_running; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||||||||||||||||
| 266 | 23 | my %params; | |||||||||||||||||||||||||||||||||||||||||
| 267 | 23 | ▶ | $params{stream} = $opts{stream} ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 268 | 23 | ▶ | $params{logs} = defined $opts{logs} ? ($opts{logs} ? 1 : 0) : 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 269 | 23 | ▶ | $params{stdout} = defined $opts{stdout} ? ($opts{stdout} ? 1 : 0) : 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 270 | 23 | ▶ | $params{stderr} = defined $opts{stderr} ? ($opts{stderr} ? 1 : 0) : 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 271 | 23 | ▶ | $params{stdin} = $opts{stdin} ? 1 : 0 if defined $opts{stdin}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 272 | return $self->client->stream_frames('POST', "/containers/$id/attach", | ||||||||||||||||||||||||||||||||||||||||||
| 273 | params => \%params, | ||||||||||||||||||||||||||||||||||||||||||
| 274 | defined $opts{tty} ? ( tty => $opts{tty} ) : (), | ||||||||||||||||||||||||||||||||||||||||||
| 275 | 23 | ▶ | %{ $self->_request_options }, | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 276 | 23 | ▶ | exists $opts{on_frame} ? ( on_frame => $opts{on_frame} ) : (), | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 277 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 278 | } | ||||||||||||||||||||||||||||||||||||||||||
| 279 | |||||||||||||||||||||||||||||||||||||||||||
| 280 | |||||||||||||||||||||||||||||||||||||||||||
| 281 | 6 | ▶ | sub top { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
top: called CC=3 SCAR=11.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 282 | 6 | my ($self, $id, %opts) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 283 | 6 | ▶ | croak "Container ID required" unless $id; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 284 | 6 | my %params; | |||||||||||||||||||||||||||||||||||||||||
| 285 | 6 | ▶ | $params{ps_args} = $opts{ps_args} if defined $opts{ps_args}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 286 | return $self->client->get("/containers/$id/top", | ||||||||||||||||||||||||||||||||||||||||||
| 287 | params => \%params, | ||||||||||||||||||||||||||||||||||||||||||
| 288 | 6 | %{ $self->_request_options }, | |||||||||||||||||||||||||||||||||||||||||
| 289 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 290 | } | ||||||||||||||||||||||||||||||||||||||||||
| 291 | |||||||||||||||||||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||||||||||||||||
| 293 | # The Podman compatibility path, and deliberately only that. Podman answers | ||||||||||||||||||||||||||||||||||||||||||
| 294 | # GET /containers/{id}/stats for a container that is not running with an error | ||||||||||||||||||||||||||||||||||||||||||
| 295 | # object inside a response it has already committed to 200 -- | ||||||||||||||||||||||||||||||||||||||||||
| 296 | # {"cause":"container is stopped","message":"container is stopped", | ||||||||||||||||||||||||||||||||||||||||||
| 297 | # "response":500}, chunked, for the one-shot call and for stream => 1 alike | ||||||||||||||||||||||||||||||||||||||||||
| 298 | # (measured on Podman 5.4.2, API 1.41). Neither guard in the transport sees | ||||||||||||||||||||||||||||||||||||||||||
| 299 | # it: the >= 400 croak reads the status line, which says 200, and the stream | ||||||||||||||||||||||||||||||||||||||||||
| 300 | # check triggers on errorDetail, which this object does not carry. Docker | ||||||||||||||||||||||||||||||||||||||||||
| 301 | # 29.7.2 (API 1.55) answers the same call with a real, zero-filled reading and | ||||||||||||||||||||||||||||||||||||||||||
| 302 | # never produces this shape at all -- so this belongs here, next to the one | ||||||||||||||||||||||||||||||||||||||||||
| 303 | # endpoint and the one engine it was measured on, and not in Role::HTTP, where | ||||||||||||||||||||||||||||||||||||||||||
| 304 | # it would be a heuristic on daemon prose sitting under all twelve modules. | ||||||||||||||||||||||||||||||||||||||||||
| 305 | # | ||||||||||||||||||||||||||||||||||||||||||
| 306 | # All four clauses have to hold. The narrowness is the point, not an accident: | ||||||||||||||||||||||||||||||||||||||||||
| 307 | # | ||||||||||||||||||||||||||||||||||||||||||
| 308 | # 1. the status was 2xx. True by construction on both paths this guards: | ||||||||||||||||||||||||||||||||||||||||||
| 309 | # _request croaks before returning for >= 400, and | ||||||||||||||||||||||||||||||||||||||||||
| 310 | # _read_streaming_response reads such a body whole rather than handing it | ||||||||||||||||||||||||||||||||||||||||||
| 311 | # to a callback, so nothing that failed the status line reaches here | ||||||||||||||||||||||||||||||||||||||||||
| 312 | # 2. the decoded value is a HashRef | ||||||||||||||||||||||||||||||||||||||||||
| 313 | # 3. it carries all three of cause, message and response, exactly | ||||||||||||||||||||||||||||||||||||||||||
| 314 | # lower-cased. Never case-insensitively, and this is the counter-example | ||||||||||||||||||||||||||||||||||||||||||
| 315 | # that fixes it: POST /containers/{id}/wait answers its SUCCESS case with | ||||||||||||||||||||||||||||||||||||||||||
| 316 | # a top-level `Error` key -- Podman sends "Error":null on every wait -- | ||||||||||||||||||||||||||||||||||||||||||
| 317 | # so a rule matching /error/i would turn every successful wait into a | ||||||||||||||||||||||||||||||||||||||||||
| 318 | # failure. Measured over fifteen read endpoints per engine and every | ||||||||||||||||||||||||||||||||||||||||||
| 319 | # fixture in t/fixtures: no 2xx body on either engine carries even one of | ||||||||||||||||||||||||||||||||||||||||||
| 320 | # these three lower-cased at the top level | ||||||||||||||||||||||||||||||||||||||||||
| 321 | # 4. `response` is a non-ref scalar reading as an integer >= 400. That is | ||||||||||||||||||||||||||||||||||||||||||
| 322 | # what makes the rule self-evidencing rather than a guess about prose: | ||||||||||||||||||||||||||||||||||||||||||
| 323 | # the object is an error because Podman says so inside it. Known miss: | ||||||||||||||||||||||||||||||||||||||||||
| 324 | # Podman's GET /plugins answers {"cause":"","message":"Path ... is not | ||||||||||||||||||||||||||||||||||||||||||
| 325 | # supported","response":0}, which clause 4 rejects -- but it arrives with | ||||||||||||||||||||||||||||||||||||||||||
| 326 | # 404 on the status line and the transport croaks it long before this | ||||||||||||||||||||||||||||||||||||||||||
| 327 | # runs, so the miss goes in the conservative direction and costs nothing | ||||||||||||||||||||||||||||||||||||||||||
| 328 | # | ||||||||||||||||||||||||||||||||||||||||||
| 329 | # A bare {message => ...} deliberately does not trigger: that is the ordinary | ||||||||||||||||||||||||||||||||||||||||||
| 330 | # Docker error body, and treating one inside a 2xx as a failure would be a | ||||||||||||||||||||||||||||||||||||||||||
| 331 | # guess about prose rather than a reading of what the engine said. | ||||||||||||||||||||||||||||||||||||||||||
| 332 | 25 | ▶ | sub _podman_error_object { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_podman_error_object: called CC=9 SCAR=22.1
| |||||||||||||||||||||||||||||||||||||||||||
| 333 | 25 | my ($self, $value) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 334 | |||||||||||||||||||||||||||||||||||||||||||
| 335 | 25 | ▶ | return unless ref $value eq 'HASH'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 336 | return unless exists $value->{cause} | ||||||||||||||||||||||||||||||||||||||||||
| 337 | && exists $value->{message} | ||||||||||||||||||||||||||||||||||||||||||
| 338 | 25 | ▶ | && exists $value->{response}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
exists $value->{"cause"} and exists $value->{"message"} and exists $value->{"response"}
exists $value->{"cause"} and exists $value->{"message"}
MC/DC66%2/3
exists $value->{"cause"} and exists $value->{"message"} and exists $value->{"response"}
exists $value->{"cause"}
exists $value->{"message"}
exists $value->{"response"}
Truth table75%3/4
A and B and C
A= exists $value->{"cause"}B= exists $value->{"message"}C= exists $value->{"response"}
| |||||||||||||||||||||||||||||||||||||||||||
| 339 | |||||||||||||||||||||||||||||||||||||||||||
| 340 | 7 | my $response = $value->{response}; | |||||||||||||||||||||||||||||||||||||||||
| 341 | 7 | ▶ | return if ref $response; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 342 | 6 | ▶ | return unless defined $response && $response =~ /\A[0-9]+\z/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $response and $response =~ /\A[0-9]+\z/
MC/DC50%1/2
defined $response and $response =~ /\A[0-9]+\z/
defined $response
$response =~ /\A[0-9]+\z/
Truth table66%2/3
A and B
A= defined $responseB= $response =~ /\A[0-9]+\z/
| |||||||||||||||||||||||||||||||||||||||||||
| 343 | 5 | ▶ | return unless $response >= 400; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 344 | |||||||||||||||||||||||||||||||||||||||||||
| 345 | 3 | return $value; | |||||||||||||||||||||||||||||||||||||||||
| 346 | } | ||||||||||||||||||||||||||||||||||||||||||
| 347 | |||||||||||||||||||||||||||||||||||||||||||
| 348 | # API::Docker::Error::HTTP rather than ::Stream: the one-shot call is not a | ||||||||||||||||||||||||||||||||||||||||||
| 349 | # stream at all, so "Docker API stream error" would be the wrong sentence for | ||||||||||||||||||||||||||||||||||||||||||
| 350 | # it and ->events would be a fabricated list. What the caller wants instead is | ||||||||||||||||||||||||||||||||||||||||||
| 351 | # exactly what this class carries -- ->status for the code Podman named, and | ||||||||||||||||||||||||||||||||||||||||||
| 352 | # ->data for the object, whose `cause` key that attribute's own POD already | ||||||||||||||||||||||||||||||||||||||||||
| 353 | # points at. Two of its attributes are left at their defaults on this path, on | ||||||||||||||||||||||||||||||||||||||||||
| 354 | # purpose: ->reason, because the status line's reason phrase was "OK" and | ||||||||||||||||||||||||||||||||||||||||||
| 355 | # putting that on a 500 would mislead, and ->body, because the bytes were | ||||||||||||||||||||||||||||||||||||||||||
| 356 | # decoded by the transport before this check ever saw them. | ||||||||||||||||||||||||||||||||||||||||||
| 357 | 25 | ▶ | sub _assert_no_podman_error { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_assert_no_podman_error: called CC=6 SCAR=19.4
| |||||||||||||||||||||||||||||||||||||||||||
| 358 | 25 | my ($self, $endpoint, $value) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 359 | |||||||||||||||||||||||||||||||||||||||||||
| 360 | 25 | ▶ | my $error = $self->_podman_error_object($value) or return $value; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 361 | |||||||||||||||||||||||||||||||||||||||||||
| 362 | 3 | my $reason = $error->{message}; | |||||||||||||||||||||||||||||||||||||||||
| 363 | 3 | ▶ | $reason = $error->{cause} unless defined $reason && length $reason; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $reason and length $reason
MC/DC0%0/2
defined $reason and length $reason
defined $reason
length $reason
Truth table33%1/3
A and B
A= defined $reasonB= length $reason
| |||||||||||||||||||||||||||||||||||||||||||
| 364 | 3 | ▶ | $reason = 'no message given' unless defined $reason && length $reason; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $reason and length $reason
MC/DC0%0/2
defined $reason and length $reason
defined $reason
length $reason
Truth table33%1/3
A and B
A= defined $reasonB= length $reason
| |||||||||||||||||||||||||||||||||||||||||||
| 365 | # Carp appends no location to a message that already ends in a newline. | ||||||||||||||||||||||||||||||||||||||||||
| 366 | 3 | $reason =~ s/\s+\z//; | |||||||||||||||||||||||||||||||||||||||||
| 367 | |||||||||||||||||||||||||||||||||||||||||||
| 368 | # The object goes into a variable first: `croak CLASS->new(...)` is indirect | ||||||||||||||||||||||||||||||||||||||||||
| 369 | # object syntax and parses as CLASS->croak(new(...)). Carp hands a reference | ||||||||||||||||||||||||||||||||||||||||||
| 370 | # straight back rather than decorating it, so the location is captured by | ||||||||||||||||||||||||||||||||||||||||||
| 371 | # hand, naming the frame a croak of a plain string would have named. | ||||||||||||||||||||||||||||||||||||||||||
| 372 | my $err = API::Docker::Error::HTTP->new( | ||||||||||||||||||||||||||||||||||||||||||
| 373 | message => 'Docker API error (' . $error->{response} . '): ' . $reason | ||||||||||||||||||||||||||||||||||||||||||
| 374 | . ' -- reported inside a 200 response to ' . $endpoint, | ||||||||||||||||||||||||||||||||||||||||||
| 375 | location => shortmess(''), | ||||||||||||||||||||||||||||||||||||||||||
| 376 | status => $error->{response}, | ||||||||||||||||||||||||||||||||||||||||||
| 377 | 3 | data => $error, | |||||||||||||||||||||||||||||||||||||||||
| 378 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 379 | 3 | croak $err; | |||||||||||||||||||||||||||||||||||||||||
| 380 | } | ||||||||||||||||||||||||||||||||||||||||||
| 381 | |||||||||||||||||||||||||||||||||||||||||||
| 382 | 22 | ▶ | sub stats { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
stats: called CC=10 SCAR=23.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 383 | 22 | my ($self, $id, %opts) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 384 | 22 | ▶ | croak "Container ID required" unless $id; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 385 | 22 | ▶ | my $stream = $opts{stream} ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 386 | 22 | my %params = ( stream => $stream ); | |||||||||||||||||||||||||||||||||||||||||
| 387 | # one-shot asks the engine not to wait for a second sampling cycle, which | ||||||||||||||||||||||||||||||||||||||||||
| 388 | # only means anything to a single reading. It is sent for the one-shot call | ||||||||||||||||||||||||||||||||||||||||||
| 389 | # alone, the way it always was, and never beside stream => 1. | ||||||||||||||||||||||||||||||||||||||||||
| 390 | 22 | ▶ | $params{'one-shot'} = 1 unless $stream; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 391 | |||||||||||||||||||||||||||||||||||||||||||
| 392 | 22 | my $endpoint = 'GET /containers/' . $id . '/stats'; | |||||||||||||||||||||||||||||||||||||||||
| 393 | |||||||||||||||||||||||||||||||||||||||||||
| 394 | # The guard has to sit on both sides of the callback split, because the same | ||||||||||||||||||||||||||||||||||||||||||
| 395 | # body arrives either way: buffered it is the return value, streamed it goes | ||||||||||||||||||||||||||||||||||||||||||
| 396 | # to the callback and is never returned at all. Wrapping puts the check in | ||||||||||||||||||||||||||||||||||||||||||
| 397 | # front of the caller's callback, so no caller is handed the error object as | ||||||||||||||||||||||||||||||||||||||||||
| 398 | # though it were a reading. Only a CodeRef is wrapped -- anything else is | ||||||||||||||||||||||||||||||||||||||||||
| 399 | # passed through untouched, so the transport still raises its own "on_event | ||||||||||||||||||||||||||||||||||||||||||
| 400 | # option must be a CodeRef" instead of this method dying on a closure it | ||||||||||||||||||||||||||||||||||||||||||
| 401 | # built around a non-callback. | ||||||||||||||||||||||||||||||||||||||||||
| 402 | 22 | my $on_event = $opts{on_event}; | |||||||||||||||||||||||||||||||||||||||||
| 403 | 22 | ▶ | if (exists $opts{on_event} && ref $on_event eq 'CODE') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
exists $opts{"on_event"} and ref $on_event eq "CODE"
MC/DC50%1/2
exists $opts{"on_event"} and ref $on_event eq "CODE"
exists $opts{"on_event"}
ref $on_event eq "CODE"
Truth table66%2/3
A and B
A= exists $opts{"on_event"}B= ref $on_event eq "CODE"
| |||||||||||||||||||||||||||||||||||||||||||
| 404 | 3 | my $cb = $on_event; | |||||||||||||||||||||||||||||||||||||||||
| 405 | 6 | ▶ | $on_event = sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 406 | 6 | my ($reading, $stop) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 407 | 6 | $self->_assert_no_podman_error($endpoint, $reading); | |||||||||||||||||||||||||||||||||||||||||
| 408 | 5 | return $cb->($reading, $stop); | |||||||||||||||||||||||||||||||||||||||||
| 409 | 3 | }; | |||||||||||||||||||||||||||||||||||||||||
| 410 | } | ||||||||||||||||||||||||||||||||||||||||||
| 411 | |||||||||||||||||||||||||||||||||||||||||||
| 412 | my $result = $self->client->get("/containers/$id/stats", | ||||||||||||||||||||||||||||||||||||||||||
| 413 | params => \%params, | ||||||||||||||||||||||||||||||||||||||||||
| 414 | 22 | ▶ | %{ $self->_request_options }, | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 415 | 22 | exists $opts{on_event} ? ( on_event => $on_event ) | |||||||||||||||||||||||||||||||||||||||||
| 416 | : $stream ? ( ndjson => 1 ) | ||||||||||||||||||||||||||||||||||||||||||
| 417 | : (), | ||||||||||||||||||||||||||||||||||||||||||
| 418 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 419 | |||||||||||||||||||||||||||||||||||||||||||
| 420 | # A HashRef for the one-shot call and an ArrayRef of readings for | ||||||||||||||||||||||||||||||||||||||||||
| 421 | # stream => 1 without a callback -- both are the buffered body and both can | ||||||||||||||||||||||||||||||||||||||||||
| 422 | # be that error object. With a callback the return value is the summary | ||||||||||||||||||||||||||||||||||||||||||
| 423 | # HashRef, which carries none of the three keys and passes untouched. | ||||||||||||||||||||||||||||||||||||||||||
| 424 | $self->_assert_no_podman_error($endpoint, $_) | ||||||||||||||||||||||||||||||||||||||||||
| 425 | 21 | ▶ | for ref $result eq 'ARRAY' ? @$result : ($result); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 426 | |||||||||||||||||||||||||||||||||||||||||||
| 427 | 19 | return $result; | |||||||||||||||||||||||||||||||||||||||||
| 428 | } | ||||||||||||||||||||||||||||||||||||||||||
| 429 | |||||||||||||||||||||||||||||||||||||||||||
| 430 | |||||||||||||||||||||||||||||||||||||||||||
| 431 | 8 | ▶ | sub changes { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
changes: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 432 | 8 | my ($self, $id) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 433 | 8 | ▶ | croak "Container ID required" unless $id; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 434 | my $result = $self->client->get("/containers/$id/changes", | ||||||||||||||||||||||||||||||||||||||||||
| 435 | 7 | %{ $self->_request_options }, | |||||||||||||||||||||||||||||||||||||||||
| 436 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 437 | # A container with nothing changed answers with a JSON null, which the | ||||||||||||||||||||||||||||||||||||||||||
| 438 | # transport decodes to undef. Normalised here so the return is always | ||||||||||||||||||||||||||||||||||||||||||
| 439 | # something a caller can iterate. | ||||||||||||||||||||||||||||||||||||||||||
| 440 | 7 | ▶ | return ref $result eq 'ARRAY' ? $result : []; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 441 | } | ||||||||||||||||||||||||||||||||||||||||||
| 442 | |||||||||||||||||||||||||||||||||||||||||||
| 443 | |||||||||||||||||||||||||||||||||||||||||||
| 444 | 7 | ▶ | sub export { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
export: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 445 | 7 | my ($self, $id) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 446 | 7 | ▶ | croak "Container ID required" unless $id; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 447 | return $self->client->get("/containers/$id/export", | ||||||||||||||||||||||||||||||||||||||||||
| 448 | raw => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 449 | 6 | %{ $self->_request_options }, | |||||||||||||||||||||||||||||||||||||||||
| 450 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 451 | } | ||||||||||||||||||||||||||||||||||||||||||
| 452 | |||||||||||||||||||||||||||||||||||||||||||
| 453 | |||||||||||||||||||||||||||||||||||||||||||
| 454 | 7 | ▶ | sub resize { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
resize: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 455 | 7 | my ($self, $id, %opts) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 456 | 7 | ▶ | croak "Container ID required" unless $id; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 457 | 6 | my %params; | |||||||||||||||||||||||||||||||||||||||||
| 458 | 6 | ▶ | $params{h} = $opts{h} if defined $opts{h}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 459 | 6 | ▶ | $params{w} = $opts{w} if defined $opts{w}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 460 | return $self->client->post("/containers/$id/resize", undef, | ||||||||||||||||||||||||||||||||||||||||||
| 461 | params => \%params, | ||||||||||||||||||||||||||||||||||||||||||
| 462 | 6 | %{ $self->_request_options }, | |||||||||||||||||||||||||||||||||||||||||
| 463 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 464 | } | ||||||||||||||||||||||||||||||||||||||||||
| 465 | |||||||||||||||||||||||||||||||||||||||||||
| 466 | |||||||||||||||||||||||||||||||||||||||||||
| 467 | 5 | ▶ | sub wait { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
wait: called CC=3 SCAR=11.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 468 | 5 | my ($self, $id, %opts) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 469 | 5 | ▶ | croak "Container ID required" unless $id; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 470 | 5 | my %params; | |||||||||||||||||||||||||||||||||||||||||
| 471 | 5 | ▶ | $params{condition} = $opts{condition} if defined $opts{condition}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 472 | return $self->client->post("/containers/$id/wait", undef, | ||||||||||||||||||||||||||||||||||||||||||
| 473 | params => \%params, | ||||||||||||||||||||||||||||||||||||||||||
| 474 | 5 | %{ $self->_request_options }, | |||||||||||||||||||||||||||||||||||||||||
| 475 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 476 | } | ||||||||||||||||||||||||||||||||||||||||||
| 477 | |||||||||||||||||||||||||||||||||||||||||||
| 478 | |||||||||||||||||||||||||||||||||||||||||||
| 479 | 6 | ▶ | sub pause { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
pause: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 480 | 6 | my ($self, $id) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 481 | 6 | ▶ | croak "Container ID required" unless $id; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 482 | return $self->_state_change("/containers/$id/pause", | ||||||||||||||||||||||||||||||||||||||||||
| 483 | 6 | %{ $self->_request_options }, | |||||||||||||||||||||||||||||||||||||||||
| 484 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 485 | } | ||||||||||||||||||||||||||||||||||||||||||
| 486 | |||||||||||||||||||||||||||||||||||||||||||
| 487 | |||||||||||||||||||||||||||||||||||||||||||
| 488 | 6 | ▶ | sub unpause { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
unpause: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 489 | 6 | my ($self, $id) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 490 | 6 | ▶ | croak "Container ID required" unless $id; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 491 | return $self->_state_change("/containers/$id/unpause", | ||||||||||||||||||||||||||||||||||||||||||
| 492 | 6 | %{ $self->_request_options }, | |||||||||||||||||||||||||||||||||||||||||
| 493 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 494 | } | ||||||||||||||||||||||||||||||||||||||||||
| 495 | |||||||||||||||||||||||||||||||||||||||||||
| 496 | |||||||||||||||||||||||||||||||||||||||||||
| 497 | 4 | ▶ | sub rename { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
rename: called CC=3 SCAR=11.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 498 | 4 | my ($self, $id, $name) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 499 | 4 | ▶ | croak "Container ID required" unless $id; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 500 | 4 | ▶ | croak "New name required" unless $name; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 501 | return $self->client->post("/containers/$id/rename", undef, | ||||||||||||||||||||||||||||||||||||||||||
| 502 | params => { name => $name }, | ||||||||||||||||||||||||||||||||||||||||||
| 503 | 4 | %{ $self->_request_options }, | |||||||||||||||||||||||||||||||||||||||||
| 504 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 505 | } | ||||||||||||||||||||||||||||||||||||||||||
| 506 | |||||||||||||||||||||||||||||||||||||||||||
| 507 | |||||||||||||||||||||||||||||||||||||||||||
| 508 | # The update body is Resources + RestartPolicy; the booleans are the two | ||||||||||||||||||||||||||||||||||||||||||
| 509 | # Resources flags. Normalised on the way out, as for create. | ||||||||||||||||||||||||||||||||||||||||||
| 510 | 52 | my @UPDATE_BOOLS = qw( Init OomKillDisable ); | |||||||||||||||||||||||||||||||||||||||||
| 511 | |||||||||||||||||||||||||||||||||||||||||||
| 512 | 1 | ▶ | sub update { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
update: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 513 | 1 | my ($self, $id, %config) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 514 | 1 | ▶ | croak "Container ID required" unless $id; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 515 | 1 | $self->_json_bools(\%config, @UPDATE_BOOLS); | |||||||||||||||||||||||||||||||||||||||||
| 516 | 1 | return $self->client->post("/containers/$id/update", \%config); | |||||||||||||||||||||||||||||||||||||||||
| 517 | } | ||||||||||||||||||||||||||||||||||||||||||
| 518 | |||||||||||||||||||||||||||||||||||||||||||
| 519 | |||||||||||||||||||||||||||||||||||||||||||
| 520 | # The engine reports what a path is in a response header rather than a body, | ||||||||||||||||||||||||||||||||||||||||||
| 521 | # so both GET and HEAD carry it and only HEAD has nothing else to say. The | ||||||||||||||||||||||||||||||||||||||||||
| 522 | # header is base64-encoded JSON; handing the caller the base64 would make | ||||||||||||||||||||||||||||||||||||||||||
| 523 | # every one of them write this. | ||||||||||||||||||||||||||||||||||||||||||
| 524 | 11 | ▶ | sub _decode_path_stat { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_decode_path_stat: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||
| 525 | 11 | my ($self, $response) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 526 | |||||||||||||||||||||||||||||||||||||||||||
| 527 | 11 | my $header = $response->{headers}{'x-docker-container-path-stat'}; | |||||||||||||||||||||||||||||||||||||||||
| 528 | 11 | ▶ | return undef unless defined $header && length $header; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $header and length $header
MC/DC100%2/2
defined $header and length $header
defined $header
length $header
Truth table100%3/3
A and B
A= defined $headerB= length $header
| |||||||||||||||||||||||||||||||||||||||||||
| 529 | |||||||||||||||||||||||||||||||||||||||||||
| 530 | # Docker encodes this one with Go's base64.StdEncoding -- unlike | ||||||||||||||||||||||||||||||||||||||||||
| 531 | # X-Registry-Auth, which is URLEncoding. Decoded tolerantly rather than | ||||||||||||||||||||||||||||||||||||||||||
| 532 | # strictly: translating the two URL-safe characters first costs nothing and | ||||||||||||||||||||||||||||||||||||||||||
| 533 | # means an engine that reached for the other alphabet is still read. | ||||||||||||||||||||||||||||||||||||||||||
| 534 | 5 | $header =~ tr{-_}{+/}; | |||||||||||||||||||||||||||||||||||||||||
| 535 | 5 | my $stat = eval { decode_json(decode_base64($header)) }; | |||||||||||||||||||||||||||||||||||||||||
| 536 | 5 | ▶ | croak "Cannot decode X-Docker-Container-Path-Stat header: $@" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 537 | unless ref $stat eq 'HASH'; | ||||||||||||||||||||||||||||||||||||||||||
| 538 | |||||||||||||||||||||||||||||||||||||||||||
| 539 | 4 | return $stat; | |||||||||||||||||||||||||||||||||||||||||
| 540 | } | ||||||||||||||||||||||||||||||||||||||||||
| 541 | |||||||||||||||||||||||||||||||||||||||||||
| 542 | 13 | ▶ | sub get_archive { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_archive: called CC=8 SCAR=20.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 543 | 13 | my ($self, $id, %opts) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 544 | 13 | ▶ | croak "Container ID required" unless $id; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 545 | 12 | ▶ | croak "Path required" unless defined $opts{path} && length $opts{path}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $opts{"path"} and length $opts{"path"}
MC/DC100%2/2
defined $opts{"path"} and length $opts{"path"}
defined $opts{"path"}
length $opts{"path"}
Truth table100%3/3
A and B
A= defined $opts{"path"}B= length $opts{"path"}
| |||||||||||||||||||||||||||||||||||||||||||
| 546 | croak "The stat option must be a HashRef" | ||||||||||||||||||||||||||||||||||||||||||
| 547 | 10 | ▶ | if exists $opts{stat} && ref $opts{stat} ne 'HASH'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
exists $opts{"stat"} and ref $opts{"stat"} ne "HASH"
MC/DC100%2/2
exists $opts{"stat"} and ref $opts{"stat"} ne "HASH"
exists $opts{"stat"}
ref $opts{"stat"} ne "HASH"
Truth table100%3/3
A and B
A= exists $opts{"stat"}B= ref $opts{"stat"} ne "HASH"
| |||||||||||||||||||||||||||||||||||||||||||
| 548 | |||||||||||||||||||||||||||||||||||||||||||
| 549 | 9 | my %response; | |||||||||||||||||||||||||||||||||||||||||
| 550 | my $tar = $self->client->get("/containers/$id/archive", | ||||||||||||||||||||||||||||||||||||||||||
| 551 | params => { path => $opts{path} }, | ||||||||||||||||||||||||||||||||||||||||||
| 552 | raw => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 553 | response => \%response, | ||||||||||||||||||||||||||||||||||||||||||
| 554 | 9 | %{ $self->_request_options }, | |||||||||||||||||||||||||||||||||||||||||
| 555 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 556 | |||||||||||||||||||||||||||||||||||||||||||
| 557 | 9 | ▶ | if (my $out = $opts{stat}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 558 | 2 | ▶ | %$out = %{ $self->_decode_path_stat(\%response) // {} }; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$self->_decode_path_stat(\%response) // {}
MC/DC100%1/1
$self->_decode_path_stat(\%response) // {}
$self->_decode_path_stat(\%response)
Truth table100%2/2
A
A= $self->_decode_path_stat(\%response)
| |||||||||||||||||||||||||||||||||||||||||||
| 559 | } | ||||||||||||||||||||||||||||||||||||||||||
| 560 | |||||||||||||||||||||||||||||||||||||||||||
| 561 | 9 | return $tar; | |||||||||||||||||||||||||||||||||||||||||
| 562 | } | ||||||||||||||||||||||||||||||||||||||||||
| 563 | |||||||||||||||||||||||||||||||||||||||||||
| 564 | |||||||||||||||||||||||||||||||||||||||||||
| 565 | 12 | ▶ | sub put_archive { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
put_archive: called CC=10 SCAR=23.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 566 | 12 | my ($self, $id, $tar, %opts) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 567 | 12 | ▶ | croak "Container ID required" unless $id; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 568 | 11 | ▶ | croak "Path required" unless defined $opts{path} && length $opts{path}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $opts{"path"} and length $opts{"path"}
MC/DC50%1/2
defined $opts{"path"} and length $opts{"path"}
defined $opts{"path"}
length $opts{"path"}
Truth table66%2/3
A and B
A= defined $opts{"path"}B= length $opts{"path"}
| |||||||||||||||||||||||||||||||||||||||||||
| 569 | 10 | ▶ | croak "Tar archive required (raw bytes or a scalar ref)" unless defined $tar; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 570 | |||||||||||||||||||||||||||||||||||||||||||
| 571 | 9 | my %params = ( path => $opts{path} ); | |||||||||||||||||||||||||||||||||||||||||
| 572 | $params{noOverwriteDirNonDir} = $opts{noOverwriteDirNonDir} ? 1 : 0 | ||||||||||||||||||||||||||||||||||||||||||
| 573 | 9 | ▶ | if defined $opts{noOverwriteDirNonDir}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 574 | $params{copyUIDGID} = $opts{copyUIDGID} ? 1 : 0 | ||||||||||||||||||||||||||||||||||||||||||
| 575 | 9 | ▶ | if defined $opts{copyUIDGID}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 576 | |||||||||||||||||||||||||||||||||||||||||||
| 577 | 9 | ▶ | my $raw = ref $tar eq 'SCALAR' ? $$tar : $tar; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 578 | |||||||||||||||||||||||||||||||||||||||||||
| 579 | return $self->client->put("/containers/$id/archive", undef, | ||||||||||||||||||||||||||||||||||||||||||
| 580 | params => \%params, | ||||||||||||||||||||||||||||||||||||||||||
| 581 | raw_body => $raw, | ||||||||||||||||||||||||||||||||||||||||||
| 582 | content_type => 'application/x-tar', | ||||||||||||||||||||||||||||||||||||||||||
| 583 | 9 | %{ $self->_request_options }, | |||||||||||||||||||||||||||||||||||||||||
| 584 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 585 | } | ||||||||||||||||||||||||||||||||||||||||||
| 586 | |||||||||||||||||||||||||||||||||||||||||||
| 587 | |||||||||||||||||||||||||||||||||||||||||||
| 588 | 11 | ▶ | sub stat_archive { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
stat_archive: called CC=4 SCAR=14.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 589 | 11 | my ($self, $id, %opts) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 590 | 11 | ▶ | croak "Container ID required" unless $id; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 591 | 11 | ▶ | croak "Path required" unless defined $opts{path} && length $opts{path}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $opts{"path"} and length $opts{"path"}
MC/DC50%1/2
defined $opts{"path"} and length $opts{"path"}
defined $opts{"path"}
length $opts{"path"}
Truth table66%2/3
A and B
A= defined $opts{"path"}B= length $opts{"path"}
| |||||||||||||||||||||||||||||||||||||||||||
| 592 | |||||||||||||||||||||||||||||||||||||||||||
| 593 | 10 | my %response; | |||||||||||||||||||||||||||||||||||||||||
| 594 | $self->client->head("/containers/$id/archive", | ||||||||||||||||||||||||||||||||||||||||||
| 595 | params => { path => $opts{path} }, | ||||||||||||||||||||||||||||||||||||||||||
| 596 | response => \%response, | ||||||||||||||||||||||||||||||||||||||||||
| 597 | 10 | %{ $self->_request_options }, | |||||||||||||||||||||||||||||||||||||||||
| 598 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 599 | |||||||||||||||||||||||||||||||||||||||||||
| 600 | 9 | return $self->_decode_path_stat(\%response); | |||||||||||||||||||||||||||||||||||||||||
| 601 | } | ||||||||||||||||||||||||||||||||||||||||||
| 602 | |||||||||||||||||||||||||||||||||||||||||||
| 603 | |||||||||||||||||||||||||||||||||||||||||||
| 604 | 5 | ▶ | sub prune { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
prune: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 605 | 5 | my ($self, %opts) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 606 | 5 | my %params; | |||||||||||||||||||||||||||||||||||||||||
| 607 | $params{filters} = $self->_normalise_filters($opts{filters}) | ||||||||||||||||||||||||||||||||||||||||||
| 608 | 5 | ▶ | if defined $opts{filters}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 609 | return $self->client->post('/containers/prune', undef, | ||||||||||||||||||||||||||||||||||||||||||
| 610 | params => \%params, | ||||||||||||||||||||||||||||||||||||||||||
| 611 | 4 | %{ $self->_request_options }, | |||||||||||||||||||||||||||||||||||||||||
| 612 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 613 | } | ||||||||||||||||||||||||||||||||||||||||||
| 614 | |||||||||||||||||||||||||||||||||||||||||||
| 615 | |||||||||||||||||||||||||||||||||||||||||||
| 616 | |||||||||||||||||||||||||||||||||||||||||||
| 617 | 52 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 618 | |||||||||||||||||||||||||||||||||||||||||||
| 619 | __END__ | ||||||||||||||||||||||||||||||||||||||||||