diff --git a/internal/.repo-metadata-full.json b/internal/.repo-metadata-full.json index 177a33a9bf91..9c4e5f164374 100644 --- a/internal/.repo-metadata-full.json +++ b/internal/.repo-metadata-full.json @@ -14,7 +14,7 @@ "language": "Go", "client_library_type": "generated", "docs_url": "https://cloud.google.com/go/docs/reference/cloud.google.com/go/latest/aiplatform/apiv1", - "release_level": "beta", + "release_level": "ga", "library_type": "" }, "cloud.google.com/go/analytics/admin/apiv1alpha": { @@ -50,7 +50,7 @@ "language": "Go", "client_library_type": "generated", "docs_url": "https://cloud.google.com/go/docs/reference/cloud.google.com/go/latest/apigeeconnect/apiv1", - "release_level": "beta", + "release_level": "ga", "library_type": "" }, "cloud.google.com/go/appengine/apiv1": { @@ -635,7 +635,7 @@ "language": "Go", "client_library_type": "generated", "docs_url": "https://cloud.google.com/go/docs/reference/cloud.google.com/go/latest/gsuiteaddons/apiv1", - "release_level": "beta", + "release_level": "ga", "library_type": "" }, "cloud.google.com/go/iam": { @@ -818,6 +818,15 @@ "release_level": "alpha", "library_type": "" }, + "cloud.google.com/go/networkmanagement/apiv1": { + "distribution_name": "cloud.google.com/go/networkmanagement/apiv1", + "description": "Network Management API", + "language": "Go", + "client_library_type": "generated", + "docs_url": "https://cloud.google.com/go/docs/reference/cloud.google.com/go/latest/networkmanagement/apiv1", + "release_level": "beta", + "library_type": "" + }, "cloud.google.com/go/notebooks/apiv1beta1": { "distribution_name": "cloud.google.com/go/notebooks/apiv1beta1", "description": "Notebooks API", @@ -1211,7 +1220,7 @@ "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", + "release_level": "ga", "library_type": "" }, "cloud.google.com/go/spanner": { @@ -1319,7 +1328,7 @@ "language": "Go", "client_library_type": "generated", "docs_url": "https://cloud.google.com/go/docs/reference/cloud.google.com/go/latest/tpu/apiv1", - "release_level": "beta", + "release_level": "ga", "library_type": "" }, "cloud.google.com/go/trace/apiv1": { @@ -1349,6 +1358,15 @@ "release_level": "ga", "library_type": "" }, + "cloud.google.com/go/video/transcoder/apiv1": { + "distribution_name": "cloud.google.com/go/video/transcoder/apiv1", + "description": "Transcoder API", + "language": "Go", + "client_library_type": "generated", + "docs_url": "https://cloud.google.com/go/docs/reference/cloud.google.com/go/latest/video/transcoder/apiv1", + "release_level": "beta", + "library_type": "" + }, "cloud.google.com/go/video/transcoder/apiv1beta1": { "distribution_name": "cloud.google.com/go/video/transcoder/apiv1beta1", "description": "Transcoder API", @@ -1400,7 +1418,7 @@ "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", + "release_level": "ga", "library_type": "" }, "cloud.google.com/go/webrisk/apiv1": { diff --git a/internal/gapicgen/generator/config.go b/internal/gapicgen/generator/config.go index 76c153554dd2..5060cc670a4e 100644 --- a/internal/gapicgen/generator/config.go +++ b/internal/gapicgen/generator/config.go @@ -838,6 +838,15 @@ var microgenGapicConfigs = []*microgenConfig{ apiServiceConfigPath: "billingbudgets.yaml", releaseLevel: "beta", }, + { + inputDirectoryPath: "google/cloud/video/transcoder/v1", + pkg: "transcoder", + importPath: "cloud.google.com/go/video/transcoder/apiv1", + gRPCServiceConfigPath: "transcoder_grpc_service_config.json", + apiServiceConfigPath: "transcoder_v1.yaml", + // GA after 2021/08/12 + releaseLevel: "beta", + }, { inputDirectoryPath: "google/cloud/video/transcoder/v1beta1", pkg: "transcoder", @@ -1123,8 +1132,7 @@ var microgenGapicConfigs = []*microgenConfig{ importPath: "cloud.google.com/go/shell/apiv1", gRPCServiceConfigPath: "cloudshell_grpc_service_config.json", apiServiceConfigPath: "cloudshell_v1.yaml", - // GA after 2021/06/26 - releaseLevel: "beta", + releaseLevel: "ga", }, { inputDirectoryPath: "google/cloud/vpcaccess/v1", @@ -1132,8 +1140,7 @@ var microgenGapicConfigs = []*microgenConfig{ importPath: "cloud.google.com/go/vpcaccess/apiv1", gRPCServiceConfigPath: "vpcaccess_grpc_service_config.json", apiServiceConfigPath: "vpcaccess_v1.yaml", - // GA after 2021/06/26 - releaseLevel: "beta", + releaseLevel: "ga", }, { inputDirectoryPath: "google/cloud/privatecatalog/v1beta1", @@ -1149,8 +1156,7 @@ var microgenGapicConfigs = []*microgenConfig{ importPath: "cloud.google.com/go/tpu/apiv1", gRPCServiceConfigPath: "tpu_grpc_service_config.json", apiServiceConfigPath: "tpu_v1.yaml", - // GA after 2021/07/02 - releaseLevel: "beta", + releaseLevel: "ga", }, { inputDirectoryPath: "google/cloud/apigeeconnect/v1", @@ -1158,8 +1164,7 @@ var microgenGapicConfigs = []*microgenConfig{ importPath: "cloud.google.com/go/apigeeconnect/apiv1", gRPCServiceConfigPath: "connection_grpc_service_config.json", apiServiceConfigPath: "apigeeconnect_v1.yaml", - // GA after 2021/07/03 - releaseLevel: "beta", + releaseLevel: "ga", }, { inputDirectoryPath: "google/cloud/lifesciences/v2beta", @@ -1175,8 +1180,7 @@ var microgenGapicConfigs = []*microgenConfig{ importPath: "cloud.google.com/go/aiplatform/apiv1", gRPCServiceConfigPath: "aiplatform_grpc_service_config.json", apiServiceConfigPath: "aiplatform_v1.yaml", - // GA after 2021/07/03 - releaseLevel: "beta", + releaseLevel: "ga", }, { inputDirectoryPath: "google/cloud/gkeconnect/gateway/v1beta1", @@ -1211,6 +1215,15 @@ var microgenGapicConfigs = []*microgenConfig{ // GA after 2021/07/30 releaseLevel: "beta", }, + { + inputDirectoryPath: "google/cloud/networkmanagement/v1", + pkg: "networkmanagement", + importPath: "cloud.google.com/go/networkmanagement/apiv1", + gRPCServiceConfigPath: "networkmanagement_grpc_service_config.json", + apiServiceConfigPath: "networkmanagement_v1.yaml", + // GA after 2021/08/12 + releaseLevel: "beta", + }, // Non-Cloud APIs { @@ -1243,8 +1256,7 @@ var microgenGapicConfigs = []*microgenConfig{ importPath: "cloud.google.com/go/gsuiteaddons/apiv1", gRPCServiceConfigPath: "gsuiteaddons_grpc_service_config.json", apiServiceConfigPath: "gsuiteaddons_v1.yaml", - // GA after 2021/06/10 - releaseLevel: "beta", + releaseLevel: "ga", }, { inputDirectoryPath: "google/storage/v1", diff --git a/networkmanagement/apiv1/doc.go b/networkmanagement/apiv1/doc.go new file mode 100644 index 000000000000..0fb9b90c3ff5 --- /dev/null +++ b/networkmanagement/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 networkmanagement is an auto-generated package for the +// Network Management API. +// +// The Network Management API provides a collection of network performance +// monitoring and diagnostic capabilities. +// +// 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 networkmanagement // import "cloud.google.com/go/networkmanagement/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 = "20210712" + +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/networkmanagement/apiv1/gapic_metadata.json b/networkmanagement/apiv1/gapic_metadata.json new file mode 100644 index 000000000000..f0493deeab7d --- /dev/null +++ b/networkmanagement/apiv1/gapic_metadata.json @@ -0,0 +1,48 @@ +{ + "schema": "1.0", + "comment": "This file maps proto services/RPCs to the corresponding library clients/methods.", + "language": "go", + "protoPackage": "google.cloud.networkmanagement.v1", + "libraryPackage": "cloud.google.com/go/networkmanagement/apiv1", + "services": { + "ReachabilityService": { + "clients": { + "grpc": { + "libraryClient": "ReachabilityClient", + "rpcs": { + "CreateConnectivityTest": { + "methods": [ + "CreateConnectivityTest" + ] + }, + "DeleteConnectivityTest": { + "methods": [ + "DeleteConnectivityTest" + ] + }, + "GetConnectivityTest": { + "methods": [ + "GetConnectivityTest" + ] + }, + "ListConnectivityTests": { + "methods": [ + "ListConnectivityTests" + ] + }, + "RerunConnectivityTest": { + "methods": [ + "RerunConnectivityTest" + ] + }, + "UpdateConnectivityTest": { + "methods": [ + "UpdateConnectivityTest" + ] + } + } + } + } + } + } +} diff --git a/networkmanagement/apiv1/reachability_client.go b/networkmanagement/apiv1/reachability_client.go new file mode 100644 index 000000000000..673009caabeb --- /dev/null +++ b/networkmanagement/apiv1/reachability_client.go @@ -0,0 +1,795 @@ +// 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 networkmanagement + +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/iterator" + "google.golang.org/api/option" + "google.golang.org/api/option/internaloption" + gtransport "google.golang.org/api/transport/grpc" + networkmanagementpb "google.golang.org/genproto/googleapis/cloud/networkmanagement/v1" + longrunningpb "google.golang.org/genproto/googleapis/longrunning" + "google.golang.org/grpc" + "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" +) + +var newReachabilityClientHook clientHook + +// ReachabilityCallOptions contains the retry settings for each method of ReachabilityClient. +type ReachabilityCallOptions struct { + ListConnectivityTests []gax.CallOption + GetConnectivityTest []gax.CallOption + CreateConnectivityTest []gax.CallOption + UpdateConnectivityTest []gax.CallOption + RerunConnectivityTest []gax.CallOption + DeleteConnectivityTest []gax.CallOption +} + +func defaultReachabilityGRPCClientOptions() []option.ClientOption { + return []option.ClientOption{ + internaloption.WithDefaultEndpoint("networkmanagement.googleapis.com:443"), + internaloption.WithDefaultMTLSEndpoint("networkmanagement.mtls.googleapis.com:443"), + internaloption.WithDefaultAudience("https://networkmanagement.googleapis.com/"), + internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), + option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), + option.WithGRPCDialOption(grpc.WithDefaultCallOptions( + grpc.MaxCallRecvMsgSize(math.MaxInt32))), + } +} + +func defaultReachabilityCallOptions() *ReachabilityCallOptions { + return &ReachabilityCallOptions{ + ListConnectivityTests: []gax.CallOption{}, + GetConnectivityTest: []gax.CallOption{}, + CreateConnectivityTest: []gax.CallOption{}, + UpdateConnectivityTest: []gax.CallOption{}, + RerunConnectivityTest: []gax.CallOption{}, + DeleteConnectivityTest: []gax.CallOption{}, + } +} + +// internalReachabilityClient is an interface that defines the methods availaible from Network Management API. +type internalReachabilityClient interface { + Close() error + setGoogleClientInfo(...string) + Connection() *grpc.ClientConn + ListConnectivityTests(context.Context, *networkmanagementpb.ListConnectivityTestsRequest, ...gax.CallOption) *ConnectivityTestIterator + GetConnectivityTest(context.Context, *networkmanagementpb.GetConnectivityTestRequest, ...gax.CallOption) (*networkmanagementpb.ConnectivityTest, error) + CreateConnectivityTest(context.Context, *networkmanagementpb.CreateConnectivityTestRequest, ...gax.CallOption) (*CreateConnectivityTestOperation, error) + CreateConnectivityTestOperation(name string) *CreateConnectivityTestOperation + UpdateConnectivityTest(context.Context, *networkmanagementpb.UpdateConnectivityTestRequest, ...gax.CallOption) (*UpdateConnectivityTestOperation, error) + UpdateConnectivityTestOperation(name string) *UpdateConnectivityTestOperation + RerunConnectivityTest(context.Context, *networkmanagementpb.RerunConnectivityTestRequest, ...gax.CallOption) (*RerunConnectivityTestOperation, error) + RerunConnectivityTestOperation(name string) *RerunConnectivityTestOperation + DeleteConnectivityTest(context.Context, *networkmanagementpb.DeleteConnectivityTestRequest, ...gax.CallOption) (*DeleteConnectivityTestOperation, error) + DeleteConnectivityTestOperation(name string) *DeleteConnectivityTestOperation +} + +// ReachabilityClient is a client for interacting with Network Management API. +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +// +// The Reachability service in the Google Cloud Network Management API provides +// services that analyze the reachability within a single Google Virtual Private +// Cloud (VPC) network, between peered VPC networks, between VPC and on-premises +// networks, or between VPC networks and internet hosts. A reachability analysis +// is based on Google Cloud network configurations. +// +// You can use the analysis results to verify these configurations and +// to troubleshoot connectivity issues. +type ReachabilityClient struct { + // The internal transport-dependent client. + internalClient internalReachabilityClient + + // The call options for this service. + CallOptions *ReachabilityCallOptions + + // 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 *ReachabilityClient) 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 *ReachabilityClient) setGoogleClientInfo(keyval ...string) { + c.internalClient.setGoogleClientInfo(keyval...) +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *ReachabilityClient) Connection() *grpc.ClientConn { + return c.internalClient.Connection() +} + +// ListConnectivityTests lists all Connectivity Tests owned by a project. +func (c *ReachabilityClient) ListConnectivityTests(ctx context.Context, req *networkmanagementpb.ListConnectivityTestsRequest, opts ...gax.CallOption) *ConnectivityTestIterator { + return c.internalClient.ListConnectivityTests(ctx, req, opts...) +} + +// GetConnectivityTest gets the details of a specific Connectivity Test. +func (c *ReachabilityClient) GetConnectivityTest(ctx context.Context, req *networkmanagementpb.GetConnectivityTestRequest, opts ...gax.CallOption) (*networkmanagementpb.ConnectivityTest, error) { + return c.internalClient.GetConnectivityTest(ctx, req, opts...) +} + +// CreateConnectivityTest creates a new Connectivity Test. +// After you create a test, the reachability analysis is performed as part +// of the long running operation, which completes when the analysis completes. +// +// If the endpoint specifications in ConnectivityTest are invalid +// (for example, containing non-existent resources in the network, or you +// don’t have read permissions to the network configurations of listed +// projects), then the reachability result returns a value of UNKNOWN. +// +// If the endpoint specifications in ConnectivityTest are +// incomplete, the reachability result returns a value of +// AMBIGUOUS. For more information, +// see the Connectivity Test documentation. +func (c *ReachabilityClient) CreateConnectivityTest(ctx context.Context, req *networkmanagementpb.CreateConnectivityTestRequest, opts ...gax.CallOption) (*CreateConnectivityTestOperation, error) { + return c.internalClient.CreateConnectivityTest(ctx, req, opts...) +} + +// CreateConnectivityTestOperation returns a new CreateConnectivityTestOperation from a given name. +// The name must be that of a previously created CreateConnectivityTestOperation, possibly from a different process. +func (c *ReachabilityClient) CreateConnectivityTestOperation(name string) *CreateConnectivityTestOperation { + return c.internalClient.CreateConnectivityTestOperation(name) +} + +// UpdateConnectivityTest updates the configuration of an existing ConnectivityTest. +// After you update a test, the reachability analysis is performed as part +// of the long running operation, which completes when the analysis completes. +// The Reachability state in the test resource is updated with the new result. +// +// If the endpoint specifications in ConnectivityTest are invalid +// (for example, they contain non-existent resources in the network, or the +// user does not have read permissions to the network configurations of +// listed projects), then the reachability result returns a value of +// UNKNOWN. +// +// If the endpoint specifications in ConnectivityTest are incomplete, the +// reachability result returns a value of AMBIGUOUS. See the documentation +// in ConnectivityTest for for more details. +func (c *ReachabilityClient) UpdateConnectivityTest(ctx context.Context, req *networkmanagementpb.UpdateConnectivityTestRequest, opts ...gax.CallOption) (*UpdateConnectivityTestOperation, error) { + return c.internalClient.UpdateConnectivityTest(ctx, req, opts...) +} + +// UpdateConnectivityTestOperation returns a new UpdateConnectivityTestOperation from a given name. +// The name must be that of a previously created UpdateConnectivityTestOperation, possibly from a different process. +func (c *ReachabilityClient) UpdateConnectivityTestOperation(name string) *UpdateConnectivityTestOperation { + return c.internalClient.UpdateConnectivityTestOperation(name) +} + +// RerunConnectivityTest rerun an existing ConnectivityTest. +// After the user triggers the rerun, the reachability analysis is performed +// as part of the long running operation, which completes when the analysis +// completes. +// +// Even though the test configuration remains the same, the reachability +// result may change due to underlying network configuration changes. +// +// If the endpoint specifications in ConnectivityTest become invalid (for +// example, specified resources are deleted in the network, or you lost +// read permissions to the network configurations of listed projects), then +// the reachability result returns a value of UNKNOWN. +func (c *ReachabilityClient) RerunConnectivityTest(ctx context.Context, req *networkmanagementpb.RerunConnectivityTestRequest, opts ...gax.CallOption) (*RerunConnectivityTestOperation, error) { + return c.internalClient.RerunConnectivityTest(ctx, req, opts...) +} + +// RerunConnectivityTestOperation returns a new RerunConnectivityTestOperation from a given name. +// The name must be that of a previously created RerunConnectivityTestOperation, possibly from a different process. +func (c *ReachabilityClient) RerunConnectivityTestOperation(name string) *RerunConnectivityTestOperation { + return c.internalClient.RerunConnectivityTestOperation(name) +} + +// DeleteConnectivityTest deletes a specific ConnectivityTest. +func (c *ReachabilityClient) DeleteConnectivityTest(ctx context.Context, req *networkmanagementpb.DeleteConnectivityTestRequest, opts ...gax.CallOption) (*DeleteConnectivityTestOperation, error) { + return c.internalClient.DeleteConnectivityTest(ctx, req, opts...) +} + +// DeleteConnectivityTestOperation returns a new DeleteConnectivityTestOperation from a given name. +// The name must be that of a previously created DeleteConnectivityTestOperation, possibly from a different process. +func (c *ReachabilityClient) DeleteConnectivityTestOperation(name string) *DeleteConnectivityTestOperation { + return c.internalClient.DeleteConnectivityTestOperation(name) +} + +// reachabilityGRPCClient is a client for interacting with Network Management API over gRPC transport. +// +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +type reachabilityGRPCClient 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 ReachabilityClient + CallOptions **ReachabilityCallOptions + + // The gRPC API client. + reachabilityClient networkmanagementpb.ReachabilityServiceClient + + // 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 +} + +// NewReachabilityClient creates a new reachability service client based on gRPC. +// The returned client must be Closed when it is done being used to clean up its underlying connections. +// +// The Reachability service in the Google Cloud Network Management API provides +// services that analyze the reachability within a single Google Virtual Private +// Cloud (VPC) network, between peered VPC networks, between VPC and on-premises +// networks, or between VPC networks and internet hosts. A reachability analysis +// is based on Google Cloud network configurations. +// +// You can use the analysis results to verify these configurations and +// to troubleshoot connectivity issues. +func NewReachabilityClient(ctx context.Context, opts ...option.ClientOption) (*ReachabilityClient, error) { + clientOpts := defaultReachabilityGRPCClientOptions() + if newReachabilityClientHook != nil { + hookOpts, err := newReachabilityClientHook(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 := ReachabilityClient{CallOptions: defaultReachabilityCallOptions()} + + c := &reachabilityGRPCClient{ + connPool: connPool, + disableDeadlines: disableDeadlines, + reachabilityClient: networkmanagementpb.NewReachabilityServiceClient(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 *reachabilityGRPCClient) 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 *reachabilityGRPCClient) 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 *reachabilityGRPCClient) Close() error { + return c.connPool.Close() +} + +func (c *reachabilityGRPCClient) ListConnectivityTests(ctx context.Context, req *networkmanagementpb.ListConnectivityTestsRequest, opts ...gax.CallOption) *ConnectivityTestIterator { + 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).ListConnectivityTests[0:len((*c.CallOptions).ListConnectivityTests):len((*c.CallOptions).ListConnectivityTests)], opts...) + it := &ConnectivityTestIterator{} + req = proto.Clone(req).(*networkmanagementpb.ListConnectivityTestsRequest) + it.InternalFetch = func(pageSize int, pageToken string) ([]*networkmanagementpb.ConnectivityTest, string, error) { + var resp *networkmanagementpb.ListConnectivityTestsResponse + 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.reachabilityClient.ListConnectivityTests(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, "", err + } + + it.Response = resp + return resp.GetResources(), 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 *reachabilityGRPCClient) GetConnectivityTest(ctx context.Context, req *networkmanagementpb.GetConnectivityTestRequest, opts ...gax.CallOption) (*networkmanagementpb.ConnectivityTest, 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).GetConnectivityTest[0:len((*c.CallOptions).GetConnectivityTest):len((*c.CallOptions).GetConnectivityTest)], opts...) + var resp *networkmanagementpb.ConnectivityTest + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.reachabilityClient.GetConnectivityTest(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} + +func (c *reachabilityGRPCClient) CreateConnectivityTest(ctx context.Context, req *networkmanagementpb.CreateConnectivityTestRequest, opts ...gax.CallOption) (*CreateConnectivityTestOperation, 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).CreateConnectivityTest[0:len((*c.CallOptions).CreateConnectivityTest):len((*c.CallOptions).CreateConnectivityTest)], opts...) + var resp *longrunningpb.Operation + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.reachabilityClient.CreateConnectivityTest(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return &CreateConnectivityTestOperation{ + lro: longrunning.InternalNewOperation(*c.LROClient, resp), + }, nil +} + +func (c *reachabilityGRPCClient) UpdateConnectivityTest(ctx context.Context, req *networkmanagementpb.UpdateConnectivityTestRequest, opts ...gax.CallOption) (*UpdateConnectivityTestOperation, 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", "resource.name", url.QueryEscape(req.GetResource().GetName()))) + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append((*c.CallOptions).UpdateConnectivityTest[0:len((*c.CallOptions).UpdateConnectivityTest):len((*c.CallOptions).UpdateConnectivityTest)], opts...) + var resp *longrunningpb.Operation + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.reachabilityClient.UpdateConnectivityTest(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return &UpdateConnectivityTestOperation{ + lro: longrunning.InternalNewOperation(*c.LROClient, resp), + }, nil +} + +func (c *reachabilityGRPCClient) RerunConnectivityTest(ctx context.Context, req *networkmanagementpb.RerunConnectivityTestRequest, opts ...gax.CallOption) (*RerunConnectivityTestOperation, 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).RerunConnectivityTest[0:len((*c.CallOptions).RerunConnectivityTest):len((*c.CallOptions).RerunConnectivityTest)], opts...) + var resp *longrunningpb.Operation + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.reachabilityClient.RerunConnectivityTest(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return &RerunConnectivityTestOperation{ + lro: longrunning.InternalNewOperation(*c.LROClient, resp), + }, nil +} + +func (c *reachabilityGRPCClient) DeleteConnectivityTest(ctx context.Context, req *networkmanagementpb.DeleteConnectivityTestRequest, opts ...gax.CallOption) (*DeleteConnectivityTestOperation, 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).DeleteConnectivityTest[0:len((*c.CallOptions).DeleteConnectivityTest):len((*c.CallOptions).DeleteConnectivityTest)], opts...) + var resp *longrunningpb.Operation + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.reachabilityClient.DeleteConnectivityTest(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return &DeleteConnectivityTestOperation{ + lro: longrunning.InternalNewOperation(*c.LROClient, resp), + }, nil +} + +// CreateConnectivityTestOperation manages a long-running operation from CreateConnectivityTest. +type CreateConnectivityTestOperation struct { + lro *longrunning.Operation +} + +// CreateConnectivityTestOperation returns a new CreateConnectivityTestOperation from a given name. +// The name must be that of a previously created CreateConnectivityTestOperation, possibly from a different process. +func (c *reachabilityGRPCClient) CreateConnectivityTestOperation(name string) *CreateConnectivityTestOperation { + return &CreateConnectivityTestOperation{ + 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 *CreateConnectivityTestOperation) Wait(ctx context.Context, opts ...gax.CallOption) (*networkmanagementpb.ConnectivityTest, error) { + var resp networkmanagementpb.ConnectivityTest + 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 *CreateConnectivityTestOperation) Poll(ctx context.Context, opts ...gax.CallOption) (*networkmanagementpb.ConnectivityTest, error) { + var resp networkmanagementpb.ConnectivityTest + 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 *CreateConnectivityTestOperation) Metadata() (*networkmanagementpb.OperationMetadata, error) { + var meta networkmanagementpb.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 *CreateConnectivityTestOperation) 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 *CreateConnectivityTestOperation) Name() string { + return op.lro.Name() +} + +// DeleteConnectivityTestOperation manages a long-running operation from DeleteConnectivityTest. +type DeleteConnectivityTestOperation struct { + lro *longrunning.Operation +} + +// DeleteConnectivityTestOperation returns a new DeleteConnectivityTestOperation from a given name. +// The name must be that of a previously created DeleteConnectivityTestOperation, possibly from a different process. +func (c *reachabilityGRPCClient) DeleteConnectivityTestOperation(name string) *DeleteConnectivityTestOperation { + return &DeleteConnectivityTestOperation{ + 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 *DeleteConnectivityTestOperation) 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 *DeleteConnectivityTestOperation) 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 *DeleteConnectivityTestOperation) Metadata() (*networkmanagementpb.OperationMetadata, error) { + var meta networkmanagementpb.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 *DeleteConnectivityTestOperation) 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 *DeleteConnectivityTestOperation) Name() string { + return op.lro.Name() +} + +// RerunConnectivityTestOperation manages a long-running operation from RerunConnectivityTest. +type RerunConnectivityTestOperation struct { + lro *longrunning.Operation +} + +// RerunConnectivityTestOperation returns a new RerunConnectivityTestOperation from a given name. +// The name must be that of a previously created RerunConnectivityTestOperation, possibly from a different process. +func (c *reachabilityGRPCClient) RerunConnectivityTestOperation(name string) *RerunConnectivityTestOperation { + return &RerunConnectivityTestOperation{ + 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 *RerunConnectivityTestOperation) Wait(ctx context.Context, opts ...gax.CallOption) (*networkmanagementpb.ConnectivityTest, error) { + var resp networkmanagementpb.ConnectivityTest + 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 *RerunConnectivityTestOperation) Poll(ctx context.Context, opts ...gax.CallOption) (*networkmanagementpb.ConnectivityTest, error) { + var resp networkmanagementpb.ConnectivityTest + 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 *RerunConnectivityTestOperation) Metadata() (*networkmanagementpb.OperationMetadata, error) { + var meta networkmanagementpb.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 *RerunConnectivityTestOperation) 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 *RerunConnectivityTestOperation) Name() string { + return op.lro.Name() +} + +// UpdateConnectivityTestOperation manages a long-running operation from UpdateConnectivityTest. +type UpdateConnectivityTestOperation struct { + lro *longrunning.Operation +} + +// UpdateConnectivityTestOperation returns a new UpdateConnectivityTestOperation from a given name. +// The name must be that of a previously created UpdateConnectivityTestOperation, possibly from a different process. +func (c *reachabilityGRPCClient) UpdateConnectivityTestOperation(name string) *UpdateConnectivityTestOperation { + return &UpdateConnectivityTestOperation{ + 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 *UpdateConnectivityTestOperation) Wait(ctx context.Context, opts ...gax.CallOption) (*networkmanagementpb.ConnectivityTest, error) { + var resp networkmanagementpb.ConnectivityTest + 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 *UpdateConnectivityTestOperation) Poll(ctx context.Context, opts ...gax.CallOption) (*networkmanagementpb.ConnectivityTest, error) { + var resp networkmanagementpb.ConnectivityTest + 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 *UpdateConnectivityTestOperation) Metadata() (*networkmanagementpb.OperationMetadata, error) { + var meta networkmanagementpb.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 *UpdateConnectivityTestOperation) 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 *UpdateConnectivityTestOperation) Name() string { + return op.lro.Name() +} + +// ConnectivityTestIterator manages a stream of *networkmanagementpb.ConnectivityTest. +type ConnectivityTestIterator struct { + items []*networkmanagementpb.ConnectivityTest + 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 []*networkmanagementpb.ConnectivityTest, nextPageToken string, err error) +} + +// PageInfo supports pagination. See the google.golang.org/api/iterator package for details. +func (it *ConnectivityTestIterator) 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 *ConnectivityTestIterator) Next() (*networkmanagementpb.ConnectivityTest, error) { + var item *networkmanagementpb.ConnectivityTest + if err := it.nextFunc(); err != nil { + return item, err + } + item = it.items[0] + it.items = it.items[1:] + return item, nil +} + +func (it *ConnectivityTestIterator) bufLen() int { + return len(it.items) +} + +func (it *ConnectivityTestIterator) takeBuf() interface{} { + b := it.items + it.items = nil + return b +} diff --git a/networkmanagement/apiv1/reachability_client_example_test.go b/networkmanagement/apiv1/reachability_client_example_test.go new file mode 100644 index 000000000000..14d25208d4e0 --- /dev/null +++ b/networkmanagement/apiv1/reachability_client_example_test.go @@ -0,0 +1,175 @@ +// 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 networkmanagement_test + +import ( + "context" + + networkmanagement "cloud.google.com/go/networkmanagement/apiv1" + "google.golang.org/api/iterator" + networkmanagementpb "google.golang.org/genproto/googleapis/cloud/networkmanagement/v1" +) + +func ExampleNewReachabilityClient() { + ctx := context.Background() + c, err := networkmanagement.NewReachabilityClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + // TODO: Use client. + _ = c +} + +func ExampleReachabilityClient_ListConnectivityTests() { + ctx := context.Background() + c, err := networkmanagement.NewReachabilityClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &networkmanagementpb.ListConnectivityTestsRequest{ + // TODO: Fill request struct fields. + } + it := c.ListConnectivityTests(ctx, req) + for { + resp, err := it.Next() + if err == iterator.Done { + break + } + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp + } +} + +func ExampleReachabilityClient_GetConnectivityTest() { + ctx := context.Background() + c, err := networkmanagement.NewReachabilityClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &networkmanagementpb.GetConnectivityTestRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.GetConnectivityTest(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleReachabilityClient_CreateConnectivityTest() { + ctx := context.Background() + c, err := networkmanagement.NewReachabilityClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &networkmanagementpb.CreateConnectivityTestRequest{ + // TODO: Fill request struct fields. + } + op, err := c.CreateConnectivityTest(ctx, req) + if err != nil { + // TODO: Handle error. + } + + resp, err := op.Wait(ctx) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleReachabilityClient_UpdateConnectivityTest() { + ctx := context.Background() + c, err := networkmanagement.NewReachabilityClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &networkmanagementpb.UpdateConnectivityTestRequest{ + // TODO: Fill request struct fields. + } + op, err := c.UpdateConnectivityTest(ctx, req) + if err != nil { + // TODO: Handle error. + } + + resp, err := op.Wait(ctx) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleReachabilityClient_RerunConnectivityTest() { + ctx := context.Background() + c, err := networkmanagement.NewReachabilityClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &networkmanagementpb.RerunConnectivityTestRequest{ + // TODO: Fill request struct fields. + } + op, err := c.RerunConnectivityTest(ctx, req) + if err != nil { + // TODO: Handle error. + } + + resp, err := op.Wait(ctx) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleReachabilityClient_DeleteConnectivityTest() { + ctx := context.Background() + c, err := networkmanagement.NewReachabilityClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &networkmanagementpb.DeleteConnectivityTestRequest{ + // TODO: Fill request struct fields. + } + op, err := c.DeleteConnectivityTest(ctx, req) + if err != nil { + // TODO: Handle error. + } + + err = op.Wait(ctx) + if err != nil { + // TODO: Handle error. + } +} diff --git a/video/transcoder/apiv1/doc.go b/video/transcoder/apiv1/doc.go new file mode 100644 index 000000000000..555b86748db5 --- /dev/null +++ b/video/transcoder/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 transcoder is an auto-generated package for the +// Transcoder API. +// +// This API converts video files into formats suitable for consumer +// distribution. +// +// 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 transcoder // import "cloud.google.com/go/video/transcoder/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 = "20210712" + +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/video/transcoder/apiv1/gapic_metadata.json b/video/transcoder/apiv1/gapic_metadata.json new file mode 100644 index 000000000000..cdf2d1c1be02 --- /dev/null +++ b/video/transcoder/apiv1/gapic_metadata.json @@ -0,0 +1,58 @@ +{ + "schema": "1.0", + "comment": "This file maps proto services/RPCs to the corresponding library clients/methods.", + "language": "go", + "protoPackage": "google.cloud.video.transcoder.v1", + "libraryPackage": "cloud.google.com/go/video/transcoder/apiv1", + "services": { + "TranscoderService": { + "clients": { + "grpc": { + "libraryClient": "Client", + "rpcs": { + "CreateJob": { + "methods": [ + "CreateJob" + ] + }, + "CreateJobTemplate": { + "methods": [ + "CreateJobTemplate" + ] + }, + "DeleteJob": { + "methods": [ + "DeleteJob" + ] + }, + "DeleteJobTemplate": { + "methods": [ + "DeleteJobTemplate" + ] + }, + "GetJob": { + "methods": [ + "GetJob" + ] + }, + "GetJobTemplate": { + "methods": [ + "GetJobTemplate" + ] + }, + "ListJobTemplates": { + "methods": [ + "ListJobTemplates" + ] + }, + "ListJobs": { + "methods": [ + "ListJobs" + ] + } + } + } + } + } + } +} diff --git a/video/transcoder/apiv1/transcoder_client.go b/video/transcoder/apiv1/transcoder_client.go new file mode 100644 index 000000000000..5be1d2ca569c --- /dev/null +++ b/video/transcoder/apiv1/transcoder_client.go @@ -0,0 +1,546 @@ +// 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 transcoder + +import ( + "context" + "fmt" + "math" + "net/url" + "time" + + 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" + transcoderpb "google.golang.org/genproto/googleapis/cloud/video/transcoder/v1" + "google.golang.org/grpc" + "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" +) + +var newClientHook clientHook + +// CallOptions contains the retry settings for each method of Client. +type CallOptions struct { + CreateJob []gax.CallOption + ListJobs []gax.CallOption + GetJob []gax.CallOption + DeleteJob []gax.CallOption + CreateJobTemplate []gax.CallOption + ListJobTemplates []gax.CallOption + GetJobTemplate []gax.CallOption + DeleteJobTemplate []gax.CallOption +} + +func defaultGRPCClientOptions() []option.ClientOption { + return []option.ClientOption{ + internaloption.WithDefaultEndpoint("transcoder.googleapis.com:443"), + internaloption.WithDefaultMTLSEndpoint("transcoder.mtls.googleapis.com:443"), + internaloption.WithDefaultAudience("https://transcoder.googleapis.com/"), + internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), + option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), + option.WithGRPCDialOption(grpc.WithDefaultCallOptions( + grpc.MaxCallRecvMsgSize(math.MaxInt32))), + } +} + +func defaultCallOptions() *CallOptions { + return &CallOptions{ + CreateJob: []gax.CallOption{}, + ListJobs: []gax.CallOption{}, + GetJob: []gax.CallOption{}, + DeleteJob: []gax.CallOption{}, + CreateJobTemplate: []gax.CallOption{}, + ListJobTemplates: []gax.CallOption{}, + GetJobTemplate: []gax.CallOption{}, + DeleteJobTemplate: []gax.CallOption{}, + } +} + +// internalClient is an interface that defines the methods availaible from Transcoder API. +type internalClient interface { + Close() error + setGoogleClientInfo(...string) + Connection() *grpc.ClientConn + CreateJob(context.Context, *transcoderpb.CreateJobRequest, ...gax.CallOption) (*transcoderpb.Job, error) + ListJobs(context.Context, *transcoderpb.ListJobsRequest, ...gax.CallOption) *JobIterator + GetJob(context.Context, *transcoderpb.GetJobRequest, ...gax.CallOption) (*transcoderpb.Job, error) + DeleteJob(context.Context, *transcoderpb.DeleteJobRequest, ...gax.CallOption) error + CreateJobTemplate(context.Context, *transcoderpb.CreateJobTemplateRequest, ...gax.CallOption) (*transcoderpb.JobTemplate, error) + ListJobTemplates(context.Context, *transcoderpb.ListJobTemplatesRequest, ...gax.CallOption) *JobTemplateIterator + GetJobTemplate(context.Context, *transcoderpb.GetJobTemplateRequest, ...gax.CallOption) (*transcoderpb.JobTemplate, error) + DeleteJobTemplate(context.Context, *transcoderpb.DeleteJobTemplateRequest, ...gax.CallOption) error +} + +// Client is a client for interacting with Transcoder API. +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +// +// Using the Transcoder API, you can queue asynchronous jobs for transcoding +// media into various output formats. Output formats may include different +// streaming standards such as HTTP Live Streaming (HLS) and Dynamic Adaptive +// Streaming over HTTP (DASH). You can also customize jobs using advanced +// features such as Digital Rights Management (DRM), audio equalization, content +// concatenation, and digital ad-stitch ready content generation. +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() +} + +// CreateJob creates a job in the specified region. +func (c *Client) CreateJob(ctx context.Context, req *transcoderpb.CreateJobRequest, opts ...gax.CallOption) (*transcoderpb.Job, error) { + return c.internalClient.CreateJob(ctx, req, opts...) +} + +// ListJobs lists jobs in the specified region. +func (c *Client) ListJobs(ctx context.Context, req *transcoderpb.ListJobsRequest, opts ...gax.CallOption) *JobIterator { + return c.internalClient.ListJobs(ctx, req, opts...) +} + +// GetJob returns the job data. +func (c *Client) GetJob(ctx context.Context, req *transcoderpb.GetJobRequest, opts ...gax.CallOption) (*transcoderpb.Job, error) { + return c.internalClient.GetJob(ctx, req, opts...) +} + +// DeleteJob deletes a job. +func (c *Client) DeleteJob(ctx context.Context, req *transcoderpb.DeleteJobRequest, opts ...gax.CallOption) error { + return c.internalClient.DeleteJob(ctx, req, opts...) +} + +// CreateJobTemplate creates a job template in the specified region. +func (c *Client) CreateJobTemplate(ctx context.Context, req *transcoderpb.CreateJobTemplateRequest, opts ...gax.CallOption) (*transcoderpb.JobTemplate, error) { + return c.internalClient.CreateJobTemplate(ctx, req, opts...) +} + +// ListJobTemplates lists job templates in the specified region. +func (c *Client) ListJobTemplates(ctx context.Context, req *transcoderpb.ListJobTemplatesRequest, opts ...gax.CallOption) *JobTemplateIterator { + return c.internalClient.ListJobTemplates(ctx, req, opts...) +} + +// GetJobTemplate returns the job template data. +func (c *Client) GetJobTemplate(ctx context.Context, req *transcoderpb.GetJobTemplateRequest, opts ...gax.CallOption) (*transcoderpb.JobTemplate, error) { + return c.internalClient.GetJobTemplate(ctx, req, opts...) +} + +// DeleteJobTemplate deletes a job template. +func (c *Client) DeleteJobTemplate(ctx context.Context, req *transcoderpb.DeleteJobTemplateRequest, opts ...gax.CallOption) error { + return c.internalClient.DeleteJobTemplate(ctx, req, opts...) +} + +// gRPCClient is a client for interacting with Transcoder 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 transcoderpb.TranscoderServiceClient + + // The x-goog-* metadata to be sent with each request. + xGoogMetadata metadata.MD +} + +// NewClient creates a new transcoder service client based on gRPC. +// The returned client must be Closed when it is done being used to clean up its underlying connections. +// +// Using the Transcoder API, you can queue asynchronous jobs for transcoding +// media into various output formats. Output formats may include different +// streaming standards such as HTTP Live Streaming (HLS) and Dynamic Adaptive +// Streaming over HTTP (DASH). You can also customize jobs using advanced +// features such as Digital Rights Management (DRM), audio equalization, content +// concatenation, and digital ad-stitch ready content generation. +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: transcoderpb.NewTranscoderServiceClient(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) CreateJob(ctx context.Context, req *transcoderpb.CreateJobRequest, opts ...gax.CallOption) (*transcoderpb.Job, 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).CreateJob[0:len((*c.CallOptions).CreateJob):len((*c.CallOptions).CreateJob)], opts...) + var resp *transcoderpb.Job + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.client.CreateJob(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} + +func (c *gRPCClient) ListJobs(ctx context.Context, req *transcoderpb.ListJobsRequest, opts ...gax.CallOption) *JobIterator { + 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).ListJobs[0:len((*c.CallOptions).ListJobs):len((*c.CallOptions).ListJobs)], opts...) + it := &JobIterator{} + req = proto.Clone(req).(*transcoderpb.ListJobsRequest) + it.InternalFetch = func(pageSize int, pageToken string) ([]*transcoderpb.Job, string, error) { + var resp *transcoderpb.ListJobsResponse + 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.ListJobs(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, "", err + } + + it.Response = resp + return resp.GetJobs(), 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) GetJob(ctx context.Context, req *transcoderpb.GetJobRequest, opts ...gax.CallOption) (*transcoderpb.Job, 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).GetJob[0:len((*c.CallOptions).GetJob):len((*c.CallOptions).GetJob)], opts...) + var resp *transcoderpb.Job + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.client.GetJob(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} + +func (c *gRPCClient) DeleteJob(ctx context.Context, req *transcoderpb.DeleteJobRequest, opts ...gax.CallOption) 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).DeleteJob[0:len((*c.CallOptions).DeleteJob):len((*c.CallOptions).DeleteJob)], opts...) + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + _, err = c.client.DeleteJob(ctx, req, settings.GRPC...) + return err + }, opts...) + return err +} + +func (c *gRPCClient) CreateJobTemplate(ctx context.Context, req *transcoderpb.CreateJobTemplateRequest, opts ...gax.CallOption) (*transcoderpb.JobTemplate, 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).CreateJobTemplate[0:len((*c.CallOptions).CreateJobTemplate):len((*c.CallOptions).CreateJobTemplate)], opts...) + var resp *transcoderpb.JobTemplate + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.client.CreateJobTemplate(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} + +func (c *gRPCClient) ListJobTemplates(ctx context.Context, req *transcoderpb.ListJobTemplatesRequest, opts ...gax.CallOption) *JobTemplateIterator { + 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).ListJobTemplates[0:len((*c.CallOptions).ListJobTemplates):len((*c.CallOptions).ListJobTemplates)], opts...) + it := &JobTemplateIterator{} + req = proto.Clone(req).(*transcoderpb.ListJobTemplatesRequest) + it.InternalFetch = func(pageSize int, pageToken string) ([]*transcoderpb.JobTemplate, string, error) { + var resp *transcoderpb.ListJobTemplatesResponse + 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.ListJobTemplates(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, "", err + } + + it.Response = resp + return resp.GetJobTemplates(), 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) GetJobTemplate(ctx context.Context, req *transcoderpb.GetJobTemplateRequest, opts ...gax.CallOption) (*transcoderpb.JobTemplate, 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).GetJobTemplate[0:len((*c.CallOptions).GetJobTemplate):len((*c.CallOptions).GetJobTemplate)], opts...) + var resp *transcoderpb.JobTemplate + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.client.GetJobTemplate(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} + +func (c *gRPCClient) DeleteJobTemplate(ctx context.Context, req *transcoderpb.DeleteJobTemplateRequest, opts ...gax.CallOption) 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).DeleteJobTemplate[0:len((*c.CallOptions).DeleteJobTemplate):len((*c.CallOptions).DeleteJobTemplate)], opts...) + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + _, err = c.client.DeleteJobTemplate(ctx, req, settings.GRPC...) + return err + }, opts...) + return err +} + +// JobIterator manages a stream of *transcoderpb.Job. +type JobIterator struct { + items []*transcoderpb.Job + 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 []*transcoderpb.Job, nextPageToken string, err error) +} + +// PageInfo supports pagination. See the google.golang.org/api/iterator package for details. +func (it *JobIterator) 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 *JobIterator) Next() (*transcoderpb.Job, error) { + var item *transcoderpb.Job + if err := it.nextFunc(); err != nil { + return item, err + } + item = it.items[0] + it.items = it.items[1:] + return item, nil +} + +func (it *JobIterator) bufLen() int { + return len(it.items) +} + +func (it *JobIterator) takeBuf() interface{} { + b := it.items + it.items = nil + return b +} + +// JobTemplateIterator manages a stream of *transcoderpb.JobTemplate. +type JobTemplateIterator struct { + items []*transcoderpb.JobTemplate + 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 []*transcoderpb.JobTemplate, nextPageToken string, err error) +} + +// PageInfo supports pagination. See the google.golang.org/api/iterator package for details. +func (it *JobTemplateIterator) 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 *JobTemplateIterator) Next() (*transcoderpb.JobTemplate, error) { + var item *transcoderpb.JobTemplate + if err := it.nextFunc(); err != nil { + return item, err + } + item = it.items[0] + it.items = it.items[1:] + return item, nil +} + +func (it *JobTemplateIterator) bufLen() int { + return len(it.items) +} + +func (it *JobTemplateIterator) takeBuf() interface{} { + b := it.items + it.items = nil + return b +} diff --git a/video/transcoder/apiv1/transcoder_client_example_test.go b/video/transcoder/apiv1/transcoder_client_example_test.go new file mode 100644 index 000000000000..6e6f7e051a1e --- /dev/null +++ b/video/transcoder/apiv1/transcoder_client_example_test.go @@ -0,0 +1,197 @@ +// 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 transcoder_test + +import ( + "context" + + transcoder "cloud.google.com/go/video/transcoder/apiv1" + "google.golang.org/api/iterator" + transcoderpb "google.golang.org/genproto/googleapis/cloud/video/transcoder/v1" +) + +func ExampleNewClient() { + ctx := context.Background() + c, err := transcoder.NewClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + // TODO: Use client. + _ = c +} + +func ExampleClient_CreateJob() { + ctx := context.Background() + c, err := transcoder.NewClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &transcoderpb.CreateJobRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.CreateJob(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleClient_ListJobs() { + ctx := context.Background() + c, err := transcoder.NewClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &transcoderpb.ListJobsRequest{ + // TODO: Fill request struct fields. + } + it := c.ListJobs(ctx, req) + for { + resp, err := it.Next() + if err == iterator.Done { + break + } + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp + } +} + +func ExampleClient_GetJob() { + ctx := context.Background() + c, err := transcoder.NewClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &transcoderpb.GetJobRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.GetJob(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleClient_DeleteJob() { + ctx := context.Background() + c, err := transcoder.NewClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &transcoderpb.DeleteJobRequest{ + // TODO: Fill request struct fields. + } + err = c.DeleteJob(ctx, req) + if err != nil { + // TODO: Handle error. + } +} + +func ExampleClient_CreateJobTemplate() { + ctx := context.Background() + c, err := transcoder.NewClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &transcoderpb.CreateJobTemplateRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.CreateJobTemplate(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleClient_ListJobTemplates() { + ctx := context.Background() + c, err := transcoder.NewClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &transcoderpb.ListJobTemplatesRequest{ + // TODO: Fill request struct fields. + } + it := c.ListJobTemplates(ctx, req) + for { + resp, err := it.Next() + if err == iterator.Done { + break + } + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp + } +} + +func ExampleClient_GetJobTemplate() { + ctx := context.Background() + c, err := transcoder.NewClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &transcoderpb.GetJobTemplateRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.GetJobTemplate(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleClient_DeleteJobTemplate() { + ctx := context.Background() + c, err := transcoder.NewClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &transcoderpb.DeleteJobTemplateRequest{ + // TODO: Fill request struct fields. + } + err = c.DeleteJobTemplate(ctx, req) + if err != nil { + // TODO: Handle error. + } +}