| 1 | package API::Docker; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | # ABSTRACT: Perl client for the Docker Engine API | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 52 | our $VERSION = '0.006'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 52 | ▶ | use Moo; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 52 | ▶ | use Carp qw( croak ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 52 | ▶ | use Log::Any qw( $log ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 52 | ▶ | use API::Docker::API::System; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 52 | ▶ | use API::Docker::API::Containers; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 52 | ▶ | use API::Docker::API::Images; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 52 | ▶ | use API::Docker::API::Networks; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 52 | ▶ | use API::Docker::API::Volumes; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 52 | ▶ | use API::Docker::API::Exec; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 52 | ▶ | use API::Docker::API::Distribution; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 52 | ▶ | use API::Docker::API::Secrets; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 52 | ▶ | use API::Docker::API::Configs; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 52 | ▶ | use API::Docker::API::Plugins; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 52 | ▶ | use namespace::clean; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | has host => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 11 | ▶ | default => sub { $ENV{DOCKER_HOST} // 'unix:///var/run/docker.sock' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
Condition100%2/2
$ENV{"DOCKER_HOST"} // "unix:///var/run/docker.sock"
MC/DC100%1/1
$ENV{"DOCKER_HOST"} // "unix:///var/run/docker.sock"
$ENV{"DOCKER_HOST"}
Truth table100%2/2
A
A= $ENV{"DOCKER_HOST"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 52 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 52 | has api_version => ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | is => 'rwp', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | default => undef, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 52 | has tls => ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | is => 'lazy', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 717 | ▶ | sub _build_tls { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_tls: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 717 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | # The docker CLI's own rule, read off cli/flags/options.go: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | # dockerTLSVerify = os.Getenv(client.EnvTLSVerify) != "" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | # Every non-empty value turns TLS on, DOCKER_TLS_VERIFY=0 included. Perl | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | # truthiness would read that '0' as off and disagree with the CLI on exactly | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | # the value a user is most likely to type for "off", so the test is | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | # defined-and-not-empty rather than a boolean one. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | return 0 unless defined $ENV{DOCKER_TLS_VERIFY} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 717 | ▶ | && $ENV{DOCKER_TLS_VERIFY} ne ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $ENV{"DOCKER_TLS_VERIFY"} and $ENV{"DOCKER_TLS_VERIFY"} ne ""
MC/DC100%2/2
defined $ENV{"DOCKER_TLS_VERIFY"} and $ENV{"DOCKER_TLS_VERIFY"} ne ""
defined $ENV{"DOCKER_TLS_VERIFY"}
$ENV{"DOCKER_TLS_VERIFY"} ne ""
Truth table100%3/3
A and B
A= defined $ENV{"DOCKER_TLS_VERIFY"}B= $ENV{"DOCKER_TLS_VERIFY"} ne ""
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | # And the CLI ignores TLS on a socket host without saying so | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | # (cli/context/docker/load.go, "there's no need to configure TLS for a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | # socket connection"). Ignoring it here is not politeness: BUILD croaks on | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | # tls => 1 with a non-tcp:// host, so a host-blind default would make a bare | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | # API::Docker->new die on every unix:// machine that exports the variable. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 48 | ▶ | return $self->host =~ m{^tcp://} ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | has cert_path => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 757 | ▶ | default => sub { $ENV{DOCKER_CERT_PATH} }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 52 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 52 | has tls_insecure => ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | default => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 801 | ▶ | sub BUILD { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BUILD: called CC=5 SCAR=16.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 801 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | # Both checks are here rather than at connect time so that a request for | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | # encryption that cannot be honoured is refused before the caller has a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | # client to hand credentials to. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 801 | ▶ | croak __PACKAGE__ . '->new tls_insecure => 1 without tls => 1 does ' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$self->tls_insecure and not $self->tls
MC/DC100%2/2
$self->tls_insecure and not $self->tls
$self->tls_insecure
not $self->tls
Truth table100%3/3
A and not(B)
A= $self->tls_insecureB= not $self->tls
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | . 'nothing: verification is only reachable on a connection that has TLS ' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | . 'to verify. Set tls => 1 as well, or drop the option' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | if $self->tls_insecure && !$self->tls; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 797 | ▶ | return unless $self->tls; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 104 | my $host = $self->host; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 104 | ▶ | croak __PACKAGE__ . '->new tls => 1 is only meaningful for a tcp:// host, ' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | . 'and this one is ' . $host . '. A Unix socket is a file rather than a ' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | . 'wire and carries nothing to encrypt, so honouring the option is not ' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | . 'possible and ignoring it would answer a request for an encrypted ' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | . 'transport with an unencrypted one' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | unless $host =~ m{^tcp://}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 52 | has _version_negotiated => ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | default => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 52 | with 'API::Docker::Role::HTTP'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | has system => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | is => 'lazy', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 32 | ▶ | builder => sub { API::Docker::API::System->new(client => $_[0]) }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_system: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 52 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | has containers => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | is => 'lazy', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 13 | ▶ | builder => sub { API::Docker::API::Containers->new(client => $_[0]) }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
_build_containers: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 52 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | has images => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | is => 'lazy', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 17 | ▶ | builder => sub { API::Docker::API::Images->new(client => $_[0]) }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 52 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | has networks => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | is => 'lazy', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 24 | ▶ | builder => sub { API::Docker::API::Networks->new(client => $_[0]) }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 52 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | has volumes => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | is => 'lazy', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 22 | ▶ | builder => sub { API::Docker::API::Volumes->new(client => $_[0]) }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 52 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | has exec => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | is => 'lazy', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 16 | ▶ | builder => sub { API::Docker::API::Exec->new(client => $_[0]) }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_exec: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 52 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | has distribution => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | is => 'lazy', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 25 | ▶ | builder => sub { API::Docker::API::Distribution->new(client => $_[0]) }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_distribution: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 52 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | has secrets => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | is => 'lazy', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 11 | ▶ | builder => sub { API::Docker::API::Secrets->new(client => $_[0]) }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_secrets: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 52 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | has configs => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | is => 'lazy', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 19 | ▶ | builder => sub { API::Docker::API::Configs->new(client => $_[0]) }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_configs: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 52 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | has plugins => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | is => 'lazy', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 71 | ▶ | builder => sub { API::Docker::API::Plugins->new(client => $_[0]) }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_plugins: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 52 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 9 | ▶ | sub negotiate_version { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
negotiate_version: called CC=14 SCAR=26.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 9 | my ($self, %opts) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | 9 | ▶ | return if $self->_version_negotiated; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | 9 | ▶ | return if defined $self->api_version; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 9 | $log->debug("Auto-negotiating API version"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | my $version_info = $self->_request('GET', '/version', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | exists $opts{read_timeout} ? ( read_timeout => $opts{read_timeout} ) : (), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 9 | ▶ | exists $opts{connect_timeout} ? ( connect_timeout => $opts{connect_timeout} ) : (), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | # The ApiVersion is put straight into every later request path (/v1.44/...), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | # so it has to be a JSON object carrying one of the form N.N -- nothing else | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | # can be trusted there. Three ways a body fails that, each measured against a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | # fake daemon: a non-object body reached strict refs ('garbage' died with | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | # "Can't use string as a HASH ref", [1] with "Not a HASH reference"); an | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | # object with no ApiVersion set _version_negotiated and then sent every | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | # request unversioned; and an ApiVersion copied verbatim let 'v1.44/../x' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | # become "GET /vv1.44/../x/info". One croak, naming the endpoint and the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | # shape, covers all of them. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | 9 | my $got; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | 9 | ▶ | if (!defined $version_info) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | 1 | $got = 'nothing'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | elsif (ref $version_info ne 'HASH') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | 2 | ▶ | $got = ref $version_info ? 'a ' . ref($version_info) . ' reference' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | : "the non-object body '" . $version_info . "'"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | elsif (!defined $version_info->{ApiVersion}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | 1 | $got = 'an object with no ApiVersion field'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | 5 | my $v = $version_info->{ApiVersion}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | 5 | ▶ | $got = 'an ApiVersion of ' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | . (ref $v ? 'a ' . ref($v) . ' reference' : "'" . $v . "'"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | croak __PACKAGE__ . '->negotiate_version: GET /version must answer with a ' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | . 'JSON object carrying an ApiVersion of the form N.N (e.g. "1.44"); got ' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | . $got | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | unless ref $version_info eq 'HASH' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | && defined $version_info->{ApiVersion} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | && !ref $version_info->{ApiVersion} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 9 | ▶ | && $version_info->{ApiVersion} =~ /^\d+\.\d+$/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition88%8/9
ref $version_info eq "HASH" and defined $version_info->{"ApiVersion"} and not ref $version_info->{"ApiVersion"} and $version_info->{"ApiVersion"} =~ /^\d+\.\d+$/
ref $version_info eq "HASH" and defined $version_info->{"ApiVersion"} and not ref $version_info->{"ApiVersion"}
ref $version_info eq "HASH" and defined $version_info->{"ApiVersion"}
MC/DC75%3/4
ref $version_info eq "HASH" and defined $version_info->{"ApiVersion"} and not ref $version_info->{"ApiVersion"} and $version_info->{"ApiVersion"} =~ /^\d+\.\d+$/
ref $version_info eq "HASH"
defined $version_info->{"ApiVersion"}
not ref $version_info->{"ApiVersion"}
$version_info->{"ApiVersion"} =~ /^\d+\.\d+$/
Truth table80%4/5
A and B and not(C) and D
A= ref $version_info eq "HASH"B= defined $version_info->{"ApiVersion"}C= not ref $version_info->{"ApiVersion"}D= $version_info->{"ApiVersion"} =~ /^\d+\.\d+$/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | 4 | $self->_set_api_version($version_info->{ApiVersion}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | 4 | $log->debugf("Negotiated API version: %s", $version_info->{ApiVersion}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | 4 | $self->_version_negotiated(1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | 325 | ▶ | around _request => sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=6 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | 325 | my ($orig, $self, $method, $path, %opts) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | # Auto-negotiate before any versioned request, but not for /version itself. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | # The triggering request's own bounds are handed to it: the negotiation is a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | # pre-flight the caller never wrote, and a caller who asked for a bound and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | # then hung in GET /version has been told something untrue (karr k72). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 325 | ▶ | if ($path ne '/version' && !defined $self->api_version && !$self->_version_negotiated) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
$path ne "/version" and not defined $self->api_version and not $self->_version_negotiated
$path ne "/version" and not defined $self->api_version
MC/DC66%2/3
$path ne "/version" and not defined $self->api_version and not $self->_version_negotiated
$path ne "/version"
not defined $self->api_version
not $self->_version_negotiated
Truth table75%3/4
A and not(B) and not(C)
A= $path ne "/version"B= not defined $self->api_versionC= not $self->_version_negotiated
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | $self->negotiate_version( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | exists $opts{read_timeout} ? ( read_timeout => $opts{read_timeout} ) : (), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | 3 | ▶ | exists $opts{connect_timeout} ? ( connect_timeout => $opts{connect_timeout} ) : (), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | 325 | return $self->$orig($method, $path, %opts); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | 52 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | 52 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||