| 1 | package API::Docker::API::Distribution; | ||||||||||||||||||||
| 2 | # ABSTRACT: Docker Engine Distribution 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::RegistryAuth', 'API::Docker::Role::Using'; | |||||||||||||||||||
| 6 | 52 | ▶ | use Carp qw( croak ); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | 52 | ▶ | use namespace::clean; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | |||||||||||||||||||||
| 9 | |||||||||||||||||||||
| 10 | 52 | has client => ( | |||||||||||||||||||
| 11 | is => 'ro', | ||||||||||||||||||||
| 12 | required => 1, | ||||||||||||||||||||
| 13 | weak_ref => 1, | ||||||||||||||||||||
| 14 | ); | ||||||||||||||||||||
| 15 | |||||||||||||||||||||
| 16 | |||||||||||||||||||||
| 17 | # Only when the caller asked for it, like the plugin family and unlike | ||||||||||||||||||||
| 18 | # /images/{name}/push. The distribution router decodes the header and | ||||||||||||||||||||
| 19 | # discards the error -- the same "ignore invalid AuthConfig" pattern the | ||||||||||||||||||||
| 20 | # plugin routes use -- so a public image is looked up anonymously, with no | ||||||||||||||||||||
| 21 | # header at all. Not verifiable on this machine: Podman serves no route here. | ||||||||||||||||||||
| 22 | 22 | ▶ | sub _auth_headers { | ||||||||||||||||||
|
Subroutine
_auth_headers: called CC=2 SCAR=6.9
| |||||||||||||||||||||
| 23 | 22 | my ($self, $opts) = @_; | |||||||||||||||||||
| 24 | 22 | ▶ | return () unless defined $opts->{auth}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 25 | 1 | return (headers => { 'X-Registry-Auth' => $self->_registry_auth_header($opts->{auth}) }); | |||||||||||||||||||
| 26 | } | ||||||||||||||||||||
| 27 | |||||||||||||||||||||
| 28 | 23 | ▶ | sub inspect { | ||||||||||||||||||
|
Subroutine
inspect: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||
| 29 | 23 | my ($self, $name, %opts) = @_; | |||||||||||||||||||
| 30 | 23 | ▶ | croak __PACKAGE__ . '->inspect requires an image reference' unless $name; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 31 | |||||||||||||||||||||
| 32 | return $self->client->get("/distribution/$name/json", | ||||||||||||||||||||
| 33 | $self->_auth_headers(\%opts), | ||||||||||||||||||||
| 34 | 22 | ▶ | %{ $self->_request_options }, | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 35 | 22 | (exists $opts{response} ? (response => $opts{response}) : ())); | |||||||||||||||||||
| 36 | } | ||||||||||||||||||||
| 37 | |||||||||||||||||||||
| 38 | |||||||||||||||||||||
| 39 | # The engine's own "I have no such route" 404 versus the registry's "I do not | ||||||||||||||||||||
| 40 | # have that reference" 404. Measured on Podman 5.4.2 (API 1.41), which has no | ||||||||||||||||||||
| 41 | # route: 'Path /v1.41/distribution/nginx:latest/json is not supported'. That | ||||||||||||||||||||
| 42 | # '1.41' is the negotiated API version echoed back from the request path, not | ||||||||||||||||||||
| 43 | # a fixed string -- it moves with negotiation, which is why the regex below | ||||||||||||||||||||
| 44 | # matches on wording rather than on a version number. | ||||||||||||||||||||
| 45 | # Docker's own unknown-route answer is 'page not found'. Anything not | ||||||||||||||||||||
| 46 | # recognised as the engine talking about itself is taken as the registry's | ||||||||||||||||||||
| 47 | # answer, so an unfamiliar wording degrades to plain "404 means no" rather | ||||||||||||||||||||
| 48 | # than to a wrong croak. | ||||||||||||||||||||
| 49 | 52 | my $NO_SUCH_ROUTE = qr/\bis not supported\b|\bpage not found\b/i; | |||||||||||||||||||
| 50 | |||||||||||||||||||||
| 51 | 13 | ▶ | sub exists { | ||||||||||||||||||
|
Subroutine
exists: called CC=7 SCAR=19.5
Pod
documented
| |||||||||||||||||||||
| 52 | 13 | my ($self, $name, %opts) = @_; | |||||||||||||||||||
| 53 | 13 | ▶ | croak __PACKAGE__ . '->exists requires an image reference' unless $name; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 54 | |||||||||||||||||||||
| 55 | # A caller's own response HashRef is reused rather than shadowed, so | ||||||||||||||||||||
| 56 | # passing one through this method still fills it. | ||||||||||||||||||||
| 57 | 13 | ▶ | my $res = ref $opts{response} eq 'HASH' ? $opts{response} : {}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 58 | 13 | my $ok = eval { | |||||||||||||||||||
| 59 | 13 | $self->inspect($name, %opts, response => $res); | |||||||||||||||||||
| 60 | 5 | 1; | |||||||||||||||||||
| 61 | }; | ||||||||||||||||||||
| 62 | 13 | ▶ | return 1 if $ok; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 63 | |||||||||||||||||||||
| 64 | 8 | my $err = $@; | |||||||||||||||||||
| 65 | 8 | ▶ | die $err unless ($res->{status} // 0) == 404; | ||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$res->{"status"} // 0
MC/DC0%0/1
$res->{"status"} // 0
$res->{"status"}
Truth table50%1/2
A
A= $res->{"status"}
| |||||||||||||||||||||
| 66 | 6 | ▶ | croak __PACKAGE__ . '->exists cannot ask this engine: ' . $err | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 67 | if $err =~ $NO_SUCH_ROUTE; | ||||||||||||||||||||
| 68 | 3 | return 0; | |||||||||||||||||||
| 69 | } | ||||||||||||||||||||
| 70 | |||||||||||||||||||||
| 71 | |||||||||||||||||||||
| 72 | |||||||||||||||||||||
| 73 | 52 | 1; | |||||||||||||||||||
| 74 | |||||||||||||||||||||
| 75 | __END__ | ||||||||||||||||||||