line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Podman::Client; |
2
|
|
|
|
|
|
|
|
3
|
7
|
|
|
7
|
|
567372
|
use Mojo::Base -base; |
|
7
|
|
|
|
|
28
|
|
|
7
|
|
|
|
|
54
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
our $VERSION = '20220211.0'; |
6
|
|
|
|
|
|
|
our $API_VERSION = '3.0.0'; |
7
|
|
|
|
|
|
|
|
8
|
7
|
|
|
7
|
|
3264
|
use English qw( -no_match_vars ); |
|
7
|
|
|
|
|
2542
|
|
|
7
|
|
|
|
|
54
|
|
9
|
7
|
|
|
7
|
|
2777
|
use Mojo::Asset::File; |
|
7
|
|
|
|
|
39739
|
|
|
7
|
|
|
|
|
54
|
|
10
|
7
|
|
|
7
|
|
580
|
use Mojo::Asset::Memory; |
|
7
|
|
|
|
|
814
|
|
|
7
|
|
|
|
|
42
|
|
11
|
7
|
|
|
7
|
|
570
|
use Mojo::JSON qw(encode_json); |
|
7
|
|
|
|
|
16471
|
|
|
7
|
|
|
|
|
335
|
|
12
|
7
|
|
|
7
|
|
502
|
use Mojo::URL; |
|
7
|
|
|
|
|
6771
|
|
|
7
|
|
|
|
|
46
|
|
13
|
7
|
|
|
7
|
|
649
|
use Mojo::UserAgent; |
|
7
|
|
|
|
|
224413
|
|
|
7
|
|
|
|
|
123
|
|
14
|
7
|
|
|
7
|
|
221
|
use Mojo::Util qw(url_escape); |
|
7
|
|
|
|
|
27
|
|
|
7
|
|
|
|
|
323
|
|
15
|
|
|
|
|
|
|
|
16
|
7
|
|
|
7
|
|
2803
|
use Podman::Exception; |
|
7
|
|
|
|
|
16
|
|
|
7
|
|
|
|
|
5364
|
|
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
|
|
82432
|
Mojo::Util::monkey_patch(__PACKAGE__, $name, sub { return shift->_request(uc $name, @_); }); |
|
|
|
|
24
|
|
|
|
|
|
|
|
24
|
|
|
|
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub _base_url { |
28
|
24
|
|
|
24
|
|
96
|
my $self = shift; |
29
|
|
|
|
|
|
|
|
30
|
24
|
100
|
|
|
|
180
|
my $base_url = Mojo::URL->new($self->_connection_url->scheme eq 'http+unix' ? 'http://d/' : $self->connection_url); |
31
|
|
|
|
|
|
|
|
32
|
24
|
|
|
|
|
8112
|
my $tx; |
33
|
24
|
|
|
|
|
139
|
my $url = $base_url->path('_ping'); |
34
|
24
|
|
|
|
|
4363
|
for (0 .. 3) { |
35
|
35
|
|
|
|
|
829
|
$tx = $self->_ua->get($url); |
36
|
35
|
100
|
|
|
|
404002
|
last if $tx->res->is_success; |
37
|
14
|
|
|
|
|
14003430
|
sleep 1; |
38
|
|
|
|
|
|
|
} |
39
|
24
|
100
|
|
|
|
8572
|
Podman::Exception->throw(900) unless $tx->res->is_success; |
40
|
|
|
|
|
|
|
|
41
|
21
|
|
|
|
|
468
|
$tx = $self->_ua->get($base_url->path('version')); |
42
|
21
|
|
|
|
|
263872
|
my $version = $tx->res->json->{Components}->[0]->{Details}->{APIVersion}; |
43
|
|
|
|
|
|
|
|
44
|
21
|
50
|
|
|
|
14628
|
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
|
284
|
|
|
284
|
|
7694
|
sub _connection_url { return Mojo::URL->new(shift->connection_url); } |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub _request { |
52
|
24
|
|
|
24
|
|
197
|
my ($self, $method, $path, %opts) = @_; |
53
|
|
|
|
|
|
|
|
54
|
24
|
|
|
|
|
247
|
my $url = $self->_base_url->path($path); |
55
|
21
|
100
|
|
|
|
6000
|
$url->query($opts{parameters}) if $opts{parameters}; |
56
|
|
|
|
|
|
|
|
57
|
21
|
|
|
|
|
1128
|
my $tx = $self->_ua->build_tx($method => $url, $opts{headers}); |
58
|
21
|
100
|
|
|
|
6293
|
if ($opts{data}) { |
59
|
|
|
|
|
|
|
my $asset |
60
|
|
|
|
|
|
|
= ref $opts{data} eq 'Mojo::File' |
61
|
|
|
|
|
|
|
? Mojo::Asset::File->new(path => $opts{data}) |
62
|
2
|
100
|
|
|
|
122
|
: Mojo::Asset::Memory->new->add_chunk(encode_json($opts{data})); |
63
|
2
|
|
|
|
|
176
|
$tx->req->content->asset($asset); |
64
|
|
|
|
|
|
|
} |
65
|
21
|
|
|
|
|
489
|
$tx = $self->_ua->start($tx); |
66
|
|
|
|
|
|
|
|
67
|
21
|
50
|
|
|
|
253061
|
Podman::Exception->throw($tx->res->code) unless $tx->res->is_success; |
68
|
|
|
|
|
|
|
|
69
|
21
|
|
|
|
|
7183
|
return $tx->res; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub _ua { |
73
|
98
|
|
|
98
|
|
284
|
my $self = shift; |
74
|
|
|
|
|
|
|
|
75
|
98
|
|
|
|
|
1001
|
my $ua = Mojo::UserAgent->new(insecure => 1); |
76
|
98
|
|
|
|
|
1519
|
$ua->transactor->name("Podman/$VERSION"); |
77
|
98
|
100
|
|
|
|
3332
|
if ($self->_connection_url->scheme eq 'http+unix') { |
78
|
81
|
|
|
|
|
7950
|
$ua->proxy->http($self->_connection_url->scheme . '://' . url_escape($self->_connection_url->path)); |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
98
|
|
|
|
|
25129
|
return $ua; |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
1; |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
__END__ |