Debian Codegraph @

datacatalog/apiv1/iam_policy_client.go

raw
1 // Copyright 2023 Google LLC
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // https://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 // Code generated by protoc-gen-go_gapic. DO NOT EDIT.
16 //
17 // Note: Generation has ceased. New GAPIC changes may need to be manually
18 // backported.
19
20 package datacatalog
21
22 import (
23 "bytes"
24 "context"
25 "fmt"
26 "io"
27 "math"
28 "net/http"
29 "net/url"
30
31 iampb "cloud.google.com/go/iam/apiv1/iampb"
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/protobuf/encoding/protojson"
42 "google.golang.org/protobuf/proto"
43 )
44
45 var newIamPolicyClientHook clientHook
46
47 // IamPolicyCallOptions contains the retry settings for each method of IamPolicyClient.
48 type IamPolicyCallOptions struct {
49 SetIamPolicy []gax.CallOption
50 GetIamPolicy []gax.CallOption
51 TestIamPermissions []gax.CallOption
52 CancelOperation []gax.CallOption
53 DeleteOperation []gax.CallOption
54 GetOperation []gax.CallOption
55 ListOperations []gax.CallOption
56 }
57
58 func defaultIamPolicyGRPCClientOptions() []option.ClientOption {
59 return []option.ClientOption{
60 internaloption.WithDefaultEndpoint("iam-meta-api.googleapis.com:443"),
61 internaloption.WithDefaultEndpointTemplate("iam-meta-api.UNIVERSE_DOMAIN:443"),
62 internaloption.WithDefaultMTLSEndpoint("iam-meta-api.mtls.googleapis.com:443"),
63 internaloption.WithDefaultAudience("https://iam-meta-api.googleapis.com/"),
64 internaloption.WithDefaultScopes(DefaultAuthScopes()...),
65 internaloption.EnableJwtWithScope(),
66 option.WithGRPCDialOption(grpc.WithDefaultCallOptions(
67 grpc.MaxCallRecvMsgSize(math.MaxInt32))),
68 }
69 }
70
71 func defaultIamPolicyCallOptions() *IamPolicyCallOptions {
72 return &IamPolicyCallOptions{
73 SetIamPolicy: []gax.CallOption{},
74 GetIamPolicy: []gax.CallOption{},
75 TestIamPermissions: []gax.CallOption{},
76 CancelOperation: []gax.CallOption{},
77 DeleteOperation: []gax.CallOption{},
78 GetOperation: []gax.CallOption{},
79 ListOperations: []gax.CallOption{},
80 }
81 }
82
83 func defaultIamPolicyRESTCallOptions() *IamPolicyCallOptions {
84 return &IamPolicyCallOptions{
85 SetIamPolicy: []gax.CallOption{},
86 GetIamPolicy: []gax.CallOption{},
87 TestIamPermissions: []gax.CallOption{},
88 CancelOperation: []gax.CallOption{},
89 DeleteOperation: []gax.CallOption{},
90 GetOperation: []gax.CallOption{},
91 ListOperations: []gax.CallOption{},
92 }
93 }
94
95 // internalIamPolicyClient is an interface that defines the methods available from Batch API.
96 type internalIamPolicyClient interface {
97 Close() error
98 setGoogleClientInfo(...string)
99 Connection() *grpc.ClientConn
100 SetIamPolicy(context.Context, *iampb.SetIamPolicyRequest, ...gax.CallOption) (*iampb.Policy, error)
101 GetIamPolicy(context.Context, *iampb.GetIamPolicyRequest, ...gax.CallOption) (*iampb.Policy, error)
102 TestIamPermissions(context.Context, *iampb.TestIamPermissionsRequest, ...gax.CallOption) (*iampb.TestIamPermissionsResponse, error)
103 CancelOperation(context.Context, *longrunningpb.CancelOperationRequest, ...gax.CallOption) error
104 DeleteOperation(context.Context, *longrunningpb.DeleteOperationRequest, ...gax.CallOption) error
105 GetOperation(context.Context, *longrunningpb.GetOperationRequest, ...gax.CallOption) (*longrunningpb.Operation, error)
106 ListOperations(context.Context, *longrunningpb.ListOperationsRequest, ...gax.CallOption) *OperationIterator
107 }
108
109 // IamPolicyClient is a client for interacting with Batch API.
110 // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
111 //
112 // # API Overview
113 //
114 // Manages Identity and Access Management (IAM) policies.
115 //
116 // Any implementation of an API that offers access control features
117 // implements the google.iam.v1.IAMPolicy interface.
118 //
119 // Data modelAccess control is applied when a principal (user or service account), takes
120 // some action on a resource exposed by a service. Resources, identified by
121 // URI-like names, are the unit of access control specification. Service
122 // implementations can choose the granularity of access control and the
123 // supported permissions for their resources.
124 // For example one database service may allow access control to be
125 // specified only at the Table level, whereas another might allow access control
126 // to also be specified at the Column level.
127 //
128 // # Policy StructureSee google.iam.v1.Policy
129 //
130 // This is intentionally not a CRUD style API because access control policies
131 // are created and deleted implicitly with the resources to which they are
132 // attached.
133 type IamPolicyClient struct {
134 // The internal transport-dependent client.
135 internalClient internalIamPolicyClient
136
137 // The call options for this service.
138 CallOptions *IamPolicyCallOptions
139 }
140
141 // Wrapper methods routed to the internal client.
142
143 // Close closes the connection to the API service. The user should invoke this when
144 // the client is no longer required.
145 func (c *IamPolicyClient) Close() error {
146 return c.internalClient.Close()
147 }
148
149 // setGoogleClientInfo sets the name and version of the application in
150 // the `x-goog-api-client` header passed on each request. Intended for
151 // use by Google-written clients.
152 func (c *IamPolicyClient) setGoogleClientInfo(keyval ...string) {
153 c.internalClient.setGoogleClientInfo(keyval...)
154 }
155
156 // Connection returns a connection to the API service.
157 //
158 // Deprecated: Connections are now pooled so this method does not always
159 // return the same resource.
160 func (c *IamPolicyClient) Connection() *grpc.ClientConn {
161 return c.internalClient.Connection()
162 }
163
164 // SetIamPolicy sets the access control policy on the specified resource. Replaces any
165 // existing policy.
166 //
167 // Can return NOT_FOUND, INVALID_ARGUMENT, and PERMISSION_DENIED errors.
168 func (c *IamPolicyClient) SetIamPolicy(ctx context.Context, req *iampb.SetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) {
169 return c.internalClient.SetIamPolicy(ctx, req, opts...)
170 }
171
172 // GetIamPolicy gets the access control policy for a resource.
173 // Returns an empty policy if the resource exists and does not have a policy
174 // set.
175 func (c *IamPolicyClient) GetIamPolicy(ctx context.Context, req *iampb.GetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) {
176 return c.internalClient.GetIamPolicy(ctx, req, opts...)
177 }
178
179 // TestIamPermissions returns permissions that a caller has on the specified resource.
180 // If the resource does not exist, this will return an empty set of
181 // permissions, not a NOT_FOUND error.
182 //
183 // Note: This operation is designed to be used for building permission-aware
184 // UIs and command-line tools, not for authorization checking. This operation
185 // may “fail open” without warning.
186 func (c *IamPolicyClient) TestIamPermissions(ctx context.Context, req *iampb.TestIamPermissionsRequest, opts ...gax.CallOption) (*iampb.TestIamPermissionsResponse, error) {
187 return c.internalClient.TestIamPermissions(ctx, req, opts...)
188 }
189
190 // CancelOperation is a utility method from google.longrunning.Operations.
191 func (c *IamPolicyClient) CancelOperation(ctx context.Context, req *longrunningpb.CancelOperationRequest, opts ...gax.CallOption) error {
192 return c.internalClient.CancelOperation(ctx, req, opts...)
193 }
194
195 // DeleteOperation is a utility method from google.longrunning.Operations.
196 func (c *IamPolicyClient) DeleteOperation(ctx context.Context, req *longrunningpb.DeleteOperationRequest, opts ...gax.CallOption) error {
197 return c.internalClient.DeleteOperation(ctx, req, opts...)
198 }
199
200 // GetOperation is a utility method from google.longrunning.Operations.
201 func (c *IamPolicyClient) GetOperation(ctx context.Context, req *longrunningpb.GetOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) {
202 return c.internalClient.GetOperation(ctx, req, opts...)
203 }
204
205 // ListOperations is a utility method from google.longrunning.Operations.
206 func (c *IamPolicyClient) ListOperations(ctx context.Context, req *longrunningpb.ListOperationsRequest, opts ...gax.CallOption) *OperationIterator {
207 return c.internalClient.ListOperations(ctx, req, opts...)
208 }
209
210 // iamPolicyGRPCClient is a client for interacting with Batch API over gRPC transport.
211 //
212 // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
213 type iamPolicyGRPCClient struct {
214 // Connection pool of gRPC connections to the service.
215 connPool gtransport.ConnPool
216
217 // Points back to the CallOptions field of the containing IamPolicyClient
218 CallOptions **IamPolicyCallOptions
219
220 // The gRPC API client.
221 iamPolicyClient iampb.IAMPolicyClient
222
223 operationsClient longrunningpb.OperationsClient
224
225 // The x-goog-* metadata to be sent with each request.
226 xGoogHeaders []string
227 }
228
229 // NewIamPolicyClient creates a new iam policy client based on gRPC.
230 // The returned client must be Closed when it is done being used to clean up its underlying connections.
231 //
232 // # API Overview
233 //
234 // Manages Identity and Access Management (IAM) policies.
235 //
236 // Any implementation of an API that offers access control features
237 // implements the google.iam.v1.IAMPolicy interface.
238 //
239 // Data modelAccess control is applied when a principal (user or service account), takes
240 // some action on a resource exposed by a service. Resources, identified by
241 // URI-like names, are the unit of access control specification. Service
242 // implementations can choose the granularity of access control and the
243 // supported permissions for their resources.
244 // For example one database service may allow access control to be
245 // specified only at the Table level, whereas another might allow access control
246 // to also be specified at the Column level.
247 //
248 // # Policy StructureSee google.iam.v1.Policy
249 //
250 // This is intentionally not a CRUD style API because access control policies
251 // are created and deleted implicitly with the resources to which they are
252 // attached.
253 func NewIamPolicyClient(ctx context.Context, opts ...option.ClientOption) (*IamPolicyClient, error) {
254 clientOpts := defaultIamPolicyGRPCClientOptions()
255 if newIamPolicyClientHook != nil {
256 hookOpts, err := newIamPolicyClientHook(ctx, clientHookParams{})
257 if err != nil {
258 return nil, err
259 }
260 clientOpts = append(clientOpts, hookOpts...)
261 }
262
263 connPool, err := gtransport.DialPool(ctx, append(clientOpts, opts...)...)
264 if err != nil {
265 return nil, err
266 }
267 client := IamPolicyClient{CallOptions: defaultIamPolicyCallOptions()}
268
269 c := &iamPolicyGRPCClient{
270 connPool: connPool,
271 iamPolicyClient: iampb.NewIAMPolicyClient(connPool),
272 CallOptions: &client.CallOptions,
273 operationsClient: longrunningpb.NewOperationsClient(connPool),
274 }
275 c.setGoogleClientInfo()
276
277 client.internalClient = c
278
279 return &client, nil
280 }
281
282 // Connection returns a connection to the API service.
283 //
284 // Deprecated: Connections are now pooled so this method does not always
285 // return the same resource.
286 func (c *iamPolicyGRPCClient) Connection() *grpc.ClientConn {
287 return c.connPool.Conn()
288 }
289
290 // setGoogleClientInfo sets the name and version of the application in
291 // the `x-goog-api-client` header passed on each request. Intended for
292 // use by Google-written clients.
293 func (c *iamPolicyGRPCClient) setGoogleClientInfo(keyval ...string) {
294 kv := append([]string{"gl-go", gax.GoVersion}, keyval...)
295 kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "grpc", grpc.Version)
296 c.xGoogHeaders = []string{"x-goog-api-client", gax.XGoogHeader(kv...)}
297 }
298
299 // Close closes the connection to the API service. The user should invoke this when
300 // the client is no longer required.
301 func (c *iamPolicyGRPCClient) Close() error {
302 return c.connPool.Close()
303 }
304
305 // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
306 type iamPolicyRESTClient struct {
307 // The http endpoint to connect to.
308 endpoint string
309
310 // The http client.
311 httpClient *http.Client
312
313 // The x-goog-* headers to be sent with each request.
314 xGoogHeaders []string
315
316 // Points back to the CallOptions field of the containing IamPolicyClient
317 CallOptions **IamPolicyCallOptions
318 }
319
320 // NewIamPolicyRESTClient creates a new iam policy rest client.
321 //
322 // # API Overview
323 //
324 // Manages Identity and Access Management (IAM) policies.
325 //
326 // Any implementation of an API that offers access control features
327 // implements the google.iam.v1.IAMPolicy interface.
328 //
329 // Data modelAccess control is applied when a principal (user or service account), takes
330 // some action on a resource exposed by a service. Resources, identified by
331 // URI-like names, are the unit of access control specification. Service
332 // implementations can choose the granularity of access control and the
333 // supported permissions for their resources.
334 // For example one database service may allow access control to be
335 // specified only at the Table level, whereas another might allow access control
336 // to also be specified at the Column level.
337 //
338 // # Policy StructureSee google.iam.v1.Policy
339 //
340 // This is intentionally not a CRUD style API because access control policies
341 // are created and deleted implicitly with the resources to which they are
342 // attached.
343 func NewIamPolicyRESTClient(ctx context.Context, opts ...option.ClientOption) (*IamPolicyClient, error) {
344 clientOpts := append(defaultIamPolicyRESTClientOptions(), opts...)
345 httpClient, endpoint, err := httptransport.NewClient(ctx, clientOpts...)
346 if err != nil {
347 return nil, err
348 }
349
350 callOpts := defaultIamPolicyRESTCallOptions()
351 c := &iamPolicyRESTClient{
352 endpoint: endpoint,
353 httpClient: httpClient,
354 CallOptions: &callOpts,
355 }
356 c.setGoogleClientInfo()
357
358 return &IamPolicyClient{internalClient: c, CallOptions: callOpts}, nil
359 }
360
361 func defaultIamPolicyRESTClientOptions() []option.ClientOption {
362 return []option.ClientOption{
363 internaloption.WithDefaultEndpoint("https://iam-meta-api.googleapis.com"),
364 internaloption.WithDefaultEndpointTemplate("https://iam-meta-api.UNIVERSE_DOMAIN"),
365 internaloption.WithDefaultMTLSEndpoint("https://iam-meta-api.mtls.googleapis.com"),
366 internaloption.WithDefaultAudience("https://iam-meta-api.googleapis.com/"),
367 internaloption.WithDefaultScopes(DefaultAuthScopes()...),
368 }
369 }
370
371 // setGoogleClientInfo sets the name and version of the application in
372 // the `x-goog-api-client` header passed on each request. Intended for
373 // use by Google-written clients.
374 func (c *iamPolicyRESTClient) setGoogleClientInfo(keyval ...string) {
375 kv := append([]string{"gl-go", gax.GoVersion}, keyval...)
376 kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "rest", "UNKNOWN")
377 c.xGoogHeaders = []string{"x-goog-api-client", gax.XGoogHeader(kv...)}
378 }
379
380 // Close closes the connection to the API service. The user should invoke this when
381 // the client is no longer required.
382 func (c *iamPolicyRESTClient) Close() error {
383 // Replace httpClient with nil to force cleanup.
384 c.httpClient = nil
385 return nil
386 }
387
388 // Connection returns a connection to the API service.
389 //
390 // Deprecated: This method always returns nil.
391 func (c *iamPolicyRESTClient) Connection() *grpc.ClientConn {
392 return nil
393 }
394 func (c *iamPolicyGRPCClient) SetIamPolicy(ctx context.Context, req *iampb.SetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) {
395 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))}
396
397 hds = append(c.xGoogHeaders, hds...)
398 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
399 opts = append((*c.CallOptions).SetIamPolicy[0:len((*c.CallOptions).SetIamPolicy):len((*c.CallOptions).SetIamPolicy)], opts...)
400 var resp *iampb.Policy
401 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
402 var err error
403 resp, err = c.iamPolicyClient.SetIamPolicy(ctx, req, settings.GRPC...)
404 return err
405 }, opts...)
406 if err != nil {
407 return nil, err
408 }
409 return resp, nil
410 }
411
412 func (c *iamPolicyGRPCClient) GetIamPolicy(ctx context.Context, req *iampb.GetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) {
413 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))}
414
415 hds = append(c.xGoogHeaders, hds...)
416 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
417 opts = append((*c.CallOptions).GetIamPolicy[0:len((*c.CallOptions).GetIamPolicy):len((*c.CallOptions).GetIamPolicy)], opts...)
418 var resp *iampb.Policy
419 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
420 var err error
421 resp, err = c.iamPolicyClient.GetIamPolicy(ctx, req, settings.GRPC...)
422 return err
423 }, opts...)
424 if err != nil {
425 return nil, err
426 }
427 return resp, nil
428 }
429
430 func (c *iamPolicyGRPCClient) TestIamPermissions(ctx context.Context, req *iampb.TestIamPermissionsRequest, opts ...gax.CallOption) (*iampb.TestIamPermissionsResponse, error) {
431 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))}
432
433 hds = append(c.xGoogHeaders, hds...)
434 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
435 opts = append((*c.CallOptions).TestIamPermissions[0:len((*c.CallOptions).TestIamPermissions):len((*c.CallOptions).TestIamPermissions)], opts...)
436 var resp *iampb.TestIamPermissionsResponse
437 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
438 var err error
439 resp, err = c.iamPolicyClient.TestIamPermissions(ctx, req, settings.GRPC...)
440 return err
441 }, opts...)
442 if err != nil {
443 return nil, err
444 }
445 return resp, nil
446 }
447
448 func (c *iamPolicyGRPCClient) CancelOperation(ctx context.Context, req *longrunningpb.CancelOperationRequest, opts ...gax.CallOption) error {
449 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
450
451 hds = append(c.xGoogHeaders, hds...)
452 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
453 opts = append((*c.CallOptions).CancelOperation[0:len((*c.CallOptions).CancelOperation):len((*c.CallOptions).CancelOperation)], opts...)
454 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
455 var err error
456 _, err = c.operationsClient.CancelOperation(ctx, req, settings.GRPC...)
457 return err
458 }, opts...)
459 return err
460 }
461
462 func (c *iamPolicyGRPCClient) DeleteOperation(ctx context.Context, req *longrunningpb.DeleteOperationRequest, opts ...gax.CallOption) error {
463 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
464
465 hds = append(c.xGoogHeaders, hds...)
466 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
467 opts = append((*c.CallOptions).DeleteOperation[0:len((*c.CallOptions).DeleteOperation):len((*c.CallOptions).DeleteOperation)], opts...)
468 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
469 var err error
470 _, err = c.operationsClient.DeleteOperation(ctx, req, settings.GRPC...)
471 return err
472 }, opts...)
473 return err
474 }
475
476 func (c *iamPolicyGRPCClient) GetOperation(ctx context.Context, req *longrunningpb.GetOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) {
477 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
478
479 hds = append(c.xGoogHeaders, hds...)
480 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
481 opts = append((*c.CallOptions).GetOperation[0:len((*c.CallOptions).GetOperation):len((*c.CallOptions).GetOperation)], opts...)
482 var resp *longrunningpb.Operation
483 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
484 var err error
485 resp, err = c.operationsClient.GetOperation(ctx, req, settings.GRPC...)
486 return err
487 }, opts...)
488 if err != nil {
489 return nil, err
490 }
491 return resp, nil
492 }
493
494 func (c *iamPolicyGRPCClient) ListOperations(ctx context.Context, req *longrunningpb.ListOperationsRequest, opts ...gax.CallOption) *OperationIterator {
495 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
496
497 hds = append(c.xGoogHeaders, hds...)
498 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
499 opts = append((*c.CallOptions).ListOperations[0:len((*c.CallOptions).ListOperations):len((*c.CallOptions).ListOperations)], opts...)
500 it := &OperationIterator{}
501 req = proto.Clone(req).(*longrunningpb.ListOperationsRequest)
502 it.InternalFetch = func(pageSize int, pageToken string) ([]*longrunningpb.Operation, string, error) {
503 resp := &longrunningpb.ListOperationsResponse{}
504 if pageToken != "" {
505 req.PageToken = pageToken
506 }
507 if pageSize > math.MaxInt32 {
508 req.PageSize = math.MaxInt32
509 } else if pageSize != 0 {
510 req.PageSize = int32(pageSize)
511 }
512 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
513 var err error
514 resp, err = c.operationsClient.ListOperations(ctx, req, settings.GRPC...)
515 return err
516 }, opts...)
517 if err != nil {
518 return nil, "", err
519 }
520
521 it.Response = resp
522 return resp.GetOperations(), resp.GetNextPageToken(), nil
523 }
524 fetch := func(pageSize int, pageToken string) (string, error) {
525 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
526 if err != nil {
527 return "", err
528 }
529 it.items = append(it.items, items...)
530 return nextPageToken, nil
531 }
532
533 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
534 it.pageInfo.MaxSize = int(req.GetPageSize())
535 it.pageInfo.Token = req.GetPageToken()
536
537 return it
538 }
539
540 // SetIamPolicy sets the access control policy on the specified resource. Replaces any
541 // existing policy.
542 //
543 // Can return NOT_FOUND, INVALID_ARGUMENT, and PERMISSION_DENIED errors.
544 func (c *iamPolicyRESTClient) SetIamPolicy(ctx context.Context, req *iampb.SetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) {
545 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
546 jsonReq, err := m.Marshal(req)
547 if err != nil {
548 return nil, err
549 }
550
551 baseUrl, err := url.Parse(c.endpoint)
552 if err != nil {
553 return nil, err
554 }
555 baseUrl.Path += fmt.Sprintf("/v1/%v:setIamPolicy", req.GetResource())
556
557 params := url.Values{}
558 params.Add("$alt", "json;enum-encoding=int")
559
560 baseUrl.RawQuery = params.Encode()
561
562 // Build HTTP headers from client and context metadata.
563 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))}
564
565 hds = append(c.xGoogHeaders, hds...)
566 hds = append(hds, "Content-Type", "application/json")
567 headers := gax.BuildHeaders(ctx, hds...)
568 opts = append((*c.CallOptions).SetIamPolicy[0:len((*c.CallOptions).SetIamPolicy):len((*c.CallOptions).SetIamPolicy)], opts...)
569 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
570 resp := &iampb.Policy{}
571 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
572 if settings.Path != "" {
573 baseUrl.Path = settings.Path
574 }
575 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
576 if err != nil {
577 return err
578 }
579 httpReq = httpReq.WithContext(ctx)
580 httpReq.Header = headers
581
582 httpRsp, err := c.httpClient.Do(httpReq)
583 if err != nil {
584 return err
585 }
586 defer httpRsp.Body.Close()
587
588 if err = googleapi.CheckResponse(httpRsp); err != nil {
589 return err
590 }
591
592 buf, err := io.ReadAll(httpRsp.Body)
593 if err != nil {
594 return err
595 }
596
597 if err := unm.Unmarshal(buf, resp); err != nil {
598 return err
599 }
600
601 return nil
602 }, opts...)
603 if e != nil {
604 return nil, e
605 }
606 return resp, nil
607 }
608
609 // GetIamPolicy gets the access control policy for a resource.
610 // Returns an empty policy if the resource exists and does not have a policy
611 // set.
612 func (c *iamPolicyRESTClient) GetIamPolicy(ctx context.Context, req *iampb.GetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) {
613 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
614 jsonReq, err := m.Marshal(req)
615 if err != nil {
616 return nil, err
617 }
618
619 baseUrl, err := url.Parse(c.endpoint)
620 if err != nil {
621 return nil, err
622 }
623 baseUrl.Path += fmt.Sprintf("/v1/%v:getIamPolicy", req.GetResource())
624
625 params := url.Values{}
626 params.Add("$alt", "json;enum-encoding=int")
627
628 baseUrl.RawQuery = params.Encode()
629
630 // Build HTTP headers from client and context metadata.
631 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))}
632
633 hds = append(c.xGoogHeaders, hds...)
634 hds = append(hds, "Content-Type", "application/json")
635 headers := gax.BuildHeaders(ctx, hds...)
636 opts = append((*c.CallOptions).GetIamPolicy[0:len((*c.CallOptions).GetIamPolicy):len((*c.CallOptions).GetIamPolicy)], opts...)
637 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
638 resp := &iampb.Policy{}
639 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
640 if settings.Path != "" {
641 baseUrl.Path = settings.Path
642 }
643 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
644 if err != nil {
645 return err
646 }
647 httpReq = httpReq.WithContext(ctx)
648 httpReq.Header = headers
649
650 httpRsp, err := c.httpClient.Do(httpReq)
651 if err != nil {
652 return err
653 }
654 defer httpRsp.Body.Close()
655
656 if err = googleapi.CheckResponse(httpRsp); err != nil {
657 return err
658 }
659
660 buf, err := io.ReadAll(httpRsp.Body)
661 if err != nil {
662 return err
663 }
664
665 if err := unm.Unmarshal(buf, resp); err != nil {
666 return err
667 }
668
669 return nil
670 }, opts...)
671 if e != nil {
672 return nil, e
673 }
674 return resp, nil
675 }
676
677 // TestIamPermissions returns permissions that a caller has on the specified resource.
678 // If the resource does not exist, this will return an empty set of
679 // permissions, not a NOT_FOUND error.
680 //
681 // Note: This operation is designed to be used for building permission-aware
682 // UIs and command-line tools, not for authorization checking. This operation
683 // may “fail open” without warning.
684 func (c *iamPolicyRESTClient) TestIamPermissions(ctx context.Context, req *iampb.TestIamPermissionsRequest, opts ...gax.CallOption) (*iampb.TestIamPermissionsResponse, error) {
685 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
686 jsonReq, err := m.Marshal(req)
687 if err != nil {
688 return nil, err
689 }
690
691 baseUrl, err := url.Parse(c.endpoint)
692 if err != nil {
693 return nil, err
694 }
695 baseUrl.Path += fmt.Sprintf("/v1/%v:testIamPermissions", req.GetResource())
696
697 params := url.Values{}
698 params.Add("$alt", "json;enum-encoding=int")
699
700 baseUrl.RawQuery = params.Encode()
701
702 // Build HTTP headers from client and context metadata.
703 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))}
704
705 hds = append(c.xGoogHeaders, hds...)
706 hds = append(hds, "Content-Type", "application/json")
707 headers := gax.BuildHeaders(ctx, hds...)
708 opts = append((*c.CallOptions).TestIamPermissions[0:len((*c.CallOptions).TestIamPermissions):len((*c.CallOptions).TestIamPermissions)], opts...)
709 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
710 resp := &iampb.TestIamPermissionsResponse{}
711 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
712 if settings.Path != "" {
713 baseUrl.Path = settings.Path
714 }
715 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
716 if err != nil {
717 return err
718 }
719 httpReq = httpReq.WithContext(ctx)
720 httpReq.Header = headers
721
722 httpRsp, err := c.httpClient.Do(httpReq)
723 if err != nil {
724 return err
725 }
726 defer httpRsp.Body.Close()
727
728 if err = googleapi.CheckResponse(httpRsp); err != nil {
729 return err
730 }
731
732 buf, err := io.ReadAll(httpRsp.Body)
733 if err != nil {
734 return err
735 }
736
737 if err := unm.Unmarshal(buf, resp); err != nil {
738 return err
739 }
740
741 return nil
742 }, opts...)
743 if e != nil {
744 return nil, e
745 }
746 return resp, nil
747 }
748
749 // CancelOperation is a utility method from google.longrunning.Operations.
750 func (c *iamPolicyRESTClient) CancelOperation(ctx context.Context, req *longrunningpb.CancelOperationRequest, opts ...gax.CallOption) error {
751 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
752 jsonReq, err := m.Marshal(req)
753 if err != nil {
754 return err
755 }
756
757 baseUrl, err := url.Parse(c.endpoint)
758 if err != nil {
759 return err
760 }
761 baseUrl.Path += fmt.Sprintf("/v1/%v:cancel", req.GetName())
762
763 params := url.Values{}
764 params.Add("$alt", "json;enum-encoding=int")
765
766 baseUrl.RawQuery = params.Encode()
767
768 // Build HTTP headers from client and context metadata.
769 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
770
771 hds = append(c.xGoogHeaders, hds...)
772 hds = append(hds, "Content-Type", "application/json")
773 headers := gax.BuildHeaders(ctx, hds...)
774 return gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
775 if settings.Path != "" {
776 baseUrl.Path = settings.Path
777 }
778 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
779 if err != nil {
780 return err
781 }
782 httpReq = httpReq.WithContext(ctx)
783 httpReq.Header = headers
784
785 httpRsp, err := c.httpClient.Do(httpReq)
786 if err != nil {
787 return err
788 }
789 defer httpRsp.Body.Close()
790
791 // Returns nil if there is no error, otherwise wraps
792 // the response code and body into a non-nil error
793 return googleapi.CheckResponse(httpRsp)
794 }, opts...)
795 }
796
797 // DeleteOperation is a utility method from google.longrunning.Operations.
798 func (c *iamPolicyRESTClient) DeleteOperation(ctx context.Context, req *longrunningpb.DeleteOperationRequest, opts ...gax.CallOption) error {
799 baseUrl, err := url.Parse(c.endpoint)
800 if err != nil {
801 return err
802 }
803 baseUrl.Path += fmt.Sprintf("/v1/%v", req.GetName())
804
805 params := url.Values{}
806 params.Add("$alt", "json;enum-encoding=int")
807
808 baseUrl.RawQuery = params.Encode()
809
810 // Build HTTP headers from client and context metadata.
811 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
812
813 hds = append(c.xGoogHeaders, hds...)
814 hds = append(hds, "Content-Type", "application/json")
815 headers := gax.BuildHeaders(ctx, hds...)
816 return gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
817 if settings.Path != "" {
818 baseUrl.Path = settings.Path
819 }
820 httpReq, err := http.NewRequest("DELETE", baseUrl.String(), nil)
821 if err != nil {
822 return err
823 }
824 httpReq = httpReq.WithContext(ctx)
825 httpReq.Header = headers
826
827 httpRsp, err := c.httpClient.Do(httpReq)
828 if err != nil {
829 return err
830 }
831 defer httpRsp.Body.Close()
832
833 // Returns nil if there is no error, otherwise wraps
834 // the response code and body into a non-nil error
835 return googleapi.CheckResponse(httpRsp)
836 }, opts...)
837 }
838
839 // GetOperation is a utility method from google.longrunning.Operations.
840 func (c *iamPolicyRESTClient) GetOperation(ctx context.Context, req *longrunningpb.GetOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) {
841 baseUrl, err := url.Parse(c.endpoint)
842 if err != nil {
843 return nil, err
844 }
845 baseUrl.Path += fmt.Sprintf("/v1/%v", req.GetName())
846
847 params := url.Values{}
848 params.Add("$alt", "json;enum-encoding=int")
849
850 baseUrl.RawQuery = params.Encode()
851
852 // Build HTTP headers from client and context metadata.
853 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
854
855 hds = append(c.xGoogHeaders, hds...)
856 hds = append(hds, "Content-Type", "application/json")
857 headers := gax.BuildHeaders(ctx, hds...)
858 opts = append((*c.CallOptions).GetOperation[0:len((*c.CallOptions).GetOperation):len((*c.CallOptions).GetOperation)], opts...)
859 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
860 resp := &longrunningpb.Operation{}
861 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
862 if settings.Path != "" {
863 baseUrl.Path = settings.Path
864 }
865 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
866 if err != nil {
867 return err
868 }
869 httpReq = httpReq.WithContext(ctx)
870 httpReq.Header = headers
871
872 httpRsp, err := c.httpClient.Do(httpReq)
873 if err != nil {
874 return err
875 }
876 defer httpRsp.Body.Close()
877
878 if err = googleapi.CheckResponse(httpRsp); err != nil {
879 return err
880 }
881
882 buf, err := io.ReadAll(httpRsp.Body)
883 if err != nil {
884 return err
885 }
886
887 if err := unm.Unmarshal(buf, resp); err != nil {
888 return err
889 }
890
891 return nil
892 }, opts...)
893 if e != nil {
894 return nil, e
895 }
896 return resp, nil
897 }
898
899 // ListOperations is a utility method from google.longrunning.Operations.
900 func (c *iamPolicyRESTClient) ListOperations(ctx context.Context, req *longrunningpb.ListOperationsRequest, opts ...gax.CallOption) *OperationIterator {
901 it := &OperationIterator{}
902 req = proto.Clone(req).(*longrunningpb.ListOperationsRequest)
903 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
904 it.InternalFetch = func(pageSize int, pageToken string) ([]*longrunningpb.Operation, string, error) {
905 resp := &longrunningpb.ListOperationsResponse{}
906 if pageToken != "" {
907 req.PageToken = pageToken
908 }
909 if pageSize > math.MaxInt32 {
910 req.PageSize = math.MaxInt32
911 } else if pageSize != 0 {
912 req.PageSize = int32(pageSize)
913 }
914 baseUrl, err := url.Parse(c.endpoint)
915 if err != nil {
916 return nil, "", err
917 }
918 baseUrl.Path += fmt.Sprintf("/v1/%v/operations", req.GetName())
919
920 params := url.Values{}
921 params.Add("$alt", "json;enum-encoding=int")
922 if req.GetFilter() != "" {
923 params.Add("filter", fmt.Sprintf("%v", req.GetFilter()))
924 }
925 if req.GetPageSize() != 0 {
926 params.Add("pageSize", fmt.Sprintf("%v", req.GetPageSize()))
927 }
928 if req.GetPageToken() != "" {
929 params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken()))
930 }
931
932 baseUrl.RawQuery = params.Encode()
933
934 // Build HTTP headers from client and context metadata.
935 hds := append(c.xGoogHeaders, "Content-Type", "application/json")
936 headers := gax.BuildHeaders(ctx, hds...)
937 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
938 if settings.Path != "" {
939 baseUrl.Path = settings.Path
940 }
941 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
942 if err != nil {
943 return err
944 }
945 httpReq.Header = headers
946
947 httpRsp, err := c.httpClient.Do(httpReq)
948 if err != nil {
949 return err
950 }
951 defer httpRsp.Body.Close()
952
953 if err = googleapi.CheckResponse(httpRsp); err != nil {
954 return err
955 }
956
957 buf, err := io.ReadAll(httpRsp.Body)
958 if err != nil {
959 return err
960 }
961
962 if err := unm.Unmarshal(buf, resp); err != nil {
963 return err
964 }
965
966 return nil
967 }, opts...)
968 if e != nil {
969 return nil, "", e
970 }
971 it.Response = resp
972 return resp.GetOperations(), resp.GetNextPageToken(), nil
973 }
974
975 fetch := func(pageSize int, pageToken string) (string, error) {
976 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
977 if err != nil {
978 return "", err
979 }
980 it.items = append(it.items, items...)
981 return nextPageToken, nil
982 }
983
984 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
985 it.pageInfo.MaxSize = int(req.GetPageSize())
986 it.pageInfo.Token = req.GetPageToken()
987
988 return it
989 }