From b96134fe91c182237359000cd544af5fec60d7db Mon Sep 17 00:00:00 2001 From: Cody Oss <6331106+codyoss@users.noreply.github.com> Date: Tue, 26 Jan 2021 14:36:04 -0700 Subject: [PATCH] feat(servicemanagement): start generating apiv1 (#3614) --- internal/.repo-metadata-full.json | 8 + internal/gapicgen/generator/config.go | 9 + servicemanagement/apiv1/doc.go | 115 ++ .../apiv1/service_manager_client.go | 1270 +++++++++++++++++ .../service_manager_client_example_test.go | 389 +++++ 5 files changed, 1791 insertions(+) create mode 100644 servicemanagement/apiv1/doc.go create mode 100644 servicemanagement/apiv1/service_manager_client.go create mode 100644 servicemanagement/apiv1/service_manager_client_example_test.go diff --git a/internal/.repo-metadata-full.json b/internal/.repo-metadata-full.json index f25ed699067..63a88bc1cec 100644 --- a/internal/.repo-metadata-full.json +++ b/internal/.repo-metadata-full.json @@ -815,6 +815,14 @@ "docs_url": "https://pkg.go.dev/cloud.google.com/go/servicedirectory/apiv1beta1", "release_level": "beta" }, + "cloud.google.com/go/servicemanagement/apiv1": { + "distribution_name": "cloud.google.com/go/servicemanagement/apiv1", + "description": "", + "language": "Go", + "client_library_type": "generated", + "docs_url": "https://pkg.go.dev/cloud.google.com/go/servicemanagement/apiv1", + "release_level": "beta" + }, "cloud.google.com/go/spanner": { "distribution_name": "cloud.google.com/go/spanner", "description": "Cloud Spanner", diff --git a/internal/gapicgen/generator/config.go b/internal/gapicgen/generator/config.go index 9af51b516fe..ed13604189d 100644 --- a/internal/gapicgen/generator/config.go +++ b/internal/gapicgen/generator/config.go @@ -940,6 +940,15 @@ var microgenGapicConfigs = []*microgenConfig{ apiServiceConfigPath: "google/cloud/dataqna/v1alpha/dataqna_v1alpha.yaml", releaseLevel: "alpha", }, + { + inputDirectoryPath: "google/api/servicemanagement/v1", + pkg: "servicemanagement", + importPath: "cloud.google.com/go/servicemanagement/apiv1", + gRPCServiceConfigPath: "google/api/servicemanagement/v1/servicemanagement_grpc_service_config.json", + apiServiceConfigPath: "google/api/servicemanagement/v1/servicemanagement_gapic.yaml", + // GA after 2021/02/26 + releaseLevel: "beta", + }, // Non-Cloud APIs { diff --git a/servicemanagement/apiv1/doc.go b/servicemanagement/apiv1/doc.go new file mode 100644 index 00000000000..08310b937df --- /dev/null +++ b/servicemanagement/apiv1/doc.go @@ -0,0 +1,115 @@ +// Copyright 2021 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Code generated by protoc-gen-go_gapic. DO NOT EDIT. + +// +// Use of Context +// +// The ctx passed to NewClient is used for authentication requests and +// for creating the underlying connection, but is not used for subsequent calls. +// Individual methods on the client use the ctx given to them. +// +// To close the open connection, use the Close() method. +// +// For information about setting deadlines, reusing contexts, and more +// please visit pkg.go.dev/cloud.google.com/go. +package servicemanagement // import "cloud.google.com/go/servicemanagement/apiv1" + +import ( + "context" + "os" + "runtime" + "strconv" + "strings" + "unicode" + + "google.golang.org/api/option" + "google.golang.org/grpc/metadata" +) + +// For more information on implementing a client constructor hook, see +// https://github.com/googleapis/google-cloud-go/wiki/Customizing-constructors. +type clientHookParams struct{} +type clientHook func(context.Context, clientHookParams) ([]option.ClientOption, error) + +const versionClient = "20210126" + +func insertMetadata(ctx context.Context, mds ...metadata.MD) context.Context { + out, _ := metadata.FromOutgoingContext(ctx) + out = out.Copy() + for _, md := range mds { + for k, v := range md { + out[k] = append(out[k], v...) + } + } + return metadata.NewOutgoingContext(ctx, out) +} + +func checkDisableDeadlines() (bool, error) { + raw, ok := os.LookupEnv("GOOGLE_API_GO_EXPERIMENTAL_DISABLE_DEFAULT_DEADLINE") + if !ok { + return false, nil + } + + b, err := strconv.ParseBool(raw) + return b, err +} + +// DefaultAuthScopes reports the default set of authentication scopes to use with this package. +func DefaultAuthScopes() []string { + return []string{ + "https://www.googleapis.com/auth/cloud-platform", + "https://www.googleapis.com/auth/cloud-platform.read-only", + "https://www.googleapis.com/auth/service.management", + "https://www.googleapis.com/auth/service.management.readonly", + } +} + +// versionGo returns the Go runtime version. The returned string +// has no whitespace, suitable for reporting in header. +func versionGo() string { + const develPrefix = "devel +" + + s := runtime.Version() + if strings.HasPrefix(s, develPrefix) { + s = s[len(develPrefix):] + if p := strings.IndexFunc(s, unicode.IsSpace); p >= 0 { + s = s[:p] + } + return s + } + + notSemverRune := func(r rune) bool { + return !strings.ContainsRune("0123456789.", r) + } + + if strings.HasPrefix(s, "go1") { + s = s[2:] + var prerelease string + if p := strings.IndexFunc(s, notSemverRune); p >= 0 { + s, prerelease = s[:p], s[p:] + } + if strings.HasSuffix(s, ".") { + s += "0" + } else if strings.Count(s, ".") < 2 { + s += ".0" + } + if prerelease != "" { + s += "-" + prerelease + } + return s + } + return "UNKNOWN" +} diff --git a/servicemanagement/apiv1/service_manager_client.go b/servicemanagement/apiv1/service_manager_client.go new file mode 100644 index 00000000000..723c70ba583 --- /dev/null +++ b/servicemanagement/apiv1/service_manager_client.go @@ -0,0 +1,1270 @@ +// Copyright 2021 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Code generated by protoc-gen-go_gapic. DO NOT EDIT. + +package servicemanagement + +import ( + "context" + "fmt" + "math" + "net/url" + "time" + + "cloud.google.com/go/longrunning" + lroauto "cloud.google.com/go/longrunning/autogen" + "github.com/golang/protobuf/proto" + gax "github.com/googleapis/gax-go/v2" + "google.golang.org/api/iterator" + "google.golang.org/api/option" + "google.golang.org/api/option/internaloption" + gtransport "google.golang.org/api/transport/grpc" + serviceconfigpb "google.golang.org/genproto/googleapis/api/serviceconfig" + servicemanagementpb "google.golang.org/genproto/googleapis/api/servicemanagement/v1" + longrunningpb "google.golang.org/genproto/googleapis/longrunning" + "google.golang.org/grpc" + "google.golang.org/grpc/metadata" +) + +var newServiceManagerClientHook clientHook + +// ServiceManagerCallOptions contains the retry settings for each method of ServiceManagerClient. +type ServiceManagerCallOptions struct { + ListServices []gax.CallOption + GetService []gax.CallOption + CreateService []gax.CallOption + DeleteService []gax.CallOption + UndeleteService []gax.CallOption + ListServiceConfigs []gax.CallOption + GetServiceConfig []gax.CallOption + CreateServiceConfig []gax.CallOption + SubmitConfigSource []gax.CallOption + ListServiceRollouts []gax.CallOption + GetServiceRollout []gax.CallOption + CreateServiceRollout []gax.CallOption + GenerateConfigReport []gax.CallOption + EnableService []gax.CallOption + DisableService []gax.CallOption +} + +func defaultServiceManagerClientOptions() []option.ClientOption { + return []option.ClientOption{ + internaloption.WithDefaultEndpoint("servicemanagement.googleapis.com:443"), + internaloption.WithDefaultMTLSEndpoint("servicemanagement.mtls.googleapis.com:443"), + internaloption.WithDefaultAudience("https://servicemanagement.googleapis.com/"), + internaloption.WithDefaultScopes(DefaultAuthScopes()...), + option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), + option.WithGRPCDialOption(grpc.WithDefaultCallOptions( + grpc.MaxCallRecvMsgSize(math.MaxInt32))), + } +} + +func defaultServiceManagerCallOptions() *ServiceManagerCallOptions { + return &ServiceManagerCallOptions{ + ListServices: []gax.CallOption{}, + GetService: []gax.CallOption{}, + CreateService: []gax.CallOption{}, + DeleteService: []gax.CallOption{}, + UndeleteService: []gax.CallOption{}, + ListServiceConfigs: []gax.CallOption{}, + GetServiceConfig: []gax.CallOption{}, + CreateServiceConfig: []gax.CallOption{}, + SubmitConfigSource: []gax.CallOption{}, + ListServiceRollouts: []gax.CallOption{}, + GetServiceRollout: []gax.CallOption{}, + CreateServiceRollout: []gax.CallOption{}, + GenerateConfigReport: []gax.CallOption{}, + EnableService: []gax.CallOption{}, + DisableService: []gax.CallOption{}, + } +} + +// ServiceManagerClient is a client for interacting with . +// +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +type ServiceManagerClient struct { + // Connection pool of gRPC connections to the service. + connPool gtransport.ConnPool + + // flag to opt out of default deadlines via GOOGLE_API_GO_EXPERIMENTAL_DISABLE_DEFAULT_DEADLINE + disableDeadlines bool + + // The gRPC API client. + serviceManagerClient servicemanagementpb.ServiceManagerClient + + // LROClient is used internally to handle longrunning operations. + // It is exposed so that its CallOptions can be modified if required. + // Users should not Close this client. + LROClient *lroauto.OperationsClient + + // The call options for this service. + CallOptions *ServiceManagerCallOptions + + // The x-goog-* metadata to be sent with each request. + xGoogMetadata metadata.MD +} + +// NewServiceManagerClient creates a new service manager client. +// +// Google Service Management API (at /service-management/overview) +func NewServiceManagerClient(ctx context.Context, opts ...option.ClientOption) (*ServiceManagerClient, error) { + clientOpts := defaultServiceManagerClientOptions() + + if newServiceManagerClientHook != nil { + hookOpts, err := newServiceManagerClientHook(ctx, clientHookParams{}) + if err != nil { + return nil, err + } + clientOpts = append(clientOpts, hookOpts...) + } + + disableDeadlines, err := checkDisableDeadlines() + if err != nil { + return nil, err + } + + connPool, err := gtransport.DialPool(ctx, append(clientOpts, opts...)...) + if err != nil { + return nil, err + } + c := &ServiceManagerClient{ + connPool: connPool, + disableDeadlines: disableDeadlines, + CallOptions: defaultServiceManagerCallOptions(), + + serviceManagerClient: servicemanagementpb.NewServiceManagerClient(connPool), + } + c.setGoogleClientInfo() + + c.LROClient, err = lroauto.NewOperationsClient(ctx, gtransport.WithConnPool(connPool)) + if err != nil { + // This error "should not happen", since we are just reusing old connection pool + // and never actually need to dial. + // If this does happen, we could leak connp. However, we cannot close conn: + // If the user invoked the constructor with option.WithGRPCConn, + // we would close a connection that's still in use. + // TODO: investigate error conditions. + return nil, err + } + return c, nil +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *ServiceManagerClient) Connection() *grpc.ClientConn { + return c.connPool.Conn() +} + +// Close closes the connection to the API service. The user should invoke this when +// the client is no longer required. +func (c *ServiceManagerClient) Close() error { + return c.connPool.Close() +} + +// setGoogleClientInfo sets the name and version of the application in +// the `x-goog-api-client` header passed on each request. Intended for +// use by Google-written clients. +func (c *ServiceManagerClient) setGoogleClientInfo(keyval ...string) { + kv := append([]string{"gl-go", versionGo()}, keyval...) + kv = append(kv, "gapic", versionClient, "gax", gax.Version, "grpc", grpc.Version) + c.xGoogMetadata = metadata.Pairs("x-goog-api-client", gax.XGoogHeader(kv...)) +} + +// ListServices lists managed services. +// +// Returns all public services. For authenticated users, also returns all +// services the calling user has “servicemanagement.services.get” permission +// for. +// +// BETA: If the caller specifies the consumer_id, it returns only the +// services enabled on the consumer. The consumer_id must have the format +// of “project:{PROJECT-ID}”. +func (c *ServiceManagerClient) ListServices(ctx context.Context, req *servicemanagementpb.ListServicesRequest, opts ...gax.CallOption) *ManagedServiceIterator { + ctx = insertMetadata(ctx, c.xGoogMetadata) + opts = append(c.CallOptions.ListServices[0:len(c.CallOptions.ListServices):len(c.CallOptions.ListServices)], opts...) + it := &ManagedServiceIterator{} + req = proto.Clone(req).(*servicemanagementpb.ListServicesRequest) + it.InternalFetch = func(pageSize int, pageToken string) ([]*servicemanagementpb.ManagedService, string, error) { + var resp *servicemanagementpb.ListServicesResponse + req.PageToken = pageToken + if pageSize > math.MaxInt32 { + req.PageSize = math.MaxInt32 + } else { + req.PageSize = int32(pageSize) + } + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.serviceManagerClient.ListServices(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, "", err + } + + it.Response = resp + return resp.GetServices(), resp.GetNextPageToken(), nil + } + fetch := func(pageSize int, pageToken string) (string, error) { + items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) + if err != nil { + return "", err + } + it.items = append(it.items, items...) + return nextPageToken, nil + } + it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) + it.pageInfo.MaxSize = int(req.GetPageSize()) + it.pageInfo.Token = req.GetPageToken() + return it +} + +// GetService gets a managed service. Authentication is required unless the service is +// public. +func (c *ServiceManagerClient) GetService(ctx context.Context, req *servicemanagementpb.GetServiceRequest, opts ...gax.CallOption) (*servicemanagementpb.ManagedService, error) { + if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { + cctx, cancel := context.WithTimeout(ctx, 10000*time.Millisecond) + defer cancel() + ctx = cctx + } + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "service_name", url.QueryEscape(req.GetServiceName()))) + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append(c.CallOptions.GetService[0:len(c.CallOptions.GetService):len(c.CallOptions.GetService)], opts...) + var resp *servicemanagementpb.ManagedService + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.serviceManagerClient.GetService(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} + +// CreateService creates a new managed service. +// Please note one producer project can own no more than 20 services. +// +// Operation +func (c *ServiceManagerClient) CreateService(ctx context.Context, req *servicemanagementpb.CreateServiceRequest, opts ...gax.CallOption) (*CreateServiceOperation, error) { + if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { + cctx, cancel := context.WithTimeout(ctx, 10000*time.Millisecond) + defer cancel() + ctx = cctx + } + ctx = insertMetadata(ctx, c.xGoogMetadata) + opts = append(c.CallOptions.CreateService[0:len(c.CallOptions.CreateService):len(c.CallOptions.CreateService)], opts...) + var resp *longrunningpb.Operation + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.serviceManagerClient.CreateService(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return &CreateServiceOperation{ + lro: longrunning.InternalNewOperation(c.LROClient, resp), + }, nil +} + +// DeleteService deletes a managed service. This method will change the service to the +// Soft-Delete state for 30 days. Within this period, service producers may +// call UndeleteService to restore the service. +// After 30 days, the service will be permanently deleted. +// +// Operation +func (c *ServiceManagerClient) DeleteService(ctx context.Context, req *servicemanagementpb.DeleteServiceRequest, opts ...gax.CallOption) (*DeleteServiceOperation, error) { + if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { + cctx, cancel := context.WithTimeout(ctx, 10000*time.Millisecond) + defer cancel() + ctx = cctx + } + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "service_name", url.QueryEscape(req.GetServiceName()))) + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append(c.CallOptions.DeleteService[0:len(c.CallOptions.DeleteService):len(c.CallOptions.DeleteService)], opts...) + var resp *longrunningpb.Operation + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.serviceManagerClient.DeleteService(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return &DeleteServiceOperation{ + lro: longrunning.InternalNewOperation(c.LROClient, resp), + }, nil +} + +// UndeleteService revives a previously deleted managed service. The method restores the +// service using the configuration at the time the service was deleted. +// The target service must exist and must have been deleted within the +// last 30 days. +// +// Operation +func (c *ServiceManagerClient) UndeleteService(ctx context.Context, req *servicemanagementpb.UndeleteServiceRequest, opts ...gax.CallOption) (*UndeleteServiceOperation, error) { + if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { + cctx, cancel := context.WithTimeout(ctx, 10000*time.Millisecond) + defer cancel() + ctx = cctx + } + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "service_name", url.QueryEscape(req.GetServiceName()))) + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append(c.CallOptions.UndeleteService[0:len(c.CallOptions.UndeleteService):len(c.CallOptions.UndeleteService)], opts...) + var resp *longrunningpb.Operation + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.serviceManagerClient.UndeleteService(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return &UndeleteServiceOperation{ + lro: longrunning.InternalNewOperation(c.LROClient, resp), + }, nil +} + +// ListServiceConfigs lists the history of the service configuration for a managed service, +// from the newest to the oldest. +func (c *ServiceManagerClient) ListServiceConfigs(ctx context.Context, req *servicemanagementpb.ListServiceConfigsRequest, opts ...gax.CallOption) *ServiceIterator { + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "service_name", url.QueryEscape(req.GetServiceName()))) + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append(c.CallOptions.ListServiceConfigs[0:len(c.CallOptions.ListServiceConfigs):len(c.CallOptions.ListServiceConfigs)], opts...) + it := &ServiceIterator{} + req = proto.Clone(req).(*servicemanagementpb.ListServiceConfigsRequest) + it.InternalFetch = func(pageSize int, pageToken string) ([]*serviceconfigpb.Service, string, error) { + var resp *servicemanagementpb.ListServiceConfigsResponse + req.PageToken = pageToken + if pageSize > math.MaxInt32 { + req.PageSize = math.MaxInt32 + } else { + req.PageSize = int32(pageSize) + } + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.serviceManagerClient.ListServiceConfigs(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, "", err + } + + it.Response = resp + return resp.GetServiceConfigs(), resp.GetNextPageToken(), nil + } + fetch := func(pageSize int, pageToken string) (string, error) { + items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) + if err != nil { + return "", err + } + it.items = append(it.items, items...) + return nextPageToken, nil + } + it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) + it.pageInfo.MaxSize = int(req.GetPageSize()) + it.pageInfo.Token = req.GetPageToken() + return it +} + +// GetServiceConfig gets a service configuration (version) for a managed service. +func (c *ServiceManagerClient) GetServiceConfig(ctx context.Context, req *servicemanagementpb.GetServiceConfigRequest, opts ...gax.CallOption) (*serviceconfigpb.Service, error) { + if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { + cctx, cancel := context.WithTimeout(ctx, 10000*time.Millisecond) + defer cancel() + ctx = cctx + } + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v&%s=%v", "service_name", url.QueryEscape(req.GetServiceName()), "config_id", url.QueryEscape(req.GetConfigId()))) + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append(c.CallOptions.GetServiceConfig[0:len(c.CallOptions.GetServiceConfig):len(c.CallOptions.GetServiceConfig)], opts...) + var resp *serviceconfigpb.Service + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.serviceManagerClient.GetServiceConfig(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} + +// CreateServiceConfig creates a new service configuration (version) for a managed service. +// This method only stores the service configuration. To roll out the service +// configuration to backend systems please call +// CreateServiceRollout. +// +// Only the 100 most recent service configurations and ones referenced by +// existing rollouts are kept for each service. The rest will be deleted +// eventually. +func (c *ServiceManagerClient) CreateServiceConfig(ctx context.Context, req *servicemanagementpb.CreateServiceConfigRequest, opts ...gax.CallOption) (*serviceconfigpb.Service, error) { + if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { + cctx, cancel := context.WithTimeout(ctx, 10000*time.Millisecond) + defer cancel() + ctx = cctx + } + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "service_name", url.QueryEscape(req.GetServiceName()))) + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append(c.CallOptions.CreateServiceConfig[0:len(c.CallOptions.CreateServiceConfig):len(c.CallOptions.CreateServiceConfig)], opts...) + var resp *serviceconfigpb.Service + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.serviceManagerClient.CreateServiceConfig(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} + +// SubmitConfigSource creates a new service configuration (version) for a managed service based +// on +// user-supplied configuration source files (for example: OpenAPI +// Specification). This method stores the source configurations as well as the +// generated service configuration. To rollout the service configuration to +// other services, +// please call CreateServiceRollout. +// +// Only the 100 most recent configuration sources and ones referenced by +// existing service configurtions are kept for each service. The rest will be +// deleted eventually. +// +// Operation +func (c *ServiceManagerClient) SubmitConfigSource(ctx context.Context, req *servicemanagementpb.SubmitConfigSourceRequest, opts ...gax.CallOption) (*SubmitConfigSourceOperation, error) { + if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { + cctx, cancel := context.WithTimeout(ctx, 10000*time.Millisecond) + defer cancel() + ctx = cctx + } + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "service_name", url.QueryEscape(req.GetServiceName()))) + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append(c.CallOptions.SubmitConfigSource[0:len(c.CallOptions.SubmitConfigSource):len(c.CallOptions.SubmitConfigSource)], opts...) + var resp *longrunningpb.Operation + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.serviceManagerClient.SubmitConfigSource(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return &SubmitConfigSourceOperation{ + lro: longrunning.InternalNewOperation(c.LROClient, resp), + }, nil +} + +// ListServiceRollouts lists the history of the service configuration rollouts for a managed +// service, from the newest to the oldest. +func (c *ServiceManagerClient) ListServiceRollouts(ctx context.Context, req *servicemanagementpb.ListServiceRolloutsRequest, opts ...gax.CallOption) *RolloutIterator { + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "service_name", url.QueryEscape(req.GetServiceName()))) + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append(c.CallOptions.ListServiceRollouts[0:len(c.CallOptions.ListServiceRollouts):len(c.CallOptions.ListServiceRollouts)], opts...) + it := &RolloutIterator{} + req = proto.Clone(req).(*servicemanagementpb.ListServiceRolloutsRequest) + it.InternalFetch = func(pageSize int, pageToken string) ([]*servicemanagementpb.Rollout, string, error) { + var resp *servicemanagementpb.ListServiceRolloutsResponse + req.PageToken = pageToken + if pageSize > math.MaxInt32 { + req.PageSize = math.MaxInt32 + } else { + req.PageSize = int32(pageSize) + } + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.serviceManagerClient.ListServiceRollouts(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, "", err + } + + it.Response = resp + return resp.GetRollouts(), resp.GetNextPageToken(), nil + } + fetch := func(pageSize int, pageToken string) (string, error) { + items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) + if err != nil { + return "", err + } + it.items = append(it.items, items...) + return nextPageToken, nil + } + it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) + it.pageInfo.MaxSize = int(req.GetPageSize()) + it.pageInfo.Token = req.GetPageToken() + return it +} + +// GetServiceRollout gets a service configuration rollout. +func (c *ServiceManagerClient) GetServiceRollout(ctx context.Context, req *servicemanagementpb.GetServiceRolloutRequest, opts ...gax.CallOption) (*servicemanagementpb.Rollout, error) { + if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { + cctx, cancel := context.WithTimeout(ctx, 10000*time.Millisecond) + defer cancel() + ctx = cctx + } + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v&%s=%v", "service_name", url.QueryEscape(req.GetServiceName()), "rollout_id", url.QueryEscape(req.GetRolloutId()))) + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append(c.CallOptions.GetServiceRollout[0:len(c.CallOptions.GetServiceRollout):len(c.CallOptions.GetServiceRollout)], opts...) + var resp *servicemanagementpb.Rollout + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.serviceManagerClient.GetServiceRollout(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} + +// CreateServiceRollout creates a new service configuration rollout. Based on rollout, the +// Google Service Management will roll out the service configurations to +// different backend services. For example, the logging configuration will be +// pushed to Google Cloud Logging. +// +// Please note that any previous pending and running Rollouts and associated +// Operations will be automatically cancelled so that the latest Rollout will +// not be blocked by previous Rollouts. +// +// Only the 100 most recent (in any state) and the last 10 successful (if not +// already part of the set of 100 most recent) rollouts are kept for each +// service. The rest will be deleted eventually. +// +// Operation +func (c *ServiceManagerClient) CreateServiceRollout(ctx context.Context, req *servicemanagementpb.CreateServiceRolloutRequest, opts ...gax.CallOption) (*CreateServiceRolloutOperation, error) { + if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { + cctx, cancel := context.WithTimeout(ctx, 10000*time.Millisecond) + defer cancel() + ctx = cctx + } + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "service_name", url.QueryEscape(req.GetServiceName()))) + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append(c.CallOptions.CreateServiceRollout[0:len(c.CallOptions.CreateServiceRollout):len(c.CallOptions.CreateServiceRollout)], opts...) + var resp *longrunningpb.Operation + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.serviceManagerClient.CreateServiceRollout(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return &CreateServiceRolloutOperation{ + lro: longrunning.InternalNewOperation(c.LROClient, resp), + }, nil +} + +// GenerateConfigReport generates and returns a report (errors, warnings and changes from +// existing configurations) associated with +// GenerateConfigReportRequest.new_value +// +// If GenerateConfigReportRequest.old_value is specified, +// GenerateConfigReportRequest will contain a single ChangeReport based on the +// comparison between GenerateConfigReportRequest.new_value and +// GenerateConfigReportRequest.old_value. +// If GenerateConfigReportRequest.old_value is not specified, this method +// will compare GenerateConfigReportRequest.new_value with the last pushed +// service configuration. +func (c *ServiceManagerClient) GenerateConfigReport(ctx context.Context, req *servicemanagementpb.GenerateConfigReportRequest, opts ...gax.CallOption) (*servicemanagementpb.GenerateConfigReportResponse, error) { + if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { + cctx, cancel := context.WithTimeout(ctx, 10000*time.Millisecond) + defer cancel() + ctx = cctx + } + ctx = insertMetadata(ctx, c.xGoogMetadata) + opts = append(c.CallOptions.GenerateConfigReport[0:len(c.CallOptions.GenerateConfigReport):len(c.CallOptions.GenerateConfigReport)], opts...) + var resp *servicemanagementpb.GenerateConfigReportResponse + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.serviceManagerClient.GenerateConfigReport(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} + +// EnableService enables a service for a project, so it can be used +// for the project. See +// Cloud Auth Guide (at https://cloud.google.com/docs/authentication) for +// more information. +// +// Operation +func (c *ServiceManagerClient) EnableService(ctx context.Context, req *servicemanagementpb.EnableServiceRequest, opts ...gax.CallOption) (*EnableServiceOperation, error) { + if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { + cctx, cancel := context.WithTimeout(ctx, 10000*time.Millisecond) + defer cancel() + ctx = cctx + } + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "service_name", url.QueryEscape(req.GetServiceName()))) + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append(c.CallOptions.EnableService[0:len(c.CallOptions.EnableService):len(c.CallOptions.EnableService)], opts...) + var resp *longrunningpb.Operation + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.serviceManagerClient.EnableService(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return &EnableServiceOperation{ + lro: longrunning.InternalNewOperation(c.LROClient, resp), + }, nil +} + +// DisableService disables a service for a project, so it can no longer be +// be used for the project. It prevents accidental usage that may cause +// unexpected billing charges or security leaks. +// +// Operation +func (c *ServiceManagerClient) DisableService(ctx context.Context, req *servicemanagementpb.DisableServiceRequest, opts ...gax.CallOption) (*DisableServiceOperation, error) { + if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { + cctx, cancel := context.WithTimeout(ctx, 10000*time.Millisecond) + defer cancel() + ctx = cctx + } + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "service_name", url.QueryEscape(req.GetServiceName()))) + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append(c.CallOptions.DisableService[0:len(c.CallOptions.DisableService):len(c.CallOptions.DisableService)], opts...) + var resp *longrunningpb.Operation + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.serviceManagerClient.DisableService(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return &DisableServiceOperation{ + lro: longrunning.InternalNewOperation(c.LROClient, resp), + }, nil +} + +// CreateServiceOperation manages a long-running operation from CreateService. +type CreateServiceOperation struct { + lro *longrunning.Operation +} + +// CreateServiceOperation returns a new CreateServiceOperation from a given name. +// The name must be that of a previously created CreateServiceOperation, possibly from a different process. +func (c *ServiceManagerClient) CreateServiceOperation(name string) *CreateServiceOperation { + return &CreateServiceOperation{ + lro: longrunning.InternalNewOperation(c.LROClient, &longrunningpb.Operation{Name: name}), + } +} + +// Wait blocks until the long-running operation is completed, returning the response and any errors encountered. +// +// See documentation of Poll for error-handling information. +func (op *CreateServiceOperation) Wait(ctx context.Context, opts ...gax.CallOption) (*servicemanagementpb.ManagedService, error) { + var resp servicemanagementpb.ManagedService + if err := op.lro.WaitWithInterval(ctx, &resp, time.Minute, opts...); err != nil { + return nil, err + } + return &resp, nil +} + +// Poll fetches the latest state of the long-running operation. +// +// Poll also fetches the latest metadata, which can be retrieved by Metadata. +// +// If Poll fails, the error is returned and op is unmodified. If Poll succeeds and +// the operation has completed with failure, the error is returned and op.Done will return true. +// If Poll succeeds and the operation has completed successfully, +// op.Done will return true, and the response of the operation is returned. +// If Poll succeeds and the operation has not completed, the returned response and error are both nil. +func (op *CreateServiceOperation) Poll(ctx context.Context, opts ...gax.CallOption) (*servicemanagementpb.ManagedService, error) { + var resp servicemanagementpb.ManagedService + if err := op.lro.Poll(ctx, &resp, opts...); err != nil { + return nil, err + } + if !op.Done() { + return nil, nil + } + return &resp, nil +} + +// Metadata returns metadata associated with the long-running operation. +// Metadata itself does not contact the server, but Poll does. +// To get the latest metadata, call this method after a successful call to Poll. +// If the metadata is not available, the returned metadata and error are both nil. +func (op *CreateServiceOperation) Metadata() (*servicemanagementpb.OperationMetadata, error) { + var meta servicemanagementpb.OperationMetadata + if err := op.lro.Metadata(&meta); err == longrunning.ErrNoMetadata { + return nil, nil + } else if err != nil { + return nil, err + } + return &meta, nil +} + +// Done reports whether the long-running operation has completed. +func (op *CreateServiceOperation) Done() bool { + return op.lro.Done() +} + +// Name returns the name of the long-running operation. +// The name is assigned by the server and is unique within the service from which the operation is created. +func (op *CreateServiceOperation) Name() string { + return op.lro.Name() +} + +// CreateServiceRolloutOperation manages a long-running operation from CreateServiceRollout. +type CreateServiceRolloutOperation struct { + lro *longrunning.Operation +} + +// CreateServiceRolloutOperation returns a new CreateServiceRolloutOperation from a given name. +// The name must be that of a previously created CreateServiceRolloutOperation, possibly from a different process. +func (c *ServiceManagerClient) CreateServiceRolloutOperation(name string) *CreateServiceRolloutOperation { + return &CreateServiceRolloutOperation{ + lro: longrunning.InternalNewOperation(c.LROClient, &longrunningpb.Operation{Name: name}), + } +} + +// Wait blocks until the long-running operation is completed, returning the response and any errors encountered. +// +// See documentation of Poll for error-handling information. +func (op *CreateServiceRolloutOperation) Wait(ctx context.Context, opts ...gax.CallOption) (*servicemanagementpb.Rollout, error) { + var resp servicemanagementpb.Rollout + if err := op.lro.WaitWithInterval(ctx, &resp, time.Minute, opts...); err != nil { + return nil, err + } + return &resp, nil +} + +// Poll fetches the latest state of the long-running operation. +// +// Poll also fetches the latest metadata, which can be retrieved by Metadata. +// +// If Poll fails, the error is returned and op is unmodified. If Poll succeeds and +// the operation has completed with failure, the error is returned and op.Done will return true. +// If Poll succeeds and the operation has completed successfully, +// op.Done will return true, and the response of the operation is returned. +// If Poll succeeds and the operation has not completed, the returned response and error are both nil. +func (op *CreateServiceRolloutOperation) Poll(ctx context.Context, opts ...gax.CallOption) (*servicemanagementpb.Rollout, error) { + var resp servicemanagementpb.Rollout + if err := op.lro.Poll(ctx, &resp, opts...); err != nil { + return nil, err + } + if !op.Done() { + return nil, nil + } + return &resp, nil +} + +// Metadata returns metadata associated with the long-running operation. +// Metadata itself does not contact the server, but Poll does. +// To get the latest metadata, call this method after a successful call to Poll. +// If the metadata is not available, the returned metadata and error are both nil. +func (op *CreateServiceRolloutOperation) Metadata() (*servicemanagementpb.OperationMetadata, error) { + var meta servicemanagementpb.OperationMetadata + if err := op.lro.Metadata(&meta); err == longrunning.ErrNoMetadata { + return nil, nil + } else if err != nil { + return nil, err + } + return &meta, nil +} + +// Done reports whether the long-running operation has completed. +func (op *CreateServiceRolloutOperation) Done() bool { + return op.lro.Done() +} + +// Name returns the name of the long-running operation. +// The name is assigned by the server and is unique within the service from which the operation is created. +func (op *CreateServiceRolloutOperation) Name() string { + return op.lro.Name() +} + +// DeleteServiceOperation manages a long-running operation from DeleteService. +type DeleteServiceOperation struct { + lro *longrunning.Operation +} + +// DeleteServiceOperation returns a new DeleteServiceOperation from a given name. +// The name must be that of a previously created DeleteServiceOperation, possibly from a different process. +func (c *ServiceManagerClient) DeleteServiceOperation(name string) *DeleteServiceOperation { + return &DeleteServiceOperation{ + lro: longrunning.InternalNewOperation(c.LROClient, &longrunningpb.Operation{Name: name}), + } +} + +// Wait blocks until the long-running operation is completed, returning the response and any errors encountered. +// +// See documentation of Poll for error-handling information. +func (op *DeleteServiceOperation) Wait(ctx context.Context, opts ...gax.CallOption) error { + return op.lro.WaitWithInterval(ctx, nil, time.Minute, opts...) +} + +// Poll fetches the latest state of the long-running operation. +// +// Poll also fetches the latest metadata, which can be retrieved by Metadata. +// +// If Poll fails, the error is returned and op is unmodified. If Poll succeeds and +// the operation has completed with failure, the error is returned and op.Done will return true. +// If Poll succeeds and the operation has completed successfully, +// op.Done will return true, and the response of the operation is returned. +// If Poll succeeds and the operation has not completed, the returned response and error are both nil. +func (op *DeleteServiceOperation) Poll(ctx context.Context, opts ...gax.CallOption) error { + return op.lro.Poll(ctx, nil, opts...) +} + +// Metadata returns metadata associated with the long-running operation. +// Metadata itself does not contact the server, but Poll does. +// To get the latest metadata, call this method after a successful call to Poll. +// If the metadata is not available, the returned metadata and error are both nil. +func (op *DeleteServiceOperation) Metadata() (*servicemanagementpb.OperationMetadata, error) { + var meta servicemanagementpb.OperationMetadata + if err := op.lro.Metadata(&meta); err == longrunning.ErrNoMetadata { + return nil, nil + } else if err != nil { + return nil, err + } + return &meta, nil +} + +// Done reports whether the long-running operation has completed. +func (op *DeleteServiceOperation) Done() bool { + return op.lro.Done() +} + +// Name returns the name of the long-running operation. +// The name is assigned by the server and is unique within the service from which the operation is created. +func (op *DeleteServiceOperation) Name() string { + return op.lro.Name() +} + +// DisableServiceOperation manages a long-running operation from DisableService. +type DisableServiceOperation struct { + lro *longrunning.Operation +} + +// DisableServiceOperation returns a new DisableServiceOperation from a given name. +// The name must be that of a previously created DisableServiceOperation, possibly from a different process. +func (c *ServiceManagerClient) DisableServiceOperation(name string) *DisableServiceOperation { + return &DisableServiceOperation{ + lro: longrunning.InternalNewOperation(c.LROClient, &longrunningpb.Operation{Name: name}), + } +} + +// Wait blocks until the long-running operation is completed, returning the response and any errors encountered. +// +// See documentation of Poll for error-handling information. +func (op *DisableServiceOperation) Wait(ctx context.Context, opts ...gax.CallOption) (*servicemanagementpb.DisableServiceResponse, error) { + var resp servicemanagementpb.DisableServiceResponse + if err := op.lro.WaitWithInterval(ctx, &resp, time.Minute, opts...); err != nil { + return nil, err + } + return &resp, nil +} + +// Poll fetches the latest state of the long-running operation. +// +// Poll also fetches the latest metadata, which can be retrieved by Metadata. +// +// If Poll fails, the error is returned and op is unmodified. If Poll succeeds and +// the operation has completed with failure, the error is returned and op.Done will return true. +// If Poll succeeds and the operation has completed successfully, +// op.Done will return true, and the response of the operation is returned. +// If Poll succeeds and the operation has not completed, the returned response and error are both nil. +func (op *DisableServiceOperation) Poll(ctx context.Context, opts ...gax.CallOption) (*servicemanagementpb.DisableServiceResponse, error) { + var resp servicemanagementpb.DisableServiceResponse + if err := op.lro.Poll(ctx, &resp, opts...); err != nil { + return nil, err + } + if !op.Done() { + return nil, nil + } + return &resp, nil +} + +// Metadata returns metadata associated with the long-running operation. +// Metadata itself does not contact the server, but Poll does. +// To get the latest metadata, call this method after a successful call to Poll. +// If the metadata is not available, the returned metadata and error are both nil. +func (op *DisableServiceOperation) Metadata() (*servicemanagementpb.OperationMetadata, error) { + var meta servicemanagementpb.OperationMetadata + if err := op.lro.Metadata(&meta); err == longrunning.ErrNoMetadata { + return nil, nil + } else if err != nil { + return nil, err + } + return &meta, nil +} + +// Done reports whether the long-running operation has completed. +func (op *DisableServiceOperation) Done() bool { + return op.lro.Done() +} + +// Name returns the name of the long-running operation. +// The name is assigned by the server and is unique within the service from which the operation is created. +func (op *DisableServiceOperation) Name() string { + return op.lro.Name() +} + +// EnableServiceOperation manages a long-running operation from EnableService. +type EnableServiceOperation struct { + lro *longrunning.Operation +} + +// EnableServiceOperation returns a new EnableServiceOperation from a given name. +// The name must be that of a previously created EnableServiceOperation, possibly from a different process. +func (c *ServiceManagerClient) EnableServiceOperation(name string) *EnableServiceOperation { + return &EnableServiceOperation{ + lro: longrunning.InternalNewOperation(c.LROClient, &longrunningpb.Operation{Name: name}), + } +} + +// Wait blocks until the long-running operation is completed, returning the response and any errors encountered. +// +// See documentation of Poll for error-handling information. +func (op *EnableServiceOperation) Wait(ctx context.Context, opts ...gax.CallOption) (*servicemanagementpb.EnableServiceResponse, error) { + var resp servicemanagementpb.EnableServiceResponse + if err := op.lro.WaitWithInterval(ctx, &resp, time.Minute, opts...); err != nil { + return nil, err + } + return &resp, nil +} + +// Poll fetches the latest state of the long-running operation. +// +// Poll also fetches the latest metadata, which can be retrieved by Metadata. +// +// If Poll fails, the error is returned and op is unmodified. If Poll succeeds and +// the operation has completed with failure, the error is returned and op.Done will return true. +// If Poll succeeds and the operation has completed successfully, +// op.Done will return true, and the response of the operation is returned. +// If Poll succeeds and the operation has not completed, the returned response and error are both nil. +func (op *EnableServiceOperation) Poll(ctx context.Context, opts ...gax.CallOption) (*servicemanagementpb.EnableServiceResponse, error) { + var resp servicemanagementpb.EnableServiceResponse + if err := op.lro.Poll(ctx, &resp, opts...); err != nil { + return nil, err + } + if !op.Done() { + return nil, nil + } + return &resp, nil +} + +// Metadata returns metadata associated with the long-running operation. +// Metadata itself does not contact the server, but Poll does. +// To get the latest metadata, call this method after a successful call to Poll. +// If the metadata is not available, the returned metadata and error are both nil. +func (op *EnableServiceOperation) Metadata() (*servicemanagementpb.OperationMetadata, error) { + var meta servicemanagementpb.OperationMetadata + if err := op.lro.Metadata(&meta); err == longrunning.ErrNoMetadata { + return nil, nil + } else if err != nil { + return nil, err + } + return &meta, nil +} + +// Done reports whether the long-running operation has completed. +func (op *EnableServiceOperation) Done() bool { + return op.lro.Done() +} + +// Name returns the name of the long-running operation. +// The name is assigned by the server and is unique within the service from which the operation is created. +func (op *EnableServiceOperation) Name() string { + return op.lro.Name() +} + +// SubmitConfigSourceOperation manages a long-running operation from SubmitConfigSource. +type SubmitConfigSourceOperation struct { + lro *longrunning.Operation +} + +// SubmitConfigSourceOperation returns a new SubmitConfigSourceOperation from a given name. +// The name must be that of a previously created SubmitConfigSourceOperation, possibly from a different process. +func (c *ServiceManagerClient) SubmitConfigSourceOperation(name string) *SubmitConfigSourceOperation { + return &SubmitConfigSourceOperation{ + lro: longrunning.InternalNewOperation(c.LROClient, &longrunningpb.Operation{Name: name}), + } +} + +// Wait blocks until the long-running operation is completed, returning the response and any errors encountered. +// +// See documentation of Poll for error-handling information. +func (op *SubmitConfigSourceOperation) Wait(ctx context.Context, opts ...gax.CallOption) (*servicemanagementpb.SubmitConfigSourceResponse, error) { + var resp servicemanagementpb.SubmitConfigSourceResponse + if err := op.lro.WaitWithInterval(ctx, &resp, time.Minute, opts...); err != nil { + return nil, err + } + return &resp, nil +} + +// Poll fetches the latest state of the long-running operation. +// +// Poll also fetches the latest metadata, which can be retrieved by Metadata. +// +// If Poll fails, the error is returned and op is unmodified. If Poll succeeds and +// the operation has completed with failure, the error is returned and op.Done will return true. +// If Poll succeeds and the operation has completed successfully, +// op.Done will return true, and the response of the operation is returned. +// If Poll succeeds and the operation has not completed, the returned response and error are both nil. +func (op *SubmitConfigSourceOperation) Poll(ctx context.Context, opts ...gax.CallOption) (*servicemanagementpb.SubmitConfigSourceResponse, error) { + var resp servicemanagementpb.SubmitConfigSourceResponse + if err := op.lro.Poll(ctx, &resp, opts...); err != nil { + return nil, err + } + if !op.Done() { + return nil, nil + } + return &resp, nil +} + +// Metadata returns metadata associated with the long-running operation. +// Metadata itself does not contact the server, but Poll does. +// To get the latest metadata, call this method after a successful call to Poll. +// If the metadata is not available, the returned metadata and error are both nil. +func (op *SubmitConfigSourceOperation) Metadata() (*servicemanagementpb.OperationMetadata, error) { + var meta servicemanagementpb.OperationMetadata + if err := op.lro.Metadata(&meta); err == longrunning.ErrNoMetadata { + return nil, nil + } else if err != nil { + return nil, err + } + return &meta, nil +} + +// Done reports whether the long-running operation has completed. +func (op *SubmitConfigSourceOperation) Done() bool { + return op.lro.Done() +} + +// Name returns the name of the long-running operation. +// The name is assigned by the server and is unique within the service from which the operation is created. +func (op *SubmitConfigSourceOperation) Name() string { + return op.lro.Name() +} + +// UndeleteServiceOperation manages a long-running operation from UndeleteService. +type UndeleteServiceOperation struct { + lro *longrunning.Operation +} + +// UndeleteServiceOperation returns a new UndeleteServiceOperation from a given name. +// The name must be that of a previously created UndeleteServiceOperation, possibly from a different process. +func (c *ServiceManagerClient) UndeleteServiceOperation(name string) *UndeleteServiceOperation { + return &UndeleteServiceOperation{ + lro: longrunning.InternalNewOperation(c.LROClient, &longrunningpb.Operation{Name: name}), + } +} + +// Wait blocks until the long-running operation is completed, returning the response and any errors encountered. +// +// See documentation of Poll for error-handling information. +func (op *UndeleteServiceOperation) Wait(ctx context.Context, opts ...gax.CallOption) (*servicemanagementpb.UndeleteServiceResponse, error) { + var resp servicemanagementpb.UndeleteServiceResponse + if err := op.lro.WaitWithInterval(ctx, &resp, time.Minute, opts...); err != nil { + return nil, err + } + return &resp, nil +} + +// Poll fetches the latest state of the long-running operation. +// +// Poll also fetches the latest metadata, which can be retrieved by Metadata. +// +// If Poll fails, the error is returned and op is unmodified. If Poll succeeds and +// the operation has completed with failure, the error is returned and op.Done will return true. +// If Poll succeeds and the operation has completed successfully, +// op.Done will return true, and the response of the operation is returned. +// If Poll succeeds and the operation has not completed, the returned response and error are both nil. +func (op *UndeleteServiceOperation) Poll(ctx context.Context, opts ...gax.CallOption) (*servicemanagementpb.UndeleteServiceResponse, error) { + var resp servicemanagementpb.UndeleteServiceResponse + if err := op.lro.Poll(ctx, &resp, opts...); err != nil { + return nil, err + } + if !op.Done() { + return nil, nil + } + return &resp, nil +} + +// Metadata returns metadata associated with the long-running operation. +// Metadata itself does not contact the server, but Poll does. +// To get the latest metadata, call this method after a successful call to Poll. +// If the metadata is not available, the returned metadata and error are both nil. +func (op *UndeleteServiceOperation) Metadata() (*servicemanagementpb.OperationMetadata, error) { + var meta servicemanagementpb.OperationMetadata + if err := op.lro.Metadata(&meta); err == longrunning.ErrNoMetadata { + return nil, nil + } else if err != nil { + return nil, err + } + return &meta, nil +} + +// Done reports whether the long-running operation has completed. +func (op *UndeleteServiceOperation) Done() bool { + return op.lro.Done() +} + +// Name returns the name of the long-running operation. +// The name is assigned by the server and is unique within the service from which the operation is created. +func (op *UndeleteServiceOperation) Name() string { + return op.lro.Name() +} + +// ManagedServiceIterator manages a stream of *servicemanagementpb.ManagedService. +type ManagedServiceIterator struct { + items []*servicemanagementpb.ManagedService + pageInfo *iterator.PageInfo + nextFunc func() error + + // Response is the raw response for the current page. + // It must be cast to the RPC response type. + // Calling Next() or InternalFetch() updates this value. + Response interface{} + + // InternalFetch is for use by the Google Cloud Libraries only. + // It is not part of the stable interface of this package. + // + // InternalFetch returns results from a single call to the underlying RPC. + // The number of results is no greater than pageSize. + // If there are no more results, nextPageToken is empty and err is nil. + InternalFetch func(pageSize int, pageToken string) (results []*servicemanagementpb.ManagedService, nextPageToken string, err error) +} + +// PageInfo supports pagination. See the google.golang.org/api/iterator package for details. +func (it *ManagedServiceIterator) PageInfo() *iterator.PageInfo { + return it.pageInfo +} + +// Next returns the next result. Its second return value is iterator.Done if there are no more +// results. Once Next returns Done, all subsequent calls will return Done. +func (it *ManagedServiceIterator) Next() (*servicemanagementpb.ManagedService, error) { + var item *servicemanagementpb.ManagedService + if err := it.nextFunc(); err != nil { + return item, err + } + item = it.items[0] + it.items = it.items[1:] + return item, nil +} + +func (it *ManagedServiceIterator) bufLen() int { + return len(it.items) +} + +func (it *ManagedServiceIterator) takeBuf() interface{} { + b := it.items + it.items = nil + return b +} + +// RolloutIterator manages a stream of *servicemanagementpb.Rollout. +type RolloutIterator struct { + items []*servicemanagementpb.Rollout + pageInfo *iterator.PageInfo + nextFunc func() error + + // Response is the raw response for the current page. + // It must be cast to the RPC response type. + // Calling Next() or InternalFetch() updates this value. + Response interface{} + + // InternalFetch is for use by the Google Cloud Libraries only. + // It is not part of the stable interface of this package. + // + // InternalFetch returns results from a single call to the underlying RPC. + // The number of results is no greater than pageSize. + // If there are no more results, nextPageToken is empty and err is nil. + InternalFetch func(pageSize int, pageToken string) (results []*servicemanagementpb.Rollout, nextPageToken string, err error) +} + +// PageInfo supports pagination. See the google.golang.org/api/iterator package for details. +func (it *RolloutIterator) PageInfo() *iterator.PageInfo { + return it.pageInfo +} + +// Next returns the next result. Its second return value is iterator.Done if there are no more +// results. Once Next returns Done, all subsequent calls will return Done. +func (it *RolloutIterator) Next() (*servicemanagementpb.Rollout, error) { + var item *servicemanagementpb.Rollout + if err := it.nextFunc(); err != nil { + return item, err + } + item = it.items[0] + it.items = it.items[1:] + return item, nil +} + +func (it *RolloutIterator) bufLen() int { + return len(it.items) +} + +func (it *RolloutIterator) takeBuf() interface{} { + b := it.items + it.items = nil + return b +} + +// ServiceIterator manages a stream of *serviceconfigpb.Service. +type ServiceIterator struct { + items []*serviceconfigpb.Service + pageInfo *iterator.PageInfo + nextFunc func() error + + // Response is the raw response for the current page. + // It must be cast to the RPC response type. + // Calling Next() or InternalFetch() updates this value. + Response interface{} + + // InternalFetch is for use by the Google Cloud Libraries only. + // It is not part of the stable interface of this package. + // + // InternalFetch returns results from a single call to the underlying RPC. + // The number of results is no greater than pageSize. + // If there are no more results, nextPageToken is empty and err is nil. + InternalFetch func(pageSize int, pageToken string) (results []*serviceconfigpb.Service, nextPageToken string, err error) +} + +// PageInfo supports pagination. See the google.golang.org/api/iterator package for details. +func (it *ServiceIterator) PageInfo() *iterator.PageInfo { + return it.pageInfo +} + +// Next returns the next result. Its second return value is iterator.Done if there are no more +// results. Once Next returns Done, all subsequent calls will return Done. +func (it *ServiceIterator) Next() (*serviceconfigpb.Service, error) { + var item *serviceconfigpb.Service + if err := it.nextFunc(); err != nil { + return item, err + } + item = it.items[0] + it.items = it.items[1:] + return item, nil +} + +func (it *ServiceIterator) bufLen() int { + return len(it.items) +} + +func (it *ServiceIterator) takeBuf() interface{} { + b := it.items + it.items = nil + return b +} diff --git a/servicemanagement/apiv1/service_manager_client_example_test.go b/servicemanagement/apiv1/service_manager_client_example_test.go new file mode 100644 index 00000000000..c85986c67d3 --- /dev/null +++ b/servicemanagement/apiv1/service_manager_client_example_test.go @@ -0,0 +1,389 @@ +// Copyright 2021 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Code generated by protoc-gen-go_gapic. DO NOT EDIT. + +package servicemanagement_test + +import ( + "context" + + servicemanagement "cloud.google.com/go/servicemanagement/apiv1" + "google.golang.org/api/iterator" + servicemanagementpb "google.golang.org/genproto/googleapis/api/servicemanagement/v1" +) + +func ExampleNewServiceManagerClient() { + ctx := context.Background() + c, err := servicemanagement.NewServiceManagerClient(ctx) + if err != nil { + // TODO: Handle error. + } + // TODO: Use client. + _ = c +} + +func ExampleServiceManagerClient_ListServices() { + // import servicemanagementpb "google.golang.org/genproto/googleapis/api/servicemanagement/v1" + // import "google.golang.org/api/iterator" + + ctx := context.Background() + c, err := servicemanagement.NewServiceManagerClient(ctx) + if err != nil { + // TODO: Handle error. + } + + req := &servicemanagementpb.ListServicesRequest{ + // TODO: Fill request struct fields. + } + it := c.ListServices(ctx, req) + for { + resp, err := it.Next() + if err == iterator.Done { + break + } + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp + } +} + +func ExampleServiceManagerClient_GetService() { + // import servicemanagementpb "google.golang.org/genproto/googleapis/api/servicemanagement/v1" + + ctx := context.Background() + c, err := servicemanagement.NewServiceManagerClient(ctx) + if err != nil { + // TODO: Handle error. + } + + req := &servicemanagementpb.GetServiceRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.GetService(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleServiceManagerClient_CreateService() { + // import servicemanagementpb "google.golang.org/genproto/googleapis/api/servicemanagement/v1" + + ctx := context.Background() + c, err := servicemanagement.NewServiceManagerClient(ctx) + if err != nil { + // TODO: Handle error. + } + + req := &servicemanagementpb.CreateServiceRequest{ + // TODO: Fill request struct fields. + } + op, err := c.CreateService(ctx, req) + if err != nil { + // TODO: Handle error. + } + + resp, err := op.Wait(ctx) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleServiceManagerClient_DeleteService() { + // import servicemanagementpb "google.golang.org/genproto/googleapis/api/servicemanagement/v1" + + ctx := context.Background() + c, err := servicemanagement.NewServiceManagerClient(ctx) + if err != nil { + // TODO: Handle error. + } + + req := &servicemanagementpb.DeleteServiceRequest{ + // TODO: Fill request struct fields. + } + op, err := c.DeleteService(ctx, req) + if err != nil { + // TODO: Handle error. + } + + err = op.Wait(ctx) + if err != nil { + // TODO: Handle error. + } +} + +func ExampleServiceManagerClient_UndeleteService() { + // import servicemanagementpb "google.golang.org/genproto/googleapis/api/servicemanagement/v1" + + ctx := context.Background() + c, err := servicemanagement.NewServiceManagerClient(ctx) + if err != nil { + // TODO: Handle error. + } + + req := &servicemanagementpb.UndeleteServiceRequest{ + // TODO: Fill request struct fields. + } + op, err := c.UndeleteService(ctx, req) + if err != nil { + // TODO: Handle error. + } + + resp, err := op.Wait(ctx) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleServiceManagerClient_ListServiceConfigs() { + // import servicemanagementpb "google.golang.org/genproto/googleapis/api/servicemanagement/v1" + // import "google.golang.org/api/iterator" + + ctx := context.Background() + c, err := servicemanagement.NewServiceManagerClient(ctx) + if err != nil { + // TODO: Handle error. + } + + req := &servicemanagementpb.ListServiceConfigsRequest{ + // TODO: Fill request struct fields. + } + it := c.ListServiceConfigs(ctx, req) + for { + resp, err := it.Next() + if err == iterator.Done { + break + } + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp + } +} + +func ExampleServiceManagerClient_GetServiceConfig() { + // import servicemanagementpb "google.golang.org/genproto/googleapis/api/servicemanagement/v1" + + ctx := context.Background() + c, err := servicemanagement.NewServiceManagerClient(ctx) + if err != nil { + // TODO: Handle error. + } + + req := &servicemanagementpb.GetServiceConfigRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.GetServiceConfig(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleServiceManagerClient_CreateServiceConfig() { + // import servicemanagementpb "google.golang.org/genproto/googleapis/api/servicemanagement/v1" + + ctx := context.Background() + c, err := servicemanagement.NewServiceManagerClient(ctx) + if err != nil { + // TODO: Handle error. + } + + req := &servicemanagementpb.CreateServiceConfigRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.CreateServiceConfig(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleServiceManagerClient_SubmitConfigSource() { + // import servicemanagementpb "google.golang.org/genproto/googleapis/api/servicemanagement/v1" + + ctx := context.Background() + c, err := servicemanagement.NewServiceManagerClient(ctx) + if err != nil { + // TODO: Handle error. + } + + req := &servicemanagementpb.SubmitConfigSourceRequest{ + // TODO: Fill request struct fields. + } + op, err := c.SubmitConfigSource(ctx, req) + if err != nil { + // TODO: Handle error. + } + + resp, err := op.Wait(ctx) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleServiceManagerClient_ListServiceRollouts() { + // import servicemanagementpb "google.golang.org/genproto/googleapis/api/servicemanagement/v1" + // import "google.golang.org/api/iterator" + + ctx := context.Background() + c, err := servicemanagement.NewServiceManagerClient(ctx) + if err != nil { + // TODO: Handle error. + } + + req := &servicemanagementpb.ListServiceRolloutsRequest{ + // TODO: Fill request struct fields. + } + it := c.ListServiceRollouts(ctx, req) + for { + resp, err := it.Next() + if err == iterator.Done { + break + } + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp + } +} + +func ExampleServiceManagerClient_GetServiceRollout() { + // import servicemanagementpb "google.golang.org/genproto/googleapis/api/servicemanagement/v1" + + ctx := context.Background() + c, err := servicemanagement.NewServiceManagerClient(ctx) + if err != nil { + // TODO: Handle error. + } + + req := &servicemanagementpb.GetServiceRolloutRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.GetServiceRollout(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleServiceManagerClient_CreateServiceRollout() { + // import servicemanagementpb "google.golang.org/genproto/googleapis/api/servicemanagement/v1" + + ctx := context.Background() + c, err := servicemanagement.NewServiceManagerClient(ctx) + if err != nil { + // TODO: Handle error. + } + + req := &servicemanagementpb.CreateServiceRolloutRequest{ + // TODO: Fill request struct fields. + } + op, err := c.CreateServiceRollout(ctx, req) + if err != nil { + // TODO: Handle error. + } + + resp, err := op.Wait(ctx) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleServiceManagerClient_GenerateConfigReport() { + // import servicemanagementpb "google.golang.org/genproto/googleapis/api/servicemanagement/v1" + + ctx := context.Background() + c, err := servicemanagement.NewServiceManagerClient(ctx) + if err != nil { + // TODO: Handle error. + } + + req := &servicemanagementpb.GenerateConfigReportRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.GenerateConfigReport(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleServiceManagerClient_EnableService() { + // import servicemanagementpb "google.golang.org/genproto/googleapis/api/servicemanagement/v1" + + ctx := context.Background() + c, err := servicemanagement.NewServiceManagerClient(ctx) + if err != nil { + // TODO: Handle error. + } + + req := &servicemanagementpb.EnableServiceRequest{ + // TODO: Fill request struct fields. + } + op, err := c.EnableService(ctx, req) + if err != nil { + // TODO: Handle error. + } + + resp, err := op.Wait(ctx) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleServiceManagerClient_DisableService() { + // import servicemanagementpb "google.golang.org/genproto/googleapis/api/servicemanagement/v1" + + ctx := context.Background() + c, err := servicemanagement.NewServiceManagerClient(ctx) + if err != nil { + // TODO: Handle error. + } + + req := &servicemanagementpb.DisableServiceRequest{ + // TODO: Fill request struct fields. + } + op, err := c.DisableService(ctx, req) + if err != nil { + // TODO: Handle error. + } + + resp, err := op.Wait(ctx) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +}