| 1 | package Docker::Registry::Call::Repositories; | ||||||||||||||
| 2 | 5 | ▶ | use Moo; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 3 | 5 | ▶ | use Types::Standard qw/Int Str/; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 4 | 5 | has n => (is => 'ro', isa => Int); | |||||||||||||
| 5 | 5 | has last => (is => 'ro', isa => Str); | |||||||||||||
| 6 | |||||||||||||||
| 7 | package Docker::Registry::Result::Repositories; | ||||||||||||||
| 8 | 5 | ▶ | use Moo; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 9 | 5 | ▶ | use Types::Standard qw/ArrayRef Str/; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 10 | 5 | has repositories => (is => 'ro', isa => ArrayRef[Str]); | |||||||||||||
| 11 | 5 | has last => (is => 'ro', isa => Str); | |||||||||||||
| 12 | |||||||||||||||
| 13 | package Docker::Registry::Call::RepositoryTags; | ||||||||||||||
| 14 | 5 | ▶ | use Moo; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 15 | 5 | ▶ | use Types::Standard qw/Int Str/; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 16 | 5 | has repository => (is => 'ro', isa => Str, required => 1); | |||||||||||||
| 17 | 5 | has n => (is => 'ro', isa => Int); | |||||||||||||
| 18 | 5 | has last => (is => 'ro', isa => Str); | |||||||||||||
| 19 | |||||||||||||||
| 20 | package Docker::Registry::Result::RepositoryTags; | ||||||||||||||
| 21 | 5 | ▶ | use Moo; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 22 | 5 | ▶ | use Types::Standard qw/ArrayRef Str/; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 23 | 5 | has name => (is => 'ro', isa => Str, required => 1); | |||||||||||||
| 24 | 5 | has tags => (is => 'ro', isa => ArrayRef[Str], required => 1); | |||||||||||||
| 25 | 5 | has last => (is => 'ro', isa => Str); | |||||||||||||
| 26 | |||||||||||||||
| 27 | package Docker::Registry::V2; | ||||||||||||||
| 28 | 5 | ▶ | use Moo; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 29 | 5 | ▶ | use Docker::Registry::Types qw(DockerRegistryURI); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 30 | 5 | ▶ | use Types::Standard qw/Str ConsumerOf InstanceOf/; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 31 | |||||||||||||||
| 32 | 5 | has url => (is => 'ro', coerce => 1, isa => DockerRegistryURI, required => 1); | |||||||||||||
| 33 | 5 | has api_base => (is => 'ro', default => 'v2'); | |||||||||||||
| 34 | |||||||||||||||
| 35 | 1 | ▶ | has caller => (is => 'ro', isa => ConsumerOf['Docker::Registry::IO'], default => sub { | ||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||
| 36 | 1 | require Docker::Registry::IO::Simple; | |||||||||||||
| 37 | 1 | Docker::Registry::IO::Simple->new; | |||||||||||||
| 38 | 5 | }); | |||||||||||||
| 39 | 5 | has auth => (is => 'ro', isa => ConsumerOf['Docker::Registry::Auth'], lazy => 1, builder => 'build_auth' ); | |||||||||||||
| 40 | 5 | ▶ | has request_builder => (is => 'ro', isa => InstanceOf['Docker::Registry::RequestBuilder'], lazy => 1, default => sub { | ||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||
| 41 | 5 | my $self = shift; | |||||||||||||
| 42 | 5 | require Docker::Registry::RequestBuilder; | |||||||||||||
| 43 | 5 | Docker::Registry::RequestBuilder->new(url => $self->url, api_base => $self->api_base); | |||||||||||||
| 44 | 5 | }); | |||||||||||||
| 45 | |||||||||||||||
| 46 | 1 | ▶ | sub build_auth { | ||||||||||||
|
Subroutine
build_auth: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||
| 47 | 1 | require Docker::Registry::Auth::None; | |||||||||||||
| 48 | 1 | Docker::Registry::Auth::None->new; | |||||||||||||
| 49 | }; | ||||||||||||||
| 50 | |||||||||||||||
| 51 | 5 | ▶ | use JSON::MaybeXS qw//; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 52 | 7 | ▶ | has _json => (is => 'ro', default => sub { | ||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||
| 53 | 7 | JSON::MaybeXS->new; | |||||||||||||
| 54 | 5 | }); | |||||||||||||
| 55 | 15 | ▶ | sub process_json_response { | ||||||||||||
|
Subroutine
process_json_response: called CC=4 SCAR=14.5
Pod
undocumented
| |||||||||||||||
| 56 | 15 | my ($self, $response) = @_; | |||||||||||||
| 57 | 15 | ▶ | if ($response->status == 200) { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 58 | 12 | my $struct = eval { | |||||||||||||
| 59 | 12 | $self->_json->decode($response->content); | |||||||||||||
| 60 | }; | ||||||||||||||
| 61 | 12 | ▶ | if ($@) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 62 | 0 | Docker::Registry::Exception->throw({ message => $@ }); | |||||||||||||
| 63 | } | ||||||||||||||
| 64 | 12 | my $pagination = $self->_parse_pagination_header($response); | |||||||||||||
| 65 | 12 | return { %$struct, %$pagination }; | |||||||||||||
| 66 | } elsif ($response->status == 401) { | ||||||||||||||
| 67 | 0 | Docker::Registry::Exception::Unauthorized->throw({ | |||||||||||||
| 68 | message => $response->content, | ||||||||||||||
| 69 | status => $response->status, | ||||||||||||||
| 70 | }); | ||||||||||||||
| 71 | } else { | ||||||||||||||
| 72 | 3 | Docker::Registry::Exception::HTTP->throw({ | |||||||||||||
| 73 | message => $response->content, | ||||||||||||||
| 74 | status => $response->status | ||||||||||||||
| 75 | }); | ||||||||||||||
| 76 | } | ||||||||||||||
| 77 | } | ||||||||||||||
| 78 | |||||||||||||||
| 79 | 5 | ▶ | use URI; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 80 | 12 | ▶ | sub _parse_pagination_header { | ||||||||||||
|
Subroutine
_parse_pagination_header: called CC=2 SCAR=6.9
| |||||||||||||||
| 81 | 12 | my ($self, $response) = @_; | |||||||||||||
| 82 | |||||||||||||||
| 83 | 12 | ▶ | return {} unless($response->headers->{link}); | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 84 | |||||||||||||||
| 85 | 1 | my ($link) = ($response->headers->{link} =~ /<([^>]*)>/); | |||||||||||||
| 86 | 1 | my $url = URI->new($link); | |||||||||||||
| 87 | 1 | my %url_params = $url->query_form; | |||||||||||||
| 88 | |||||||||||||||
| 89 | 1 | return {last => $url_params{last}}; | |||||||||||||
| 90 | } | ||||||||||||||
| 91 | |||||||||||||||
| 92 | 7 | ▶ | sub repositories { | ||||||||||||
|
Subroutine
repositories: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||
| 93 | 7 | my $self = shift; | |||||||||||||
| 94 | # Inputs n, last | ||||||||||||||
| 95 | # | ||||||||||||||
| 96 | # GET /v2/_catalog | ||||||||||||||
| 97 | # | ||||||||||||||
| 98 | # Header next | ||||||||||||||
| 99 | # { | ||||||||||||||
| 100 | # "repositories": [ | ||||||||||||||
| 101 | # <name>, | ||||||||||||||
| 102 | # ... | ||||||||||||||
| 103 | # ] | ||||||||||||||
| 104 | # } | ||||||||||||||
| 105 | 7 | my $call_class = 'Docker::Registry::Call::Repositories'; | |||||||||||||
| 106 | 7 | my $call = $call_class->new({ @_ }); | |||||||||||||
| 107 | |||||||||||||||
| 108 | 7 | my $request = $self->request_builder->build_request($call); | |||||||||||||
| 109 | |||||||||||||||
| 110 | 7 | my $scope = 'registry:catalog:*'; | |||||||||||||
| 111 | 7 | $request = $self->auth->authorize($request, $scope); | |||||||||||||
| 112 | 7 | my $response = $self->caller->send_request($request); | |||||||||||||
| 113 | 7 | my $result_class = 'Docker::Registry::Result::Repositories'; | |||||||||||||
| 114 | 7 | my $result = $result_class->new($self->process_json_response($response)); | |||||||||||||
| 115 | 4 | return $result; | |||||||||||||
| 116 | } | ||||||||||||||
| 117 | |||||||||||||||
| 118 | 8 | ▶ | sub repository_tags { | ||||||||||||
|
Subroutine
repository_tags: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||
| 119 | 8 | my $self = shift; | |||||||||||||
| 120 | |||||||||||||||
| 121 | # n, last | ||||||||||||||
| 122 | #GET /v2/$repository/tags/list | ||||||||||||||
| 123 | # | ||||||||||||||
| 124 | #{"name":"$repository","tags":["2017.09","latest"]} | ||||||||||||||
| 125 | 8 | my $call_class = 'Docker::Registry::Call::RepositoryTags'; | |||||||||||||
| 126 | 8 | my $call = $call_class->new({ @_ }); | |||||||||||||
| 127 | |||||||||||||||
| 128 | 8 | my $request = $self->request_builder->build_request($call); | |||||||||||||
| 129 | |||||||||||||||
| 130 | 8 | my $scope = sprintf 'repository:%s:%s', $call->repository, 'pull'; | |||||||||||||
| 131 | 8 | $request = $self->auth->authorize($request, $scope); | |||||||||||||
| 132 | 8 | my $response = $self->caller->send_request($request); | |||||||||||||
| 133 | 8 | my $result_class = 'Docker::Registry::Result::RepositoryTags'; | |||||||||||||
| 134 | 8 | my $result = $result_class->new($self->process_json_response($response)); | |||||||||||||
| 135 | 8 | return $result; | |||||||||||||
| 136 | } | ||||||||||||||
| 137 | |||||||||||||||
| 138 | 0 | ▶ | sub is_registry { | ||||||||||||
|
Subroutine
is_registry: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||
| 139 | 0 | my $self = shift; | |||||||||||||
| 140 | # GET /v2 | ||||||||||||||
| 141 | # if (200 or 401) and (header.Docker-Distribution-API-Version eq 'registry/2.0') | ||||||||||||||
| 142 | } | ||||||||||||||
| 143 | |||||||||||||||
| 144 | # Actionable failure conditions, covered in detail in their relevant sections, | ||||||||||||||
| 145 | # are reported as part of 4xx responses, in a json response body. One or more | ||||||||||||||
| 146 | # errors will be returned in the following format: | ||||||||||||||
| 147 | # { | ||||||||||||||
| 148 | # "errors:" [{ | ||||||||||||||
| 149 | # "code": <error identifier>, | ||||||||||||||
| 150 | # "message": <message describing condition>, | ||||||||||||||
| 151 | # "detail": <unstructured> | ||||||||||||||
| 152 | # }, | ||||||||||||||
| 153 | # ... | ||||||||||||||
| 154 | # ] | ||||||||||||||
| 155 | # } | ||||||||||||||
| 156 | |||||||||||||||
| 157 | # ECR: returns 401 error body as "Not Authorized" | ||||||||||||||
| 158 | 0 | ▶ | sub process_error { | ||||||||||||
|
Subroutine
process_error: not called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||
| 159 | |||||||||||||||
| 160 | } | ||||||||||||||
| 161 | |||||||||||||||
| 162 | 0 | ▶ | sub request { | ||||||||||||
|
Subroutine
request: not called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||
| 163 | |||||||||||||||
| 164 | } | ||||||||||||||
| 165 | 5 | 1; | |||||||||||||