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