line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Google::CloudTasks::Client; |
2
|
|
|
|
|
|
|
|
3
|
4
|
|
|
4
|
|
1895
|
use Mouse; |
|
4
|
|
|
|
|
114206
|
|
|
4
|
|
|
|
|
17
|
|
4
|
4
|
|
|
4
|
|
3943
|
use WWW::Google::Cloud::Auth::ServiceAccount; |
|
4
|
|
|
|
|
3108997
|
|
|
4
|
|
|
|
|
333
|
|
5
|
4
|
|
|
4
|
|
48
|
use LWP::UserAgent; |
|
4
|
|
|
|
|
11
|
|
|
4
|
|
|
|
|
113
|
|
6
|
4
|
|
|
4
|
|
23
|
use HTTP::Request; |
|
4
|
|
|
|
|
9
|
|
|
4
|
|
|
|
|
157
|
|
7
|
4
|
|
|
4
|
|
24
|
use URI; |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
115
|
|
8
|
4
|
|
|
4
|
|
2797
|
use URI::QueryParam; |
|
4
|
|
|
|
|
3696
|
|
|
4
|
|
|
|
|
130
|
|
9
|
4
|
|
|
4
|
|
26
|
use JSON::XS; |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
734
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our $VERSION = "0.01"; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
has base_url => ( |
14
|
|
|
|
|
|
|
is => 'ro', |
15
|
|
|
|
|
|
|
isa => 'Str', |
16
|
|
|
|
|
|
|
default => 'https://cloudtasks.googleapis.com/', |
17
|
|
|
|
|
|
|
); |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
has version => ( |
20
|
|
|
|
|
|
|
is => 'ro', |
21
|
|
|
|
|
|
|
isa => 'Str', |
22
|
|
|
|
|
|
|
default => 'v2', |
23
|
|
|
|
|
|
|
); |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
has credentials_path => ( |
26
|
|
|
|
|
|
|
is => 'ro', |
27
|
|
|
|
|
|
|
isa => 'Str' |
28
|
|
|
|
|
|
|
); |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
has auth => ( |
31
|
|
|
|
|
|
|
is => 'ro', |
32
|
|
|
|
|
|
|
lazy_build => 1, |
33
|
|
|
|
|
|
|
); |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
has ua => ( |
36
|
|
|
|
|
|
|
is => 'ro', |
37
|
|
|
|
|
|
|
lazy => 1, |
38
|
|
|
|
|
|
|
default => sub { LWP::UserAgent->new() }, |
39
|
|
|
|
|
|
|
); |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
has is_debug => ( |
42
|
|
|
|
|
|
|
is => 'ro', |
43
|
|
|
|
|
|
|
isa => 'Bool', |
44
|
|
|
|
|
|
|
default => 0, |
45
|
|
|
|
|
|
|
); |
46
|
|
|
|
|
|
|
|
47
|
4
|
|
|
4
|
|
29
|
no Mouse; |
|
4
|
|
|
|
|
16
|
|
|
4
|
|
|
|
|
43
|
|
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub _build_auth { |
52
|
0
|
|
|
0
|
|
|
my ($self) = @_; |
53
|
|
|
|
|
|
|
|
54
|
0
|
0
|
|
|
|
|
if (!$self->credentials_path) { |
55
|
0
|
|
|
|
|
|
die "attribute 'credentials_path' is required"; |
56
|
|
|
|
|
|
|
} |
57
|
0
|
|
|
|
|
|
my $auth = WWW::Google::Cloud::Auth::ServiceAccount->new( |
58
|
|
|
|
|
|
|
credentials_path => $self->credentials_path, |
59
|
|
|
|
|
|
|
); |
60
|
0
|
|
|
|
|
|
return $auth; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub request { |
64
|
0
|
|
|
0
|
0
|
|
my ($self, $method, $path, $content) = @_; |
65
|
|
|
|
|
|
|
|
66
|
0
|
|
|
|
|
|
my $url = $self->base_url . $self->version . '/' . $path; |
67
|
0
|
|
|
|
|
|
my $req = HTTP::Request->new($method, $url); |
68
|
0
|
|
|
|
|
|
$req->header('Content-Type' => 'application/json; charset=utf8'); |
69
|
0
|
|
|
|
|
|
$req->header('Authorization' => 'Bearer ' . $self->auth->get_token); |
70
|
0
|
0
|
|
|
|
|
if ($content) { |
71
|
0
|
|
|
|
|
|
my $encoded_body = encode_json($content); |
72
|
0
|
|
|
|
|
|
$req->header('Content-Length' => length($encoded_body)); |
73
|
0
|
|
|
|
|
|
$req->content($encoded_body); |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
0
|
0
|
|
|
|
|
if ($self->is_debug) { |
77
|
4
|
|
|
4
|
|
4257
|
use Data::Dumper; |
|
4
|
|
|
|
|
26126
|
|
|
4
|
|
|
|
|
5178
|
|
78
|
0
|
|
|
|
|
|
print "Request : " . Dumper($req); |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
0
|
|
|
|
|
|
my $res = $self->ua->request($req); |
82
|
|
|
|
|
|
|
|
83
|
0
|
0
|
|
|
|
|
if ($res->is_success) { |
84
|
0
|
|
|
|
|
|
return decode_json($res->content); |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
else { |
87
|
0
|
|
|
|
|
|
die "Fail: " . $res->content; |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
sub request_get { |
92
|
0
|
|
|
0
|
0
|
|
my ($self, $path) = @_; |
93
|
0
|
|
|
|
|
|
return $self->request(GET => $path); |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
sub request_post { |
97
|
0
|
|
|
0
|
0
|
|
my ($self, $path, $content) = @_; |
98
|
0
|
|
0
|
|
|
|
$content //= {}; |
99
|
0
|
|
|
|
|
|
return $self->request(POST => $path, $content); |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
sub request_delete { |
103
|
0
|
|
|
0
|
0
|
|
my ($self, $path) = @_; |
104
|
0
|
|
|
|
|
|
return $self->request(DELETE => $path); |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
sub request_patch { |
108
|
0
|
|
|
0
|
0
|
|
my ($self, $path, $content) = @_; |
109
|
0
|
|
|
|
|
|
return $self->request(PATCH => $path, $content); |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
sub _make_query_param { |
113
|
0
|
|
|
0
|
|
|
my ($args, @keys) = @_; |
114
|
|
|
|
|
|
|
|
115
|
0
|
|
|
|
|
|
my $u = URI->new(); |
116
|
0
|
|
|
|
|
|
for (@keys) { |
117
|
0
|
0
|
|
|
|
|
if (defined $args->{$_}) { |
118
|
0
|
|
|
|
|
|
$u->query_param($_ => $args->{$_}); |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
|
122
|
0
|
0
|
|
|
|
|
return $u->query ? '?' . $u->query : ''; |
123
|
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
sub get_location { |
126
|
0
|
|
|
0
|
0
|
|
my ($self, $name) = @_; |
127
|
0
|
|
|
|
|
|
my $path = $name; |
128
|
|
|
|
|
|
|
|
129
|
0
|
|
|
|
|
|
return $self->request_get($path); |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
sub list_locations { |
133
|
0
|
|
|
0
|
0
|
|
my ($self, $name, $opts) = @_; |
134
|
0
|
|
|
|
|
|
my $path = $name . '/locations'; |
135
|
0
|
|
|
|
|
|
$path .= _make_query_param($opts, qw/filter pageSize pageToken/); |
136
|
|
|
|
|
|
|
|
137
|
0
|
|
|
|
|
|
return $self->request_get($path); |
138
|
|
|
|
|
|
|
} |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
sub create_queue { |
141
|
0
|
|
|
0
|
0
|
|
my ($self, $parent, $queue) = @_; |
142
|
0
|
|
|
|
|
|
my $path = $parent . '/queues'; |
143
|
|
|
|
|
|
|
|
144
|
0
|
|
|
|
|
|
return $self->request_post($path, $queue); |
145
|
|
|
|
|
|
|
} |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
sub delete_queue { |
148
|
0
|
|
|
0
|
0
|
|
my ($self, $name) = @_; |
149
|
0
|
|
|
|
|
|
my $path = $name; |
150
|
|
|
|
|
|
|
|
151
|
0
|
|
|
|
|
|
return $self->request_delete($path); |
152
|
|
|
|
|
|
|
} |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
sub get_iam_policy_queue { |
155
|
0
|
|
|
0
|
0
|
|
my ($self, $resource) = @_; |
156
|
0
|
|
|
|
|
|
my $path = $resource . ':getIamPolicy'; |
157
|
|
|
|
|
|
|
|
158
|
0
|
|
|
|
|
|
return $self->request_post($path); |
159
|
|
|
|
|
|
|
} |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
sub set_iam_policy_queue { |
162
|
0
|
|
|
0
|
0
|
|
my ($self, $resource, $policy) = @_; |
163
|
0
|
|
|
|
|
|
my $path = $resource . ':setIamPolicy'; |
164
|
|
|
|
|
|
|
|
165
|
0
|
|
|
|
|
|
return $self->request_post($path, { policy => $policy }); |
166
|
|
|
|
|
|
|
} |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
sub list_queues { |
169
|
0
|
|
|
0
|
0
|
|
my ($self, $parent, $opts) = @_; |
170
|
0
|
|
|
|
|
|
my $path = $parent . '/queues'; |
171
|
0
|
|
|
|
|
|
$path .= _make_query_param($opts, qw/filter pageSize pageToken/); |
172
|
|
|
|
|
|
|
|
173
|
0
|
|
|
|
|
|
return $self->request_get($path); |
174
|
|
|
|
|
|
|
} |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
sub get_queue { |
177
|
0
|
|
|
0
|
0
|
|
my ($self, $name) = @_; |
178
|
0
|
|
|
|
|
|
my $path = $name; |
179
|
|
|
|
|
|
|
|
180
|
0
|
|
|
|
|
|
return $self->request_get($path); |
181
|
|
|
|
|
|
|
} |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
sub patch_queue { |
184
|
0
|
|
|
0
|
0
|
|
my ($self, $name, $queue, $opts) = @_; |
185
|
0
|
|
|
|
|
|
my $path = $name; |
186
|
0
|
|
|
|
|
|
$path .= _make_query_param($opts, qw/updateMask/); |
187
|
|
|
|
|
|
|
|
188
|
0
|
|
|
|
|
|
return $self->request_patch($path, $queue); |
189
|
|
|
|
|
|
|
} |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
sub pause_queue { |
192
|
0
|
|
|
0
|
0
|
|
my ($self, $name) = @_; |
193
|
0
|
|
|
|
|
|
my $path = $name . ':pause'; |
194
|
0
|
|
|
|
|
|
return $self->request_post($path); |
195
|
|
|
|
|
|
|
} |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
sub purge_queue { |
198
|
0
|
|
|
0
|
0
|
|
my ($self, $name) = @_; |
199
|
0
|
|
|
|
|
|
my $path = $name . ':purge'; |
200
|
0
|
|
|
|
|
|
return $self->request_post($path); |
201
|
|
|
|
|
|
|
} |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
sub resume_queue { |
204
|
0
|
|
|
0
|
0
|
|
my ($self, $name) = @_; |
205
|
0
|
|
|
|
|
|
my $path = $name . ':resume'; |
206
|
0
|
|
|
|
|
|
return $self->request_post($path); |
207
|
|
|
|
|
|
|
} |
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
sub test_iam_permissions { |
210
|
0
|
|
|
0
|
0
|
|
my ($self, $resource, $permissions) = @_; |
211
|
0
|
|
|
|
|
|
my $path = $resource . ':testIamPermissions'; |
212
|
0
|
|
|
|
|
|
return $self->request_post($path, { permissions => $permissions }); |
213
|
|
|
|
|
|
|
} |
214
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
sub create_task { |
216
|
0
|
|
|
0
|
0
|
|
my ($self, $parent, $task, $opts) = @_; |
217
|
0
|
|
|
|
|
|
my $path = $parent . '/tasks'; |
218
|
|
|
|
|
|
|
|
219
|
0
|
|
|
|
|
|
my %param = ( |
220
|
|
|
|
|
|
|
task => $task, |
221
|
|
|
|
|
|
|
); |
222
|
0
|
0
|
|
|
|
|
defined $opts->{responseView} and $param{responseView} = $opts->{responseView}; |
223
|
|
|
|
|
|
|
|
224
|
0
|
|
|
|
|
|
return $self->request_post($path, \%param); |
225
|
|
|
|
|
|
|
} |
226
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
sub delete_task { |
228
|
0
|
|
|
0
|
0
|
|
my ($self, $name) = @_; |
229
|
0
|
|
|
|
|
|
my $path = $name; |
230
|
|
|
|
|
|
|
|
231
|
0
|
|
|
|
|
|
return $self->request_delete($path); |
232
|
|
|
|
|
|
|
} |
233
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
sub get_task { |
235
|
0
|
|
|
0
|
0
|
|
my ($self, $name, $opts) = @_; |
236
|
0
|
|
|
|
|
|
my $path = $name; |
237
|
|
|
|
|
|
|
|
238
|
0
|
|
|
|
|
|
$path .= _make_query_param($opts, qw/responseView/); |
239
|
|
|
|
|
|
|
|
240
|
0
|
|
|
|
|
|
return $self->request_get($path); |
241
|
|
|
|
|
|
|
} |
242
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
sub list_tasks { |
244
|
0
|
|
|
0
|
0
|
|
my ($self, $parent, $opts) = @_; |
245
|
0
|
|
|
|
|
|
my $path = $parent . '/tasks'; |
246
|
|
|
|
|
|
|
|
247
|
0
|
|
|
|
|
|
$path .= _make_query_param($opts, qw/responseView pageSize pageToken/); |
248
|
|
|
|
|
|
|
|
249
|
0
|
|
|
|
|
|
return $self->request_get($path); |
250
|
|
|
|
|
|
|
} |
251
|
|
|
|
|
|
|
|
252
|
|
|
|
|
|
|
sub run_task { |
253
|
0
|
|
|
0
|
0
|
|
my ($self, $name, $opts) = @_; |
254
|
0
|
|
|
|
|
|
my $path = $name . ':run'; |
255
|
|
|
|
|
|
|
|
256
|
0
|
|
|
|
|
|
my %param = (); |
257
|
0
|
0
|
|
|
|
|
defined $opts->{responseView} and $param{responseView} = $opts->{responseView}; |
258
|
|
|
|
|
|
|
|
259
|
0
|
|
|
|
|
|
return $self->request_post($path, \%param); |
260
|
|
|
|
|
|
|
} |
261
|
|
|
|
|
|
|
|
262
|
|
|
|
|
|
|
1; |