line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Docker::Registry::Auth::Gitlab; |
2
|
1
|
|
|
1
|
|
27732
|
use Moo; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
7
|
|
3
|
1
|
|
|
1
|
|
362
|
use Types::Standard qw/Str/; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
19
|
|
4
|
1
|
|
|
1
|
|
604
|
use namespace::autoclean; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
10
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
# ABSTRACT: Authentication module for gitlab registry |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
with 'Docker::Registry::Auth'; |
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
537
|
use Docker::Registry::Types qw(DockerRegistryURI); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
11
|
|
11
|
1
|
|
|
1
|
|
1063
|
use HTTP::Tiny; |
|
1
|
|
|
|
|
51929
|
|
|
1
|
|
|
|
|
53
|
|
12
|
1
|
|
|
1
|
|
485
|
use JSON::MaybeXS qw(decode_json); |
|
1
|
|
|
|
|
5750
|
|
|
1
|
|
|
|
|
471
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
has username => ( |
15
|
|
|
|
|
|
|
is => 'ro', |
16
|
|
|
|
|
|
|
isa => Str, |
17
|
|
|
|
|
|
|
required => 1, |
18
|
|
|
|
|
|
|
); |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
has access_token => ( |
21
|
|
|
|
|
|
|
is => 'ro', |
22
|
|
|
|
|
|
|
isa => Str, |
23
|
|
|
|
|
|
|
required => 1, |
24
|
|
|
|
|
|
|
); |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
has jwt => ( |
27
|
|
|
|
|
|
|
is => 'ro', |
28
|
|
|
|
|
|
|
isa => DockerRegistryURI, |
29
|
|
|
|
|
|
|
coerce => 1, |
30
|
|
|
|
|
|
|
default => 'https://gitlab.com/jwt/auth', |
31
|
|
|
|
|
|
|
); |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub _build_token_uri { |
34
|
3
|
|
|
3
|
|
9518
|
my ($self, $scope) = @_; |
35
|
|
|
|
|
|
|
|
36
|
3
|
|
|
|
|
20
|
my $uri = $self->jwt->clone; |
37
|
|
|
|
|
|
|
|
38
|
3
|
|
|
|
|
103
|
$uri->query_form({ |
39
|
|
|
|
|
|
|
service => 'container_registry', |
40
|
|
|
|
|
|
|
scope => $scope, |
41
|
|
|
|
|
|
|
client_id => 'docker', |
42
|
|
|
|
|
|
|
offline_token => 'true', |
43
|
|
|
|
|
|
|
}); |
44
|
|
|
|
|
|
|
|
45
|
3
|
|
|
|
|
427
|
$uri->userinfo(join(':', $self->username, $self->access_token)); |
46
|
3
|
|
|
|
|
237
|
return $uri; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub get_bearer_token { |
50
|
2
|
|
|
2
|
1
|
12861
|
my ($self, $scope) = @_; |
51
|
|
|
|
|
|
|
|
52
|
2
|
|
|
|
|
8
|
my $uri = $self->_build_token_uri($scope); |
53
|
|
|
|
|
|
|
|
54
|
2
|
|
|
|
|
14
|
my $ua = HTTP::Tiny->new(); |
55
|
2
|
|
|
|
|
202
|
my $res = $ua->get($uri); |
56
|
|
|
|
|
|
|
|
57
|
2
|
50
|
|
|
|
19
|
if ($res->{success}) { |
58
|
2
|
|
|
|
|
42
|
return decode_json($res->{content})->{token}; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
0
|
|
|
|
|
0
|
die "Unable to get token from gitlab!"; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub authorize { |
65
|
1
|
|
|
1
|
1
|
159
|
my ($self, $request, $scope) = @_; |
66
|
|
|
|
|
|
|
|
67
|
1
|
|
|
|
|
7
|
my $bearer_token = $self->get_bearer_token($scope); |
68
|
|
|
|
|
|
|
|
69
|
1
|
|
|
|
|
15
|
$request->header('Authorization', 'Bearer ' . $bearer_token); |
70
|
1
|
|
|
|
|
112
|
$request->header('Accept', |
71
|
|
|
|
|
|
|
'application/vnd.docker.distribution.manifest.v2+json'); |
72
|
|
|
|
|
|
|
|
73
|
1
|
|
|
|
|
52
|
return $request; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
__END__ |