Debian Codegraph @

servicemanagement/apiv1/service_manager_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 servicemanagement
18
19 import (
20 "bytes"
21 "context"
22 "fmt"
23 "log/slog"
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 servicemanagementpb "cloud.google.com/go/servicemanagement/apiv1/servicemanagementpb"
34 gax "github.com/googleapis/gax-go/v2"
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 serviceconfigpb "google.golang.org/genproto/googleapis/api/serviceconfig"
41 "google.golang.org/grpc"
42 "google.golang.org/protobuf/encoding/protojson"
43 "google.golang.org/protobuf/proto"
44 )
45
46 var newServiceManagerClientHook clientHook
47
48 // ServiceManagerCallOptions contains the retry settings for each method of ServiceManagerClient.
49 type ServiceManagerCallOptions struct {
50 ListServices []gax.CallOption
51 GetService []gax.CallOption
52 CreateService []gax.CallOption
53 DeleteService []gax.CallOption
54 UndeleteService []gax.CallOption
55 ListServiceConfigs []gax.CallOption
56 GetServiceConfig []gax.CallOption
57 CreateServiceConfig []gax.CallOption
58 SubmitConfigSource []gax.CallOption
59 ListServiceRollouts []gax.CallOption
60 GetServiceRollout []gax.CallOption
61 CreateServiceRollout []gax.CallOption
62 GenerateConfigReport []gax.CallOption
63 GetIamPolicy []gax.CallOption
64 SetIamPolicy []gax.CallOption
65 TestIamPermissions []gax.CallOption
66 ListOperations []gax.CallOption
67 }
68
69 func defaultServiceManagerGRPCClientOptions() []option.ClientOption {
70 return []option.ClientOption{
71 internaloption.WithDefaultEndpoint("servicemanagement.googleapis.com:443"),
72 internaloption.WithDefaultEndpointTemplate("servicemanagement.UNIVERSE_DOMAIN:443"),
73 internaloption.WithDefaultMTLSEndpoint("servicemanagement.mtls.googleapis.com:443"),
74 internaloption.WithDefaultUniverseDomain("googleapis.com"),
75 internaloption.WithDefaultAudience("https://servicemanagement.googleapis.com/"),
76 internaloption.WithDefaultScopes(DefaultAuthScopes()...),
77 internaloption.EnableJwtWithScope(),
78 internaloption.EnableNewAuthLibrary(),
79 option.WithGRPCDialOption(grpc.WithDefaultCallOptions(
80 grpc.MaxCallRecvMsgSize(math.MaxInt32))),
81 }
82 }
83
84 func defaultServiceManagerCallOptions() *ServiceManagerCallOptions {
85 return &ServiceManagerCallOptions{
86 ListServices: []gax.CallOption{
87 gax.WithTimeout(10000 * time.Millisecond),
88 },
89 GetService: []gax.CallOption{
90 gax.WithTimeout(10000 * time.Millisecond),
91 },
92 CreateService: []gax.CallOption{
93 gax.WithTimeout(10000 * time.Millisecond),
94 },
95 DeleteService: []gax.CallOption{
96 gax.WithTimeout(10000 * time.Millisecond),
97 },
98 UndeleteService: []gax.CallOption{
99 gax.WithTimeout(10000 * time.Millisecond),
100 },
101 ListServiceConfigs: []gax.CallOption{
102 gax.WithTimeout(10000 * time.Millisecond),
103 },
104 GetServiceConfig: []gax.CallOption{
105 gax.WithTimeout(10000 * time.Millisecond),
106 },
107 CreateServiceConfig: []gax.CallOption{
108 gax.WithTimeout(10000 * time.Millisecond),
109 },
110 SubmitConfigSource: []gax.CallOption{
111 gax.WithTimeout(10000 * time.Millisecond),
112 },
113 ListServiceRollouts: []gax.CallOption{
114 gax.WithTimeout(10000 * time.Millisecond),
115 },
116 GetServiceRollout: []gax.CallOption{
117 gax.WithTimeout(10000 * time.Millisecond),
118 },
119 CreateServiceRollout: []gax.CallOption{
120 gax.WithTimeout(10000 * time.Millisecond),
121 },
122 GenerateConfigReport: []gax.CallOption{
123 gax.WithTimeout(10000 * time.Millisecond),
124 },
125 GetIamPolicy: []gax.CallOption{},
126 SetIamPolicy: []gax.CallOption{},
127 TestIamPermissions: []gax.CallOption{},
128 ListOperations: []gax.CallOption{},
129 }
130 }
131
132 func defaultServiceManagerRESTCallOptions() *ServiceManagerCallOptions {
133 return &ServiceManagerCallOptions{
134 ListServices: []gax.CallOption{
135 gax.WithTimeout(10000 * time.Millisecond),
136 },
137 GetService: []gax.CallOption{
138 gax.WithTimeout(10000 * time.Millisecond),
139 },
140 CreateService: []gax.CallOption{
141 gax.WithTimeout(10000 * time.Millisecond),
142 },
143 DeleteService: []gax.CallOption{
144 gax.WithTimeout(10000 * time.Millisecond),
145 },
146 UndeleteService: []gax.CallOption{
147 gax.WithTimeout(10000 * time.Millisecond),
148 },
149 ListServiceConfigs: []gax.CallOption{
150 gax.WithTimeout(10000 * time.Millisecond),
151 },
152 GetServiceConfig: []gax.CallOption{
153 gax.WithTimeout(10000 * time.Millisecond),
154 },
155 CreateServiceConfig: []gax.CallOption{
156 gax.WithTimeout(10000 * time.Millisecond),
157 },
158 SubmitConfigSource: []gax.CallOption{
159 gax.WithTimeout(10000 * time.Millisecond),
160 },
161 ListServiceRollouts: []gax.CallOption{
162 gax.WithTimeout(10000 * time.Millisecond),
163 },
164 GetServiceRollout: []gax.CallOption{
165 gax.WithTimeout(10000 * time.Millisecond),
166 },
167 CreateServiceRollout: []gax.CallOption{
168 gax.WithTimeout(10000 * time.Millisecond),
169 },
170 GenerateConfigReport: []gax.CallOption{
171 gax.WithTimeout(10000 * time.Millisecond),
172 },
173 GetIamPolicy: []gax.CallOption{},
174 SetIamPolicy: []gax.CallOption{},
175 TestIamPermissions: []gax.CallOption{},
176 ListOperations: []gax.CallOption{},
177 }
178 }
179
180 // internalServiceManagerClient is an interface that defines the methods available from Service Management API.
181 type internalServiceManagerClient interface {
182 Close() error
183 setGoogleClientInfo(...string)
184 Connection() *grpc.ClientConn
185 ListServices(context.Context, *servicemanagementpb.ListServicesRequest, ...gax.CallOption) *ManagedServiceIterator
186 GetService(context.Context, *servicemanagementpb.GetServiceRequest, ...gax.CallOption) (*servicemanagementpb.ManagedService, error)
187 CreateService(context.Context, *servicemanagementpb.CreateServiceRequest, ...gax.CallOption) (*CreateServiceOperation, error)
188 CreateServiceOperation(name string) *CreateServiceOperation
189 DeleteService(context.Context, *servicemanagementpb.DeleteServiceRequest, ...gax.CallOption) (*DeleteServiceOperation, error)
190 DeleteServiceOperation(name string) *DeleteServiceOperation
191 UndeleteService(context.Context, *servicemanagementpb.UndeleteServiceRequest, ...gax.CallOption) (*UndeleteServiceOperation, error)
192 UndeleteServiceOperation(name string) *UndeleteServiceOperation
193 ListServiceConfigs(context.Context, *servicemanagementpb.ListServiceConfigsRequest, ...gax.CallOption) *ServiceIterator
194 GetServiceConfig(context.Context, *servicemanagementpb.GetServiceConfigRequest, ...gax.CallOption) (*serviceconfigpb.Service, error)
195 CreateServiceConfig(context.Context, *servicemanagementpb.CreateServiceConfigRequest, ...gax.CallOption) (*serviceconfigpb.Service, error)
196 SubmitConfigSource(context.Context, *servicemanagementpb.SubmitConfigSourceRequest, ...gax.CallOption) (*SubmitConfigSourceOperation, error)
197 SubmitConfigSourceOperation(name string) *SubmitConfigSourceOperation
198 ListServiceRollouts(context.Context, *servicemanagementpb.ListServiceRolloutsRequest, ...gax.CallOption) *RolloutIterator
199 GetServiceRollout(context.Context, *servicemanagementpb.GetServiceRolloutRequest, ...gax.CallOption) (*servicemanagementpb.Rollout, error)
200 CreateServiceRollout(context.Context, *servicemanagementpb.CreateServiceRolloutRequest, ...gax.CallOption) (*CreateServiceRolloutOperation, error)
201 CreateServiceRolloutOperation(name string) *CreateServiceRolloutOperation
202 GenerateConfigReport(context.Context, *servicemanagementpb.GenerateConfigReportRequest, ...gax.CallOption) (*servicemanagementpb.GenerateConfigReportResponse, error)
203 GetIamPolicy(context.Context, *iampb.GetIamPolicyRequest, ...gax.CallOption) (*iampb.Policy, error)
204 SetIamPolicy(context.Context, *iampb.SetIamPolicyRequest, ...gax.CallOption) (*iampb.Policy, error)
205 TestIamPermissions(context.Context, *iampb.TestIamPermissionsRequest, ...gax.CallOption) (*iampb.TestIamPermissionsResponse, error)
206 ListOperations(context.Context, *longrunningpb.ListOperationsRequest, ...gax.CallOption) *OperationIterator
207 }
208
209 // ServiceManagerClient is a client for interacting with Service Management API.
210 // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
211 //
212 // Google Service Management
213 // API (at https://cloud.google.com/service-infrastructure/docs/overview)
214 type ServiceManagerClient struct {
215 // The internal transport-dependent client.
216 internalClient internalServiceManagerClient
217
218 // The call options for this service.
219 CallOptions *ServiceManagerCallOptions
220
221 // LROClient is used internally to handle long-running operations.
222 // It is exposed so that its CallOptions can be modified if required.
223 // Users should not Close this client.
224 LROClient *lroauto.OperationsClient
225 }
226
227 // Wrapper methods routed to the internal client.
228
229 // Close closes the connection to the API service. The user should invoke this when
230 // the client is no longer required.
231 func (c *ServiceManagerClient) Close() error {
232 return c.internalClient.Close()
233 }
234
235 // setGoogleClientInfo sets the name and version of the application in
236 // the `x-goog-api-client` header passed on each request. Intended for
237 // use by Google-written clients.
238 func (c *ServiceManagerClient) setGoogleClientInfo(keyval ...string) {
239 c.internalClient.setGoogleClientInfo(keyval...)
240 }
241
242 // Connection returns a connection to the API service.
243 //
244 // Deprecated: Connections are now pooled so this method does not always
245 // return the same resource.
246 func (c *ServiceManagerClient) Connection() *grpc.ClientConn {
247 return c.internalClient.Connection()
248 }
249
250 // ListServices lists managed services.
251 //
252 // Returns all public services. For authenticated users, also returns all
253 // services the calling user has “servicemanagement.services.get” permission
254 // for.
255 func (c *ServiceManagerClient) ListServices(ctx context.Context, req *servicemanagementpb.ListServicesRequest, opts ...gax.CallOption) *ManagedServiceIterator {
256 return c.internalClient.ListServices(ctx, req, opts...)
257 }
258
259 // GetService gets a managed service. Authentication is required unless the service is
260 // public.
261 func (c *ServiceManagerClient) GetService(ctx context.Context, req *servicemanagementpb.GetServiceRequest, opts ...gax.CallOption) (*servicemanagementpb.ManagedService, error) {
262 return c.internalClient.GetService(ctx, req, opts...)
263 }
264
265 // CreateService creates a new managed service.
266 //
267 // A managed service is immutable, and is subject to mandatory 30-day
268 // data retention. You cannot move a service or recreate it within 30 days
269 // after deletion.
270 //
271 // One producer project can own no more than 500 services. For security and
272 // reliability purposes, a production service should be hosted in a
273 // dedicated producer project.
274 //
275 // Operation<response: ManagedService>
276 func (c *ServiceManagerClient) CreateService(ctx context.Context, req *servicemanagementpb.CreateServiceRequest, opts ...gax.CallOption) (*CreateServiceOperation, error) {
277 return c.internalClient.CreateService(ctx, req, opts...)
278 }
279
280 // CreateServiceOperation returns a new CreateServiceOperation from a given name.
281 // The name must be that of a previously created CreateServiceOperation, possibly from a different process.
282 func (c *ServiceManagerClient) CreateServiceOperation(name string) *CreateServiceOperation {
283 return c.internalClient.CreateServiceOperation(name)
284 }
285
286 // DeleteService deletes a managed service. This method will change the service to the
287 // Soft-Delete state for 30 days. Within this period, service producers may
288 // call
289 // UndeleteService
290 // to restore the service. After 30 days, the service will be permanently
291 // deleted.
292 //
293 // Operation<response: google.protobuf.Empty>
294 func (c *ServiceManagerClient) DeleteService(ctx context.Context, req *servicemanagementpb.DeleteServiceRequest, opts ...gax.CallOption) (*DeleteServiceOperation, error) {
295 return c.internalClient.DeleteService(ctx, req, opts...)
296 }
297
298 // DeleteServiceOperation returns a new DeleteServiceOperation from a given name.
299 // The name must be that of a previously created DeleteServiceOperation, possibly from a different process.
300 func (c *ServiceManagerClient) DeleteServiceOperation(name string) *DeleteServiceOperation {
301 return c.internalClient.DeleteServiceOperation(name)
302 }
303
304 // UndeleteService revives a previously deleted managed service. The method restores the
305 // service using the configuration at the time the service was deleted.
306 // The target service must exist and must have been deleted within the
307 // last 30 days.
308 //
309 // Operation<response: UndeleteServiceResponse>
310 func (c *ServiceManagerClient) UndeleteService(ctx context.Context, req *servicemanagementpb.UndeleteServiceRequest, opts ...gax.CallOption) (*UndeleteServiceOperation, error) {
311 return c.internalClient.UndeleteService(ctx, req, opts...)
312 }
313
314 // UndeleteServiceOperation returns a new UndeleteServiceOperation from a given name.
315 // The name must be that of a previously created UndeleteServiceOperation, possibly from a different process.
316 func (c *ServiceManagerClient) UndeleteServiceOperation(name string) *UndeleteServiceOperation {
317 return c.internalClient.UndeleteServiceOperation(name)
318 }
319
320 // ListServiceConfigs lists the history of the service configuration for a managed service,
321 // from the newest to the oldest.
322 func (c *ServiceManagerClient) ListServiceConfigs(ctx context.Context, req *servicemanagementpb.ListServiceConfigsRequest, opts ...gax.CallOption) *ServiceIterator {
323 return c.internalClient.ListServiceConfigs(ctx, req, opts...)
324 }
325
326 // GetServiceConfig gets a service configuration (version) for a managed service.
327 func (c *ServiceManagerClient) GetServiceConfig(ctx context.Context, req *servicemanagementpb.GetServiceConfigRequest, opts ...gax.CallOption) (*serviceconfigpb.Service, error) {
328 return c.internalClient.GetServiceConfig(ctx, req, opts...)
329 }
330
331 // CreateServiceConfig creates a new service configuration (version) for a managed service.
332 // This method only stores the service configuration. To roll out the service
333 // configuration to backend systems please call
334 // CreateServiceRollout.
335 //
336 // Only the 100 most recent service configurations and ones referenced by
337 // existing rollouts are kept for each service. The rest will be deleted
338 // eventually.
339 func (c *ServiceManagerClient) CreateServiceConfig(ctx context.Context, req *servicemanagementpb.CreateServiceConfigRequest, opts ...gax.CallOption) (*serviceconfigpb.Service, error) {
340 return c.internalClient.CreateServiceConfig(ctx, req, opts...)
341 }
342
343 // SubmitConfigSource creates a new service configuration (version) for a managed service based
344 // on
345 // user-supplied configuration source files (for example: OpenAPI
346 // Specification). This method stores the source configurations as well as the
347 // generated service configuration. To rollout the service configuration to
348 // other services,
349 // please call
350 // CreateServiceRollout.
351 //
352 // Only the 100 most recent configuration sources and ones referenced by
353 // existing service configurtions are kept for each service. The rest will be
354 // deleted eventually.
355 //
356 // Operation<response: SubmitConfigSourceResponse>
357 func (c *ServiceManagerClient) SubmitConfigSource(ctx context.Context, req *servicemanagementpb.SubmitConfigSourceRequest, opts ...gax.CallOption) (*SubmitConfigSourceOperation, error) {
358 return c.internalClient.SubmitConfigSource(ctx, req, opts...)
359 }
360
361 // SubmitConfigSourceOperation returns a new SubmitConfigSourceOperation from a given name.
362 // The name must be that of a previously created SubmitConfigSourceOperation, possibly from a different process.
363 func (c *ServiceManagerClient) SubmitConfigSourceOperation(name string) *SubmitConfigSourceOperation {
364 return c.internalClient.SubmitConfigSourceOperation(name)
365 }
366
367 // ListServiceRollouts lists the history of the service configuration rollouts for a managed
368 // service, from the newest to the oldest.
369 func (c *ServiceManagerClient) ListServiceRollouts(ctx context.Context, req *servicemanagementpb.ListServiceRolloutsRequest, opts ...gax.CallOption) *RolloutIterator {
370 return c.internalClient.ListServiceRollouts(ctx, req, opts...)
371 }
372
373 // GetServiceRollout gets a service configuration
374 // rollout.
375 func (c *ServiceManagerClient) GetServiceRollout(ctx context.Context, req *servicemanagementpb.GetServiceRolloutRequest, opts ...gax.CallOption) (*servicemanagementpb.Rollout, error) {
376 return c.internalClient.GetServiceRollout(ctx, req, opts...)
377 }
378
379 // CreateServiceRollout creates a new service configuration rollout. Based on rollout, the
380 // Google Service Management will roll out the service configurations to
381 // different backend services. For example, the logging configuration will be
382 // pushed to Google Cloud Logging.
383 //
384 // Please note that any previous pending and running Rollouts and associated
385 // Operations will be automatically cancelled so that the latest Rollout will
386 // not be blocked by previous Rollouts.
387 //
388 // Only the 100 most recent (in any state) and the last 10 successful (if not
389 // already part of the set of 100 most recent) rollouts are kept for each
390 // service. The rest will be deleted eventually.
391 //
392 // Operation<response: Rollout>
393 func (c *ServiceManagerClient) CreateServiceRollout(ctx context.Context, req *servicemanagementpb.CreateServiceRolloutRequest, opts ...gax.CallOption) (*CreateServiceRolloutOperation, error) {
394 return c.internalClient.CreateServiceRollout(ctx, req, opts...)
395 }
396
397 // CreateServiceRolloutOperation returns a new CreateServiceRolloutOperation from a given name.
398 // The name must be that of a previously created CreateServiceRolloutOperation, possibly from a different process.
399 func (c *ServiceManagerClient) CreateServiceRolloutOperation(name string) *CreateServiceRolloutOperation {
400 return c.internalClient.CreateServiceRolloutOperation(name)
401 }
402
403 // GenerateConfigReport generates and returns a report (errors, warnings and changes from
404 // existing configurations) associated with
405 // GenerateConfigReportRequest.new_value
406 //
407 // If GenerateConfigReportRequest.old_value is specified,
408 // GenerateConfigReportRequest will contain a single ChangeReport based on the
409 // comparison between GenerateConfigReportRequest.new_value and
410 // GenerateConfigReportRequest.old_value.
411 // If GenerateConfigReportRequest.old_value is not specified, this method
412 // will compare GenerateConfigReportRequest.new_value with the last pushed
413 // service configuration.
414 func (c *ServiceManagerClient) GenerateConfigReport(ctx context.Context, req *servicemanagementpb.GenerateConfigReportRequest, opts ...gax.CallOption) (*servicemanagementpb.GenerateConfigReportResponse, error) {
415 return c.internalClient.GenerateConfigReport(ctx, req, opts...)
416 }
417
418 // GetIamPolicy gets the access control policy for a resource. Returns an empty policy
419 // if the resource exists and does not have a policy set.
420 func (c *ServiceManagerClient) GetIamPolicy(ctx context.Context, req *iampb.GetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) {
421 return c.internalClient.GetIamPolicy(ctx, req, opts...)
422 }
423
424 // SetIamPolicy sets the access control policy on the specified resource. Replaces
425 // any existing policy.
426 //
427 // Can return NOT_FOUND, INVALID_ARGUMENT, and PERMISSION_DENIED
428 // errors.
429 func (c *ServiceManagerClient) SetIamPolicy(ctx context.Context, req *iampb.SetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) {
430 return c.internalClient.SetIamPolicy(ctx, req, opts...)
431 }
432
433 // TestIamPermissions returns permissions that a caller has on the specified resource. If the
434 // resource does not exist, this will return an empty set of
435 // permissions, not a NOT_FOUND error.
436 //
437 // Note: This operation is designed to be used for building
438 // permission-aware UIs and command-line tools, not for authorization
439 // checking. This operation may “fail open” without warning.
440 func (c *ServiceManagerClient) TestIamPermissions(ctx context.Context, req *iampb.TestIamPermissionsRequest, opts ...gax.CallOption) (*iampb.TestIamPermissionsResponse, error) {
441 return c.internalClient.TestIamPermissions(ctx, req, opts...)
442 }
443
444 // ListOperations lists service operations that match the specified filter in the request.
445 func (c *ServiceManagerClient) ListOperations(ctx context.Context, req *longrunningpb.ListOperationsRequest, opts ...gax.CallOption) *OperationIterator {
446 return c.internalClient.ListOperations(ctx, req, opts...)
447 }
448
449 // serviceManagerGRPCClient is a client for interacting with Service Management API over gRPC transport.
450 //
451 // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
452 type serviceManagerGRPCClient struct {
453 // Connection pool of gRPC connections to the service.
454 connPool gtransport.ConnPool
455
456 // Points back to the CallOptions field of the containing ServiceManagerClient
457 CallOptions **ServiceManagerCallOptions
458
459 // The gRPC API client.
460 serviceManagerClient servicemanagementpb.ServiceManagerClient
461
462 // LROClient is used internally to handle long-running operations.
463 // It is exposed so that its CallOptions can be modified if required.
464 // Users should not Close this client.
465 LROClient **lroauto.OperationsClient
466
467 operationsClient longrunningpb.OperationsClient
468
469 iamPolicyClient iampb.IAMPolicyClient
470
471 // The x-goog-* metadata to be sent with each request.
472 xGoogHeaders []string
473
474 logger *slog.Logger
475 }
476
477 // NewServiceManagerClient creates a new service manager client based on gRPC.
478 // The returned client must be Closed when it is done being used to clean up its underlying connections.
479 //
480 // Google Service Management
481 // API (at https://cloud.google.com/service-infrastructure/docs/overview)
482 func NewServiceManagerClient(ctx context.Context, opts ...option.ClientOption) (*ServiceManagerClient, error) {
483 clientOpts := defaultServiceManagerGRPCClientOptions()
484 if newServiceManagerClientHook != nil {
485 hookOpts, err := newServiceManagerClientHook(ctx, clientHookParams{})
486 if err != nil {
487 return nil, err
488 }
489 clientOpts = append(clientOpts, hookOpts...)
490 }
491
492 connPool, err := gtransport.DialPool(ctx, append(clientOpts, opts...)...)
493 if err != nil {
494 return nil, err
495 }
496 client := ServiceManagerClient{CallOptions: defaultServiceManagerCallOptions()}
497
498 c := &serviceManagerGRPCClient{
499 connPool: connPool,
500 serviceManagerClient: servicemanagementpb.NewServiceManagerClient(connPool),
501 CallOptions: &client.CallOptions,
502 logger: internaloption.GetLogger(opts),
503 operationsClient: longrunningpb.NewOperationsClient(connPool),
504 iamPolicyClient: iampb.NewIAMPolicyClient(connPool),
505 }
506 c.setGoogleClientInfo()
507
508 client.internalClient = c
509
510 client.LROClient, err = lroauto.NewOperationsClient(ctx, gtransport.WithConnPool(connPool))
511 if err != nil {
512 // This error "should not happen", since we are just reusing old connection pool
513 // and never actually need to dial.
514 // If this does happen, we could leak connp. However, we cannot close conn:
515 // If the user invoked the constructor with option.WithGRPCConn,
516 // we would close a connection that's still in use.
517 // TODO: investigate error conditions.
518 return nil, err
519 }
520 c.LROClient = &client.LROClient
521 return &client, nil
522 }
523
524 // Connection returns a connection to the API service.
525 //
526 // Deprecated: Connections are now pooled so this method does not always
527 // return the same resource.
528 func (c *serviceManagerGRPCClient) Connection() *grpc.ClientConn {
529 return c.connPool.Conn()
530 }
531
532 // setGoogleClientInfo sets the name and version of the application in
533 // the `x-goog-api-client` header passed on each request. Intended for
534 // use by Google-written clients.
535 func (c *serviceManagerGRPCClient) setGoogleClientInfo(keyval ...string) {
536 kv := append([]string{"gl-go", gax.GoVersion}, keyval...)
537 kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "grpc", grpc.Version, "pb", protoVersion)
538 c.xGoogHeaders = []string{
539 "x-goog-api-client", gax.XGoogHeader(kv...),
540 }
541 }
542
543 // Close closes the connection to the API service. The user should invoke this when
544 // the client is no longer required.
545 func (c *serviceManagerGRPCClient) Close() error {
546 return c.connPool.Close()
547 }
548
549 // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
550 type serviceManagerRESTClient struct {
551 // The http endpoint to connect to.
552 endpoint string
553
554 // The http client.
555 httpClient *http.Client
556
557 // LROClient is used internally to handle long-running operations.
558 // It is exposed so that its CallOptions can be modified if required.
559 // Users should not Close this client.
560 LROClient **lroauto.OperationsClient
561
562 // The x-goog-* headers to be sent with each request.
563 xGoogHeaders []string
564
565 // Points back to the CallOptions field of the containing ServiceManagerClient
566 CallOptions **ServiceManagerCallOptions
567
568 logger *slog.Logger
569 }
570
571 // NewServiceManagerRESTClient creates a new service manager rest client.
572 //
573 // Google Service Management
574 // API (at https://cloud.google.com/service-infrastructure/docs/overview)
575 func NewServiceManagerRESTClient(ctx context.Context, opts ...option.ClientOption) (*ServiceManagerClient, error) {
576 clientOpts := append(defaultServiceManagerRESTClientOptions(), opts...)
577 httpClient, endpoint, err := httptransport.NewClient(ctx, clientOpts...)
578 if err != nil {
579 return nil, err
580 }
581
582 callOpts := defaultServiceManagerRESTCallOptions()
583 c := &serviceManagerRESTClient{
584 endpoint: endpoint,
585 httpClient: httpClient,
586 CallOptions: &callOpts,
587 logger: internaloption.GetLogger(opts),
588 }
589 c.setGoogleClientInfo()
590
591 lroOpts := []option.ClientOption{
592 option.WithHTTPClient(httpClient),
593 option.WithEndpoint(endpoint),
594 }
595 opClient, err := lroauto.NewOperationsRESTClient(ctx, lroOpts...)
596 if err != nil {
597 return nil, err
598 }
599 c.LROClient = &opClient
600
601 return &ServiceManagerClient{internalClient: c, CallOptions: callOpts}, nil
602 }
603
604 func defaultServiceManagerRESTClientOptions() []option.ClientOption {
605 return []option.ClientOption{
606 internaloption.WithDefaultEndpoint("https://servicemanagement.googleapis.com"),
607 internaloption.WithDefaultEndpointTemplate("https://servicemanagement.UNIVERSE_DOMAIN"),
608 internaloption.WithDefaultMTLSEndpoint("https://servicemanagement.mtls.googleapis.com"),
609 internaloption.WithDefaultUniverseDomain("googleapis.com"),
610 internaloption.WithDefaultAudience("https://servicemanagement.googleapis.com/"),
611 internaloption.WithDefaultScopes(DefaultAuthScopes()...),
612 internaloption.EnableNewAuthLibrary(),
613 }
614 }
615
616 // setGoogleClientInfo sets the name and version of the application in
617 // the `x-goog-api-client` header passed on each request. Intended for
618 // use by Google-written clients.
619 func (c *serviceManagerRESTClient) setGoogleClientInfo(keyval ...string) {
620 kv := append([]string{"gl-go", gax.GoVersion}, keyval...)
621 kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "rest", "UNKNOWN", "pb", protoVersion)
622 c.xGoogHeaders = []string{
623 "x-goog-api-client", gax.XGoogHeader(kv...),
624 }
625 }
626
627 // Close closes the connection to the API service. The user should invoke this when
628 // the client is no longer required.
629 func (c *serviceManagerRESTClient) Close() error {
630 // Replace httpClient with nil to force cleanup.
631 c.httpClient = nil
632 return nil
633 }
634
635 // Connection returns a connection to the API service.
636 //
637 // Deprecated: This method always returns nil.
638 func (c *serviceManagerRESTClient) Connection() *grpc.ClientConn {
639 return nil
640 }
641 func (c *serviceManagerGRPCClient) ListServices(ctx context.Context, req *servicemanagementpb.ListServicesRequest, opts ...gax.CallOption) *ManagedServiceIterator {
642 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, c.xGoogHeaders...)
643 opts = append((*c.CallOptions).ListServices[0:len((*c.CallOptions).ListServices):len((*c.CallOptions).ListServices)], opts...)
644 it := &ManagedServiceIterator{}
645 req = proto.Clone(req).(*servicemanagementpb.ListServicesRequest)
646 it.InternalFetch = func(pageSize int, pageToken string) ([]*servicemanagementpb.ManagedService, string, error) {
647 resp := &servicemanagementpb.ListServicesResponse{}
648 if pageToken != "" {
649 req.PageToken = pageToken
650 }
651 if pageSize > math.MaxInt32 {
652 req.PageSize = math.MaxInt32
653 } else if pageSize != 0 {
654 req.PageSize = int32(pageSize)
655 }
656 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
657 var err error
658 resp, err = executeRPC(ctx, c.serviceManagerClient.ListServices, req, settings.GRPC, c.logger, "ListServices")
659 return err
660 }, opts...)
661 if err != nil {
662 return nil, "", err
663 }
664
665 it.Response = resp
666 return resp.GetServices(), resp.GetNextPageToken(), nil
667 }
668 fetch := func(pageSize int, pageToken string) (string, error) {
669 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
670 if err != nil {
671 return "", err
672 }
673 it.items = append(it.items, items...)
674 return nextPageToken, nil
675 }
676
677 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
678 it.pageInfo.MaxSize = int(req.GetPageSize())
679 it.pageInfo.Token = req.GetPageToken()
680
681 return it
682 }
683
684 func (c *serviceManagerGRPCClient) GetService(ctx context.Context, req *servicemanagementpb.GetServiceRequest, opts ...gax.CallOption) (*servicemanagementpb.ManagedService, error) {
685 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "service_name", url.QueryEscape(req.GetServiceName()))}
686
687 hds = append(c.xGoogHeaders, hds...)
688 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
689 opts = append((*c.CallOptions).GetService[0:len((*c.CallOptions).GetService):len((*c.CallOptions).GetService)], opts...)
690 var resp *servicemanagementpb.ManagedService
691 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
692 var err error
693 resp, err = executeRPC(ctx, c.serviceManagerClient.GetService, req, settings.GRPC, c.logger, "GetService")
694 return err
695 }, opts...)
696 if err != nil {
697 return nil, err
698 }
699 return resp, nil
700 }
701
702 func (c *serviceManagerGRPCClient) CreateService(ctx context.Context, req *servicemanagementpb.CreateServiceRequest, opts ...gax.CallOption) (*CreateServiceOperation, error) {
703 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, c.xGoogHeaders...)
704 opts = append((*c.CallOptions).CreateService[0:len((*c.CallOptions).CreateService):len((*c.CallOptions).CreateService)], opts...)
705 var resp *longrunningpb.Operation
706 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
707 var err error
708 resp, err = executeRPC(ctx, c.serviceManagerClient.CreateService, req, settings.GRPC, c.logger, "CreateService")
709 return err
710 }, opts...)
711 if err != nil {
712 return nil, err
713 }
714 return &CreateServiceOperation{
715 lro: longrunning.InternalNewOperation(*c.LROClient, resp),
716 }, nil
717 }
718
719 func (c *serviceManagerGRPCClient) DeleteService(ctx context.Context, req *servicemanagementpb.DeleteServiceRequest, opts ...gax.CallOption) (*DeleteServiceOperation, error) {
720 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "service_name", url.QueryEscape(req.GetServiceName()))}
721
722 hds = append(c.xGoogHeaders, hds...)
723 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
724 opts = append((*c.CallOptions).DeleteService[0:len((*c.CallOptions).DeleteService):len((*c.CallOptions).DeleteService)], opts...)
725 var resp *longrunningpb.Operation
726 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
727 var err error
728 resp, err = executeRPC(ctx, c.serviceManagerClient.DeleteService, req, settings.GRPC, c.logger, "DeleteService")
729 return err
730 }, opts...)
731 if err != nil {
732 return nil, err
733 }
734 return &DeleteServiceOperation{
735 lro: longrunning.InternalNewOperation(*c.LROClient, resp),
736 }, nil
737 }
738
739 func (c *serviceManagerGRPCClient) UndeleteService(ctx context.Context, req *servicemanagementpb.UndeleteServiceRequest, opts ...gax.CallOption) (*UndeleteServiceOperation, error) {
740 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "service_name", url.QueryEscape(req.GetServiceName()))}
741
742 hds = append(c.xGoogHeaders, hds...)
743 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
744 opts = append((*c.CallOptions).UndeleteService[0:len((*c.CallOptions).UndeleteService):len((*c.CallOptions).UndeleteService)], opts...)
745 var resp *longrunningpb.Operation
746 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
747 var err error
748 resp, err = executeRPC(ctx, c.serviceManagerClient.UndeleteService, req, settings.GRPC, c.logger, "UndeleteService")
749 return err
750 }, opts...)
751 if err != nil {
752 return nil, err
753 }
754 return &UndeleteServiceOperation{
755 lro: longrunning.InternalNewOperation(*c.LROClient, resp),
756 }, nil
757 }
758
759 func (c *serviceManagerGRPCClient) ListServiceConfigs(ctx context.Context, req *servicemanagementpb.ListServiceConfigsRequest, opts ...gax.CallOption) *ServiceIterator {
760 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "service_name", url.QueryEscape(req.GetServiceName()))}
761
762 hds = append(c.xGoogHeaders, hds...)
763 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
764 opts = append((*c.CallOptions).ListServiceConfigs[0:len((*c.CallOptions).ListServiceConfigs):len((*c.CallOptions).ListServiceConfigs)], opts...)
765 it := &ServiceIterator{}
766 req = proto.Clone(req).(*servicemanagementpb.ListServiceConfigsRequest)
767 it.InternalFetch = func(pageSize int, pageToken string) ([]*serviceconfigpb.Service, string, error) {
768 resp := &servicemanagementpb.ListServiceConfigsResponse{}
769 if pageToken != "" {
770 req.PageToken = pageToken
771 }
772 if pageSize > math.MaxInt32 {
773 req.PageSize = math.MaxInt32
774 } else if pageSize != 0 {
775 req.PageSize = int32(pageSize)
776 }
777 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
778 var err error
779 resp, err = executeRPC(ctx, c.serviceManagerClient.ListServiceConfigs, req, settings.GRPC, c.logger, "ListServiceConfigs")
780 return err
781 }, opts...)
782 if err != nil {
783 return nil, "", err
784 }
785
786 it.Response = resp
787 return resp.GetServiceConfigs(), resp.GetNextPageToken(), nil
788 }
789 fetch := func(pageSize int, pageToken string) (string, error) {
790 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
791 if err != nil {
792 return "", err
793 }
794 it.items = append(it.items, items...)
795 return nextPageToken, nil
796 }
797
798 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
799 it.pageInfo.MaxSize = int(req.GetPageSize())
800 it.pageInfo.Token = req.GetPageToken()
801
802 return it
803 }
804
805 func (c *serviceManagerGRPCClient) GetServiceConfig(ctx context.Context, req *servicemanagementpb.GetServiceConfigRequest, opts ...gax.CallOption) (*serviceconfigpb.Service, error) {
806 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v&%s=%v", "service_name", url.QueryEscape(req.GetServiceName()), "config_id", url.QueryEscape(req.GetConfigId()))}
807
808 hds = append(c.xGoogHeaders, hds...)
809 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
810 opts = append((*c.CallOptions).GetServiceConfig[0:len((*c.CallOptions).GetServiceConfig):len((*c.CallOptions).GetServiceConfig)], opts...)
811 var resp *serviceconfigpb.Service
812 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
813 var err error
814 resp, err = executeRPC(ctx, c.serviceManagerClient.GetServiceConfig, req, settings.GRPC, c.logger, "GetServiceConfig")
815 return err
816 }, opts...)
817 if err != nil {
818 return nil, err
819 }
820 return resp, nil
821 }
822
823 func (c *serviceManagerGRPCClient) CreateServiceConfig(ctx context.Context, req *servicemanagementpb.CreateServiceConfigRequest, opts ...gax.CallOption) (*serviceconfigpb.Service, error) {
824 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "service_name", url.QueryEscape(req.GetServiceName()))}
825
826 hds = append(c.xGoogHeaders, hds...)
827 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
828 opts = append((*c.CallOptions).CreateServiceConfig[0:len((*c.CallOptions).CreateServiceConfig):len((*c.CallOptions).CreateServiceConfig)], opts...)
829 var resp *serviceconfigpb.Service
830 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
831 var err error
832 resp, err = executeRPC(ctx, c.serviceManagerClient.CreateServiceConfig, req, settings.GRPC, c.logger, "CreateServiceConfig")
833 return err
834 }, opts...)
835 if err != nil {
836 return nil, err
837 }
838 return resp, nil
839 }
840
841 func (c *serviceManagerGRPCClient) SubmitConfigSource(ctx context.Context, req *servicemanagementpb.SubmitConfigSourceRequest, opts ...gax.CallOption) (*SubmitConfigSourceOperation, error) {
842 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "service_name", url.QueryEscape(req.GetServiceName()))}
843
844 hds = append(c.xGoogHeaders, hds...)
845 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
846 opts = append((*c.CallOptions).SubmitConfigSource[0:len((*c.CallOptions).SubmitConfigSource):len((*c.CallOptions).SubmitConfigSource)], opts...)
847 var resp *longrunningpb.Operation
848 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
849 var err error
850 resp, err = executeRPC(ctx, c.serviceManagerClient.SubmitConfigSource, req, settings.GRPC, c.logger, "SubmitConfigSource")
851 return err
852 }, opts...)
853 if err != nil {
854 return nil, err
855 }
856 return &SubmitConfigSourceOperation{
857 lro: longrunning.InternalNewOperation(*c.LROClient, resp),
858 }, nil
859 }
860
861 func (c *serviceManagerGRPCClient) ListServiceRollouts(ctx context.Context, req *servicemanagementpb.ListServiceRolloutsRequest, opts ...gax.CallOption) *RolloutIterator {
862 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "service_name", url.QueryEscape(req.GetServiceName()))}
863
864 hds = append(c.xGoogHeaders, hds...)
865 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
866 opts = append((*c.CallOptions).ListServiceRollouts[0:len((*c.CallOptions).ListServiceRollouts):len((*c.CallOptions).ListServiceRollouts)], opts...)
867 it := &RolloutIterator{}
868 req = proto.Clone(req).(*servicemanagementpb.ListServiceRolloutsRequest)
869 it.InternalFetch = func(pageSize int, pageToken string) ([]*servicemanagementpb.Rollout, string, error) {
870 resp := &servicemanagementpb.ListServiceRolloutsResponse{}
871 if pageToken != "" {
872 req.PageToken = pageToken
873 }
874 if pageSize > math.MaxInt32 {
875 req.PageSize = math.MaxInt32
876 } else if pageSize != 0 {
877 req.PageSize = int32(pageSize)
878 }
879 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
880 var err error
881 resp, err = executeRPC(ctx, c.serviceManagerClient.ListServiceRollouts, req, settings.GRPC, c.logger, "ListServiceRollouts")
882 return err
883 }, opts...)
884 if err != nil {
885 return nil, "", err
886 }
887
888 it.Response = resp
889 return resp.GetRollouts(), resp.GetNextPageToken(), nil
890 }
891 fetch := func(pageSize int, pageToken string) (string, error) {
892 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
893 if err != nil {
894 return "", err
895 }
896 it.items = append(it.items, items...)
897 return nextPageToken, nil
898 }
899
900 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
901 it.pageInfo.MaxSize = int(req.GetPageSize())
902 it.pageInfo.Token = req.GetPageToken()
903
904 return it
905 }
906
907 func (c *serviceManagerGRPCClient) GetServiceRollout(ctx context.Context, req *servicemanagementpb.GetServiceRolloutRequest, opts ...gax.CallOption) (*servicemanagementpb.Rollout, error) {
908 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v&%s=%v", "service_name", url.QueryEscape(req.GetServiceName()), "rollout_id", url.QueryEscape(req.GetRolloutId()))}
909
910 hds = append(c.xGoogHeaders, hds...)
911 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
912 opts = append((*c.CallOptions).GetServiceRollout[0:len((*c.CallOptions).GetServiceRollout):len((*c.CallOptions).GetServiceRollout)], opts...)
913 var resp *servicemanagementpb.Rollout
914 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
915 var err error
916 resp, err = executeRPC(ctx, c.serviceManagerClient.GetServiceRollout, req, settings.GRPC, c.logger, "GetServiceRollout")
917 return err
918 }, opts...)
919 if err != nil {
920 return nil, err
921 }
922 return resp, nil
923 }
924
925 func (c *serviceManagerGRPCClient) CreateServiceRollout(ctx context.Context, req *servicemanagementpb.CreateServiceRolloutRequest, opts ...gax.CallOption) (*CreateServiceRolloutOperation, error) {
926 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "service_name", url.QueryEscape(req.GetServiceName()))}
927
928 hds = append(c.xGoogHeaders, hds...)
929 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
930 opts = append((*c.CallOptions).CreateServiceRollout[0:len((*c.CallOptions).CreateServiceRollout):len((*c.CallOptions).CreateServiceRollout)], opts...)
931 var resp *longrunningpb.Operation
932 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
933 var err error
934 resp, err = executeRPC(ctx, c.serviceManagerClient.CreateServiceRollout, req, settings.GRPC, c.logger, "CreateServiceRollout")
935 return err
936 }, opts...)
937 if err != nil {
938 return nil, err
939 }
940 return &CreateServiceRolloutOperation{
941 lro: longrunning.InternalNewOperation(*c.LROClient, resp),
942 }, nil
943 }
944
945 func (c *serviceManagerGRPCClient) GenerateConfigReport(ctx context.Context, req *servicemanagementpb.GenerateConfigReportRequest, opts ...gax.CallOption) (*servicemanagementpb.GenerateConfigReportResponse, error) {
946 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, c.xGoogHeaders...)
947 opts = append((*c.CallOptions).GenerateConfigReport[0:len((*c.CallOptions).GenerateConfigReport):len((*c.CallOptions).GenerateConfigReport)], opts...)
948 var resp *servicemanagementpb.GenerateConfigReportResponse
949 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
950 var err error
951 resp, err = executeRPC(ctx, c.serviceManagerClient.GenerateConfigReport, req, settings.GRPC, c.logger, "GenerateConfigReport")
952 return err
953 }, opts...)
954 if err != nil {
955 return nil, err
956 }
957 return resp, nil
958 }
959
960 func (c *serviceManagerGRPCClient) GetIamPolicy(ctx context.Context, req *iampb.GetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) {
961 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))}
962
963 hds = append(c.xGoogHeaders, hds...)
964 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
965 opts = append((*c.CallOptions).GetIamPolicy[0:len((*c.CallOptions).GetIamPolicy):len((*c.CallOptions).GetIamPolicy)], opts...)
966 var resp *iampb.Policy
967 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
968 var err error
969 resp, err = executeRPC(ctx, c.iamPolicyClient.GetIamPolicy, req, settings.GRPC, c.logger, "GetIamPolicy")
970 return err
971 }, opts...)
972 if err != nil {
973 return nil, err
974 }
975 return resp, nil
976 }
977
978 func (c *serviceManagerGRPCClient) SetIamPolicy(ctx context.Context, req *iampb.SetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) {
979 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))}
980
981 hds = append(c.xGoogHeaders, hds...)
982 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
983 opts = append((*c.CallOptions).SetIamPolicy[0:len((*c.CallOptions).SetIamPolicy):len((*c.CallOptions).SetIamPolicy)], opts...)
984 var resp *iampb.Policy
985 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
986 var err error
987 resp, err = executeRPC(ctx, c.iamPolicyClient.SetIamPolicy, req, settings.GRPC, c.logger, "SetIamPolicy")
988 return err
989 }, opts...)
990 if err != nil {
991 return nil, err
992 }
993 return resp, nil
994 }
995
996 func (c *serviceManagerGRPCClient) TestIamPermissions(ctx context.Context, req *iampb.TestIamPermissionsRequest, opts ...gax.CallOption) (*iampb.TestIamPermissionsResponse, error) {
997 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))}
998
999 hds = append(c.xGoogHeaders, hds...)
1000 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
1001 opts = append((*c.CallOptions).TestIamPermissions[0:len((*c.CallOptions).TestIamPermissions):len((*c.CallOptions).TestIamPermissions)], opts...)
1002 var resp *iampb.TestIamPermissionsResponse
1003 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1004 var err error
1005 resp, err = executeRPC(ctx, c.iamPolicyClient.TestIamPermissions, req, settings.GRPC, c.logger, "TestIamPermissions")
1006 return err
1007 }, opts...)
1008 if err != nil {
1009 return nil, err
1010 }
1011 return resp, nil
1012 }
1013
1014 func (c *serviceManagerGRPCClient) ListOperations(ctx context.Context, req *longrunningpb.ListOperationsRequest, opts ...gax.CallOption) *OperationIterator {
1015 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, c.xGoogHeaders...)
1016 opts = append((*c.CallOptions).ListOperations[0:len((*c.CallOptions).ListOperations):len((*c.CallOptions).ListOperations)], opts...)
1017 it := &OperationIterator{}
1018 req = proto.Clone(req).(*longrunningpb.ListOperationsRequest)
1019 it.InternalFetch = func(pageSize int, pageToken string) ([]*longrunningpb.Operation, string, error) {
1020 resp := &longrunningpb.ListOperationsResponse{}
1021 if pageToken != "" {
1022 req.PageToken = pageToken
1023 }
1024 if pageSize > math.MaxInt32 {
1025 req.PageSize = math.MaxInt32
1026 } else if pageSize != 0 {
1027 req.PageSize = int32(pageSize)
1028 }
1029 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1030 var err error
1031 resp, err = executeRPC(ctx, c.operationsClient.ListOperations, req, settings.GRPC, c.logger, "ListOperations")
1032 return err
1033 }, opts...)
1034 if err != nil {
1035 return nil, "", err
1036 }
1037
1038 it.Response = resp
1039 return resp.GetOperations(), resp.GetNextPageToken(), nil
1040 }
1041 fetch := func(pageSize int, pageToken string) (string, error) {
1042 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
1043 if err != nil {
1044 return "", err
1045 }
1046 it.items = append(it.items, items...)
1047 return nextPageToken, nil
1048 }
1049
1050 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
1051 it.pageInfo.MaxSize = int(req.GetPageSize())
1052 it.pageInfo.Token = req.GetPageToken()
1053
1054 return it
1055 }
1056
1057 // ListServices lists managed services.
1058 //
1059 // Returns all public services. For authenticated users, also returns all
1060 // services the calling user has “servicemanagement.services.get” permission
1061 // for.
1062 func (c *serviceManagerRESTClient) ListServices(ctx context.Context, req *servicemanagementpb.ListServicesRequest, opts ...gax.CallOption) *ManagedServiceIterator {
1063 it := &ManagedServiceIterator{}
1064 req = proto.Clone(req).(*servicemanagementpb.ListServicesRequest)
1065 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
1066 it.InternalFetch = func(pageSize int, pageToken string) ([]*servicemanagementpb.ManagedService, string, error) {
1067 resp := &servicemanagementpb.ListServicesResponse{}
1068 if pageToken != "" {
1069 req.PageToken = pageToken
1070 }
1071 if pageSize > math.MaxInt32 {
1072 req.PageSize = math.MaxInt32
1073 } else if pageSize != 0 {
1074 req.PageSize = int32(pageSize)
1075 }
1076 baseUrl, err := url.Parse(c.endpoint)
1077 if err != nil {
1078 return nil, "", err
1079 }
1080 baseUrl.Path += fmt.Sprintf("/v1/services")
1081
1082 params := url.Values{}
1083 params.Add("$alt", "json;enum-encoding=int")
1084 if req.GetConsumerId() != "" {
1085 params.Add("consumerId", fmt.Sprintf("%v", req.GetConsumerId()))
1086 }
1087 if req.GetPageSize() != 0 {
1088 params.Add("pageSize", fmt.Sprintf("%v", req.GetPageSize()))
1089 }
1090 if req.GetPageToken() != "" {
1091 params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken()))
1092 }
1093 if req.GetProducerProjectId() != "" {
1094 params.Add("producerProjectId", fmt.Sprintf("%v", req.GetProducerProjectId()))
1095 }
1096
1097 baseUrl.RawQuery = params.Encode()
1098
1099 // Build HTTP headers from client and context metadata.
1100 hds := append(c.xGoogHeaders, "Content-Type", "application/json")
1101 headers := gax.BuildHeaders(ctx, hds...)
1102 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1103 if settings.Path != "" {
1104 baseUrl.Path = settings.Path
1105 }
1106 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
1107 if err != nil {
1108 return err
1109 }
1110 httpReq.Header = headers
1111
1112 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "ListServices")
1113 if err != nil {
1114 return err
1115 }
1116 if err := unm.Unmarshal(buf, resp); err != nil {
1117 return err
1118 }
1119
1120 return nil
1121 }, opts...)
1122 if e != nil {
1123 return nil, "", e
1124 }
1125 it.Response = resp
1126 return resp.GetServices(), resp.GetNextPageToken(), nil
1127 }
1128
1129 fetch := func(pageSize int, pageToken string) (string, error) {
1130 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
1131 if err != nil {
1132 return "", err
1133 }
1134 it.items = append(it.items, items...)
1135 return nextPageToken, nil
1136 }
1137
1138 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
1139 it.pageInfo.MaxSize = int(req.GetPageSize())
1140 it.pageInfo.Token = req.GetPageToken()
1141
1142 return it
1143 }
1144
1145 // GetService gets a managed service. Authentication is required unless the service is
1146 // public.
1147 func (c *serviceManagerRESTClient) GetService(ctx context.Context, req *servicemanagementpb.GetServiceRequest, opts ...gax.CallOption) (*servicemanagementpb.ManagedService, error) {
1148 baseUrl, err := url.Parse(c.endpoint)
1149 if err != nil {
1150 return nil, err
1151 }
1152 baseUrl.Path += fmt.Sprintf("/v1/services/%v", req.GetServiceName())
1153
1154 params := url.Values{}
1155 params.Add("$alt", "json;enum-encoding=int")
1156
1157 baseUrl.RawQuery = params.Encode()
1158
1159 // Build HTTP headers from client and context metadata.
1160 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "service_name", url.QueryEscape(req.GetServiceName()))}
1161
1162 hds = append(c.xGoogHeaders, hds...)
1163 hds = append(hds, "Content-Type", "application/json")
1164 headers := gax.BuildHeaders(ctx, hds...)
1165 opts = append((*c.CallOptions).GetService[0:len((*c.CallOptions).GetService):len((*c.CallOptions).GetService)], opts...)
1166 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
1167 resp := &servicemanagementpb.ManagedService{}
1168 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1169 if settings.Path != "" {
1170 baseUrl.Path = settings.Path
1171 }
1172 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
1173 if err != nil {
1174 return err
1175 }
1176 httpReq = httpReq.WithContext(ctx)
1177 httpReq.Header = headers
1178
1179 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "GetService")
1180 if err != nil {
1181 return err
1182 }
1183
1184 if err := unm.Unmarshal(buf, resp); err != nil {
1185 return err
1186 }
1187
1188 return nil
1189 }, opts...)
1190 if e != nil {
1191 return nil, e
1192 }
1193 return resp, nil
1194 }
1195
1196 // CreateService creates a new managed service.
1197 //
1198 // A managed service is immutable, and is subject to mandatory 30-day
1199 // data retention. You cannot move a service or recreate it within 30 days
1200 // after deletion.
1201 //
1202 // One producer project can own no more than 500 services. For security and
1203 // reliability purposes, a production service should be hosted in a
1204 // dedicated producer project.
1205 //
1206 // Operation<response: ManagedService>
1207 func (c *serviceManagerRESTClient) CreateService(ctx context.Context, req *servicemanagementpb.CreateServiceRequest, opts ...gax.CallOption) (*CreateServiceOperation, error) {
1208 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
1209 body := req.GetService()
1210 jsonReq, err := m.Marshal(body)
1211 if err != nil {
1212 return nil, err
1213 }
1214
1215 baseUrl, err := url.Parse(c.endpoint)
1216 if err != nil {
1217 return nil, err
1218 }
1219 baseUrl.Path += fmt.Sprintf("/v1/services")
1220
1221 params := url.Values{}
1222 params.Add("$alt", "json;enum-encoding=int")
1223
1224 baseUrl.RawQuery = params.Encode()
1225
1226 // Build HTTP headers from client and context metadata.
1227 hds := append(c.xGoogHeaders, "Content-Type", "application/json")
1228 headers := gax.BuildHeaders(ctx, hds...)
1229 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
1230 resp := &longrunningpb.Operation{}
1231 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1232 if settings.Path != "" {
1233 baseUrl.Path = settings.Path
1234 }
1235 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
1236 if err != nil {
1237 return err
1238 }
1239 httpReq = httpReq.WithContext(ctx)
1240 httpReq.Header = headers
1241
1242 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "CreateService")
1243 if err != nil {
1244 return err
1245 }
1246 if err := unm.Unmarshal(buf, resp); err != nil {
1247 return err
1248 }
1249
1250 return nil
1251 }, opts...)
1252 if e != nil {
1253 return nil, e
1254 }
1255
1256 override := fmt.Sprintf("/v1/%s", resp.GetName())
1257 return &CreateServiceOperation{
1258 lro: longrunning.InternalNewOperation(*c.LROClient, resp),
1259 pollPath: override,
1260 }, nil
1261 }
1262
1263 // DeleteService deletes a managed service. This method will change the service to the
1264 // Soft-Delete state for 30 days. Within this period, service producers may
1265 // call
1266 // UndeleteService
1267 // to restore the service. After 30 days, the service will be permanently
1268 // deleted.
1269 //
1270 // Operation<response: google.protobuf.Empty>
1271 func (c *serviceManagerRESTClient) DeleteService(ctx context.Context, req *servicemanagementpb.DeleteServiceRequest, opts ...gax.CallOption) (*DeleteServiceOperation, error) {
1272 baseUrl, err := url.Parse(c.endpoint)
1273 if err != nil {
1274 return nil, err
1275 }
1276 baseUrl.Path += fmt.Sprintf("/v1/services/%v", req.GetServiceName())
1277
1278 params := url.Values{}
1279 params.Add("$alt", "json;enum-encoding=int")
1280
1281 baseUrl.RawQuery = params.Encode()
1282
1283 // Build HTTP headers from client and context metadata.
1284 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "service_name", url.QueryEscape(req.GetServiceName()))}
1285
1286 hds = append(c.xGoogHeaders, hds...)
1287 hds = append(hds, "Content-Type", "application/json")
1288 headers := gax.BuildHeaders(ctx, hds...)
1289 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
1290 resp := &longrunningpb.Operation{}
1291 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1292 if settings.Path != "" {
1293 baseUrl.Path = settings.Path
1294 }
1295 httpReq, err := http.NewRequest("DELETE", baseUrl.String(), nil)
1296 if err != nil {
1297 return err
1298 }
1299 httpReq = httpReq.WithContext(ctx)
1300 httpReq.Header = headers
1301
1302 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "DeleteService")
1303 if err != nil {
1304 return err
1305 }
1306 if err := unm.Unmarshal(buf, resp); err != nil {
1307 return err
1308 }
1309
1310 return nil
1311 }, opts...)
1312 if e != nil {
1313 return nil, e
1314 }
1315
1316 override := fmt.Sprintf("/v1/%s", resp.GetName())
1317 return &DeleteServiceOperation{
1318 lro: longrunning.InternalNewOperation(*c.LROClient, resp),
1319 pollPath: override,
1320 }, nil
1321 }
1322
1323 // UndeleteService revives a previously deleted managed service. The method restores the
1324 // service using the configuration at the time the service was deleted.
1325 // The target service must exist and must have been deleted within the
1326 // last 30 days.
1327 //
1328 // Operation<response: UndeleteServiceResponse>
1329 func (c *serviceManagerRESTClient) UndeleteService(ctx context.Context, req *servicemanagementpb.UndeleteServiceRequest, opts ...gax.CallOption) (*UndeleteServiceOperation, error) {
1330 baseUrl, err := url.Parse(c.endpoint)
1331 if err != nil {
1332 return nil, err
1333 }
1334 baseUrl.Path += fmt.Sprintf("/v1/services/%v:undelete", req.GetServiceName())
1335
1336 params := url.Values{}
1337 params.Add("$alt", "json;enum-encoding=int")
1338
1339 baseUrl.RawQuery = params.Encode()
1340
1341 // Build HTTP headers from client and context metadata.
1342 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "service_name", url.QueryEscape(req.GetServiceName()))}
1343
1344 hds = append(c.xGoogHeaders, hds...)
1345 hds = append(hds, "Content-Type", "application/json")
1346 headers := gax.BuildHeaders(ctx, hds...)
1347 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
1348 resp := &longrunningpb.Operation{}
1349 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1350 if settings.Path != "" {
1351 baseUrl.Path = settings.Path
1352 }
1353 httpReq, err := http.NewRequest("POST", baseUrl.String(), nil)
1354 if err != nil {
1355 return err
1356 }
1357 httpReq = httpReq.WithContext(ctx)
1358 httpReq.Header = headers
1359
1360 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "UndeleteService")
1361 if err != nil {
1362 return err
1363 }
1364 if err := unm.Unmarshal(buf, resp); err != nil {
1365 return err
1366 }
1367
1368 return nil
1369 }, opts...)
1370 if e != nil {
1371 return nil, e
1372 }
1373
1374 override := fmt.Sprintf("/v1/%s", resp.GetName())
1375 return &UndeleteServiceOperation{
1376 lro: longrunning.InternalNewOperation(*c.LROClient, resp),
1377 pollPath: override,
1378 }, nil
1379 }
1380
1381 // ListServiceConfigs lists the history of the service configuration for a managed service,
1382 // from the newest to the oldest.
1383 func (c *serviceManagerRESTClient) ListServiceConfigs(ctx context.Context, req *servicemanagementpb.ListServiceConfigsRequest, opts ...gax.CallOption) *ServiceIterator {
1384 it := &ServiceIterator{}
1385 req = proto.Clone(req).(*servicemanagementpb.ListServiceConfigsRequest)
1386 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
1387 it.InternalFetch = func(pageSize int, pageToken string) ([]*serviceconfigpb.Service, string, error) {
1388 resp := &servicemanagementpb.ListServiceConfigsResponse{}
1389 if pageToken != "" {
1390 req.PageToken = pageToken
1391 }
1392 if pageSize > math.MaxInt32 {
1393 req.PageSize = math.MaxInt32
1394 } else if pageSize != 0 {
1395 req.PageSize = int32(pageSize)
1396 }
1397 baseUrl, err := url.Parse(c.endpoint)
1398 if err != nil {
1399 return nil, "", err
1400 }
1401 baseUrl.Path += fmt.Sprintf("/v1/services/%v/configs", req.GetServiceName())
1402
1403 params := url.Values{}
1404 params.Add("$alt", "json;enum-encoding=int")
1405 if req.GetPageSize() != 0 {
1406 params.Add("pageSize", fmt.Sprintf("%v", req.GetPageSize()))
1407 }
1408 if req.GetPageToken() != "" {
1409 params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken()))
1410 }
1411
1412 baseUrl.RawQuery = params.Encode()
1413
1414 // Build HTTP headers from client and context metadata.
1415 hds := append(c.xGoogHeaders, "Content-Type", "application/json")
1416 headers := gax.BuildHeaders(ctx, hds...)
1417 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1418 if settings.Path != "" {
1419 baseUrl.Path = settings.Path
1420 }
1421 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
1422 if err != nil {
1423 return err
1424 }
1425 httpReq.Header = headers
1426
1427 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "ListServiceConfigs")
1428 if err != nil {
1429 return err
1430 }
1431 if err := unm.Unmarshal(buf, resp); err != nil {
1432 return err
1433 }
1434
1435 return nil
1436 }, opts...)
1437 if e != nil {
1438 return nil, "", e
1439 }
1440 it.Response = resp
1441 return resp.GetServiceConfigs(), resp.GetNextPageToken(), nil
1442 }
1443
1444 fetch := func(pageSize int, pageToken string) (string, error) {
1445 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
1446 if err != nil {
1447 return "", err
1448 }
1449 it.items = append(it.items, items...)
1450 return nextPageToken, nil
1451 }
1452
1453 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
1454 it.pageInfo.MaxSize = int(req.GetPageSize())
1455 it.pageInfo.Token = req.GetPageToken()
1456
1457 return it
1458 }
1459
1460 // GetServiceConfig gets a service configuration (version) for a managed service.
1461 func (c *serviceManagerRESTClient) GetServiceConfig(ctx context.Context, req *servicemanagementpb.GetServiceConfigRequest, opts ...gax.CallOption) (*serviceconfigpb.Service, error) {
1462 baseUrl, err := url.Parse(c.endpoint)
1463 if err != nil {
1464 return nil, err
1465 }
1466 baseUrl.Path += fmt.Sprintf("/v1/services/%v/configs/%v", req.GetServiceName(), req.GetConfigId())
1467
1468 params := url.Values{}
1469 params.Add("$alt", "json;enum-encoding=int")
1470 if req.GetView() != 0 {
1471 params.Add("view", fmt.Sprintf("%v", req.GetView()))
1472 }
1473
1474 baseUrl.RawQuery = params.Encode()
1475
1476 // Build HTTP headers from client and context metadata.
1477 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v&%s=%v", "service_name", url.QueryEscape(req.GetServiceName()), "config_id", url.QueryEscape(req.GetConfigId()))}
1478
1479 hds = append(c.xGoogHeaders, hds...)
1480 hds = append(hds, "Content-Type", "application/json")
1481 headers := gax.BuildHeaders(ctx, hds...)
1482 opts = append((*c.CallOptions).GetServiceConfig[0:len((*c.CallOptions).GetServiceConfig):len((*c.CallOptions).GetServiceConfig)], opts...)
1483 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
1484 resp := &serviceconfigpb.Service{}
1485 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1486 if settings.Path != "" {
1487 baseUrl.Path = settings.Path
1488 }
1489 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
1490 if err != nil {
1491 return err
1492 }
1493 httpReq = httpReq.WithContext(ctx)
1494 httpReq.Header = headers
1495
1496 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "GetServiceConfig")
1497 if err != nil {
1498 return err
1499 }
1500
1501 if err := unm.Unmarshal(buf, resp); err != nil {
1502 return err
1503 }
1504
1505 return nil
1506 }, opts...)
1507 if e != nil {
1508 return nil, e
1509 }
1510 return resp, nil
1511 }
1512
1513 // CreateServiceConfig creates a new service configuration (version) for a managed service.
1514 // This method only stores the service configuration. To roll out the service
1515 // configuration to backend systems please call
1516 // CreateServiceRollout.
1517 //
1518 // Only the 100 most recent service configurations and ones referenced by
1519 // existing rollouts are kept for each service. The rest will be deleted
1520 // eventually.
1521 func (c *serviceManagerRESTClient) CreateServiceConfig(ctx context.Context, req *servicemanagementpb.CreateServiceConfigRequest, opts ...gax.CallOption) (*serviceconfigpb.Service, error) {
1522 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
1523 body := req.GetServiceConfig()
1524 jsonReq, err := m.Marshal(body)
1525 if err != nil {
1526 return nil, err
1527 }
1528
1529 baseUrl, err := url.Parse(c.endpoint)
1530 if err != nil {
1531 return nil, err
1532 }
1533 baseUrl.Path += fmt.Sprintf("/v1/services/%v/configs", req.GetServiceName())
1534
1535 params := url.Values{}
1536 params.Add("$alt", "json;enum-encoding=int")
1537
1538 baseUrl.RawQuery = params.Encode()
1539
1540 // Build HTTP headers from client and context metadata.
1541 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "service_name", url.QueryEscape(req.GetServiceName()))}
1542
1543 hds = append(c.xGoogHeaders, hds...)
1544 hds = append(hds, "Content-Type", "application/json")
1545 headers := gax.BuildHeaders(ctx, hds...)
1546 opts = append((*c.CallOptions).CreateServiceConfig[0:len((*c.CallOptions).CreateServiceConfig):len((*c.CallOptions).CreateServiceConfig)], opts...)
1547 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
1548 resp := &serviceconfigpb.Service{}
1549 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1550 if settings.Path != "" {
1551 baseUrl.Path = settings.Path
1552 }
1553 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
1554 if err != nil {
1555 return err
1556 }
1557 httpReq = httpReq.WithContext(ctx)
1558 httpReq.Header = headers
1559
1560 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "CreateServiceConfig")
1561 if err != nil {
1562 return err
1563 }
1564
1565 if err := unm.Unmarshal(buf, resp); err != nil {
1566 return err
1567 }
1568
1569 return nil
1570 }, opts...)
1571 if e != nil {
1572 return nil, e
1573 }
1574 return resp, nil
1575 }
1576
1577 // SubmitConfigSource creates a new service configuration (version) for a managed service based
1578 // on
1579 // user-supplied configuration source files (for example: OpenAPI
1580 // Specification). This method stores the source configurations as well as the
1581 // generated service configuration. To rollout the service configuration to
1582 // other services,
1583 // please call
1584 // CreateServiceRollout.
1585 //
1586 // Only the 100 most recent configuration sources and ones referenced by
1587 // existing service configurtions are kept for each service. The rest will be
1588 // deleted eventually.
1589 //
1590 // Operation<response: SubmitConfigSourceResponse>
1591 func (c *serviceManagerRESTClient) SubmitConfigSource(ctx context.Context, req *servicemanagementpb.SubmitConfigSourceRequest, opts ...gax.CallOption) (*SubmitConfigSourceOperation, error) {
1592 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
1593 jsonReq, err := m.Marshal(req)
1594 if err != nil {
1595 return nil, err
1596 }
1597
1598 baseUrl, err := url.Parse(c.endpoint)
1599 if err != nil {
1600 return nil, err
1601 }
1602 baseUrl.Path += fmt.Sprintf("/v1/services/%v/configs:submit", req.GetServiceName())
1603
1604 params := url.Values{}
1605 params.Add("$alt", "json;enum-encoding=int")
1606
1607 baseUrl.RawQuery = params.Encode()
1608
1609 // Build HTTP headers from client and context metadata.
1610 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "service_name", url.QueryEscape(req.GetServiceName()))}
1611
1612 hds = append(c.xGoogHeaders, hds...)
1613 hds = append(hds, "Content-Type", "application/json")
1614 headers := gax.BuildHeaders(ctx, hds...)
1615 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
1616 resp := &longrunningpb.Operation{}
1617 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1618 if settings.Path != "" {
1619 baseUrl.Path = settings.Path
1620 }
1621 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
1622 if err != nil {
1623 return err
1624 }
1625 httpReq = httpReq.WithContext(ctx)
1626 httpReq.Header = headers
1627
1628 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "SubmitConfigSource")
1629 if err != nil {
1630 return err
1631 }
1632 if err := unm.Unmarshal(buf, resp); err != nil {
1633 return err
1634 }
1635
1636 return nil
1637 }, opts...)
1638 if e != nil {
1639 return nil, e
1640 }
1641
1642 override := fmt.Sprintf("/v1/%s", resp.GetName())
1643 return &SubmitConfigSourceOperation{
1644 lro: longrunning.InternalNewOperation(*c.LROClient, resp),
1645 pollPath: override,
1646 }, nil
1647 }
1648
1649 // ListServiceRollouts lists the history of the service configuration rollouts for a managed
1650 // service, from the newest to the oldest.
1651 func (c *serviceManagerRESTClient) ListServiceRollouts(ctx context.Context, req *servicemanagementpb.ListServiceRolloutsRequest, opts ...gax.CallOption) *RolloutIterator {
1652 it := &RolloutIterator{}
1653 req = proto.Clone(req).(*servicemanagementpb.ListServiceRolloutsRequest)
1654 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
1655 it.InternalFetch = func(pageSize int, pageToken string) ([]*servicemanagementpb.Rollout, string, error) {
1656 resp := &servicemanagementpb.ListServiceRolloutsResponse{}
1657 if pageToken != "" {
1658 req.PageToken = pageToken
1659 }
1660 if pageSize > math.MaxInt32 {
1661 req.PageSize = math.MaxInt32
1662 } else if pageSize != 0 {
1663 req.PageSize = int32(pageSize)
1664 }
1665 baseUrl, err := url.Parse(c.endpoint)
1666 if err != nil {
1667 return nil, "", err
1668 }
1669 baseUrl.Path += fmt.Sprintf("/v1/services/%v/rollouts", req.GetServiceName())
1670
1671 params := url.Values{}
1672 params.Add("$alt", "json;enum-encoding=int")
1673 params.Add("filter", fmt.Sprintf("%v", req.GetFilter()))
1674 if req.GetPageSize() != 0 {
1675 params.Add("pageSize", fmt.Sprintf("%v", req.GetPageSize()))
1676 }
1677 if req.GetPageToken() != "" {
1678 params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken()))
1679 }
1680
1681 baseUrl.RawQuery = params.Encode()
1682
1683 // Build HTTP headers from client and context metadata.
1684 hds := append(c.xGoogHeaders, "Content-Type", "application/json")
1685 headers := gax.BuildHeaders(ctx, hds...)
1686 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1687 if settings.Path != "" {
1688 baseUrl.Path = settings.Path
1689 }
1690 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
1691 if err != nil {
1692 return err
1693 }
1694 httpReq.Header = headers
1695
1696 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "ListServiceRollouts")
1697 if err != nil {
1698 return err
1699 }
1700 if err := unm.Unmarshal(buf, resp); err != nil {
1701 return err
1702 }
1703
1704 return nil
1705 }, opts...)
1706 if e != nil {
1707 return nil, "", e
1708 }
1709 it.Response = resp
1710 return resp.GetRollouts(), resp.GetNextPageToken(), nil
1711 }
1712
1713 fetch := func(pageSize int, pageToken string) (string, error) {
1714 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
1715 if err != nil {
1716 return "", err
1717 }
1718 it.items = append(it.items, items...)
1719 return nextPageToken, nil
1720 }
1721
1722 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
1723 it.pageInfo.MaxSize = int(req.GetPageSize())
1724 it.pageInfo.Token = req.GetPageToken()
1725
1726 return it
1727 }
1728
1729 // GetServiceRollout gets a service configuration
1730 // rollout.
1731 func (c *serviceManagerRESTClient) GetServiceRollout(ctx context.Context, req *servicemanagementpb.GetServiceRolloutRequest, opts ...gax.CallOption) (*servicemanagementpb.Rollout, error) {
1732 baseUrl, err := url.Parse(c.endpoint)
1733 if err != nil {
1734 return nil, err
1735 }
1736 baseUrl.Path += fmt.Sprintf("/v1/services/%v/rollouts/%v", req.GetServiceName(), req.GetRolloutId())
1737
1738 params := url.Values{}
1739 params.Add("$alt", "json;enum-encoding=int")
1740
1741 baseUrl.RawQuery = params.Encode()
1742
1743 // Build HTTP headers from client and context metadata.
1744 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v&%s=%v", "service_name", url.QueryEscape(req.GetServiceName()), "rollout_id", url.QueryEscape(req.GetRolloutId()))}
1745
1746 hds = append(c.xGoogHeaders, hds...)
1747 hds = append(hds, "Content-Type", "application/json")
1748 headers := gax.BuildHeaders(ctx, hds...)
1749 opts = append((*c.CallOptions).GetServiceRollout[0:len((*c.CallOptions).GetServiceRollout):len((*c.CallOptions).GetServiceRollout)], opts...)
1750 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
1751 resp := &servicemanagementpb.Rollout{}
1752 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1753 if settings.Path != "" {
1754 baseUrl.Path = settings.Path
1755 }
1756 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
1757 if err != nil {
1758 return err
1759 }
1760 httpReq = httpReq.WithContext(ctx)
1761 httpReq.Header = headers
1762
1763 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "GetServiceRollout")
1764 if err != nil {
1765 return err
1766 }
1767
1768 if err := unm.Unmarshal(buf, resp); err != nil {
1769 return err
1770 }
1771
1772 return nil
1773 }, opts...)
1774 if e != nil {
1775 return nil, e
1776 }
1777 return resp, nil
1778 }
1779
1780 // CreateServiceRollout creates a new service configuration rollout. Based on rollout, the
1781 // Google Service Management will roll out the service configurations to
1782 // different backend services. For example, the logging configuration will be
1783 // pushed to Google Cloud Logging.
1784 //
1785 // Please note that any previous pending and running Rollouts and associated
1786 // Operations will be automatically cancelled so that the latest Rollout will
1787 // not be blocked by previous Rollouts.
1788 //
1789 // Only the 100 most recent (in any state) and the last 10 successful (if not
1790 // already part of the set of 100 most recent) rollouts are kept for each
1791 // service. The rest will be deleted eventually.
1792 //
1793 // Operation<response: Rollout>
1794 func (c *serviceManagerRESTClient) CreateServiceRollout(ctx context.Context, req *servicemanagementpb.CreateServiceRolloutRequest, opts ...gax.CallOption) (*CreateServiceRolloutOperation, error) {
1795 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
1796 body := req.GetRollout()
1797 jsonReq, err := m.Marshal(body)
1798 if err != nil {
1799 return nil, err
1800 }
1801
1802 baseUrl, err := url.Parse(c.endpoint)
1803 if err != nil {
1804 return nil, err
1805 }
1806 baseUrl.Path += fmt.Sprintf("/v1/services/%v/rollouts", req.GetServiceName())
1807
1808 params := url.Values{}
1809 params.Add("$alt", "json;enum-encoding=int")
1810
1811 baseUrl.RawQuery = params.Encode()
1812
1813 // Build HTTP headers from client and context metadata.
1814 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "service_name", url.QueryEscape(req.GetServiceName()))}
1815
1816 hds = append(c.xGoogHeaders, hds...)
1817 hds = append(hds, "Content-Type", "application/json")
1818 headers := gax.BuildHeaders(ctx, hds...)
1819 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
1820 resp := &longrunningpb.Operation{}
1821 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1822 if settings.Path != "" {
1823 baseUrl.Path = settings.Path
1824 }
1825 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
1826 if err != nil {
1827 return err
1828 }
1829 httpReq = httpReq.WithContext(ctx)
1830 httpReq.Header = headers
1831
1832 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "CreateServiceRollout")
1833 if err != nil {
1834 return err
1835 }
1836 if err := unm.Unmarshal(buf, resp); err != nil {
1837 return err
1838 }
1839
1840 return nil
1841 }, opts...)
1842 if e != nil {
1843 return nil, e
1844 }
1845
1846 override := fmt.Sprintf("/v1/%s", resp.GetName())
1847 return &CreateServiceRolloutOperation{
1848 lro: longrunning.InternalNewOperation(*c.LROClient, resp),
1849 pollPath: override,
1850 }, nil
1851 }
1852
1853 // GenerateConfigReport generates and returns a report (errors, warnings and changes from
1854 // existing configurations) associated with
1855 // GenerateConfigReportRequest.new_value
1856 //
1857 // If GenerateConfigReportRequest.old_value is specified,
1858 // GenerateConfigReportRequest will contain a single ChangeReport based on the
1859 // comparison between GenerateConfigReportRequest.new_value and
1860 // GenerateConfigReportRequest.old_value.
1861 // If GenerateConfigReportRequest.old_value is not specified, this method
1862 // will compare GenerateConfigReportRequest.new_value with the last pushed
1863 // service configuration.
1864 func (c *serviceManagerRESTClient) GenerateConfigReport(ctx context.Context, req *servicemanagementpb.GenerateConfigReportRequest, opts ...gax.CallOption) (*servicemanagementpb.GenerateConfigReportResponse, error) {
1865 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
1866 jsonReq, err := m.Marshal(req)
1867 if err != nil {
1868 return nil, err
1869 }
1870
1871 baseUrl, err := url.Parse(c.endpoint)
1872 if err != nil {
1873 return nil, err
1874 }
1875 baseUrl.Path += fmt.Sprintf("/v1/services:generateConfigReport")
1876
1877 params := url.Values{}
1878 params.Add("$alt", "json;enum-encoding=int")
1879
1880 baseUrl.RawQuery = params.Encode()
1881
1882 // Build HTTP headers from client and context metadata.
1883 hds := append(c.xGoogHeaders, "Content-Type", "application/json")
1884 headers := gax.BuildHeaders(ctx, hds...)
1885 opts = append((*c.CallOptions).GenerateConfigReport[0:len((*c.CallOptions).GenerateConfigReport):len((*c.CallOptions).GenerateConfigReport)], opts...)
1886 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
1887 resp := &servicemanagementpb.GenerateConfigReportResponse{}
1888 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1889 if settings.Path != "" {
1890 baseUrl.Path = settings.Path
1891 }
1892 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
1893 if err != nil {
1894 return err
1895 }
1896 httpReq = httpReq.WithContext(ctx)
1897 httpReq.Header = headers
1898
1899 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "GenerateConfigReport")
1900 if err != nil {
1901 return err
1902 }
1903
1904 if err := unm.Unmarshal(buf, resp); err != nil {
1905 return err
1906 }
1907
1908 return nil
1909 }, opts...)
1910 if e != nil {
1911 return nil, e
1912 }
1913 return resp, nil
1914 }
1915
1916 // GetIamPolicy gets the access control policy for a resource. Returns an empty policy
1917 // if the resource exists and does not have a policy set.
1918 func (c *serviceManagerRESTClient) GetIamPolicy(ctx context.Context, req *iampb.GetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) {
1919 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
1920 jsonReq, err := m.Marshal(req)
1921 if err != nil {
1922 return nil, err
1923 }
1924
1925 baseUrl, err := url.Parse(c.endpoint)
1926 if err != nil {
1927 return nil, err
1928 }
1929 baseUrl.Path += fmt.Sprintf("/v1/%v:getIamPolicy", req.GetResource())
1930
1931 params := url.Values{}
1932 params.Add("$alt", "json;enum-encoding=int")
1933
1934 baseUrl.RawQuery = params.Encode()
1935
1936 // Build HTTP headers from client and context metadata.
1937 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))}
1938
1939 hds = append(c.xGoogHeaders, hds...)
1940 hds = append(hds, "Content-Type", "application/json")
1941 headers := gax.BuildHeaders(ctx, hds...)
1942 opts = append((*c.CallOptions).GetIamPolicy[0:len((*c.CallOptions).GetIamPolicy):len((*c.CallOptions).GetIamPolicy)], opts...)
1943 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
1944 resp := &iampb.Policy{}
1945 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1946 if settings.Path != "" {
1947 baseUrl.Path = settings.Path
1948 }
1949 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
1950 if err != nil {
1951 return err
1952 }
1953 httpReq = httpReq.WithContext(ctx)
1954 httpReq.Header = headers
1955
1956 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "GetIamPolicy")
1957 if err != nil {
1958 return err
1959 }
1960
1961 if err := unm.Unmarshal(buf, resp); err != nil {
1962 return err
1963 }
1964
1965 return nil
1966 }, opts...)
1967 if e != nil {
1968 return nil, e
1969 }
1970 return resp, nil
1971 }
1972
1973 // SetIamPolicy sets the access control policy on the specified resource. Replaces
1974 // any existing policy.
1975 //
1976 // Can return NOT_FOUND, INVALID_ARGUMENT, and PERMISSION_DENIED
1977 // errors.
1978 func (c *serviceManagerRESTClient) SetIamPolicy(ctx context.Context, req *iampb.SetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) {
1979 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
1980 jsonReq, err := m.Marshal(req)
1981 if err != nil {
1982 return nil, err
1983 }
1984
1985 baseUrl, err := url.Parse(c.endpoint)
1986 if err != nil {
1987 return nil, err
1988 }
1989 baseUrl.Path += fmt.Sprintf("/v1/%v:setIamPolicy", req.GetResource())
1990
1991 params := url.Values{}
1992 params.Add("$alt", "json;enum-encoding=int")
1993
1994 baseUrl.RawQuery = params.Encode()
1995
1996 // Build HTTP headers from client and context metadata.
1997 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))}
1998
1999 hds = append(c.xGoogHeaders, hds...)
2000 hds = append(hds, "Content-Type", "application/json")
2001 headers := gax.BuildHeaders(ctx, hds...)
2002 opts = append((*c.CallOptions).SetIamPolicy[0:len((*c.CallOptions).SetIamPolicy):len((*c.CallOptions).SetIamPolicy)], opts...)
2003 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
2004 resp := &iampb.Policy{}
2005 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
2006 if settings.Path != "" {
2007 baseUrl.Path = settings.Path
2008 }
2009 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
2010 if err != nil {
2011 return err
2012 }
2013 httpReq = httpReq.WithContext(ctx)
2014 httpReq.Header = headers
2015
2016 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "SetIamPolicy")
2017 if err != nil {
2018 return err
2019 }
2020
2021 if err := unm.Unmarshal(buf, resp); err != nil {
2022 return err
2023 }
2024
2025 return nil
2026 }, opts...)
2027 if e != nil {
2028 return nil, e
2029 }
2030 return resp, nil
2031 }
2032
2033 // TestIamPermissions returns permissions that a caller has on the specified resource. If the
2034 // resource does not exist, this will return an empty set of
2035 // permissions, not a NOT_FOUND error.
2036 //
2037 // Note: This operation is designed to be used for building
2038 // permission-aware UIs and command-line tools, not for authorization
2039 // checking. This operation may “fail open” without warning.
2040 func (c *serviceManagerRESTClient) TestIamPermissions(ctx context.Context, req *iampb.TestIamPermissionsRequest, opts ...gax.CallOption) (*iampb.TestIamPermissionsResponse, error) {
2041 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
2042 jsonReq, err := m.Marshal(req)
2043 if err != nil {
2044 return nil, err
2045 }
2046
2047 baseUrl, err := url.Parse(c.endpoint)
2048 if err != nil {
2049 return nil, err
2050 }
2051 baseUrl.Path += fmt.Sprintf("/v1/%v:testIamPermissions", req.GetResource())
2052
2053 params := url.Values{}
2054 params.Add("$alt", "json;enum-encoding=int")
2055
2056 baseUrl.RawQuery = params.Encode()
2057
2058 // Build HTTP headers from client and context metadata.
2059 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))}
2060
2061 hds = append(c.xGoogHeaders, hds...)
2062 hds = append(hds, "Content-Type", "application/json")
2063 headers := gax.BuildHeaders(ctx, hds...)
2064 opts = append((*c.CallOptions).TestIamPermissions[0:len((*c.CallOptions).TestIamPermissions):len((*c.CallOptions).TestIamPermissions)], opts...)
2065 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
2066 resp := &iampb.TestIamPermissionsResponse{}
2067 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
2068 if settings.Path != "" {
2069 baseUrl.Path = settings.Path
2070 }
2071 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
2072 if err != nil {
2073 return err
2074 }
2075 httpReq = httpReq.WithContext(ctx)
2076 httpReq.Header = headers
2077
2078 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "TestIamPermissions")
2079 if err != nil {
2080 return err
2081 }
2082
2083 if err := unm.Unmarshal(buf, resp); err != nil {
2084 return err
2085 }
2086
2087 return nil
2088 }, opts...)
2089 if e != nil {
2090 return nil, e
2091 }
2092 return resp, nil
2093 }
2094
2095 // ListOperations lists service operations that match the specified filter in the request.
2096 func (c *serviceManagerRESTClient) ListOperations(ctx context.Context, req *longrunningpb.ListOperationsRequest, opts ...gax.CallOption) *OperationIterator {
2097 it := &OperationIterator{}
2098 req = proto.Clone(req).(*longrunningpb.ListOperationsRequest)
2099 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
2100 it.InternalFetch = func(pageSize int, pageToken string) ([]*longrunningpb.Operation, string, error) {
2101 resp := &longrunningpb.ListOperationsResponse{}
2102 if pageToken != "" {
2103 req.PageToken = pageToken
2104 }
2105 if pageSize > math.MaxInt32 {
2106 req.PageSize = math.MaxInt32
2107 } else if pageSize != 0 {
2108 req.PageSize = int32(pageSize)
2109 }
2110 baseUrl, err := url.Parse(c.endpoint)
2111 if err != nil {
2112 return nil, "", err
2113 }
2114 baseUrl.Path += fmt.Sprintf("/v1/operations")
2115
2116 params := url.Values{}
2117 params.Add("$alt", "json;enum-encoding=int")
2118 if req.GetFilter() != "" {
2119 params.Add("filter", fmt.Sprintf("%v", req.GetFilter()))
2120 }
2121 if req.GetName() != "" {
2122 params.Add("name", fmt.Sprintf("%v", req.GetName()))
2123 }
2124 if req.GetPageSize() != 0 {
2125 params.Add("pageSize", fmt.Sprintf("%v", req.GetPageSize()))
2126 }
2127 if req.GetPageToken() != "" {
2128 params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken()))
2129 }
2130
2131 baseUrl.RawQuery = params.Encode()
2132
2133 // Build HTTP headers from client and context metadata.
2134 hds := append(c.xGoogHeaders, "Content-Type", "application/json")
2135 headers := gax.BuildHeaders(ctx, hds...)
2136 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
2137 if settings.Path != "" {
2138 baseUrl.Path = settings.Path
2139 }
2140 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
2141 if err != nil {
2142 return err
2143 }
2144 httpReq.Header = headers
2145
2146 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "ListOperations")
2147 if err != nil {
2148 return err
2149 }
2150 if err := unm.Unmarshal(buf, resp); err != nil {
2151 return err
2152 }
2153
2154 return nil
2155 }, opts...)
2156 if e != nil {
2157 return nil, "", e
2158 }
2159 it.Response = resp
2160 return resp.GetOperations(), resp.GetNextPageToken(), nil
2161 }
2162
2163 fetch := func(pageSize int, pageToken string) (string, error) {
2164 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
2165 if err != nil {
2166 return "", err
2167 }
2168 it.items = append(it.items, items...)
2169 return nextPageToken, nil
2170 }
2171
2172 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
2173 it.pageInfo.MaxSize = int(req.GetPageSize())
2174 it.pageInfo.Token = req.GetPageToken()
2175
2176 return it
2177 }
2178
2179 // CreateServiceOperation returns a new CreateServiceOperation from a given name.
2180 // The name must be that of a previously created CreateServiceOperation, possibly from a different process.
2181 func (c *serviceManagerGRPCClient) CreateServiceOperation(name string) *CreateServiceOperation {
2182 return &CreateServiceOperation{
2183 lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}),
2184 }
2185 }
2186
2187 // CreateServiceOperation returns a new CreateServiceOperation from a given name.
2188 // The name must be that of a previously created CreateServiceOperation, possibly from a different process.
2189 func (c *serviceManagerRESTClient) CreateServiceOperation(name string) *CreateServiceOperation {
2190 override := fmt.Sprintf("/v1/%s", name)
2191 return &CreateServiceOperation{
2192 lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}),
2193 pollPath: override,
2194 }
2195 }
2196
2197 // CreateServiceRolloutOperation returns a new CreateServiceRolloutOperation from a given name.
2198 // The name must be that of a previously created CreateServiceRolloutOperation, possibly from a different process.
2199 func (c *serviceManagerGRPCClient) CreateServiceRolloutOperation(name string) *CreateServiceRolloutOperation {
2200 return &CreateServiceRolloutOperation{
2201 lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}),
2202 }
2203 }
2204
2205 // CreateServiceRolloutOperation returns a new CreateServiceRolloutOperation from a given name.
2206 // The name must be that of a previously created CreateServiceRolloutOperation, possibly from a different process.
2207 func (c *serviceManagerRESTClient) CreateServiceRolloutOperation(name string) *CreateServiceRolloutOperation {
2208 override := fmt.Sprintf("/v1/%s", name)
2209 return &CreateServiceRolloutOperation{
2210 lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}),
2211 pollPath: override,
2212 }
2213 }
2214
2215 // DeleteServiceOperation returns a new DeleteServiceOperation from a given name.
2216 // The name must be that of a previously created DeleteServiceOperation, possibly from a different process.
2217 func (c *serviceManagerGRPCClient) DeleteServiceOperation(name string) *DeleteServiceOperation {
2218 return &DeleteServiceOperation{
2219 lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}),
2220 }
2221 }
2222
2223 // DeleteServiceOperation returns a new DeleteServiceOperation from a given name.
2224 // The name must be that of a previously created DeleteServiceOperation, possibly from a different process.
2225 func (c *serviceManagerRESTClient) DeleteServiceOperation(name string) *DeleteServiceOperation {
2226 override := fmt.Sprintf("/v1/%s", name)
2227 return &DeleteServiceOperation{
2228 lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}),
2229 pollPath: override,
2230 }
2231 }
2232
2233 // SubmitConfigSourceOperation returns a new SubmitConfigSourceOperation from a given name.
2234 // The name must be that of a previously created SubmitConfigSourceOperation, possibly from a different process.
2235 func (c *serviceManagerGRPCClient) SubmitConfigSourceOperation(name string) *SubmitConfigSourceOperation {
2236 return &SubmitConfigSourceOperation{
2237 lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}),
2238 }
2239 }
2240
2241 // SubmitConfigSourceOperation returns a new SubmitConfigSourceOperation from a given name.
2242 // The name must be that of a previously created SubmitConfigSourceOperation, possibly from a different process.
2243 func (c *serviceManagerRESTClient) SubmitConfigSourceOperation(name string) *SubmitConfigSourceOperation {
2244 override := fmt.Sprintf("/v1/%s", name)
2245 return &SubmitConfigSourceOperation{
2246 lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}),
2247 pollPath: override,
2248 }
2249 }
2250
2251 // UndeleteServiceOperation returns a new UndeleteServiceOperation from a given name.
2252 // The name must be that of a previously created UndeleteServiceOperation, possibly from a different process.
2253 func (c *serviceManagerGRPCClient) UndeleteServiceOperation(name string) *UndeleteServiceOperation {
2254 return &UndeleteServiceOperation{
2255 lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}),
2256 }
2257 }
2258
2259 // UndeleteServiceOperation returns a new UndeleteServiceOperation from a given name.
2260 // The name must be that of a previously created UndeleteServiceOperation, possibly from a different process.
2261 func (c *serviceManagerRESTClient) UndeleteServiceOperation(name string) *UndeleteServiceOperation {
2262 override := fmt.Sprintf("/v1/%s", name)
2263 return &UndeleteServiceOperation{
2264 lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}),
2265 pollPath: override,
2266 }
2267 }