Docker-Registry
view release on metacpan or search on metacpan
lib/Docker/Registry/V2.pm view on Meta::CPAN
package Docker::Registry::Call::Repositories;
use Moo;
use Types::Standard qw/Int Str/;
has n => (is => 'ro', isa => Int);
has last => (is => 'ro', isa => Str);
package Docker::Registry::Result::Repositories;
use Moo;
use Types::Standard qw/ArrayRef Str/;
has repositories => (is => 'ro', isa => ArrayRef[Str]);
has last => (is => 'ro', isa => Str);
package Docker::Registry::Call::RepositoryTags;
use Moo;
use Types::Standard qw/Int Str/;
has repository => (is => 'ro', isa => Str, required => 1);
has n => (is => 'ro', isa => Int);
has last => (is => 'ro', isa => Str);
package Docker::Registry::Result::RepositoryTags;
use Moo;
use Types::Standard qw/ArrayRef Str/;
has name => (is => 'ro', isa => Str, required => 1);
has tags => (is => 'ro', isa => ArrayRef[Str], required => 1);
has last => (is => 'ro', isa => Str);
package Docker::Registry::V2;
use Moo;
use Docker::Registry::Types qw(DockerRegistryURI);
use Types::Standard qw/Str ConsumerOf InstanceOf/;
has url => (is => 'ro', coerce => 1, isa => DockerRegistryURI, required => 1);
has api_base => (is => 'ro', default => 'v2');
has caller => (is => 'ro', isa => ConsumerOf['Docker::Registry::IO'], default => sub {
require Docker::Registry::IO::Simple;
Docker::Registry::IO::Simple->new;
});
has auth => (is => 'ro', isa => ConsumerOf['Docker::Registry::Auth'], lazy => 1, builder => 'build_auth' );
has request_builder => (is => 'ro', isa => InstanceOf['Docker::Registry::RequestBuilder'], lazy => 1, default => sub {
my $self = shift;
require Docker::Registry::RequestBuilder;
Docker::Registry::RequestBuilder->new(url => $self->url, api_base => $self->api_base);
});
sub build_auth {
require Docker::Registry::Auth::None;
Docker::Registry::Auth::None->new;
};
use JSON::MaybeXS qw//;
has _json => (is => 'ro', default => sub {
JSON::MaybeXS->new;
});
sub process_json_response {
my ($self, $response) = @_;
if ($response->status == 200) {
my $struct = eval {
$self->_json->decode($response->content);
};
if ($@) {
Docker::Registry::Exception->throw({ message => $@ });
}
my $pagination = $self->_parse_pagination_header($response);
return { %$struct, %$pagination };
} elsif ($response->status == 401) {
Docker::Registry::Exception::Unauthorized->throw({
message => $response->content,
status => $response->status,
});
} else {
Docker::Registry::Exception::HTTP->throw({
message => $response->content,
status => $response->status
});
}
}
use URI;
sub _parse_pagination_header {
my ($self, $response) = @_;
return {} unless($response->headers->{link});
( run in 3.153 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )