line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Podman::Client; |
2
|
|
|
|
|
|
|
|
3
|
7
|
|
|
7
|
|
507258
|
use Mojo::Base -base; |
|
7
|
|
|
|
|
23
|
|
|
7
|
|
|
|
|
45
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
our $VERSION = '20220210.0'; |
6
|
|
|
|
|
|
|
our $API_VERSION = '3.0.0'; |
7
|
|
|
|
|
|
|
|
8
|
7
|
|
|
7
|
|
3451
|
use English qw( -no_match_vars ); |
|
7
|
|
|
|
|
2433
|
|
|
7
|
|
|
|
|
45
|
|
9
|
7
|
|
|
7
|
|
2540
|
use Mojo::Asset::File; |
|
7
|
|
|
|
|
32366
|
|
|
7
|
|
|
|
|
54
|
|
10
|
7
|
|
|
7
|
|
577
|
use Mojo::Asset::Memory; |
|
7
|
|
|
|
|
824
|
|
|
7
|
|
|
|
|
38
|
|
11
|
7
|
|
|
7
|
|
641
|
use Mojo::JSON qw(encode_json); |
|
7
|
|
|
|
|
15376
|
|
|
7
|
|
|
|
|
322
|
|
12
|
7
|
|
|
7
|
|
465
|
use Mojo::URL; |
|
7
|
|
|
|
|
6743
|
|
|
7
|
|
|
|
|
44
|
|
13
|
7
|
|
|
7
|
|
737
|
use Mojo::UserAgent; |
|
7
|
|
|
|
|
209918
|
|
|
7
|
|
|
|
|
105
|
|
14
|
7
|
|
|
7
|
|
245
|
use Mojo::Util qw(url_escape); |
|
7
|
|
|
|
|
16
|
|
|
7
|
|
|
|
|
304
|
|
15
|
|
|
|
|
|
|
|
16
|
7
|
|
|
7
|
|
2690
|
use Podman::Exception; |
|
7
|
|
|
|
|
15
|
|
|
7
|
|
|
|
|
5034
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
has 'connection_url' => sub { |
19
|
|
|
|
|
|
|
return $ENV{PODMAN_CONNECTION_URL} |
20
|
|
|
|
|
|
|
|| ($UID != 0 ? "http+unix:///run/user/$UID/podman/podman.sock" : 'http+unix:///run/podman/podman.sock'); |
21
|
|
|
|
|
|
|
}; |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
for my $name (qw(delete get post)) { |
24
|
24
|
|
|
24
|
|
95439
|
Mojo::Util::monkey_patch(__PACKAGE__, $name, sub { return shift->_request(uc $name, @_); }); |
|
|
|
|
24
|
|
|
|
|
|
|
|
24
|
|
|
|
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub _base_url { |
28
|
24
|
|
|
24
|
|
92
|
my $self = shift; |
29
|
|
|
|
|
|
|
|
30
|
24
|
100
|
|
|
|
176
|
my $base_url = Mojo::URL->new($self->_connection_url->scheme eq 'http+unix' ? 'http://d/' : $self->connection_url); |
31
|
|
|
|
|
|
|
|
32
|
24
|
|
|
|
|
7240
|
my $tx; |
33
|
24
|
|
|
|
|
130
|
my $url = $base_url->path('_ping'); |
34
|
24
|
|
|
|
|
4320
|
for (0 .. 3) { |
35
|
33
|
|
|
|
|
452
|
$tx = $self->_ua->get($url); |
36
|
33
|
100
|
|
|
|
387471
|
last if $tx->res->is_success; |
37
|
12
|
|
|
|
|
12002708
|
sleep 1; |
38
|
|
|
|
|
|
|
} |
39
|
24
|
100
|
|
|
|
8669
|
Podman::Exception->throw(900) unless $tx->res->is_success; |
40
|
|
|
|
|
|
|
|
41
|
21
|
|
|
|
|
509
|
$tx = $self->_ua->get($base_url->path('version')); |
42
|
21
|
|
|
|
|
273227
|
my $version = $tx->res->json->{Components}->[0]->{Details}->{APIVersion}; |
43
|
|
|
|
|
|
|
|
44
|
21
|
50
|
|
|
|
14640
|
say {*STDERR} "Potential insufficient supported Podman service API version." if $version ne $API_VERSION; |
|
0
|
|
|
|
|
0
|
|
45
|
|
|
|
|
|
|
|
46
|
21
|
|
|
|
|
204
|
return $base_url->path('v' . $version . '/libpod/'); |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
280
|
|
|
280
|
|
7321
|
sub _connection_url { return Mojo::URL->new(shift->connection_url); } |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub _request { |
52
|
24
|
|
|
24
|
|
249
|
my ($self, $method, $path, %opts) = @_; |
53
|
|
|
|
|
|
|
|
54
|
24
|
|
|
|
|
243
|
my $url = $self->_base_url->path($path); |
55
|
21
|
100
|
|
|
|
6034
|
$url->query($opts{parameters}) if $opts{parameters}; |
56
|
|
|
|
|
|
|
|
57
|
21
|
|
|
|
|
986
|
my $tx = $self->_ua->build_tx($method => $url, $opts{headers}); |
58
|
21
|
100
|
|
|
|
5842
|
if ($opts{data}) { |
59
|
|
|
|
|
|
|
my $asset |
60
|
|
|
|
|
|
|
= ref $opts{data} eq 'Mojo::File' |
61
|
|
|
|
|
|
|
? Mojo::Asset::File->new(path => $opts{data}) |
62
|
2
|
100
|
|
|
|
113
|
: Mojo::Asset::Memory->new->add_chunk(encode_json($opts{data})); |
63
|
2
|
|
|
|
|
182
|
$tx->req->content->asset($asset); |
64
|
|
|
|
|
|
|
} |
65
|
21
|
|
|
|
|
492
|
$tx = $self->_ua->start($tx); |
66
|
|
|
|
|
|
|
|
67
|
21
|
50
|
|
|
|
255485
|
Podman::Exception->throw($tx->res->code) unless $tx->res->is_success; |
68
|
|
|
|
|
|
|
|
69
|
21
|
|
|
|
|
7485
|
return $tx->res; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub _ua { |
73
|
96
|
|
|
96
|
|
287
|
my $self = shift; |
74
|
|
|
|
|
|
|
|
75
|
96
|
|
|
|
|
931
|
my $ua = Mojo::UserAgent->new(insecure => 1); |
76
|
96
|
|
|
|
|
1321
|
$ua->transactor->name("Podman/$VERSION"); |
77
|
96
|
100
|
|
|
|
3270
|
if ($self->_connection_url->scheme eq 'http+unix') { |
78
|
80
|
|
|
|
|
7390
|
$ua->proxy->http($self->_connection_url->scheme . '://' . url_escape($self->_connection_url->path)); |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
96
|
|
|
|
|
23412
|
return $ua; |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
1; |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
__END__ |