Debian Codegraph @

storagetransfer/apiv1/storage_transfer_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 storagetransfer
18
19 import (
20 "bytes"
21 "context"
22 "fmt"
23 "log/slog"
24 "math"
25 "net/http"
26 "net/url"
27 "time"
28
29 "cloud.google.com/go/longrunning"
30 lroauto "cloud.google.com/go/longrunning/autogen"
31 longrunningpb "cloud.google.com/go/longrunning/autogen/longrunningpb"
32 storagetransferpb "cloud.google.com/go/storagetransfer/apiv1/storagetransferpb"
33 gax "github.com/googleapis/gax-go/v2"
34 "google.golang.org/api/iterator"
35 "google.golang.org/api/option"
36 "google.golang.org/api/option/internaloption"
37 gtransport "google.golang.org/api/transport/grpc"
38 httptransport "google.golang.org/api/transport/http"
39 "google.golang.org/grpc"
40 "google.golang.org/grpc/codes"
41 "google.golang.org/protobuf/encoding/protojson"
42 "google.golang.org/protobuf/proto"
43 )
44
45 var newClientHook clientHook
46
47 // CallOptions contains the retry settings for each method of Client.
48 type CallOptions struct {
49 GetGoogleServiceAccount []gax.CallOption
50 CreateTransferJob []gax.CallOption
51 UpdateTransferJob []gax.CallOption
52 GetTransferJob []gax.CallOption
53 ListTransferJobs []gax.CallOption
54 PauseTransferOperation []gax.CallOption
55 ResumeTransferOperation []gax.CallOption
56 RunTransferJob []gax.CallOption
57 DeleteTransferJob []gax.CallOption
58 CreateAgentPool []gax.CallOption
59 UpdateAgentPool []gax.CallOption
60 GetAgentPool []gax.CallOption
61 ListAgentPools []gax.CallOption
62 DeleteAgentPool []gax.CallOption
63 CancelOperation []gax.CallOption
64 GetOperation []gax.CallOption
65 ListOperations []gax.CallOption
66 }
67
68 func defaultGRPCClientOptions() []option.ClientOption {
69 return []option.ClientOption{
70 internaloption.WithDefaultEndpoint("storagetransfer.googleapis.com:443"),
71 internaloption.WithDefaultEndpointTemplate("storagetransfer.UNIVERSE_DOMAIN:443"),
72 internaloption.WithDefaultMTLSEndpoint("storagetransfer.mtls.googleapis.com:443"),
73 internaloption.WithDefaultUniverseDomain("googleapis.com"),
74 internaloption.WithDefaultAudience("https://storagetransfer.googleapis.com/"),
75 internaloption.WithDefaultScopes(DefaultAuthScopes()...),
76 internaloption.EnableJwtWithScope(),
77 internaloption.EnableNewAuthLibrary(),
78 option.WithGRPCDialOption(grpc.WithDefaultCallOptions(
79 grpc.MaxCallRecvMsgSize(math.MaxInt32))),
80 }
81 }
82
83 func defaultCallOptions() *CallOptions {
84 return &CallOptions{
85 GetGoogleServiceAccount: []gax.CallOption{
86 gax.WithTimeout(60000 * time.Millisecond),
87 gax.WithRetry(func() gax.Retryer {
88 return gax.OnCodes([]codes.Code{
89 codes.Unavailable,
90 }, gax.Backoff{
91 Initial: 1000 * time.Millisecond,
92 Max: 60000 * time.Millisecond,
93 Multiplier: 2.00,
94 })
95 }),
96 },
97 CreateTransferJob: []gax.CallOption{
98 gax.WithTimeout(60000 * time.Millisecond),
99 },
100 UpdateTransferJob: []gax.CallOption{
101 gax.WithTimeout(60000 * time.Millisecond),
102 gax.WithRetry(func() gax.Retryer {
103 return gax.OnCodes([]codes.Code{
104 codes.Unavailable,
105 }, gax.Backoff{
106 Initial: 1000 * time.Millisecond,
107 Max: 60000 * time.Millisecond,
108 Multiplier: 2.00,
109 })
110 }),
111 },
112 GetTransferJob: []gax.CallOption{
113 gax.WithTimeout(60000 * time.Millisecond),
114 gax.WithRetry(func() gax.Retryer {
115 return gax.OnCodes([]codes.Code{
116 codes.Unavailable,
117 }, gax.Backoff{
118 Initial: 1000 * time.Millisecond,
119 Max: 60000 * time.Millisecond,
120 Multiplier: 2.00,
121 })
122 }),
123 },
124 ListTransferJobs: []gax.CallOption{
125 gax.WithTimeout(60000 * time.Millisecond),
126 gax.WithRetry(func() gax.Retryer {
127 return gax.OnCodes([]codes.Code{
128 codes.Unavailable,
129 }, gax.Backoff{
130 Initial: 1000 * time.Millisecond,
131 Max: 60000 * time.Millisecond,
132 Multiplier: 2.00,
133 })
134 }),
135 },
136 PauseTransferOperation: []gax.CallOption{
137 gax.WithTimeout(60000 * time.Millisecond),
138 gax.WithRetry(func() gax.Retryer {
139 return gax.OnCodes([]codes.Code{
140 codes.Unavailable,
141 }, gax.Backoff{
142 Initial: 1000 * time.Millisecond,
143 Max: 60000 * time.Millisecond,
144 Multiplier: 2.00,
145 })
146 }),
147 },
148 ResumeTransferOperation: []gax.CallOption{
149 gax.WithTimeout(60000 * time.Millisecond),
150 gax.WithRetry(func() gax.Retryer {
151 return gax.OnCodes([]codes.Code{
152 codes.Unavailable,
153 }, gax.Backoff{
154 Initial: 1000 * time.Millisecond,
155 Max: 60000 * time.Millisecond,
156 Multiplier: 2.00,
157 })
158 }),
159 },
160 RunTransferJob: []gax.CallOption{
161 gax.WithTimeout(60000 * time.Millisecond),
162 gax.WithRetry(func() gax.Retryer {
163 return gax.OnCodes([]codes.Code{
164 codes.Unavailable,
165 }, gax.Backoff{
166 Initial: 1000 * time.Millisecond,
167 Max: 60000 * time.Millisecond,
168 Multiplier: 2.00,
169 })
170 }),
171 },
172 DeleteTransferJob: []gax.CallOption{
173 gax.WithTimeout(60000 * time.Millisecond),
174 gax.WithRetry(func() gax.Retryer {
175 return gax.OnCodes([]codes.Code{
176 codes.Unavailable,
177 }, gax.Backoff{
178 Initial: 1000 * time.Millisecond,
179 Max: 60000 * time.Millisecond,
180 Multiplier: 2.00,
181 })
182 }),
183 },
184 CreateAgentPool: []gax.CallOption{
185 gax.WithTimeout(60000 * time.Millisecond),
186 gax.WithRetry(func() gax.Retryer {
187 return gax.OnCodes([]codes.Code{
188 codes.Unavailable,
189 }, gax.Backoff{
190 Initial: 1000 * time.Millisecond,
191 Max: 60000 * time.Millisecond,
192 Multiplier: 2.00,
193 })
194 }),
195 },
196 UpdateAgentPool: []gax.CallOption{
197 gax.WithTimeout(60000 * time.Millisecond),
198 gax.WithRetry(func() gax.Retryer {
199 return gax.OnCodes([]codes.Code{
200 codes.Unavailable,
201 }, gax.Backoff{
202 Initial: 1000 * time.Millisecond,
203 Max: 60000 * time.Millisecond,
204 Multiplier: 2.00,
205 })
206 }),
207 },
208 GetAgentPool: []gax.CallOption{
209 gax.WithTimeout(60000 * time.Millisecond),
210 gax.WithRetry(func() gax.Retryer {
211 return gax.OnCodes([]codes.Code{
212 codes.Unavailable,
213 }, gax.Backoff{
214 Initial: 1000 * time.Millisecond,
215 Max: 60000 * time.Millisecond,
216 Multiplier: 2.00,
217 })
218 }),
219 },
220 ListAgentPools: []gax.CallOption{
221 gax.WithTimeout(60000 * time.Millisecond),
222 gax.WithRetry(func() gax.Retryer {
223 return gax.OnCodes([]codes.Code{
224 codes.Unavailable,
225 }, gax.Backoff{
226 Initial: 1000 * time.Millisecond,
227 Max: 60000 * time.Millisecond,
228 Multiplier: 2.00,
229 })
230 }),
231 },
232 DeleteAgentPool: []gax.CallOption{
233 gax.WithTimeout(60000 * time.Millisecond),
234 gax.WithRetry(func() gax.Retryer {
235 return gax.OnCodes([]codes.Code{
236 codes.Unavailable,
237 }, gax.Backoff{
238 Initial: 1000 * time.Millisecond,
239 Max: 60000 * time.Millisecond,
240 Multiplier: 2.00,
241 })
242 }),
243 },
244 CancelOperation: []gax.CallOption{
245 gax.WithTimeout(60000 * time.Millisecond),
246 gax.WithRetry(func() gax.Retryer {
247 return gax.OnCodes([]codes.Code{
248 codes.Unavailable,
249 }, gax.Backoff{
250 Initial: 1000 * time.Millisecond,
251 Max: 60000 * time.Millisecond,
252 Multiplier: 2.00,
253 })
254 }),
255 },
256 GetOperation: []gax.CallOption{
257 gax.WithTimeout(60000 * time.Millisecond),
258 gax.WithRetry(func() gax.Retryer {
259 return gax.OnCodes([]codes.Code{
260 codes.Unavailable,
261 }, gax.Backoff{
262 Initial: 1000 * time.Millisecond,
263 Max: 60000 * time.Millisecond,
264 Multiplier: 2.00,
265 })
266 }),
267 },
268 ListOperations: []gax.CallOption{
269 gax.WithTimeout(60000 * time.Millisecond),
270 gax.WithRetry(func() gax.Retryer {
271 return gax.OnCodes([]codes.Code{
272 codes.Unavailable,
273 }, gax.Backoff{
274 Initial: 1000 * time.Millisecond,
275 Max: 60000 * time.Millisecond,
276 Multiplier: 2.00,
277 })
278 }),
279 },
280 }
281 }
282
283 func defaultRESTCallOptions() *CallOptions {
284 return &CallOptions{
285 GetGoogleServiceAccount: []gax.CallOption{
286 gax.WithTimeout(60000 * time.Millisecond),
287 gax.WithRetry(func() gax.Retryer {
288 return gax.OnHTTPCodes(gax.Backoff{
289 Initial: 1000 * time.Millisecond,
290 Max: 60000 * time.Millisecond,
291 Multiplier: 2.00,
292 },
293 http.StatusServiceUnavailable)
294 }),
295 },
296 CreateTransferJob: []gax.CallOption{
297 gax.WithTimeout(60000 * time.Millisecond),
298 },
299 UpdateTransferJob: []gax.CallOption{
300 gax.WithTimeout(60000 * time.Millisecond),
301 gax.WithRetry(func() gax.Retryer {
302 return gax.OnHTTPCodes(gax.Backoff{
303 Initial: 1000 * time.Millisecond,
304 Max: 60000 * time.Millisecond,
305 Multiplier: 2.00,
306 },
307 http.StatusServiceUnavailable)
308 }),
309 },
310 GetTransferJob: []gax.CallOption{
311 gax.WithTimeout(60000 * time.Millisecond),
312 gax.WithRetry(func() gax.Retryer {
313 return gax.OnHTTPCodes(gax.Backoff{
314 Initial: 1000 * time.Millisecond,
315 Max: 60000 * time.Millisecond,
316 Multiplier: 2.00,
317 },
318 http.StatusServiceUnavailable)
319 }),
320 },
321 ListTransferJobs: []gax.CallOption{
322 gax.WithTimeout(60000 * time.Millisecond),
323 gax.WithRetry(func() gax.Retryer {
324 return gax.OnHTTPCodes(gax.Backoff{
325 Initial: 1000 * time.Millisecond,
326 Max: 60000 * time.Millisecond,
327 Multiplier: 2.00,
328 },
329 http.StatusServiceUnavailable)
330 }),
331 },
332 PauseTransferOperation: []gax.CallOption{
333 gax.WithTimeout(60000 * time.Millisecond),
334 gax.WithRetry(func() gax.Retryer {
335 return gax.OnHTTPCodes(gax.Backoff{
336 Initial: 1000 * time.Millisecond,
337 Max: 60000 * time.Millisecond,
338 Multiplier: 2.00,
339 },
340 http.StatusServiceUnavailable)
341 }),
342 },
343 ResumeTransferOperation: []gax.CallOption{
344 gax.WithTimeout(60000 * time.Millisecond),
345 gax.WithRetry(func() gax.Retryer {
346 return gax.OnHTTPCodes(gax.Backoff{
347 Initial: 1000 * time.Millisecond,
348 Max: 60000 * time.Millisecond,
349 Multiplier: 2.00,
350 },
351 http.StatusServiceUnavailable)
352 }),
353 },
354 RunTransferJob: []gax.CallOption{
355 gax.WithTimeout(60000 * time.Millisecond),
356 gax.WithRetry(func() gax.Retryer {
357 return gax.OnHTTPCodes(gax.Backoff{
358 Initial: 1000 * time.Millisecond,
359 Max: 60000 * time.Millisecond,
360 Multiplier: 2.00,
361 },
362 http.StatusServiceUnavailable)
363 }),
364 },
365 DeleteTransferJob: []gax.CallOption{
366 gax.WithTimeout(60000 * time.Millisecond),
367 gax.WithRetry(func() gax.Retryer {
368 return gax.OnHTTPCodes(gax.Backoff{
369 Initial: 1000 * time.Millisecond,
370 Max: 60000 * time.Millisecond,
371 Multiplier: 2.00,
372 },
373 http.StatusServiceUnavailable)
374 }),
375 },
376 CreateAgentPool: []gax.CallOption{
377 gax.WithTimeout(60000 * time.Millisecond),
378 gax.WithRetry(func() gax.Retryer {
379 return gax.OnHTTPCodes(gax.Backoff{
380 Initial: 1000 * time.Millisecond,
381 Max: 60000 * time.Millisecond,
382 Multiplier: 2.00,
383 },
384 http.StatusServiceUnavailable)
385 }),
386 },
387 UpdateAgentPool: []gax.CallOption{
388 gax.WithTimeout(60000 * time.Millisecond),
389 gax.WithRetry(func() gax.Retryer {
390 return gax.OnHTTPCodes(gax.Backoff{
391 Initial: 1000 * time.Millisecond,
392 Max: 60000 * time.Millisecond,
393 Multiplier: 2.00,
394 },
395 http.StatusServiceUnavailable)
396 }),
397 },
398 GetAgentPool: []gax.CallOption{
399 gax.WithTimeout(60000 * time.Millisecond),
400 gax.WithRetry(func() gax.Retryer {
401 return gax.OnHTTPCodes(gax.Backoff{
402 Initial: 1000 * time.Millisecond,
403 Max: 60000 * time.Millisecond,
404 Multiplier: 2.00,
405 },
406 http.StatusServiceUnavailable)
407 }),
408 },
409 ListAgentPools: []gax.CallOption{
410 gax.WithTimeout(60000 * time.Millisecond),
411 gax.WithRetry(func() gax.Retryer {
412 return gax.OnHTTPCodes(gax.Backoff{
413 Initial: 1000 * time.Millisecond,
414 Max: 60000 * time.Millisecond,
415 Multiplier: 2.00,
416 },
417 http.StatusServiceUnavailable)
418 }),
419 },
420 DeleteAgentPool: []gax.CallOption{
421 gax.WithTimeout(60000 * time.Millisecond),
422 gax.WithRetry(func() gax.Retryer {
423 return gax.OnHTTPCodes(gax.Backoff{
424 Initial: 1000 * time.Millisecond,
425 Max: 60000 * time.Millisecond,
426 Multiplier: 2.00,
427 },
428 http.StatusServiceUnavailable)
429 }),
430 },
431 CancelOperation: []gax.CallOption{
432 gax.WithTimeout(60000 * time.Millisecond),
433 gax.WithRetry(func() gax.Retryer {
434 return gax.OnHTTPCodes(gax.Backoff{
435 Initial: 1000 * time.Millisecond,
436 Max: 60000 * time.Millisecond,
437 Multiplier: 2.00,
438 },
439 http.StatusServiceUnavailable)
440 }),
441 },
442 GetOperation: []gax.CallOption{
443 gax.WithTimeout(60000 * time.Millisecond),
444 gax.WithRetry(func() gax.Retryer {
445 return gax.OnHTTPCodes(gax.Backoff{
446 Initial: 1000 * time.Millisecond,
447 Max: 60000 * time.Millisecond,
448 Multiplier: 2.00,
449 },
450 http.StatusServiceUnavailable)
451 }),
452 },
453 ListOperations: []gax.CallOption{
454 gax.WithTimeout(60000 * time.Millisecond),
455 gax.WithRetry(func() gax.Retryer {
456 return gax.OnHTTPCodes(gax.Backoff{
457 Initial: 1000 * time.Millisecond,
458 Max: 60000 * time.Millisecond,
459 Multiplier: 2.00,
460 },
461 http.StatusServiceUnavailable)
462 }),
463 },
464 }
465 }
466
467 // internalClient is an interface that defines the methods available from Storage Transfer API.
468 type internalClient interface {
469 Close() error
470 setGoogleClientInfo(...string)
471 Connection() *grpc.ClientConn
472 GetGoogleServiceAccount(context.Context, *storagetransferpb.GetGoogleServiceAccountRequest, ...gax.CallOption) (*storagetransferpb.GoogleServiceAccount, error)
473 CreateTransferJob(context.Context, *storagetransferpb.CreateTransferJobRequest, ...gax.CallOption) (*storagetransferpb.TransferJob, error)
474 UpdateTransferJob(context.Context, *storagetransferpb.UpdateTransferJobRequest, ...gax.CallOption) (*storagetransferpb.TransferJob, error)
475 GetTransferJob(context.Context, *storagetransferpb.GetTransferJobRequest, ...gax.CallOption) (*storagetransferpb.TransferJob, error)
476 ListTransferJobs(context.Context, *storagetransferpb.ListTransferJobsRequest, ...gax.CallOption) *TransferJobIterator
477 PauseTransferOperation(context.Context, *storagetransferpb.PauseTransferOperationRequest, ...gax.CallOption) error
478 ResumeTransferOperation(context.Context, *storagetransferpb.ResumeTransferOperationRequest, ...gax.CallOption) error
479 RunTransferJob(context.Context, *storagetransferpb.RunTransferJobRequest, ...gax.CallOption) (*RunTransferJobOperation, error)
480 RunTransferJobOperation(name string) *RunTransferJobOperation
481 DeleteTransferJob(context.Context, *storagetransferpb.DeleteTransferJobRequest, ...gax.CallOption) error
482 CreateAgentPool(context.Context, *storagetransferpb.CreateAgentPoolRequest, ...gax.CallOption) (*storagetransferpb.AgentPool, error)
483 UpdateAgentPool(context.Context, *storagetransferpb.UpdateAgentPoolRequest, ...gax.CallOption) (*storagetransferpb.AgentPool, error)
484 GetAgentPool(context.Context, *storagetransferpb.GetAgentPoolRequest, ...gax.CallOption) (*storagetransferpb.AgentPool, error)
485 ListAgentPools(context.Context, *storagetransferpb.ListAgentPoolsRequest, ...gax.CallOption) *AgentPoolIterator
486 DeleteAgentPool(context.Context, *storagetransferpb.DeleteAgentPoolRequest, ...gax.CallOption) error
487 CancelOperation(context.Context, *longrunningpb.CancelOperationRequest, ...gax.CallOption) error
488 GetOperation(context.Context, *longrunningpb.GetOperationRequest, ...gax.CallOption) (*longrunningpb.Operation, error)
489 ListOperations(context.Context, *longrunningpb.ListOperationsRequest, ...gax.CallOption) *OperationIterator
490 }
491
492 // Client is a client for interacting with Storage Transfer API.
493 // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
494 //
495 // Storage Transfer Service and its protos.
496 // Transfers data between between Google Cloud Storage buckets or from a data
497 // source external to Google to a Cloud Storage bucket.
498 type Client struct {
499 // The internal transport-dependent client.
500 internalClient internalClient
501
502 // The call options for this service.
503 CallOptions *CallOptions
504
505 // LROClient is used internally to handle long-running operations.
506 // It is exposed so that its CallOptions can be modified if required.
507 // Users should not Close this client.
508 LROClient *lroauto.OperationsClient
509 }
510
511 // Wrapper methods routed to the internal client.
512
513 // Close closes the connection to the API service. The user should invoke this when
514 // the client is no longer required.
515 func (c *Client) Close() error {
516 return c.internalClient.Close()
517 }
518
519 // setGoogleClientInfo sets the name and version of the application in
520 // the `x-goog-api-client` header passed on each request. Intended for
521 // use by Google-written clients.
522 func (c *Client) setGoogleClientInfo(keyval ...string) {
523 c.internalClient.setGoogleClientInfo(keyval...)
524 }
525
526 // Connection returns a connection to the API service.
527 //
528 // Deprecated: Connections are now pooled so this method does not always
529 // return the same resource.
530 func (c *Client) Connection() *grpc.ClientConn {
531 return c.internalClient.Connection()
532 }
533
534 // GetGoogleServiceAccount returns the Google service account that is used by Storage Transfer
535 // Service to access buckets in the project where transfers
536 // run or in other projects. Each Google service account is associated
537 // with one Google Cloud project. Users
538 // should add this service account to the Google Cloud Storage bucket
539 // ACLs to grant access to Storage Transfer Service. This service
540 // account is created and owned by Storage Transfer Service and can
541 // only be used by Storage Transfer Service.
542 func (c *Client) GetGoogleServiceAccount(ctx context.Context, req *storagetransferpb.GetGoogleServiceAccountRequest, opts ...gax.CallOption) (*storagetransferpb.GoogleServiceAccount, error) {
543 return c.internalClient.GetGoogleServiceAccount(ctx, req, opts...)
544 }
545
546 // CreateTransferJob creates a transfer job that runs periodically.
547 func (c *Client) CreateTransferJob(ctx context.Context, req *storagetransferpb.CreateTransferJobRequest, opts ...gax.CallOption) (*storagetransferpb.TransferJob, error) {
548 return c.internalClient.CreateTransferJob(ctx, req, opts...)
549 }
550
551 // UpdateTransferJob updates a transfer job. Updating a job’s transfer spec does not affect
552 // transfer operations that are running already.
553 //
554 // Note: The job’s status
555 // field can be modified using this RPC (for example, to set a job’s status to
556 // DELETED,
557 // DISABLED, or
558 // ENABLED).
559 func (c *Client) UpdateTransferJob(ctx context.Context, req *storagetransferpb.UpdateTransferJobRequest, opts ...gax.CallOption) (*storagetransferpb.TransferJob, error) {
560 return c.internalClient.UpdateTransferJob(ctx, req, opts...)
561 }
562
563 // GetTransferJob gets a transfer job.
564 func (c *Client) GetTransferJob(ctx context.Context, req *storagetransferpb.GetTransferJobRequest, opts ...gax.CallOption) (*storagetransferpb.TransferJob, error) {
565 return c.internalClient.GetTransferJob(ctx, req, opts...)
566 }
567
568 // ListTransferJobs lists transfer jobs.
569 func (c *Client) ListTransferJobs(ctx context.Context, req *storagetransferpb.ListTransferJobsRequest, opts ...gax.CallOption) *TransferJobIterator {
570 return c.internalClient.ListTransferJobs(ctx, req, opts...)
571 }
572
573 // PauseTransferOperation pauses a transfer operation.
574 func (c *Client) PauseTransferOperation(ctx context.Context, req *storagetransferpb.PauseTransferOperationRequest, opts ...gax.CallOption) error {
575 return c.internalClient.PauseTransferOperation(ctx, req, opts...)
576 }
577
578 // ResumeTransferOperation resumes a transfer operation that is paused.
579 func (c *Client) ResumeTransferOperation(ctx context.Context, req *storagetransferpb.ResumeTransferOperationRequest, opts ...gax.CallOption) error {
580 return c.internalClient.ResumeTransferOperation(ctx, req, opts...)
581 }
582
583 // RunTransferJob starts a new operation for the specified transfer job.
584 // A TransferJob has a maximum of one active TransferOperation. If this
585 // method is called while a TransferOperation is active, an error is
586 // returned.
587 func (c *Client) RunTransferJob(ctx context.Context, req *storagetransferpb.RunTransferJobRequest, opts ...gax.CallOption) (*RunTransferJobOperation, error) {
588 return c.internalClient.RunTransferJob(ctx, req, opts...)
589 }
590
591 // RunTransferJobOperation returns a new RunTransferJobOperation from a given name.
592 // The name must be that of a previously created RunTransferJobOperation, possibly from a different process.
593 func (c *Client) RunTransferJobOperation(name string) *RunTransferJobOperation {
594 return c.internalClient.RunTransferJobOperation(name)
595 }
596
597 // DeleteTransferJob deletes a transfer job. Deleting a transfer job sets its status to
598 // DELETED.
599 func (c *Client) DeleteTransferJob(ctx context.Context, req *storagetransferpb.DeleteTransferJobRequest, opts ...gax.CallOption) error {
600 return c.internalClient.DeleteTransferJob(ctx, req, opts...)
601 }
602
603 // CreateAgentPool creates an agent pool resource.
604 func (c *Client) CreateAgentPool(ctx context.Context, req *storagetransferpb.CreateAgentPoolRequest, opts ...gax.CallOption) (*storagetransferpb.AgentPool, error) {
605 return c.internalClient.CreateAgentPool(ctx, req, opts...)
606 }
607
608 // UpdateAgentPool updates an existing agent pool resource.
609 func (c *Client) UpdateAgentPool(ctx context.Context, req *storagetransferpb.UpdateAgentPoolRequest, opts ...gax.CallOption) (*storagetransferpb.AgentPool, error) {
610 return c.internalClient.UpdateAgentPool(ctx, req, opts...)
611 }
612
613 // GetAgentPool gets an agent pool.
614 func (c *Client) GetAgentPool(ctx context.Context, req *storagetransferpb.GetAgentPoolRequest, opts ...gax.CallOption) (*storagetransferpb.AgentPool, error) {
615 return c.internalClient.GetAgentPool(ctx, req, opts...)
616 }
617
618 // ListAgentPools lists agent pools.
619 func (c *Client) ListAgentPools(ctx context.Context, req *storagetransferpb.ListAgentPoolsRequest, opts ...gax.CallOption) *AgentPoolIterator {
620 return c.internalClient.ListAgentPools(ctx, req, opts...)
621 }
622
623 // DeleteAgentPool deletes an agent pool.
624 func (c *Client) DeleteAgentPool(ctx context.Context, req *storagetransferpb.DeleteAgentPoolRequest, opts ...gax.CallOption) error {
625 return c.internalClient.DeleteAgentPool(ctx, req, opts...)
626 }
627
628 // CancelOperation cancels a transfer. Use
629 // the transferOperations.get
630 // method to check if the cancellation succeeded or if the operation
631 // completed despite the cancel request.
632 //
633 // When you cancel an operation, the currently running transfer is
634 // interrupted. For recurring transfer jobs, the next instance of the
635 // transfer job will still run. For example, if your job is configured
636 // to run every day at 1pm and you cancel Monday’s operation at 1:05pm,
637 // Monday’s transfer
638 // will stop. However, a transfer job will still be attempted on Tuesday.
639 //
640 // This applies only to currently running operations. If an operation is
641 // not currently running, cancel does nothing.
642 //
643 // When you cancel a job, the next job computes a delta of files and may
644 // repair any inconsistent state. For instance, if you run a job every
645 // day, and today’s job found 10 new files and transferred five files
646 // before you canceled the job, tomorrow’s transfer operation will
647 // compute a new delta with the five files that were not copied today
648 // plus any new files discovered tomorrow.
649 func (c *Client) CancelOperation(ctx context.Context, req *longrunningpb.CancelOperationRequest, opts ...gax.CallOption) error {
650 return c.internalClient.CancelOperation(ctx, req, opts...)
651 }
652
653 // GetOperation is a utility method from google.longrunning.Operations.
654 func (c *Client) GetOperation(ctx context.Context, req *longrunningpb.GetOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) {
655 return c.internalClient.GetOperation(ctx, req, opts...)
656 }
657
658 // ListOperations lists transfer operations. Operations are ordered by their creation
659 // time in reverse chronological order.
660 func (c *Client) ListOperations(ctx context.Context, req *longrunningpb.ListOperationsRequest, opts ...gax.CallOption) *OperationIterator {
661 return c.internalClient.ListOperations(ctx, req, opts...)
662 }
663
664 // gRPCClient is a client for interacting with Storage Transfer API over gRPC transport.
665 //
666 // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
667 type gRPCClient struct {
668 // Connection pool of gRPC connections to the service.
669 connPool gtransport.ConnPool
670
671 // Points back to the CallOptions field of the containing Client
672 CallOptions **CallOptions
673
674 // The gRPC API client.
675 client storagetransferpb.StorageTransferServiceClient
676
677 // LROClient is used internally to handle long-running operations.
678 // It is exposed so that its CallOptions can be modified if required.
679 // Users should not Close this client.
680 LROClient **lroauto.OperationsClient
681
682 operationsClient longrunningpb.OperationsClient
683
684 // The x-goog-* metadata to be sent with each request.
685 xGoogHeaders []string
686
687 logger *slog.Logger
688 }
689
690 // NewClient creates a new storage transfer service client based on gRPC.
691 // The returned client must be Closed when it is done being used to clean up its underlying connections.
692 //
693 // Storage Transfer Service and its protos.
694 // Transfers data between between Google Cloud Storage buckets or from a data
695 // source external to Google to a Cloud Storage bucket.
696 func NewClient(ctx context.Context, opts ...option.ClientOption) (*Client, error) {
697 clientOpts := defaultGRPCClientOptions()
698 if newClientHook != nil {
699 hookOpts, err := newClientHook(ctx, clientHookParams{})
700 if err != nil {
701 return nil, err
702 }
703 clientOpts = append(clientOpts, hookOpts...)
704 }
705
706 connPool, err := gtransport.DialPool(ctx, append(clientOpts, opts...)...)
707 if err != nil {
708 return nil, err
709 }
710 client := Client{CallOptions: defaultCallOptions()}
711
712 c := &gRPCClient{
713 connPool: connPool,
714 client: storagetransferpb.NewStorageTransferServiceClient(connPool),
715 CallOptions: &client.CallOptions,
716 logger: internaloption.GetLogger(opts),
717 operationsClient: longrunningpb.NewOperationsClient(connPool),
718 }
719 c.setGoogleClientInfo()
720
721 client.internalClient = c
722
723 client.LROClient, err = lroauto.NewOperationsClient(ctx, gtransport.WithConnPool(connPool))
724 if err != nil {
725 // This error "should not happen", since we are just reusing old connection pool
726 // and never actually need to dial.
727 // If this does happen, we could leak connp. However, we cannot close conn:
728 // If the user invoked the constructor with option.WithGRPCConn,
729 // we would close a connection that's still in use.
730 // TODO: investigate error conditions.
731 return nil, err
732 }
733 c.LROClient = &client.LROClient
734 return &client, nil
735 }
736
737 // Connection returns a connection to the API service.
738 //
739 // Deprecated: Connections are now pooled so this method does not always
740 // return the same resource.
741 func (c *gRPCClient) Connection() *grpc.ClientConn {
742 return c.connPool.Conn()
743 }
744
745 // setGoogleClientInfo sets the name and version of the application in
746 // the `x-goog-api-client` header passed on each request. Intended for
747 // use by Google-written clients.
748 func (c *gRPCClient) setGoogleClientInfo(keyval ...string) {
749 kv := append([]string{"gl-go", gax.GoVersion}, keyval...)
750 kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "grpc", grpc.Version, "pb", protoVersion)
751 c.xGoogHeaders = []string{
752 "x-goog-api-client", gax.XGoogHeader(kv...),
753 }
754 }
755
756 // Close closes the connection to the API service. The user should invoke this when
757 // the client is no longer required.
758 func (c *gRPCClient) Close() error {
759 return c.connPool.Close()
760 }
761
762 // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
763 type restClient struct {
764 // The http endpoint to connect to.
765 endpoint string
766
767 // The http client.
768 httpClient *http.Client
769
770 // LROClient is used internally to handle long-running operations.
771 // It is exposed so that its CallOptions can be modified if required.
772 // Users should not Close this client.
773 LROClient **lroauto.OperationsClient
774
775 // The x-goog-* headers to be sent with each request.
776 xGoogHeaders []string
777
778 // Points back to the CallOptions field of the containing Client
779 CallOptions **CallOptions
780
781 logger *slog.Logger
782 }
783
784 // NewRESTClient creates a new storage transfer service rest client.
785 //
786 // Storage Transfer Service and its protos.
787 // Transfers data between between Google Cloud Storage buckets or from a data
788 // source external to Google to a Cloud Storage bucket.
789 func NewRESTClient(ctx context.Context, opts ...option.ClientOption) (*Client, error) {
790 clientOpts := append(defaultRESTClientOptions(), opts...)
791 httpClient, endpoint, err := httptransport.NewClient(ctx, clientOpts...)
792 if err != nil {
793 return nil, err
794 }
795
796 callOpts := defaultRESTCallOptions()
797 c := &restClient{
798 endpoint: endpoint,
799 httpClient: httpClient,
800 CallOptions: &callOpts,
801 logger: internaloption.GetLogger(opts),
802 }
803 c.setGoogleClientInfo()
804
805 lroOpts := []option.ClientOption{
806 option.WithHTTPClient(httpClient),
807 option.WithEndpoint(endpoint),
808 }
809 opClient, err := lroauto.NewOperationsRESTClient(ctx, lroOpts...)
810 if err != nil {
811 return nil, err
812 }
813 c.LROClient = &opClient
814
815 return &Client{internalClient: c, CallOptions: callOpts}, nil
816 }
817
818 func defaultRESTClientOptions() []option.ClientOption {
819 return []option.ClientOption{
820 internaloption.WithDefaultEndpoint("https://storagetransfer.googleapis.com"),
821 internaloption.WithDefaultEndpointTemplate("https://storagetransfer.UNIVERSE_DOMAIN"),
822 internaloption.WithDefaultMTLSEndpoint("https://storagetransfer.mtls.googleapis.com"),
823 internaloption.WithDefaultUniverseDomain("googleapis.com"),
824 internaloption.WithDefaultAudience("https://storagetransfer.googleapis.com/"),
825 internaloption.WithDefaultScopes(DefaultAuthScopes()...),
826 internaloption.EnableNewAuthLibrary(),
827 }
828 }
829
830 // setGoogleClientInfo sets the name and version of the application in
831 // the `x-goog-api-client` header passed on each request. Intended for
832 // use by Google-written clients.
833 func (c *restClient) setGoogleClientInfo(keyval ...string) {
834 kv := append([]string{"gl-go", gax.GoVersion}, keyval...)
835 kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "rest", "UNKNOWN", "pb", protoVersion)
836 c.xGoogHeaders = []string{
837 "x-goog-api-client", gax.XGoogHeader(kv...),
838 }
839 }
840
841 // Close closes the connection to the API service. The user should invoke this when
842 // the client is no longer required.
843 func (c *restClient) Close() error {
844 // Replace httpClient with nil to force cleanup.
845 c.httpClient = nil
846 return nil
847 }
848
849 // Connection returns a connection to the API service.
850 //
851 // Deprecated: This method always returns nil.
852 func (c *restClient) Connection() *grpc.ClientConn {
853 return nil
854 }
855 func (c *gRPCClient) GetGoogleServiceAccount(ctx context.Context, req *storagetransferpb.GetGoogleServiceAccountRequest, opts ...gax.CallOption) (*storagetransferpb.GoogleServiceAccount, error) {
856 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "project_id", url.QueryEscape(req.GetProjectId()))}
857
858 hds = append(c.xGoogHeaders, hds...)
859 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
860 opts = append((*c.CallOptions).GetGoogleServiceAccount[0:len((*c.CallOptions).GetGoogleServiceAccount):len((*c.CallOptions).GetGoogleServiceAccount)], opts...)
861 var resp *storagetransferpb.GoogleServiceAccount
862 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
863 var err error
864 resp, err = executeRPC(ctx, c.client.GetGoogleServiceAccount, req, settings.GRPC, c.logger, "GetGoogleServiceAccount")
865 return err
866 }, opts...)
867 if err != nil {
868 return nil, err
869 }
870 return resp, nil
871 }
872
873 func (c *gRPCClient) CreateTransferJob(ctx context.Context, req *storagetransferpb.CreateTransferJobRequest, opts ...gax.CallOption) (*storagetransferpb.TransferJob, error) {
874 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, c.xGoogHeaders...)
875 opts = append((*c.CallOptions).CreateTransferJob[0:len((*c.CallOptions).CreateTransferJob):len((*c.CallOptions).CreateTransferJob)], opts...)
876 var resp *storagetransferpb.TransferJob
877 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
878 var err error
879 resp, err = executeRPC(ctx, c.client.CreateTransferJob, req, settings.GRPC, c.logger, "CreateTransferJob")
880 return err
881 }, opts...)
882 if err != nil {
883 return nil, err
884 }
885 return resp, nil
886 }
887
888 func (c *gRPCClient) UpdateTransferJob(ctx context.Context, req *storagetransferpb.UpdateTransferJobRequest, opts ...gax.CallOption) (*storagetransferpb.TransferJob, error) {
889 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "job_name", url.QueryEscape(req.GetJobName()))}
890
891 hds = append(c.xGoogHeaders, hds...)
892 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
893 opts = append((*c.CallOptions).UpdateTransferJob[0:len((*c.CallOptions).UpdateTransferJob):len((*c.CallOptions).UpdateTransferJob)], opts...)
894 var resp *storagetransferpb.TransferJob
895 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
896 var err error
897 resp, err = executeRPC(ctx, c.client.UpdateTransferJob, req, settings.GRPC, c.logger, "UpdateTransferJob")
898 return err
899 }, opts...)
900 if err != nil {
901 return nil, err
902 }
903 return resp, nil
904 }
905
906 func (c *gRPCClient) GetTransferJob(ctx context.Context, req *storagetransferpb.GetTransferJobRequest, opts ...gax.CallOption) (*storagetransferpb.TransferJob, error) {
907 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "job_name", url.QueryEscape(req.GetJobName()))}
908
909 hds = append(c.xGoogHeaders, hds...)
910 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
911 opts = append((*c.CallOptions).GetTransferJob[0:len((*c.CallOptions).GetTransferJob):len((*c.CallOptions).GetTransferJob)], opts...)
912 var resp *storagetransferpb.TransferJob
913 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
914 var err error
915 resp, err = executeRPC(ctx, c.client.GetTransferJob, req, settings.GRPC, c.logger, "GetTransferJob")
916 return err
917 }, opts...)
918 if err != nil {
919 return nil, err
920 }
921 return resp, nil
922 }
923
924 func (c *gRPCClient) ListTransferJobs(ctx context.Context, req *storagetransferpb.ListTransferJobsRequest, opts ...gax.CallOption) *TransferJobIterator {
925 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, c.xGoogHeaders...)
926 opts = append((*c.CallOptions).ListTransferJobs[0:len((*c.CallOptions).ListTransferJobs):len((*c.CallOptions).ListTransferJobs)], opts...)
927 it := &TransferJobIterator{}
928 req = proto.Clone(req).(*storagetransferpb.ListTransferJobsRequest)
929 it.InternalFetch = func(pageSize int, pageToken string) ([]*storagetransferpb.TransferJob, string, error) {
930 resp := &storagetransferpb.ListTransferJobsResponse{}
931 if pageToken != "" {
932 req.PageToken = pageToken
933 }
934 if pageSize > math.MaxInt32 {
935 req.PageSize = math.MaxInt32
936 } else if pageSize != 0 {
937 req.PageSize = int32(pageSize)
938 }
939 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
940 var err error
941 resp, err = executeRPC(ctx, c.client.ListTransferJobs, req, settings.GRPC, c.logger, "ListTransferJobs")
942 return err
943 }, opts...)
944 if err != nil {
945 return nil, "", err
946 }
947
948 it.Response = resp
949 return resp.GetTransferJobs(), resp.GetNextPageToken(), nil
950 }
951 fetch := func(pageSize int, pageToken string) (string, error) {
952 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
953 if err != nil {
954 return "", err
955 }
956 it.items = append(it.items, items...)
957 return nextPageToken, nil
958 }
959
960 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
961 it.pageInfo.MaxSize = int(req.GetPageSize())
962 it.pageInfo.Token = req.GetPageToken()
963
964 return it
965 }
966
967 func (c *gRPCClient) PauseTransferOperation(ctx context.Context, req *storagetransferpb.PauseTransferOperationRequest, opts ...gax.CallOption) error {
968 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
969
970 hds = append(c.xGoogHeaders, hds...)
971 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
972 opts = append((*c.CallOptions).PauseTransferOperation[0:len((*c.CallOptions).PauseTransferOperation):len((*c.CallOptions).PauseTransferOperation)], opts...)
973 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
974 var err error
975 _, err = executeRPC(ctx, c.client.PauseTransferOperation, req, settings.GRPC, c.logger, "PauseTransferOperation")
976 return err
977 }, opts...)
978 return err
979 }
980
981 func (c *gRPCClient) ResumeTransferOperation(ctx context.Context, req *storagetransferpb.ResumeTransferOperationRequest, opts ...gax.CallOption) error {
982 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
983
984 hds = append(c.xGoogHeaders, hds...)
985 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
986 opts = append((*c.CallOptions).ResumeTransferOperation[0:len((*c.CallOptions).ResumeTransferOperation):len((*c.CallOptions).ResumeTransferOperation)], opts...)
987 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
988 var err error
989 _, err = executeRPC(ctx, c.client.ResumeTransferOperation, req, settings.GRPC, c.logger, "ResumeTransferOperation")
990 return err
991 }, opts...)
992 return err
993 }
994
995 func (c *gRPCClient) RunTransferJob(ctx context.Context, req *storagetransferpb.RunTransferJobRequest, opts ...gax.CallOption) (*RunTransferJobOperation, error) {
996 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "job_name", url.QueryEscape(req.GetJobName()))}
997
998 hds = append(c.xGoogHeaders, hds...)
999 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
1000 opts = append((*c.CallOptions).RunTransferJob[0:len((*c.CallOptions).RunTransferJob):len((*c.CallOptions).RunTransferJob)], opts...)
1001 var resp *longrunningpb.Operation
1002 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1003 var err error
1004 resp, err = executeRPC(ctx, c.client.RunTransferJob, req, settings.GRPC, c.logger, "RunTransferJob")
1005 return err
1006 }, opts...)
1007 if err != nil {
1008 return nil, err
1009 }
1010 return &RunTransferJobOperation{
1011 lro: longrunning.InternalNewOperation(*c.LROClient, resp),
1012 }, nil
1013 }
1014
1015 func (c *gRPCClient) DeleteTransferJob(ctx context.Context, req *storagetransferpb.DeleteTransferJobRequest, opts ...gax.CallOption) error {
1016 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "job_name", url.QueryEscape(req.GetJobName()))}
1017
1018 hds = append(c.xGoogHeaders, hds...)
1019 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
1020 opts = append((*c.CallOptions).DeleteTransferJob[0:len((*c.CallOptions).DeleteTransferJob):len((*c.CallOptions).DeleteTransferJob)], opts...)
1021 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1022 var err error
1023 _, err = executeRPC(ctx, c.client.DeleteTransferJob, req, settings.GRPC, c.logger, "DeleteTransferJob")
1024 return err
1025 }, opts...)
1026 return err
1027 }
1028
1029 func (c *gRPCClient) CreateAgentPool(ctx context.Context, req *storagetransferpb.CreateAgentPoolRequest, opts ...gax.CallOption) (*storagetransferpb.AgentPool, error) {
1030 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "project_id", url.QueryEscape(req.GetProjectId()))}
1031
1032 hds = append(c.xGoogHeaders, hds...)
1033 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
1034 opts = append((*c.CallOptions).CreateAgentPool[0:len((*c.CallOptions).CreateAgentPool):len((*c.CallOptions).CreateAgentPool)], opts...)
1035 var resp *storagetransferpb.AgentPool
1036 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1037 var err error
1038 resp, err = executeRPC(ctx, c.client.CreateAgentPool, req, settings.GRPC, c.logger, "CreateAgentPool")
1039 return err
1040 }, opts...)
1041 if err != nil {
1042 return nil, err
1043 }
1044 return resp, nil
1045 }
1046
1047 func (c *gRPCClient) UpdateAgentPool(ctx context.Context, req *storagetransferpb.UpdateAgentPoolRequest, opts ...gax.CallOption) (*storagetransferpb.AgentPool, error) {
1048 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "agent_pool.name", url.QueryEscape(req.GetAgentPool().GetName()))}
1049
1050 hds = append(c.xGoogHeaders, hds...)
1051 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
1052 opts = append((*c.CallOptions).UpdateAgentPool[0:len((*c.CallOptions).UpdateAgentPool):len((*c.CallOptions).UpdateAgentPool)], opts...)
1053 var resp *storagetransferpb.AgentPool
1054 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1055 var err error
1056 resp, err = executeRPC(ctx, c.client.UpdateAgentPool, req, settings.GRPC, c.logger, "UpdateAgentPool")
1057 return err
1058 }, opts...)
1059 if err != nil {
1060 return nil, err
1061 }
1062 return resp, nil
1063 }
1064
1065 func (c *gRPCClient) GetAgentPool(ctx context.Context, req *storagetransferpb.GetAgentPoolRequest, opts ...gax.CallOption) (*storagetransferpb.AgentPool, error) {
1066 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
1067
1068 hds = append(c.xGoogHeaders, hds...)
1069 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
1070 opts = append((*c.CallOptions).GetAgentPool[0:len((*c.CallOptions).GetAgentPool):len((*c.CallOptions).GetAgentPool)], opts...)
1071 var resp *storagetransferpb.AgentPool
1072 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1073 var err error
1074 resp, err = executeRPC(ctx, c.client.GetAgentPool, req, settings.GRPC, c.logger, "GetAgentPool")
1075 return err
1076 }, opts...)
1077 if err != nil {
1078 return nil, err
1079 }
1080 return resp, nil
1081 }
1082
1083 func (c *gRPCClient) ListAgentPools(ctx context.Context, req *storagetransferpb.ListAgentPoolsRequest, opts ...gax.CallOption) *AgentPoolIterator {
1084 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "project_id", url.QueryEscape(req.GetProjectId()))}
1085
1086 hds = append(c.xGoogHeaders, hds...)
1087 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
1088 opts = append((*c.CallOptions).ListAgentPools[0:len((*c.CallOptions).ListAgentPools):len((*c.CallOptions).ListAgentPools)], opts...)
1089 it := &AgentPoolIterator{}
1090 req = proto.Clone(req).(*storagetransferpb.ListAgentPoolsRequest)
1091 it.InternalFetch = func(pageSize int, pageToken string) ([]*storagetransferpb.AgentPool, string, error) {
1092 resp := &storagetransferpb.ListAgentPoolsResponse{}
1093 if pageToken != "" {
1094 req.PageToken = pageToken
1095 }
1096 if pageSize > math.MaxInt32 {
1097 req.PageSize = math.MaxInt32
1098 } else if pageSize != 0 {
1099 req.PageSize = int32(pageSize)
1100 }
1101 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1102 var err error
1103 resp, err = executeRPC(ctx, c.client.ListAgentPools, req, settings.GRPC, c.logger, "ListAgentPools")
1104 return err
1105 }, opts...)
1106 if err != nil {
1107 return nil, "", err
1108 }
1109
1110 it.Response = resp
1111 return resp.GetAgentPools(), resp.GetNextPageToken(), nil
1112 }
1113 fetch := func(pageSize int, pageToken string) (string, error) {
1114 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
1115 if err != nil {
1116 return "", err
1117 }
1118 it.items = append(it.items, items...)
1119 return nextPageToken, nil
1120 }
1121
1122 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
1123 it.pageInfo.MaxSize = int(req.GetPageSize())
1124 it.pageInfo.Token = req.GetPageToken()
1125
1126 return it
1127 }
1128
1129 func (c *gRPCClient) DeleteAgentPool(ctx context.Context, req *storagetransferpb.DeleteAgentPoolRequest, opts ...gax.CallOption) error {
1130 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
1131
1132 hds = append(c.xGoogHeaders, hds...)
1133 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
1134 opts = append((*c.CallOptions).DeleteAgentPool[0:len((*c.CallOptions).DeleteAgentPool):len((*c.CallOptions).DeleteAgentPool)], opts...)
1135 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1136 var err error
1137 _, err = executeRPC(ctx, c.client.DeleteAgentPool, req, settings.GRPC, c.logger, "DeleteAgentPool")
1138 return err
1139 }, opts...)
1140 return err
1141 }
1142
1143 func (c *gRPCClient) CancelOperation(ctx context.Context, req *longrunningpb.CancelOperationRequest, opts ...gax.CallOption) error {
1144 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
1145
1146 hds = append(c.xGoogHeaders, hds...)
1147 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
1148 opts = append((*c.CallOptions).CancelOperation[0:len((*c.CallOptions).CancelOperation):len((*c.CallOptions).CancelOperation)], opts...)
1149 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1150 var err error
1151 _, err = executeRPC(ctx, c.operationsClient.CancelOperation, req, settings.GRPC, c.logger, "CancelOperation")
1152 return err
1153 }, opts...)
1154 return err
1155 }
1156
1157 func (c *gRPCClient) GetOperation(ctx context.Context, req *longrunningpb.GetOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) {
1158 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
1159
1160 hds = append(c.xGoogHeaders, hds...)
1161 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
1162 opts = append((*c.CallOptions).GetOperation[0:len((*c.CallOptions).GetOperation):len((*c.CallOptions).GetOperation)], opts...)
1163 var resp *longrunningpb.Operation
1164 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1165 var err error
1166 resp, err = executeRPC(ctx, c.operationsClient.GetOperation, req, settings.GRPC, c.logger, "GetOperation")
1167 return err
1168 }, opts...)
1169 if err != nil {
1170 return nil, err
1171 }
1172 return resp, nil
1173 }
1174
1175 func (c *gRPCClient) ListOperations(ctx context.Context, req *longrunningpb.ListOperationsRequest, opts ...gax.CallOption) *OperationIterator {
1176 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
1177
1178 hds = append(c.xGoogHeaders, hds...)
1179 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
1180 opts = append((*c.CallOptions).ListOperations[0:len((*c.CallOptions).ListOperations):len((*c.CallOptions).ListOperations)], opts...)
1181 it := &OperationIterator{}
1182 req = proto.Clone(req).(*longrunningpb.ListOperationsRequest)
1183 it.InternalFetch = func(pageSize int, pageToken string) ([]*longrunningpb.Operation, string, error) {
1184 resp := &longrunningpb.ListOperationsResponse{}
1185 if pageToken != "" {
1186 req.PageToken = pageToken
1187 }
1188 if pageSize > math.MaxInt32 {
1189 req.PageSize = math.MaxInt32
1190 } else if pageSize != 0 {
1191 req.PageSize = int32(pageSize)
1192 }
1193 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1194 var err error
1195 resp, err = executeRPC(ctx, c.operationsClient.ListOperations, req, settings.GRPC, c.logger, "ListOperations")
1196 return err
1197 }, opts...)
1198 if err != nil {
1199 return nil, "", err
1200 }
1201
1202 it.Response = resp
1203 return resp.GetOperations(), resp.GetNextPageToken(), nil
1204 }
1205 fetch := func(pageSize int, pageToken string) (string, error) {
1206 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
1207 if err != nil {
1208 return "", err
1209 }
1210 it.items = append(it.items, items...)
1211 return nextPageToken, nil
1212 }
1213
1214 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
1215 it.pageInfo.MaxSize = int(req.GetPageSize())
1216 it.pageInfo.Token = req.GetPageToken()
1217
1218 return it
1219 }
1220
1221 // GetGoogleServiceAccount returns the Google service account that is used by Storage Transfer
1222 // Service to access buckets in the project where transfers
1223 // run or in other projects. Each Google service account is associated
1224 // with one Google Cloud project. Users
1225 // should add this service account to the Google Cloud Storage bucket
1226 // ACLs to grant access to Storage Transfer Service. This service
1227 // account is created and owned by Storage Transfer Service and can
1228 // only be used by Storage Transfer Service.
1229 func (c *restClient) GetGoogleServiceAccount(ctx context.Context, req *storagetransferpb.GetGoogleServiceAccountRequest, opts ...gax.CallOption) (*storagetransferpb.GoogleServiceAccount, error) {
1230 baseUrl, err := url.Parse(c.endpoint)
1231 if err != nil {
1232 return nil, err
1233 }
1234 baseUrl.Path += fmt.Sprintf("/v1/googleServiceAccounts/%v", req.GetProjectId())
1235
1236 params := url.Values{}
1237 params.Add("$alt", "json;enum-encoding=int")
1238
1239 baseUrl.RawQuery = params.Encode()
1240
1241 // Build HTTP headers from client and context metadata.
1242 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "project_id", url.QueryEscape(req.GetProjectId()))}
1243
1244 hds = append(c.xGoogHeaders, hds...)
1245 hds = append(hds, "Content-Type", "application/json")
1246 headers := gax.BuildHeaders(ctx, hds...)
1247 opts = append((*c.CallOptions).GetGoogleServiceAccount[0:len((*c.CallOptions).GetGoogleServiceAccount):len((*c.CallOptions).GetGoogleServiceAccount)], opts...)
1248 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
1249 resp := &storagetransferpb.GoogleServiceAccount{}
1250 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1251 if settings.Path != "" {
1252 baseUrl.Path = settings.Path
1253 }
1254 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
1255 if err != nil {
1256 return err
1257 }
1258 httpReq = httpReq.WithContext(ctx)
1259 httpReq.Header = headers
1260
1261 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "GetGoogleServiceAccount")
1262 if err != nil {
1263 return err
1264 }
1265
1266 if err := unm.Unmarshal(buf, resp); err != nil {
1267 return err
1268 }
1269
1270 return nil
1271 }, opts...)
1272 if e != nil {
1273 return nil, e
1274 }
1275 return resp, nil
1276 }
1277
1278 // CreateTransferJob creates a transfer job that runs periodically.
1279 func (c *restClient) CreateTransferJob(ctx context.Context, req *storagetransferpb.CreateTransferJobRequest, opts ...gax.CallOption) (*storagetransferpb.TransferJob, error) {
1280 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
1281 body := req.GetTransferJob()
1282 jsonReq, err := m.Marshal(body)
1283 if err != nil {
1284 return nil, err
1285 }
1286
1287 baseUrl, err := url.Parse(c.endpoint)
1288 if err != nil {
1289 return nil, err
1290 }
1291 baseUrl.Path += fmt.Sprintf("/v1/transferJobs")
1292
1293 params := url.Values{}
1294 params.Add("$alt", "json;enum-encoding=int")
1295
1296 baseUrl.RawQuery = params.Encode()
1297
1298 // Build HTTP headers from client and context metadata.
1299 hds := append(c.xGoogHeaders, "Content-Type", "application/json")
1300 headers := gax.BuildHeaders(ctx, hds...)
1301 opts = append((*c.CallOptions).CreateTransferJob[0:len((*c.CallOptions).CreateTransferJob):len((*c.CallOptions).CreateTransferJob)], opts...)
1302 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
1303 resp := &storagetransferpb.TransferJob{}
1304 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1305 if settings.Path != "" {
1306 baseUrl.Path = settings.Path
1307 }
1308 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
1309 if err != nil {
1310 return err
1311 }
1312 httpReq = httpReq.WithContext(ctx)
1313 httpReq.Header = headers
1314
1315 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "CreateTransferJob")
1316 if err != nil {
1317 return err
1318 }
1319
1320 if err := unm.Unmarshal(buf, resp); err != nil {
1321 return err
1322 }
1323
1324 return nil
1325 }, opts...)
1326 if e != nil {
1327 return nil, e
1328 }
1329 return resp, nil
1330 }
1331
1332 // UpdateTransferJob updates a transfer job. Updating a job’s transfer spec does not affect
1333 // transfer operations that are running already.
1334 //
1335 // Note: The job’s status
1336 // field can be modified using this RPC (for example, to set a job’s status to
1337 // DELETED,
1338 // DISABLED, or
1339 // ENABLED).
1340 func (c *restClient) UpdateTransferJob(ctx context.Context, req *storagetransferpb.UpdateTransferJobRequest, opts ...gax.CallOption) (*storagetransferpb.TransferJob, error) {
1341 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
1342 jsonReq, err := m.Marshal(req)
1343 if err != nil {
1344 return nil, err
1345 }
1346
1347 baseUrl, err := url.Parse(c.endpoint)
1348 if err != nil {
1349 return nil, err
1350 }
1351 baseUrl.Path += fmt.Sprintf("/v1/%v", req.GetJobName())
1352
1353 params := url.Values{}
1354 params.Add("$alt", "json;enum-encoding=int")
1355
1356 baseUrl.RawQuery = params.Encode()
1357
1358 // Build HTTP headers from client and context metadata.
1359 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "job_name", url.QueryEscape(req.GetJobName()))}
1360
1361 hds = append(c.xGoogHeaders, hds...)
1362 hds = append(hds, "Content-Type", "application/json")
1363 headers := gax.BuildHeaders(ctx, hds...)
1364 opts = append((*c.CallOptions).UpdateTransferJob[0:len((*c.CallOptions).UpdateTransferJob):len((*c.CallOptions).UpdateTransferJob)], opts...)
1365 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
1366 resp := &storagetransferpb.TransferJob{}
1367 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1368 if settings.Path != "" {
1369 baseUrl.Path = settings.Path
1370 }
1371 httpReq, err := http.NewRequest("PATCH", baseUrl.String(), bytes.NewReader(jsonReq))
1372 if err != nil {
1373 return err
1374 }
1375 httpReq = httpReq.WithContext(ctx)
1376 httpReq.Header = headers
1377
1378 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "UpdateTransferJob")
1379 if err != nil {
1380 return err
1381 }
1382
1383 if err := unm.Unmarshal(buf, resp); err != nil {
1384 return err
1385 }
1386
1387 return nil
1388 }, opts...)
1389 if e != nil {
1390 return nil, e
1391 }
1392 return resp, nil
1393 }
1394
1395 // GetTransferJob gets a transfer job.
1396 func (c *restClient) GetTransferJob(ctx context.Context, req *storagetransferpb.GetTransferJobRequest, opts ...gax.CallOption) (*storagetransferpb.TransferJob, error) {
1397 baseUrl, err := url.Parse(c.endpoint)
1398 if err != nil {
1399 return nil, err
1400 }
1401 baseUrl.Path += fmt.Sprintf("/v1/%v", req.GetJobName())
1402
1403 params := url.Values{}
1404 params.Add("$alt", "json;enum-encoding=int")
1405 params.Add("projectId", fmt.Sprintf("%v", req.GetProjectId()))
1406
1407 baseUrl.RawQuery = params.Encode()
1408
1409 // Build HTTP headers from client and context metadata.
1410 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "job_name", url.QueryEscape(req.GetJobName()))}
1411
1412 hds = append(c.xGoogHeaders, hds...)
1413 hds = append(hds, "Content-Type", "application/json")
1414 headers := gax.BuildHeaders(ctx, hds...)
1415 opts = append((*c.CallOptions).GetTransferJob[0:len((*c.CallOptions).GetTransferJob):len((*c.CallOptions).GetTransferJob)], opts...)
1416 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
1417 resp := &storagetransferpb.TransferJob{}
1418 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1419 if settings.Path != "" {
1420 baseUrl.Path = settings.Path
1421 }
1422 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
1423 if err != nil {
1424 return err
1425 }
1426 httpReq = httpReq.WithContext(ctx)
1427 httpReq.Header = headers
1428
1429 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "GetTransferJob")
1430 if err != nil {
1431 return err
1432 }
1433
1434 if err := unm.Unmarshal(buf, resp); err != nil {
1435 return err
1436 }
1437
1438 return nil
1439 }, opts...)
1440 if e != nil {
1441 return nil, e
1442 }
1443 return resp, nil
1444 }
1445
1446 // ListTransferJobs lists transfer jobs.
1447 func (c *restClient) ListTransferJobs(ctx context.Context, req *storagetransferpb.ListTransferJobsRequest, opts ...gax.CallOption) *TransferJobIterator {
1448 it := &TransferJobIterator{}
1449 req = proto.Clone(req).(*storagetransferpb.ListTransferJobsRequest)
1450 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
1451 it.InternalFetch = func(pageSize int, pageToken string) ([]*storagetransferpb.TransferJob, string, error) {
1452 resp := &storagetransferpb.ListTransferJobsResponse{}
1453 if pageToken != "" {
1454 req.PageToken = pageToken
1455 }
1456 if pageSize > math.MaxInt32 {
1457 req.PageSize = math.MaxInt32
1458 } else if pageSize != 0 {
1459 req.PageSize = int32(pageSize)
1460 }
1461 baseUrl, err := url.Parse(c.endpoint)
1462 if err != nil {
1463 return nil, "", err
1464 }
1465 baseUrl.Path += fmt.Sprintf("/v1/transferJobs")
1466
1467 params := url.Values{}
1468 params.Add("$alt", "json;enum-encoding=int")
1469 params.Add("filter", fmt.Sprintf("%v", req.GetFilter()))
1470 if req.GetPageSize() != 0 {
1471 params.Add("pageSize", fmt.Sprintf("%v", req.GetPageSize()))
1472 }
1473 if req.GetPageToken() != "" {
1474 params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken()))
1475 }
1476
1477 baseUrl.RawQuery = params.Encode()
1478
1479 // Build HTTP headers from client and context metadata.
1480 hds := append(c.xGoogHeaders, "Content-Type", "application/json")
1481 headers := gax.BuildHeaders(ctx, hds...)
1482 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1483 if settings.Path != "" {
1484 baseUrl.Path = settings.Path
1485 }
1486 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
1487 if err != nil {
1488 return err
1489 }
1490 httpReq.Header = headers
1491
1492 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "ListTransferJobs")
1493 if err != nil {
1494 return err
1495 }
1496 if err := unm.Unmarshal(buf, resp); err != nil {
1497 return err
1498 }
1499
1500 return nil
1501 }, opts...)
1502 if e != nil {
1503 return nil, "", e
1504 }
1505 it.Response = resp
1506 return resp.GetTransferJobs(), resp.GetNextPageToken(), nil
1507 }
1508
1509 fetch := func(pageSize int, pageToken string) (string, error) {
1510 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
1511 if err != nil {
1512 return "", err
1513 }
1514 it.items = append(it.items, items...)
1515 return nextPageToken, nil
1516 }
1517
1518 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
1519 it.pageInfo.MaxSize = int(req.GetPageSize())
1520 it.pageInfo.Token = req.GetPageToken()
1521
1522 return it
1523 }
1524
1525 // PauseTransferOperation pauses a transfer operation.
1526 func (c *restClient) PauseTransferOperation(ctx context.Context, req *storagetransferpb.PauseTransferOperationRequest, opts ...gax.CallOption) error {
1527 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
1528 jsonReq, err := m.Marshal(req)
1529 if err != nil {
1530 return err
1531 }
1532
1533 baseUrl, err := url.Parse(c.endpoint)
1534 if err != nil {
1535 return err
1536 }
1537 baseUrl.Path += fmt.Sprintf("/v1/%v:pause", req.GetName())
1538
1539 params := url.Values{}
1540 params.Add("$alt", "json;enum-encoding=int")
1541
1542 baseUrl.RawQuery = params.Encode()
1543
1544 // Build HTTP headers from client and context metadata.
1545 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
1546
1547 hds = append(c.xGoogHeaders, hds...)
1548 hds = append(hds, "Content-Type", "application/json")
1549 headers := gax.BuildHeaders(ctx, hds...)
1550 return gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1551 if settings.Path != "" {
1552 baseUrl.Path = settings.Path
1553 }
1554 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
1555 if err != nil {
1556 return err
1557 }
1558 httpReq = httpReq.WithContext(ctx)
1559 httpReq.Header = headers
1560
1561 _, err = executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "PauseTransferOperation")
1562 return err
1563 }, opts...)
1564 }
1565
1566 // ResumeTransferOperation resumes a transfer operation that is paused.
1567 func (c *restClient) ResumeTransferOperation(ctx context.Context, req *storagetransferpb.ResumeTransferOperationRequest, opts ...gax.CallOption) error {
1568 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
1569 jsonReq, err := m.Marshal(req)
1570 if err != nil {
1571 return err
1572 }
1573
1574 baseUrl, err := url.Parse(c.endpoint)
1575 if err != nil {
1576 return err
1577 }
1578 baseUrl.Path += fmt.Sprintf("/v1/%v:resume", req.GetName())
1579
1580 params := url.Values{}
1581 params.Add("$alt", "json;enum-encoding=int")
1582
1583 baseUrl.RawQuery = params.Encode()
1584
1585 // Build HTTP headers from client and context metadata.
1586 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
1587
1588 hds = append(c.xGoogHeaders, hds...)
1589 hds = append(hds, "Content-Type", "application/json")
1590 headers := gax.BuildHeaders(ctx, hds...)
1591 return gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1592 if settings.Path != "" {
1593 baseUrl.Path = settings.Path
1594 }
1595 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
1596 if err != nil {
1597 return err
1598 }
1599 httpReq = httpReq.WithContext(ctx)
1600 httpReq.Header = headers
1601
1602 _, err = executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "ResumeTransferOperation")
1603 return err
1604 }, opts...)
1605 }
1606
1607 // RunTransferJob starts a new operation for the specified transfer job.
1608 // A TransferJob has a maximum of one active TransferOperation. If this
1609 // method is called while a TransferOperation is active, an error is
1610 // returned.
1611 func (c *restClient) RunTransferJob(ctx context.Context, req *storagetransferpb.RunTransferJobRequest, opts ...gax.CallOption) (*RunTransferJobOperation, error) {
1612 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
1613 jsonReq, err := m.Marshal(req)
1614 if err != nil {
1615 return nil, err
1616 }
1617
1618 baseUrl, err := url.Parse(c.endpoint)
1619 if err != nil {
1620 return nil, err
1621 }
1622 baseUrl.Path += fmt.Sprintf("/v1/%v:run", req.GetJobName())
1623
1624 params := url.Values{}
1625 params.Add("$alt", "json;enum-encoding=int")
1626
1627 baseUrl.RawQuery = params.Encode()
1628
1629 // Build HTTP headers from client and context metadata.
1630 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "job_name", url.QueryEscape(req.GetJobName()))}
1631
1632 hds = append(c.xGoogHeaders, hds...)
1633 hds = append(hds, "Content-Type", "application/json")
1634 headers := gax.BuildHeaders(ctx, hds...)
1635 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
1636 resp := &longrunningpb.Operation{}
1637 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1638 if settings.Path != "" {
1639 baseUrl.Path = settings.Path
1640 }
1641 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
1642 if err != nil {
1643 return err
1644 }
1645 httpReq = httpReq.WithContext(ctx)
1646 httpReq.Header = headers
1647
1648 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "RunTransferJob")
1649 if err != nil {
1650 return err
1651 }
1652 if err := unm.Unmarshal(buf, resp); err != nil {
1653 return err
1654 }
1655
1656 return nil
1657 }, opts...)
1658 if e != nil {
1659 return nil, e
1660 }
1661
1662 override := fmt.Sprintf("/v1/%s", resp.GetName())
1663 return &RunTransferJobOperation{
1664 lro: longrunning.InternalNewOperation(*c.LROClient, resp),
1665 pollPath: override,
1666 }, nil
1667 }
1668
1669 // DeleteTransferJob deletes a transfer job. Deleting a transfer job sets its status to
1670 // DELETED.
1671 func (c *restClient) DeleteTransferJob(ctx context.Context, req *storagetransferpb.DeleteTransferJobRequest, opts ...gax.CallOption) error {
1672 baseUrl, err := url.Parse(c.endpoint)
1673 if err != nil {
1674 return err
1675 }
1676 baseUrl.Path += fmt.Sprintf("/v1/%v", req.GetJobName())
1677
1678 params := url.Values{}
1679 params.Add("$alt", "json;enum-encoding=int")
1680 params.Add("projectId", fmt.Sprintf("%v", req.GetProjectId()))
1681
1682 baseUrl.RawQuery = params.Encode()
1683
1684 // Build HTTP headers from client and context metadata.
1685 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "job_name", url.QueryEscape(req.GetJobName()))}
1686
1687 hds = append(c.xGoogHeaders, hds...)
1688 hds = append(hds, "Content-Type", "application/json")
1689 headers := gax.BuildHeaders(ctx, hds...)
1690 return gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1691 if settings.Path != "" {
1692 baseUrl.Path = settings.Path
1693 }
1694 httpReq, err := http.NewRequest("DELETE", baseUrl.String(), nil)
1695 if err != nil {
1696 return err
1697 }
1698 httpReq = httpReq.WithContext(ctx)
1699 httpReq.Header = headers
1700
1701 _, err = executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "DeleteTransferJob")
1702 return err
1703 }, opts...)
1704 }
1705
1706 // CreateAgentPool creates an agent pool resource.
1707 func (c *restClient) CreateAgentPool(ctx context.Context, req *storagetransferpb.CreateAgentPoolRequest, opts ...gax.CallOption) (*storagetransferpb.AgentPool, error) {
1708 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
1709 body := req.GetAgentPool()
1710 jsonReq, err := m.Marshal(body)
1711 if err != nil {
1712 return nil, err
1713 }
1714
1715 baseUrl, err := url.Parse(c.endpoint)
1716 if err != nil {
1717 return nil, err
1718 }
1719 baseUrl.Path += fmt.Sprintf("/v1/projects/%v/agentPools", req.GetProjectId())
1720
1721 params := url.Values{}
1722 params.Add("$alt", "json;enum-encoding=int")
1723 params.Add("agentPoolId", fmt.Sprintf("%v", req.GetAgentPoolId()))
1724
1725 baseUrl.RawQuery = params.Encode()
1726
1727 // Build HTTP headers from client and context metadata.
1728 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "project_id", url.QueryEscape(req.GetProjectId()))}
1729
1730 hds = append(c.xGoogHeaders, hds...)
1731 hds = append(hds, "Content-Type", "application/json")
1732 headers := gax.BuildHeaders(ctx, hds...)
1733 opts = append((*c.CallOptions).CreateAgentPool[0:len((*c.CallOptions).CreateAgentPool):len((*c.CallOptions).CreateAgentPool)], opts...)
1734 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
1735 resp := &storagetransferpb.AgentPool{}
1736 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1737 if settings.Path != "" {
1738 baseUrl.Path = settings.Path
1739 }
1740 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
1741 if err != nil {
1742 return err
1743 }
1744 httpReq = httpReq.WithContext(ctx)
1745 httpReq.Header = headers
1746
1747 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "CreateAgentPool")
1748 if err != nil {
1749 return err
1750 }
1751
1752 if err := unm.Unmarshal(buf, resp); err != nil {
1753 return err
1754 }
1755
1756 return nil
1757 }, opts...)
1758 if e != nil {
1759 return nil, e
1760 }
1761 return resp, nil
1762 }
1763
1764 // UpdateAgentPool updates an existing agent pool resource.
1765 func (c *restClient) UpdateAgentPool(ctx context.Context, req *storagetransferpb.UpdateAgentPoolRequest, opts ...gax.CallOption) (*storagetransferpb.AgentPool, error) {
1766 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
1767 body := req.GetAgentPool()
1768 jsonReq, err := m.Marshal(body)
1769 if err != nil {
1770 return nil, err
1771 }
1772
1773 baseUrl, err := url.Parse(c.endpoint)
1774 if err != nil {
1775 return nil, err
1776 }
1777 baseUrl.Path += fmt.Sprintf("/v1/%v", req.GetAgentPool().GetName())
1778
1779 params := url.Values{}
1780 params.Add("$alt", "json;enum-encoding=int")
1781 if req.GetUpdateMask() != nil {
1782 field, err := protojson.Marshal(req.GetUpdateMask())
1783 if err != nil {
1784 return nil, err
1785 }
1786 params.Add("updateMask", string(field[1:len(field)-1]))
1787 }
1788
1789 baseUrl.RawQuery = params.Encode()
1790
1791 // Build HTTP headers from client and context metadata.
1792 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "agent_pool.name", url.QueryEscape(req.GetAgentPool().GetName()))}
1793
1794 hds = append(c.xGoogHeaders, hds...)
1795 hds = append(hds, "Content-Type", "application/json")
1796 headers := gax.BuildHeaders(ctx, hds...)
1797 opts = append((*c.CallOptions).UpdateAgentPool[0:len((*c.CallOptions).UpdateAgentPool):len((*c.CallOptions).UpdateAgentPool)], opts...)
1798 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
1799 resp := &storagetransferpb.AgentPool{}
1800 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1801 if settings.Path != "" {
1802 baseUrl.Path = settings.Path
1803 }
1804 httpReq, err := http.NewRequest("PATCH", baseUrl.String(), bytes.NewReader(jsonReq))
1805 if err != nil {
1806 return err
1807 }
1808 httpReq = httpReq.WithContext(ctx)
1809 httpReq.Header = headers
1810
1811 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "UpdateAgentPool")
1812 if err != nil {
1813 return err
1814 }
1815
1816 if err := unm.Unmarshal(buf, resp); err != nil {
1817 return err
1818 }
1819
1820 return nil
1821 }, opts...)
1822 if e != nil {
1823 return nil, e
1824 }
1825 return resp, nil
1826 }
1827
1828 // GetAgentPool gets an agent pool.
1829 func (c *restClient) GetAgentPool(ctx context.Context, req *storagetransferpb.GetAgentPoolRequest, opts ...gax.CallOption) (*storagetransferpb.AgentPool, error) {
1830 baseUrl, err := url.Parse(c.endpoint)
1831 if err != nil {
1832 return nil, err
1833 }
1834 baseUrl.Path += fmt.Sprintf("/v1/%v", req.GetName())
1835
1836 params := url.Values{}
1837 params.Add("$alt", "json;enum-encoding=int")
1838
1839 baseUrl.RawQuery = params.Encode()
1840
1841 // Build HTTP headers from client and context metadata.
1842 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
1843
1844 hds = append(c.xGoogHeaders, hds...)
1845 hds = append(hds, "Content-Type", "application/json")
1846 headers := gax.BuildHeaders(ctx, hds...)
1847 opts = append((*c.CallOptions).GetAgentPool[0:len((*c.CallOptions).GetAgentPool):len((*c.CallOptions).GetAgentPool)], opts...)
1848 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
1849 resp := &storagetransferpb.AgentPool{}
1850 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1851 if settings.Path != "" {
1852 baseUrl.Path = settings.Path
1853 }
1854 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
1855 if err != nil {
1856 return err
1857 }
1858 httpReq = httpReq.WithContext(ctx)
1859 httpReq.Header = headers
1860
1861 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "GetAgentPool")
1862 if err != nil {
1863 return err
1864 }
1865
1866 if err := unm.Unmarshal(buf, resp); err != nil {
1867 return err
1868 }
1869
1870 return nil
1871 }, opts...)
1872 if e != nil {
1873 return nil, e
1874 }
1875 return resp, nil
1876 }
1877
1878 // ListAgentPools lists agent pools.
1879 func (c *restClient) ListAgentPools(ctx context.Context, req *storagetransferpb.ListAgentPoolsRequest, opts ...gax.CallOption) *AgentPoolIterator {
1880 it := &AgentPoolIterator{}
1881 req = proto.Clone(req).(*storagetransferpb.ListAgentPoolsRequest)
1882 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
1883 it.InternalFetch = func(pageSize int, pageToken string) ([]*storagetransferpb.AgentPool, string, error) {
1884 resp := &storagetransferpb.ListAgentPoolsResponse{}
1885 if pageToken != "" {
1886 req.PageToken = pageToken
1887 }
1888 if pageSize > math.MaxInt32 {
1889 req.PageSize = math.MaxInt32
1890 } else if pageSize != 0 {
1891 req.PageSize = int32(pageSize)
1892 }
1893 baseUrl, err := url.Parse(c.endpoint)
1894 if err != nil {
1895 return nil, "", err
1896 }
1897 baseUrl.Path += fmt.Sprintf("/v1/projects/%v/agentPools", req.GetProjectId())
1898
1899 params := url.Values{}
1900 params.Add("$alt", "json;enum-encoding=int")
1901 if req.GetFilter() != "" {
1902 params.Add("filter", fmt.Sprintf("%v", req.GetFilter()))
1903 }
1904 if req.GetPageSize() != 0 {
1905 params.Add("pageSize", fmt.Sprintf("%v", req.GetPageSize()))
1906 }
1907 if req.GetPageToken() != "" {
1908 params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken()))
1909 }
1910
1911 baseUrl.RawQuery = params.Encode()
1912
1913 // Build HTTP headers from client and context metadata.
1914 hds := append(c.xGoogHeaders, "Content-Type", "application/json")
1915 headers := gax.BuildHeaders(ctx, hds...)
1916 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1917 if settings.Path != "" {
1918 baseUrl.Path = settings.Path
1919 }
1920 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
1921 if err != nil {
1922 return err
1923 }
1924 httpReq.Header = headers
1925
1926 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "ListAgentPools")
1927 if err != nil {
1928 return err
1929 }
1930 if err := unm.Unmarshal(buf, resp); err != nil {
1931 return err
1932 }
1933
1934 return nil
1935 }, opts...)
1936 if e != nil {
1937 return nil, "", e
1938 }
1939 it.Response = resp
1940 return resp.GetAgentPools(), resp.GetNextPageToken(), nil
1941 }
1942
1943 fetch := func(pageSize int, pageToken string) (string, error) {
1944 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
1945 if err != nil {
1946 return "", err
1947 }
1948 it.items = append(it.items, items...)
1949 return nextPageToken, nil
1950 }
1951
1952 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
1953 it.pageInfo.MaxSize = int(req.GetPageSize())
1954 it.pageInfo.Token = req.GetPageToken()
1955
1956 return it
1957 }
1958
1959 // DeleteAgentPool deletes an agent pool.
1960 func (c *restClient) DeleteAgentPool(ctx context.Context, req *storagetransferpb.DeleteAgentPoolRequest, opts ...gax.CallOption) error {
1961 baseUrl, err := url.Parse(c.endpoint)
1962 if err != nil {
1963 return err
1964 }
1965 baseUrl.Path += fmt.Sprintf("/v1/%v", req.GetName())
1966
1967 params := url.Values{}
1968 params.Add("$alt", "json;enum-encoding=int")
1969
1970 baseUrl.RawQuery = params.Encode()
1971
1972 // Build HTTP headers from client and context metadata.
1973 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
1974
1975 hds = append(c.xGoogHeaders, hds...)
1976 hds = append(hds, "Content-Type", "application/json")
1977 headers := gax.BuildHeaders(ctx, hds...)
1978 return gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1979 if settings.Path != "" {
1980 baseUrl.Path = settings.Path
1981 }
1982 httpReq, err := http.NewRequest("DELETE", baseUrl.String(), nil)
1983 if err != nil {
1984 return err
1985 }
1986 httpReq = httpReq.WithContext(ctx)
1987 httpReq.Header = headers
1988
1989 _, err = executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "DeleteAgentPool")
1990 return err
1991 }, opts...)
1992 }
1993
1994 // CancelOperation cancels a transfer. Use
1995 // the transferOperations.get
1996 // method to check if the cancellation succeeded or if the operation
1997 // completed despite the cancel request.
1998 //
1999 // When you cancel an operation, the currently running transfer is
2000 // interrupted. For recurring transfer jobs, the next instance of the
2001 // transfer job will still run. For example, if your job is configured
2002 // to run every day at 1pm and you cancel Monday’s operation at 1:05pm,
2003 // Monday’s transfer
2004 // will stop. However, a transfer job will still be attempted on Tuesday.
2005 //
2006 // This applies only to currently running operations. If an operation is
2007 // not currently running, cancel does nothing.
2008 //
2009 // When you cancel a job, the next job computes a delta of files and may
2010 // repair any inconsistent state. For instance, if you run a job every
2011 // day, and today’s job found 10 new files and transferred five files
2012 // before you canceled the job, tomorrow’s transfer operation will
2013 // compute a new delta with the five files that were not copied today
2014 // plus any new files discovered tomorrow.
2015 func (c *restClient) CancelOperation(ctx context.Context, req *longrunningpb.CancelOperationRequest, opts ...gax.CallOption) error {
2016 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
2017 jsonReq, err := m.Marshal(req)
2018 if err != nil {
2019 return err
2020 }
2021
2022 baseUrl, err := url.Parse(c.endpoint)
2023 if err != nil {
2024 return err
2025 }
2026 baseUrl.Path += fmt.Sprintf("/v1/%v:cancel", req.GetName())
2027
2028 params := url.Values{}
2029 params.Add("$alt", "json;enum-encoding=int")
2030
2031 baseUrl.RawQuery = params.Encode()
2032
2033 // Build HTTP headers from client and context metadata.
2034 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
2035
2036 hds = append(c.xGoogHeaders, hds...)
2037 hds = append(hds, "Content-Type", "application/json")
2038 headers := gax.BuildHeaders(ctx, hds...)
2039 return gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
2040 if settings.Path != "" {
2041 baseUrl.Path = settings.Path
2042 }
2043 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
2044 if err != nil {
2045 return err
2046 }
2047 httpReq = httpReq.WithContext(ctx)
2048 httpReq.Header = headers
2049
2050 _, err = executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "CancelOperation")
2051 return err
2052 }, opts...)
2053 }
2054
2055 // GetOperation is a utility method from google.longrunning.Operations.
2056 func (c *restClient) GetOperation(ctx context.Context, req *longrunningpb.GetOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) {
2057 baseUrl, err := url.Parse(c.endpoint)
2058 if err != nil {
2059 return nil, err
2060 }
2061 baseUrl.Path += fmt.Sprintf("/v1/%v", req.GetName())
2062
2063 params := url.Values{}
2064 params.Add("$alt", "json;enum-encoding=int")
2065
2066 baseUrl.RawQuery = params.Encode()
2067
2068 // Build HTTP headers from client and context metadata.
2069 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
2070
2071 hds = append(c.xGoogHeaders, hds...)
2072 hds = append(hds, "Content-Type", "application/json")
2073 headers := gax.BuildHeaders(ctx, hds...)
2074 opts = append((*c.CallOptions).GetOperation[0:len((*c.CallOptions).GetOperation):len((*c.CallOptions).GetOperation)], opts...)
2075 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
2076 resp := &longrunningpb.Operation{}
2077 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
2078 if settings.Path != "" {
2079 baseUrl.Path = settings.Path
2080 }
2081 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
2082 if err != nil {
2083 return err
2084 }
2085 httpReq = httpReq.WithContext(ctx)
2086 httpReq.Header = headers
2087
2088 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "GetOperation")
2089 if err != nil {
2090 return err
2091 }
2092
2093 if err := unm.Unmarshal(buf, resp); err != nil {
2094 return err
2095 }
2096
2097 return nil
2098 }, opts...)
2099 if e != nil {
2100 return nil, e
2101 }
2102 return resp, nil
2103 }
2104
2105 // ListOperations lists transfer operations. Operations are ordered by their creation
2106 // time in reverse chronological order.
2107 func (c *restClient) ListOperations(ctx context.Context, req *longrunningpb.ListOperationsRequest, opts ...gax.CallOption) *OperationIterator {
2108 it := &OperationIterator{}
2109 req = proto.Clone(req).(*longrunningpb.ListOperationsRequest)
2110 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
2111 it.InternalFetch = func(pageSize int, pageToken string) ([]*longrunningpb.Operation, string, error) {
2112 resp := &longrunningpb.ListOperationsResponse{}
2113 if pageToken != "" {
2114 req.PageToken = pageToken
2115 }
2116 if pageSize > math.MaxInt32 {
2117 req.PageSize = math.MaxInt32
2118 } else if pageSize != 0 {
2119 req.PageSize = int32(pageSize)
2120 }
2121 baseUrl, err := url.Parse(c.endpoint)
2122 if err != nil {
2123 return nil, "", err
2124 }
2125 baseUrl.Path += fmt.Sprintf("/v1/%v", req.GetName())
2126
2127 params := url.Values{}
2128 params.Add("$alt", "json;enum-encoding=int")
2129 if req.GetFilter() != "" {
2130 params.Add("filter", fmt.Sprintf("%v", req.GetFilter()))
2131 }
2132 if req.GetPageSize() != 0 {
2133 params.Add("pageSize", fmt.Sprintf("%v", req.GetPageSize()))
2134 }
2135 if req.GetPageToken() != "" {
2136 params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken()))
2137 }
2138
2139 baseUrl.RawQuery = params.Encode()
2140
2141 // Build HTTP headers from client and context metadata.
2142 hds := append(c.xGoogHeaders, "Content-Type", "application/json")
2143 headers := gax.BuildHeaders(ctx, hds...)
2144 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
2145 if settings.Path != "" {
2146 baseUrl.Path = settings.Path
2147 }
2148 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
2149 if err != nil {
2150 return err
2151 }
2152 httpReq.Header = headers
2153
2154 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "ListOperations")
2155 if err != nil {
2156 return err
2157 }
2158 if err := unm.Unmarshal(buf, resp); err != nil {
2159 return err
2160 }
2161
2162 return nil
2163 }, opts...)
2164 if e != nil {
2165 return nil, "", e
2166 }
2167 it.Response = resp
2168 return resp.GetOperations(), resp.GetNextPageToken(), nil
2169 }
2170
2171 fetch := func(pageSize int, pageToken string) (string, error) {
2172 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
2173 if err != nil {
2174 return "", err
2175 }
2176 it.items = append(it.items, items...)
2177 return nextPageToken, nil
2178 }
2179
2180 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
2181 it.pageInfo.MaxSize = int(req.GetPageSize())
2182 it.pageInfo.Token = req.GetPageToken()
2183
2184 return it
2185 }
2186
2187 // RunTransferJobOperation returns a new RunTransferJobOperation from a given name.
2188 // The name must be that of a previously created RunTransferJobOperation, possibly from a different process.
2189 func (c *gRPCClient) RunTransferJobOperation(name string) *RunTransferJobOperation {
2190 return &RunTransferJobOperation{
2191 lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}),
2192 }
2193 }
2194
2195 // RunTransferJobOperation returns a new RunTransferJobOperation from a given name.
2196 // The name must be that of a previously created RunTransferJobOperation, possibly from a different process.
2197 func (c *restClient) RunTransferJobOperation(name string) *RunTransferJobOperation {
2198 override := fmt.Sprintf("/v1/%s", name)
2199 return &RunTransferJobOperation{
2200 lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}),
2201 pollPath: override,
2202 }
2203 }