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 "cloud.google.com/go/longrunning"
31 lroauto "cloud.google.com/go/longrunning/autogen"
32 longrunningpb "cloud.google.com/go/longrunning/autogen/longrunningpb"
33 resourcemanagerpb "cloud.google.com/go/resourcemanager/apiv3/resourcemanagerpb"
34 gax "github.com/googleapis/gax-go/v2"
35 "google.golang.org/api/googleapi"
36 "google.golang.org/api/iterator"
37 "google.golang.org/api/option"
38 "google.golang.org/api/option/internaloption"
39 gtransport "google.golang.org/api/transport/grpc"
40 httptransport "google.golang.org/api/transport/http"
41 "google.golang.org/grpc"
42 "google.golang.org/grpc/codes"
43 "google.golang.org/protobuf/encoding/protojson"
44 "google.golang.org/protobuf/proto"
45 )
46
47 var newProjectsClientHook clientHook
48
49
50 type ProjectsCallOptions struct {
51 GetProject []gax.CallOption
52 ListProjects []gax.CallOption
53 SearchProjects []gax.CallOption
54 CreateProject []gax.CallOption
55 UpdateProject []gax.CallOption
56 MoveProject []gax.CallOption
57 DeleteProject []gax.CallOption
58 UndeleteProject []gax.CallOption
59 GetIamPolicy []gax.CallOption
60 SetIamPolicy []gax.CallOption
61 TestIamPermissions []gax.CallOption
62 GetOperation []gax.CallOption
63 }
64
65 func defaultProjectsGRPCClientOptions() []option.ClientOption {
66 return []option.ClientOption{
67 internaloption.WithDefaultEndpoint("cloudresourcemanager.googleapis.com:443"),
68 internaloption.WithDefaultEndpointTemplate("cloudresourcemanager.UNIVERSE_DOMAIN:443"),
69 internaloption.WithDefaultMTLSEndpoint("cloudresourcemanager.mtls.googleapis.com:443"),
70 internaloption.WithDefaultUniverseDomain("googleapis.com"),
71 internaloption.WithDefaultAudience("https://cloudresourcemanager.googleapis.com/"),
72 internaloption.WithDefaultScopes(DefaultAuthScopes()...),
73 internaloption.EnableJwtWithScope(),
74 option.WithGRPCDialOption(grpc.WithDefaultCallOptions(
75 grpc.MaxCallRecvMsgSize(math.MaxInt32))),
76 }
77 }
78
79 func defaultProjectsCallOptions() *ProjectsCallOptions {
80 return &ProjectsCallOptions{
81 GetProject: []gax.CallOption{
82 gax.WithTimeout(60000 * time.Millisecond),
83 gax.WithRetry(func() gax.Retryer {
84 return gax.OnCodes([]codes.Code{
85 codes.Unavailable,
86 }, gax.Backoff{
87 Initial: 100 * time.Millisecond,
88 Max: 60000 * time.Millisecond,
89 Multiplier: 1.30,
90 })
91 }),
92 },
93 ListProjects: []gax.CallOption{
94 gax.WithTimeout(60000 * time.Millisecond),
95 gax.WithRetry(func() gax.Retryer {
96 return gax.OnCodes([]codes.Code{
97 codes.Unavailable,
98 }, gax.Backoff{
99 Initial: 100 * time.Millisecond,
100 Max: 60000 * time.Millisecond,
101 Multiplier: 1.30,
102 })
103 }),
104 },
105 SearchProjects: []gax.CallOption{
106 gax.WithTimeout(60000 * time.Millisecond),
107 },
108 CreateProject: []gax.CallOption{
109 gax.WithTimeout(60000 * time.Millisecond),
110 },
111 UpdateProject: []gax.CallOption{
112 gax.WithTimeout(60000 * time.Millisecond),
113 },
114 MoveProject: []gax.CallOption{
115 gax.WithTimeout(60000 * time.Millisecond),
116 },
117 DeleteProject: []gax.CallOption{
118 gax.WithTimeout(60000 * time.Millisecond),
119 },
120 UndeleteProject: []gax.CallOption{
121 gax.WithTimeout(60000 * time.Millisecond),
122 },
123 GetIamPolicy: []gax.CallOption{
124 gax.WithTimeout(60000 * time.Millisecond),
125 gax.WithRetry(func() gax.Retryer {
126 return gax.OnCodes([]codes.Code{
127 codes.Unavailable,
128 }, gax.Backoff{
129 Initial: 100 * time.Millisecond,
130 Max: 60000 * time.Millisecond,
131 Multiplier: 1.30,
132 })
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 func defaultProjectsRESTCallOptions() *ProjectsCallOptions {
144 return &ProjectsCallOptions{
145 GetProject: []gax.CallOption{
146 gax.WithTimeout(60000 * time.Millisecond),
147 gax.WithRetry(func() gax.Retryer {
148 return gax.OnHTTPCodes(gax.Backoff{
149 Initial: 100 * time.Millisecond,
150 Max: 60000 * time.Millisecond,
151 Multiplier: 1.30,
152 },
153 http.StatusServiceUnavailable)
154 }),
155 },
156 ListProjects: []gax.CallOption{
157 gax.WithTimeout(60000 * time.Millisecond),
158 gax.WithRetry(func() gax.Retryer {
159 return gax.OnHTTPCodes(gax.Backoff{
160 Initial: 100 * time.Millisecond,
161 Max: 60000 * time.Millisecond,
162 Multiplier: 1.30,
163 },
164 http.StatusServiceUnavailable)
165 }),
166 },
167 SearchProjects: []gax.CallOption{
168 gax.WithTimeout(60000 * time.Millisecond),
169 },
170 CreateProject: []gax.CallOption{
171 gax.WithTimeout(60000 * time.Millisecond),
172 },
173 UpdateProject: []gax.CallOption{
174 gax.WithTimeout(60000 * time.Millisecond),
175 },
176 MoveProject: []gax.CallOption{
177 gax.WithTimeout(60000 * time.Millisecond),
178 },
179 DeleteProject: []gax.CallOption{
180 gax.WithTimeout(60000 * time.Millisecond),
181 },
182 UndeleteProject: []gax.CallOption{
183 gax.WithTimeout(60000 * time.Millisecond),
184 },
185 GetIamPolicy: []gax.CallOption{
186 gax.WithTimeout(60000 * time.Millisecond),
187 gax.WithRetry(func() gax.Retryer {
188 return gax.OnHTTPCodes(gax.Backoff{
189 Initial: 100 * time.Millisecond,
190 Max: 60000 * time.Millisecond,
191 Multiplier: 1.30,
192 },
193 http.StatusServiceUnavailable)
194 }),
195 },
196 SetIamPolicy: []gax.CallOption{
197 gax.WithTimeout(60000 * time.Millisecond),
198 },
199 TestIamPermissions: []gax.CallOption{},
200 GetOperation: []gax.CallOption{},
201 }
202 }
203
204
205 type internalProjectsClient interface {
206 Close() error
207 setGoogleClientInfo(...string)
208 Connection() *grpc.ClientConn
209 GetProject(context.Context, *resourcemanagerpb.GetProjectRequest, ...gax.CallOption) (*resourcemanagerpb.Project, error)
210 ListProjects(context.Context, *resourcemanagerpb.ListProjectsRequest, ...gax.CallOption) *ProjectIterator
211 SearchProjects(context.Context, *resourcemanagerpb.SearchProjectsRequest, ...gax.CallOption) *ProjectIterator
212 CreateProject(context.Context, *resourcemanagerpb.CreateProjectRequest, ...gax.CallOption) (*CreateProjectOperation, error)
213 CreateProjectOperation(name string) *CreateProjectOperation
214 UpdateProject(context.Context, *resourcemanagerpb.UpdateProjectRequest, ...gax.CallOption) (*UpdateProjectOperation, error)
215 UpdateProjectOperation(name string) *UpdateProjectOperation
216 MoveProject(context.Context, *resourcemanagerpb.MoveProjectRequest, ...gax.CallOption) (*MoveProjectOperation, error)
217 MoveProjectOperation(name string) *MoveProjectOperation
218 DeleteProject(context.Context, *resourcemanagerpb.DeleteProjectRequest, ...gax.CallOption) (*DeleteProjectOperation, error)
219 DeleteProjectOperation(name string) *DeleteProjectOperation
220 UndeleteProject(context.Context, *resourcemanagerpb.UndeleteProjectRequest, ...gax.CallOption) (*UndeleteProjectOperation, error)
221 UndeleteProjectOperation(name string) *UndeleteProjectOperation
222 GetIamPolicy(context.Context, *iampb.GetIamPolicyRequest, ...gax.CallOption) (*iampb.Policy, error)
223 SetIamPolicy(context.Context, *iampb.SetIamPolicyRequest, ...gax.CallOption) (*iampb.Policy, error)
224 TestIamPermissions(context.Context, *iampb.TestIamPermissionsRequest, ...gax.CallOption) (*iampb.TestIamPermissionsResponse, error)
225 GetOperation(context.Context, *longrunningpb.GetOperationRequest, ...gax.CallOption) (*longrunningpb.Operation, error)
226 }
227
228
229
230
231
232 type ProjectsClient struct {
233
234 internalClient internalProjectsClient
235
236
237 CallOptions *ProjectsCallOptions
238
239
240
241
242 LROClient *lroauto.OperationsClient
243 }
244
245
246
247
248
249 func (c *ProjectsClient) Close() error {
250 return c.internalClient.Close()
251 }
252
253
254
255
256 func (c *ProjectsClient) setGoogleClientInfo(keyval ...string) {
257 c.internalClient.setGoogleClientInfo(keyval...)
258 }
259
260
261
262
263
264 func (c *ProjectsClient) Connection() *grpc.ClientConn {
265 return c.internalClient.Connection()
266 }
267
268
269
270
271
272
273 func (c *ProjectsClient) GetProject(ctx context.Context, req *resourcemanagerpb.GetProjectRequest, opts ...gax.CallOption) (*resourcemanagerpb.Project, error) {
274 return c.internalClient.GetProject(ctx, req, opts...)
275 }
276
277
278
279
280
281
282
283 func (c *ProjectsClient) ListProjects(ctx context.Context, req *resourcemanagerpb.ListProjectsRequest, opts ...gax.CallOption) *ProjectIterator {
284 return c.internalClient.ListProjects(ctx, req, opts...)
285 }
286
287
288
289
290
291
292
293
294
295
296
297 func (c *ProjectsClient) SearchProjects(ctx context.Context, req *resourcemanagerpb.SearchProjectsRequest, opts ...gax.CallOption) *ProjectIterator {
298 return c.internalClient.SearchProjects(ctx, req, opts...)
299 }
300
301
302
303
304
305
306 func (c *ProjectsClient) CreateProject(ctx context.Context, req *resourcemanagerpb.CreateProjectRequest, opts ...gax.CallOption) (*CreateProjectOperation, error) {
307 return c.internalClient.CreateProject(ctx, req, opts...)
308 }
309
310
311
312 func (c *ProjectsClient) CreateProjectOperation(name string) *CreateProjectOperation {
313 return c.internalClient.CreateProjectOperation(name)
314 }
315
316
317
318
319
320
321
322 func (c *ProjectsClient) UpdateProject(ctx context.Context, req *resourcemanagerpb.UpdateProjectRequest, opts ...gax.CallOption) (*UpdateProjectOperation, error) {
323 return c.internalClient.UpdateProject(ctx, req, opts...)
324 }
325
326
327
328 func (c *ProjectsClient) UpdateProjectOperation(name string) *UpdateProjectOperation {
329 return c.internalClient.UpdateProjectOperation(name)
330 }
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346 func (c *ProjectsClient) MoveProject(ctx context.Context, req *resourcemanagerpb.MoveProjectRequest, opts ...gax.CallOption) (*MoveProjectOperation, error) {
347 return c.internalClient.MoveProject(ctx, req, opts...)
348 }
349
350
351
352 func (c *ProjectsClient) MoveProjectOperation(name string) *MoveProjectOperation {
353 return c.internalClient.MoveProjectOperation(name)
354 }
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389 func (c *ProjectsClient) DeleteProject(ctx context.Context, req *resourcemanagerpb.DeleteProjectRequest, opts ...gax.CallOption) (*DeleteProjectOperation, error) {
390 return c.internalClient.DeleteProject(ctx, req, opts...)
391 }
392
393
394
395 func (c *ProjectsClient) DeleteProjectOperation(name string) *DeleteProjectOperation {
396 return c.internalClient.DeleteProjectOperation(name)
397 }
398
399
400
401
402
403
404
405
406
407
408 func (c *ProjectsClient) UndeleteProject(ctx context.Context, req *resourcemanagerpb.UndeleteProjectRequest, opts ...gax.CallOption) (*UndeleteProjectOperation, error) {
409 return c.internalClient.UndeleteProject(ctx, req, opts...)
410 }
411
412
413
414 func (c *ProjectsClient) UndeleteProjectOperation(name string) *UndeleteProjectOperation {
415 return c.internalClient.UndeleteProjectOperation(name)
416 }
417
418
419
420
421 func (c *ProjectsClient) GetIamPolicy(ctx context.Context, req *iampb.GetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) {
422 return c.internalClient.GetIamPolicy(ctx, req, opts...)
423 }
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466 func (c *ProjectsClient) SetIamPolicy(ctx context.Context, req *iampb.SetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) {
467 return c.internalClient.SetIamPolicy(ctx, req, opts...)
468 }
469
470
471
472 func (c *ProjectsClient) TestIamPermissions(ctx context.Context, req *iampb.TestIamPermissionsRequest, opts ...gax.CallOption) (*iampb.TestIamPermissionsResponse, error) {
473 return c.internalClient.TestIamPermissions(ctx, req, opts...)
474 }
475
476
477 func (c *ProjectsClient) GetOperation(ctx context.Context, req *longrunningpb.GetOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) {
478 return c.internalClient.GetOperation(ctx, req, opts...)
479 }
480
481
482
483
484 type projectsGRPCClient struct {
485
486 connPool gtransport.ConnPool
487
488
489 CallOptions **ProjectsCallOptions
490
491
492 projectsClient resourcemanagerpb.ProjectsClient
493
494
495
496
497 LROClient **lroauto.OperationsClient
498
499 operationsClient longrunningpb.OperationsClient
500
501
502 xGoogHeaders []string
503 }
504
505
506
507
508
509 func NewProjectsClient(ctx context.Context, opts ...option.ClientOption) (*ProjectsClient, error) {
510 clientOpts := defaultProjectsGRPCClientOptions()
511 if newProjectsClientHook != nil {
512 hookOpts, err := newProjectsClientHook(ctx, clientHookParams{})
513 if err != nil {
514 return nil, err
515 }
516 clientOpts = append(clientOpts, hookOpts...)
517 }
518
519 connPool, err := gtransport.DialPool(ctx, append(clientOpts, opts...)...)
520 if err != nil {
521 return nil, err
522 }
523 client := ProjectsClient{CallOptions: defaultProjectsCallOptions()}
524
525 c := &projectsGRPCClient{
526 connPool: connPool,
527 projectsClient: resourcemanagerpb.NewProjectsClient(connPool),
528 CallOptions: &client.CallOptions,
529 operationsClient: longrunningpb.NewOperationsClient(connPool),
530 }
531 c.setGoogleClientInfo()
532
533 client.internalClient = c
534
535 client.LROClient, err = lroauto.NewOperationsClient(ctx, gtransport.WithConnPool(connPool))
536 if err != nil {
537
538
539
540
541
542
543 return nil, err
544 }
545 c.LROClient = &client.LROClient
546 return &client, nil
547 }
548
549
550
551
552
553 func (c *projectsGRPCClient) Connection() *grpc.ClientConn {
554 return c.connPool.Conn()
555 }
556
557
558
559
560 func (c *projectsGRPCClient) setGoogleClientInfo(keyval ...string) {
561 kv := append([]string{"gl-go", gax.GoVersion}, keyval...)
562 kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "grpc", grpc.Version)
563 c.xGoogHeaders = []string{"x-goog-api-client", gax.XGoogHeader(kv...)}
564 }
565
566
567
568 func (c *projectsGRPCClient) Close() error {
569 return c.connPool.Close()
570 }
571
572
573 type projectsRESTClient struct {
574
575 endpoint string
576
577
578 httpClient *http.Client
579
580
581
582
583 LROClient **lroauto.OperationsClient
584
585
586 xGoogHeaders []string
587
588
589 CallOptions **ProjectsCallOptions
590 }
591
592
593
594
595 func NewProjectsRESTClient(ctx context.Context, opts ...option.ClientOption) (*ProjectsClient, error) {
596 clientOpts := append(defaultProjectsRESTClientOptions(), opts...)
597 httpClient, endpoint, err := httptransport.NewClient(ctx, clientOpts...)
598 if err != nil {
599 return nil, err
600 }
601
602 callOpts := defaultProjectsRESTCallOptions()
603 c := &projectsRESTClient{
604 endpoint: endpoint,
605 httpClient: httpClient,
606 CallOptions: &callOpts,
607 }
608 c.setGoogleClientInfo()
609
610 lroOpts := []option.ClientOption{
611 option.WithHTTPClient(httpClient),
612 option.WithEndpoint(endpoint),
613 }
614 opClient, err := lroauto.NewOperationsRESTClient(ctx, lroOpts...)
615 if err != nil {
616 return nil, err
617 }
618 c.LROClient = &opClient
619
620 return &ProjectsClient{internalClient: c, CallOptions: callOpts}, nil
621 }
622
623 func defaultProjectsRESTClientOptions() []option.ClientOption {
624 return []option.ClientOption{
625 internaloption.WithDefaultEndpoint("https://cloudresourcemanager.googleapis.com"),
626 internaloption.WithDefaultEndpointTemplate("https://cloudresourcemanager.UNIVERSE_DOMAIN"),
627 internaloption.WithDefaultMTLSEndpoint("https://cloudresourcemanager.mtls.googleapis.com"),
628 internaloption.WithDefaultUniverseDomain("googleapis.com"),
629 internaloption.WithDefaultAudience("https://cloudresourcemanager.googleapis.com/"),
630 internaloption.WithDefaultScopes(DefaultAuthScopes()...),
631 }
632 }
633
634
635
636
637 func (c *projectsRESTClient) setGoogleClientInfo(keyval ...string) {
638 kv := append([]string{"gl-go", gax.GoVersion}, keyval...)
639 kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "rest", "UNKNOWN")
640 c.xGoogHeaders = []string{"x-goog-api-client", gax.XGoogHeader(kv...)}
641 }
642
643
644
645 func (c *projectsRESTClient) Close() error {
646
647 c.httpClient = nil
648 return nil
649 }
650
651
652
653
654 func (c *projectsRESTClient) Connection() *grpc.ClientConn {
655 return nil
656 }
657 func (c *projectsGRPCClient) GetProject(ctx context.Context, req *resourcemanagerpb.GetProjectRequest, opts ...gax.CallOption) (*resourcemanagerpb.Project, error) {
658 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
659
660 hds = append(c.xGoogHeaders, hds...)
661 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
662 opts = append((*c.CallOptions).GetProject[0:len((*c.CallOptions).GetProject):len((*c.CallOptions).GetProject)], opts...)
663 var resp *resourcemanagerpb.Project
664 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
665 var err error
666 resp, err = c.projectsClient.GetProject(ctx, req, settings.GRPC...)
667 return err
668 }, opts...)
669 if err != nil {
670 return nil, err
671 }
672 return resp, nil
673 }
674
675 func (c *projectsGRPCClient) ListProjects(ctx context.Context, req *resourcemanagerpb.ListProjectsRequest, opts ...gax.CallOption) *ProjectIterator {
676 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, c.xGoogHeaders...)
677 opts = append((*c.CallOptions).ListProjects[0:len((*c.CallOptions).ListProjects):len((*c.CallOptions).ListProjects)], opts...)
678 it := &ProjectIterator{}
679 req = proto.Clone(req).(*resourcemanagerpb.ListProjectsRequest)
680 it.InternalFetch = func(pageSize int, pageToken string) ([]*resourcemanagerpb.Project, string, error) {
681 resp := &resourcemanagerpb.ListProjectsResponse{}
682 if pageToken != "" {
683 req.PageToken = pageToken
684 }
685 if pageSize > math.MaxInt32 {
686 req.PageSize = math.MaxInt32
687 } else if pageSize != 0 {
688 req.PageSize = int32(pageSize)
689 }
690 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
691 var err error
692 resp, err = c.projectsClient.ListProjects(ctx, req, settings.GRPC...)
693 return err
694 }, opts...)
695 if err != nil {
696 return nil, "", err
697 }
698
699 it.Response = resp
700 return resp.GetProjects(), resp.GetNextPageToken(), nil
701 }
702 fetch := func(pageSize int, pageToken string) (string, error) {
703 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
704 if err != nil {
705 return "", err
706 }
707 it.items = append(it.items, items...)
708 return nextPageToken, nil
709 }
710
711 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
712 it.pageInfo.MaxSize = int(req.GetPageSize())
713 it.pageInfo.Token = req.GetPageToken()
714
715 return it
716 }
717
718 func (c *projectsGRPCClient) SearchProjects(ctx context.Context, req *resourcemanagerpb.SearchProjectsRequest, opts ...gax.CallOption) *ProjectIterator {
719 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, c.xGoogHeaders...)
720 opts = append((*c.CallOptions).SearchProjects[0:len((*c.CallOptions).SearchProjects):len((*c.CallOptions).SearchProjects)], opts...)
721 it := &ProjectIterator{}
722 req = proto.Clone(req).(*resourcemanagerpb.SearchProjectsRequest)
723 it.InternalFetch = func(pageSize int, pageToken string) ([]*resourcemanagerpb.Project, string, error) {
724 resp := &resourcemanagerpb.SearchProjectsResponse{}
725 if pageToken != "" {
726 req.PageToken = pageToken
727 }
728 if pageSize > math.MaxInt32 {
729 req.PageSize = math.MaxInt32
730 } else if pageSize != 0 {
731 req.PageSize = int32(pageSize)
732 }
733 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
734 var err error
735 resp, err = c.projectsClient.SearchProjects(ctx, req, settings.GRPC...)
736 return err
737 }, opts...)
738 if err != nil {
739 return nil, "", err
740 }
741
742 it.Response = resp
743 return resp.GetProjects(), resp.GetNextPageToken(), nil
744 }
745 fetch := func(pageSize int, pageToken string) (string, error) {
746 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
747 if err != nil {
748 return "", err
749 }
750 it.items = append(it.items, items...)
751 return nextPageToken, nil
752 }
753
754 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
755 it.pageInfo.MaxSize = int(req.GetPageSize())
756 it.pageInfo.Token = req.GetPageToken()
757
758 return it
759 }
760
761 func (c *projectsGRPCClient) CreateProject(ctx context.Context, req *resourcemanagerpb.CreateProjectRequest, opts ...gax.CallOption) (*CreateProjectOperation, error) {
762 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, c.xGoogHeaders...)
763 opts = append((*c.CallOptions).CreateProject[0:len((*c.CallOptions).CreateProject):len((*c.CallOptions).CreateProject)], opts...)
764 var resp *longrunningpb.Operation
765 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
766 var err error
767 resp, err = c.projectsClient.CreateProject(ctx, req, settings.GRPC...)
768 return err
769 }, opts...)
770 if err != nil {
771 return nil, err
772 }
773 return &CreateProjectOperation{
774 lro: longrunning.InternalNewOperation(*c.LROClient, resp),
775 }, nil
776 }
777
778 func (c *projectsGRPCClient) UpdateProject(ctx context.Context, req *resourcemanagerpb.UpdateProjectRequest, opts ...gax.CallOption) (*UpdateProjectOperation, error) {
779 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "project.name", url.QueryEscape(req.GetProject().GetName()))}
780
781 hds = append(c.xGoogHeaders, hds...)
782 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
783 opts = append((*c.CallOptions).UpdateProject[0:len((*c.CallOptions).UpdateProject):len((*c.CallOptions).UpdateProject)], opts...)
784 var resp *longrunningpb.Operation
785 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
786 var err error
787 resp, err = c.projectsClient.UpdateProject(ctx, req, settings.GRPC...)
788 return err
789 }, opts...)
790 if err != nil {
791 return nil, err
792 }
793 return &UpdateProjectOperation{
794 lro: longrunning.InternalNewOperation(*c.LROClient, resp),
795 }, nil
796 }
797
798 func (c *projectsGRPCClient) MoveProject(ctx context.Context, req *resourcemanagerpb.MoveProjectRequest, opts ...gax.CallOption) (*MoveProjectOperation, error) {
799 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
800
801 hds = append(c.xGoogHeaders, hds...)
802 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
803 opts = append((*c.CallOptions).MoveProject[0:len((*c.CallOptions).MoveProject):len((*c.CallOptions).MoveProject)], opts...)
804 var resp *longrunningpb.Operation
805 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
806 var err error
807 resp, err = c.projectsClient.MoveProject(ctx, req, settings.GRPC...)
808 return err
809 }, opts...)
810 if err != nil {
811 return nil, err
812 }
813 return &MoveProjectOperation{
814 lro: longrunning.InternalNewOperation(*c.LROClient, resp),
815 }, nil
816 }
817
818 func (c *projectsGRPCClient) DeleteProject(ctx context.Context, req *resourcemanagerpb.DeleteProjectRequest, opts ...gax.CallOption) (*DeleteProjectOperation, error) {
819 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
820
821 hds = append(c.xGoogHeaders, hds...)
822 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
823 opts = append((*c.CallOptions).DeleteProject[0:len((*c.CallOptions).DeleteProject):len((*c.CallOptions).DeleteProject)], opts...)
824 var resp *longrunningpb.Operation
825 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
826 var err error
827 resp, err = c.projectsClient.DeleteProject(ctx, req, settings.GRPC...)
828 return err
829 }, opts...)
830 if err != nil {
831 return nil, err
832 }
833 return &DeleteProjectOperation{
834 lro: longrunning.InternalNewOperation(*c.LROClient, resp),
835 }, nil
836 }
837
838 func (c *projectsGRPCClient) UndeleteProject(ctx context.Context, req *resourcemanagerpb.UndeleteProjectRequest, opts ...gax.CallOption) (*UndeleteProjectOperation, error) {
839 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
840
841 hds = append(c.xGoogHeaders, hds...)
842 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
843 opts = append((*c.CallOptions).UndeleteProject[0:len((*c.CallOptions).UndeleteProject):len((*c.CallOptions).UndeleteProject)], opts...)
844 var resp *longrunningpb.Operation
845 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
846 var err error
847 resp, err = c.projectsClient.UndeleteProject(ctx, req, settings.GRPC...)
848 return err
849 }, opts...)
850 if err != nil {
851 return nil, err
852 }
853 return &UndeleteProjectOperation{
854 lro: longrunning.InternalNewOperation(*c.LROClient, resp),
855 }, nil
856 }
857
858 func (c *projectsGRPCClient) GetIamPolicy(ctx context.Context, req *iampb.GetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) {
859 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))}
860
861 hds = append(c.xGoogHeaders, hds...)
862 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
863 opts = append((*c.CallOptions).GetIamPolicy[0:len((*c.CallOptions).GetIamPolicy):len((*c.CallOptions).GetIamPolicy)], opts...)
864 var resp *iampb.Policy
865 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
866 var err error
867 resp, err = c.projectsClient.GetIamPolicy(ctx, req, settings.GRPC...)
868 return err
869 }, opts...)
870 if err != nil {
871 return nil, err
872 }
873 return resp, nil
874 }
875
876 func (c *projectsGRPCClient) SetIamPolicy(ctx context.Context, req *iampb.SetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) {
877 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))}
878
879 hds = append(c.xGoogHeaders, hds...)
880 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
881 opts = append((*c.CallOptions).SetIamPolicy[0:len((*c.CallOptions).SetIamPolicy):len((*c.CallOptions).SetIamPolicy)], opts...)
882 var resp *iampb.Policy
883 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
884 var err error
885 resp, err = c.projectsClient.SetIamPolicy(ctx, req, settings.GRPC...)
886 return err
887 }, opts...)
888 if err != nil {
889 return nil, err
890 }
891 return resp, nil
892 }
893
894 func (c *projectsGRPCClient) TestIamPermissions(ctx context.Context, req *iampb.TestIamPermissionsRequest, opts ...gax.CallOption) (*iampb.TestIamPermissionsResponse, error) {
895 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))}
896
897 hds = append(c.xGoogHeaders, hds...)
898 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
899 opts = append((*c.CallOptions).TestIamPermissions[0:len((*c.CallOptions).TestIamPermissions):len((*c.CallOptions).TestIamPermissions)], opts...)
900 var resp *iampb.TestIamPermissionsResponse
901 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
902 var err error
903 resp, err = c.projectsClient.TestIamPermissions(ctx, req, settings.GRPC...)
904 return err
905 }, opts...)
906 if err != nil {
907 return nil, err
908 }
909 return resp, nil
910 }
911
912 func (c *projectsGRPCClient) GetOperation(ctx context.Context, req *longrunningpb.GetOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) {
913 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
914
915 hds = append(c.xGoogHeaders, hds...)
916 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
917 opts = append((*c.CallOptions).GetOperation[0:len((*c.CallOptions).GetOperation):len((*c.CallOptions).GetOperation)], opts...)
918 var resp *longrunningpb.Operation
919 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
920 var err error
921 resp, err = c.operationsClient.GetOperation(ctx, req, settings.GRPC...)
922 return err
923 }, opts...)
924 if err != nil {
925 return nil, err
926 }
927 return resp, nil
928 }
929
930
931
932
933
934
935 func (c *projectsRESTClient) GetProject(ctx context.Context, req *resourcemanagerpb.GetProjectRequest, opts ...gax.CallOption) (*resourcemanagerpb.Project, error) {
936 baseUrl, err := url.Parse(c.endpoint)
937 if err != nil {
938 return nil, err
939 }
940 baseUrl.Path += fmt.Sprintf("/v3/%v", req.GetName())
941
942 params := url.Values{}
943 params.Add("$alt", "json;enum-encoding=int")
944
945 baseUrl.RawQuery = params.Encode()
946
947
948 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
949
950 hds = append(c.xGoogHeaders, hds...)
951 hds = append(hds, "Content-Type", "application/json")
952 headers := gax.BuildHeaders(ctx, hds...)
953 opts = append((*c.CallOptions).GetProject[0:len((*c.CallOptions).GetProject):len((*c.CallOptions).GetProject)], opts...)
954 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
955 resp := &resourcemanagerpb.Project{}
956 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
957 if settings.Path != "" {
958 baseUrl.Path = settings.Path
959 }
960 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
961 if err != nil {
962 return err
963 }
964 httpReq = httpReq.WithContext(ctx)
965 httpReq.Header = headers
966
967 httpRsp, err := c.httpClient.Do(httpReq)
968 if err != nil {
969 return err
970 }
971 defer httpRsp.Body.Close()
972
973 if err = googleapi.CheckResponse(httpRsp); err != nil {
974 return err
975 }
976
977 buf, err := io.ReadAll(httpRsp.Body)
978 if err != nil {
979 return err
980 }
981
982 if err := unm.Unmarshal(buf, resp); err != nil {
983 return err
984 }
985
986 return nil
987 }, opts...)
988 if e != nil {
989 return nil, e
990 }
991 return resp, nil
992 }
993
994
995
996
997
998
999
1000 func (c *projectsRESTClient) ListProjects(ctx context.Context, req *resourcemanagerpb.ListProjectsRequest, opts ...gax.CallOption) *ProjectIterator {
1001 it := &ProjectIterator{}
1002 req = proto.Clone(req).(*resourcemanagerpb.ListProjectsRequest)
1003 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
1004 it.InternalFetch = func(pageSize int, pageToken string) ([]*resourcemanagerpb.Project, string, error) {
1005 resp := &resourcemanagerpb.ListProjectsResponse{}
1006 if pageToken != "" {
1007 req.PageToken = pageToken
1008 }
1009 if pageSize > math.MaxInt32 {
1010 req.PageSize = math.MaxInt32
1011 } else if pageSize != 0 {
1012 req.PageSize = int32(pageSize)
1013 }
1014 baseUrl, err := url.Parse(c.endpoint)
1015 if err != nil {
1016 return nil, "", err
1017 }
1018 baseUrl.Path += fmt.Sprintf("/v3/projects")
1019
1020 params := url.Values{}
1021 params.Add("$alt", "json;enum-encoding=int")
1022 if req.GetPageSize() != 0 {
1023 params.Add("pageSize", fmt.Sprintf("%v", req.GetPageSize()))
1024 }
1025 if req.GetPageToken() != "" {
1026 params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken()))
1027 }
1028 params.Add("parent", fmt.Sprintf("%v", req.GetParent()))
1029 if req.GetShowDeleted() {
1030 params.Add("showDeleted", fmt.Sprintf("%v", req.GetShowDeleted()))
1031 }
1032
1033 baseUrl.RawQuery = params.Encode()
1034
1035
1036 hds := append(c.xGoogHeaders, "Content-Type", "application/json")
1037 headers := gax.BuildHeaders(ctx, hds...)
1038 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1039 if settings.Path != "" {
1040 baseUrl.Path = settings.Path
1041 }
1042 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
1043 if err != nil {
1044 return err
1045 }
1046 httpReq.Header = headers
1047
1048 httpRsp, err := c.httpClient.Do(httpReq)
1049 if err != nil {
1050 return err
1051 }
1052 defer httpRsp.Body.Close()
1053
1054 if err = googleapi.CheckResponse(httpRsp); err != nil {
1055 return err
1056 }
1057
1058 buf, err := io.ReadAll(httpRsp.Body)
1059 if err != nil {
1060 return err
1061 }
1062
1063 if err := unm.Unmarshal(buf, resp); err != nil {
1064 return err
1065 }
1066
1067 return nil
1068 }, opts...)
1069 if e != nil {
1070 return nil, "", e
1071 }
1072 it.Response = resp
1073 return resp.GetProjects(), resp.GetNextPageToken(), nil
1074 }
1075
1076 fetch := func(pageSize int, pageToken string) (string, error) {
1077 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
1078 if err != nil {
1079 return "", err
1080 }
1081 it.items = append(it.items, items...)
1082 return nextPageToken, nil
1083 }
1084
1085 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
1086 it.pageInfo.MaxSize = int(req.GetPageSize())
1087 it.pageInfo.Token = req.GetPageToken()
1088
1089 return it
1090 }
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102 func (c *projectsRESTClient) SearchProjects(ctx context.Context, req *resourcemanagerpb.SearchProjectsRequest, opts ...gax.CallOption) *ProjectIterator {
1103 it := &ProjectIterator{}
1104 req = proto.Clone(req).(*resourcemanagerpb.SearchProjectsRequest)
1105 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
1106 it.InternalFetch = func(pageSize int, pageToken string) ([]*resourcemanagerpb.Project, string, error) {
1107 resp := &resourcemanagerpb.SearchProjectsResponse{}
1108 if pageToken != "" {
1109 req.PageToken = pageToken
1110 }
1111 if pageSize > math.MaxInt32 {
1112 req.PageSize = math.MaxInt32
1113 } else if pageSize != 0 {
1114 req.PageSize = int32(pageSize)
1115 }
1116 baseUrl, err := url.Parse(c.endpoint)
1117 if err != nil {
1118 return nil, "", err
1119 }
1120 baseUrl.Path += fmt.Sprintf("/v3/projects:search")
1121
1122 params := url.Values{}
1123 params.Add("$alt", "json;enum-encoding=int")
1124 if req.GetPageSize() != 0 {
1125 params.Add("pageSize", fmt.Sprintf("%v", req.GetPageSize()))
1126 }
1127 if req.GetPageToken() != "" {
1128 params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken()))
1129 }
1130 if req.GetQuery() != "" {
1131 params.Add("query", fmt.Sprintf("%v", req.GetQuery()))
1132 }
1133
1134 baseUrl.RawQuery = params.Encode()
1135
1136
1137 hds := append(c.xGoogHeaders, "Content-Type", "application/json")
1138 headers := gax.BuildHeaders(ctx, hds...)
1139 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1140 if settings.Path != "" {
1141 baseUrl.Path = settings.Path
1142 }
1143 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
1144 if err != nil {
1145 return err
1146 }
1147 httpReq.Header = headers
1148
1149 httpRsp, err := c.httpClient.Do(httpReq)
1150 if err != nil {
1151 return err
1152 }
1153 defer httpRsp.Body.Close()
1154
1155 if err = googleapi.CheckResponse(httpRsp); err != nil {
1156 return err
1157 }
1158
1159 buf, err := io.ReadAll(httpRsp.Body)
1160 if err != nil {
1161 return err
1162 }
1163
1164 if err := unm.Unmarshal(buf, resp); err != nil {
1165 return err
1166 }
1167
1168 return nil
1169 }, opts...)
1170 if e != nil {
1171 return nil, "", e
1172 }
1173 it.Response = resp
1174 return resp.GetProjects(), resp.GetNextPageToken(), nil
1175 }
1176
1177 fetch := func(pageSize int, pageToken string) (string, error) {
1178 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
1179 if err != nil {
1180 return "", err
1181 }
1182 it.items = append(it.items, items...)
1183 return nextPageToken, nil
1184 }
1185
1186 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
1187 it.pageInfo.MaxSize = int(req.GetPageSize())
1188 it.pageInfo.Token = req.GetPageToken()
1189
1190 return it
1191 }
1192
1193
1194
1195
1196
1197
1198 func (c *projectsRESTClient) CreateProject(ctx context.Context, req *resourcemanagerpb.CreateProjectRequest, opts ...gax.CallOption) (*CreateProjectOperation, error) {
1199 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
1200 body := req.GetProject()
1201 jsonReq, err := m.Marshal(body)
1202 if err != nil {
1203 return nil, err
1204 }
1205
1206 baseUrl, err := url.Parse(c.endpoint)
1207 if err != nil {
1208 return nil, err
1209 }
1210 baseUrl.Path += fmt.Sprintf("/v3/projects")
1211
1212 params := url.Values{}
1213 params.Add("$alt", "json;enum-encoding=int")
1214
1215 baseUrl.RawQuery = params.Encode()
1216
1217
1218 hds := append(c.xGoogHeaders, "Content-Type", "application/json")
1219 headers := gax.BuildHeaders(ctx, hds...)
1220 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
1221 resp := &longrunningpb.Operation{}
1222 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1223 if settings.Path != "" {
1224 baseUrl.Path = settings.Path
1225 }
1226 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
1227 if err != nil {
1228 return err
1229 }
1230 httpReq = httpReq.WithContext(ctx)
1231 httpReq.Header = headers
1232
1233 httpRsp, err := c.httpClient.Do(httpReq)
1234 if err != nil {
1235 return err
1236 }
1237 defer httpRsp.Body.Close()
1238
1239 if err = googleapi.CheckResponse(httpRsp); err != nil {
1240 return err
1241 }
1242
1243 buf, err := io.ReadAll(httpRsp.Body)
1244 if err != nil {
1245 return err
1246 }
1247
1248 if err := unm.Unmarshal(buf, resp); err != nil {
1249 return err
1250 }
1251
1252 return nil
1253 }, opts...)
1254 if e != nil {
1255 return nil, e
1256 }
1257
1258 override := fmt.Sprintf("/v3/%s", resp.GetName())
1259 return &CreateProjectOperation{
1260 lro: longrunning.InternalNewOperation(*c.LROClient, resp),
1261 pollPath: override,
1262 }, nil
1263 }
1264
1265
1266
1267
1268
1269
1270
1271 func (c *projectsRESTClient) UpdateProject(ctx context.Context, req *resourcemanagerpb.UpdateProjectRequest, opts ...gax.CallOption) (*UpdateProjectOperation, error) {
1272 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
1273 body := req.GetProject()
1274 jsonReq, err := m.Marshal(body)
1275 if err != nil {
1276 return nil, err
1277 }
1278
1279 baseUrl, err := url.Parse(c.endpoint)
1280 if err != nil {
1281 return nil, err
1282 }
1283 baseUrl.Path += fmt.Sprintf("/v3/%v", req.GetProject().GetName())
1284
1285 params := url.Values{}
1286 params.Add("$alt", "json;enum-encoding=int")
1287 if req.GetUpdateMask() != nil {
1288 updateMask, err := protojson.Marshal(req.GetUpdateMask())
1289 if err != nil {
1290 return nil, err
1291 }
1292 params.Add("updateMask", string(updateMask[1:len(updateMask)-1]))
1293 }
1294
1295 baseUrl.RawQuery = params.Encode()
1296
1297
1298 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "project.name", url.QueryEscape(req.GetProject().GetName()))}
1299
1300 hds = append(c.xGoogHeaders, hds...)
1301 hds = append(hds, "Content-Type", "application/json")
1302 headers := gax.BuildHeaders(ctx, hds...)
1303 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
1304 resp := &longrunningpb.Operation{}
1305 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1306 if settings.Path != "" {
1307 baseUrl.Path = settings.Path
1308 }
1309 httpReq, err := http.NewRequest("PATCH", baseUrl.String(), bytes.NewReader(jsonReq))
1310 if err != nil {
1311 return err
1312 }
1313 httpReq = httpReq.WithContext(ctx)
1314 httpReq.Header = headers
1315
1316 httpRsp, err := c.httpClient.Do(httpReq)
1317 if err != nil {
1318 return err
1319 }
1320 defer httpRsp.Body.Close()
1321
1322 if err = googleapi.CheckResponse(httpRsp); err != nil {
1323 return err
1324 }
1325
1326 buf, err := io.ReadAll(httpRsp.Body)
1327 if err != nil {
1328 return err
1329 }
1330
1331 if err := unm.Unmarshal(buf, resp); err != nil {
1332 return err
1333 }
1334
1335 return nil
1336 }, opts...)
1337 if e != nil {
1338 return nil, e
1339 }
1340
1341 override := fmt.Sprintf("/v3/%s", resp.GetName())
1342 return &UpdateProjectOperation{
1343 lro: longrunning.InternalNewOperation(*c.LROClient, resp),
1344 pollPath: override,
1345 }, nil
1346 }
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362 func (c *projectsRESTClient) MoveProject(ctx context.Context, req *resourcemanagerpb.MoveProjectRequest, opts ...gax.CallOption) (*MoveProjectOperation, error) {
1363 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
1364 jsonReq, err := m.Marshal(req)
1365 if err != nil {
1366 return nil, err
1367 }
1368
1369 baseUrl, err := url.Parse(c.endpoint)
1370 if err != nil {
1371 return nil, err
1372 }
1373 baseUrl.Path += fmt.Sprintf("/v3/%v:move", req.GetName())
1374
1375 params := url.Values{}
1376 params.Add("$alt", "json;enum-encoding=int")
1377
1378 baseUrl.RawQuery = params.Encode()
1379
1380
1381 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
1382
1383 hds = append(c.xGoogHeaders, hds...)
1384 hds = append(hds, "Content-Type", "application/json")
1385 headers := gax.BuildHeaders(ctx, hds...)
1386 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
1387 resp := &longrunningpb.Operation{}
1388 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1389 if settings.Path != "" {
1390 baseUrl.Path = settings.Path
1391 }
1392 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
1393 if err != nil {
1394 return err
1395 }
1396 httpReq = httpReq.WithContext(ctx)
1397 httpReq.Header = headers
1398
1399 httpRsp, err := c.httpClient.Do(httpReq)
1400 if err != nil {
1401 return err
1402 }
1403 defer httpRsp.Body.Close()
1404
1405 if err = googleapi.CheckResponse(httpRsp); err != nil {
1406 return err
1407 }
1408
1409 buf, err := io.ReadAll(httpRsp.Body)
1410 if err != nil {
1411 return err
1412 }
1413
1414 if err := unm.Unmarshal(buf, resp); err != nil {
1415 return err
1416 }
1417
1418 return nil
1419 }, opts...)
1420 if e != nil {
1421 return nil, e
1422 }
1423
1424 override := fmt.Sprintf("/v3/%s", resp.GetName())
1425 return &MoveProjectOperation{
1426 lro: longrunning.InternalNewOperation(*c.LROClient, resp),
1427 pollPath: override,
1428 }, nil
1429 }
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464 func (c *projectsRESTClient) DeleteProject(ctx context.Context, req *resourcemanagerpb.DeleteProjectRequest, opts ...gax.CallOption) (*DeleteProjectOperation, error) {
1465 baseUrl, err := url.Parse(c.endpoint)
1466 if err != nil {
1467 return nil, err
1468 }
1469 baseUrl.Path += fmt.Sprintf("/v3/%v", req.GetName())
1470
1471 params := url.Values{}
1472 params.Add("$alt", "json;enum-encoding=int")
1473
1474 baseUrl.RawQuery = params.Encode()
1475
1476
1477 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
1478
1479 hds = append(c.xGoogHeaders, hds...)
1480 hds = append(hds, "Content-Type", "application/json")
1481 headers := gax.BuildHeaders(ctx, hds...)
1482 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
1483 resp := &longrunningpb.Operation{}
1484 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1485 if settings.Path != "" {
1486 baseUrl.Path = settings.Path
1487 }
1488 httpReq, err := http.NewRequest("DELETE", baseUrl.String(), nil)
1489 if err != nil {
1490 return err
1491 }
1492 httpReq = httpReq.WithContext(ctx)
1493 httpReq.Header = headers
1494
1495 httpRsp, err := c.httpClient.Do(httpReq)
1496 if err != nil {
1497 return err
1498 }
1499 defer httpRsp.Body.Close()
1500
1501 if err = googleapi.CheckResponse(httpRsp); err != nil {
1502 return err
1503 }
1504
1505 buf, err := io.ReadAll(httpRsp.Body)
1506 if err != nil {
1507 return err
1508 }
1509
1510 if err := unm.Unmarshal(buf, resp); err != nil {
1511 return err
1512 }
1513
1514 return nil
1515 }, opts...)
1516 if e != nil {
1517 return nil, e
1518 }
1519
1520 override := fmt.Sprintf("/v3/%s", resp.GetName())
1521 return &DeleteProjectOperation{
1522 lro: longrunning.InternalNewOperation(*c.LROClient, resp),
1523 pollPath: override,
1524 }, nil
1525 }
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536 func (c *projectsRESTClient) UndeleteProject(ctx context.Context, req *resourcemanagerpb.UndeleteProjectRequest, opts ...gax.CallOption) (*UndeleteProjectOperation, error) {
1537 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
1538 jsonReq, err := m.Marshal(req)
1539 if err != nil {
1540 return nil, err
1541 }
1542
1543 baseUrl, err := url.Parse(c.endpoint)
1544 if err != nil {
1545 return nil, err
1546 }
1547 baseUrl.Path += fmt.Sprintf("/v3/%v:undelete", req.GetName())
1548
1549 params := url.Values{}
1550 params.Add("$alt", "json;enum-encoding=int")
1551
1552 baseUrl.RawQuery = params.Encode()
1553
1554
1555 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
1556
1557 hds = append(c.xGoogHeaders, hds...)
1558 hds = append(hds, "Content-Type", "application/json")
1559 headers := gax.BuildHeaders(ctx, hds...)
1560 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
1561 resp := &longrunningpb.Operation{}
1562 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1563 if settings.Path != "" {
1564 baseUrl.Path = settings.Path
1565 }
1566 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
1567 if err != nil {
1568 return err
1569 }
1570 httpReq = httpReq.WithContext(ctx)
1571 httpReq.Header = headers
1572
1573 httpRsp, err := c.httpClient.Do(httpReq)
1574 if err != nil {
1575 return err
1576 }
1577 defer httpRsp.Body.Close()
1578
1579 if err = googleapi.CheckResponse(httpRsp); err != nil {
1580 return err
1581 }
1582
1583 buf, err := io.ReadAll(httpRsp.Body)
1584 if err != nil {
1585 return err
1586 }
1587
1588 if err := unm.Unmarshal(buf, resp); err != nil {
1589 return err
1590 }
1591
1592 return nil
1593 }, opts...)
1594 if e != nil {
1595 return nil, e
1596 }
1597
1598 override := fmt.Sprintf("/v3/%s", resp.GetName())
1599 return &UndeleteProjectOperation{
1600 lro: longrunning.InternalNewOperation(*c.LROClient, resp),
1601 pollPath: override,
1602 }, nil
1603 }
1604
1605
1606
1607
1608 func (c *projectsRESTClient) GetIamPolicy(ctx context.Context, req *iampb.GetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) {
1609 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
1610 jsonReq, err := m.Marshal(req)
1611 if err != nil {
1612 return nil, err
1613 }
1614
1615 baseUrl, err := url.Parse(c.endpoint)
1616 if err != nil {
1617 return nil, err
1618 }
1619 baseUrl.Path += fmt.Sprintf("/v3/%v:getIamPolicy", req.GetResource())
1620
1621 params := url.Values{}
1622 params.Add("$alt", "json;enum-encoding=int")
1623
1624 baseUrl.RawQuery = params.Encode()
1625
1626
1627 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))}
1628
1629 hds = append(c.xGoogHeaders, hds...)
1630 hds = append(hds, "Content-Type", "application/json")
1631 headers := gax.BuildHeaders(ctx, hds...)
1632 opts = append((*c.CallOptions).GetIamPolicy[0:len((*c.CallOptions).GetIamPolicy):len((*c.CallOptions).GetIamPolicy)], opts...)
1633 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
1634 resp := &iampb.Policy{}
1635 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1636 if settings.Path != "" {
1637 baseUrl.Path = settings.Path
1638 }
1639 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
1640 if err != nil {
1641 return err
1642 }
1643 httpReq = httpReq.WithContext(ctx)
1644 httpReq.Header = headers
1645
1646 httpRsp, err := c.httpClient.Do(httpReq)
1647 if err != nil {
1648 return err
1649 }
1650 defer httpRsp.Body.Close()
1651
1652 if err = googleapi.CheckResponse(httpRsp); err != nil {
1653 return err
1654 }
1655
1656 buf, err := io.ReadAll(httpRsp.Body)
1657 if err != nil {
1658 return err
1659 }
1660
1661 if err := unm.Unmarshal(buf, resp); err != nil {
1662 return err
1663 }
1664
1665 return nil
1666 }, opts...)
1667 if e != nil {
1668 return nil, e
1669 }
1670 return resp, nil
1671 }
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714 func (c *projectsRESTClient) SetIamPolicy(ctx context.Context, req *iampb.SetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) {
1715 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
1716 jsonReq, err := m.Marshal(req)
1717 if err != nil {
1718 return nil, err
1719 }
1720
1721 baseUrl, err := url.Parse(c.endpoint)
1722 if err != nil {
1723 return nil, err
1724 }
1725 baseUrl.Path += fmt.Sprintf("/v3/%v:setIamPolicy", req.GetResource())
1726
1727 params := url.Values{}
1728 params.Add("$alt", "json;enum-encoding=int")
1729
1730 baseUrl.RawQuery = params.Encode()
1731
1732
1733 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))}
1734
1735 hds = append(c.xGoogHeaders, hds...)
1736 hds = append(hds, "Content-Type", "application/json")
1737 headers := gax.BuildHeaders(ctx, hds...)
1738 opts = append((*c.CallOptions).SetIamPolicy[0:len((*c.CallOptions).SetIamPolicy):len((*c.CallOptions).SetIamPolicy)], opts...)
1739 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
1740 resp := &iampb.Policy{}
1741 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1742 if settings.Path != "" {
1743 baseUrl.Path = settings.Path
1744 }
1745 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
1746 if err != nil {
1747 return err
1748 }
1749 httpReq = httpReq.WithContext(ctx)
1750 httpReq.Header = headers
1751
1752 httpRsp, err := c.httpClient.Do(httpReq)
1753 if err != nil {
1754 return err
1755 }
1756 defer httpRsp.Body.Close()
1757
1758 if err = googleapi.CheckResponse(httpRsp); err != nil {
1759 return err
1760 }
1761
1762 buf, err := io.ReadAll(httpRsp.Body)
1763 if err != nil {
1764 return err
1765 }
1766
1767 if err := unm.Unmarshal(buf, resp); err != nil {
1768 return err
1769 }
1770
1771 return nil
1772 }, opts...)
1773 if e != nil {
1774 return nil, e
1775 }
1776 return resp, nil
1777 }
1778
1779
1780
1781 func (c *projectsRESTClient) TestIamPermissions(ctx context.Context, req *iampb.TestIamPermissionsRequest, opts ...gax.CallOption) (*iampb.TestIamPermissionsResponse, error) {
1782 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
1783 jsonReq, err := m.Marshal(req)
1784 if err != nil {
1785 return nil, err
1786 }
1787
1788 baseUrl, err := url.Parse(c.endpoint)
1789 if err != nil {
1790 return nil, err
1791 }
1792 baseUrl.Path += fmt.Sprintf("/v3/%v:testIamPermissions", req.GetResource())
1793
1794 params := url.Values{}
1795 params.Add("$alt", "json;enum-encoding=int")
1796
1797 baseUrl.RawQuery = params.Encode()
1798
1799
1800 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))}
1801
1802 hds = append(c.xGoogHeaders, hds...)
1803 hds = append(hds, "Content-Type", "application/json")
1804 headers := gax.BuildHeaders(ctx, hds...)
1805 opts = append((*c.CallOptions).TestIamPermissions[0:len((*c.CallOptions).TestIamPermissions):len((*c.CallOptions).TestIamPermissions)], opts...)
1806 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
1807 resp := &iampb.TestIamPermissionsResponse{}
1808 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1809 if settings.Path != "" {
1810 baseUrl.Path = settings.Path
1811 }
1812 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
1813 if err != nil {
1814 return err
1815 }
1816 httpReq = httpReq.WithContext(ctx)
1817 httpReq.Header = headers
1818
1819 httpRsp, err := c.httpClient.Do(httpReq)
1820 if err != nil {
1821 return err
1822 }
1823 defer httpRsp.Body.Close()
1824
1825 if err = googleapi.CheckResponse(httpRsp); err != nil {
1826 return err
1827 }
1828
1829 buf, err := io.ReadAll(httpRsp.Body)
1830 if err != nil {
1831 return err
1832 }
1833
1834 if err := unm.Unmarshal(buf, resp); err != nil {
1835 return err
1836 }
1837
1838 return nil
1839 }, opts...)
1840 if e != nil {
1841 return nil, e
1842 }
1843 return resp, nil
1844 }
1845
1846
1847 func (c *projectsRESTClient) GetOperation(ctx context.Context, req *longrunningpb.GetOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) {
1848 baseUrl, err := url.Parse(c.endpoint)
1849 if err != nil {
1850 return nil, err
1851 }
1852 baseUrl.Path += fmt.Sprintf("/v3/%v", req.GetName())
1853
1854 params := url.Values{}
1855 params.Add("$alt", "json;enum-encoding=int")
1856
1857 baseUrl.RawQuery = params.Encode()
1858
1859
1860 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
1861
1862 hds = append(c.xGoogHeaders, hds...)
1863 hds = append(hds, "Content-Type", "application/json")
1864 headers := gax.BuildHeaders(ctx, hds...)
1865 opts = append((*c.CallOptions).GetOperation[0:len((*c.CallOptions).GetOperation):len((*c.CallOptions).GetOperation)], opts...)
1866 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
1867 resp := &longrunningpb.Operation{}
1868 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1869 if settings.Path != "" {
1870 baseUrl.Path = settings.Path
1871 }
1872 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
1873 if err != nil {
1874 return err
1875 }
1876 httpReq = httpReq.WithContext(ctx)
1877 httpReq.Header = headers
1878
1879 httpRsp, err := c.httpClient.Do(httpReq)
1880 if err != nil {
1881 return err
1882 }
1883 defer httpRsp.Body.Close()
1884
1885 if err = googleapi.CheckResponse(httpRsp); err != nil {
1886 return err
1887 }
1888
1889 buf, err := io.ReadAll(httpRsp.Body)
1890 if err != nil {
1891 return err
1892 }
1893
1894 if err := unm.Unmarshal(buf, resp); err != nil {
1895 return err
1896 }
1897
1898 return nil
1899 }, opts...)
1900 if e != nil {
1901 return nil, e
1902 }
1903 return resp, nil
1904 }
1905
1906
1907
1908 func (c *projectsGRPCClient) CreateProjectOperation(name string) *CreateProjectOperation {
1909 return &CreateProjectOperation{
1910 lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}),
1911 }
1912 }
1913
1914
1915
1916 func (c *projectsRESTClient) CreateProjectOperation(name string) *CreateProjectOperation {
1917 override := fmt.Sprintf("/v3/%s", name)
1918 return &CreateProjectOperation{
1919 lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}),
1920 pollPath: override,
1921 }
1922 }
1923
1924
1925
1926 func (c *projectsGRPCClient) DeleteProjectOperation(name string) *DeleteProjectOperation {
1927 return &DeleteProjectOperation{
1928 lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}),
1929 }
1930 }
1931
1932
1933
1934 func (c *projectsRESTClient) DeleteProjectOperation(name string) *DeleteProjectOperation {
1935 override := fmt.Sprintf("/v3/%s", name)
1936 return &DeleteProjectOperation{
1937 lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}),
1938 pollPath: override,
1939 }
1940 }
1941
1942
1943
1944 func (c *projectsGRPCClient) MoveProjectOperation(name string) *MoveProjectOperation {
1945 return &MoveProjectOperation{
1946 lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}),
1947 }
1948 }
1949
1950
1951
1952 func (c *projectsRESTClient) MoveProjectOperation(name string) *MoveProjectOperation {
1953 override := fmt.Sprintf("/v3/%s", name)
1954 return &MoveProjectOperation{
1955 lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}),
1956 pollPath: override,
1957 }
1958 }
1959
1960
1961
1962 func (c *projectsGRPCClient) UndeleteProjectOperation(name string) *UndeleteProjectOperation {
1963 return &UndeleteProjectOperation{
1964 lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}),
1965 }
1966 }
1967
1968
1969
1970 func (c *projectsRESTClient) UndeleteProjectOperation(name string) *UndeleteProjectOperation {
1971 override := fmt.Sprintf("/v3/%s", name)
1972 return &UndeleteProjectOperation{
1973 lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}),
1974 pollPath: override,
1975 }
1976 }
1977
1978
1979
1980 func (c *projectsGRPCClient) UpdateProjectOperation(name string) *UpdateProjectOperation {
1981 return &UpdateProjectOperation{
1982 lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}),
1983 }
1984 }
1985
1986
1987
1988 func (c *projectsRESTClient) UpdateProjectOperation(name string) *UpdateProjectOperation {
1989 override := fmt.Sprintf("/v3/%s", name)
1990 return &UpdateProjectOperation{
1991 lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}),
1992 pollPath: override,
1993 }
1994 }
1995
View as plain text