Debian Codegraph @

apigeeregistry/apiv1/provisioning_client.go

raw
1 // Copyright 2025 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 package apigeeregistry
18
19 import (
20 "context"
21 "fmt"
22 "log/slog"
23 "math"
24 "net/url"
25
26 apigeeregistrypb "cloud.google.com/go/apigeeregistry/apiv1/apigeeregistrypb"
27 iampb "cloud.google.com/go/iam/apiv1/iampb"
28 "cloud.google.com/go/longrunning"
29 lroauto "cloud.google.com/go/longrunning/autogen"
30 longrunningpb "cloud.google.com/go/longrunning/autogen/longrunningpb"
31 gax "github.com/googleapis/gax-go/v2"
32 "google.golang.org/api/iterator"
33 "google.golang.org/api/option"
34 "google.golang.org/api/option/internaloption"
35 gtransport "google.golang.org/api/transport/grpc"
36 locationpb "google.golang.org/genproto/googleapis/cloud/location"
37 "google.golang.org/grpc"
38 "google.golang.org/protobuf/proto"
39 )
40
41 var newProvisioningClientHook clientHook
42
43 // ProvisioningCallOptions contains the retry settings for each method of ProvisioningClient.
44 type ProvisioningCallOptions struct {
45 CreateInstance []gax.CallOption
46 DeleteInstance []gax.CallOption
47 GetInstance []gax.CallOption
48 GetLocation []gax.CallOption
49 ListLocations []gax.CallOption
50 GetIamPolicy []gax.CallOption
51 SetIamPolicy []gax.CallOption
52 TestIamPermissions []gax.CallOption
53 CancelOperation []gax.CallOption
54 DeleteOperation []gax.CallOption
55 GetOperation []gax.CallOption
56 ListOperations []gax.CallOption
57 }
58
59 func defaultProvisioningGRPCClientOptions() []option.ClientOption {
60 return []option.ClientOption{
61 internaloption.WithDefaultEndpoint("apigeeregistry.googleapis.com:443"),
62 internaloption.WithDefaultEndpointTemplate("apigeeregistry.UNIVERSE_DOMAIN:443"),
63 internaloption.WithDefaultMTLSEndpoint("apigeeregistry.mtls.googleapis.com:443"),
64 internaloption.WithDefaultUniverseDomain("googleapis.com"),
65 internaloption.WithDefaultAudience("https://apigeeregistry.googleapis.com/"),
66 internaloption.WithDefaultScopes(DefaultAuthScopes()...),
67 internaloption.EnableJwtWithScope(),
68 internaloption.EnableNewAuthLibrary(),
69 option.WithGRPCDialOption(grpc.WithDefaultCallOptions(
70 grpc.MaxCallRecvMsgSize(math.MaxInt32))),
71 }
72 }
73
74 func defaultProvisioningCallOptions() *ProvisioningCallOptions {
75 return &ProvisioningCallOptions{
76 CreateInstance: []gax.CallOption{},
77 DeleteInstance: []gax.CallOption{},
78 GetInstance: []gax.CallOption{},
79 GetLocation: []gax.CallOption{},
80 ListLocations: []gax.CallOption{},
81 GetIamPolicy: []gax.CallOption{},
82 SetIamPolicy: []gax.CallOption{},
83 TestIamPermissions: []gax.CallOption{},
84 CancelOperation: []gax.CallOption{},
85 DeleteOperation: []gax.CallOption{},
86 GetOperation: []gax.CallOption{},
87 ListOperations: []gax.CallOption{},
88 }
89 }
90
91 // internalProvisioningClient is an interface that defines the methods available from Apigee Registry API.
92 type internalProvisioningClient interface {
93 Close() error
94 setGoogleClientInfo(...string)
95 Connection() *grpc.ClientConn
96 CreateInstance(context.Context, *apigeeregistrypb.CreateInstanceRequest, ...gax.CallOption) (*CreateInstanceOperation, error)
97 CreateInstanceOperation(name string) *CreateInstanceOperation
98 DeleteInstance(context.Context, *apigeeregistrypb.DeleteInstanceRequest, ...gax.CallOption) (*DeleteInstanceOperation, error)
99 DeleteInstanceOperation(name string) *DeleteInstanceOperation
100 GetInstance(context.Context, *apigeeregistrypb.GetInstanceRequest, ...gax.CallOption) (*apigeeregistrypb.Instance, error)
101 GetLocation(context.Context, *locationpb.GetLocationRequest, ...gax.CallOption) (*locationpb.Location, error)
102 ListLocations(context.Context, *locationpb.ListLocationsRequest, ...gax.CallOption) *LocationIterator
103 GetIamPolicy(context.Context, *iampb.GetIamPolicyRequest, ...gax.CallOption) (*iampb.Policy, error)
104 SetIamPolicy(context.Context, *iampb.SetIamPolicyRequest, ...gax.CallOption) (*iampb.Policy, error)
105 TestIamPermissions(context.Context, *iampb.TestIamPermissionsRequest, ...gax.CallOption) (*iampb.TestIamPermissionsResponse, error)
106 CancelOperation(context.Context, *longrunningpb.CancelOperationRequest, ...gax.CallOption) error
107 DeleteOperation(context.Context, *longrunningpb.DeleteOperationRequest, ...gax.CallOption) error
108 GetOperation(context.Context, *longrunningpb.GetOperationRequest, ...gax.CallOption) (*longrunningpb.Operation, error)
109 ListOperations(context.Context, *longrunningpb.ListOperationsRequest, ...gax.CallOption) *OperationIterator
110 }
111
112 // ProvisioningClient is a client for interacting with Apigee Registry API.
113 // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
114 //
115 // The service that is used for managing the data plane provisioning of the
116 // Registry.
117 type ProvisioningClient struct {
118 // The internal transport-dependent client.
119 internalClient internalProvisioningClient
120
121 // The call options for this service.
122 CallOptions *ProvisioningCallOptions
123
124 // LROClient is used internally to handle long-running operations.
125 // It is exposed so that its CallOptions can be modified if required.
126 // Users should not Close this client.
127 LROClient *lroauto.OperationsClient
128 }
129
130 // Wrapper methods routed to the internal client.
131
132 // Close closes the connection to the API service. The user should invoke this when
133 // the client is no longer required.
134 func (c *ProvisioningClient) Close() error {
135 return c.internalClient.Close()
136 }
137
138 // setGoogleClientInfo sets the name and version of the application in
139 // the `x-goog-api-client` header passed on each request. Intended for
140 // use by Google-written clients.
141 func (c *ProvisioningClient) setGoogleClientInfo(keyval ...string) {
142 c.internalClient.setGoogleClientInfo(keyval...)
143 }
144
145 // Connection returns a connection to the API service.
146 //
147 // Deprecated: Connections are now pooled so this method does not always
148 // return the same resource.
149 func (c *ProvisioningClient) Connection() *grpc.ClientConn {
150 return c.internalClient.Connection()
151 }
152
153 // CreateInstance provisions instance resources for the Registry.
154 func (c *ProvisioningClient) CreateInstance(ctx context.Context, req *apigeeregistrypb.CreateInstanceRequest, opts ...gax.CallOption) (*CreateInstanceOperation, error) {
155 return c.internalClient.CreateInstance(ctx, req, opts...)
156 }
157
158 // CreateInstanceOperation returns a new CreateInstanceOperation from a given name.
159 // The name must be that of a previously created CreateInstanceOperation, possibly from a different process.
160 func (c *ProvisioningClient) CreateInstanceOperation(name string) *CreateInstanceOperation {
161 return c.internalClient.CreateInstanceOperation(name)
162 }
163
164 // DeleteInstance deletes the Registry instance.
165 func (c *ProvisioningClient) DeleteInstance(ctx context.Context, req *apigeeregistrypb.DeleteInstanceRequest, opts ...gax.CallOption) (*DeleteInstanceOperation, error) {
166 return c.internalClient.DeleteInstance(ctx, req, opts...)
167 }
168
169 // DeleteInstanceOperation returns a new DeleteInstanceOperation from a given name.
170 // The name must be that of a previously created DeleteInstanceOperation, possibly from a different process.
171 func (c *ProvisioningClient) DeleteInstanceOperation(name string) *DeleteInstanceOperation {
172 return c.internalClient.DeleteInstanceOperation(name)
173 }
174
175 // GetInstance gets details of a single Instance.
176 func (c *ProvisioningClient) GetInstance(ctx context.Context, req *apigeeregistrypb.GetInstanceRequest, opts ...gax.CallOption) (*apigeeregistrypb.Instance, error) {
177 return c.internalClient.GetInstance(ctx, req, opts...)
178 }
179
180 // GetLocation gets information about a location.
181 func (c *ProvisioningClient) GetLocation(ctx context.Context, req *locationpb.GetLocationRequest, opts ...gax.CallOption) (*locationpb.Location, error) {
182 return c.internalClient.GetLocation(ctx, req, opts...)
183 }
184
185 // ListLocations lists information about the supported locations for this service.
186 func (c *ProvisioningClient) ListLocations(ctx context.Context, req *locationpb.ListLocationsRequest, opts ...gax.CallOption) *LocationIterator {
187 return c.internalClient.ListLocations(ctx, req, opts...)
188 }
189
190 // GetIamPolicy gets the access control policy for a resource. Returns an empty policy
191 // if the resource exists and does not have a policy set.
192 func (c *ProvisioningClient) GetIamPolicy(ctx context.Context, req *iampb.GetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) {
193 return c.internalClient.GetIamPolicy(ctx, req, opts...)
194 }
195
196 // SetIamPolicy sets the access control policy on the specified resource. Replaces
197 // any existing policy.
198 //
199 // Can return NOT_FOUND, INVALID_ARGUMENT, and PERMISSION_DENIED
200 // errors.
201 func (c *ProvisioningClient) SetIamPolicy(ctx context.Context, req *iampb.SetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) {
202 return c.internalClient.SetIamPolicy(ctx, req, opts...)
203 }
204
205 // TestIamPermissions returns permissions that a caller has on the specified resource. If the
206 // resource does not exist, this will return an empty set of
207 // permissions, not a NOT_FOUND error.
208 //
209 // Note: This operation is designed to be used for building
210 // permission-aware UIs and command-line tools, not for authorization
211 // checking. This operation may “fail open” without warning.
212 func (c *ProvisioningClient) TestIamPermissions(ctx context.Context, req *iampb.TestIamPermissionsRequest, opts ...gax.CallOption) (*iampb.TestIamPermissionsResponse, error) {
213 return c.internalClient.TestIamPermissions(ctx, req, opts...)
214 }
215
216 // CancelOperation is a utility method from google.longrunning.Operations.
217 func (c *ProvisioningClient) CancelOperation(ctx context.Context, req *longrunningpb.CancelOperationRequest, opts ...gax.CallOption) error {
218 return c.internalClient.CancelOperation(ctx, req, opts...)
219 }
220
221 // DeleteOperation is a utility method from google.longrunning.Operations.
222 func (c *ProvisioningClient) DeleteOperation(ctx context.Context, req *longrunningpb.DeleteOperationRequest, opts ...gax.CallOption) error {
223 return c.internalClient.DeleteOperation(ctx, req, opts...)
224 }
225
226 // GetOperation is a utility method from google.longrunning.Operations.
227 func (c *ProvisioningClient) GetOperation(ctx context.Context, req *longrunningpb.GetOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) {
228 return c.internalClient.GetOperation(ctx, req, opts...)
229 }
230
231 // ListOperations is a utility method from google.longrunning.Operations.
232 func (c *ProvisioningClient) ListOperations(ctx context.Context, req *longrunningpb.ListOperationsRequest, opts ...gax.CallOption) *OperationIterator {
233 return c.internalClient.ListOperations(ctx, req, opts...)
234 }
235
236 // provisioningGRPCClient is a client for interacting with Apigee Registry API over gRPC transport.
237 //
238 // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
239 type provisioningGRPCClient struct {
240 // Connection pool of gRPC connections to the service.
241 connPool gtransport.ConnPool
242
243 // Points back to the CallOptions field of the containing ProvisioningClient
244 CallOptions **ProvisioningCallOptions
245
246 // The gRPC API client.
247 provisioningClient apigeeregistrypb.ProvisioningClient
248
249 // LROClient is used internally to handle long-running operations.
250 // It is exposed so that its CallOptions can be modified if required.
251 // Users should not Close this client.
252 LROClient **lroauto.OperationsClient
253
254 operationsClient longrunningpb.OperationsClient
255
256 iamPolicyClient iampb.IAMPolicyClient
257
258 locationsClient locationpb.LocationsClient
259
260 // The x-goog-* metadata to be sent with each request.
261 xGoogHeaders []string
262
263 logger *slog.Logger
264 }
265
266 // NewProvisioningClient creates a new provisioning client based on gRPC.
267 // The returned client must be Closed when it is done being used to clean up its underlying connections.
268 //
269 // The service that is used for managing the data plane provisioning of the
270 // Registry.
271 func NewProvisioningClient(ctx context.Context, opts ...option.ClientOption) (*ProvisioningClient, error) {
272 clientOpts := defaultProvisioningGRPCClientOptions()
273 if newProvisioningClientHook != nil {
274 hookOpts, err := newProvisioningClientHook(ctx, clientHookParams{})
275 if err != nil {
276 return nil, err
277 }
278 clientOpts = append(clientOpts, hookOpts...)
279 }
280
281 connPool, err := gtransport.DialPool(ctx, append(clientOpts, opts...)...)
282 if err != nil {
283 return nil, err
284 }
285 client := ProvisioningClient{CallOptions: defaultProvisioningCallOptions()}
286
287 c := &provisioningGRPCClient{
288 connPool: connPool,
289 provisioningClient: apigeeregistrypb.NewProvisioningClient(connPool),
290 CallOptions: &client.CallOptions,
291 logger: internaloption.GetLogger(opts),
292 operationsClient: longrunningpb.NewOperationsClient(connPool),
293 iamPolicyClient: iampb.NewIAMPolicyClient(connPool),
294 locationsClient: locationpb.NewLocationsClient(connPool),
295 }
296 c.setGoogleClientInfo()
297
298 client.internalClient = c
299
300 client.LROClient, err = lroauto.NewOperationsClient(ctx, gtransport.WithConnPool(connPool))
301 if err != nil {
302 // This error "should not happen", since we are just reusing old connection pool
303 // and never actually need to dial.
304 // If this does happen, we could leak connp. However, we cannot close conn:
305 // If the user invoked the constructor with option.WithGRPCConn,
306 // we would close a connection that's still in use.
307 // TODO: investigate error conditions.
308 return nil, err
309 }
310 c.LROClient = &client.LROClient
311 return &client, nil
312 }
313
314 // Connection returns a connection to the API service.
315 //
316 // Deprecated: Connections are now pooled so this method does not always
317 // return the same resource.
318 func (c *provisioningGRPCClient) Connection() *grpc.ClientConn {
319 return c.connPool.Conn()
320 }
321
322 // setGoogleClientInfo sets the name and version of the application in
323 // the `x-goog-api-client` header passed on each request. Intended for
324 // use by Google-written clients.
325 func (c *provisioningGRPCClient) setGoogleClientInfo(keyval ...string) {
326 kv := append([]string{"gl-go", gax.GoVersion}, keyval...)
327 kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "grpc", grpc.Version, "pb", protoVersion)
328 c.xGoogHeaders = []string{
329 "x-goog-api-client", gax.XGoogHeader(kv...),
330 }
331 }
332
333 // Close closes the connection to the API service. The user should invoke this when
334 // the client is no longer required.
335 func (c *provisioningGRPCClient) Close() error {
336 return c.connPool.Close()
337 }
338
339 func (c *provisioningGRPCClient) CreateInstance(ctx context.Context, req *apigeeregistrypb.CreateInstanceRequest, opts ...gax.CallOption) (*CreateInstanceOperation, error) {
340 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
341
342 hds = append(c.xGoogHeaders, hds...)
343 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
344 opts = append((*c.CallOptions).CreateInstance[0:len((*c.CallOptions).CreateInstance):len((*c.CallOptions).CreateInstance)], opts...)
345 var resp *longrunningpb.Operation
346 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
347 var err error
348 resp, err = executeRPC(ctx, c.provisioningClient.CreateInstance, req, settings.GRPC, c.logger, "CreateInstance")
349 return err
350 }, opts...)
351 if err != nil {
352 return nil, err
353 }
354 return &CreateInstanceOperation{
355 lro: longrunning.InternalNewOperation(*c.LROClient, resp),
356 }, nil
357 }
358
359 func (c *provisioningGRPCClient) DeleteInstance(ctx context.Context, req *apigeeregistrypb.DeleteInstanceRequest, opts ...gax.CallOption) (*DeleteInstanceOperation, error) {
360 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
361
362 hds = append(c.xGoogHeaders, hds...)
363 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
364 opts = append((*c.CallOptions).DeleteInstance[0:len((*c.CallOptions).DeleteInstance):len((*c.CallOptions).DeleteInstance)], opts...)
365 var resp *longrunningpb.Operation
366 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
367 var err error
368 resp, err = executeRPC(ctx, c.provisioningClient.DeleteInstance, req, settings.GRPC, c.logger, "DeleteInstance")
369 return err
370 }, opts...)
371 if err != nil {
372 return nil, err
373 }
374 return &DeleteInstanceOperation{
375 lro: longrunning.InternalNewOperation(*c.LROClient, resp),
376 }, nil
377 }
378
379 func (c *provisioningGRPCClient) GetInstance(ctx context.Context, req *apigeeregistrypb.GetInstanceRequest, opts ...gax.CallOption) (*apigeeregistrypb.Instance, error) {
380 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
381
382 hds = append(c.xGoogHeaders, hds...)
383 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
384 opts = append((*c.CallOptions).GetInstance[0:len((*c.CallOptions).GetInstance):len((*c.CallOptions).GetInstance)], opts...)
385 var resp *apigeeregistrypb.Instance
386 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
387 var err error
388 resp, err = executeRPC(ctx, c.provisioningClient.GetInstance, req, settings.GRPC, c.logger, "GetInstance")
389 return err
390 }, opts...)
391 if err != nil {
392 return nil, err
393 }
394 return resp, nil
395 }
396
397 func (c *provisioningGRPCClient) GetLocation(ctx context.Context, req *locationpb.GetLocationRequest, opts ...gax.CallOption) (*locationpb.Location, error) {
398 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
399
400 hds = append(c.xGoogHeaders, hds...)
401 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
402 opts = append((*c.CallOptions).GetLocation[0:len((*c.CallOptions).GetLocation):len((*c.CallOptions).GetLocation)], opts...)
403 var resp *locationpb.Location
404 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
405 var err error
406 resp, err = executeRPC(ctx, c.locationsClient.GetLocation, req, settings.GRPC, c.logger, "GetLocation")
407 return err
408 }, opts...)
409 if err != nil {
410 return nil, err
411 }
412 return resp, nil
413 }
414
415 func (c *provisioningGRPCClient) ListLocations(ctx context.Context, req *locationpb.ListLocationsRequest, opts ...gax.CallOption) *LocationIterator {
416 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
417
418 hds = append(c.xGoogHeaders, hds...)
419 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
420 opts = append((*c.CallOptions).ListLocations[0:len((*c.CallOptions).ListLocations):len((*c.CallOptions).ListLocations)], opts...)
421 it := &LocationIterator{}
422 req = proto.Clone(req).(*locationpb.ListLocationsRequest)
423 it.InternalFetch = func(pageSize int, pageToken string) ([]*locationpb.Location, string, error) {
424 resp := &locationpb.ListLocationsResponse{}
425 if pageToken != "" {
426 req.PageToken = pageToken
427 }
428 if pageSize > math.MaxInt32 {
429 req.PageSize = math.MaxInt32
430 } else if pageSize != 0 {
431 req.PageSize = int32(pageSize)
432 }
433 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
434 var err error
435 resp, err = executeRPC(ctx, c.locationsClient.ListLocations, req, settings.GRPC, c.logger, "ListLocations")
436 return err
437 }, opts...)
438 if err != nil {
439 return nil, "", err
440 }
441
442 it.Response = resp
443 return resp.GetLocations(), resp.GetNextPageToken(), nil
444 }
445 fetch := func(pageSize int, pageToken string) (string, error) {
446 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
447 if err != nil {
448 return "", err
449 }
450 it.items = append(it.items, items...)
451 return nextPageToken, nil
452 }
453
454 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
455 it.pageInfo.MaxSize = int(req.GetPageSize())
456 it.pageInfo.Token = req.GetPageToken()
457
458 return it
459 }
460
461 func (c *provisioningGRPCClient) GetIamPolicy(ctx context.Context, req *iampb.GetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) {
462 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))}
463
464 hds = append(c.xGoogHeaders, hds...)
465 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
466 opts = append((*c.CallOptions).GetIamPolicy[0:len((*c.CallOptions).GetIamPolicy):len((*c.CallOptions).GetIamPolicy)], opts...)
467 var resp *iampb.Policy
468 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
469 var err error
470 resp, err = executeRPC(ctx, c.iamPolicyClient.GetIamPolicy, req, settings.GRPC, c.logger, "GetIamPolicy")
471 return err
472 }, opts...)
473 if err != nil {
474 return nil, err
475 }
476 return resp, nil
477 }
478
479 func (c *provisioningGRPCClient) SetIamPolicy(ctx context.Context, req *iampb.SetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) {
480 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))}
481
482 hds = append(c.xGoogHeaders, hds...)
483 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
484 opts = append((*c.CallOptions).SetIamPolicy[0:len((*c.CallOptions).SetIamPolicy):len((*c.CallOptions).SetIamPolicy)], opts...)
485 var resp *iampb.Policy
486 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
487 var err error
488 resp, err = executeRPC(ctx, c.iamPolicyClient.SetIamPolicy, req, settings.GRPC, c.logger, "SetIamPolicy")
489 return err
490 }, opts...)
491 if err != nil {
492 return nil, err
493 }
494 return resp, nil
495 }
496
497 func (c *provisioningGRPCClient) TestIamPermissions(ctx context.Context, req *iampb.TestIamPermissionsRequest, opts ...gax.CallOption) (*iampb.TestIamPermissionsResponse, error) {
498 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))}
499
500 hds = append(c.xGoogHeaders, hds...)
501 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
502 opts = append((*c.CallOptions).TestIamPermissions[0:len((*c.CallOptions).TestIamPermissions):len((*c.CallOptions).TestIamPermissions)], opts...)
503 var resp *iampb.TestIamPermissionsResponse
504 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
505 var err error
506 resp, err = executeRPC(ctx, c.iamPolicyClient.TestIamPermissions, req, settings.GRPC, c.logger, "TestIamPermissions")
507 return err
508 }, opts...)
509 if err != nil {
510 return nil, err
511 }
512 return resp, nil
513 }
514
515 func (c *provisioningGRPCClient) CancelOperation(ctx context.Context, req *longrunningpb.CancelOperationRequest, opts ...gax.CallOption) error {
516 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
517
518 hds = append(c.xGoogHeaders, hds...)
519 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
520 opts = append((*c.CallOptions).CancelOperation[0:len((*c.CallOptions).CancelOperation):len((*c.CallOptions).CancelOperation)], opts...)
521 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
522 var err error
523 _, err = executeRPC(ctx, c.operationsClient.CancelOperation, req, settings.GRPC, c.logger, "CancelOperation")
524 return err
525 }, opts...)
526 return err
527 }
528
529 func (c *provisioningGRPCClient) DeleteOperation(ctx context.Context, req *longrunningpb.DeleteOperationRequest, opts ...gax.CallOption) error {
530 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
531
532 hds = append(c.xGoogHeaders, hds...)
533 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
534 opts = append((*c.CallOptions).DeleteOperation[0:len((*c.CallOptions).DeleteOperation):len((*c.CallOptions).DeleteOperation)], opts...)
535 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
536 var err error
537 _, err = executeRPC(ctx, c.operationsClient.DeleteOperation, req, settings.GRPC, c.logger, "DeleteOperation")
538 return err
539 }, opts...)
540 return err
541 }
542
543 func (c *provisioningGRPCClient) GetOperation(ctx context.Context, req *longrunningpb.GetOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) {
544 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
545
546 hds = append(c.xGoogHeaders, hds...)
547 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
548 opts = append((*c.CallOptions).GetOperation[0:len((*c.CallOptions).GetOperation):len((*c.CallOptions).GetOperation)], opts...)
549 var resp *longrunningpb.Operation
550 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
551 var err error
552 resp, err = executeRPC(ctx, c.operationsClient.GetOperation, req, settings.GRPC, c.logger, "GetOperation")
553 return err
554 }, opts...)
555 if err != nil {
556 return nil, err
557 }
558 return resp, nil
559 }
560
561 func (c *provisioningGRPCClient) ListOperations(ctx context.Context, req *longrunningpb.ListOperationsRequest, opts ...gax.CallOption) *OperationIterator {
562 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
563
564 hds = append(c.xGoogHeaders, hds...)
565 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
566 opts = append((*c.CallOptions).ListOperations[0:len((*c.CallOptions).ListOperations):len((*c.CallOptions).ListOperations)], opts...)
567 it := &OperationIterator{}
568 req = proto.Clone(req).(*longrunningpb.ListOperationsRequest)
569 it.InternalFetch = func(pageSize int, pageToken string) ([]*longrunningpb.Operation, string, error) {
570 resp := &longrunningpb.ListOperationsResponse{}
571 if pageToken != "" {
572 req.PageToken = pageToken
573 }
574 if pageSize > math.MaxInt32 {
575 req.PageSize = math.MaxInt32
576 } else if pageSize != 0 {
577 req.PageSize = int32(pageSize)
578 }
579 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
580 var err error
581 resp, err = executeRPC(ctx, c.operationsClient.ListOperations, req, settings.GRPC, c.logger, "ListOperations")
582 return err
583 }, opts...)
584 if err != nil {
585 return nil, "", err
586 }
587
588 it.Response = resp
589 return resp.GetOperations(), resp.GetNextPageToken(), nil
590 }
591 fetch := func(pageSize int, pageToken string) (string, error) {
592 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
593 if err != nil {
594 return "", err
595 }
596 it.items = append(it.items, items...)
597 return nextPageToken, nil
598 }
599
600 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
601 it.pageInfo.MaxSize = int(req.GetPageSize())
602 it.pageInfo.Token = req.GetPageToken()
603
604 return it
605 }
606
607 // CreateInstanceOperation returns a new CreateInstanceOperation from a given name.
608 // The name must be that of a previously created CreateInstanceOperation, possibly from a different process.
609 func (c *provisioningGRPCClient) CreateInstanceOperation(name string) *CreateInstanceOperation {
610 return &CreateInstanceOperation{
611 lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}),
612 }
613 }
614
615 // DeleteInstanceOperation returns a new DeleteInstanceOperation from a given name.
616 // The name must be that of a previously created DeleteInstanceOperation, possibly from a different process.
617 func (c *provisioningGRPCClient) DeleteInstanceOperation(name string) *DeleteInstanceOperation {
618 return &DeleteInstanceOperation{
619 lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}),
620 }
621 }