diff --git a/internal/.repo-metadata-full.json b/internal/.repo-metadata-full.json index 8987f0c59e5..982d685ef5f 100644 --- a/internal/.repo-metadata-full.json +++ b/internal/.repo-metadata-full.json @@ -622,7 +622,7 @@ }, "cloud.google.com/go/language/apiv1beta2": { "distribution_name": "cloud.google.com/go/language/apiv1beta2", - "description": "Cloud Natural Language API", + "description": "Google Cloud Natural Language API", "language": "Go", "client_library_type": "generated", "docs_url": "https://cloud.google.com/go/docs/reference/cloud.google.com/go/latest/language/apiv1beta2", @@ -845,6 +845,15 @@ "release_level": "ga", "library_type": "" }, + "cloud.google.com/go/privatecatalog/apiv1beta1": { + "distribution_name": "cloud.google.com/go/privatecatalog/apiv1beta1", + "description": "Cloud Private Catalog API", + "language": "Go", + "client_library_type": "generated", + "docs_url": "https://cloud.google.com/go/docs/reference/cloud.google.com/go/latest/privatecatalog/apiv1beta1", + "release_level": "beta", + "library_type": "" + }, "cloud.google.com/go/profiler": { "distribution_name": "cloud.google.com/go/profiler", "description": "Cloud Profiler", @@ -1124,6 +1133,15 @@ "release_level": "beta", "library_type": "" }, + "cloud.google.com/go/shell/apiv1": { + "distribution_name": "cloud.google.com/go/shell/apiv1", + "description": "Cloud Shell API", + "language": "Go", + "client_library_type": "generated", + "docs_url": "https://cloud.google.com/go/docs/reference/cloud.google.com/go/latest/shell/apiv1", + "release_level": "beta", + "library_type": "" + }, "cloud.google.com/go/spanner": { "distribution_name": "cloud.google.com/go/spanner", "description": "Cloud Spanner", @@ -1286,6 +1304,15 @@ "release_level": "beta", "library_type": "" }, + "cloud.google.com/go/vpcaccess/apiv1": { + "distribution_name": "cloud.google.com/go/vpcaccess/apiv1", + "description": "Serverless VPC Access API", + "language": "Go", + "client_library_type": "generated", + "docs_url": "https://cloud.google.com/go/docs/reference/cloud.google.com/go/latest/vpcaccess/apiv1", + "release_level": "beta", + "library_type": "" + }, "cloud.google.com/go/webrisk/apiv1": { "distribution_name": "cloud.google.com/go/webrisk/apiv1", "description": "Web Risk API", diff --git a/internal/gapicgen/generator/config.go b/internal/gapicgen/generator/config.go index e37bbe088dc..914cae69ef3 100644 --- a/internal/gapicgen/generator/config.go +++ b/internal/gapicgen/generator/config.go @@ -79,7 +79,7 @@ var microgenGapicConfigs = []*microgenConfig{ pkg: "language", importPath: "cloud.google.com/go/language/apiv1", gRPCServiceConfigPath: "google/cloud/language/v1/language_grpc_service_config.json", - apiServiceConfigPath: "google/cloud/language/language_v1.yaml", + apiServiceConfigPath: "google/cloud/language/v1/language_v1.yaml", releaseLevel: "ga", }, { @@ -1099,6 +1099,32 @@ var microgenGapicConfigs = []*microgenConfig{ // GA after 2021/06/18 releaseLevel: "beta", }, + { + inputDirectoryPath: "google/cloud/shell/v1", + pkg: "shell", + importPath: "cloud.google.com/go/shell/apiv1", + gRPCServiceConfigPath: "google/cloud/shell/v1/cloudshell_grpc_service_config.json", + apiServiceConfigPath: "google/cloud/shell/v1/cloudshell_v1.yaml", + // GA after 2021/06/26 + releaseLevel: "beta", + }, + { + inputDirectoryPath: "google/cloud/vpcaccess/v1", + pkg: "vpcaccess", + importPath: "cloud.google.com/go/vpcaccess/apiv1", + gRPCServiceConfigPath: "google/cloud/vpcaccess/v1/vpcaccess_grpc_service_config.json", + apiServiceConfigPath: "google/cloud/vpcaccess/v1/vpcaccess_v1.yaml", + // GA after 2021/06/26 + releaseLevel: "beta", + }, + { + inputDirectoryPath: "google/cloud/privatecatalog/v1beta1", + pkg: "privatecatalog", + importPath: "cloud.google.com/go/privatecatalog/apiv1beta1", + gRPCServiceConfigPath: "google/cloud/privatecatalog/v1beta1/cloudprivatecatalog_grpc_service_config.json", + apiServiceConfigPath: "google/cloud/privatecatalog/v1beta1/cloudprivatecatalog_v1beta1.yaml", + releaseLevel: "beta", + }, // Non-Cloud APIs { diff --git a/internal/gapicgen/generator/gapics.go b/internal/gapicgen/generator/gapics.go index eb8987ac0c6..8362dffc32b 100644 --- a/internal/gapicgen/generator/gapics.go +++ b/internal/gapicgen/generator/gapics.go @@ -64,7 +64,7 @@ func (g *GapicGenerator) Regen(ctx context.Context) error { // config has a block on it. Or if generating a single gapic and it does // not match the specified import path. if (c.stopGeneration && g.gapicToGenerate == "") || - (g.gapicToGenerate != "" && g.gapicToGenerate != c.importPath) { + (g.gapicToGenerate != "" && !strings.Contains(g.gapicToGenerate, c.importPath)) { continue } if err := g.microgen(c); err != nil { diff --git a/privatecatalog/apiv1beta1/doc.go b/privatecatalog/apiv1beta1/doc.go new file mode 100644 index 00000000000..e12dfedeb32 --- /dev/null +++ b/privatecatalog/apiv1beta1/doc.go @@ -0,0 +1,119 @@ +// 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 privatecatalog is an auto-generated package for the +// Cloud Private Catalog API. +// +// Enable cloud users to discover private catalogs and products in their +// organizations. +// +// NOTE: This package is in beta. It is not stable, and may be subject to changes. +// +// 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 https://pkg.go.dev/cloud.google.com/go. +package privatecatalog // import "cloud.google.com/go/privatecatalog/apiv1beta1" + +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 = "20210526" + +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", + } +} + +// 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/privatecatalog/apiv1beta1/gapic_metadata.json b/privatecatalog/apiv1beta1/gapic_metadata.json new file mode 100644 index 00000000000..a549a3afcb2 --- /dev/null +++ b/privatecatalog/apiv1beta1/gapic_metadata.json @@ -0,0 +1,33 @@ +{ + "schema": "1.0", + "comment": "This file maps proto services/RPCs to the corresponding library clients/methods.", + "language": "go", + "protoPackage": "google.cloud.privatecatalog.v1beta1", + "libraryPackage": "cloud.google.com/go/privatecatalog/apiv1beta1", + "services": { + "PrivateCatalog": { + "clients": { + "grpc": { + "libraryClient": "Client", + "rpcs": { + "SearchCatalogs": { + "methods": [ + "SearchCatalogs" + ] + }, + "SearchProducts": { + "methods": [ + "SearchProducts" + ] + }, + "SearchVersions": { + "methods": [ + "SearchVersions" + ] + } + } + } + } + } + } +} diff --git a/privatecatalog/apiv1beta1/private_catalog_client.go b/privatecatalog/apiv1beta1/private_catalog_client.go new file mode 100644 index 00000000000..2f848409fcb --- /dev/null +++ b/privatecatalog/apiv1beta1/private_catalog_client.go @@ -0,0 +1,506 @@ +// 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 privatecatalog + +import ( + "context" + "fmt" + "math" + "net/url" + + "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" + privatecatalogpb "google.golang.org/genproto/googleapis/cloud/privatecatalog/v1beta1" + "google.golang.org/grpc" + "google.golang.org/grpc/metadata" +) + +var newClientHook clientHook + +// CallOptions contains the retry settings for each method of Client. +type CallOptions struct { + SearchCatalogs []gax.CallOption + SearchProducts []gax.CallOption + SearchVersions []gax.CallOption +} + +func defaultGRPCClientOptions() []option.ClientOption { + return []option.ClientOption{ + internaloption.WithDefaultEndpoint("cloudprivatecatalog.googleapis.com:443"), + internaloption.WithDefaultMTLSEndpoint("cloudprivatecatalog.mtls.googleapis.com:443"), + internaloption.WithDefaultAudience("https://cloudprivatecatalog.googleapis.com/"), + internaloption.WithDefaultScopes(DefaultAuthScopes()...), + option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), + option.WithGRPCDialOption(grpc.WithDefaultCallOptions( + grpc.MaxCallRecvMsgSize(math.MaxInt32))), + } +} + +func defaultCallOptions() *CallOptions { + return &CallOptions{ + SearchCatalogs: []gax.CallOption{}, + SearchProducts: []gax.CallOption{}, + SearchVersions: []gax.CallOption{}, + } +} + +// internalClient is an interface that defines the methods availaible from Cloud Private Catalog API. +type internalClient interface { + Close() error + setGoogleClientInfo(...string) + Connection() *grpc.ClientConn + SearchCatalogs(context.Context, *privatecatalogpb.SearchCatalogsRequest, ...gax.CallOption) *CatalogIterator + SearchProducts(context.Context, *privatecatalogpb.SearchProductsRequest, ...gax.CallOption) *ProductIterator + SearchVersions(context.Context, *privatecatalogpb.SearchVersionsRequest, ...gax.CallOption) *VersionIterator +} + +// Client is a client for interacting with Cloud Private Catalog API. +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +// +// PrivateCatalog allows catalog consumers to retrieve Catalog, Product +// and Version resources under a target resource context. +// +// Catalog is computed based on the Associations linked to the target +// resource and its ancestors. Each association’s +// google.cloud.privatecatalogproducer.v1beta.Catalog is transformed into a +// Catalog. If multiple associations have the same parent +// google.cloud.privatecatalogproducer.v1beta.Catalog, they are +// de-duplicated into one Catalog. Users must have +// cloudprivatecatalog.catalogTargets.get IAM permission on the resource +// context in order to access catalogs. Catalog contains the resource name and +// a subset of data of the original +// google.cloud.privatecatalogproducer.v1beta.Catalog. +// +// Product is child resource of the catalog. A Product contains the resource +// name and a subset of the data of the original +// google.cloud.privatecatalogproducer.v1beta.Product. +// +// Version is child resource of the product. A Version contains the resource +// name and a subset of the data of the original +// google.cloud.privatecatalogproducer.v1beta.Version. +type Client struct { + // The internal transport-dependent client. + internalClient internalClient + + // The call options for this service. + CallOptions *CallOptions +} + +// Wrapper methods routed to the internal client. + +// Close closes the connection to the API service. The user should invoke this when +// the client is no longer required. +func (c *Client) Close() error { + return c.internalClient.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 *Client) setGoogleClientInfo(keyval ...string) { + c.internalClient.setGoogleClientInfo(keyval...) +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *Client) Connection() *grpc.ClientConn { + return c.internalClient.Connection() +} + +// SearchCatalogs search Catalog resources that consumers have access to, within the +// scope of the consumer cloud resource hierarchy context. +func (c *Client) SearchCatalogs(ctx context.Context, req *privatecatalogpb.SearchCatalogsRequest, opts ...gax.CallOption) *CatalogIterator { + return c.internalClient.SearchCatalogs(ctx, req, opts...) +} + +// SearchProducts search Product resources that consumers have access to, within the +// scope of the consumer cloud resource hierarchy context. +func (c *Client) SearchProducts(ctx context.Context, req *privatecatalogpb.SearchProductsRequest, opts ...gax.CallOption) *ProductIterator { + return c.internalClient.SearchProducts(ctx, req, opts...) +} + +// SearchVersions search Version resources that consumers have access to, within the +// scope of the consumer cloud resource hierarchy context. +func (c *Client) SearchVersions(ctx context.Context, req *privatecatalogpb.SearchVersionsRequest, opts ...gax.CallOption) *VersionIterator { + return c.internalClient.SearchVersions(ctx, req, opts...) +} + +// gRPCClient is a client for interacting with Cloud Private Catalog API over gRPC transport. +// +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +type gRPCClient 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 + + // Points back to the CallOptions field of the containing Client + CallOptions **CallOptions + + // The gRPC API client. + client privatecatalogpb.PrivateCatalogClient + + // The x-goog-* metadata to be sent with each request. + xGoogMetadata metadata.MD +} + +// NewClient creates a new private catalog client based on gRPC. +// The returned client must be Closed when it is done being used to clean up its underlying connections. +// +// PrivateCatalog allows catalog consumers to retrieve Catalog, Product +// and Version resources under a target resource context. +// +// Catalog is computed based on the Associations linked to the target +// resource and its ancestors. Each association’s +// google.cloud.privatecatalogproducer.v1beta.Catalog is transformed into a +// Catalog. If multiple associations have the same parent +// google.cloud.privatecatalogproducer.v1beta.Catalog, they are +// de-duplicated into one Catalog. Users must have +// cloudprivatecatalog.catalogTargets.get IAM permission on the resource +// context in order to access catalogs. Catalog contains the resource name and +// a subset of data of the original +// google.cloud.privatecatalogproducer.v1beta.Catalog. +// +// Product is child resource of the catalog. A Product contains the resource +// name and a subset of the data of the original +// google.cloud.privatecatalogproducer.v1beta.Product. +// +// Version is child resource of the product. A Version contains the resource +// name and a subset of the data of the original +// google.cloud.privatecatalogproducer.v1beta.Version. +func NewClient(ctx context.Context, opts ...option.ClientOption) (*Client, error) { + clientOpts := defaultGRPCClientOptions() + if newClientHook != nil { + hookOpts, err := newClientHook(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 + } + client := Client{CallOptions: defaultCallOptions()} + + c := &gRPCClient{ + connPool: connPool, + disableDeadlines: disableDeadlines, + client: privatecatalogpb.NewPrivateCatalogClient(connPool), + CallOptions: &client.CallOptions, + } + c.setGoogleClientInfo() + + client.internalClient = c + + return &client, nil +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *gRPCClient) Connection() *grpc.ClientConn { + return c.connPool.Conn() +} + +// 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 *gRPCClient) 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...)) +} + +// Close closes the connection to the API service. The user should invoke this when +// the client is no longer required. +func (c *gRPCClient) Close() error { + return c.connPool.Close() +} + +func (c *gRPCClient) SearchCatalogs(ctx context.Context, req *privatecatalogpb.SearchCatalogsRequest, opts ...gax.CallOption) *CatalogIterator { + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))) + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append((*c.CallOptions).SearchCatalogs[0:len((*c.CallOptions).SearchCatalogs):len((*c.CallOptions).SearchCatalogs)], opts...) + it := &CatalogIterator{} + req = proto.Clone(req).(*privatecatalogpb.SearchCatalogsRequest) + it.InternalFetch = func(pageSize int, pageToken string) ([]*privatecatalogpb.Catalog, string, error) { + var resp *privatecatalogpb.SearchCatalogsResponse + 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.client.SearchCatalogs(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, "", err + } + + it.Response = resp + return resp.GetCatalogs(), 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 +} + +func (c *gRPCClient) SearchProducts(ctx context.Context, req *privatecatalogpb.SearchProductsRequest, opts ...gax.CallOption) *ProductIterator { + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))) + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append((*c.CallOptions).SearchProducts[0:len((*c.CallOptions).SearchProducts):len((*c.CallOptions).SearchProducts)], opts...) + it := &ProductIterator{} + req = proto.Clone(req).(*privatecatalogpb.SearchProductsRequest) + it.InternalFetch = func(pageSize int, pageToken string) ([]*privatecatalogpb.Product, string, error) { + var resp *privatecatalogpb.SearchProductsResponse + 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.client.SearchProducts(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, "", err + } + + it.Response = resp + return resp.GetProducts(), 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 +} + +func (c *gRPCClient) SearchVersions(ctx context.Context, req *privatecatalogpb.SearchVersionsRequest, opts ...gax.CallOption) *VersionIterator { + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))) + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append((*c.CallOptions).SearchVersions[0:len((*c.CallOptions).SearchVersions):len((*c.CallOptions).SearchVersions)], opts...) + it := &VersionIterator{} + req = proto.Clone(req).(*privatecatalogpb.SearchVersionsRequest) + it.InternalFetch = func(pageSize int, pageToken string) ([]*privatecatalogpb.Version, string, error) { + var resp *privatecatalogpb.SearchVersionsResponse + 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.client.SearchVersions(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, "", err + } + + it.Response = resp + return resp.GetVersions(), 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 +} + +// CatalogIterator manages a stream of *privatecatalogpb.Catalog. +type CatalogIterator struct { + items []*privatecatalogpb.Catalog + 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 []*privatecatalogpb.Catalog, nextPageToken string, err error) +} + +// PageInfo supports pagination. See the google.golang.org/api/iterator package for details. +func (it *CatalogIterator) 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 *CatalogIterator) Next() (*privatecatalogpb.Catalog, error) { + var item *privatecatalogpb.Catalog + if err := it.nextFunc(); err != nil { + return item, err + } + item = it.items[0] + it.items = it.items[1:] + return item, nil +} + +func (it *CatalogIterator) bufLen() int { + return len(it.items) +} + +func (it *CatalogIterator) takeBuf() interface{} { + b := it.items + it.items = nil + return b +} + +// ProductIterator manages a stream of *privatecatalogpb.Product. +type ProductIterator struct { + items []*privatecatalogpb.Product + 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 []*privatecatalogpb.Product, nextPageToken string, err error) +} + +// PageInfo supports pagination. See the google.golang.org/api/iterator package for details. +func (it *ProductIterator) 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 *ProductIterator) Next() (*privatecatalogpb.Product, error) { + var item *privatecatalogpb.Product + if err := it.nextFunc(); err != nil { + return item, err + } + item = it.items[0] + it.items = it.items[1:] + return item, nil +} + +func (it *ProductIterator) bufLen() int { + return len(it.items) +} + +func (it *ProductIterator) takeBuf() interface{} { + b := it.items + it.items = nil + return b +} + +// VersionIterator manages a stream of *privatecatalogpb.Version. +type VersionIterator struct { + items []*privatecatalogpb.Version + 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 []*privatecatalogpb.Version, nextPageToken string, err error) +} + +// PageInfo supports pagination. See the google.golang.org/api/iterator package for details. +func (it *VersionIterator) 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 *VersionIterator) Next() (*privatecatalogpb.Version, error) { + var item *privatecatalogpb.Version + if err := it.nextFunc(); err != nil { + return item, err + } + item = it.items[0] + it.items = it.items[1:] + return item, nil +} + +func (it *VersionIterator) bufLen() int { + return len(it.items) +} + +func (it *VersionIterator) takeBuf() interface{} { + b := it.items + it.items = nil + return b +} diff --git a/privatecatalog/apiv1beta1/private_catalog_client_example_test.go b/privatecatalog/apiv1beta1/private_catalog_client_example_test.go new file mode 100644 index 00000000000..6e6bb62d3af --- /dev/null +++ b/privatecatalog/apiv1beta1/private_catalog_client_example_test.go @@ -0,0 +1,112 @@ +// 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 privatecatalog_test + +import ( + "context" + + privatecatalog "cloud.google.com/go/privatecatalog/apiv1beta1" + "google.golang.org/api/iterator" + privatecatalogpb "google.golang.org/genproto/googleapis/cloud/privatecatalog/v1beta1" +) + +func ExampleNewClient() { + ctx := context.Background() + c, err := privatecatalog.NewClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + // TODO: Use client. + _ = c +} + +func ExampleClient_SearchCatalogs() { + ctx := context.Background() + c, err := privatecatalog.NewClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &privatecatalogpb.SearchCatalogsRequest{ + // TODO: Fill request struct fields. + } + it := c.SearchCatalogs(ctx, req) + for { + resp, err := it.Next() + if err == iterator.Done { + break + } + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp + } +} + +func ExampleClient_SearchProducts() { + ctx := context.Background() + c, err := privatecatalog.NewClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &privatecatalogpb.SearchProductsRequest{ + // TODO: Fill request struct fields. + } + it := c.SearchProducts(ctx, req) + for { + resp, err := it.Next() + if err == iterator.Done { + break + } + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp + } +} + +func ExampleClient_SearchVersions() { + ctx := context.Background() + c, err := privatecatalog.NewClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &privatecatalogpb.SearchVersionsRequest{ + // TODO: Fill request struct fields. + } + it := c.SearchVersions(ctx, req) + for { + resp, err := it.Next() + if err == iterator.Done { + break + } + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp + } +} diff --git a/shell/apiv1/cloud_shell_client.go b/shell/apiv1/cloud_shell_client.go new file mode 100644 index 00000000000..8917de48634 --- /dev/null +++ b/shell/apiv1/cloud_shell_client.go @@ -0,0 +1,695 @@ +// 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 shell + +import ( + "context" + "fmt" + "math" + "net/url" + "time" + + "cloud.google.com/go/longrunning" + lroauto "cloud.google.com/go/longrunning/autogen" + gax "github.com/googleapis/gax-go/v2" + "google.golang.org/api/option" + "google.golang.org/api/option/internaloption" + gtransport "google.golang.org/api/transport/grpc" + shellpb "google.golang.org/genproto/googleapis/cloud/shell/v1" + longrunningpb "google.golang.org/genproto/googleapis/longrunning" + "google.golang.org/grpc" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/metadata" +) + +var newCloudShellClientHook clientHook + +// CloudShellCallOptions contains the retry settings for each method of CloudShellClient. +type CloudShellCallOptions struct { + GetEnvironment []gax.CallOption + StartEnvironment []gax.CallOption + AuthorizeEnvironment []gax.CallOption + AddPublicKey []gax.CallOption + RemovePublicKey []gax.CallOption +} + +func defaultCloudShellGRPCClientOptions() []option.ClientOption { + return []option.ClientOption{ + internaloption.WithDefaultEndpoint("cloudshell.googleapis.com:443"), + internaloption.WithDefaultMTLSEndpoint("cloudshell.mtls.googleapis.com:443"), + internaloption.WithDefaultAudience("https://cloudshell.googleapis.com/"), + internaloption.WithDefaultScopes(DefaultAuthScopes()...), + option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), + option.WithGRPCDialOption(grpc.WithDefaultCallOptions( + grpc.MaxCallRecvMsgSize(math.MaxInt32))), + } +} + +func defaultCloudShellCallOptions() *CloudShellCallOptions { + return &CloudShellCallOptions{ + GetEnvironment: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.Unavailable, + codes.Unknown, + }, gax.Backoff{ + Initial: 1000 * time.Millisecond, + Max: 60000 * time.Millisecond, + Multiplier: 1.30, + }) + }), + }, + StartEnvironment: []gax.CallOption{}, + AuthorizeEnvironment: []gax.CallOption{}, + AddPublicKey: []gax.CallOption{}, + RemovePublicKey: []gax.CallOption{}, + } +} + +// internalCloudShellClient is an interface that defines the methods availaible from Cloud Shell API. +type internalCloudShellClient interface { + Close() error + setGoogleClientInfo(...string) + Connection() *grpc.ClientConn + GetEnvironment(context.Context, *shellpb.GetEnvironmentRequest, ...gax.CallOption) (*shellpb.Environment, error) + StartEnvironment(context.Context, *shellpb.StartEnvironmentRequest, ...gax.CallOption) (*StartEnvironmentOperation, error) + StartEnvironmentOperation(name string) *StartEnvironmentOperation + AuthorizeEnvironment(context.Context, *shellpb.AuthorizeEnvironmentRequest, ...gax.CallOption) (*AuthorizeEnvironmentOperation, error) + AuthorizeEnvironmentOperation(name string) *AuthorizeEnvironmentOperation + AddPublicKey(context.Context, *shellpb.AddPublicKeyRequest, ...gax.CallOption) (*AddPublicKeyOperation, error) + AddPublicKeyOperation(name string) *AddPublicKeyOperation + RemovePublicKey(context.Context, *shellpb.RemovePublicKeyRequest, ...gax.CallOption) (*RemovePublicKeyOperation, error) + RemovePublicKeyOperation(name string) *RemovePublicKeyOperation +} + +// CloudShellClient is a client for interacting with Cloud Shell API. +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +// +// API for interacting with Google Cloud Shell. Each user of Cloud Shell has at +// least one environment, which has the ID “default”. Environment consists of a +// Docker image defining what is installed on the environment and a home +// directory containing the user’s data that will remain across sessions. +// Clients use this API to start and fetch information about their environment, +// which can then be used to connect to that environment via a separate SSH +// client. +type CloudShellClient struct { + // The internal transport-dependent client. + internalClient internalCloudShellClient + + // The call options for this service. + CallOptions *CloudShellCallOptions + + // LROClient is used internally to handle long-running operations. + // It is exposed so that its CallOptions can be modified if required. + // Users should not Close this client. + LROClient *lroauto.OperationsClient +} + +// Wrapper methods routed to the internal client. + +// Close closes the connection to the API service. The user should invoke this when +// the client is no longer required. +func (c *CloudShellClient) Close() error { + return c.internalClient.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 *CloudShellClient) setGoogleClientInfo(keyval ...string) { + c.internalClient.setGoogleClientInfo(keyval...) +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *CloudShellClient) Connection() *grpc.ClientConn { + return c.internalClient.Connection() +} + +// GetEnvironment gets an environment. Returns NOT_FOUND if the environment does not exist. +func (c *CloudShellClient) GetEnvironment(ctx context.Context, req *shellpb.GetEnvironmentRequest, opts ...gax.CallOption) (*shellpb.Environment, error) { + return c.internalClient.GetEnvironment(ctx, req, opts...) +} + +// StartEnvironment starts an existing environment, allowing clients to connect to it. The +// returned operation will contain an instance of StartEnvironmentMetadata in +// its metadata field. Users can wait for the environment to start by polling +// this operation via GetOperation. Once the environment has finished starting +// and is ready to accept connections, the operation will contain a +// StartEnvironmentResponse in its response field. +func (c *CloudShellClient) StartEnvironment(ctx context.Context, req *shellpb.StartEnvironmentRequest, opts ...gax.CallOption) (*StartEnvironmentOperation, error) { + return c.internalClient.StartEnvironment(ctx, req, opts...) +} + +// StartEnvironmentOperation returns a new StartEnvironmentOperation from a given name. +// The name must be that of a previously created StartEnvironmentOperation, possibly from a different process. +func (c *CloudShellClient) StartEnvironmentOperation(name string) *StartEnvironmentOperation { + return c.internalClient.StartEnvironmentOperation(name) +} + +// AuthorizeEnvironment sends OAuth credentials to a running environment on behalf of a user. When +// this completes, the environment will be authorized to run various Google +// Cloud command line tools without requiring the user to manually +// authenticate. +func (c *CloudShellClient) AuthorizeEnvironment(ctx context.Context, req *shellpb.AuthorizeEnvironmentRequest, opts ...gax.CallOption) (*AuthorizeEnvironmentOperation, error) { + return c.internalClient.AuthorizeEnvironment(ctx, req, opts...) +} + +// AuthorizeEnvironmentOperation returns a new AuthorizeEnvironmentOperation from a given name. +// The name must be that of a previously created AuthorizeEnvironmentOperation, possibly from a different process. +func (c *CloudShellClient) AuthorizeEnvironmentOperation(name string) *AuthorizeEnvironmentOperation { + return c.internalClient.AuthorizeEnvironmentOperation(name) +} + +// AddPublicKey adds a public SSH key to an environment, allowing clients with the +// corresponding private key to connect to that environment via SSH. If a key +// with the same content already exists, this will error with ALREADY_EXISTS. +func (c *CloudShellClient) AddPublicKey(ctx context.Context, req *shellpb.AddPublicKeyRequest, opts ...gax.CallOption) (*AddPublicKeyOperation, error) { + return c.internalClient.AddPublicKey(ctx, req, opts...) +} + +// AddPublicKeyOperation returns a new AddPublicKeyOperation from a given name. +// The name must be that of a previously created AddPublicKeyOperation, possibly from a different process. +func (c *CloudShellClient) AddPublicKeyOperation(name string) *AddPublicKeyOperation { + return c.internalClient.AddPublicKeyOperation(name) +} + +// RemovePublicKey removes a public SSH key from an environment. Clients will no longer be +// able to connect to the environment using the corresponding private key. +// If a key with the same content is not present, this will error with +// NOT_FOUND. +func (c *CloudShellClient) RemovePublicKey(ctx context.Context, req *shellpb.RemovePublicKeyRequest, opts ...gax.CallOption) (*RemovePublicKeyOperation, error) { + return c.internalClient.RemovePublicKey(ctx, req, opts...) +} + +// RemovePublicKeyOperation returns a new RemovePublicKeyOperation from a given name. +// The name must be that of a previously created RemovePublicKeyOperation, possibly from a different process. +func (c *CloudShellClient) RemovePublicKeyOperation(name string) *RemovePublicKeyOperation { + return c.internalClient.RemovePublicKeyOperation(name) +} + +// cloudShellGRPCClient is a client for interacting with Cloud Shell API over gRPC transport. +// +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +type cloudShellGRPCClient 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 + + // Points back to the CallOptions field of the containing CloudShellClient + CallOptions **CloudShellCallOptions + + // The gRPC API client. + cloudShellClient shellpb.CloudShellServiceClient + + // LROClient is used internally to handle long-running operations. + // It is exposed so that its CallOptions can be modified if required. + // Users should not Close this client. + LROClient **lroauto.OperationsClient + + // The x-goog-* metadata to be sent with each request. + xGoogMetadata metadata.MD +} + +// NewCloudShellClient creates a new cloud shell service client based on gRPC. +// The returned client must be Closed when it is done being used to clean up its underlying connections. +// +// API for interacting with Google Cloud Shell. Each user of Cloud Shell has at +// least one environment, which has the ID “default”. Environment consists of a +// Docker image defining what is installed on the environment and a home +// directory containing the user’s data that will remain across sessions. +// Clients use this API to start and fetch information about their environment, +// which can then be used to connect to that environment via a separate SSH +// client. +func NewCloudShellClient(ctx context.Context, opts ...option.ClientOption) (*CloudShellClient, error) { + clientOpts := defaultCloudShellGRPCClientOptions() + if newCloudShellClientHook != nil { + hookOpts, err := newCloudShellClientHook(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 + } + client := CloudShellClient{CallOptions: defaultCloudShellCallOptions()} + + c := &cloudShellGRPCClient{ + connPool: connPool, + disableDeadlines: disableDeadlines, + cloudShellClient: shellpb.NewCloudShellServiceClient(connPool), + CallOptions: &client.CallOptions, + } + c.setGoogleClientInfo() + + client.internalClient = c + + client.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 + } + c.LROClient = &client.LROClient + return &client, nil +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *cloudShellGRPCClient) Connection() *grpc.ClientConn { + return c.connPool.Conn() +} + +// 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 *cloudShellGRPCClient) 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...)) +} + +// Close closes the connection to the API service. The user should invoke this when +// the client is no longer required. +func (c *cloudShellGRPCClient) Close() error { + return c.connPool.Close() +} + +func (c *cloudShellGRPCClient) GetEnvironment(ctx context.Context, req *shellpb.GetEnvironmentRequest, opts ...gax.CallOption) (*shellpb.Environment, error) { + if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { + cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond) + defer cancel() + ctx = cctx + } + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))) + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append((*c.CallOptions).GetEnvironment[0:len((*c.CallOptions).GetEnvironment):len((*c.CallOptions).GetEnvironment)], opts...) + var resp *shellpb.Environment + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.cloudShellClient.GetEnvironment(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} + +func (c *cloudShellGRPCClient) StartEnvironment(ctx context.Context, req *shellpb.StartEnvironmentRequest, opts ...gax.CallOption) (*StartEnvironmentOperation, error) { + if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { + cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond) + defer cancel() + ctx = cctx + } + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))) + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append((*c.CallOptions).StartEnvironment[0:len((*c.CallOptions).StartEnvironment):len((*c.CallOptions).StartEnvironment)], opts...) + var resp *longrunningpb.Operation + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.cloudShellClient.StartEnvironment(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return &StartEnvironmentOperation{ + lro: longrunning.InternalNewOperation(*c.LROClient, resp), + }, nil +} + +func (c *cloudShellGRPCClient) AuthorizeEnvironment(ctx context.Context, req *shellpb.AuthorizeEnvironmentRequest, opts ...gax.CallOption) (*AuthorizeEnvironmentOperation, error) { + if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { + cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond) + defer cancel() + ctx = cctx + } + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))) + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append((*c.CallOptions).AuthorizeEnvironment[0:len((*c.CallOptions).AuthorizeEnvironment):len((*c.CallOptions).AuthorizeEnvironment)], opts...) + var resp *longrunningpb.Operation + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.cloudShellClient.AuthorizeEnvironment(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return &AuthorizeEnvironmentOperation{ + lro: longrunning.InternalNewOperation(*c.LROClient, resp), + }, nil +} + +func (c *cloudShellGRPCClient) AddPublicKey(ctx context.Context, req *shellpb.AddPublicKeyRequest, opts ...gax.CallOption) (*AddPublicKeyOperation, error) { + if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { + cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond) + defer cancel() + ctx = cctx + } + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "environment", url.QueryEscape(req.GetEnvironment()))) + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append((*c.CallOptions).AddPublicKey[0:len((*c.CallOptions).AddPublicKey):len((*c.CallOptions).AddPublicKey)], opts...) + var resp *longrunningpb.Operation + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.cloudShellClient.AddPublicKey(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return &AddPublicKeyOperation{ + lro: longrunning.InternalNewOperation(*c.LROClient, resp), + }, nil +} + +func (c *cloudShellGRPCClient) RemovePublicKey(ctx context.Context, req *shellpb.RemovePublicKeyRequest, opts ...gax.CallOption) (*RemovePublicKeyOperation, error) { + if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { + cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond) + defer cancel() + ctx = cctx + } + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "environment", url.QueryEscape(req.GetEnvironment()))) + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append((*c.CallOptions).RemovePublicKey[0:len((*c.CallOptions).RemovePublicKey):len((*c.CallOptions).RemovePublicKey)], opts...) + var resp *longrunningpb.Operation + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.cloudShellClient.RemovePublicKey(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return &RemovePublicKeyOperation{ + lro: longrunning.InternalNewOperation(*c.LROClient, resp), + }, nil +} + +// AddPublicKeyOperation manages a long-running operation from AddPublicKey. +type AddPublicKeyOperation struct { + lro *longrunning.Operation +} + +// AddPublicKeyOperation returns a new AddPublicKeyOperation from a given name. +// The name must be that of a previously created AddPublicKeyOperation, possibly from a different process. +func (c *cloudShellGRPCClient) AddPublicKeyOperation(name string) *AddPublicKeyOperation { + return &AddPublicKeyOperation{ + 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 *AddPublicKeyOperation) Wait(ctx context.Context, opts ...gax.CallOption) (*shellpb.AddPublicKeyResponse, error) { + var resp shellpb.AddPublicKeyResponse + 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 *AddPublicKeyOperation) Poll(ctx context.Context, opts ...gax.CallOption) (*shellpb.AddPublicKeyResponse, error) { + var resp shellpb.AddPublicKeyResponse + 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 *AddPublicKeyOperation) Metadata() (*shellpb.AddPublicKeyMetadata, error) { + var meta shellpb.AddPublicKeyMetadata + 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 *AddPublicKeyOperation) 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 *AddPublicKeyOperation) Name() string { + return op.lro.Name() +} + +// AuthorizeEnvironmentOperation manages a long-running operation from AuthorizeEnvironment. +type AuthorizeEnvironmentOperation struct { + lro *longrunning.Operation +} + +// AuthorizeEnvironmentOperation returns a new AuthorizeEnvironmentOperation from a given name. +// The name must be that of a previously created AuthorizeEnvironmentOperation, possibly from a different process. +func (c *cloudShellGRPCClient) AuthorizeEnvironmentOperation(name string) *AuthorizeEnvironmentOperation { + return &AuthorizeEnvironmentOperation{ + 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 *AuthorizeEnvironmentOperation) Wait(ctx context.Context, opts ...gax.CallOption) (*shellpb.AuthorizeEnvironmentResponse, error) { + var resp shellpb.AuthorizeEnvironmentResponse + 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 *AuthorizeEnvironmentOperation) Poll(ctx context.Context, opts ...gax.CallOption) (*shellpb.AuthorizeEnvironmentResponse, error) { + var resp shellpb.AuthorizeEnvironmentResponse + 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 *AuthorizeEnvironmentOperation) Metadata() (*shellpb.AuthorizeEnvironmentMetadata, error) { + var meta shellpb.AuthorizeEnvironmentMetadata + 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 *AuthorizeEnvironmentOperation) 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 *AuthorizeEnvironmentOperation) Name() string { + return op.lro.Name() +} + +// RemovePublicKeyOperation manages a long-running operation from RemovePublicKey. +type RemovePublicKeyOperation struct { + lro *longrunning.Operation +} + +// RemovePublicKeyOperation returns a new RemovePublicKeyOperation from a given name. +// The name must be that of a previously created RemovePublicKeyOperation, possibly from a different process. +func (c *cloudShellGRPCClient) RemovePublicKeyOperation(name string) *RemovePublicKeyOperation { + return &RemovePublicKeyOperation{ + 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 *RemovePublicKeyOperation) Wait(ctx context.Context, opts ...gax.CallOption) (*shellpb.RemovePublicKeyResponse, error) { + var resp shellpb.RemovePublicKeyResponse + 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 *RemovePublicKeyOperation) Poll(ctx context.Context, opts ...gax.CallOption) (*shellpb.RemovePublicKeyResponse, error) { + var resp shellpb.RemovePublicKeyResponse + 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 *RemovePublicKeyOperation) Metadata() (*shellpb.RemovePublicKeyMetadata, error) { + var meta shellpb.RemovePublicKeyMetadata + 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 *RemovePublicKeyOperation) 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 *RemovePublicKeyOperation) Name() string { + return op.lro.Name() +} + +// StartEnvironmentOperation manages a long-running operation from StartEnvironment. +type StartEnvironmentOperation struct { + lro *longrunning.Operation +} + +// StartEnvironmentOperation returns a new StartEnvironmentOperation from a given name. +// The name must be that of a previously created StartEnvironmentOperation, possibly from a different process. +func (c *cloudShellGRPCClient) StartEnvironmentOperation(name string) *StartEnvironmentOperation { + return &StartEnvironmentOperation{ + 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 *StartEnvironmentOperation) Wait(ctx context.Context, opts ...gax.CallOption) (*shellpb.StartEnvironmentResponse, error) { + var resp shellpb.StartEnvironmentResponse + 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 *StartEnvironmentOperation) Poll(ctx context.Context, opts ...gax.CallOption) (*shellpb.StartEnvironmentResponse, error) { + var resp shellpb.StartEnvironmentResponse + 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 *StartEnvironmentOperation) Metadata() (*shellpb.StartEnvironmentMetadata, error) { + var meta shellpb.StartEnvironmentMetadata + 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 *StartEnvironmentOperation) 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 *StartEnvironmentOperation) Name() string { + return op.lro.Name() +} diff --git a/shell/apiv1/cloud_shell_client_example_test.go b/shell/apiv1/cloud_shell_client_example_test.go new file mode 100644 index 00000000000..da200b6ccd0 --- /dev/null +++ b/shell/apiv1/cloud_shell_client_example_test.go @@ -0,0 +1,151 @@ +// 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 shell_test + +import ( + "context" + + shell "cloud.google.com/go/shell/apiv1" + shellpb "google.golang.org/genproto/googleapis/cloud/shell/v1" +) + +func ExampleNewCloudShellClient() { + ctx := context.Background() + c, err := shell.NewCloudShellClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + // TODO: Use client. + _ = c +} + +func ExampleCloudShellClient_GetEnvironment() { + ctx := context.Background() + c, err := shell.NewCloudShellClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &shellpb.GetEnvironmentRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.GetEnvironment(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleCloudShellClient_StartEnvironment() { + ctx := context.Background() + c, err := shell.NewCloudShellClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &shellpb.StartEnvironmentRequest{ + // TODO: Fill request struct fields. + } + op, err := c.StartEnvironment(ctx, req) + if err != nil { + // TODO: Handle error. + } + + resp, err := op.Wait(ctx) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleCloudShellClient_AuthorizeEnvironment() { + ctx := context.Background() + c, err := shell.NewCloudShellClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &shellpb.AuthorizeEnvironmentRequest{ + // TODO: Fill request struct fields. + } + op, err := c.AuthorizeEnvironment(ctx, req) + if err != nil { + // TODO: Handle error. + } + + resp, err := op.Wait(ctx) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleCloudShellClient_AddPublicKey() { + ctx := context.Background() + c, err := shell.NewCloudShellClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &shellpb.AddPublicKeyRequest{ + // TODO: Fill request struct fields. + } + op, err := c.AddPublicKey(ctx, req) + if err != nil { + // TODO: Handle error. + } + + resp, err := op.Wait(ctx) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleCloudShellClient_RemovePublicKey() { + ctx := context.Background() + c, err := shell.NewCloudShellClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &shellpb.RemovePublicKeyRequest{ + // TODO: Fill request struct fields. + } + op, err := c.RemovePublicKey(ctx, req) + if err != nil { + // TODO: Handle error. + } + + resp, err := op.Wait(ctx) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} diff --git a/shell/apiv1/doc.go b/shell/apiv1/doc.go new file mode 100644 index 00000000000..ef6ff1d3d50 --- /dev/null +++ b/shell/apiv1/doc.go @@ -0,0 +1,119 @@ +// 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 shell is an auto-generated package for the +// Cloud Shell API. +// +// Allows users to start, configure, and connect to interactive shell +// sessions running in the cloud. +// +// NOTE: This package is in beta. It is not stable, and may be subject to changes. +// +// 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 https://pkg.go.dev/cloud.google.com/go. +package shell // import "cloud.google.com/go/shell/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 = "20210526" + +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", + } +} + +// 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/shell/apiv1/gapic_metadata.json b/shell/apiv1/gapic_metadata.json new file mode 100644 index 00000000000..9f2bef8962e --- /dev/null +++ b/shell/apiv1/gapic_metadata.json @@ -0,0 +1,43 @@ +{ + "schema": "1.0", + "comment": "This file maps proto services/RPCs to the corresponding library clients/methods.", + "language": "go", + "protoPackage": "google.cloud.shell.v1", + "libraryPackage": "cloud.google.com/go/shell/apiv1", + "services": { + "CloudShellService": { + "clients": { + "grpc": { + "libraryClient": "CloudShellClient", + "rpcs": { + "AddPublicKey": { + "methods": [ + "AddPublicKey" + ] + }, + "AuthorizeEnvironment": { + "methods": [ + "AuthorizeEnvironment" + ] + }, + "GetEnvironment": { + "methods": [ + "GetEnvironment" + ] + }, + "RemovePublicKey": { + "methods": [ + "RemovePublicKey" + ] + }, + "StartEnvironment": { + "methods": [ + "StartEnvironment" + ] + } + } + } + } + } + } +} diff --git a/vpcaccess/apiv1/doc.go b/vpcaccess/apiv1/doc.go new file mode 100644 index 00000000000..60fec5601d4 --- /dev/null +++ b/vpcaccess/apiv1/doc.go @@ -0,0 +1,118 @@ +// 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 vpcaccess is an auto-generated package for the +// Serverless VPC Access API. +// +// API for managing VPC access connectors. +// +// NOTE: This package is in beta. It is not stable, and may be subject to changes. +// +// 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 https://pkg.go.dev/cloud.google.com/go. +package vpcaccess // import "cloud.google.com/go/vpcaccess/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 = "20210526" + +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", + } +} + +// 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/vpcaccess/apiv1/gapic_metadata.json b/vpcaccess/apiv1/gapic_metadata.json new file mode 100644 index 00000000000..bc096e30bbd --- /dev/null +++ b/vpcaccess/apiv1/gapic_metadata.json @@ -0,0 +1,38 @@ +{ + "schema": "1.0", + "comment": "This file maps proto services/RPCs to the corresponding library clients/methods.", + "language": "go", + "protoPackage": "google.cloud.vpcaccess.v1", + "libraryPackage": "cloud.google.com/go/vpcaccess/apiv1", + "services": { + "VpcAccessService": { + "clients": { + "grpc": { + "libraryClient": "Client", + "rpcs": { + "CreateConnector": { + "methods": [ + "CreateConnector" + ] + }, + "DeleteConnector": { + "methods": [ + "DeleteConnector" + ] + }, + "GetConnector": { + "methods": [ + "GetConnector" + ] + }, + "ListConnectors": { + "methods": [ + "ListConnectors" + ] + } + } + } + } + } + } +} diff --git a/vpcaccess/apiv1/vpc_access_client.go b/vpcaccess/apiv1/vpc_access_client.go new file mode 100644 index 00000000000..443261256c3 --- /dev/null +++ b/vpcaccess/apiv1/vpc_access_client.go @@ -0,0 +1,536 @@ +// 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 vpcaccess + +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" + vpcaccesspb "google.golang.org/genproto/googleapis/cloud/vpcaccess/v1" + longrunningpb "google.golang.org/genproto/googleapis/longrunning" + "google.golang.org/grpc" + "google.golang.org/grpc/metadata" +) + +var newClientHook clientHook + +// CallOptions contains the retry settings for each method of Client. +type CallOptions struct { + CreateConnector []gax.CallOption + GetConnector []gax.CallOption + ListConnectors []gax.CallOption + DeleteConnector []gax.CallOption +} + +func defaultGRPCClientOptions() []option.ClientOption { + return []option.ClientOption{ + internaloption.WithDefaultEndpoint("vpcaccess.googleapis.com:443"), + internaloption.WithDefaultMTLSEndpoint("vpcaccess.mtls.googleapis.com:443"), + internaloption.WithDefaultAudience("https://vpcaccess.googleapis.com/"), + internaloption.WithDefaultScopes(DefaultAuthScopes()...), + option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), + option.WithGRPCDialOption(grpc.WithDefaultCallOptions( + grpc.MaxCallRecvMsgSize(math.MaxInt32))), + } +} + +func defaultCallOptions() *CallOptions { + return &CallOptions{ + CreateConnector: []gax.CallOption{}, + GetConnector: []gax.CallOption{}, + ListConnectors: []gax.CallOption{}, + DeleteConnector: []gax.CallOption{}, + } +} + +// internalClient is an interface that defines the methods availaible from Serverless VPC Access API. +type internalClient interface { + Close() error + setGoogleClientInfo(...string) + Connection() *grpc.ClientConn + CreateConnector(context.Context, *vpcaccesspb.CreateConnectorRequest, ...gax.CallOption) (*CreateConnectorOperation, error) + CreateConnectorOperation(name string) *CreateConnectorOperation + GetConnector(context.Context, *vpcaccesspb.GetConnectorRequest, ...gax.CallOption) (*vpcaccesspb.Connector, error) + ListConnectors(context.Context, *vpcaccesspb.ListConnectorsRequest, ...gax.CallOption) *ConnectorIterator + DeleteConnector(context.Context, *vpcaccesspb.DeleteConnectorRequest, ...gax.CallOption) (*DeleteConnectorOperation, error) + DeleteConnectorOperation(name string) *DeleteConnectorOperation +} + +// Client is a client for interacting with Serverless VPC Access API. +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +// +// Serverless VPC Access API allows users to create and manage connectors for +// App Engine, Cloud Functions and Cloud Run to have internal connections to +// Virtual Private Cloud networks. +type Client struct { + // The internal transport-dependent client. + internalClient internalClient + + // The call options for this service. + CallOptions *CallOptions + + // LROClient is used internally to handle long-running operations. + // It is exposed so that its CallOptions can be modified if required. + // Users should not Close this client. + LROClient *lroauto.OperationsClient +} + +// Wrapper methods routed to the internal client. + +// Close closes the connection to the API service. The user should invoke this when +// the client is no longer required. +func (c *Client) Close() error { + return c.internalClient.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 *Client) setGoogleClientInfo(keyval ...string) { + c.internalClient.setGoogleClientInfo(keyval...) +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *Client) Connection() *grpc.ClientConn { + return c.internalClient.Connection() +} + +// CreateConnector creates a Serverless VPC Access connector, returns an operation. +func (c *Client) CreateConnector(ctx context.Context, req *vpcaccesspb.CreateConnectorRequest, opts ...gax.CallOption) (*CreateConnectorOperation, error) { + return c.internalClient.CreateConnector(ctx, req, opts...) +} + +// CreateConnectorOperation returns a new CreateConnectorOperation from a given name. +// The name must be that of a previously created CreateConnectorOperation, possibly from a different process. +func (c *Client) CreateConnectorOperation(name string) *CreateConnectorOperation { + return c.internalClient.CreateConnectorOperation(name) +} + +// GetConnector gets a Serverless VPC Access connector. Returns NOT_FOUND if the resource +// does not exist. +func (c *Client) GetConnector(ctx context.Context, req *vpcaccesspb.GetConnectorRequest, opts ...gax.CallOption) (*vpcaccesspb.Connector, error) { + return c.internalClient.GetConnector(ctx, req, opts...) +} + +// ListConnectors lists Serverless VPC Access connectors. +func (c *Client) ListConnectors(ctx context.Context, req *vpcaccesspb.ListConnectorsRequest, opts ...gax.CallOption) *ConnectorIterator { + return c.internalClient.ListConnectors(ctx, req, opts...) +} + +// DeleteConnector deletes a Serverless VPC Access connector. Returns NOT_FOUND if the +// resource does not exist. +func (c *Client) DeleteConnector(ctx context.Context, req *vpcaccesspb.DeleteConnectorRequest, opts ...gax.CallOption) (*DeleteConnectorOperation, error) { + return c.internalClient.DeleteConnector(ctx, req, opts...) +} + +// DeleteConnectorOperation returns a new DeleteConnectorOperation from a given name. +// The name must be that of a previously created DeleteConnectorOperation, possibly from a different process. +func (c *Client) DeleteConnectorOperation(name string) *DeleteConnectorOperation { + return c.internalClient.DeleteConnectorOperation(name) +} + +// gRPCClient is a client for interacting with Serverless VPC Access API over gRPC transport. +// +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +type gRPCClient 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 + + // Points back to the CallOptions field of the containing Client + CallOptions **CallOptions + + // The gRPC API client. + client vpcaccesspb.VpcAccessServiceClient + + // LROClient is used internally to handle long-running operations. + // It is exposed so that its CallOptions can be modified if required. + // Users should not Close this client. + LROClient **lroauto.OperationsClient + + // The x-goog-* metadata to be sent with each request. + xGoogMetadata metadata.MD +} + +// NewClient creates a new vpc access service client based on gRPC. +// The returned client must be Closed when it is done being used to clean up its underlying connections. +// +// Serverless VPC Access API allows users to create and manage connectors for +// App Engine, Cloud Functions and Cloud Run to have internal connections to +// Virtual Private Cloud networks. +func NewClient(ctx context.Context, opts ...option.ClientOption) (*Client, error) { + clientOpts := defaultGRPCClientOptions() + if newClientHook != nil { + hookOpts, err := newClientHook(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 + } + client := Client{CallOptions: defaultCallOptions()} + + c := &gRPCClient{ + connPool: connPool, + disableDeadlines: disableDeadlines, + client: vpcaccesspb.NewVpcAccessServiceClient(connPool), + CallOptions: &client.CallOptions, + } + c.setGoogleClientInfo() + + client.internalClient = c + + client.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 + } + c.LROClient = &client.LROClient + return &client, nil +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *gRPCClient) Connection() *grpc.ClientConn { + return c.connPool.Conn() +} + +// 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 *gRPCClient) 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...)) +} + +// Close closes the connection to the API service. The user should invoke this when +// the client is no longer required. +func (c *gRPCClient) Close() error { + return c.connPool.Close() +} + +func (c *gRPCClient) CreateConnector(ctx context.Context, req *vpcaccesspb.CreateConnectorRequest, opts ...gax.CallOption) (*CreateConnectorOperation, error) { + if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { + cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond) + defer cancel() + ctx = cctx + } + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))) + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append((*c.CallOptions).CreateConnector[0:len((*c.CallOptions).CreateConnector):len((*c.CallOptions).CreateConnector)], opts...) + var resp *longrunningpb.Operation + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.client.CreateConnector(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return &CreateConnectorOperation{ + lro: longrunning.InternalNewOperation(*c.LROClient, resp), + }, nil +} + +func (c *gRPCClient) GetConnector(ctx context.Context, req *vpcaccesspb.GetConnectorRequest, opts ...gax.CallOption) (*vpcaccesspb.Connector, error) { + if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { + cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond) + defer cancel() + ctx = cctx + } + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))) + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append((*c.CallOptions).GetConnector[0:len((*c.CallOptions).GetConnector):len((*c.CallOptions).GetConnector)], opts...) + var resp *vpcaccesspb.Connector + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.client.GetConnector(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} + +func (c *gRPCClient) ListConnectors(ctx context.Context, req *vpcaccesspb.ListConnectorsRequest, opts ...gax.CallOption) *ConnectorIterator { + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))) + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append((*c.CallOptions).ListConnectors[0:len((*c.CallOptions).ListConnectors):len((*c.CallOptions).ListConnectors)], opts...) + it := &ConnectorIterator{} + req = proto.Clone(req).(*vpcaccesspb.ListConnectorsRequest) + it.InternalFetch = func(pageSize int, pageToken string) ([]*vpcaccesspb.Connector, string, error) { + var resp *vpcaccesspb.ListConnectorsResponse + 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.client.ListConnectors(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, "", err + } + + it.Response = resp + return resp.GetConnectors(), 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 +} + +func (c *gRPCClient) DeleteConnector(ctx context.Context, req *vpcaccesspb.DeleteConnectorRequest, opts ...gax.CallOption) (*DeleteConnectorOperation, error) { + if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { + cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond) + defer cancel() + ctx = cctx + } + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))) + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append((*c.CallOptions).DeleteConnector[0:len((*c.CallOptions).DeleteConnector):len((*c.CallOptions).DeleteConnector)], opts...) + var resp *longrunningpb.Operation + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.client.DeleteConnector(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return &DeleteConnectorOperation{ + lro: longrunning.InternalNewOperation(*c.LROClient, resp), + }, nil +} + +// CreateConnectorOperation manages a long-running operation from CreateConnector. +type CreateConnectorOperation struct { + lro *longrunning.Operation +} + +// CreateConnectorOperation returns a new CreateConnectorOperation from a given name. +// The name must be that of a previously created CreateConnectorOperation, possibly from a different process. +func (c *gRPCClient) CreateConnectorOperation(name string) *CreateConnectorOperation { + return &CreateConnectorOperation{ + 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 *CreateConnectorOperation) Wait(ctx context.Context, opts ...gax.CallOption) (*vpcaccesspb.Connector, error) { + var resp vpcaccesspb.Connector + 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 *CreateConnectorOperation) Poll(ctx context.Context, opts ...gax.CallOption) (*vpcaccesspb.Connector, error) { + var resp vpcaccesspb.Connector + 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 *CreateConnectorOperation) Metadata() (*vpcaccesspb.OperationMetadata, error) { + var meta vpcaccesspb.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 *CreateConnectorOperation) 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 *CreateConnectorOperation) Name() string { + return op.lro.Name() +} + +// DeleteConnectorOperation manages a long-running operation from DeleteConnector. +type DeleteConnectorOperation struct { + lro *longrunning.Operation +} + +// DeleteConnectorOperation returns a new DeleteConnectorOperation from a given name. +// The name must be that of a previously created DeleteConnectorOperation, possibly from a different process. +func (c *gRPCClient) DeleteConnectorOperation(name string) *DeleteConnectorOperation { + return &DeleteConnectorOperation{ + 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 *DeleteConnectorOperation) 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 *DeleteConnectorOperation) 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 *DeleteConnectorOperation) Metadata() (*vpcaccesspb.OperationMetadata, error) { + var meta vpcaccesspb.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 *DeleteConnectorOperation) 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 *DeleteConnectorOperation) Name() string { + return op.lro.Name() +} + +// ConnectorIterator manages a stream of *vpcaccesspb.Connector. +type ConnectorIterator struct { + items []*vpcaccesspb.Connector + 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 []*vpcaccesspb.Connector, nextPageToken string, err error) +} + +// PageInfo supports pagination. See the google.golang.org/api/iterator package for details. +func (it *ConnectorIterator) 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 *ConnectorIterator) Next() (*vpcaccesspb.Connector, error) { + var item *vpcaccesspb.Connector + if err := it.nextFunc(); err != nil { + return item, err + } + item = it.items[0] + it.items = it.items[1:] + return item, nil +} + +func (it *ConnectorIterator) bufLen() int { + return len(it.items) +} + +func (it *ConnectorIterator) takeBuf() interface{} { + b := it.items + it.items = nil + return b +} diff --git a/vpcaccess/apiv1/vpc_access_client_example_test.go b/vpcaccess/apiv1/vpc_access_client_example_test.go new file mode 100644 index 00000000000..f66e7022cbf --- /dev/null +++ b/vpcaccess/apiv1/vpc_access_client_example_test.go @@ -0,0 +1,127 @@ +// 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 vpcaccess_test + +import ( + "context" + + vpcaccess "cloud.google.com/go/vpcaccess/apiv1" + "google.golang.org/api/iterator" + vpcaccesspb "google.golang.org/genproto/googleapis/cloud/vpcaccess/v1" +) + +func ExampleNewClient() { + ctx := context.Background() + c, err := vpcaccess.NewClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + // TODO: Use client. + _ = c +} + +func ExampleClient_CreateConnector() { + ctx := context.Background() + c, err := vpcaccess.NewClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &vpcaccesspb.CreateConnectorRequest{ + // TODO: Fill request struct fields. + } + op, err := c.CreateConnector(ctx, req) + if err != nil { + // TODO: Handle error. + } + + resp, err := op.Wait(ctx) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleClient_GetConnector() { + ctx := context.Background() + c, err := vpcaccess.NewClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &vpcaccesspb.GetConnectorRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.GetConnector(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleClient_ListConnectors() { + ctx := context.Background() + c, err := vpcaccess.NewClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &vpcaccesspb.ListConnectorsRequest{ + // TODO: Fill request struct fields. + } + it := c.ListConnectors(ctx, req) + for { + resp, err := it.Next() + if err == iterator.Done { + break + } + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp + } +} + +func ExampleClient_DeleteConnector() { + ctx := context.Background() + c, err := vpcaccess.NewClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &vpcaccesspb.DeleteConnectorRequest{ + // TODO: Fill request struct fields. + } + op, err := c.DeleteConnector(ctx, req) + if err != nil { + // TODO: Handle error. + } + + err = op.Wait(ctx) + if err != nil { + // TODO: Handle error. + } +}