1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package iam
18
19 import (
20 "bytes"
21 "context"
22 "fmt"
23 "io"
24 "math"
25 "net/http"
26 "net/url"
27 "time"
28
29 iampb "cloud.google.com/go/iam/apiv2/iampb"
30 "cloud.google.com/go/longrunning"
31 lroauto "cloud.google.com/go/longrunning/autogen"
32 longrunningpb "cloud.google.com/go/longrunning/autogen/longrunningpb"
33 gax "github.com/googleapis/gax-go/v2"
34 "google.golang.org/api/googleapi"
35 "google.golang.org/api/iterator"
36 "google.golang.org/api/option"
37 "google.golang.org/api/option/internaloption"
38 gtransport "google.golang.org/api/transport/grpc"
39 httptransport "google.golang.org/api/transport/http"
40 "google.golang.org/grpc"
41 "google.golang.org/grpc/codes"
42 "google.golang.org/protobuf/encoding/protojson"
43 "google.golang.org/protobuf/proto"
44 )
45
46 var newPoliciesClientHook clientHook
47
48
49 type PoliciesCallOptions struct {
50 ListPolicies []gax.CallOption
51 GetPolicy []gax.CallOption
52 CreatePolicy []gax.CallOption
53 UpdatePolicy []gax.CallOption
54 DeletePolicy []gax.CallOption
55 GetOperation []gax.CallOption
56 }
57
58 func defaultPoliciesGRPCClientOptions() []option.ClientOption {
59 return []option.ClientOption{
60 internaloption.WithDefaultEndpoint("iam.googleapis.com:443"),
61 internaloption.WithDefaultEndpointTemplate("iam.UNIVERSE_DOMAIN:443"),
62 internaloption.WithDefaultMTLSEndpoint("iam.mtls.googleapis.com:443"),
63 internaloption.WithDefaultUniverseDomain("googleapis.com"),
64 internaloption.WithDefaultAudience("https://iam.googleapis.com/"),
65 internaloption.WithDefaultScopes(DefaultAuthScopes()...),
66 internaloption.EnableJwtWithScope(),
67 option.WithGRPCDialOption(grpc.WithDefaultCallOptions(
68 grpc.MaxCallRecvMsgSize(math.MaxInt32))),
69 }
70 }
71
72 func defaultPoliciesCallOptions() *PoliciesCallOptions {
73 return &PoliciesCallOptions{
74 ListPolicies: []gax.CallOption{
75 gax.WithTimeout(60000 * time.Millisecond),
76 gax.WithRetry(func() gax.Retryer {
77 return gax.OnCodes([]codes.Code{
78 codes.Unavailable,
79 }, gax.Backoff{
80 Initial: 1000 * time.Millisecond,
81 Max: 10000 * time.Millisecond,
82 Multiplier: 1.30,
83 })
84 }),
85 },
86 GetPolicy: []gax.CallOption{
87 gax.WithTimeout(60000 * time.Millisecond),
88 gax.WithRetry(func() gax.Retryer {
89 return gax.OnCodes([]codes.Code{
90 codes.Unavailable,
91 }, gax.Backoff{
92 Initial: 1000 * time.Millisecond,
93 Max: 10000 * time.Millisecond,
94 Multiplier: 1.30,
95 })
96 }),
97 },
98 CreatePolicy: []gax.CallOption{
99 gax.WithTimeout(60000 * time.Millisecond),
100 gax.WithRetry(func() gax.Retryer {
101 return gax.OnCodes([]codes.Code{
102 codes.Unavailable,
103 }, gax.Backoff{
104 Initial: 1000 * time.Millisecond,
105 Max: 10000 * time.Millisecond,
106 Multiplier: 1.30,
107 })
108 }),
109 },
110 UpdatePolicy: []gax.CallOption{
111 gax.WithTimeout(60000 * time.Millisecond),
112 gax.WithRetry(func() gax.Retryer {
113 return gax.OnCodes([]codes.Code{
114 codes.Unavailable,
115 }, gax.Backoff{
116 Initial: 1000 * time.Millisecond,
117 Max: 10000 * time.Millisecond,
118 Multiplier: 1.30,
119 })
120 }),
121 },
122 DeletePolicy: []gax.CallOption{
123 gax.WithTimeout(60000 * time.Millisecond),
124 gax.WithRetry(func() gax.Retryer {
125 return gax.OnCodes([]codes.Code{
126 codes.Unavailable,
127 }, gax.Backoff{
128 Initial: 1000 * time.Millisecond,
129 Max: 10000 * time.Millisecond,
130 Multiplier: 1.30,
131 })
132 }),
133 },
134 GetOperation: []gax.CallOption{},
135 }
136 }
137
138 func defaultPoliciesRESTCallOptions() *PoliciesCallOptions {
139 return &PoliciesCallOptions{
140 ListPolicies: []gax.CallOption{
141 gax.WithTimeout(60000 * time.Millisecond),
142 gax.WithRetry(func() gax.Retryer {
143 return gax.OnHTTPCodes(gax.Backoff{
144 Initial: 1000 * time.Millisecond,
145 Max: 10000 * time.Millisecond,
146 Multiplier: 1.30,
147 },
148 http.StatusServiceUnavailable)
149 }),
150 },
151 GetPolicy: []gax.CallOption{
152 gax.WithTimeout(60000 * time.Millisecond),
153 gax.WithRetry(func() gax.Retryer {
154 return gax.OnHTTPCodes(gax.Backoff{
155 Initial: 1000 * time.Millisecond,
156 Max: 10000 * time.Millisecond,
157 Multiplier: 1.30,
158 },
159 http.StatusServiceUnavailable)
160 }),
161 },
162 CreatePolicy: []gax.CallOption{
163 gax.WithTimeout(60000 * time.Millisecond),
164 gax.WithRetry(func() gax.Retryer {
165 return gax.OnHTTPCodes(gax.Backoff{
166 Initial: 1000 * time.Millisecond,
167 Max: 10000 * time.Millisecond,
168 Multiplier: 1.30,
169 },
170 http.StatusServiceUnavailable)
171 }),
172 },
173 UpdatePolicy: []gax.CallOption{
174 gax.WithTimeout(60000 * time.Millisecond),
175 gax.WithRetry(func() gax.Retryer {
176 return gax.OnHTTPCodes(gax.Backoff{
177 Initial: 1000 * time.Millisecond,
178 Max: 10000 * time.Millisecond,
179 Multiplier: 1.30,
180 },
181 http.StatusServiceUnavailable)
182 }),
183 },
184 DeletePolicy: []gax.CallOption{
185 gax.WithTimeout(60000 * time.Millisecond),
186 gax.WithRetry(func() gax.Retryer {
187 return gax.OnHTTPCodes(gax.Backoff{
188 Initial: 1000 * time.Millisecond,
189 Max: 10000 * time.Millisecond,
190 Multiplier: 1.30,
191 },
192 http.StatusServiceUnavailable)
193 }),
194 },
195 GetOperation: []gax.CallOption{},
196 }
197 }
198
199
200 type internalPoliciesClient interface {
201 Close() error
202 setGoogleClientInfo(...string)
203 Connection() *grpc.ClientConn
204 ListPolicies(context.Context, *iampb.ListPoliciesRequest, ...gax.CallOption) *PolicyIterator
205 GetPolicy(context.Context, *iampb.GetPolicyRequest, ...gax.CallOption) (*iampb.Policy, error)
206 CreatePolicy(context.Context, *iampb.CreatePolicyRequest, ...gax.CallOption) (*CreatePolicyOperation, error)
207 CreatePolicyOperation(name string) *CreatePolicyOperation
208 UpdatePolicy(context.Context, *iampb.UpdatePolicyRequest, ...gax.CallOption) (*UpdatePolicyOperation, error)
209 UpdatePolicyOperation(name string) *UpdatePolicyOperation
210 DeletePolicy(context.Context, *iampb.DeletePolicyRequest, ...gax.CallOption) (*DeletePolicyOperation, error)
211 DeletePolicyOperation(name string) *DeletePolicyOperation
212 GetOperation(context.Context, *longrunningpb.GetOperationRequest, ...gax.CallOption) (*longrunningpb.Operation, error)
213 }
214
215
216
217
218
219 type PoliciesClient struct {
220
221 internalClient internalPoliciesClient
222
223
224 CallOptions *PoliciesCallOptions
225
226
227
228
229 LROClient *lroauto.OperationsClient
230 }
231
232
233
234
235
236 func (c *PoliciesClient) Close() error {
237 return c.internalClient.Close()
238 }
239
240
241
242
243 func (c *PoliciesClient) setGoogleClientInfo(keyval ...string) {
244 c.internalClient.setGoogleClientInfo(keyval...)
245 }
246
247
248
249
250
251 func (c *PoliciesClient) Connection() *grpc.ClientConn {
252 return c.internalClient.Connection()
253 }
254
255
256
257
258
259
260 func (c *PoliciesClient) ListPolicies(ctx context.Context, req *iampb.ListPoliciesRequest, opts ...gax.CallOption) *PolicyIterator {
261 return c.internalClient.ListPolicies(ctx, req, opts...)
262 }
263
264
265 func (c *PoliciesClient) GetPolicy(ctx context.Context, req *iampb.GetPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) {
266 return c.internalClient.GetPolicy(ctx, req, opts...)
267 }
268
269
270 func (c *PoliciesClient) CreatePolicy(ctx context.Context, req *iampb.CreatePolicyRequest, opts ...gax.CallOption) (*CreatePolicyOperation, error) {
271 return c.internalClient.CreatePolicy(ctx, req, opts...)
272 }
273
274
275
276 func (c *PoliciesClient) CreatePolicyOperation(name string) *CreatePolicyOperation {
277 return c.internalClient.CreatePolicyOperation(name)
278 }
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293 func (c *PoliciesClient) UpdatePolicy(ctx context.Context, req *iampb.UpdatePolicyRequest, opts ...gax.CallOption) (*UpdatePolicyOperation, error) {
294 return c.internalClient.UpdatePolicy(ctx, req, opts...)
295 }
296
297
298
299 func (c *PoliciesClient) UpdatePolicyOperation(name string) *UpdatePolicyOperation {
300 return c.internalClient.UpdatePolicyOperation(name)
301 }
302
303
304 func (c *PoliciesClient) DeletePolicy(ctx context.Context, req *iampb.DeletePolicyRequest, opts ...gax.CallOption) (*DeletePolicyOperation, error) {
305 return c.internalClient.DeletePolicy(ctx, req, opts...)
306 }
307
308
309
310 func (c *PoliciesClient) DeletePolicyOperation(name string) *DeletePolicyOperation {
311 return c.internalClient.DeletePolicyOperation(name)
312 }
313
314
315 func (c *PoliciesClient) GetOperation(ctx context.Context, req *longrunningpb.GetOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) {
316 return c.internalClient.GetOperation(ctx, req, opts...)
317 }
318
319
320
321
322 type policiesGRPCClient struct {
323
324 connPool gtransport.ConnPool
325
326
327 CallOptions **PoliciesCallOptions
328
329
330 policiesClient iampb.PoliciesClient
331
332
333
334
335 LROClient **lroauto.OperationsClient
336
337 operationsClient longrunningpb.OperationsClient
338
339
340 xGoogHeaders []string
341 }
342
343
344
345
346
347 func NewPoliciesClient(ctx context.Context, opts ...option.ClientOption) (*PoliciesClient, error) {
348 clientOpts := defaultPoliciesGRPCClientOptions()
349 if newPoliciesClientHook != nil {
350 hookOpts, err := newPoliciesClientHook(ctx, clientHookParams{})
351 if err != nil {
352 return nil, err
353 }
354 clientOpts = append(clientOpts, hookOpts...)
355 }
356
357 connPool, err := gtransport.DialPool(ctx, append(clientOpts, opts...)...)
358 if err != nil {
359 return nil, err
360 }
361 client := PoliciesClient{CallOptions: defaultPoliciesCallOptions()}
362
363 c := &policiesGRPCClient{
364 connPool: connPool,
365 policiesClient: iampb.NewPoliciesClient(connPool),
366 CallOptions: &client.CallOptions,
367 operationsClient: longrunningpb.NewOperationsClient(connPool),
368 }
369 c.setGoogleClientInfo()
370
371 client.internalClient = c
372
373 client.LROClient, err = lroauto.NewOperationsClient(ctx, gtransport.WithConnPool(connPool))
374 if err != nil {
375
376
377
378
379
380
381 return nil, err
382 }
383 c.LROClient = &client.LROClient
384 return &client, nil
385 }
386
387
388
389
390
391 func (c *policiesGRPCClient) Connection() *grpc.ClientConn {
392 return c.connPool.Conn()
393 }
394
395
396
397
398 func (c *policiesGRPCClient) setGoogleClientInfo(keyval ...string) {
399 kv := append([]string{"gl-go", gax.GoVersion}, keyval...)
400 kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "grpc", grpc.Version)
401 c.xGoogHeaders = []string{"x-goog-api-client", gax.XGoogHeader(kv...)}
402 }
403
404
405
406 func (c *policiesGRPCClient) Close() error {
407 return c.connPool.Close()
408 }
409
410
411 type policiesRESTClient struct {
412
413 endpoint string
414
415
416 httpClient *http.Client
417
418
419
420
421 LROClient **lroauto.OperationsClient
422
423
424 xGoogHeaders []string
425
426
427 CallOptions **PoliciesCallOptions
428 }
429
430
431
432
433 func NewPoliciesRESTClient(ctx context.Context, opts ...option.ClientOption) (*PoliciesClient, error) {
434 clientOpts := append(defaultPoliciesRESTClientOptions(), opts...)
435 httpClient, endpoint, err := httptransport.NewClient(ctx, clientOpts...)
436 if err != nil {
437 return nil, err
438 }
439
440 callOpts := defaultPoliciesRESTCallOptions()
441 c := &policiesRESTClient{
442 endpoint: endpoint,
443 httpClient: httpClient,
444 CallOptions: &callOpts,
445 }
446 c.setGoogleClientInfo()
447
448 lroOpts := []option.ClientOption{
449 option.WithHTTPClient(httpClient),
450 option.WithEndpoint(endpoint),
451 }
452 opClient, err := lroauto.NewOperationsRESTClient(ctx, lroOpts...)
453 if err != nil {
454 return nil, err
455 }
456 c.LROClient = &opClient
457
458 return &PoliciesClient{internalClient: c, CallOptions: callOpts}, nil
459 }
460
461 func defaultPoliciesRESTClientOptions() []option.ClientOption {
462 return []option.ClientOption{
463 internaloption.WithDefaultEndpoint("https://iam.googleapis.com"),
464 internaloption.WithDefaultEndpointTemplate("https://iam.UNIVERSE_DOMAIN"),
465 internaloption.WithDefaultMTLSEndpoint("https://iam.mtls.googleapis.com"),
466 internaloption.WithDefaultUniverseDomain("googleapis.com"),
467 internaloption.WithDefaultAudience("https://iam.googleapis.com/"),
468 internaloption.WithDefaultScopes(DefaultAuthScopes()...),
469 }
470 }
471
472
473
474
475 func (c *policiesRESTClient) setGoogleClientInfo(keyval ...string) {
476 kv := append([]string{"gl-go", gax.GoVersion}, keyval...)
477 kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "rest", "UNKNOWN")
478 c.xGoogHeaders = []string{"x-goog-api-client", gax.XGoogHeader(kv...)}
479 }
480
481
482
483 func (c *policiesRESTClient) Close() error {
484
485 c.httpClient = nil
486 return nil
487 }
488
489
490
491
492 func (c *policiesRESTClient) Connection() *grpc.ClientConn {
493 return nil
494 }
495 func (c *policiesGRPCClient) ListPolicies(ctx context.Context, req *iampb.ListPoliciesRequest, opts ...gax.CallOption) *PolicyIterator {
496 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
497
498 hds = append(c.xGoogHeaders, hds...)
499 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
500 opts = append((*c.CallOptions).ListPolicies[0:len((*c.CallOptions).ListPolicies):len((*c.CallOptions).ListPolicies)], opts...)
501 it := &PolicyIterator{}
502 req = proto.Clone(req).(*iampb.ListPoliciesRequest)
503 it.InternalFetch = func(pageSize int, pageToken string) ([]*iampb.Policy, string, error) {
504 resp := &iampb.ListPoliciesResponse{}
505 if pageToken != "" {
506 req.PageToken = pageToken
507 }
508 if pageSize > math.MaxInt32 {
509 req.PageSize = math.MaxInt32
510 } else if pageSize != 0 {
511 req.PageSize = int32(pageSize)
512 }
513 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
514 var err error
515 resp, err = c.policiesClient.ListPolicies(ctx, req, settings.GRPC...)
516 return err
517 }, opts...)
518 if err != nil {
519 return nil, "", err
520 }
521
522 it.Response = resp
523 return resp.GetPolicies(), resp.GetNextPageToken(), nil
524 }
525 fetch := func(pageSize int, pageToken string) (string, error) {
526 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
527 if err != nil {
528 return "", err
529 }
530 it.items = append(it.items, items...)
531 return nextPageToken, nil
532 }
533
534 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
535 it.pageInfo.MaxSize = int(req.GetPageSize())
536 it.pageInfo.Token = req.GetPageToken()
537
538 return it
539 }
540
541 func (c *policiesGRPCClient) GetPolicy(ctx context.Context, req *iampb.GetPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) {
542 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
543
544 hds = append(c.xGoogHeaders, hds...)
545 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
546 opts = append((*c.CallOptions).GetPolicy[0:len((*c.CallOptions).GetPolicy):len((*c.CallOptions).GetPolicy)], opts...)
547 var resp *iampb.Policy
548 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
549 var err error
550 resp, err = c.policiesClient.GetPolicy(ctx, req, settings.GRPC...)
551 return err
552 }, opts...)
553 if err != nil {
554 return nil, err
555 }
556 return resp, nil
557 }
558
559 func (c *policiesGRPCClient) CreatePolicy(ctx context.Context, req *iampb.CreatePolicyRequest, opts ...gax.CallOption) (*CreatePolicyOperation, error) {
560 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
561
562 hds = append(c.xGoogHeaders, hds...)
563 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
564 opts = append((*c.CallOptions).CreatePolicy[0:len((*c.CallOptions).CreatePolicy):len((*c.CallOptions).CreatePolicy)], opts...)
565 var resp *longrunningpb.Operation
566 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
567 var err error
568 resp, err = c.policiesClient.CreatePolicy(ctx, req, settings.GRPC...)
569 return err
570 }, opts...)
571 if err != nil {
572 return nil, err
573 }
574 return &CreatePolicyOperation{
575 lro: longrunning.InternalNewOperation(*c.LROClient, resp),
576 }, nil
577 }
578
579 func (c *policiesGRPCClient) UpdatePolicy(ctx context.Context, req *iampb.UpdatePolicyRequest, opts ...gax.CallOption) (*UpdatePolicyOperation, error) {
580 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "policy.name", url.QueryEscape(req.GetPolicy().GetName()))}
581
582 hds = append(c.xGoogHeaders, hds...)
583 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
584 opts = append((*c.CallOptions).UpdatePolicy[0:len((*c.CallOptions).UpdatePolicy):len((*c.CallOptions).UpdatePolicy)], opts...)
585 var resp *longrunningpb.Operation
586 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
587 var err error
588 resp, err = c.policiesClient.UpdatePolicy(ctx, req, settings.GRPC...)
589 return err
590 }, opts...)
591 if err != nil {
592 return nil, err
593 }
594 return &UpdatePolicyOperation{
595 lro: longrunning.InternalNewOperation(*c.LROClient, resp),
596 }, nil
597 }
598
599 func (c *policiesGRPCClient) DeletePolicy(ctx context.Context, req *iampb.DeletePolicyRequest, opts ...gax.CallOption) (*DeletePolicyOperation, error) {
600 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
601
602 hds = append(c.xGoogHeaders, hds...)
603 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
604 opts = append((*c.CallOptions).DeletePolicy[0:len((*c.CallOptions).DeletePolicy):len((*c.CallOptions).DeletePolicy)], opts...)
605 var resp *longrunningpb.Operation
606 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
607 var err error
608 resp, err = c.policiesClient.DeletePolicy(ctx, req, settings.GRPC...)
609 return err
610 }, opts...)
611 if err != nil {
612 return nil, err
613 }
614 return &DeletePolicyOperation{
615 lro: longrunning.InternalNewOperation(*c.LROClient, resp),
616 }, nil
617 }
618
619 func (c *policiesGRPCClient) GetOperation(ctx context.Context, req *longrunningpb.GetOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) {
620 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
621
622 hds = append(c.xGoogHeaders, hds...)
623 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
624 opts = append((*c.CallOptions).GetOperation[0:len((*c.CallOptions).GetOperation):len((*c.CallOptions).GetOperation)], opts...)
625 var resp *longrunningpb.Operation
626 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
627 var err error
628 resp, err = c.operationsClient.GetOperation(ctx, req, settings.GRPC...)
629 return err
630 }, opts...)
631 if err != nil {
632 return nil, err
633 }
634 return resp, nil
635 }
636
637
638
639
640
641
642 func (c *policiesRESTClient) ListPolicies(ctx context.Context, req *iampb.ListPoliciesRequest, opts ...gax.CallOption) *PolicyIterator {
643 it := &PolicyIterator{}
644 req = proto.Clone(req).(*iampb.ListPoliciesRequest)
645 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
646 it.InternalFetch = func(pageSize int, pageToken string) ([]*iampb.Policy, string, error) {
647 resp := &iampb.ListPoliciesResponse{}
648 if pageToken != "" {
649 req.PageToken = pageToken
650 }
651 if pageSize > math.MaxInt32 {
652 req.PageSize = math.MaxInt32
653 } else if pageSize != 0 {
654 req.PageSize = int32(pageSize)
655 }
656 baseUrl, err := url.Parse(c.endpoint)
657 if err != nil {
658 return nil, "", err
659 }
660 baseUrl.Path += fmt.Sprintf("/v2/%v", req.GetParent())
661
662 params := url.Values{}
663 params.Add("$alt", "json;enum-encoding=int")
664 if req.GetPageSize() != 0 {
665 params.Add("pageSize", fmt.Sprintf("%v", req.GetPageSize()))
666 }
667 if req.GetPageToken() != "" {
668 params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken()))
669 }
670
671 baseUrl.RawQuery = params.Encode()
672
673
674 hds := append(c.xGoogHeaders, "Content-Type", "application/json")
675 headers := gax.BuildHeaders(ctx, hds...)
676 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
677 if settings.Path != "" {
678 baseUrl.Path = settings.Path
679 }
680 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
681 if err != nil {
682 return err
683 }
684 httpReq.Header = headers
685
686 httpRsp, err := c.httpClient.Do(httpReq)
687 if err != nil {
688 return err
689 }
690 defer httpRsp.Body.Close()
691
692 if err = googleapi.CheckResponse(httpRsp); err != nil {
693 return err
694 }
695
696 buf, err := io.ReadAll(httpRsp.Body)
697 if err != nil {
698 return err
699 }
700
701 if err := unm.Unmarshal(buf, resp); err != nil {
702 return err
703 }
704
705 return nil
706 }, opts...)
707 if e != nil {
708 return nil, "", e
709 }
710 it.Response = resp
711 return resp.GetPolicies(), resp.GetNextPageToken(), nil
712 }
713
714 fetch := func(pageSize int, pageToken string) (string, error) {
715 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
716 if err != nil {
717 return "", err
718 }
719 it.items = append(it.items, items...)
720 return nextPageToken, nil
721 }
722
723 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
724 it.pageInfo.MaxSize = int(req.GetPageSize())
725 it.pageInfo.Token = req.GetPageToken()
726
727 return it
728 }
729
730
731 func (c *policiesRESTClient) GetPolicy(ctx context.Context, req *iampb.GetPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) {
732 baseUrl, err := url.Parse(c.endpoint)
733 if err != nil {
734 return nil, err
735 }
736 baseUrl.Path += fmt.Sprintf("/v2/%v", req.GetName())
737
738 params := url.Values{}
739 params.Add("$alt", "json;enum-encoding=int")
740
741 baseUrl.RawQuery = params.Encode()
742
743
744 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
745
746 hds = append(c.xGoogHeaders, hds...)
747 hds = append(hds, "Content-Type", "application/json")
748 headers := gax.BuildHeaders(ctx, hds...)
749 opts = append((*c.CallOptions).GetPolicy[0:len((*c.CallOptions).GetPolicy):len((*c.CallOptions).GetPolicy)], opts...)
750 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
751 resp := &iampb.Policy{}
752 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
753 if settings.Path != "" {
754 baseUrl.Path = settings.Path
755 }
756 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
757 if err != nil {
758 return err
759 }
760 httpReq = httpReq.WithContext(ctx)
761 httpReq.Header = headers
762
763 httpRsp, err := c.httpClient.Do(httpReq)
764 if err != nil {
765 return err
766 }
767 defer httpRsp.Body.Close()
768
769 if err = googleapi.CheckResponse(httpRsp); err != nil {
770 return err
771 }
772
773 buf, err := io.ReadAll(httpRsp.Body)
774 if err != nil {
775 return err
776 }
777
778 if err := unm.Unmarshal(buf, resp); err != nil {
779 return err
780 }
781
782 return nil
783 }, opts...)
784 if e != nil {
785 return nil, e
786 }
787 return resp, nil
788 }
789
790
791 func (c *policiesRESTClient) CreatePolicy(ctx context.Context, req *iampb.CreatePolicyRequest, opts ...gax.CallOption) (*CreatePolicyOperation, error) {
792 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
793 body := req.GetPolicy()
794 jsonReq, err := m.Marshal(body)
795 if err != nil {
796 return nil, err
797 }
798
799 baseUrl, err := url.Parse(c.endpoint)
800 if err != nil {
801 return nil, err
802 }
803 baseUrl.Path += fmt.Sprintf("/v2/%v", req.GetParent())
804
805 params := url.Values{}
806 params.Add("$alt", "json;enum-encoding=int")
807 if req.GetPolicyId() != "" {
808 params.Add("policyId", fmt.Sprintf("%v", req.GetPolicyId()))
809 }
810
811 baseUrl.RawQuery = params.Encode()
812
813
814 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
815
816 hds = append(c.xGoogHeaders, hds...)
817 hds = append(hds, "Content-Type", "application/json")
818 headers := gax.BuildHeaders(ctx, hds...)
819 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
820 resp := &longrunningpb.Operation{}
821 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
822 if settings.Path != "" {
823 baseUrl.Path = settings.Path
824 }
825 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
826 if err != nil {
827 return err
828 }
829 httpReq = httpReq.WithContext(ctx)
830 httpReq.Header = headers
831
832 httpRsp, err := c.httpClient.Do(httpReq)
833 if err != nil {
834 return err
835 }
836 defer httpRsp.Body.Close()
837
838 if err = googleapi.CheckResponse(httpRsp); err != nil {
839 return err
840 }
841
842 buf, err := io.ReadAll(httpRsp.Body)
843 if err != nil {
844 return err
845 }
846
847 if err := unm.Unmarshal(buf, resp); err != nil {
848 return err
849 }
850
851 return nil
852 }, opts...)
853 if e != nil {
854 return nil, e
855 }
856
857 override := fmt.Sprintf("/v2/%s", resp.GetName())
858 return &CreatePolicyOperation{
859 lro: longrunning.InternalNewOperation(*c.LROClient, resp),
860 pollPath: override,
861 }, nil
862 }
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877 func (c *policiesRESTClient) UpdatePolicy(ctx context.Context, req *iampb.UpdatePolicyRequest, opts ...gax.CallOption) (*UpdatePolicyOperation, error) {
878 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
879 body := req.GetPolicy()
880 jsonReq, err := m.Marshal(body)
881 if err != nil {
882 return nil, err
883 }
884
885 baseUrl, err := url.Parse(c.endpoint)
886 if err != nil {
887 return nil, err
888 }
889 baseUrl.Path += fmt.Sprintf("/v2/%v", req.GetPolicy().GetName())
890
891 params := url.Values{}
892 params.Add("$alt", "json;enum-encoding=int")
893
894 baseUrl.RawQuery = params.Encode()
895
896
897 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "policy.name", url.QueryEscape(req.GetPolicy().GetName()))}
898
899 hds = append(c.xGoogHeaders, hds...)
900 hds = append(hds, "Content-Type", "application/json")
901 headers := gax.BuildHeaders(ctx, hds...)
902 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
903 resp := &longrunningpb.Operation{}
904 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
905 if settings.Path != "" {
906 baseUrl.Path = settings.Path
907 }
908 httpReq, err := http.NewRequest("PUT", baseUrl.String(), bytes.NewReader(jsonReq))
909 if err != nil {
910 return err
911 }
912 httpReq = httpReq.WithContext(ctx)
913 httpReq.Header = headers
914
915 httpRsp, err := c.httpClient.Do(httpReq)
916 if err != nil {
917 return err
918 }
919 defer httpRsp.Body.Close()
920
921 if err = googleapi.CheckResponse(httpRsp); err != nil {
922 return err
923 }
924
925 buf, err := io.ReadAll(httpRsp.Body)
926 if err != nil {
927 return err
928 }
929
930 if err := unm.Unmarshal(buf, resp); err != nil {
931 return err
932 }
933
934 return nil
935 }, opts...)
936 if e != nil {
937 return nil, e
938 }
939
940 override := fmt.Sprintf("/v2/%s", resp.GetName())
941 return &UpdatePolicyOperation{
942 lro: longrunning.InternalNewOperation(*c.LROClient, resp),
943 pollPath: override,
944 }, nil
945 }
946
947
948 func (c *policiesRESTClient) DeletePolicy(ctx context.Context, req *iampb.DeletePolicyRequest, opts ...gax.CallOption) (*DeletePolicyOperation, error) {
949 baseUrl, err := url.Parse(c.endpoint)
950 if err != nil {
951 return nil, err
952 }
953 baseUrl.Path += fmt.Sprintf("/v2/%v", req.GetName())
954
955 params := url.Values{}
956 params.Add("$alt", "json;enum-encoding=int")
957 if req.GetEtag() != "" {
958 params.Add("etag", fmt.Sprintf("%v", req.GetEtag()))
959 }
960
961 baseUrl.RawQuery = params.Encode()
962
963
964 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
965
966 hds = append(c.xGoogHeaders, hds...)
967 hds = append(hds, "Content-Type", "application/json")
968 headers := gax.BuildHeaders(ctx, hds...)
969 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
970 resp := &longrunningpb.Operation{}
971 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
972 if settings.Path != "" {
973 baseUrl.Path = settings.Path
974 }
975 httpReq, err := http.NewRequest("DELETE", baseUrl.String(), nil)
976 if err != nil {
977 return err
978 }
979 httpReq = httpReq.WithContext(ctx)
980 httpReq.Header = headers
981
982 httpRsp, err := c.httpClient.Do(httpReq)
983 if err != nil {
984 return err
985 }
986 defer httpRsp.Body.Close()
987
988 if err = googleapi.CheckResponse(httpRsp); err != nil {
989 return err
990 }
991
992 buf, err := io.ReadAll(httpRsp.Body)
993 if err != nil {
994 return err
995 }
996
997 if err := unm.Unmarshal(buf, resp); err != nil {
998 return err
999 }
1000
1001 return nil
1002 }, opts...)
1003 if e != nil {
1004 return nil, e
1005 }
1006
1007 override := fmt.Sprintf("/v2/%s", resp.GetName())
1008 return &DeletePolicyOperation{
1009 lro: longrunning.InternalNewOperation(*c.LROClient, resp),
1010 pollPath: override,
1011 }, nil
1012 }
1013
1014
1015 func (c *policiesRESTClient) GetOperation(ctx context.Context, req *longrunningpb.GetOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) {
1016 baseUrl, err := url.Parse(c.endpoint)
1017 if err != nil {
1018 return nil, err
1019 }
1020 baseUrl.Path += fmt.Sprintf("/v2/%v", req.GetName())
1021
1022 params := url.Values{}
1023 params.Add("$alt", "json;enum-encoding=int")
1024
1025 baseUrl.RawQuery = params.Encode()
1026
1027
1028 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
1029
1030 hds = append(c.xGoogHeaders, hds...)
1031 hds = append(hds, "Content-Type", "application/json")
1032 headers := gax.BuildHeaders(ctx, hds...)
1033 opts = append((*c.CallOptions).GetOperation[0:len((*c.CallOptions).GetOperation):len((*c.CallOptions).GetOperation)], opts...)
1034 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
1035 resp := &longrunningpb.Operation{}
1036 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1037 if settings.Path != "" {
1038 baseUrl.Path = settings.Path
1039 }
1040 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
1041 if err != nil {
1042 return err
1043 }
1044 httpReq = httpReq.WithContext(ctx)
1045 httpReq.Header = headers
1046
1047 httpRsp, err := c.httpClient.Do(httpReq)
1048 if err != nil {
1049 return err
1050 }
1051 defer httpRsp.Body.Close()
1052
1053 if err = googleapi.CheckResponse(httpRsp); err != nil {
1054 return err
1055 }
1056
1057 buf, err := io.ReadAll(httpRsp.Body)
1058 if err != nil {
1059 return err
1060 }
1061
1062 if err := unm.Unmarshal(buf, resp); err != nil {
1063 return err
1064 }
1065
1066 return nil
1067 }, opts...)
1068 if e != nil {
1069 return nil, e
1070 }
1071 return resp, nil
1072 }
1073
1074
1075
1076 func (c *policiesGRPCClient) CreatePolicyOperation(name string) *CreatePolicyOperation {
1077 return &CreatePolicyOperation{
1078 lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}),
1079 }
1080 }
1081
1082
1083
1084 func (c *policiesRESTClient) CreatePolicyOperation(name string) *CreatePolicyOperation {
1085 override := fmt.Sprintf("/v2/%s", name)
1086 return &CreatePolicyOperation{
1087 lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}),
1088 pollPath: override,
1089 }
1090 }
1091
1092
1093
1094 func (c *policiesGRPCClient) DeletePolicyOperation(name string) *DeletePolicyOperation {
1095 return &DeletePolicyOperation{
1096 lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}),
1097 }
1098 }
1099
1100
1101
1102 func (c *policiesRESTClient) DeletePolicyOperation(name string) *DeletePolicyOperation {
1103 override := fmt.Sprintf("/v2/%s", name)
1104 return &DeletePolicyOperation{
1105 lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}),
1106 pollPath: override,
1107 }
1108 }
1109
1110
1111
1112 func (c *policiesGRPCClient) UpdatePolicyOperation(name string) *UpdatePolicyOperation {
1113 return &UpdatePolicyOperation{
1114 lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}),
1115 }
1116 }
1117
1118
1119
1120 func (c *policiesRESTClient) UpdatePolicyOperation(name string) *UpdatePolicyOperation {
1121 override := fmt.Sprintf("/v2/%s", name)
1122 return &UpdatePolicyOperation{
1123 lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}),
1124 pollPath: override,
1125 }
1126 }
1127
View as plain text