1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package longrunning
18
19 import (
20 "bytes"
21 "context"
22 "fmt"
23 "io"
24 "math"
25 "net/http"
26 "net/url"
27 "time"
28
29 longrunningpb "cloud.google.com/go/longrunning/autogen/longrunningpb"
30 gax "github.com/googleapis/gax-go/v2"
31 "google.golang.org/api/googleapi"
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 "google.golang.org/grpc"
38 "google.golang.org/grpc/codes"
39 "google.golang.org/protobuf/encoding/protojson"
40 "google.golang.org/protobuf/proto"
41 )
42
43 var newOperationsClientHook clientHook
44
45
46 type OperationsCallOptions struct {
47 ListOperations []gax.CallOption
48 GetOperation []gax.CallOption
49 DeleteOperation []gax.CallOption
50 CancelOperation []gax.CallOption
51 WaitOperation []gax.CallOption
52 }
53
54 func defaultOperationsGRPCClientOptions() []option.ClientOption {
55 return []option.ClientOption{
56 internaloption.WithDefaultEndpoint("longrunning.googleapis.com:443"),
57 internaloption.WithDefaultEndpointTemplate("longrunning.UNIVERSE_DOMAIN:443"),
58 internaloption.WithDefaultMTLSEndpoint("longrunning.mtls.googleapis.com:443"),
59 internaloption.WithDefaultUniverseDomain("googleapis.com"),
60 internaloption.WithDefaultAudience("https://longrunning.googleapis.com/"),
61 internaloption.WithDefaultScopes(DefaultAuthScopes()...),
62 internaloption.EnableJwtWithScope(),
63 option.WithGRPCDialOption(grpc.WithDefaultCallOptions(
64 grpc.MaxCallRecvMsgSize(math.MaxInt32))),
65 }
66 }
67
68 func defaultOperationsCallOptions() *OperationsCallOptions {
69 return &OperationsCallOptions{
70 ListOperations: []gax.CallOption{
71 gax.WithTimeout(10000 * time.Millisecond),
72 gax.WithRetry(func() gax.Retryer {
73 return gax.OnCodes([]codes.Code{
74 codes.Unavailable,
75 }, gax.Backoff{
76 Initial: 500 * time.Millisecond,
77 Max: 10000 * time.Millisecond,
78 Multiplier: 2.00,
79 })
80 }),
81 },
82 GetOperation: []gax.CallOption{
83 gax.WithTimeout(10000 * time.Millisecond),
84 gax.WithRetry(func() gax.Retryer {
85 return gax.OnCodes([]codes.Code{
86 codes.Unavailable,
87 }, gax.Backoff{
88 Initial: 500 * time.Millisecond,
89 Max: 10000 * time.Millisecond,
90 Multiplier: 2.00,
91 })
92 }),
93 },
94 DeleteOperation: []gax.CallOption{
95 gax.WithTimeout(10000 * time.Millisecond),
96 gax.WithRetry(func() gax.Retryer {
97 return gax.OnCodes([]codes.Code{
98 codes.Unavailable,
99 }, gax.Backoff{
100 Initial: 500 * time.Millisecond,
101 Max: 10000 * time.Millisecond,
102 Multiplier: 2.00,
103 })
104 }),
105 },
106 CancelOperation: []gax.CallOption{
107 gax.WithTimeout(10000 * time.Millisecond),
108 gax.WithRetry(func() gax.Retryer {
109 return gax.OnCodes([]codes.Code{
110 codes.Unavailable,
111 }, gax.Backoff{
112 Initial: 500 * time.Millisecond,
113 Max: 10000 * time.Millisecond,
114 Multiplier: 2.00,
115 })
116 }),
117 },
118 WaitOperation: []gax.CallOption{},
119 }
120 }
121
122 func defaultOperationsRESTCallOptions() *OperationsCallOptions {
123 return &OperationsCallOptions{
124 ListOperations: []gax.CallOption{
125 gax.WithTimeout(10000 * time.Millisecond),
126 gax.WithRetry(func() gax.Retryer {
127 return gax.OnHTTPCodes(gax.Backoff{
128 Initial: 500 * time.Millisecond,
129 Max: 10000 * time.Millisecond,
130 Multiplier: 2.00,
131 },
132 http.StatusServiceUnavailable)
133 }),
134 },
135 GetOperation: []gax.CallOption{
136 gax.WithTimeout(10000 * time.Millisecond),
137 gax.WithRetry(func() gax.Retryer {
138 return gax.OnHTTPCodes(gax.Backoff{
139 Initial: 500 * time.Millisecond,
140 Max: 10000 * time.Millisecond,
141 Multiplier: 2.00,
142 },
143 http.StatusServiceUnavailable)
144 }),
145 },
146 DeleteOperation: []gax.CallOption{
147 gax.WithTimeout(10000 * time.Millisecond),
148 gax.WithRetry(func() gax.Retryer {
149 return gax.OnHTTPCodes(gax.Backoff{
150 Initial: 500 * time.Millisecond,
151 Max: 10000 * time.Millisecond,
152 Multiplier: 2.00,
153 },
154 http.StatusServiceUnavailable)
155 }),
156 },
157 CancelOperation: []gax.CallOption{
158 gax.WithTimeout(10000 * time.Millisecond),
159 gax.WithRetry(func() gax.Retryer {
160 return gax.OnHTTPCodes(gax.Backoff{
161 Initial: 500 * time.Millisecond,
162 Max: 10000 * time.Millisecond,
163 Multiplier: 2.00,
164 },
165 http.StatusServiceUnavailable)
166 }),
167 },
168 WaitOperation: []gax.CallOption{},
169 }
170 }
171
172
173 type internalOperationsClient interface {
174 Close() error
175 setGoogleClientInfo(...string)
176 Connection() *grpc.ClientConn
177 ListOperations(context.Context, *longrunningpb.ListOperationsRequest, ...gax.CallOption) *OperationIterator
178 GetOperation(context.Context, *longrunningpb.GetOperationRequest, ...gax.CallOption) (*longrunningpb.Operation, error)
179 DeleteOperation(context.Context, *longrunningpb.DeleteOperationRequest, ...gax.CallOption) error
180 CancelOperation(context.Context, *longrunningpb.CancelOperationRequest, ...gax.CallOption) error
181 WaitOperation(context.Context, *longrunningpb.WaitOperationRequest, ...gax.CallOption) (*longrunningpb.Operation, error)
182 }
183
184
185
186
187
188
189
190
191
192
193
194
195
196 type OperationsClient struct {
197
198 internalClient internalOperationsClient
199
200
201 CallOptions *OperationsCallOptions
202 }
203
204
205
206
207
208 func (c *OperationsClient) Close() error {
209 return c.internalClient.Close()
210 }
211
212
213
214
215 func (c *OperationsClient) setGoogleClientInfo(keyval ...string) {
216 c.internalClient.setGoogleClientInfo(keyval...)
217 }
218
219
220
221
222
223 func (c *OperationsClient) Connection() *grpc.ClientConn {
224 return c.internalClient.Connection()
225 }
226
227
228
229
230
231
232
233
234
235
236
237 func (c *OperationsClient) ListOperations(ctx context.Context, req *longrunningpb.ListOperationsRequest, opts ...gax.CallOption) *OperationIterator {
238 return c.internalClient.ListOperations(ctx, req, opts...)
239 }
240
241
242
243
244 func (c *OperationsClient) GetOperation(ctx context.Context, req *longrunningpb.GetOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) {
245 return c.internalClient.GetOperation(ctx, req, opts...)
246 }
247
248
249
250
251
252 func (c *OperationsClient) DeleteOperation(ctx context.Context, req *longrunningpb.DeleteOperationRequest, opts ...gax.CallOption) error {
253 return c.internalClient.DeleteOperation(ctx, req, opts...)
254 }
255
256
257
258
259
260
261
262
263
264
265
266 func (c *OperationsClient) CancelOperation(ctx context.Context, req *longrunningpb.CancelOperationRequest, opts ...gax.CallOption) error {
267 return c.internalClient.CancelOperation(ctx, req, opts...)
268 }
269
270
271
272
273
274
275
276
277
278
279 func (c *OperationsClient) WaitOperation(ctx context.Context, req *longrunningpb.WaitOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) {
280 return c.internalClient.WaitOperation(ctx, req, opts...)
281 }
282
283
284
285
286 type operationsGRPCClient struct {
287
288 connPool gtransport.ConnPool
289
290
291 CallOptions **OperationsCallOptions
292
293
294 operationsClient longrunningpb.OperationsClient
295
296
297 xGoogHeaders []string
298 }
299
300
301
302
303
304
305
306
307
308
309
310
311
312 func NewOperationsClient(ctx context.Context, opts ...option.ClientOption) (*OperationsClient, error) {
313 clientOpts := defaultOperationsGRPCClientOptions()
314 if newOperationsClientHook != nil {
315 hookOpts, err := newOperationsClientHook(ctx, clientHookParams{})
316 if err != nil {
317 return nil, err
318 }
319 clientOpts = append(clientOpts, hookOpts...)
320 }
321
322 connPool, err := gtransport.DialPool(ctx, append(clientOpts, opts...)...)
323 if err != nil {
324 return nil, err
325 }
326 client := OperationsClient{CallOptions: defaultOperationsCallOptions()}
327
328 c := &operationsGRPCClient{
329 connPool: connPool,
330 operationsClient: longrunningpb.NewOperationsClient(connPool),
331 CallOptions: &client.CallOptions,
332 }
333 c.setGoogleClientInfo()
334
335 client.internalClient = c
336
337 return &client, nil
338 }
339
340
341
342
343
344 func (c *operationsGRPCClient) Connection() *grpc.ClientConn {
345 return c.connPool.Conn()
346 }
347
348
349
350
351 func (c *operationsGRPCClient) setGoogleClientInfo(keyval ...string) {
352 kv := append([]string{"gl-go", gax.GoVersion}, keyval...)
353 kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "grpc", grpc.Version)
354 c.xGoogHeaders = []string{"x-goog-api-client", gax.XGoogHeader(kv...)}
355 }
356
357
358
359 func (c *operationsGRPCClient) Close() error {
360 return c.connPool.Close()
361 }
362
363
364 type operationsRESTClient struct {
365
366 endpoint string
367
368
369 httpClient *http.Client
370
371
372 xGoogHeaders []string
373
374
375 CallOptions **OperationsCallOptions
376 }
377
378
379
380
381
382
383
384
385
386
387
388
389 func NewOperationsRESTClient(ctx context.Context, opts ...option.ClientOption) (*OperationsClient, error) {
390 clientOpts := append(defaultOperationsRESTClientOptions(), opts...)
391 httpClient, endpoint, err := httptransport.NewClient(ctx, clientOpts...)
392 if err != nil {
393 return nil, err
394 }
395
396 callOpts := defaultOperationsRESTCallOptions()
397 c := &operationsRESTClient{
398 endpoint: endpoint,
399 httpClient: httpClient,
400 CallOptions: &callOpts,
401 }
402 c.setGoogleClientInfo()
403
404 return &OperationsClient{internalClient: c, CallOptions: callOpts}, nil
405 }
406
407 func defaultOperationsRESTClientOptions() []option.ClientOption {
408 return []option.ClientOption{
409 internaloption.WithDefaultEndpoint("https://longrunning.googleapis.com"),
410 internaloption.WithDefaultEndpointTemplate("https://longrunning.UNIVERSE_DOMAIN"),
411 internaloption.WithDefaultMTLSEndpoint("https://longrunning.mtls.googleapis.com"),
412 internaloption.WithDefaultUniverseDomain("googleapis.com"),
413 internaloption.WithDefaultAudience("https://longrunning.googleapis.com/"),
414 internaloption.WithDefaultScopes(DefaultAuthScopes()...),
415 }
416 }
417
418
419
420
421 func (c *operationsRESTClient) setGoogleClientInfo(keyval ...string) {
422 kv := append([]string{"gl-go", gax.GoVersion}, keyval...)
423 kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "rest", "UNKNOWN")
424 c.xGoogHeaders = []string{"x-goog-api-client", gax.XGoogHeader(kv...)}
425 }
426
427
428
429 func (c *operationsRESTClient) Close() error {
430
431 c.httpClient = nil
432 return nil
433 }
434
435
436
437
438 func (c *operationsRESTClient) Connection() *grpc.ClientConn {
439 return nil
440 }
441 func (c *operationsGRPCClient) ListOperations(ctx context.Context, req *longrunningpb.ListOperationsRequest, opts ...gax.CallOption) *OperationIterator {
442 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
443
444 hds = append(c.xGoogHeaders, hds...)
445 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
446 opts = append((*c.CallOptions).ListOperations[0:len((*c.CallOptions).ListOperations):len((*c.CallOptions).ListOperations)], opts...)
447 it := &OperationIterator{}
448 req = proto.Clone(req).(*longrunningpb.ListOperationsRequest)
449 it.InternalFetch = func(pageSize int, pageToken string) ([]*longrunningpb.Operation, string, error) {
450 resp := &longrunningpb.ListOperationsResponse{}
451 if pageToken != "" {
452 req.PageToken = pageToken
453 }
454 if pageSize > math.MaxInt32 {
455 req.PageSize = math.MaxInt32
456 } else if pageSize != 0 {
457 req.PageSize = int32(pageSize)
458 }
459 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
460 var err error
461 resp, err = c.operationsClient.ListOperations(ctx, req, settings.GRPC...)
462 return err
463 }, opts...)
464 if err != nil {
465 return nil, "", err
466 }
467
468 it.Response = resp
469 return resp.GetOperations(), resp.GetNextPageToken(), nil
470 }
471 fetch := func(pageSize int, pageToken string) (string, error) {
472 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
473 if err != nil {
474 return "", err
475 }
476 it.items = append(it.items, items...)
477 return nextPageToken, nil
478 }
479
480 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
481 it.pageInfo.MaxSize = int(req.GetPageSize())
482 it.pageInfo.Token = req.GetPageToken()
483
484 return it
485 }
486
487 func (c *operationsGRPCClient) GetOperation(ctx context.Context, req *longrunningpb.GetOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) {
488 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
489
490 hds = append(c.xGoogHeaders, hds...)
491 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
492 opts = append((*c.CallOptions).GetOperation[0:len((*c.CallOptions).GetOperation):len((*c.CallOptions).GetOperation)], opts...)
493 var resp *longrunningpb.Operation
494 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
495 var err error
496 resp, err = c.operationsClient.GetOperation(ctx, req, settings.GRPC...)
497 return err
498 }, opts...)
499 if err != nil {
500 return nil, err
501 }
502 return resp, nil
503 }
504
505 func (c *operationsGRPCClient) DeleteOperation(ctx context.Context, req *longrunningpb.DeleteOperationRequest, opts ...gax.CallOption) error {
506 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
507
508 hds = append(c.xGoogHeaders, hds...)
509 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
510 opts = append((*c.CallOptions).DeleteOperation[0:len((*c.CallOptions).DeleteOperation):len((*c.CallOptions).DeleteOperation)], opts...)
511 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
512 var err error
513 _, err = c.operationsClient.DeleteOperation(ctx, req, settings.GRPC...)
514 return err
515 }, opts...)
516 return err
517 }
518
519 func (c *operationsGRPCClient) CancelOperation(ctx context.Context, req *longrunningpb.CancelOperationRequest, opts ...gax.CallOption) error {
520 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
521
522 hds = append(c.xGoogHeaders, hds...)
523 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
524 opts = append((*c.CallOptions).CancelOperation[0:len((*c.CallOptions).CancelOperation):len((*c.CallOptions).CancelOperation)], opts...)
525 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
526 var err error
527 _, err = c.operationsClient.CancelOperation(ctx, req, settings.GRPC...)
528 return err
529 }, opts...)
530 return err
531 }
532
533 func (c *operationsGRPCClient) WaitOperation(ctx context.Context, req *longrunningpb.WaitOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) {
534 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, c.xGoogHeaders...)
535 opts = append((*c.CallOptions).WaitOperation[0:len((*c.CallOptions).WaitOperation):len((*c.CallOptions).WaitOperation)], opts...)
536 var resp *longrunningpb.Operation
537 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
538 var err error
539 resp, err = c.operationsClient.WaitOperation(ctx, req, settings.GRPC...)
540 return err
541 }, opts...)
542 if err != nil {
543 return nil, err
544 }
545 return resp, nil
546 }
547
548
549
550
551
552
553
554
555
556
557
558 func (c *operationsRESTClient) ListOperations(ctx context.Context, req *longrunningpb.ListOperationsRequest, opts ...gax.CallOption) *OperationIterator {
559 it := &OperationIterator{}
560 req = proto.Clone(req).(*longrunningpb.ListOperationsRequest)
561 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
562 it.InternalFetch = func(pageSize int, pageToken string) ([]*longrunningpb.Operation, string, error) {
563 resp := &longrunningpb.ListOperationsResponse{}
564 if pageToken != "" {
565 req.PageToken = pageToken
566 }
567 if pageSize > math.MaxInt32 {
568 req.PageSize = math.MaxInt32
569 } else if pageSize != 0 {
570 req.PageSize = int32(pageSize)
571 }
572 baseUrl, err := url.Parse(c.endpoint)
573 if err != nil {
574 return nil, "", err
575 }
576 baseUrl.Path += fmt.Sprintf("/v1/%v", req.GetName())
577
578 params := url.Values{}
579 if req.GetFilter() != "" {
580 params.Add("filter", fmt.Sprintf("%v", req.GetFilter()))
581 }
582 if req.GetPageSize() != 0 {
583 params.Add("pageSize", fmt.Sprintf("%v", req.GetPageSize()))
584 }
585 if req.GetPageToken() != "" {
586 params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken()))
587 }
588
589 baseUrl.RawQuery = params.Encode()
590
591
592 hds := append(c.xGoogHeaders, "Content-Type", "application/json")
593 headers := gax.BuildHeaders(ctx, hds...)
594 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
595 if settings.Path != "" {
596 baseUrl.Path = settings.Path
597 }
598 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
599 if err != nil {
600 return err
601 }
602 httpReq.Header = headers
603
604 httpRsp, err := c.httpClient.Do(httpReq)
605 if err != nil {
606 return err
607 }
608 defer httpRsp.Body.Close()
609
610 if err = googleapi.CheckResponse(httpRsp); err != nil {
611 return err
612 }
613
614 buf, err := io.ReadAll(httpRsp.Body)
615 if err != nil {
616 return err
617 }
618
619 if err := unm.Unmarshal(buf, resp); err != nil {
620 return err
621 }
622
623 return nil
624 }, opts...)
625 if e != nil {
626 return nil, "", e
627 }
628 it.Response = resp
629 return resp.GetOperations(), resp.GetNextPageToken(), nil
630 }
631
632 fetch := func(pageSize int, pageToken string) (string, error) {
633 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
634 if err != nil {
635 return "", err
636 }
637 it.items = append(it.items, items...)
638 return nextPageToken, nil
639 }
640
641 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
642 it.pageInfo.MaxSize = int(req.GetPageSize())
643 it.pageInfo.Token = req.GetPageToken()
644
645 return it
646 }
647
648
649
650
651 func (c *operationsRESTClient) GetOperation(ctx context.Context, req *longrunningpb.GetOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) {
652 baseUrl, err := url.Parse(c.endpoint)
653 if err != nil {
654 return nil, err
655 }
656 baseUrl.Path += fmt.Sprintf("/v1/%v", req.GetName())
657
658
659 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
660
661 hds = append(c.xGoogHeaders, hds...)
662 hds = append(hds, "Content-Type", "application/json")
663 headers := gax.BuildHeaders(ctx, hds...)
664 opts = append((*c.CallOptions).GetOperation[0:len((*c.CallOptions).GetOperation):len((*c.CallOptions).GetOperation)], opts...)
665 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
666 resp := &longrunningpb.Operation{}
667 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
668 if settings.Path != "" {
669 baseUrl.Path = settings.Path
670 }
671 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
672 if err != nil {
673 return err
674 }
675 httpReq = httpReq.WithContext(ctx)
676 httpReq.Header = headers
677
678 httpRsp, err := c.httpClient.Do(httpReq)
679 if err != nil {
680 return err
681 }
682 defer httpRsp.Body.Close()
683
684 if err = googleapi.CheckResponse(httpRsp); err != nil {
685 return err
686 }
687
688 buf, err := io.ReadAll(httpRsp.Body)
689 if err != nil {
690 return err
691 }
692
693 if err := unm.Unmarshal(buf, resp); err != nil {
694 return err
695 }
696
697 return nil
698 }, opts...)
699 if e != nil {
700 return nil, e
701 }
702 return resp, nil
703 }
704
705
706
707
708
709 func (c *operationsRESTClient) DeleteOperation(ctx context.Context, req *longrunningpb.DeleteOperationRequest, opts ...gax.CallOption) error {
710 baseUrl, err := url.Parse(c.endpoint)
711 if err != nil {
712 return err
713 }
714 baseUrl.Path += fmt.Sprintf("/v1/%v", req.GetName())
715
716
717 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
718
719 hds = append(c.xGoogHeaders, hds...)
720 hds = append(hds, "Content-Type", "application/json")
721 headers := gax.BuildHeaders(ctx, hds...)
722 return gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
723 if settings.Path != "" {
724 baseUrl.Path = settings.Path
725 }
726 httpReq, err := http.NewRequest("DELETE", baseUrl.String(), nil)
727 if err != nil {
728 return err
729 }
730 httpReq = httpReq.WithContext(ctx)
731 httpReq.Header = headers
732
733 httpRsp, err := c.httpClient.Do(httpReq)
734 if err != nil {
735 return err
736 }
737 defer httpRsp.Body.Close()
738
739
740
741 return googleapi.CheckResponse(httpRsp)
742 }, opts...)
743 }
744
745
746
747
748
749
750
751
752
753
754
755 func (c *operationsRESTClient) CancelOperation(ctx context.Context, req *longrunningpb.CancelOperationRequest, opts ...gax.CallOption) error {
756 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
757 jsonReq, err := m.Marshal(req)
758 if err != nil {
759 return err
760 }
761
762 baseUrl, err := url.Parse(c.endpoint)
763 if err != nil {
764 return err
765 }
766 baseUrl.Path += fmt.Sprintf("/v1/%v:cancel", req.GetName())
767
768
769 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
770
771 hds = append(c.xGoogHeaders, hds...)
772 hds = append(hds, "Content-Type", "application/json")
773 headers := gax.BuildHeaders(ctx, hds...)
774 return gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
775 if settings.Path != "" {
776 baseUrl.Path = settings.Path
777 }
778 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
779 if err != nil {
780 return err
781 }
782 httpReq = httpReq.WithContext(ctx)
783 httpReq.Header = headers
784
785 httpRsp, err := c.httpClient.Do(httpReq)
786 if err != nil {
787 return err
788 }
789 defer httpRsp.Body.Close()
790
791
792
793 return googleapi.CheckResponse(httpRsp)
794 }, opts...)
795 }
796
797
798
799
800
801
802
803
804
805
806 func (c *operationsRESTClient) WaitOperation(ctx context.Context, req *longrunningpb.WaitOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) {
807 baseUrl, err := url.Parse(c.endpoint)
808 if err != nil {
809 return nil, err
810 }
811 baseUrl.Path += fmt.Sprintf("")
812
813 params := url.Values{}
814 if req.GetName() != "" {
815 params.Add("name", fmt.Sprintf("%v", req.GetName()))
816 }
817 if req.GetTimeout() != nil {
818 timeout, err := protojson.Marshal(req.GetTimeout())
819 if err != nil {
820 return nil, err
821 }
822 params.Add("timeout", string(timeout[1:len(timeout)-1]))
823 }
824
825 baseUrl.RawQuery = params.Encode()
826
827
828 hds := append(c.xGoogHeaders, "Content-Type", "application/json")
829 headers := gax.BuildHeaders(ctx, hds...)
830 opts = append((*c.CallOptions).WaitOperation[0:len((*c.CallOptions).WaitOperation):len((*c.CallOptions).WaitOperation)], opts...)
831 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
832 resp := &longrunningpb.Operation{}
833 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
834 if settings.Path != "" {
835 baseUrl.Path = settings.Path
836 }
837 httpReq, err := http.NewRequest("", baseUrl.String(), nil)
838 if err != nil {
839 return err
840 }
841 httpReq = httpReq.WithContext(ctx)
842 httpReq.Header = headers
843
844 httpRsp, err := c.httpClient.Do(httpReq)
845 if err != nil {
846 return err
847 }
848 defer httpRsp.Body.Close()
849
850 if err = googleapi.CheckResponse(httpRsp); err != nil {
851 return err
852 }
853
854 buf, err := io.ReadAll(httpRsp.Body)
855 if err != nil {
856 return err
857 }
858
859 if err := unm.Unmarshal(buf, resp); err != nil {
860 return err
861 }
862
863 return nil
864 }, opts...)
865 if e != nil {
866 return nil, e
867 }
868 return resp, nil
869 }
870
View as plain text