Debian Codegraph @

cloudtasks/apiv2beta2/cloud_tasks_client.go

raw
1 // Copyright 2025 Google LLC
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // https://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 // Code generated by protoc-gen-go_gapic. DO NOT EDIT.
16
17 package cloudtasks
18
19 import (
20 "bytes"
21 "context"
22 "fmt"
23 "log/slog"
24 "math"
25 "net/http"
26 "net/url"
27 "time"
28
29 cloudtaskspb "cloud.google.com/go/cloudtasks/apiv2beta2/cloudtaskspb"
30 iampb "cloud.google.com/go/iam/apiv1/iampb"
31 gax "github.com/googleapis/gax-go/v2"
32 "google.golang.org/api/iterator"
33 "google.golang.org/api/option"
34 "google.golang.org/api/option/internaloption"
35 gtransport "google.golang.org/api/transport/grpc"
36 httptransport "google.golang.org/api/transport/http"
37 locationpb "google.golang.org/genproto/googleapis/cloud/location"
38 "google.golang.org/grpc"
39 "google.golang.org/grpc/codes"
40 "google.golang.org/protobuf/encoding/protojson"
41 "google.golang.org/protobuf/proto"
42 )
43
44 var newClientHook clientHook
45
46 // CallOptions contains the retry settings for each method of Client.
47 type CallOptions struct {
48 ListQueues []gax.CallOption
49 GetQueue []gax.CallOption
50 CreateQueue []gax.CallOption
51 UpdateQueue []gax.CallOption
52 DeleteQueue []gax.CallOption
53 PurgeQueue []gax.CallOption
54 PauseQueue []gax.CallOption
55 ResumeQueue []gax.CallOption
56 UploadQueueYaml []gax.CallOption
57 GetIamPolicy []gax.CallOption
58 SetIamPolicy []gax.CallOption
59 TestIamPermissions []gax.CallOption
60 ListTasks []gax.CallOption
61 GetTask []gax.CallOption
62 CreateTask []gax.CallOption
63 DeleteTask []gax.CallOption
64 LeaseTasks []gax.CallOption
65 AcknowledgeTask []gax.CallOption
66 RenewLease []gax.CallOption
67 CancelLease []gax.CallOption
68 RunTask []gax.CallOption
69 GetLocation []gax.CallOption
70 ListLocations []gax.CallOption
71 }
72
73 func defaultGRPCClientOptions() []option.ClientOption {
74 return []option.ClientOption{
75 internaloption.WithDefaultEndpoint("cloudtasks.googleapis.com:443"),
76 internaloption.WithDefaultEndpointTemplate("cloudtasks.UNIVERSE_DOMAIN:443"),
77 internaloption.WithDefaultMTLSEndpoint("cloudtasks.mtls.googleapis.com:443"),
78 internaloption.WithDefaultUniverseDomain("googleapis.com"),
79 internaloption.WithDefaultAudience("https://cloudtasks.googleapis.com/"),
80 internaloption.WithDefaultScopes(DefaultAuthScopes()...),
81 internaloption.EnableJwtWithScope(),
82 internaloption.EnableNewAuthLibrary(),
83 option.WithGRPCDialOption(grpc.WithDefaultCallOptions(
84 grpc.MaxCallRecvMsgSize(math.MaxInt32))),
85 }
86 }
87
88 func defaultCallOptions() *CallOptions {
89 return &CallOptions{
90 ListQueues: []gax.CallOption{
91 gax.WithTimeout(20000 * time.Millisecond),
92 gax.WithRetry(func() gax.Retryer {
93 return gax.OnCodes([]codes.Code{
94 codes.Unavailable,
95 codes.DeadlineExceeded,
96 }, gax.Backoff{
97 Initial: 100 * time.Millisecond,
98 Max: 10000 * time.Millisecond,
99 Multiplier: 1.30,
100 })
101 }),
102 },
103 GetQueue: []gax.CallOption{
104 gax.WithTimeout(20000 * time.Millisecond),
105 gax.WithRetry(func() gax.Retryer {
106 return gax.OnCodes([]codes.Code{
107 codes.Unavailable,
108 codes.DeadlineExceeded,
109 }, gax.Backoff{
110 Initial: 100 * time.Millisecond,
111 Max: 10000 * time.Millisecond,
112 Multiplier: 1.30,
113 })
114 }),
115 },
116 CreateQueue: []gax.CallOption{
117 gax.WithTimeout(20000 * time.Millisecond),
118 },
119 UpdateQueue: []gax.CallOption{
120 gax.WithTimeout(20000 * time.Millisecond),
121 },
122 DeleteQueue: []gax.CallOption{
123 gax.WithTimeout(20000 * time.Millisecond),
124 gax.WithRetry(func() gax.Retryer {
125 return gax.OnCodes([]codes.Code{
126 codes.Unavailable,
127 codes.DeadlineExceeded,
128 }, gax.Backoff{
129 Initial: 100 * time.Millisecond,
130 Max: 10000 * time.Millisecond,
131 Multiplier: 1.30,
132 })
133 }),
134 },
135 PurgeQueue: []gax.CallOption{
136 gax.WithTimeout(20000 * time.Millisecond),
137 },
138 PauseQueue: []gax.CallOption{
139 gax.WithTimeout(20000 * time.Millisecond),
140 },
141 ResumeQueue: []gax.CallOption{
142 gax.WithTimeout(20000 * time.Millisecond),
143 },
144 UploadQueueYaml: []gax.CallOption{
145 gax.WithTimeout(20000 * time.Millisecond),
146 },
147 GetIamPolicy: []gax.CallOption{
148 gax.WithTimeout(20000 * time.Millisecond),
149 gax.WithRetry(func() gax.Retryer {
150 return gax.OnCodes([]codes.Code{
151 codes.Unavailable,
152 codes.DeadlineExceeded,
153 }, gax.Backoff{
154 Initial: 100 * time.Millisecond,
155 Max: 10000 * time.Millisecond,
156 Multiplier: 1.30,
157 })
158 }),
159 },
160 SetIamPolicy: []gax.CallOption{
161 gax.WithTimeout(20000 * time.Millisecond),
162 },
163 TestIamPermissions: []gax.CallOption{
164 gax.WithTimeout(20000 * time.Millisecond),
165 gax.WithRetry(func() gax.Retryer {
166 return gax.OnCodes([]codes.Code{
167 codes.Unavailable,
168 codes.DeadlineExceeded,
169 }, gax.Backoff{
170 Initial: 100 * time.Millisecond,
171 Max: 10000 * time.Millisecond,
172 Multiplier: 1.30,
173 })
174 }),
175 },
176 ListTasks: []gax.CallOption{
177 gax.WithTimeout(20000 * time.Millisecond),
178 gax.WithRetry(func() gax.Retryer {
179 return gax.OnCodes([]codes.Code{
180 codes.Unavailable,
181 codes.DeadlineExceeded,
182 }, gax.Backoff{
183 Initial: 100 * time.Millisecond,
184 Max: 10000 * time.Millisecond,
185 Multiplier: 1.30,
186 })
187 }),
188 },
189 GetTask: []gax.CallOption{
190 gax.WithTimeout(20000 * time.Millisecond),
191 gax.WithRetry(func() gax.Retryer {
192 return gax.OnCodes([]codes.Code{
193 codes.Unavailable,
194 codes.DeadlineExceeded,
195 }, gax.Backoff{
196 Initial: 100 * time.Millisecond,
197 Max: 10000 * time.Millisecond,
198 Multiplier: 1.30,
199 })
200 }),
201 },
202 CreateTask: []gax.CallOption{
203 gax.WithTimeout(20000 * time.Millisecond),
204 },
205 DeleteTask: []gax.CallOption{
206 gax.WithTimeout(20000 * time.Millisecond),
207 gax.WithRetry(func() gax.Retryer {
208 return gax.OnCodes([]codes.Code{
209 codes.Unavailable,
210 codes.DeadlineExceeded,
211 }, gax.Backoff{
212 Initial: 100 * time.Millisecond,
213 Max: 10000 * time.Millisecond,
214 Multiplier: 1.30,
215 })
216 }),
217 },
218 LeaseTasks: []gax.CallOption{
219 gax.WithTimeout(20000 * time.Millisecond),
220 },
221 AcknowledgeTask: []gax.CallOption{
222 gax.WithTimeout(20000 * time.Millisecond),
223 },
224 RenewLease: []gax.CallOption{
225 gax.WithTimeout(20000 * time.Millisecond),
226 },
227 CancelLease: []gax.CallOption{
228 gax.WithTimeout(20000 * time.Millisecond),
229 },
230 RunTask: []gax.CallOption{
231 gax.WithTimeout(20000 * time.Millisecond),
232 },
233 GetLocation: []gax.CallOption{},
234 ListLocations: []gax.CallOption{},
235 }
236 }
237
238 func defaultRESTCallOptions() *CallOptions {
239 return &CallOptions{
240 ListQueues: []gax.CallOption{
241 gax.WithTimeout(20000 * time.Millisecond),
242 gax.WithRetry(func() gax.Retryer {
243 return gax.OnHTTPCodes(gax.Backoff{
244 Initial: 100 * time.Millisecond,
245 Max: 10000 * time.Millisecond,
246 Multiplier: 1.30,
247 },
248 http.StatusServiceUnavailable,
249 http.StatusGatewayTimeout)
250 }),
251 },
252 GetQueue: []gax.CallOption{
253 gax.WithTimeout(20000 * time.Millisecond),
254 gax.WithRetry(func() gax.Retryer {
255 return gax.OnHTTPCodes(gax.Backoff{
256 Initial: 100 * time.Millisecond,
257 Max: 10000 * time.Millisecond,
258 Multiplier: 1.30,
259 },
260 http.StatusServiceUnavailable,
261 http.StatusGatewayTimeout)
262 }),
263 },
264 CreateQueue: []gax.CallOption{
265 gax.WithTimeout(20000 * time.Millisecond),
266 },
267 UpdateQueue: []gax.CallOption{
268 gax.WithTimeout(20000 * time.Millisecond),
269 },
270 DeleteQueue: []gax.CallOption{
271 gax.WithTimeout(20000 * time.Millisecond),
272 gax.WithRetry(func() gax.Retryer {
273 return gax.OnHTTPCodes(gax.Backoff{
274 Initial: 100 * time.Millisecond,
275 Max: 10000 * time.Millisecond,
276 Multiplier: 1.30,
277 },
278 http.StatusServiceUnavailable,
279 http.StatusGatewayTimeout)
280 }),
281 },
282 PurgeQueue: []gax.CallOption{
283 gax.WithTimeout(20000 * time.Millisecond),
284 },
285 PauseQueue: []gax.CallOption{
286 gax.WithTimeout(20000 * time.Millisecond),
287 },
288 ResumeQueue: []gax.CallOption{
289 gax.WithTimeout(20000 * time.Millisecond),
290 },
291 UploadQueueYaml: []gax.CallOption{
292 gax.WithTimeout(20000 * time.Millisecond),
293 },
294 GetIamPolicy: []gax.CallOption{
295 gax.WithTimeout(20000 * time.Millisecond),
296 gax.WithRetry(func() gax.Retryer {
297 return gax.OnHTTPCodes(gax.Backoff{
298 Initial: 100 * time.Millisecond,
299 Max: 10000 * time.Millisecond,
300 Multiplier: 1.30,
301 },
302 http.StatusServiceUnavailable,
303 http.StatusGatewayTimeout)
304 }),
305 },
306 SetIamPolicy: []gax.CallOption{
307 gax.WithTimeout(20000 * time.Millisecond),
308 },
309 TestIamPermissions: []gax.CallOption{
310 gax.WithTimeout(20000 * time.Millisecond),
311 gax.WithRetry(func() gax.Retryer {
312 return gax.OnHTTPCodes(gax.Backoff{
313 Initial: 100 * time.Millisecond,
314 Max: 10000 * time.Millisecond,
315 Multiplier: 1.30,
316 },
317 http.StatusServiceUnavailable,
318 http.StatusGatewayTimeout)
319 }),
320 },
321 ListTasks: []gax.CallOption{
322 gax.WithTimeout(20000 * time.Millisecond),
323 gax.WithRetry(func() gax.Retryer {
324 return gax.OnHTTPCodes(gax.Backoff{
325 Initial: 100 * time.Millisecond,
326 Max: 10000 * time.Millisecond,
327 Multiplier: 1.30,
328 },
329 http.StatusServiceUnavailable,
330 http.StatusGatewayTimeout)
331 }),
332 },
333 GetTask: []gax.CallOption{
334 gax.WithTimeout(20000 * time.Millisecond),
335 gax.WithRetry(func() gax.Retryer {
336 return gax.OnHTTPCodes(gax.Backoff{
337 Initial: 100 * time.Millisecond,
338 Max: 10000 * time.Millisecond,
339 Multiplier: 1.30,
340 },
341 http.StatusServiceUnavailable,
342 http.StatusGatewayTimeout)
343 }),
344 },
345 CreateTask: []gax.CallOption{
346 gax.WithTimeout(20000 * time.Millisecond),
347 },
348 DeleteTask: []gax.CallOption{
349 gax.WithTimeout(20000 * time.Millisecond),
350 gax.WithRetry(func() gax.Retryer {
351 return gax.OnHTTPCodes(gax.Backoff{
352 Initial: 100 * time.Millisecond,
353 Max: 10000 * time.Millisecond,
354 Multiplier: 1.30,
355 },
356 http.StatusServiceUnavailable,
357 http.StatusGatewayTimeout)
358 }),
359 },
360 LeaseTasks: []gax.CallOption{
361 gax.WithTimeout(20000 * time.Millisecond),
362 },
363 AcknowledgeTask: []gax.CallOption{
364 gax.WithTimeout(20000 * time.Millisecond),
365 },
366 RenewLease: []gax.CallOption{
367 gax.WithTimeout(20000 * time.Millisecond),
368 },
369 CancelLease: []gax.CallOption{
370 gax.WithTimeout(20000 * time.Millisecond),
371 },
372 RunTask: []gax.CallOption{
373 gax.WithTimeout(20000 * time.Millisecond),
374 },
375 GetLocation: []gax.CallOption{},
376 ListLocations: []gax.CallOption{},
377 }
378 }
379
380 // internalClient is an interface that defines the methods available from Cloud Tasks API.
381 type internalClient interface {
382 Close() error
383 setGoogleClientInfo(...string)
384 Connection() *grpc.ClientConn
385 ListQueues(context.Context, *cloudtaskspb.ListQueuesRequest, ...gax.CallOption) *QueueIterator
386 GetQueue(context.Context, *cloudtaskspb.GetQueueRequest, ...gax.CallOption) (*cloudtaskspb.Queue, error)
387 CreateQueue(context.Context, *cloudtaskspb.CreateQueueRequest, ...gax.CallOption) (*cloudtaskspb.Queue, error)
388 UpdateQueue(context.Context, *cloudtaskspb.UpdateQueueRequest, ...gax.CallOption) (*cloudtaskspb.Queue, error)
389 DeleteQueue(context.Context, *cloudtaskspb.DeleteQueueRequest, ...gax.CallOption) error
390 PurgeQueue(context.Context, *cloudtaskspb.PurgeQueueRequest, ...gax.CallOption) (*cloudtaskspb.Queue, error)
391 PauseQueue(context.Context, *cloudtaskspb.PauseQueueRequest, ...gax.CallOption) (*cloudtaskspb.Queue, error)
392 ResumeQueue(context.Context, *cloudtaskspb.ResumeQueueRequest, ...gax.CallOption) (*cloudtaskspb.Queue, error)
393 UploadQueueYaml(context.Context, *cloudtaskspb.UploadQueueYamlRequest, ...gax.CallOption) error
394 GetIamPolicy(context.Context, *iampb.GetIamPolicyRequest, ...gax.CallOption) (*iampb.Policy, error)
395 SetIamPolicy(context.Context, *iampb.SetIamPolicyRequest, ...gax.CallOption) (*iampb.Policy, error)
396 TestIamPermissions(context.Context, *iampb.TestIamPermissionsRequest, ...gax.CallOption) (*iampb.TestIamPermissionsResponse, error)
397 ListTasks(context.Context, *cloudtaskspb.ListTasksRequest, ...gax.CallOption) *TaskIterator
398 GetTask(context.Context, *cloudtaskspb.GetTaskRequest, ...gax.CallOption) (*cloudtaskspb.Task, error)
399 CreateTask(context.Context, *cloudtaskspb.CreateTaskRequest, ...gax.CallOption) (*cloudtaskspb.Task, error)
400 DeleteTask(context.Context, *cloudtaskspb.DeleteTaskRequest, ...gax.CallOption) error
401 LeaseTasks(context.Context, *cloudtaskspb.LeaseTasksRequest, ...gax.CallOption) (*cloudtaskspb.LeaseTasksResponse, error)
402 AcknowledgeTask(context.Context, *cloudtaskspb.AcknowledgeTaskRequest, ...gax.CallOption) error
403 RenewLease(context.Context, *cloudtaskspb.RenewLeaseRequest, ...gax.CallOption) (*cloudtaskspb.Task, error)
404 CancelLease(context.Context, *cloudtaskspb.CancelLeaseRequest, ...gax.CallOption) (*cloudtaskspb.Task, error)
405 RunTask(context.Context, *cloudtaskspb.RunTaskRequest, ...gax.CallOption) (*cloudtaskspb.Task, error)
406 GetLocation(context.Context, *locationpb.GetLocationRequest, ...gax.CallOption) (*locationpb.Location, error)
407 ListLocations(context.Context, *locationpb.ListLocationsRequest, ...gax.CallOption) *LocationIterator
408 }
409
410 // Client is a client for interacting with Cloud Tasks API.
411 // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
412 //
413 // Cloud Tasks allows developers to manage the execution of background
414 // work in their applications.
415 type Client struct {
416 // The internal transport-dependent client.
417 internalClient internalClient
418
419 // The call options for this service.
420 CallOptions *CallOptions
421 }
422
423 // Wrapper methods routed to the internal client.
424
425 // Close closes the connection to the API service. The user should invoke this when
426 // the client is no longer required.
427 func (c *Client) Close() error {
428 return c.internalClient.Close()
429 }
430
431 // setGoogleClientInfo sets the name and version of the application in
432 // the `x-goog-api-client` header passed on each request. Intended for
433 // use by Google-written clients.
434 func (c *Client) setGoogleClientInfo(keyval ...string) {
435 c.internalClient.setGoogleClientInfo(keyval...)
436 }
437
438 // Connection returns a connection to the API service.
439 //
440 // Deprecated: Connections are now pooled so this method does not always
441 // return the same resource.
442 func (c *Client) Connection() *grpc.ClientConn {
443 return c.internalClient.Connection()
444 }
445
446 // ListQueues lists queues.
447 //
448 // Queues are returned in lexicographical order.
449 func (c *Client) ListQueues(ctx context.Context, req *cloudtaskspb.ListQueuesRequest, opts ...gax.CallOption) *QueueIterator {
450 return c.internalClient.ListQueues(ctx, req, opts...)
451 }
452
453 // GetQueue gets a queue.
454 func (c *Client) GetQueue(ctx context.Context, req *cloudtaskspb.GetQueueRequest, opts ...gax.CallOption) (*cloudtaskspb.Queue, error) {
455 return c.internalClient.GetQueue(ctx, req, opts...)
456 }
457
458 // CreateQueue creates a queue.
459 //
460 // Queues created with this method allow tasks to live for a maximum of 31
461 // days. After a task is 31 days old, the task will be deleted regardless of
462 // whether it was dispatched or not.
463 //
464 // WARNING: Using this method may have unintended side effects if you are
465 // using an App Engine queue.yaml or queue.xml file to manage your queues.
466 // Read
467 // Overview of Queue Management and
468 // queue.yaml (at https://cloud.google.com/tasks/docs/queue-yaml) before using
469 // this method.
470 func (c *Client) CreateQueue(ctx context.Context, req *cloudtaskspb.CreateQueueRequest, opts ...gax.CallOption) (*cloudtaskspb.Queue, error) {
471 return c.internalClient.CreateQueue(ctx, req, opts...)
472 }
473
474 // UpdateQueue updates a queue.
475 //
476 // This method creates the queue if it does not exist and updates
477 // the queue if it does exist.
478 //
479 // Queues created with this method allow tasks to live for a maximum of 31
480 // days. After a task is 31 days old, the task will be deleted regardless of
481 // whether it was dispatched or not.
482 //
483 // WARNING: Using this method may have unintended side effects if you are
484 // using an App Engine queue.yaml or queue.xml file to manage your queues.
485 // Read
486 // Overview of Queue Management and
487 // queue.yaml (at https://cloud.google.com/tasks/docs/queue-yaml) before using
488 // this method.
489 func (c *Client) UpdateQueue(ctx context.Context, req *cloudtaskspb.UpdateQueueRequest, opts ...gax.CallOption) (*cloudtaskspb.Queue, error) {
490 return c.internalClient.UpdateQueue(ctx, req, opts...)
491 }
492
493 // DeleteQueue deletes a queue.
494 //
495 // This command will delete the queue even if it has tasks in it.
496 //
497 // Note: If you delete a queue, a queue with the same name can’t be created
498 // for 7 days.
499 //
500 // WARNING: Using this method may have unintended side effects if you are
501 // using an App Engine queue.yaml or queue.xml file to manage your queues.
502 // Read
503 // Overview of Queue Management and
504 // queue.yaml (at https://cloud.google.com/tasks/docs/queue-yaml) before using
505 // this method.
506 func (c *Client) DeleteQueue(ctx context.Context, req *cloudtaskspb.DeleteQueueRequest, opts ...gax.CallOption) error {
507 return c.internalClient.DeleteQueue(ctx, req, opts...)
508 }
509
510 // PurgeQueue purges a queue by deleting all of its tasks.
511 //
512 // All tasks created before this method is called are permanently deleted.
513 //
514 // Purge operations can take up to one minute to take effect. Tasks
515 // might be dispatched before the purge takes effect. A purge is irreversible.
516 func (c *Client) PurgeQueue(ctx context.Context, req *cloudtaskspb.PurgeQueueRequest, opts ...gax.CallOption) (*cloudtaskspb.Queue, error) {
517 return c.internalClient.PurgeQueue(ctx, req, opts...)
518 }
519
520 // PauseQueue pauses the queue.
521 //
522 // If a queue is paused then the system will stop dispatching tasks
523 // until the queue is resumed via
524 // ResumeQueue. Tasks can
525 // still be added when the queue is paused. A queue is paused if its
526 // state is
527 // PAUSED.
528 func (c *Client) PauseQueue(ctx context.Context, req *cloudtaskspb.PauseQueueRequest, opts ...gax.CallOption) (*cloudtaskspb.Queue, error) {
529 return c.internalClient.PauseQueue(ctx, req, opts...)
530 }
531
532 // ResumeQueue resume a queue.
533 //
534 // This method resumes a queue after it has been
535 // PAUSED or
536 // DISABLED. The state of a
537 // queue is stored in the queue’s
538 // state; after calling this method
539 // it will be set to
540 // RUNNING.
541 //
542 // WARNING: Resuming many high-QPS queues at the same time can
543 // lead to target overloading. If you are resuming high-QPS
544 // queues, follow the 500/50/5 pattern described in
545 // Managing Cloud Tasks Scaling
546 // Risks (at https://cloud.google.com/tasks/docs/manage-cloud-task-scaling).
547 func (c *Client) ResumeQueue(ctx context.Context, req *cloudtaskspb.ResumeQueueRequest, opts ...gax.CallOption) (*cloudtaskspb.Queue, error) {
548 return c.internalClient.ResumeQueue(ctx, req, opts...)
549 }
550
551 // UploadQueueYaml update queue list by uploading a queue.yaml file.
552 //
553 // The queue.yaml file is supplied in the request body as a YAML encoded
554 // string. This method was added to support gcloud clients versions before
555 // 322.0.0. New clients should use CreateQueue instead of this method.
556 func (c *Client) UploadQueueYaml(ctx context.Context, req *cloudtaskspb.UploadQueueYamlRequest, opts ...gax.CallOption) error {
557 return c.internalClient.UploadQueueYaml(ctx, req, opts...)
558 }
559
560 // GetIamPolicy gets the access control policy for a
561 // Queue. Returns an empty policy if the
562 // resource exists and does not have a policy set.
563 //
564 // Authorization requires the following
565 // Google IAM (at https://cloud.google.com/iam) permission on the specified
566 // resource parent:
567 //
568 // cloudtasks.queues.getIamPolicy
569 func (c *Client) GetIamPolicy(ctx context.Context, req *iampb.GetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) {
570 return c.internalClient.GetIamPolicy(ctx, req, opts...)
571 }
572
573 // SetIamPolicy sets the access control policy for a
574 // Queue. Replaces any existing policy.
575 //
576 // Note: The Cloud Console does not check queue-level IAM permissions yet.
577 // Project-level permissions are required to use the Cloud Console.
578 //
579 // Authorization requires the following
580 // Google IAM (at https://cloud.google.com/iam) permission on the specified
581 // resource parent:
582 //
583 // cloudtasks.queues.setIamPolicy
584 func (c *Client) SetIamPolicy(ctx context.Context, req *iampb.SetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) {
585 return c.internalClient.SetIamPolicy(ctx, req, opts...)
586 }
587
588 // TestIamPermissions returns permissions that a caller has on a
589 // Queue. If the resource does not exist,
590 // this will return an empty set of permissions, not a
591 // NOT_FOUND error.
592 //
593 // Note: This operation is designed to be used for building permission-aware
594 // UIs and command-line tools, not for authorization checking. This operation
595 // may “fail open” without warning.
596 func (c *Client) TestIamPermissions(ctx context.Context, req *iampb.TestIamPermissionsRequest, opts ...gax.CallOption) (*iampb.TestIamPermissionsResponse, error) {
597 return c.internalClient.TestIamPermissions(ctx, req, opts...)
598 }
599
600 // ListTasks lists the tasks in a queue.
601 //
602 // By default, only the BASIC
603 // view is retrieved due to performance considerations;
604 // response_view
605 // controls the subset of information which is returned.
606 //
607 // The tasks may be returned in any order. The ordering may change at any
608 // time.
609 func (c *Client) ListTasks(ctx context.Context, req *cloudtaskspb.ListTasksRequest, opts ...gax.CallOption) *TaskIterator {
610 return c.internalClient.ListTasks(ctx, req, opts...)
611 }
612
613 // GetTask gets a task.
614 func (c *Client) GetTask(ctx context.Context, req *cloudtaskspb.GetTaskRequest, opts ...gax.CallOption) (*cloudtaskspb.Task, error) {
615 return c.internalClient.GetTask(ctx, req, opts...)
616 }
617
618 // CreateTask creates a task and adds it to a queue.
619 //
620 // Tasks cannot be updated after creation; there is no UpdateTask command.
621 //
622 // For [App Engine queues][google.cloud.tasks.v2beta2.AppEngineHttpTarget],
623 // the maximum task size is
624 // 100KB.
625 //
626 // For [pull queues][google.cloud.tasks.v2beta2.PullTarget], the maximum
627 // task size is 1MB.
628 func (c *Client) CreateTask(ctx context.Context, req *cloudtaskspb.CreateTaskRequest, opts ...gax.CallOption) (*cloudtaskspb.Task, error) {
629 return c.internalClient.CreateTask(ctx, req, opts...)
630 }
631
632 // DeleteTask deletes a task.
633 //
634 // A task can be deleted if it is scheduled or dispatched. A task
635 // cannot be deleted if it has completed successfully or permanently
636 // failed.
637 func (c *Client) DeleteTask(ctx context.Context, req *cloudtaskspb.DeleteTaskRequest, opts ...gax.CallOption) error {
638 return c.internalClient.DeleteTask(ctx, req, opts...)
639 }
640
641 // LeaseTasks leases tasks from a pull queue for
642 // lease_duration.
643 //
644 // This method is invoked by the worker to obtain a lease. The
645 // worker must acknowledge the task via
646 // AcknowledgeTask
647 // after they have performed the work associated with the task.
648 //
649 // The payload is intended
650 // to store data that the worker needs to perform the work associated with the
651 // task. To return the payloads in the
652 // response, set
653 // response_view
654 // to FULL.
655 //
656 // A maximum of 10 qps of
657 // LeaseTasks requests are
658 // allowed per queue. RESOURCE_EXHAUSTED
659 // is returned when this limit is
660 // exceeded. RESOURCE_EXHAUSTED
661 // is also returned when
662 // max_tasks_dispatched_per_second
663 // is exceeded.
664 func (c *Client) LeaseTasks(ctx context.Context, req *cloudtaskspb.LeaseTasksRequest, opts ...gax.CallOption) (*cloudtaskspb.LeaseTasksResponse, error) {
665 return c.internalClient.LeaseTasks(ctx, req, opts...)
666 }
667
668 // AcknowledgeTask acknowledges a pull task.
669 //
670 // The worker, that is, the entity that
671 // leased this task must
672 // call this method to indicate that the work associated with the task has
673 // finished.
674 //
675 // The worker must acknowledge a task within the
676 // lease_duration
677 // or the lease will expire and the task will become available to be leased
678 // again. After the task is acknowledged, it will not be returned
679 // by a later LeaseTasks,
680 // GetTask, or
681 // ListTasks.
682 func (c *Client) AcknowledgeTask(ctx context.Context, req *cloudtaskspb.AcknowledgeTaskRequest, opts ...gax.CallOption) error {
683 return c.internalClient.AcknowledgeTask(ctx, req, opts...)
684 }
685
686 // RenewLease renew the current lease of a pull task.
687 //
688 // The worker can use this method to extend the lease by a new
689 // duration, starting from now. The new task lease will be
690 // returned in the task’s
691 // schedule_time.
692 func (c *Client) RenewLease(ctx context.Context, req *cloudtaskspb.RenewLeaseRequest, opts ...gax.CallOption) (*cloudtaskspb.Task, error) {
693 return c.internalClient.RenewLease(ctx, req, opts...)
694 }
695
696 // CancelLease cancel a pull task’s lease.
697 //
698 // The worker can use this method to cancel a task’s lease by
699 // setting its schedule_time
700 // to now. This will make the task available to be leased to the next caller
701 // of LeaseTasks.
702 func (c *Client) CancelLease(ctx context.Context, req *cloudtaskspb.CancelLeaseRequest, opts ...gax.CallOption) (*cloudtaskspb.Task, error) {
703 return c.internalClient.CancelLease(ctx, req, opts...)
704 }
705
706 // RunTask forces a task to run now.
707 //
708 // When this method is called, Cloud Tasks will dispatch the task, even if
709 // the task is already running, the queue has reached its
710 // RateLimits or is
711 // PAUSED.
712 //
713 // This command is meant to be used for manual debugging. For
714 // example, RunTask can be
715 // used to retry a failed task after a fix has been made or to manually force
716 // a task to be dispatched now.
717 //
718 // The dispatched task is returned. That is, the task that is returned
719 // contains the status after the
720 // task is dispatched but before the task is received by its target.
721 //
722 // If Cloud Tasks receives a successful response from the task’s
723 // target, then the task will be deleted; otherwise the task’s
724 // schedule_time will be
725 // reset to the time that
726 // RunTask was called plus
727 // the retry delay specified in the queue’s
728 // RetryConfig.
729 //
730 // RunTask returns
731 // NOT_FOUND when it is called on a
732 // task that has already succeeded or permanently failed.
733 //
734 // RunTask cannot be called
735 // on a [pull task][google.cloud.tasks.v2beta2.PullMessage].
736 func (c *Client) RunTask(ctx context.Context, req *cloudtaskspb.RunTaskRequest, opts ...gax.CallOption) (*cloudtaskspb.Task, error) {
737 return c.internalClient.RunTask(ctx, req, opts...)
738 }
739
740 // GetLocation gets information about a location.
741 func (c *Client) GetLocation(ctx context.Context, req *locationpb.GetLocationRequest, opts ...gax.CallOption) (*locationpb.Location, error) {
742 return c.internalClient.GetLocation(ctx, req, opts...)
743 }
744
745 // ListLocations lists information about the supported locations for this service.
746 func (c *Client) ListLocations(ctx context.Context, req *locationpb.ListLocationsRequest, opts ...gax.CallOption) *LocationIterator {
747 return c.internalClient.ListLocations(ctx, req, opts...)
748 }
749
750 // gRPCClient is a client for interacting with Cloud Tasks API over gRPC transport.
751 //
752 // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
753 type gRPCClient struct {
754 // Connection pool of gRPC connections to the service.
755 connPool gtransport.ConnPool
756
757 // Points back to the CallOptions field of the containing Client
758 CallOptions **CallOptions
759
760 // The gRPC API client.
761 client cloudtaskspb.CloudTasksClient
762
763 locationsClient locationpb.LocationsClient
764
765 // The x-goog-* metadata to be sent with each request.
766 xGoogHeaders []string
767
768 logger *slog.Logger
769 }
770
771 // NewClient creates a new cloud tasks client based on gRPC.
772 // The returned client must be Closed when it is done being used to clean up its underlying connections.
773 //
774 // Cloud Tasks allows developers to manage the execution of background
775 // work in their applications.
776 func NewClient(ctx context.Context, opts ...option.ClientOption) (*Client, error) {
777 clientOpts := defaultGRPCClientOptions()
778 if newClientHook != nil {
779 hookOpts, err := newClientHook(ctx, clientHookParams{})
780 if err != nil {
781 return nil, err
782 }
783 clientOpts = append(clientOpts, hookOpts...)
784 }
785
786 connPool, err := gtransport.DialPool(ctx, append(clientOpts, opts...)...)
787 if err != nil {
788 return nil, err
789 }
790 client := Client{CallOptions: defaultCallOptions()}
791
792 c := &gRPCClient{
793 connPool: connPool,
794 client: cloudtaskspb.NewCloudTasksClient(connPool),
795 CallOptions: &client.CallOptions,
796 logger: internaloption.GetLogger(opts),
797 locationsClient: locationpb.NewLocationsClient(connPool),
798 }
799 c.setGoogleClientInfo()
800
801 client.internalClient = c
802
803 return &client, nil
804 }
805
806 // Connection returns a connection to the API service.
807 //
808 // Deprecated: Connections are now pooled so this method does not always
809 // return the same resource.
810 func (c *gRPCClient) Connection() *grpc.ClientConn {
811 return c.connPool.Conn()
812 }
813
814 // setGoogleClientInfo sets the name and version of the application in
815 // the `x-goog-api-client` header passed on each request. Intended for
816 // use by Google-written clients.
817 func (c *gRPCClient) setGoogleClientInfo(keyval ...string) {
818 kv := append([]string{"gl-go", gax.GoVersion}, keyval...)
819 kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "grpc", grpc.Version, "pb", protoVersion)
820 c.xGoogHeaders = []string{
821 "x-goog-api-client", gax.XGoogHeader(kv...),
822 }
823 }
824
825 // Close closes the connection to the API service. The user should invoke this when
826 // the client is no longer required.
827 func (c *gRPCClient) Close() error {
828 return c.connPool.Close()
829 }
830
831 // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
832 type restClient struct {
833 // The http endpoint to connect to.
834 endpoint string
835
836 // The http client.
837 httpClient *http.Client
838
839 // The x-goog-* headers to be sent with each request.
840 xGoogHeaders []string
841
842 // Points back to the CallOptions field of the containing Client
843 CallOptions **CallOptions
844
845 logger *slog.Logger
846 }
847
848 // NewRESTClient creates a new cloud tasks rest client.
849 //
850 // Cloud Tasks allows developers to manage the execution of background
851 // work in their applications.
852 func NewRESTClient(ctx context.Context, opts ...option.ClientOption) (*Client, error) {
853 clientOpts := append(defaultRESTClientOptions(), opts...)
854 httpClient, endpoint, err := httptransport.NewClient(ctx, clientOpts...)
855 if err != nil {
856 return nil, err
857 }
858
859 callOpts := defaultRESTCallOptions()
860 c := &restClient{
861 endpoint: endpoint,
862 httpClient: httpClient,
863 CallOptions: &callOpts,
864 logger: internaloption.GetLogger(opts),
865 }
866 c.setGoogleClientInfo()
867
868 return &Client{internalClient: c, CallOptions: callOpts}, nil
869 }
870
871 func defaultRESTClientOptions() []option.ClientOption {
872 return []option.ClientOption{
873 internaloption.WithDefaultEndpoint("https://cloudtasks.googleapis.com"),
874 internaloption.WithDefaultEndpointTemplate("https://cloudtasks.UNIVERSE_DOMAIN"),
875 internaloption.WithDefaultMTLSEndpoint("https://cloudtasks.mtls.googleapis.com"),
876 internaloption.WithDefaultUniverseDomain("googleapis.com"),
877 internaloption.WithDefaultAudience("https://cloudtasks.googleapis.com/"),
878 internaloption.WithDefaultScopes(DefaultAuthScopes()...),
879 internaloption.EnableNewAuthLibrary(),
880 }
881 }
882
883 // setGoogleClientInfo sets the name and version of the application in
884 // the `x-goog-api-client` header passed on each request. Intended for
885 // use by Google-written clients.
886 func (c *restClient) setGoogleClientInfo(keyval ...string) {
887 kv := append([]string{"gl-go", gax.GoVersion}, keyval...)
888 kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "rest", "UNKNOWN", "pb", protoVersion)
889 c.xGoogHeaders = []string{
890 "x-goog-api-client", gax.XGoogHeader(kv...),
891 }
892 }
893
894 // Close closes the connection to the API service. The user should invoke this when
895 // the client is no longer required.
896 func (c *restClient) Close() error {
897 // Replace httpClient with nil to force cleanup.
898 c.httpClient = nil
899 return nil
900 }
901
902 // Connection returns a connection to the API service.
903 //
904 // Deprecated: This method always returns nil.
905 func (c *restClient) Connection() *grpc.ClientConn {
906 return nil
907 }
908 func (c *gRPCClient) ListQueues(ctx context.Context, req *cloudtaskspb.ListQueuesRequest, opts ...gax.CallOption) *QueueIterator {
909 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
910
911 hds = append(c.xGoogHeaders, hds...)
912 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
913 opts = append((*c.CallOptions).ListQueues[0:len((*c.CallOptions).ListQueues):len((*c.CallOptions).ListQueues)], opts...)
914 it := &QueueIterator{}
915 req = proto.Clone(req).(*cloudtaskspb.ListQueuesRequest)
916 it.InternalFetch = func(pageSize int, pageToken string) ([]*cloudtaskspb.Queue, string, error) {
917 resp := &cloudtaskspb.ListQueuesResponse{}
918 if pageToken != "" {
919 req.PageToken = pageToken
920 }
921 if pageSize > math.MaxInt32 {
922 req.PageSize = math.MaxInt32
923 } else if pageSize != 0 {
924 req.PageSize = int32(pageSize)
925 }
926 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
927 var err error
928 resp, err = executeRPC(ctx, c.client.ListQueues, req, settings.GRPC, c.logger, "ListQueues")
929 return err
930 }, opts...)
931 if err != nil {
932 return nil, "", err
933 }
934
935 it.Response = resp
936 return resp.GetQueues(), resp.GetNextPageToken(), nil
937 }
938 fetch := func(pageSize int, pageToken string) (string, error) {
939 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
940 if err != nil {
941 return "", err
942 }
943 it.items = append(it.items, items...)
944 return nextPageToken, nil
945 }
946
947 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
948 it.pageInfo.MaxSize = int(req.GetPageSize())
949 it.pageInfo.Token = req.GetPageToken()
950
951 return it
952 }
953
954 func (c *gRPCClient) GetQueue(ctx context.Context, req *cloudtaskspb.GetQueueRequest, opts ...gax.CallOption) (*cloudtaskspb.Queue, error) {
955 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
956
957 hds = append(c.xGoogHeaders, hds...)
958 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
959 opts = append((*c.CallOptions).GetQueue[0:len((*c.CallOptions).GetQueue):len((*c.CallOptions).GetQueue)], opts...)
960 var resp *cloudtaskspb.Queue
961 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
962 var err error
963 resp, err = executeRPC(ctx, c.client.GetQueue, req, settings.GRPC, c.logger, "GetQueue")
964 return err
965 }, opts...)
966 if err != nil {
967 return nil, err
968 }
969 return resp, nil
970 }
971
972 func (c *gRPCClient) CreateQueue(ctx context.Context, req *cloudtaskspb.CreateQueueRequest, opts ...gax.CallOption) (*cloudtaskspb.Queue, error) {
973 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
974
975 hds = append(c.xGoogHeaders, hds...)
976 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
977 opts = append((*c.CallOptions).CreateQueue[0:len((*c.CallOptions).CreateQueue):len((*c.CallOptions).CreateQueue)], opts...)
978 var resp *cloudtaskspb.Queue
979 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
980 var err error
981 resp, err = executeRPC(ctx, c.client.CreateQueue, req, settings.GRPC, c.logger, "CreateQueue")
982 return err
983 }, opts...)
984 if err != nil {
985 return nil, err
986 }
987 return resp, nil
988 }
989
990 func (c *gRPCClient) UpdateQueue(ctx context.Context, req *cloudtaskspb.UpdateQueueRequest, opts ...gax.CallOption) (*cloudtaskspb.Queue, error) {
991 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "queue.name", url.QueryEscape(req.GetQueue().GetName()))}
992
993 hds = append(c.xGoogHeaders, hds...)
994 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
995 opts = append((*c.CallOptions).UpdateQueue[0:len((*c.CallOptions).UpdateQueue):len((*c.CallOptions).UpdateQueue)], opts...)
996 var resp *cloudtaskspb.Queue
997 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
998 var err error
999 resp, err = executeRPC(ctx, c.client.UpdateQueue, req, settings.GRPC, c.logger, "UpdateQueue")
1000 return err
1001 }, opts...)
1002 if err != nil {
1003 return nil, err
1004 }
1005 return resp, nil
1006 }
1007
1008 func (c *gRPCClient) DeleteQueue(ctx context.Context, req *cloudtaskspb.DeleteQueueRequest, opts ...gax.CallOption) error {
1009 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
1010
1011 hds = append(c.xGoogHeaders, hds...)
1012 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
1013 opts = append((*c.CallOptions).DeleteQueue[0:len((*c.CallOptions).DeleteQueue):len((*c.CallOptions).DeleteQueue)], opts...)
1014 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1015 var err error
1016 _, err = executeRPC(ctx, c.client.DeleteQueue, req, settings.GRPC, c.logger, "DeleteQueue")
1017 return err
1018 }, opts...)
1019 return err
1020 }
1021
1022 func (c *gRPCClient) PurgeQueue(ctx context.Context, req *cloudtaskspb.PurgeQueueRequest, opts ...gax.CallOption) (*cloudtaskspb.Queue, error) {
1023 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
1024
1025 hds = append(c.xGoogHeaders, hds...)
1026 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
1027 opts = append((*c.CallOptions).PurgeQueue[0:len((*c.CallOptions).PurgeQueue):len((*c.CallOptions).PurgeQueue)], opts...)
1028 var resp *cloudtaskspb.Queue
1029 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1030 var err error
1031 resp, err = executeRPC(ctx, c.client.PurgeQueue, req, settings.GRPC, c.logger, "PurgeQueue")
1032 return err
1033 }, opts...)
1034 if err != nil {
1035 return nil, err
1036 }
1037 return resp, nil
1038 }
1039
1040 func (c *gRPCClient) PauseQueue(ctx context.Context, req *cloudtaskspb.PauseQueueRequest, opts ...gax.CallOption) (*cloudtaskspb.Queue, error) {
1041 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
1042
1043 hds = append(c.xGoogHeaders, hds...)
1044 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
1045 opts = append((*c.CallOptions).PauseQueue[0:len((*c.CallOptions).PauseQueue):len((*c.CallOptions).PauseQueue)], opts...)
1046 var resp *cloudtaskspb.Queue
1047 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1048 var err error
1049 resp, err = executeRPC(ctx, c.client.PauseQueue, req, settings.GRPC, c.logger, "PauseQueue")
1050 return err
1051 }, opts...)
1052 if err != nil {
1053 return nil, err
1054 }
1055 return resp, nil
1056 }
1057
1058 func (c *gRPCClient) ResumeQueue(ctx context.Context, req *cloudtaskspb.ResumeQueueRequest, opts ...gax.CallOption) (*cloudtaskspb.Queue, error) {
1059 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
1060
1061 hds = append(c.xGoogHeaders, hds...)
1062 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
1063 opts = append((*c.CallOptions).ResumeQueue[0:len((*c.CallOptions).ResumeQueue):len((*c.CallOptions).ResumeQueue)], opts...)
1064 var resp *cloudtaskspb.Queue
1065 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1066 var err error
1067 resp, err = executeRPC(ctx, c.client.ResumeQueue, req, settings.GRPC, c.logger, "ResumeQueue")
1068 return err
1069 }, opts...)
1070 if err != nil {
1071 return nil, err
1072 }
1073 return resp, nil
1074 }
1075
1076 func (c *gRPCClient) UploadQueueYaml(ctx context.Context, req *cloudtaskspb.UploadQueueYamlRequest, opts ...gax.CallOption) error {
1077 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, c.xGoogHeaders...)
1078 opts = append((*c.CallOptions).UploadQueueYaml[0:len((*c.CallOptions).UploadQueueYaml):len((*c.CallOptions).UploadQueueYaml)], opts...)
1079 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1080 var err error
1081 _, err = executeRPC(ctx, c.client.UploadQueueYaml, req, settings.GRPC, c.logger, "UploadQueueYaml")
1082 return err
1083 }, opts...)
1084 return err
1085 }
1086
1087 func (c *gRPCClient) GetIamPolicy(ctx context.Context, req *iampb.GetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) {
1088 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))}
1089
1090 hds = append(c.xGoogHeaders, hds...)
1091 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
1092 opts = append((*c.CallOptions).GetIamPolicy[0:len((*c.CallOptions).GetIamPolicy):len((*c.CallOptions).GetIamPolicy)], opts...)
1093 var resp *iampb.Policy
1094 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1095 var err error
1096 resp, err = executeRPC(ctx, c.client.GetIamPolicy, req, settings.GRPC, c.logger, "GetIamPolicy")
1097 return err
1098 }, opts...)
1099 if err != nil {
1100 return nil, err
1101 }
1102 return resp, nil
1103 }
1104
1105 func (c *gRPCClient) SetIamPolicy(ctx context.Context, req *iampb.SetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) {
1106 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))}
1107
1108 hds = append(c.xGoogHeaders, hds...)
1109 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
1110 opts = append((*c.CallOptions).SetIamPolicy[0:len((*c.CallOptions).SetIamPolicy):len((*c.CallOptions).SetIamPolicy)], opts...)
1111 var resp *iampb.Policy
1112 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1113 var err error
1114 resp, err = executeRPC(ctx, c.client.SetIamPolicy, req, settings.GRPC, c.logger, "SetIamPolicy")
1115 return err
1116 }, opts...)
1117 if err != nil {
1118 return nil, err
1119 }
1120 return resp, nil
1121 }
1122
1123 func (c *gRPCClient) TestIamPermissions(ctx context.Context, req *iampb.TestIamPermissionsRequest, opts ...gax.CallOption) (*iampb.TestIamPermissionsResponse, error) {
1124 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))}
1125
1126 hds = append(c.xGoogHeaders, hds...)
1127 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
1128 opts = append((*c.CallOptions).TestIamPermissions[0:len((*c.CallOptions).TestIamPermissions):len((*c.CallOptions).TestIamPermissions)], opts...)
1129 var resp *iampb.TestIamPermissionsResponse
1130 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1131 var err error
1132 resp, err = executeRPC(ctx, c.client.TestIamPermissions, req, settings.GRPC, c.logger, "TestIamPermissions")
1133 return err
1134 }, opts...)
1135 if err != nil {
1136 return nil, err
1137 }
1138 return resp, nil
1139 }
1140
1141 func (c *gRPCClient) ListTasks(ctx context.Context, req *cloudtaskspb.ListTasksRequest, opts ...gax.CallOption) *TaskIterator {
1142 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
1143
1144 hds = append(c.xGoogHeaders, hds...)
1145 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
1146 opts = append((*c.CallOptions).ListTasks[0:len((*c.CallOptions).ListTasks):len((*c.CallOptions).ListTasks)], opts...)
1147 it := &TaskIterator{}
1148 req = proto.Clone(req).(*cloudtaskspb.ListTasksRequest)
1149 it.InternalFetch = func(pageSize int, pageToken string) ([]*cloudtaskspb.Task, string, error) {
1150 resp := &cloudtaskspb.ListTasksResponse{}
1151 if pageToken != "" {
1152 req.PageToken = pageToken
1153 }
1154 if pageSize > math.MaxInt32 {
1155 req.PageSize = math.MaxInt32
1156 } else if pageSize != 0 {
1157 req.PageSize = int32(pageSize)
1158 }
1159 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1160 var err error
1161 resp, err = executeRPC(ctx, c.client.ListTasks, req, settings.GRPC, c.logger, "ListTasks")
1162 return err
1163 }, opts...)
1164 if err != nil {
1165 return nil, "", err
1166 }
1167
1168 it.Response = resp
1169 return resp.GetTasks(), resp.GetNextPageToken(), nil
1170 }
1171 fetch := func(pageSize int, pageToken string) (string, error) {
1172 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
1173 if err != nil {
1174 return "", err
1175 }
1176 it.items = append(it.items, items...)
1177 return nextPageToken, nil
1178 }
1179
1180 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
1181 it.pageInfo.MaxSize = int(req.GetPageSize())
1182 it.pageInfo.Token = req.GetPageToken()
1183
1184 return it
1185 }
1186
1187 func (c *gRPCClient) GetTask(ctx context.Context, req *cloudtaskspb.GetTaskRequest, opts ...gax.CallOption) (*cloudtaskspb.Task, error) {
1188 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
1189
1190 hds = append(c.xGoogHeaders, hds...)
1191 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
1192 opts = append((*c.CallOptions).GetTask[0:len((*c.CallOptions).GetTask):len((*c.CallOptions).GetTask)], opts...)
1193 var resp *cloudtaskspb.Task
1194 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1195 var err error
1196 resp, err = executeRPC(ctx, c.client.GetTask, req, settings.GRPC, c.logger, "GetTask")
1197 return err
1198 }, opts...)
1199 if err != nil {
1200 return nil, err
1201 }
1202 return resp, nil
1203 }
1204
1205 func (c *gRPCClient) CreateTask(ctx context.Context, req *cloudtaskspb.CreateTaskRequest, opts ...gax.CallOption) (*cloudtaskspb.Task, error) {
1206 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
1207
1208 hds = append(c.xGoogHeaders, hds...)
1209 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
1210 opts = append((*c.CallOptions).CreateTask[0:len((*c.CallOptions).CreateTask):len((*c.CallOptions).CreateTask)], opts...)
1211 var resp *cloudtaskspb.Task
1212 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1213 var err error
1214 resp, err = executeRPC(ctx, c.client.CreateTask, req, settings.GRPC, c.logger, "CreateTask")
1215 return err
1216 }, opts...)
1217 if err != nil {
1218 return nil, err
1219 }
1220 return resp, nil
1221 }
1222
1223 func (c *gRPCClient) DeleteTask(ctx context.Context, req *cloudtaskspb.DeleteTaskRequest, opts ...gax.CallOption) error {
1224 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
1225
1226 hds = append(c.xGoogHeaders, hds...)
1227 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
1228 opts = append((*c.CallOptions).DeleteTask[0:len((*c.CallOptions).DeleteTask):len((*c.CallOptions).DeleteTask)], opts...)
1229 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1230 var err error
1231 _, err = executeRPC(ctx, c.client.DeleteTask, req, settings.GRPC, c.logger, "DeleteTask")
1232 return err
1233 }, opts...)
1234 return err
1235 }
1236
1237 func (c *gRPCClient) LeaseTasks(ctx context.Context, req *cloudtaskspb.LeaseTasksRequest, opts ...gax.CallOption) (*cloudtaskspb.LeaseTasksResponse, error) {
1238 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
1239
1240 hds = append(c.xGoogHeaders, hds...)
1241 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
1242 opts = append((*c.CallOptions).LeaseTasks[0:len((*c.CallOptions).LeaseTasks):len((*c.CallOptions).LeaseTasks)], opts...)
1243 var resp *cloudtaskspb.LeaseTasksResponse
1244 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1245 var err error
1246 resp, err = executeRPC(ctx, c.client.LeaseTasks, req, settings.GRPC, c.logger, "LeaseTasks")
1247 return err
1248 }, opts...)
1249 if err != nil {
1250 return nil, err
1251 }
1252 return resp, nil
1253 }
1254
1255 func (c *gRPCClient) AcknowledgeTask(ctx context.Context, req *cloudtaskspb.AcknowledgeTaskRequest, opts ...gax.CallOption) error {
1256 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
1257
1258 hds = append(c.xGoogHeaders, hds...)
1259 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
1260 opts = append((*c.CallOptions).AcknowledgeTask[0:len((*c.CallOptions).AcknowledgeTask):len((*c.CallOptions).AcknowledgeTask)], opts...)
1261 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1262 var err error
1263 _, err = executeRPC(ctx, c.client.AcknowledgeTask, req, settings.GRPC, c.logger, "AcknowledgeTask")
1264 return err
1265 }, opts...)
1266 return err
1267 }
1268
1269 func (c *gRPCClient) RenewLease(ctx context.Context, req *cloudtaskspb.RenewLeaseRequest, opts ...gax.CallOption) (*cloudtaskspb.Task, error) {
1270 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
1271
1272 hds = append(c.xGoogHeaders, hds...)
1273 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
1274 opts = append((*c.CallOptions).RenewLease[0:len((*c.CallOptions).RenewLease):len((*c.CallOptions).RenewLease)], opts...)
1275 var resp *cloudtaskspb.Task
1276 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1277 var err error
1278 resp, err = executeRPC(ctx, c.client.RenewLease, req, settings.GRPC, c.logger, "RenewLease")
1279 return err
1280 }, opts...)
1281 if err != nil {
1282 return nil, err
1283 }
1284 return resp, nil
1285 }
1286
1287 func (c *gRPCClient) CancelLease(ctx context.Context, req *cloudtaskspb.CancelLeaseRequest, opts ...gax.CallOption) (*cloudtaskspb.Task, error) {
1288 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
1289
1290 hds = append(c.xGoogHeaders, hds...)
1291 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
1292 opts = append((*c.CallOptions).CancelLease[0:len((*c.CallOptions).CancelLease):len((*c.CallOptions).CancelLease)], opts...)
1293 var resp *cloudtaskspb.Task
1294 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1295 var err error
1296 resp, err = executeRPC(ctx, c.client.CancelLease, req, settings.GRPC, c.logger, "CancelLease")
1297 return err
1298 }, opts...)
1299 if err != nil {
1300 return nil, err
1301 }
1302 return resp, nil
1303 }
1304
1305 func (c *gRPCClient) RunTask(ctx context.Context, req *cloudtaskspb.RunTaskRequest, opts ...gax.CallOption) (*cloudtaskspb.Task, error) {
1306 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
1307
1308 hds = append(c.xGoogHeaders, hds...)
1309 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
1310 opts = append((*c.CallOptions).RunTask[0:len((*c.CallOptions).RunTask):len((*c.CallOptions).RunTask)], opts...)
1311 var resp *cloudtaskspb.Task
1312 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1313 var err error
1314 resp, err = executeRPC(ctx, c.client.RunTask, req, settings.GRPC, c.logger, "RunTask")
1315 return err
1316 }, opts...)
1317 if err != nil {
1318 return nil, err
1319 }
1320 return resp, nil
1321 }
1322
1323 func (c *gRPCClient) GetLocation(ctx context.Context, req *locationpb.GetLocationRequest, opts ...gax.CallOption) (*locationpb.Location, error) {
1324 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
1325
1326 hds = append(c.xGoogHeaders, hds...)
1327 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
1328 opts = append((*c.CallOptions).GetLocation[0:len((*c.CallOptions).GetLocation):len((*c.CallOptions).GetLocation)], opts...)
1329 var resp *locationpb.Location
1330 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1331 var err error
1332 resp, err = executeRPC(ctx, c.locationsClient.GetLocation, req, settings.GRPC, c.logger, "GetLocation")
1333 return err
1334 }, opts...)
1335 if err != nil {
1336 return nil, err
1337 }
1338 return resp, nil
1339 }
1340
1341 func (c *gRPCClient) ListLocations(ctx context.Context, req *locationpb.ListLocationsRequest, opts ...gax.CallOption) *LocationIterator {
1342 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
1343
1344 hds = append(c.xGoogHeaders, hds...)
1345 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
1346 opts = append((*c.CallOptions).ListLocations[0:len((*c.CallOptions).ListLocations):len((*c.CallOptions).ListLocations)], opts...)
1347 it := &LocationIterator{}
1348 req = proto.Clone(req).(*locationpb.ListLocationsRequest)
1349 it.InternalFetch = func(pageSize int, pageToken string) ([]*locationpb.Location, string, error) {
1350 resp := &locationpb.ListLocationsResponse{}
1351 if pageToken != "" {
1352 req.PageToken = pageToken
1353 }
1354 if pageSize > math.MaxInt32 {
1355 req.PageSize = math.MaxInt32
1356 } else if pageSize != 0 {
1357 req.PageSize = int32(pageSize)
1358 }
1359 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1360 var err error
1361 resp, err = executeRPC(ctx, c.locationsClient.ListLocations, req, settings.GRPC, c.logger, "ListLocations")
1362 return err
1363 }, opts...)
1364 if err != nil {
1365 return nil, "", err
1366 }
1367
1368 it.Response = resp
1369 return resp.GetLocations(), resp.GetNextPageToken(), nil
1370 }
1371 fetch := func(pageSize int, pageToken string) (string, error) {
1372 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
1373 if err != nil {
1374 return "", err
1375 }
1376 it.items = append(it.items, items...)
1377 return nextPageToken, nil
1378 }
1379
1380 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
1381 it.pageInfo.MaxSize = int(req.GetPageSize())
1382 it.pageInfo.Token = req.GetPageToken()
1383
1384 return it
1385 }
1386
1387 // ListQueues lists queues.
1388 //
1389 // Queues are returned in lexicographical order.
1390 func (c *restClient) ListQueues(ctx context.Context, req *cloudtaskspb.ListQueuesRequest, opts ...gax.CallOption) *QueueIterator {
1391 it := &QueueIterator{}
1392 req = proto.Clone(req).(*cloudtaskspb.ListQueuesRequest)
1393 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
1394 it.InternalFetch = func(pageSize int, pageToken string) ([]*cloudtaskspb.Queue, string, error) {
1395 resp := &cloudtaskspb.ListQueuesResponse{}
1396 if pageToken != "" {
1397 req.PageToken = pageToken
1398 }
1399 if pageSize > math.MaxInt32 {
1400 req.PageSize = math.MaxInt32
1401 } else if pageSize != 0 {
1402 req.PageSize = int32(pageSize)
1403 }
1404 baseUrl, err := url.Parse(c.endpoint)
1405 if err != nil {
1406 return nil, "", err
1407 }
1408 baseUrl.Path += fmt.Sprintf("/v2beta2/%v/queues", req.GetParent())
1409
1410 params := url.Values{}
1411 params.Add("$alt", "json;enum-encoding=int")
1412 if req.GetFilter() != "" {
1413 params.Add("filter", fmt.Sprintf("%v", req.GetFilter()))
1414 }
1415 if req.GetPageSize() != 0 {
1416 params.Add("pageSize", fmt.Sprintf("%v", req.GetPageSize()))
1417 }
1418 if req.GetPageToken() != "" {
1419 params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken()))
1420 }
1421 if req.GetReadMask() != nil {
1422 field, err := protojson.Marshal(req.GetReadMask())
1423 if err != nil {
1424 return nil, "", err
1425 }
1426 params.Add("readMask", string(field[1:len(field)-1]))
1427 }
1428
1429 baseUrl.RawQuery = params.Encode()
1430
1431 // Build HTTP headers from client and context metadata.
1432 hds := append(c.xGoogHeaders, "Content-Type", "application/json")
1433 headers := gax.BuildHeaders(ctx, hds...)
1434 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1435 if settings.Path != "" {
1436 baseUrl.Path = settings.Path
1437 }
1438 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
1439 if err != nil {
1440 return err
1441 }
1442 httpReq.Header = headers
1443
1444 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "ListQueues")
1445 if err != nil {
1446 return err
1447 }
1448 if err := unm.Unmarshal(buf, resp); err != nil {
1449 return err
1450 }
1451
1452 return nil
1453 }, opts...)
1454 if e != nil {
1455 return nil, "", e
1456 }
1457 it.Response = resp
1458 return resp.GetQueues(), resp.GetNextPageToken(), nil
1459 }
1460
1461 fetch := func(pageSize int, pageToken string) (string, error) {
1462 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
1463 if err != nil {
1464 return "", err
1465 }
1466 it.items = append(it.items, items...)
1467 return nextPageToken, nil
1468 }
1469
1470 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
1471 it.pageInfo.MaxSize = int(req.GetPageSize())
1472 it.pageInfo.Token = req.GetPageToken()
1473
1474 return it
1475 }
1476
1477 // GetQueue gets a queue.
1478 func (c *restClient) GetQueue(ctx context.Context, req *cloudtaskspb.GetQueueRequest, opts ...gax.CallOption) (*cloudtaskspb.Queue, error) {
1479 baseUrl, err := url.Parse(c.endpoint)
1480 if err != nil {
1481 return nil, err
1482 }
1483 baseUrl.Path += fmt.Sprintf("/v2beta2/%v", req.GetName())
1484
1485 params := url.Values{}
1486 params.Add("$alt", "json;enum-encoding=int")
1487 if req.GetReadMask() != nil {
1488 field, err := protojson.Marshal(req.GetReadMask())
1489 if err != nil {
1490 return nil, err
1491 }
1492 params.Add("readMask", string(field[1:len(field)-1]))
1493 }
1494
1495 baseUrl.RawQuery = params.Encode()
1496
1497 // Build HTTP headers from client and context metadata.
1498 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
1499
1500 hds = append(c.xGoogHeaders, hds...)
1501 hds = append(hds, "Content-Type", "application/json")
1502 headers := gax.BuildHeaders(ctx, hds...)
1503 opts = append((*c.CallOptions).GetQueue[0:len((*c.CallOptions).GetQueue):len((*c.CallOptions).GetQueue)], opts...)
1504 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
1505 resp := &cloudtaskspb.Queue{}
1506 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1507 if settings.Path != "" {
1508 baseUrl.Path = settings.Path
1509 }
1510 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
1511 if err != nil {
1512 return err
1513 }
1514 httpReq = httpReq.WithContext(ctx)
1515 httpReq.Header = headers
1516
1517 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "GetQueue")
1518 if err != nil {
1519 return err
1520 }
1521
1522 if err := unm.Unmarshal(buf, resp); err != nil {
1523 return err
1524 }
1525
1526 return nil
1527 }, opts...)
1528 if e != nil {
1529 return nil, e
1530 }
1531 return resp, nil
1532 }
1533
1534 // CreateQueue creates a queue.
1535 //
1536 // Queues created with this method allow tasks to live for a maximum of 31
1537 // days. After a task is 31 days old, the task will be deleted regardless of
1538 // whether it was dispatched or not.
1539 //
1540 // WARNING: Using this method may have unintended side effects if you are
1541 // using an App Engine queue.yaml or queue.xml file to manage your queues.
1542 // Read
1543 // Overview of Queue Management and
1544 // queue.yaml (at https://cloud.google.com/tasks/docs/queue-yaml) before using
1545 // this method.
1546 func (c *restClient) CreateQueue(ctx context.Context, req *cloudtaskspb.CreateQueueRequest, opts ...gax.CallOption) (*cloudtaskspb.Queue, error) {
1547 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
1548 body := req.GetQueue()
1549 jsonReq, err := m.Marshal(body)
1550 if err != nil {
1551 return nil, err
1552 }
1553
1554 baseUrl, err := url.Parse(c.endpoint)
1555 if err != nil {
1556 return nil, err
1557 }
1558 baseUrl.Path += fmt.Sprintf("/v2beta2/%v/queues", req.GetParent())
1559
1560 params := url.Values{}
1561 params.Add("$alt", "json;enum-encoding=int")
1562
1563 baseUrl.RawQuery = params.Encode()
1564
1565 // Build HTTP headers from client and context metadata.
1566 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
1567
1568 hds = append(c.xGoogHeaders, hds...)
1569 hds = append(hds, "Content-Type", "application/json")
1570 headers := gax.BuildHeaders(ctx, hds...)
1571 opts = append((*c.CallOptions).CreateQueue[0:len((*c.CallOptions).CreateQueue):len((*c.CallOptions).CreateQueue)], opts...)
1572 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
1573 resp := &cloudtaskspb.Queue{}
1574 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1575 if settings.Path != "" {
1576 baseUrl.Path = settings.Path
1577 }
1578 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
1579 if err != nil {
1580 return err
1581 }
1582 httpReq = httpReq.WithContext(ctx)
1583 httpReq.Header = headers
1584
1585 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "CreateQueue")
1586 if err != nil {
1587 return err
1588 }
1589
1590 if err := unm.Unmarshal(buf, resp); err != nil {
1591 return err
1592 }
1593
1594 return nil
1595 }, opts...)
1596 if e != nil {
1597 return nil, e
1598 }
1599 return resp, nil
1600 }
1601
1602 // UpdateQueue updates a queue.
1603 //
1604 // This method creates the queue if it does not exist and updates
1605 // the queue if it does exist.
1606 //
1607 // Queues created with this method allow tasks to live for a maximum of 31
1608 // days. After a task is 31 days old, the task will be deleted regardless of
1609 // whether it was dispatched or not.
1610 //
1611 // WARNING: Using this method may have unintended side effects if you are
1612 // using an App Engine queue.yaml or queue.xml file to manage your queues.
1613 // Read
1614 // Overview of Queue Management and
1615 // queue.yaml (at https://cloud.google.com/tasks/docs/queue-yaml) before using
1616 // this method.
1617 func (c *restClient) UpdateQueue(ctx context.Context, req *cloudtaskspb.UpdateQueueRequest, opts ...gax.CallOption) (*cloudtaskspb.Queue, error) {
1618 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
1619 body := req.GetQueue()
1620 jsonReq, err := m.Marshal(body)
1621 if err != nil {
1622 return nil, err
1623 }
1624
1625 baseUrl, err := url.Parse(c.endpoint)
1626 if err != nil {
1627 return nil, err
1628 }
1629 baseUrl.Path += fmt.Sprintf("/v2beta2/%v", req.GetQueue().GetName())
1630
1631 params := url.Values{}
1632 params.Add("$alt", "json;enum-encoding=int")
1633 if req.GetUpdateMask() != nil {
1634 field, err := protojson.Marshal(req.GetUpdateMask())
1635 if err != nil {
1636 return nil, err
1637 }
1638 params.Add("updateMask", string(field[1:len(field)-1]))
1639 }
1640
1641 baseUrl.RawQuery = params.Encode()
1642
1643 // Build HTTP headers from client and context metadata.
1644 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "queue.name", url.QueryEscape(req.GetQueue().GetName()))}
1645
1646 hds = append(c.xGoogHeaders, hds...)
1647 hds = append(hds, "Content-Type", "application/json")
1648 headers := gax.BuildHeaders(ctx, hds...)
1649 opts = append((*c.CallOptions).UpdateQueue[0:len((*c.CallOptions).UpdateQueue):len((*c.CallOptions).UpdateQueue)], opts...)
1650 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
1651 resp := &cloudtaskspb.Queue{}
1652 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1653 if settings.Path != "" {
1654 baseUrl.Path = settings.Path
1655 }
1656 httpReq, err := http.NewRequest("PATCH", baseUrl.String(), bytes.NewReader(jsonReq))
1657 if err != nil {
1658 return err
1659 }
1660 httpReq = httpReq.WithContext(ctx)
1661 httpReq.Header = headers
1662
1663 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "UpdateQueue")
1664 if err != nil {
1665 return err
1666 }
1667
1668 if err := unm.Unmarshal(buf, resp); err != nil {
1669 return err
1670 }
1671
1672 return nil
1673 }, opts...)
1674 if e != nil {
1675 return nil, e
1676 }
1677 return resp, nil
1678 }
1679
1680 // DeleteQueue deletes a queue.
1681 //
1682 // This command will delete the queue even if it has tasks in it.
1683 //
1684 // Note: If you delete a queue, a queue with the same name can’t be created
1685 // for 7 days.
1686 //
1687 // WARNING: Using this method may have unintended side effects if you are
1688 // using an App Engine queue.yaml or queue.xml file to manage your queues.
1689 // Read
1690 // Overview of Queue Management and
1691 // queue.yaml (at https://cloud.google.com/tasks/docs/queue-yaml) before using
1692 // this method.
1693 func (c *restClient) DeleteQueue(ctx context.Context, req *cloudtaskspb.DeleteQueueRequest, opts ...gax.CallOption) error {
1694 baseUrl, err := url.Parse(c.endpoint)
1695 if err != nil {
1696 return err
1697 }
1698 baseUrl.Path += fmt.Sprintf("/v2beta2/%v", req.GetName())
1699
1700 params := url.Values{}
1701 params.Add("$alt", "json;enum-encoding=int")
1702
1703 baseUrl.RawQuery = params.Encode()
1704
1705 // Build HTTP headers from client and context metadata.
1706 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
1707
1708 hds = append(c.xGoogHeaders, hds...)
1709 hds = append(hds, "Content-Type", "application/json")
1710 headers := gax.BuildHeaders(ctx, hds...)
1711 return gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1712 if settings.Path != "" {
1713 baseUrl.Path = settings.Path
1714 }
1715 httpReq, err := http.NewRequest("DELETE", baseUrl.String(), nil)
1716 if err != nil {
1717 return err
1718 }
1719 httpReq = httpReq.WithContext(ctx)
1720 httpReq.Header = headers
1721
1722 _, err = executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "DeleteQueue")
1723 return err
1724 }, opts...)
1725 }
1726
1727 // PurgeQueue purges a queue by deleting all of its tasks.
1728 //
1729 // All tasks created before this method is called are permanently deleted.
1730 //
1731 // Purge operations can take up to one minute to take effect. Tasks
1732 // might be dispatched before the purge takes effect. A purge is irreversible.
1733 func (c *restClient) PurgeQueue(ctx context.Context, req *cloudtaskspb.PurgeQueueRequest, opts ...gax.CallOption) (*cloudtaskspb.Queue, error) {
1734 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
1735 jsonReq, err := m.Marshal(req)
1736 if err != nil {
1737 return nil, err
1738 }
1739
1740 baseUrl, err := url.Parse(c.endpoint)
1741 if err != nil {
1742 return nil, err
1743 }
1744 baseUrl.Path += fmt.Sprintf("/v2beta2/%v:purge", req.GetName())
1745
1746 params := url.Values{}
1747 params.Add("$alt", "json;enum-encoding=int")
1748
1749 baseUrl.RawQuery = params.Encode()
1750
1751 // Build HTTP headers from client and context metadata.
1752 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
1753
1754 hds = append(c.xGoogHeaders, hds...)
1755 hds = append(hds, "Content-Type", "application/json")
1756 headers := gax.BuildHeaders(ctx, hds...)
1757 opts = append((*c.CallOptions).PurgeQueue[0:len((*c.CallOptions).PurgeQueue):len((*c.CallOptions).PurgeQueue)], opts...)
1758 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
1759 resp := &cloudtaskspb.Queue{}
1760 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1761 if settings.Path != "" {
1762 baseUrl.Path = settings.Path
1763 }
1764 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
1765 if err != nil {
1766 return err
1767 }
1768 httpReq = httpReq.WithContext(ctx)
1769 httpReq.Header = headers
1770
1771 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "PurgeQueue")
1772 if err != nil {
1773 return err
1774 }
1775
1776 if err := unm.Unmarshal(buf, resp); err != nil {
1777 return err
1778 }
1779
1780 return nil
1781 }, opts...)
1782 if e != nil {
1783 return nil, e
1784 }
1785 return resp, nil
1786 }
1787
1788 // PauseQueue pauses the queue.
1789 //
1790 // If a queue is paused then the system will stop dispatching tasks
1791 // until the queue is resumed via
1792 // ResumeQueue. Tasks can
1793 // still be added when the queue is paused. A queue is paused if its
1794 // state is
1795 // PAUSED.
1796 func (c *restClient) PauseQueue(ctx context.Context, req *cloudtaskspb.PauseQueueRequest, opts ...gax.CallOption) (*cloudtaskspb.Queue, error) {
1797 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
1798 jsonReq, err := m.Marshal(req)
1799 if err != nil {
1800 return nil, err
1801 }
1802
1803 baseUrl, err := url.Parse(c.endpoint)
1804 if err != nil {
1805 return nil, err
1806 }
1807 baseUrl.Path += fmt.Sprintf("/v2beta2/%v:pause", req.GetName())
1808
1809 params := url.Values{}
1810 params.Add("$alt", "json;enum-encoding=int")
1811
1812 baseUrl.RawQuery = params.Encode()
1813
1814 // Build HTTP headers from client and context metadata.
1815 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
1816
1817 hds = append(c.xGoogHeaders, hds...)
1818 hds = append(hds, "Content-Type", "application/json")
1819 headers := gax.BuildHeaders(ctx, hds...)
1820 opts = append((*c.CallOptions).PauseQueue[0:len((*c.CallOptions).PauseQueue):len((*c.CallOptions).PauseQueue)], opts...)
1821 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
1822 resp := &cloudtaskspb.Queue{}
1823 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1824 if settings.Path != "" {
1825 baseUrl.Path = settings.Path
1826 }
1827 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
1828 if err != nil {
1829 return err
1830 }
1831 httpReq = httpReq.WithContext(ctx)
1832 httpReq.Header = headers
1833
1834 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "PauseQueue")
1835 if err != nil {
1836 return err
1837 }
1838
1839 if err := unm.Unmarshal(buf, resp); err != nil {
1840 return err
1841 }
1842
1843 return nil
1844 }, opts...)
1845 if e != nil {
1846 return nil, e
1847 }
1848 return resp, nil
1849 }
1850
1851 // ResumeQueue resume a queue.
1852 //
1853 // This method resumes a queue after it has been
1854 // PAUSED or
1855 // DISABLED. The state of a
1856 // queue is stored in the queue’s
1857 // state; after calling this method
1858 // it will be set to
1859 // RUNNING.
1860 //
1861 // WARNING: Resuming many high-QPS queues at the same time can
1862 // lead to target overloading. If you are resuming high-QPS
1863 // queues, follow the 500/50/5 pattern described in
1864 // Managing Cloud Tasks Scaling
1865 // Risks (at https://cloud.google.com/tasks/docs/manage-cloud-task-scaling).
1866 func (c *restClient) ResumeQueue(ctx context.Context, req *cloudtaskspb.ResumeQueueRequest, opts ...gax.CallOption) (*cloudtaskspb.Queue, error) {
1867 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
1868 jsonReq, err := m.Marshal(req)
1869 if err != nil {
1870 return nil, err
1871 }
1872
1873 baseUrl, err := url.Parse(c.endpoint)
1874 if err != nil {
1875 return nil, err
1876 }
1877 baseUrl.Path += fmt.Sprintf("/v2beta2/%v:resume", req.GetName())
1878
1879 params := url.Values{}
1880 params.Add("$alt", "json;enum-encoding=int")
1881
1882 baseUrl.RawQuery = params.Encode()
1883
1884 // Build HTTP headers from client and context metadata.
1885 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
1886
1887 hds = append(c.xGoogHeaders, hds...)
1888 hds = append(hds, "Content-Type", "application/json")
1889 headers := gax.BuildHeaders(ctx, hds...)
1890 opts = append((*c.CallOptions).ResumeQueue[0:len((*c.CallOptions).ResumeQueue):len((*c.CallOptions).ResumeQueue)], opts...)
1891 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
1892 resp := &cloudtaskspb.Queue{}
1893 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1894 if settings.Path != "" {
1895 baseUrl.Path = settings.Path
1896 }
1897 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
1898 if err != nil {
1899 return err
1900 }
1901 httpReq = httpReq.WithContext(ctx)
1902 httpReq.Header = headers
1903
1904 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "ResumeQueue")
1905 if err != nil {
1906 return err
1907 }
1908
1909 if err := unm.Unmarshal(buf, resp); err != nil {
1910 return err
1911 }
1912
1913 return nil
1914 }, opts...)
1915 if e != nil {
1916 return nil, e
1917 }
1918 return resp, nil
1919 }
1920
1921 // UploadQueueYaml update queue list by uploading a queue.yaml file.
1922 //
1923 // The queue.yaml file is supplied in the request body as a YAML encoded
1924 // string. This method was added to support gcloud clients versions before
1925 // 322.0.0. New clients should use CreateQueue instead of this method.
1926 func (c *restClient) UploadQueueYaml(ctx context.Context, req *cloudtaskspb.UploadQueueYamlRequest, opts ...gax.CallOption) error {
1927 baseUrl, err := url.Parse(c.endpoint)
1928 if err != nil {
1929 return err
1930 }
1931 baseUrl.Path += fmt.Sprintf("")
1932
1933 params := url.Values{}
1934 params.Add("$alt", "json;enum-encoding=int")
1935 params.Add("appId", fmt.Sprintf("%v", req.GetAppId()))
1936 if req.GetHttpBody().GetContentType() != "" {
1937 params.Add("httpBody.contentType", fmt.Sprintf("%v", req.GetHttpBody().GetContentType()))
1938 }
1939 if req.GetHttpBody().GetData() != nil {
1940 params.Add("httpBody.data", fmt.Sprintf("%v", req.GetHttpBody().GetData()))
1941 }
1942
1943 baseUrl.RawQuery = params.Encode()
1944
1945 // Build HTTP headers from client and context metadata.
1946 hds := append(c.xGoogHeaders, "Content-Type", "application/json")
1947 headers := gax.BuildHeaders(ctx, hds...)
1948 return gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1949 if settings.Path != "" {
1950 baseUrl.Path = settings.Path
1951 }
1952 httpReq, err := http.NewRequest("", baseUrl.String(), nil)
1953 if err != nil {
1954 return err
1955 }
1956 httpReq = httpReq.WithContext(ctx)
1957 httpReq.Header = headers
1958
1959 _, err = executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "UploadQueueYaml")
1960 return err
1961 }, opts...)
1962 }
1963
1964 // GetIamPolicy gets the access control policy for a
1965 // Queue. Returns an empty policy if the
1966 // resource exists and does not have a policy set.
1967 //
1968 // Authorization requires the following
1969 // Google IAM (at https://cloud.google.com/iam) permission on the specified
1970 // resource parent:
1971 //
1972 // cloudtasks.queues.getIamPolicy
1973 func (c *restClient) GetIamPolicy(ctx context.Context, req *iampb.GetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) {
1974 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
1975 jsonReq, err := m.Marshal(req)
1976 if err != nil {
1977 return nil, err
1978 }
1979
1980 baseUrl, err := url.Parse(c.endpoint)
1981 if err != nil {
1982 return nil, err
1983 }
1984 baseUrl.Path += fmt.Sprintf("/v2beta2/%v:getIamPolicy", req.GetResource())
1985
1986 params := url.Values{}
1987 params.Add("$alt", "json;enum-encoding=int")
1988
1989 baseUrl.RawQuery = params.Encode()
1990
1991 // Build HTTP headers from client and context metadata.
1992 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))}
1993
1994 hds = append(c.xGoogHeaders, hds...)
1995 hds = append(hds, "Content-Type", "application/json")
1996 headers := gax.BuildHeaders(ctx, hds...)
1997 opts = append((*c.CallOptions).GetIamPolicy[0:len((*c.CallOptions).GetIamPolicy):len((*c.CallOptions).GetIamPolicy)], opts...)
1998 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
1999 resp := &iampb.Policy{}
2000 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
2001 if settings.Path != "" {
2002 baseUrl.Path = settings.Path
2003 }
2004 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
2005 if err != nil {
2006 return err
2007 }
2008 httpReq = httpReq.WithContext(ctx)
2009 httpReq.Header = headers
2010
2011 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "GetIamPolicy")
2012 if err != nil {
2013 return err
2014 }
2015
2016 if err := unm.Unmarshal(buf, resp); err != nil {
2017 return err
2018 }
2019
2020 return nil
2021 }, opts...)
2022 if e != nil {
2023 return nil, e
2024 }
2025 return resp, nil
2026 }
2027
2028 // SetIamPolicy sets the access control policy for a
2029 // Queue. Replaces any existing policy.
2030 //
2031 // Note: The Cloud Console does not check queue-level IAM permissions yet.
2032 // Project-level permissions are required to use the Cloud Console.
2033 //
2034 // Authorization requires the following
2035 // Google IAM (at https://cloud.google.com/iam) permission on the specified
2036 // resource parent:
2037 //
2038 // cloudtasks.queues.setIamPolicy
2039 func (c *restClient) SetIamPolicy(ctx context.Context, req *iampb.SetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) {
2040 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
2041 jsonReq, err := m.Marshal(req)
2042 if err != nil {
2043 return nil, err
2044 }
2045
2046 baseUrl, err := url.Parse(c.endpoint)
2047 if err != nil {
2048 return nil, err
2049 }
2050 baseUrl.Path += fmt.Sprintf("/v2beta2/%v:setIamPolicy", req.GetResource())
2051
2052 params := url.Values{}
2053 params.Add("$alt", "json;enum-encoding=int")
2054
2055 baseUrl.RawQuery = params.Encode()
2056
2057 // Build HTTP headers from client and context metadata.
2058 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))}
2059
2060 hds = append(c.xGoogHeaders, hds...)
2061 hds = append(hds, "Content-Type", "application/json")
2062 headers := gax.BuildHeaders(ctx, hds...)
2063 opts = append((*c.CallOptions).SetIamPolicy[0:len((*c.CallOptions).SetIamPolicy):len((*c.CallOptions).SetIamPolicy)], opts...)
2064 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
2065 resp := &iampb.Policy{}
2066 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
2067 if settings.Path != "" {
2068 baseUrl.Path = settings.Path
2069 }
2070 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
2071 if err != nil {
2072 return err
2073 }
2074 httpReq = httpReq.WithContext(ctx)
2075 httpReq.Header = headers
2076
2077 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "SetIamPolicy")
2078 if err != nil {
2079 return err
2080 }
2081
2082 if err := unm.Unmarshal(buf, resp); err != nil {
2083 return err
2084 }
2085
2086 return nil
2087 }, opts...)
2088 if e != nil {
2089 return nil, e
2090 }
2091 return resp, nil
2092 }
2093
2094 // TestIamPermissions returns permissions that a caller has on a
2095 // Queue. If the resource does not exist,
2096 // this will return an empty set of permissions, not a
2097 // NOT_FOUND error.
2098 //
2099 // Note: This operation is designed to be used for building permission-aware
2100 // UIs and command-line tools, not for authorization checking. This operation
2101 // may “fail open” without warning.
2102 func (c *restClient) TestIamPermissions(ctx context.Context, req *iampb.TestIamPermissionsRequest, opts ...gax.CallOption) (*iampb.TestIamPermissionsResponse, error) {
2103 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
2104 jsonReq, err := m.Marshal(req)
2105 if err != nil {
2106 return nil, err
2107 }
2108
2109 baseUrl, err := url.Parse(c.endpoint)
2110 if err != nil {
2111 return nil, err
2112 }
2113 baseUrl.Path += fmt.Sprintf("/v2beta2/%v:testIamPermissions", req.GetResource())
2114
2115 params := url.Values{}
2116 params.Add("$alt", "json;enum-encoding=int")
2117
2118 baseUrl.RawQuery = params.Encode()
2119
2120 // Build HTTP headers from client and context metadata.
2121 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))}
2122
2123 hds = append(c.xGoogHeaders, hds...)
2124 hds = append(hds, "Content-Type", "application/json")
2125 headers := gax.BuildHeaders(ctx, hds...)
2126 opts = append((*c.CallOptions).TestIamPermissions[0:len((*c.CallOptions).TestIamPermissions):len((*c.CallOptions).TestIamPermissions)], opts...)
2127 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
2128 resp := &iampb.TestIamPermissionsResponse{}
2129 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
2130 if settings.Path != "" {
2131 baseUrl.Path = settings.Path
2132 }
2133 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
2134 if err != nil {
2135 return err
2136 }
2137 httpReq = httpReq.WithContext(ctx)
2138 httpReq.Header = headers
2139
2140 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "TestIamPermissions")
2141 if err != nil {
2142 return err
2143 }
2144
2145 if err := unm.Unmarshal(buf, resp); err != nil {
2146 return err
2147 }
2148
2149 return nil
2150 }, opts...)
2151 if e != nil {
2152 return nil, e
2153 }
2154 return resp, nil
2155 }
2156
2157 // ListTasks lists the tasks in a queue.
2158 //
2159 // By default, only the BASIC
2160 // view is retrieved due to performance considerations;
2161 // response_view
2162 // controls the subset of information which is returned.
2163 //
2164 // The tasks may be returned in any order. The ordering may change at any
2165 // time.
2166 func (c *restClient) ListTasks(ctx context.Context, req *cloudtaskspb.ListTasksRequest, opts ...gax.CallOption) *TaskIterator {
2167 it := &TaskIterator{}
2168 req = proto.Clone(req).(*cloudtaskspb.ListTasksRequest)
2169 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
2170 it.InternalFetch = func(pageSize int, pageToken string) ([]*cloudtaskspb.Task, string, error) {
2171 resp := &cloudtaskspb.ListTasksResponse{}
2172 if pageToken != "" {
2173 req.PageToken = pageToken
2174 }
2175 if pageSize > math.MaxInt32 {
2176 req.PageSize = math.MaxInt32
2177 } else if pageSize != 0 {
2178 req.PageSize = int32(pageSize)
2179 }
2180 baseUrl, err := url.Parse(c.endpoint)
2181 if err != nil {
2182 return nil, "", err
2183 }
2184 baseUrl.Path += fmt.Sprintf("/v2beta2/%v/tasks", req.GetParent())
2185
2186 params := url.Values{}
2187 params.Add("$alt", "json;enum-encoding=int")
2188 if req.GetPageSize() != 0 {
2189 params.Add("pageSize", fmt.Sprintf("%v", req.GetPageSize()))
2190 }
2191 if req.GetPageToken() != "" {
2192 params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken()))
2193 }
2194 if req.GetResponseView() != 0 {
2195 params.Add("responseView", fmt.Sprintf("%v", req.GetResponseView()))
2196 }
2197
2198 baseUrl.RawQuery = params.Encode()
2199
2200 // Build HTTP headers from client and context metadata.
2201 hds := append(c.xGoogHeaders, "Content-Type", "application/json")
2202 headers := gax.BuildHeaders(ctx, hds...)
2203 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
2204 if settings.Path != "" {
2205 baseUrl.Path = settings.Path
2206 }
2207 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
2208 if err != nil {
2209 return err
2210 }
2211 httpReq.Header = headers
2212
2213 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "ListTasks")
2214 if err != nil {
2215 return err
2216 }
2217 if err := unm.Unmarshal(buf, resp); err != nil {
2218 return err
2219 }
2220
2221 return nil
2222 }, opts...)
2223 if e != nil {
2224 return nil, "", e
2225 }
2226 it.Response = resp
2227 return resp.GetTasks(), resp.GetNextPageToken(), nil
2228 }
2229
2230 fetch := func(pageSize int, pageToken string) (string, error) {
2231 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
2232 if err != nil {
2233 return "", err
2234 }
2235 it.items = append(it.items, items...)
2236 return nextPageToken, nil
2237 }
2238
2239 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
2240 it.pageInfo.MaxSize = int(req.GetPageSize())
2241 it.pageInfo.Token = req.GetPageToken()
2242
2243 return it
2244 }
2245
2246 // GetTask gets a task.
2247 func (c *restClient) GetTask(ctx context.Context, req *cloudtaskspb.GetTaskRequest, opts ...gax.CallOption) (*cloudtaskspb.Task, error) {
2248 baseUrl, err := url.Parse(c.endpoint)
2249 if err != nil {
2250 return nil, err
2251 }
2252 baseUrl.Path += fmt.Sprintf("/v2beta2/%v", req.GetName())
2253
2254 params := url.Values{}
2255 params.Add("$alt", "json;enum-encoding=int")
2256 if req.GetResponseView() != 0 {
2257 params.Add("responseView", fmt.Sprintf("%v", req.GetResponseView()))
2258 }
2259
2260 baseUrl.RawQuery = params.Encode()
2261
2262 // Build HTTP headers from client and context metadata.
2263 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
2264
2265 hds = append(c.xGoogHeaders, hds...)
2266 hds = append(hds, "Content-Type", "application/json")
2267 headers := gax.BuildHeaders(ctx, hds...)
2268 opts = append((*c.CallOptions).GetTask[0:len((*c.CallOptions).GetTask):len((*c.CallOptions).GetTask)], opts...)
2269 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
2270 resp := &cloudtaskspb.Task{}
2271 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
2272 if settings.Path != "" {
2273 baseUrl.Path = settings.Path
2274 }
2275 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
2276 if err != nil {
2277 return err
2278 }
2279 httpReq = httpReq.WithContext(ctx)
2280 httpReq.Header = headers
2281
2282 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "GetTask")
2283 if err != nil {
2284 return err
2285 }
2286
2287 if err := unm.Unmarshal(buf, resp); err != nil {
2288 return err
2289 }
2290
2291 return nil
2292 }, opts...)
2293 if e != nil {
2294 return nil, e
2295 }
2296 return resp, nil
2297 }
2298
2299 // CreateTask creates a task and adds it to a queue.
2300 //
2301 // Tasks cannot be updated after creation; there is no UpdateTask command.
2302 //
2303 // For [App Engine queues][google.cloud.tasks.v2beta2.AppEngineHttpTarget],
2304 // the maximum task size is
2305 // 100KB.
2306 //
2307 // For [pull queues][google.cloud.tasks.v2beta2.PullTarget], the maximum
2308 // task size is 1MB.
2309 func (c *restClient) CreateTask(ctx context.Context, req *cloudtaskspb.CreateTaskRequest, opts ...gax.CallOption) (*cloudtaskspb.Task, error) {
2310 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
2311 jsonReq, err := m.Marshal(req)
2312 if err != nil {
2313 return nil, err
2314 }
2315
2316 baseUrl, err := url.Parse(c.endpoint)
2317 if err != nil {
2318 return nil, err
2319 }
2320 baseUrl.Path += fmt.Sprintf("/v2beta2/%v/tasks", req.GetParent())
2321
2322 params := url.Values{}
2323 params.Add("$alt", "json;enum-encoding=int")
2324
2325 baseUrl.RawQuery = params.Encode()
2326
2327 // Build HTTP headers from client and context metadata.
2328 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
2329
2330 hds = append(c.xGoogHeaders, hds...)
2331 hds = append(hds, "Content-Type", "application/json")
2332 headers := gax.BuildHeaders(ctx, hds...)
2333 opts = append((*c.CallOptions).CreateTask[0:len((*c.CallOptions).CreateTask):len((*c.CallOptions).CreateTask)], opts...)
2334 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
2335 resp := &cloudtaskspb.Task{}
2336 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
2337 if settings.Path != "" {
2338 baseUrl.Path = settings.Path
2339 }
2340 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
2341 if err != nil {
2342 return err
2343 }
2344 httpReq = httpReq.WithContext(ctx)
2345 httpReq.Header = headers
2346
2347 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "CreateTask")
2348 if err != nil {
2349 return err
2350 }
2351
2352 if err := unm.Unmarshal(buf, resp); err != nil {
2353 return err
2354 }
2355
2356 return nil
2357 }, opts...)
2358 if e != nil {
2359 return nil, e
2360 }
2361 return resp, nil
2362 }
2363
2364 // DeleteTask deletes a task.
2365 //
2366 // A task can be deleted if it is scheduled or dispatched. A task
2367 // cannot be deleted if it has completed successfully or permanently
2368 // failed.
2369 func (c *restClient) DeleteTask(ctx context.Context, req *cloudtaskspb.DeleteTaskRequest, opts ...gax.CallOption) error {
2370 baseUrl, err := url.Parse(c.endpoint)
2371 if err != nil {
2372 return err
2373 }
2374 baseUrl.Path += fmt.Sprintf("/v2beta2/%v", req.GetName())
2375
2376 params := url.Values{}
2377 params.Add("$alt", "json;enum-encoding=int")
2378
2379 baseUrl.RawQuery = params.Encode()
2380
2381 // Build HTTP headers from client and context metadata.
2382 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
2383
2384 hds = append(c.xGoogHeaders, hds...)
2385 hds = append(hds, "Content-Type", "application/json")
2386 headers := gax.BuildHeaders(ctx, hds...)
2387 return gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
2388 if settings.Path != "" {
2389 baseUrl.Path = settings.Path
2390 }
2391 httpReq, err := http.NewRequest("DELETE", baseUrl.String(), nil)
2392 if err != nil {
2393 return err
2394 }
2395 httpReq = httpReq.WithContext(ctx)
2396 httpReq.Header = headers
2397
2398 _, err = executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "DeleteTask")
2399 return err
2400 }, opts...)
2401 }
2402
2403 // LeaseTasks leases tasks from a pull queue for
2404 // lease_duration.
2405 //
2406 // This method is invoked by the worker to obtain a lease. The
2407 // worker must acknowledge the task via
2408 // AcknowledgeTask
2409 // after they have performed the work associated with the task.
2410 //
2411 // The payload is intended
2412 // to store data that the worker needs to perform the work associated with the
2413 // task. To return the payloads in the
2414 // response, set
2415 // response_view
2416 // to FULL.
2417 //
2418 // A maximum of 10 qps of
2419 // LeaseTasks requests are
2420 // allowed per queue. RESOURCE_EXHAUSTED
2421 // is returned when this limit is
2422 // exceeded. RESOURCE_EXHAUSTED
2423 // is also returned when
2424 // max_tasks_dispatched_per_second
2425 // is exceeded.
2426 func (c *restClient) LeaseTasks(ctx context.Context, req *cloudtaskspb.LeaseTasksRequest, opts ...gax.CallOption) (*cloudtaskspb.LeaseTasksResponse, error) {
2427 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
2428 jsonReq, err := m.Marshal(req)
2429 if err != nil {
2430 return nil, err
2431 }
2432
2433 baseUrl, err := url.Parse(c.endpoint)
2434 if err != nil {
2435 return nil, err
2436 }
2437 baseUrl.Path += fmt.Sprintf("/v2beta2/%v/tasks:lease", req.GetParent())
2438
2439 params := url.Values{}
2440 params.Add("$alt", "json;enum-encoding=int")
2441
2442 baseUrl.RawQuery = params.Encode()
2443
2444 // Build HTTP headers from client and context metadata.
2445 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
2446
2447 hds = append(c.xGoogHeaders, hds...)
2448 hds = append(hds, "Content-Type", "application/json")
2449 headers := gax.BuildHeaders(ctx, hds...)
2450 opts = append((*c.CallOptions).LeaseTasks[0:len((*c.CallOptions).LeaseTasks):len((*c.CallOptions).LeaseTasks)], opts...)
2451 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
2452 resp := &cloudtaskspb.LeaseTasksResponse{}
2453 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
2454 if settings.Path != "" {
2455 baseUrl.Path = settings.Path
2456 }
2457 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
2458 if err != nil {
2459 return err
2460 }
2461 httpReq = httpReq.WithContext(ctx)
2462 httpReq.Header = headers
2463
2464 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "LeaseTasks")
2465 if err != nil {
2466 return err
2467 }
2468
2469 if err := unm.Unmarshal(buf, resp); err != nil {
2470 return err
2471 }
2472
2473 return nil
2474 }, opts...)
2475 if e != nil {
2476 return nil, e
2477 }
2478 return resp, nil
2479 }
2480
2481 // AcknowledgeTask acknowledges a pull task.
2482 //
2483 // The worker, that is, the entity that
2484 // leased this task must
2485 // call this method to indicate that the work associated with the task has
2486 // finished.
2487 //
2488 // The worker must acknowledge a task within the
2489 // lease_duration
2490 // or the lease will expire and the task will become available to be leased
2491 // again. After the task is acknowledged, it will not be returned
2492 // by a later LeaseTasks,
2493 // GetTask, or
2494 // ListTasks.
2495 func (c *restClient) AcknowledgeTask(ctx context.Context, req *cloudtaskspb.AcknowledgeTaskRequest, opts ...gax.CallOption) error {
2496 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
2497 jsonReq, err := m.Marshal(req)
2498 if err != nil {
2499 return err
2500 }
2501
2502 baseUrl, err := url.Parse(c.endpoint)
2503 if err != nil {
2504 return err
2505 }
2506 baseUrl.Path += fmt.Sprintf("/v2beta2/%v:acknowledge", req.GetName())
2507
2508 params := url.Values{}
2509 params.Add("$alt", "json;enum-encoding=int")
2510
2511 baseUrl.RawQuery = params.Encode()
2512
2513 // Build HTTP headers from client and context metadata.
2514 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
2515
2516 hds = append(c.xGoogHeaders, hds...)
2517 hds = append(hds, "Content-Type", "application/json")
2518 headers := gax.BuildHeaders(ctx, hds...)
2519 return gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
2520 if settings.Path != "" {
2521 baseUrl.Path = settings.Path
2522 }
2523 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
2524 if err != nil {
2525 return err
2526 }
2527 httpReq = httpReq.WithContext(ctx)
2528 httpReq.Header = headers
2529
2530 _, err = executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "AcknowledgeTask")
2531 return err
2532 }, opts...)
2533 }
2534
2535 // RenewLease renew the current lease of a pull task.
2536 //
2537 // The worker can use this method to extend the lease by a new
2538 // duration, starting from now. The new task lease will be
2539 // returned in the task’s
2540 // schedule_time.
2541 func (c *restClient) RenewLease(ctx context.Context, req *cloudtaskspb.RenewLeaseRequest, opts ...gax.CallOption) (*cloudtaskspb.Task, error) {
2542 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
2543 jsonReq, err := m.Marshal(req)
2544 if err != nil {
2545 return nil, err
2546 }
2547
2548 baseUrl, err := url.Parse(c.endpoint)
2549 if err != nil {
2550 return nil, err
2551 }
2552 baseUrl.Path += fmt.Sprintf("/v2beta2/%v:renewLease", req.GetName())
2553
2554 params := url.Values{}
2555 params.Add("$alt", "json;enum-encoding=int")
2556
2557 baseUrl.RawQuery = params.Encode()
2558
2559 // Build HTTP headers from client and context metadata.
2560 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
2561
2562 hds = append(c.xGoogHeaders, hds...)
2563 hds = append(hds, "Content-Type", "application/json")
2564 headers := gax.BuildHeaders(ctx, hds...)
2565 opts = append((*c.CallOptions).RenewLease[0:len((*c.CallOptions).RenewLease):len((*c.CallOptions).RenewLease)], opts...)
2566 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
2567 resp := &cloudtaskspb.Task{}
2568 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
2569 if settings.Path != "" {
2570 baseUrl.Path = settings.Path
2571 }
2572 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
2573 if err != nil {
2574 return err
2575 }
2576 httpReq = httpReq.WithContext(ctx)
2577 httpReq.Header = headers
2578
2579 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "RenewLease")
2580 if err != nil {
2581 return err
2582 }
2583
2584 if err := unm.Unmarshal(buf, resp); err != nil {
2585 return err
2586 }
2587
2588 return nil
2589 }, opts...)
2590 if e != nil {
2591 return nil, e
2592 }
2593 return resp, nil
2594 }
2595
2596 // CancelLease cancel a pull task’s lease.
2597 //
2598 // The worker can use this method to cancel a task’s lease by
2599 // setting its schedule_time
2600 // to now. This will make the task available to be leased to the next caller
2601 // of LeaseTasks.
2602 func (c *restClient) CancelLease(ctx context.Context, req *cloudtaskspb.CancelLeaseRequest, opts ...gax.CallOption) (*cloudtaskspb.Task, error) {
2603 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
2604 jsonReq, err := m.Marshal(req)
2605 if err != nil {
2606 return nil, err
2607 }
2608
2609 baseUrl, err := url.Parse(c.endpoint)
2610 if err != nil {
2611 return nil, err
2612 }
2613 baseUrl.Path += fmt.Sprintf("/v2beta2/%v:cancelLease", req.GetName())
2614
2615 params := url.Values{}
2616 params.Add("$alt", "json;enum-encoding=int")
2617
2618 baseUrl.RawQuery = params.Encode()
2619
2620 // Build HTTP headers from client and context metadata.
2621 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
2622
2623 hds = append(c.xGoogHeaders, hds...)
2624 hds = append(hds, "Content-Type", "application/json")
2625 headers := gax.BuildHeaders(ctx, hds...)
2626 opts = append((*c.CallOptions).CancelLease[0:len((*c.CallOptions).CancelLease):len((*c.CallOptions).CancelLease)], opts...)
2627 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
2628 resp := &cloudtaskspb.Task{}
2629 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
2630 if settings.Path != "" {
2631 baseUrl.Path = settings.Path
2632 }
2633 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
2634 if err != nil {
2635 return err
2636 }
2637 httpReq = httpReq.WithContext(ctx)
2638 httpReq.Header = headers
2639
2640 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "CancelLease")
2641 if err != nil {
2642 return err
2643 }
2644
2645 if err := unm.Unmarshal(buf, resp); err != nil {
2646 return err
2647 }
2648
2649 return nil
2650 }, opts...)
2651 if e != nil {
2652 return nil, e
2653 }
2654 return resp, nil
2655 }
2656
2657 // RunTask forces a task to run now.
2658 //
2659 // When this method is called, Cloud Tasks will dispatch the task, even if
2660 // the task is already running, the queue has reached its
2661 // RateLimits or is
2662 // PAUSED.
2663 //
2664 // This command is meant to be used for manual debugging. For
2665 // example, RunTask can be
2666 // used to retry a failed task after a fix has been made or to manually force
2667 // a task to be dispatched now.
2668 //
2669 // The dispatched task is returned. That is, the task that is returned
2670 // contains the status after the
2671 // task is dispatched but before the task is received by its target.
2672 //
2673 // If Cloud Tasks receives a successful response from the task’s
2674 // target, then the task will be deleted; otherwise the task’s
2675 // schedule_time will be
2676 // reset to the time that
2677 // RunTask was called plus
2678 // the retry delay specified in the queue’s
2679 // RetryConfig.
2680 //
2681 // RunTask returns
2682 // NOT_FOUND when it is called on a
2683 // task that has already succeeded or permanently failed.
2684 //
2685 // RunTask cannot be called
2686 // on a [pull task][google.cloud.tasks.v2beta2.PullMessage].
2687 func (c *restClient) RunTask(ctx context.Context, req *cloudtaskspb.RunTaskRequest, opts ...gax.CallOption) (*cloudtaskspb.Task, error) {
2688 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
2689 jsonReq, err := m.Marshal(req)
2690 if err != nil {
2691 return nil, err
2692 }
2693
2694 baseUrl, err := url.Parse(c.endpoint)
2695 if err != nil {
2696 return nil, err
2697 }
2698 baseUrl.Path += fmt.Sprintf("/v2beta2/%v:run", req.GetName())
2699
2700 params := url.Values{}
2701 params.Add("$alt", "json;enum-encoding=int")
2702
2703 baseUrl.RawQuery = params.Encode()
2704
2705 // Build HTTP headers from client and context metadata.
2706 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
2707
2708 hds = append(c.xGoogHeaders, hds...)
2709 hds = append(hds, "Content-Type", "application/json")
2710 headers := gax.BuildHeaders(ctx, hds...)
2711 opts = append((*c.CallOptions).RunTask[0:len((*c.CallOptions).RunTask):len((*c.CallOptions).RunTask)], opts...)
2712 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
2713 resp := &cloudtaskspb.Task{}
2714 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
2715 if settings.Path != "" {
2716 baseUrl.Path = settings.Path
2717 }
2718 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
2719 if err != nil {
2720 return err
2721 }
2722 httpReq = httpReq.WithContext(ctx)
2723 httpReq.Header = headers
2724
2725 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "RunTask")
2726 if err != nil {
2727 return err
2728 }
2729
2730 if err := unm.Unmarshal(buf, resp); err != nil {
2731 return err
2732 }
2733
2734 return nil
2735 }, opts...)
2736 if e != nil {
2737 return nil, e
2738 }
2739 return resp, nil
2740 }
2741
2742 // GetLocation gets information about a location.
2743 func (c *restClient) GetLocation(ctx context.Context, req *locationpb.GetLocationRequest, opts ...gax.CallOption) (*locationpb.Location, error) {
2744 baseUrl, err := url.Parse(c.endpoint)
2745 if err != nil {
2746 return nil, err
2747 }
2748 baseUrl.Path += fmt.Sprintf("/v2beta2/%v", req.GetName())
2749
2750 params := url.Values{}
2751 params.Add("$alt", "json;enum-encoding=int")
2752
2753 baseUrl.RawQuery = params.Encode()
2754
2755 // Build HTTP headers from client and context metadata.
2756 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
2757
2758 hds = append(c.xGoogHeaders, hds...)
2759 hds = append(hds, "Content-Type", "application/json")
2760 headers := gax.BuildHeaders(ctx, hds...)
2761 opts = append((*c.CallOptions).GetLocation[0:len((*c.CallOptions).GetLocation):len((*c.CallOptions).GetLocation)], opts...)
2762 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
2763 resp := &locationpb.Location{}
2764 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
2765 if settings.Path != "" {
2766 baseUrl.Path = settings.Path
2767 }
2768 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
2769 if err != nil {
2770 return err
2771 }
2772 httpReq = httpReq.WithContext(ctx)
2773 httpReq.Header = headers
2774
2775 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "GetLocation")
2776 if err != nil {
2777 return err
2778 }
2779
2780 if err := unm.Unmarshal(buf, resp); err != nil {
2781 return err
2782 }
2783
2784 return nil
2785 }, opts...)
2786 if e != nil {
2787 return nil, e
2788 }
2789 return resp, nil
2790 }
2791
2792 // ListLocations lists information about the supported locations for this service.
2793 func (c *restClient) ListLocations(ctx context.Context, req *locationpb.ListLocationsRequest, opts ...gax.CallOption) *LocationIterator {
2794 it := &LocationIterator{}
2795 req = proto.Clone(req).(*locationpb.ListLocationsRequest)
2796 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
2797 it.InternalFetch = func(pageSize int, pageToken string) ([]*locationpb.Location, string, error) {
2798 resp := &locationpb.ListLocationsResponse{}
2799 if pageToken != "" {
2800 req.PageToken = pageToken
2801 }
2802 if pageSize > math.MaxInt32 {
2803 req.PageSize = math.MaxInt32
2804 } else if pageSize != 0 {
2805 req.PageSize = int32(pageSize)
2806 }
2807 baseUrl, err := url.Parse(c.endpoint)
2808 if err != nil {
2809 return nil, "", err
2810 }
2811 baseUrl.Path += fmt.Sprintf("/v2beta2/%v/locations", req.GetName())
2812
2813 params := url.Values{}
2814 params.Add("$alt", "json;enum-encoding=int")
2815 if req.GetFilter() != "" {
2816 params.Add("filter", fmt.Sprintf("%v", req.GetFilter()))
2817 }
2818 if req.GetPageSize() != 0 {
2819 params.Add("pageSize", fmt.Sprintf("%v", req.GetPageSize()))
2820 }
2821 if req.GetPageToken() != "" {
2822 params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken()))
2823 }
2824
2825 baseUrl.RawQuery = params.Encode()
2826
2827 // Build HTTP headers from client and context metadata.
2828 hds := append(c.xGoogHeaders, "Content-Type", "application/json")
2829 headers := gax.BuildHeaders(ctx, hds...)
2830 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
2831 if settings.Path != "" {
2832 baseUrl.Path = settings.Path
2833 }
2834 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
2835 if err != nil {
2836 return err
2837 }
2838 httpReq.Header = headers
2839
2840 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "ListLocations")
2841 if err != nil {
2842 return err
2843 }
2844 if err := unm.Unmarshal(buf, resp); err != nil {
2845 return err
2846 }
2847
2848 return nil
2849 }, opts...)
2850 if e != nil {
2851 return nil, "", e
2852 }
2853 it.Response = resp
2854 return resp.GetLocations(), resp.GetNextPageToken(), nil
2855 }
2856
2857 fetch := func(pageSize int, pageToken string) (string, error) {
2858 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
2859 if err != nil {
2860 return "", err
2861 }
2862 it.items = append(it.items, items...)
2863 return nextPageToken, nil
2864 }
2865
2866 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
2867 it.pageInfo.MaxSize = int(req.GetPageSize())
2868 it.pageInfo.Token = req.GetPageToken()
2869
2870 return it
2871 }