diff --git a/.github/blunderbuss.yml b/.github/blunderbuss.yml index ee6a8c7b7e2..a339964791c 100644 --- a/.github/blunderbuss.yml +++ b/.github/blunderbuss.yml @@ -25,4 +25,4 @@ assign_issues_by: - 'api: logging' - 'api: clouderrorreporting' to: - - nicoleczhu + - googleapis/api-logging diff --git a/CHANGES.md b/CHANGES.md index ff6d1ec3e65..b0d936c6057 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,5 +1,37 @@ # Changes +## [0.86.0](https://www.github.com/googleapis/google-cloud-go/compare/v0.85.0...v0.86.0) (2021-07-01) + + +### Features + +* **bigquery managedwriter:** schema conversion support ([#4357](https://www.github.com/googleapis/google-cloud-go/issues/4357)) ([f2b20f4](https://www.github.com/googleapis/google-cloud-go/commit/f2b20f493e2ed5a883ce42fa65695c03c574feb5)) + +## [0.85.0](https://www.github.com/googleapis/google-cloud-go/compare/v0.84.0...v0.85.0) (2021-06-30) + + +### Features + +* **dataflow:** start generating apiv1beta3 ([cfee361](https://www.github.com/googleapis/google-cloud-go/commit/cfee36161d41e3a0f769e51ab96c25d0967af273)) +* **datastream:** start generating apiv1alpha1 ([cfee361](https://www.github.com/googleapis/google-cloud-go/commit/cfee36161d41e3a0f769e51ab96c25d0967af273)) +* **dialogflow:** added Automated agent reply type and allow cancellation flag for partial response feature. ([5a9c6ce](https://www.github.com/googleapis/google-cloud-go/commit/5a9c6ce781fb6a338e29d3dee72367998d834af0)) +* **documentai:** update document.proto, add the processor management methods. ([5a9c6ce](https://www.github.com/googleapis/google-cloud-go/commit/5a9c6ce781fb6a338e29d3dee72367998d834af0)) +* **eventarc:** start generating apiv1 ([cfee361](https://www.github.com/googleapis/google-cloud-go/commit/cfee36161d41e3a0f769e51ab96c25d0967af273)) +* **gkehub:** added v1alpha messages and client for gkehub ([8fb4649](https://www.github.com/googleapis/google-cloud-go/commit/8fb464956f0ca51d30e8e14dc625ff9fa150c437)) +* **internal/godocfx:** add support for other modules ([#4290](https://www.github.com/googleapis/google-cloud-go/issues/4290)) ([d52bae6](https://www.github.com/googleapis/google-cloud-go/commit/d52bae6cd77474174192c46236d309bf967dfa00)) +* **internal/godocfx:** different metadata for different modules ([#4297](https://www.github.com/googleapis/google-cloud-go/issues/4297)) ([598f5b9](https://www.github.com/googleapis/google-cloud-go/commit/598f5b93778b2e2e75265ae54484dd54477433f5)) +* **internal:** add force option for regen ([#4310](https://www.github.com/googleapis/google-cloud-go/issues/4310)) ([de654eb](https://www.github.com/googleapis/google-cloud-go/commit/de654ebfcf23a53b4d1fee0aa48c73999a55c1a6)) +* **servicecontrol:** Added the gRPC service config for the Service Controller v1 API docs: Updated some comments. ([8fb4649](https://www.github.com/googleapis/google-cloud-go/commit/8fb464956f0ca51d30e8e14dc625ff9fa150c437)) +* **workflows/executions:** start generating apiv1 ([cfee361](https://www.github.com/googleapis/google-cloud-go/commit/cfee36161d41e3a0f769e51ab96c25d0967af273)) + + +### Bug Fixes + +* **internal:** add autogenerated header to snippets ([#4261](https://www.github.com/googleapis/google-cloud-go/issues/4261)) ([2220787](https://www.github.com/googleapis/google-cloud-go/commit/222078722c37c3fdadec7bbbe0bcf81edd105f1a)), refs [#4260](https://www.github.com/googleapis/google-cloud-go/issues/4260) +* **internal:** fix googleapis-disco regen ([#4354](https://www.github.com/googleapis/google-cloud-go/issues/4354)) ([aeea1ce](https://www.github.com/googleapis/google-cloud-go/commit/aeea1ce1e5dff3acdfe208932327b52c49851b41)) +* **kms:** replace IAMPolicy mixin in service config. ([5a9c6ce](https://www.github.com/googleapis/google-cloud-go/commit/5a9c6ce781fb6a338e29d3dee72367998d834af0)) +* **security/privateca:** Fixed casing of the Ruby namespace ([5a9c6ce](https://www.github.com/googleapis/google-cloud-go/commit/5a9c6ce781fb6a338e29d3dee72367998d834af0)) + ## [0.84.0](https://www.github.com/googleapis/google-cloud-go/compare/v0.83.0...v0.84.0) (2021-06-09) diff --git a/accessapproval/apiv1/access_approval_client.go b/accessapproval/apiv1/access_approval_client.go index c4394e09497..fec2c79abc9 100644 --- a/accessapproval/apiv1/access_approval_client.go +++ b/accessapproval/apiv1/access_approval_client.go @@ -23,7 +23,6 @@ import ( "net/url" "time" - "github.com/golang/protobuf/proto" gax "github.com/googleapis/gax-go/v2" "google.golang.org/api/iterator" "google.golang.org/api/option" @@ -33,6 +32,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newClientHook clientHook @@ -54,6 +54,7 @@ func defaultGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("accessapproval.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://accessapproval.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/accessapproval/apiv1/doc.go b/accessapproval/apiv1/doc.go index c7520053af0..aee0b5b99f4 100644 --- a/accessapproval/apiv1/doc.go +++ b/accessapproval/apiv1/doc.go @@ -48,7 +48,7 @@ import ( type clientHookParams struct{} type clientHook func(context.Context, clientHookParams) ([]option.ClientOption, error) -const versionClient = "20210612" +const versionClient = "20210701" func insertMetadata(ctx context.Context, mds ...metadata.MD) context.Context { out, _ := metadata.FromOutgoingContext(ctx) diff --git a/aiplatform/apiv1/dataset_client.go b/aiplatform/apiv1/dataset_client.go index 9307ace54be..4214aeaab7d 100644 --- a/aiplatform/apiv1/dataset_client.go +++ b/aiplatform/apiv1/dataset_client.go @@ -25,7 +25,6 @@ import ( "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" @@ -35,6 +34,7 @@ import ( longrunningpb "google.golang.org/genproto/googleapis/longrunning" "google.golang.org/grpc" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newDatasetClientHook clientHook @@ -59,6 +59,7 @@ func defaultDatasetGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("aiplatform.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://aiplatform.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/aiplatform/apiv1/doc.go b/aiplatform/apiv1/doc.go index 18afa20658d..ed83992c68f 100644 --- a/aiplatform/apiv1/doc.go +++ b/aiplatform/apiv1/doc.go @@ -51,7 +51,7 @@ import ( type clientHookParams struct{} type clientHook func(context.Context, clientHookParams) ([]option.ClientOption, error) -const versionClient = "20210612" +const versionClient = "20210701" func insertMetadata(ctx context.Context, mds ...metadata.MD) context.Context { out, _ := metadata.FromOutgoingContext(ctx) diff --git a/aiplatform/apiv1/endpoint_client.go b/aiplatform/apiv1/endpoint_client.go index 7589c153447..636c46e522e 100644 --- a/aiplatform/apiv1/endpoint_client.go +++ b/aiplatform/apiv1/endpoint_client.go @@ -25,7 +25,6 @@ import ( "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" @@ -35,6 +34,7 @@ import ( longrunningpb "google.golang.org/genproto/googleapis/longrunning" "google.golang.org/grpc" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newEndpointClientHook clientHook @@ -56,6 +56,7 @@ func defaultEndpointGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("aiplatform.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://aiplatform.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/aiplatform/apiv1/job_client.go b/aiplatform/apiv1/job_client.go index c8a5308aa48..c4fecf637db 100644 --- a/aiplatform/apiv1/job_client.go +++ b/aiplatform/apiv1/job_client.go @@ -25,7 +25,6 @@ import ( "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" @@ -35,6 +34,7 @@ import ( longrunningpb "google.golang.org/genproto/googleapis/longrunning" "google.golang.org/grpc" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newJobClientHook clientHook @@ -69,6 +69,7 @@ func defaultJobGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("aiplatform.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://aiplatform.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/aiplatform/apiv1/migration_client.go b/aiplatform/apiv1/migration_client.go index 46a1e6f7ee9..447fc83ba47 100644 --- a/aiplatform/apiv1/migration_client.go +++ b/aiplatform/apiv1/migration_client.go @@ -25,7 +25,6 @@ import ( "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" @@ -35,6 +34,7 @@ import ( longrunningpb "google.golang.org/genproto/googleapis/longrunning" "google.golang.org/grpc" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newMigrationClientHook clientHook @@ -51,6 +51,7 @@ func defaultMigrationGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("aiplatform.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://aiplatform.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/aiplatform/apiv1/model_client.go b/aiplatform/apiv1/model_client.go index 5484919db10..2b52406a393 100644 --- a/aiplatform/apiv1/model_client.go +++ b/aiplatform/apiv1/model_client.go @@ -25,7 +25,6 @@ import ( "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" @@ -35,6 +34,7 @@ import ( longrunningpb "google.golang.org/genproto/googleapis/longrunning" "google.golang.org/grpc" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newModelClientHook clientHook @@ -59,6 +59,7 @@ func defaultModelGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("aiplatform.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://aiplatform.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/aiplatform/apiv1/pipeline_client.go b/aiplatform/apiv1/pipeline_client.go index 788c74a5145..757da517ef5 100644 --- a/aiplatform/apiv1/pipeline_client.go +++ b/aiplatform/apiv1/pipeline_client.go @@ -25,7 +25,6 @@ import ( "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" @@ -35,6 +34,7 @@ import ( longrunningpb "google.golang.org/genproto/googleapis/longrunning" "google.golang.org/grpc" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newPipelineClientHook clientHook @@ -54,6 +54,7 @@ func defaultPipelineGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("aiplatform.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://aiplatform.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/aiplatform/apiv1/prediction_client.go b/aiplatform/apiv1/prediction_client.go index 5308483dbc7..2230c25f34e 100644 --- a/aiplatform/apiv1/prediction_client.go +++ b/aiplatform/apiv1/prediction_client.go @@ -45,6 +45,7 @@ func defaultPredictionGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("aiplatform.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://aiplatform.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/aiplatform/apiv1/specialist_pool_client.go b/aiplatform/apiv1/specialist_pool_client.go index 654cd3db4a4..1e43a1f661b 100644 --- a/aiplatform/apiv1/specialist_pool_client.go +++ b/aiplatform/apiv1/specialist_pool_client.go @@ -25,7 +25,6 @@ import ( "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" @@ -35,6 +34,7 @@ import ( longrunningpb "google.golang.org/genproto/googleapis/longrunning" "google.golang.org/grpc" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newSpecialistPoolClientHook clientHook @@ -54,6 +54,7 @@ func defaultSpecialistPoolGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("aiplatform.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://aiplatform.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/analytics/admin/apiv1alpha/analytics_admin_client.go b/analytics/admin/apiv1alpha/analytics_admin_client.go index a4fb2254aa8..66ac56428a2 100644 --- a/analytics/admin/apiv1alpha/analytics_admin_client.go +++ b/analytics/admin/apiv1alpha/analytics_admin_client.go @@ -23,7 +23,6 @@ import ( "net/url" "time" - "github.com/golang/protobuf/proto" gax "github.com/googleapis/gax-go/v2" "google.golang.org/api/iterator" "google.golang.org/api/option" @@ -33,6 +32,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newAnalyticsAdminClientHook clientHook @@ -115,6 +115,7 @@ func defaultAnalyticsAdminGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("analyticsadmin.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://analyticsadmin.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/analytics/admin/apiv1alpha/doc.go b/analytics/admin/apiv1alpha/doc.go index 8d2c9d2bc76..45b5491c685 100644 --- a/analytics/admin/apiv1alpha/doc.go +++ b/analytics/admin/apiv1alpha/doc.go @@ -48,7 +48,7 @@ import ( type clientHookParams struct{} type clientHook func(context.Context, clientHookParams) ([]option.ClientOption, error) -const versionClient = "20210612" +const versionClient = "20210701" func insertMetadata(ctx context.Context, mds ...metadata.MD) context.Context { out, _ := metadata.FromOutgoingContext(ctx) diff --git a/analytics/data/apiv1alpha/alpha_analytics_data_client.go b/analytics/data/apiv1alpha/alpha_analytics_data_client.go index 36941b6eb24..af4865312ca 100644 --- a/analytics/data/apiv1alpha/alpha_analytics_data_client.go +++ b/analytics/data/apiv1alpha/alpha_analytics_data_client.go @@ -51,6 +51,7 @@ func defaultAlphaAnalyticsDataGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("analyticsdata.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://analyticsdata.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/analytics/data/apiv1alpha/doc.go b/analytics/data/apiv1alpha/doc.go index 430c77099b4..910b0e116d2 100644 --- a/analytics/data/apiv1alpha/doc.go +++ b/analytics/data/apiv1alpha/doc.go @@ -50,7 +50,7 @@ import ( type clientHookParams struct{} type clientHook func(context.Context, clientHookParams) ([]option.ClientOption, error) -const versionClient = "20210617" +const versionClient = "20210701" func insertMetadata(ctx context.Context, mds ...metadata.MD) context.Context { out, _ := metadata.FromOutgoingContext(ctx) diff --git a/apigateway/apiv1/api_gateway_client.go b/apigateway/apiv1/api_gateway_client.go index ade65eecddd..e84288806e8 100644 --- a/apigateway/apiv1/api_gateway_client.go +++ b/apigateway/apiv1/api_gateway_client.go @@ -25,7 +25,6 @@ import ( "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" @@ -36,6 +35,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newClientHook clientHook @@ -65,6 +65,7 @@ func defaultGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("apigateway.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://apigateway.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/apigateway/apiv1/doc.go b/apigateway/apiv1/doc.go index 1890f8dc4cf..c82a2e66029 100644 --- a/apigateway/apiv1/doc.go +++ b/apigateway/apiv1/doc.go @@ -46,7 +46,7 @@ import ( type clientHookParams struct{} type clientHook func(context.Context, clientHookParams) ([]option.ClientOption, error) -const versionClient = "20210612" +const versionClient = "20210701" func insertMetadata(ctx context.Context, mds ...metadata.MD) context.Context { out, _ := metadata.FromOutgoingContext(ctx) diff --git a/apigeeconnect/apiv1/connection_client.go b/apigeeconnect/apiv1/connection_client.go index 088df7683c2..479a5ebcf3c 100644 --- a/apigeeconnect/apiv1/connection_client.go +++ b/apigeeconnect/apiv1/connection_client.go @@ -23,7 +23,6 @@ import ( "net/url" "time" - "github.com/golang/protobuf/proto" gax "github.com/googleapis/gax-go/v2" "google.golang.org/api/iterator" "google.golang.org/api/option" @@ -33,6 +32,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newConnectionClientHook clientHook @@ -48,6 +48,7 @@ func defaultConnectionGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("apigeeconnect.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://apigeeconnect.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/apigeeconnect/apiv1/doc.go b/apigeeconnect/apiv1/doc.go index 869d11c3fa1..0cd7905ed55 100644 --- a/apigeeconnect/apiv1/doc.go +++ b/apigeeconnect/apiv1/doc.go @@ -48,7 +48,7 @@ import ( type clientHookParams struct{} type clientHook func(context.Context, clientHookParams) ([]option.ClientOption, error) -const versionClient = "20210612" +const versionClient = "20210701" func insertMetadata(ctx context.Context, mds ...metadata.MD) context.Context { out, _ := metadata.FromOutgoingContext(ctx) diff --git a/apigeeconnect/apiv1/tether_client.go b/apigeeconnect/apiv1/tether_client.go index 374bc70cffb..e6aec6a875a 100644 --- a/apigeeconnect/apiv1/tether_client.go +++ b/apigeeconnect/apiv1/tether_client.go @@ -42,6 +42,7 @@ func defaultTetherGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("apigeeconnect.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://apigeeconnect.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/appengine/apiv1/applications_client.go b/appengine/apiv1/applications_client.go index 73b624338c7..fa9757bd434 100644 --- a/appengine/apiv1/applications_client.go +++ b/appengine/apiv1/applications_client.go @@ -51,6 +51,7 @@ func defaultApplicationsGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("appengine.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://appengine.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/appengine/apiv1/authorized_certificates_client.go b/appengine/apiv1/authorized_certificates_client.go index 532ce70d1aa..7f70f751d43 100644 --- a/appengine/apiv1/authorized_certificates_client.go +++ b/appengine/apiv1/authorized_certificates_client.go @@ -22,7 +22,6 @@ import ( "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" @@ -31,6 +30,7 @@ import ( appenginepb "google.golang.org/genproto/googleapis/appengine/v1" "google.golang.org/grpc" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newAuthorizedCertificatesClientHook clientHook @@ -50,6 +50,7 @@ func defaultAuthorizedCertificatesGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("appengine.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://appengine.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/appengine/apiv1/authorized_domains_client.go b/appengine/apiv1/authorized_domains_client.go index d506cc6a0dc..970a0b90745 100644 --- a/appengine/apiv1/authorized_domains_client.go +++ b/appengine/apiv1/authorized_domains_client.go @@ -22,7 +22,6 @@ import ( "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" @@ -31,6 +30,7 @@ import ( appenginepb "google.golang.org/genproto/googleapis/appengine/v1" "google.golang.org/grpc" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newAuthorizedDomainsClientHook clientHook @@ -46,6 +46,7 @@ func defaultAuthorizedDomainsGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("appengine.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://appengine.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/appengine/apiv1/doc.go b/appengine/apiv1/doc.go index 758444d2d16..a2deb21f60e 100644 --- a/appengine/apiv1/doc.go +++ b/appengine/apiv1/doc.go @@ -48,7 +48,7 @@ import ( type clientHookParams struct{} type clientHook func(context.Context, clientHookParams) ([]option.ClientOption, error) -const versionClient = "20210612" +const versionClient = "20210701" func insertMetadata(ctx context.Context, mds ...metadata.MD) context.Context { out, _ := metadata.FromOutgoingContext(ctx) diff --git a/appengine/apiv1/domain_mappings_client.go b/appengine/apiv1/domain_mappings_client.go index 1b7eaf21704..3b6c6b6f83a 100644 --- a/appengine/apiv1/domain_mappings_client.go +++ b/appengine/apiv1/domain_mappings_client.go @@ -25,7 +25,6 @@ import ( "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" @@ -35,6 +34,7 @@ import ( longrunningpb "google.golang.org/genproto/googleapis/longrunning" "google.golang.org/grpc" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newDomainMappingsClientHook clientHook @@ -54,6 +54,7 @@ func defaultDomainMappingsGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("appengine.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://appengine.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/appengine/apiv1/firewall_client.go b/appengine/apiv1/firewall_client.go index e8389c7440d..f31e79829df 100644 --- a/appengine/apiv1/firewall_client.go +++ b/appengine/apiv1/firewall_client.go @@ -22,7 +22,6 @@ import ( "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" @@ -31,6 +30,7 @@ import ( appenginepb "google.golang.org/genproto/googleapis/appengine/v1" "google.golang.org/grpc" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newFirewallClientHook clientHook @@ -51,6 +51,7 @@ func defaultFirewallGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("appengine.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://appengine.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/appengine/apiv1/instances_client.go b/appengine/apiv1/instances_client.go index e13fcc2617b..9e1cfec8bec 100644 --- a/appengine/apiv1/instances_client.go +++ b/appengine/apiv1/instances_client.go @@ -25,7 +25,6 @@ import ( "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" @@ -35,6 +34,7 @@ import ( longrunningpb "google.golang.org/genproto/googleapis/longrunning" "google.golang.org/grpc" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newInstancesClientHook clientHook @@ -53,6 +53,7 @@ func defaultInstancesGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("appengine.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://appengine.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/appengine/apiv1/services_client.go b/appengine/apiv1/services_client.go index ba575b48ab4..1f4f79193b9 100644 --- a/appengine/apiv1/services_client.go +++ b/appengine/apiv1/services_client.go @@ -25,7 +25,6 @@ import ( "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" @@ -35,6 +34,7 @@ import ( longrunningpb "google.golang.org/genproto/googleapis/longrunning" "google.golang.org/grpc" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newServicesClientHook clientHook @@ -53,6 +53,7 @@ func defaultServicesGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("appengine.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://appengine.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/appengine/apiv1/versions_client.go b/appengine/apiv1/versions_client.go index 043fa132a0f..33cf343a08f 100644 --- a/appengine/apiv1/versions_client.go +++ b/appengine/apiv1/versions_client.go @@ -25,7 +25,6 @@ import ( "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" @@ -35,6 +34,7 @@ import ( longrunningpb "google.golang.org/genproto/googleapis/longrunning" "google.golang.org/grpc" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newVersionsClientHook clientHook @@ -54,6 +54,7 @@ func defaultVersionsGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("appengine.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://appengine.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/area120/tables/apiv1alpha1/doc.go b/area120/tables/apiv1alpha1/doc.go index 146530b7a06..8ad0b3b2cda 100644 --- a/area120/tables/apiv1alpha1/doc.go +++ b/area120/tables/apiv1alpha1/doc.go @@ -48,7 +48,7 @@ import ( type clientHookParams struct{} type clientHook func(context.Context, clientHookParams) ([]option.ClientOption, error) -const versionClient = "20210612" +const versionClient = "20210701" func insertMetadata(ctx context.Context, mds ...metadata.MD) context.Context { out, _ := metadata.FromOutgoingContext(ctx) diff --git a/area120/tables/apiv1alpha1/tables_client.go b/area120/tables/apiv1alpha1/tables_client.go index fedd9b53f4a..d165f012a5b 100644 --- a/area120/tables/apiv1alpha1/tables_client.go +++ b/area120/tables/apiv1alpha1/tables_client.go @@ -23,7 +23,6 @@ import ( "net/url" "time" - "github.com/golang/protobuf/proto" gax "github.com/googleapis/gax-go/v2" "google.golang.org/api/iterator" "google.golang.org/api/option" @@ -32,6 +31,7 @@ import ( tablespb "google.golang.org/genproto/googleapis/area120/tables/v1alpha1" "google.golang.org/grpc" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newClientHook clientHook @@ -58,6 +58,7 @@ func defaultGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("area120tables.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://area120tables.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/artifactregistry/apiv1beta2/artifact_registry_client.go b/artifactregistry/apiv1beta2/artifact_registry_client.go index 19b331caaff..684affc170f 100644 --- a/artifactregistry/apiv1beta2/artifact_registry_client.go +++ b/artifactregistry/apiv1beta2/artifact_registry_client.go @@ -25,7 +25,6 @@ import ( "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" @@ -37,6 +36,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newClientHook clientHook @@ -72,6 +72,7 @@ func defaultGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("artifactregistry.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://artifactregistry.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/artifactregistry/apiv1beta2/doc.go b/artifactregistry/apiv1beta2/doc.go index 253bcc22ee3..b9b06bfa24e 100644 --- a/artifactregistry/apiv1beta2/doc.go +++ b/artifactregistry/apiv1beta2/doc.go @@ -49,7 +49,7 @@ import ( type clientHookParams struct{} type clientHook func(context.Context, clientHookParams) ([]option.ClientOption, error) -const versionClient = "20210612" +const versionClient = "20210701" func insertMetadata(ctx context.Context, mds ...metadata.MD) context.Context { out, _ := metadata.FromOutgoingContext(ctx) diff --git a/asset/apiv1/asset_client.go b/asset/apiv1/asset_client.go index d94d417823d..3dae3b1a3ae 100644 --- a/asset/apiv1/asset_client.go +++ b/asset/apiv1/asset_client.go @@ -25,7 +25,6 @@ import ( "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" @@ -36,6 +35,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newClientHook clientHook @@ -62,6 +62,7 @@ func defaultGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("cloudasset.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://cloudasset.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), @@ -136,7 +137,6 @@ func defaultCallOptions() *CallOptions { SearchAllResources: []gax.CallOption{ gax.WithRetry(func() gax.Retryer { return gax.OnCodes([]codes.Code{ - codes.DeadlineExceeded, codes.Unavailable, }, gax.Backoff{ Initial: 100 * time.Millisecond, @@ -148,7 +148,6 @@ func defaultCallOptions() *CallOptions { SearchAllIamPolicies: []gax.CallOption{ gax.WithRetry(func() gax.Retryer { return gax.OnCodes([]codes.Code{ - codes.DeadlineExceeded, codes.Unavailable, }, gax.Backoff{ Initial: 100 * time.Millisecond, diff --git a/asset/apiv1/doc.go b/asset/apiv1/doc.go index 6ee437ef7b7..daac2897766 100644 --- a/asset/apiv1/doc.go +++ b/asset/apiv1/doc.go @@ -48,7 +48,7 @@ import ( type clientHookParams struct{} type clientHook func(context.Context, clientHookParams) ([]option.ClientOption, error) -const versionClient = "20210612" +const versionClient = "20210701" func insertMetadata(ctx context.Context, mds ...metadata.MD) context.Context { out, _ := metadata.FromOutgoingContext(ctx) diff --git a/asset/apiv1p2beta1/asset_client.go b/asset/apiv1p2beta1/asset_client.go index 2822bcfc935..40417c17638 100644 --- a/asset/apiv1p2beta1/asset_client.go +++ b/asset/apiv1p2beta1/asset_client.go @@ -50,6 +50,7 @@ func defaultGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("cloudasset.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://cloudasset.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/asset/apiv1p2beta1/doc.go b/asset/apiv1p2beta1/doc.go index abad0941ffe..6016dbea501 100644 --- a/asset/apiv1p2beta1/doc.go +++ b/asset/apiv1p2beta1/doc.go @@ -50,7 +50,7 @@ import ( type clientHookParams struct{} type clientHook func(context.Context, clientHookParams) ([]option.ClientOption, error) -const versionClient = "20210612" +const versionClient = "20210701" func insertMetadata(ctx context.Context, mds ...metadata.MD) context.Context { out, _ := metadata.FromOutgoingContext(ctx) diff --git a/asset/apiv1p5beta1/asset_client.go b/asset/apiv1p5beta1/asset_client.go index c8036dcf923..3b08aff4bbc 100644 --- a/asset/apiv1p5beta1/asset_client.go +++ b/asset/apiv1p5beta1/asset_client.go @@ -23,7 +23,6 @@ import ( "net/url" "time" - "github.com/golang/protobuf/proto" gax "github.com/googleapis/gax-go/v2" "google.golang.org/api/iterator" "google.golang.org/api/option" @@ -33,6 +32,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newClientHook clientHook @@ -48,6 +48,7 @@ func defaultGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("cloudasset.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://cloudasset.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/asset/apiv1p5beta1/doc.go b/asset/apiv1p5beta1/doc.go index 9159be7ba3c..ea4ba08b1e5 100644 --- a/asset/apiv1p5beta1/doc.go +++ b/asset/apiv1p5beta1/doc.go @@ -50,7 +50,7 @@ import ( type clientHookParams struct{} type clientHook func(context.Context, clientHookParams) ([]option.ClientOption, error) -const versionClient = "20210612" +const versionClient = "20210701" func insertMetadata(ctx context.Context, mds ...metadata.MD) context.Context { out, _ := metadata.FromOutgoingContext(ctx) diff --git a/assuredworkloads/apiv1beta1/assured_workloads_client.go b/assuredworkloads/apiv1beta1/assured_workloads_client.go index 7f6b73b835d..c6cdd18b7b9 100644 --- a/assuredworkloads/apiv1beta1/assured_workloads_client.go +++ b/assuredworkloads/apiv1beta1/assured_workloads_client.go @@ -25,7 +25,6 @@ import ( "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" @@ -36,6 +35,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newClientHook clientHook @@ -55,6 +55,7 @@ func defaultGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("assuredworkloads.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://assuredworkloads.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/assuredworkloads/apiv1beta1/doc.go b/assuredworkloads/apiv1beta1/doc.go index 778e1a1b283..4045dda7a78 100644 --- a/assuredworkloads/apiv1beta1/doc.go +++ b/assuredworkloads/apiv1beta1/doc.go @@ -48,7 +48,7 @@ import ( type clientHookParams struct{} type clientHook func(context.Context, clientHookParams) ([]option.ClientOption, error) -const versionClient = "20210612" +const versionClient = "20210701" func insertMetadata(ctx context.Context, mds ...metadata.MD) context.Context { out, _ := metadata.FromOutgoingContext(ctx) diff --git a/automl/apiv1/auto_ml_client.go b/automl/apiv1/auto_ml_client.go index 1dff2414438..c1cf25f4abe 100644 --- a/automl/apiv1/auto_ml_client.go +++ b/automl/apiv1/auto_ml_client.go @@ -25,7 +25,6 @@ import ( "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" @@ -36,6 +35,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newClientHook clientHook @@ -68,6 +68,7 @@ func defaultGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("automl.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://automl.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/automl/apiv1/doc.go b/automl/apiv1/doc.go index c44f6bd4e1d..6fac611d1b1 100644 --- a/automl/apiv1/doc.go +++ b/automl/apiv1/doc.go @@ -49,7 +49,7 @@ import ( type clientHookParams struct{} type clientHook func(context.Context, clientHookParams) ([]option.ClientOption, error) -const versionClient = "20210612" +const versionClient = "20210701" func insertMetadata(ctx context.Context, mds ...metadata.MD) context.Context { out, _ := metadata.FromOutgoingContext(ctx) diff --git a/automl/apiv1/prediction_client.go b/automl/apiv1/prediction_client.go index 8402aaa72fb..c11ee2a0cb2 100644 --- a/automl/apiv1/prediction_client.go +++ b/automl/apiv1/prediction_client.go @@ -49,6 +49,7 @@ func defaultPredictionGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("automl.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://automl.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/automl/apiv1beta1/auto_ml_client.go b/automl/apiv1beta1/auto_ml_client.go index 9124de33525..47e36dfc3f1 100644 --- a/automl/apiv1beta1/auto_ml_client.go +++ b/automl/apiv1beta1/auto_ml_client.go @@ -25,7 +25,6 @@ import ( "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" @@ -36,6 +35,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newClientHook clientHook @@ -74,6 +74,7 @@ func defaultGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("automl.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://automl.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/automl/apiv1beta1/doc.go b/automl/apiv1beta1/doc.go index 9018a5ef277..047fd5676a8 100644 --- a/automl/apiv1beta1/doc.go +++ b/automl/apiv1beta1/doc.go @@ -51,7 +51,7 @@ import ( type clientHookParams struct{} type clientHook func(context.Context, clientHookParams) ([]option.ClientOption, error) -const versionClient = "20210612" +const versionClient = "20210701" func insertMetadata(ctx context.Context, mds ...metadata.MD) context.Context { out, _ := metadata.FromOutgoingContext(ctx) diff --git a/automl/apiv1beta1/prediction_client.go b/automl/apiv1beta1/prediction_client.go index c145b55204e..69d982c8246 100644 --- a/automl/apiv1beta1/prediction_client.go +++ b/automl/apiv1beta1/prediction_client.go @@ -49,6 +49,7 @@ func defaultPredictionGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("automl.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://automl.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/bigquery/CHANGES.md b/bigquery/CHANGES.md index aa538162b3a..5bde60e6ae2 100644 --- a/bigquery/CHANGES.md +++ b/bigquery/CHANGES.md @@ -1,5 +1,25 @@ # Changes +## [1.19.0](https://www.github.com/googleapis/google-cloud-go/compare/bigquery/v1.18.0...bigquery/v1.19.0) (2021-06-29) + + +### Features + +* **bigquery/storage:** Add ZSTD compression as an option for Arrow. ([770db30](https://www.github.com/googleapis/google-cloud-go/commit/770db3083270d485d265362fe5a4b2a1b23619ff)) +* **bigquery/storage:** remove alpha client ([#4100](https://www.github.com/googleapis/google-cloud-go/issues/4100)) ([a2d137d](https://www.github.com/googleapis/google-cloud-go/commit/a2d137d233e7a401976fbe1fd8ff81145dda515d)), refs [#4098](https://www.github.com/googleapis/google-cloud-go/issues/4098) +* **bigquery:** add support for parameterized types ([#4103](https://www.github.com/googleapis/google-cloud-go/issues/4103)) ([a2330e4](https://www.github.com/googleapis/google-cloud-go/commit/a2330e4d66c0a1832fb3b9e23a33c006c9345c28)) +* **bigquery:** add support for snapshot/restore ([#4112](https://www.github.com/googleapis/google-cloud-go/issues/4112)) ([4c12b42](https://www.github.com/googleapis/google-cloud-go/commit/4c12b424eec06c7d87244eaa922995bbe6e46e7e)) +* **bigquery:** add support for user defined TVF ([#4043](https://www.github.com/googleapis/google-cloud-go/issues/4043)) ([37607b4](https://www.github.com/googleapis/google-cloud-go/commit/37607b4afbc4c42baa4a931a9a86cddcc6d885ca)) +* **bigquery:** enable project autodetection, expose project ids further ([#4312](https://www.github.com/googleapis/google-cloud-go/issues/4312)) ([267787e](https://www.github.com/googleapis/google-cloud-go/commit/267787eb245d9307cf78304c1ce34bdfb2aaf5ab)) +* **bigquery:** support job deletion ([#3935](https://www.github.com/googleapis/google-cloud-go/issues/3935)) ([363ba03](https://www.github.com/googleapis/google-cloud-go/commit/363ba03e1c3c813749a65ff3c050877ce4f60016)) +* **bigquery:** support nullable params and geography params ([#4225](https://www.github.com/googleapis/google-cloud-go/issues/4225)) ([43755d3](https://www.github.com/googleapis/google-cloud-go/commit/43755d38b5d928222127cc6be26183d6bfbb1cb4)) + + +### Bug Fixes + +* **bigquery:** minor rename to feature that's not yet in a release ([#4320](https://www.github.com/googleapis/google-cloud-go/issues/4320)) ([ef8d138](https://www.github.com/googleapis/google-cloud-go/commit/ef8d1386149cff28ae6258ab167789bae6af6407)) +* **bigquery:** update streaming insert error test ([#4321](https://www.github.com/googleapis/google-cloud-go/issues/4321)) ([12f3042](https://www.github.com/googleapis/google-cloud-go/commit/12f3042716d51fb0d7a23071d00a20f9751bac91)) + ## [1.18.0](https://www.github.com/googleapis/google-cloud-go/compare/bigquery/v1.17.0...bigquery/v1.18.0) (2021-05-06) diff --git a/bigquery/bigquery.go b/bigquery/bigquery.go index 0a32f02c3d5..28ea5446f1f 100644 --- a/bigquery/bigquery.go +++ b/bigquery/bigquery.go @@ -16,6 +16,7 @@ package bigquery import ( "context" + "errors" "fmt" "io" "net/http" @@ -29,6 +30,7 @@ import ( bq "google.golang.org/api/bigquery/v2" "google.golang.org/api/googleapi" "google.golang.org/api/option" + "google.golang.org/api/transport" ) const ( @@ -56,8 +58,20 @@ type Client struct { bqs *bq.Service } +// DetectProjectID is a sentinel value that instructs NewClient to detect the +// project ID. It is given in place of the projectID argument. NewClient will +// use the project ID from the given credentials or the default credentials +// (https://developers.google.com/accounts/docs/application-default-credentials) +// if no credentials were provided. When providing credentials, not all +// options will allow NewClient to extract the project ID. Specifically a JWT +// does not have the project ID encoded. +const DetectProjectID = "*detect-project-id*" + // NewClient constructs a new Client which can perform BigQuery operations. // Operations performed via the client are billed to the specified GCP project. +// +// If the project ID is set to DetectProjectID, NewClient will attempt to detect +// the project ID from credentials. func NewClient(ctx context.Context, projectID string, opts ...option.ClientOption) (*Client, error) { o := []option.ClientOption{ option.WithScopes(Scope), @@ -68,6 +82,14 @@ func NewClient(ctx context.Context, projectID string, opts ...option.ClientOptio if err != nil { return nil, fmt.Errorf("bigquery: constructing client: %v", err) } + + if projectID == DetectProjectID { + projectID, err = detectProjectID(ctx, opts...) + if err != nil { + return nil, fmt.Errorf("failed to detect project: %v", err) + } + } + c := &Client{ projectID: projectID, bqs: bqs, @@ -75,6 +97,12 @@ func NewClient(ctx context.Context, projectID string, opts ...option.ClientOptio return c, nil } +// Project returns the project ID or number for this instance of the client, which may have +// either been explicitly specified or autodetected. +func (c *Client) Project() string { + return c.projectID +} + // Close closes any resources held by the client. // Close should be called when the client is no longer needed. // It need not be called at program exit. @@ -82,6 +110,17 @@ func (c *Client) Close() error { return nil } +func detectProjectID(ctx context.Context, opts ...option.ClientOption) (string, error) { + creds, err := transport.Creds(ctx, opts...) + if err != nil { + return "", fmt.Errorf("fetching creds: %v", err) + } + if creds.ProjectID == "" { + return "", errors.New("credentials did not provide a valid ProjectID") + } + return creds.ProjectID, nil +} + // Calls the Jobs.Insert RPC and returns a Job. func (c *Client) insertJob(ctx context.Context, job *bq.Job, media io.Reader) (*Job, error) { call := c.bqs.Jobs.Insert(c.projectID, job).Context(ctx) diff --git a/bigquery/connection/apiv1/connection_client.go b/bigquery/connection/apiv1/connection_client.go index fdd24abdd84..3f2f69330f7 100644 --- a/bigquery/connection/apiv1/connection_client.go +++ b/bigquery/connection/apiv1/connection_client.go @@ -23,7 +23,6 @@ import ( "net/url" "time" - "github.com/golang/protobuf/proto" gax "github.com/googleapis/gax-go/v2" "google.golang.org/api/iterator" "google.golang.org/api/option" @@ -34,6 +33,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newClientHook clientHook @@ -56,6 +56,7 @@ func defaultGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("bigqueryconnection.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://bigqueryconnection.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/bigquery/connection/apiv1/doc.go b/bigquery/connection/apiv1/doc.go index 32961413a7b..1822652c996 100644 --- a/bigquery/connection/apiv1/doc.go +++ b/bigquery/connection/apiv1/doc.go @@ -48,7 +48,7 @@ import ( type clientHookParams struct{} type clientHook func(context.Context, clientHookParams) ([]option.ClientOption, error) -const versionClient = "20210612" +const versionClient = "20210701" func insertMetadata(ctx context.Context, mds ...metadata.MD) context.Context { out, _ := metadata.FromOutgoingContext(ctx) diff --git a/bigquery/connection/apiv1beta1/connection_client.go b/bigquery/connection/apiv1beta1/connection_client.go index 61f9881a4bd..dfa7fad606a 100644 --- a/bigquery/connection/apiv1beta1/connection_client.go +++ b/bigquery/connection/apiv1beta1/connection_client.go @@ -55,6 +55,7 @@ func defaultGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("bigqueryconnection.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://bigqueryconnection.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/bigquery/connection/apiv1beta1/doc.go b/bigquery/connection/apiv1beta1/doc.go index fe78fae5e82..85a960e5796 100644 --- a/bigquery/connection/apiv1beta1/doc.go +++ b/bigquery/connection/apiv1beta1/doc.go @@ -50,7 +50,7 @@ import ( type clientHookParams struct{} type clientHook func(context.Context, clientHookParams) ([]option.ClientOption, error) -const versionClient = "20210612" +const versionClient = "20210701" func insertMetadata(ctx context.Context, mds ...metadata.MD) context.Context { out, _ := metadata.FromOutgoingContext(ctx) diff --git a/bigquery/datatransfer/apiv1/data_transfer_client.go b/bigquery/datatransfer/apiv1/data_transfer_client.go index a7e075a8e7a..43ad4d4f6af 100644 --- a/bigquery/datatransfer/apiv1/data_transfer_client.go +++ b/bigquery/datatransfer/apiv1/data_transfer_client.go @@ -23,7 +23,6 @@ import ( "net/url" "time" - "github.com/golang/protobuf/proto" gax "github.com/googleapis/gax-go/v2" "google.golang.org/api/iterator" "google.golang.org/api/option" @@ -33,6 +32,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newClientHook clientHook @@ -61,6 +61,7 @@ func defaultGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("bigquerydatatransfer.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://bigquerydatatransfer.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/bigquery/datatransfer/apiv1/doc.go b/bigquery/datatransfer/apiv1/doc.go index 931d5c6f019..b55bc21e9aa 100644 --- a/bigquery/datatransfer/apiv1/doc.go +++ b/bigquery/datatransfer/apiv1/doc.go @@ -49,7 +49,7 @@ import ( type clientHookParams struct{} type clientHook func(context.Context, clientHookParams) ([]option.ClientOption, error) -const versionClient = "20210612" +const versionClient = "20210701" func insertMetadata(ctx context.Context, mds ...metadata.MD) context.Context { out, _ := metadata.FromOutgoingContext(ctx) diff --git a/bigquery/go.mod b/bigquery/go.mod index 74eba857422..5a64aeeb87d 100644 --- a/bigquery/go.mod +++ b/bigquery/go.mod @@ -9,7 +9,8 @@ require ( github.com/google/go-cmp v0.5.6 github.com/googleapis/gax-go/v2 v2.0.5 golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 - google.golang.org/api v0.48.0 - google.golang.org/genproto v0.0.0-20210614143202-012ab6975634 + google.golang.org/api v0.50.0 + google.golang.org/genproto v0.0.0-20210701133433-6b8dcf568a95 google.golang.org/grpc v1.38.0 + google.golang.org/protobuf v1.27.1 ) diff --git a/bigquery/go.sum b/bigquery/go.sum index 4b662411ea8..cb33ac8204c 100644 --- a/bigquery/go.sum +++ b/bigquery/go.sum @@ -252,8 +252,9 @@ golang.org/x/oauth2 v0.0.0-20201208152858-08078c50e5b5/go.mod h1:KelEdhl1UZF7XfJ golang.org/x/oauth2 v0.0.0-20210218202405-ba52d332ba99/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= golang.org/x/oauth2 v0.0.0-20210220000619-9bb904979d93/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= golang.org/x/oauth2 v0.0.0-20210313182246-cd4f82c27b84/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= -golang.org/x/oauth2 v0.0.0-20210514164344-f6687ab2804c h1:pkQiBZBvdos9qq4wBAHqlzuZHEXo07pqV06ef90u1WI= golang.org/x/oauth2 v0.0.0-20210514164344-f6687ab2804c/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= +golang.org/x/oauth2 v0.0.0-20210628180205-a41e5a781914 h1:3B43BWw0xEBsLZ/NO1VALz6fppU3481pik+2Ksv45z8= +golang.org/x/oauth2 v0.0.0-20210628180205-a41e5a781914/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= @@ -304,8 +305,9 @@ golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210514084401-e8d321eab015/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20210603125802-9665404d3644 h1:CA1DEQ4NdKphKeL70tvsWNdT5oFh1lOjihRcEDROi0I= golang.org/x/sys v0.0.0-20210603125802-9665404d3644/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20210616094352-59db8d763f22 h1:RqytpXGR1iVNX7psjB3ff8y7sNFinVFvkx1c8SjBkio= +golang.org/x/sys v0.0.0-20210616094352-59db8d763f22/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= @@ -367,8 +369,9 @@ golang.org/x/tools v0.0.0-20210105154028-b0ab187a4818/go.mod h1:emZCQorbCU4vsT4f golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0= golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.2/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= -golang.org/x/tools v0.1.3 h1:L69ShwSZEyCsLKoAxDKeMvLDZkumEe8gXUZAjab0tX8= golang.org/x/tools v0.1.3/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= +golang.org/x/tools v0.1.4 h1:cVngSRcfgyZCzys3KYOpCFa+4dqX/Oub9tAq00ttGVs= +golang.org/x/tools v0.1.4/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= @@ -396,8 +399,9 @@ google.golang.org/api v0.40.0/go.mod h1:fYKFpnQN0DsDSKRVRcQSDQNtqWPfM9i+zNPxepjR google.golang.org/api v0.41.0/go.mod h1:RkxM5lITDfTzmyKFPt+wGrCJbVfniCr2ool8kTBzRTU= google.golang.org/api v0.43.0/go.mod h1:nQsDGjRXMo4lvh5hP0TKqF244gqhGcr/YSIykhUk/94= google.golang.org/api v0.47.0/go.mod h1:Wbvgpq1HddcWVtzsVLyfLp8lDg6AA241LmgIL59tHXo= -google.golang.org/api v0.48.0 h1:RDAPWfNFY06dffEXfn7hZF5Fr1ZbnChzfQZAPyBd1+I= google.golang.org/api v0.48.0/go.mod h1:71Pr1vy+TAZRPkPs/xlCf5SsU8WjuAWv1Pfjbtukyy4= +google.golang.org/api v0.50.0 h1:LX7NFCFYOHzr7WHaYiRUpeipZe9o5L8T+2F4Z798VDw= +google.golang.org/api v0.50.0/go.mod h1:4bNT5pAuq5ji4SRZm+5QIkjny9JAyVD/3gaSihNefaw= google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= google.golang.org/appengine v1.5.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= @@ -449,8 +453,9 @@ google.golang.org/genproto v0.0.0-20210513213006-bf773b8c8384/go.mod h1:P3QM42oQ google.golang.org/genproto v0.0.0-20210602131652-f16073e35f0c/go.mod h1:UODoCrxHCcBojKKwX1terBiRUaqAsFqJiF615XL43r0= google.golang.org/genproto v0.0.0-20210604141403-392c879c8b08/go.mod h1:UODoCrxHCcBojKKwX1terBiRUaqAsFqJiF615XL43r0= google.golang.org/genproto v0.0.0-20210608205507-b6d2f5bf0d7d/go.mod h1:UODoCrxHCcBojKKwX1terBiRUaqAsFqJiF615XL43r0= -google.golang.org/genproto v0.0.0-20210614143202-012ab6975634 h1:LnkHrvncK4mYysgs+R1wPeMAILrmunf0Tzl0Li71pxo= -google.golang.org/genproto v0.0.0-20210614143202-012ab6975634/go.mod h1:SzzZ/N+nwJDaO1kznhnlzqS8ocJICar6hYhVyhi++24= +google.golang.org/genproto v0.0.0-20210624195500-8bfb893ecb84/go.mod h1:SzzZ/N+nwJDaO1kznhnlzqS8ocJICar6hYhVyhi++24= +google.golang.org/genproto v0.0.0-20210701133433-6b8dcf568a95 h1:xyRjacsGcaSoZ2fTcaLCSzh2JEceLLOT4X8k32Q0xAQ= +google.golang.org/genproto v0.0.0-20210701133433-6b8dcf568a95/go.mod h1:yiaVoXHpRzHGyxV3o4DktVWY4mSUErTKaeEOq6C3t3U= google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38= google.golang.org/grpc v1.21.1/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM= @@ -485,8 +490,9 @@ google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpAD google.golang.org/protobuf v1.24.0/go.mod h1:r/3tXBNzIEhYS9I1OUVjXDlt8tc493IdKGjtUeSXeh4= google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c= google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= -google.golang.org/protobuf v1.26.0 h1:bxAC2xTBsZGibn2RTntX0oH50xLsqy1OxA9tTL3p/lk= google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= +google.golang.org/protobuf v1.27.1 h1:SnqbnDw1V7RiZcXPx5MEeqPv2s79L9i7BJUlG/+RurQ= +google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= diff --git a/bigquery/integration_test.go b/bigquery/integration_test.go index 9cca940d876..9bf2f91030e 100644 --- a/bigquery/integration_test.go +++ b/bigquery/integration_test.go @@ -228,6 +228,24 @@ func initTestState(client *Client, t time.Time) func() { } } +func TestIntegration_DetectProjectID(t *testing.T) { + ctx := context.Background() + testCreds := testutil.Credentials(ctx) + if testCreds == nil { + t.Skip("test credentials not present, skipping") + } + + if _, err := NewClient(ctx, DetectProjectID, option.WithCredentials(testCreds)); err != nil { + t.Errorf("test NewClient: %v", err) + } + + badTS := testutil.ErroringTokenSource{} + + if badClient, err := NewClient(ctx, DetectProjectID, option.WithTokenSource(badTS)); err == nil { + t.Errorf("expected error from bad token source, NewClient succeeded with project: %s", badClient.Project()) + } +} + func TestIntegration_TableCreate(t *testing.T) { // Check that creating a record field with an empty schema is an error. if client == nil { @@ -1360,9 +1378,11 @@ func TestIntegration_InsertErrors(t *testing.T) { if !ok { t.Errorf("Wanted googleapi.Error, got: %v", err) } - want := "Request payload size exceeds the limit" - if !strings.Contains(e.Message, want) { - t.Errorf("Error didn't contain expected message (%s): %s", want, e.Message) + if e.Code != http.StatusRequestEntityTooLarge { + want := "Request payload size exceeds the limit" + if !strings.Contains(e.Message, want) { + t.Errorf("Error didn't contain expected message (%s): %#v", want, e) + } } // Case 2: Very Large Request // Request so large it gets rejected by intermediate infra (3x 10MB rows) diff --git a/bigquery/job.go b/bigquery/job.go index 2d259f910b4..6bdcbcc3c32 100644 --- a/bigquery/job.go +++ b/bigquery/job.go @@ -63,6 +63,11 @@ func (c *Client) JobFromIDLocation(ctx context.Context, id, location string) (j return bqToJob(bqjob, c) } +// ProjectID returns the job's associated project. +func (j *Job) ProjectID() string { + return j.projectID +} + // ID returns the job's ID. func (j *Job) ID() string { return j.jobID diff --git a/bigquery/reservation/apiv1/doc.go b/bigquery/reservation/apiv1/doc.go index e4e7c567dcc..fe2140eba81 100644 --- a/bigquery/reservation/apiv1/doc.go +++ b/bigquery/reservation/apiv1/doc.go @@ -48,7 +48,7 @@ import ( type clientHookParams struct{} type clientHook func(context.Context, clientHookParams) ([]option.ClientOption, error) -const versionClient = "20210612" +const versionClient = "20210701" func insertMetadata(ctx context.Context, mds ...metadata.MD) context.Context { out, _ := metadata.FromOutgoingContext(ctx) diff --git a/bigquery/reservation/apiv1/reservation_client.go b/bigquery/reservation/apiv1/reservation_client.go index b367fac4959..9e8a419ff2b 100644 --- a/bigquery/reservation/apiv1/reservation_client.go +++ b/bigquery/reservation/apiv1/reservation_client.go @@ -23,7 +23,6 @@ import ( "net/url" "time" - "github.com/golang/protobuf/proto" gax "github.com/googleapis/gax-go/v2" "google.golang.org/api/iterator" "google.golang.org/api/option" @@ -33,6 +32,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newClientHook clientHook @@ -66,6 +66,7 @@ func defaultGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("bigqueryreservation.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://bigqueryreservation.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/bigquery/reservation/apiv1beta1/doc.go b/bigquery/reservation/apiv1beta1/doc.go index 58fdebc2bed..fe50baf00b9 100644 --- a/bigquery/reservation/apiv1beta1/doc.go +++ b/bigquery/reservation/apiv1beta1/doc.go @@ -50,7 +50,7 @@ import ( type clientHookParams struct{} type clientHook func(context.Context, clientHookParams) ([]option.ClientOption, error) -const versionClient = "20210612" +const versionClient = "20210701" func insertMetadata(ctx context.Context, mds ...metadata.MD) context.Context { out, _ := metadata.FromOutgoingContext(ctx) diff --git a/bigquery/reservation/apiv1beta1/reservation_client.go b/bigquery/reservation/apiv1beta1/reservation_client.go index 5f88b27042c..dfc99636407 100644 --- a/bigquery/reservation/apiv1beta1/reservation_client.go +++ b/bigquery/reservation/apiv1beta1/reservation_client.go @@ -23,7 +23,6 @@ import ( "net/url" "time" - "github.com/golang/protobuf/proto" gax "github.com/googleapis/gax-go/v2" "google.golang.org/api/iterator" "google.golang.org/api/option" @@ -33,6 +32,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newClientHook clientHook @@ -66,6 +66,7 @@ func defaultGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("bigqueryreservation.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://bigqueryreservation.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/bigquery/storage/apiv1/big_query_read_client.go b/bigquery/storage/apiv1/big_query_read_client.go index 215191faa89..30d7cdc5146 100644 --- a/bigquery/storage/apiv1/big_query_read_client.go +++ b/bigquery/storage/apiv1/big_query_read_client.go @@ -48,6 +48,7 @@ func defaultBigQueryReadGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("bigquerystorage.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://bigquerystorage.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/bigquery/storage/apiv1/doc.go b/bigquery/storage/apiv1/doc.go index 9a1652b254b..928b143116b 100644 --- a/bigquery/storage/apiv1/doc.go +++ b/bigquery/storage/apiv1/doc.go @@ -46,7 +46,7 @@ import ( type clientHookParams struct{} type clientHook func(context.Context, clientHookParams) ([]option.ClientOption, error) -const versionClient = "20210612" +const versionClient = "20210701" func insertMetadata(ctx context.Context, mds ...metadata.MD) context.Context { out, _ := metadata.FromOutgoingContext(ctx) diff --git a/bigquery/storage/apiv1beta1/big_query_storage_client.go b/bigquery/storage/apiv1beta1/big_query_storage_client.go index 3f6a87fe766..a43b98eeca3 100644 --- a/bigquery/storage/apiv1beta1/big_query_storage_client.go +++ b/bigquery/storage/apiv1beta1/big_query_storage_client.go @@ -50,6 +50,7 @@ func defaultBigQueryStorageGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("bigquerystorage.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://bigquerystorage.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/bigquery/storage/apiv1beta1/doc.go b/bigquery/storage/apiv1beta1/doc.go index 34eeb9412aa..d0873afd2bc 100644 --- a/bigquery/storage/apiv1beta1/doc.go +++ b/bigquery/storage/apiv1beta1/doc.go @@ -48,7 +48,7 @@ import ( type clientHookParams struct{} type clientHook func(context.Context, clientHookParams) ([]option.ClientOption, error) -const versionClient = "20210612" +const versionClient = "20210701" func insertMetadata(ctx context.Context, mds ...metadata.MD) context.Context { out, _ := metadata.FromOutgoingContext(ctx) diff --git a/bigquery/storage/apiv1beta2/big_query_read_client.go b/bigquery/storage/apiv1beta2/big_query_read_client.go index fd3d79d2389..46324315221 100644 --- a/bigquery/storage/apiv1beta2/big_query_read_client.go +++ b/bigquery/storage/apiv1beta2/big_query_read_client.go @@ -48,6 +48,7 @@ func defaultBigQueryReadGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("bigquerystorage.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://bigquerystorage.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/bigquery/storage/apiv1beta2/big_query_write_client.go b/bigquery/storage/apiv1beta2/big_query_write_client.go index 74ceab7123b..659031bb4a3 100644 --- a/bigquery/storage/apiv1beta2/big_query_write_client.go +++ b/bigquery/storage/apiv1beta2/big_query_write_client.go @@ -51,6 +51,7 @@ func defaultBigQueryWriteGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("bigquerystorage.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://bigquerystorage.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/bigquery/storage/apiv1beta2/doc.go b/bigquery/storage/apiv1beta2/doc.go index b888f9ac5dc..aa879f71d40 100644 --- a/bigquery/storage/apiv1beta2/doc.go +++ b/bigquery/storage/apiv1beta2/doc.go @@ -48,7 +48,7 @@ import ( type clientHookParams struct{} type clientHook func(context.Context, clientHookParams) ([]option.ClientOption, error) -const versionClient = "20210612" +const versionClient = "20210701" func insertMetadata(ctx context.Context, mds ...metadata.MD) context.Context { out, _ := metadata.FromOutgoingContext(ctx) diff --git a/bigquery/storage/managedwriter/adapt/doc.go b/bigquery/storage/managedwriter/adapt/doc.go new file mode 100644 index 00000000000..c06d3039200 --- /dev/null +++ b/bigquery/storage/managedwriter/adapt/doc.go @@ -0,0 +1,19 @@ +// 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. + +// Package adapt adds functionality related to converting bigquery representations +// like schema and data type representations. +// +// It is EXPERIMENTAL and subject to change or removal without notice. +package adapt diff --git a/bigquery/storage/managedwriter/adapt/schemaconversion.go b/bigquery/storage/managedwriter/adapt/schemaconversion.go new file mode 100644 index 00000000000..8de22575db6 --- /dev/null +++ b/bigquery/storage/managedwriter/adapt/schemaconversion.go @@ -0,0 +1,140 @@ +// 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. + +package adapt + +import ( + "fmt" + + "cloud.google.com/go/bigquery" + storagepb "google.golang.org/genproto/googleapis/cloud/bigquery/storage/v1beta2" +) + +var fieldTypeMap = map[bigquery.FieldType]storagepb.TableFieldSchema_Type{ + bigquery.StringFieldType: storagepb.TableFieldSchema_STRING, + bigquery.BytesFieldType: storagepb.TableFieldSchema_BYTES, + bigquery.IntegerFieldType: storagepb.TableFieldSchema_INT64, + bigquery.FloatFieldType: storagepb.TableFieldSchema_DOUBLE, + bigquery.BooleanFieldType: storagepb.TableFieldSchema_BOOL, + bigquery.TimestampFieldType: storagepb.TableFieldSchema_TIMESTAMP, + bigquery.RecordFieldType: storagepb.TableFieldSchema_STRUCT, + bigquery.DateFieldType: storagepb.TableFieldSchema_DATE, + bigquery.TimeFieldType: storagepb.TableFieldSchema_TIME, + bigquery.DateTimeFieldType: storagepb.TableFieldSchema_DATETIME, + bigquery.NumericFieldType: storagepb.TableFieldSchema_NUMERIC, + bigquery.BigNumericFieldType: storagepb.TableFieldSchema_BIGNUMERIC, + bigquery.GeographyFieldType: storagepb.TableFieldSchema_GEOGRAPHY, +} + +func bqFieldToProto(in *bigquery.FieldSchema) (*storagepb.TableFieldSchema, error) { + if in == nil { + return nil, nil + } + out := &storagepb.TableFieldSchema{ + Name: in.Name, + Description: in.Description, + } + + // Type conversion. + typ, ok := fieldTypeMap[in.Type] + if !ok { + return nil, fmt.Errorf("could not convert field (%s) due to unknown type value: %s", in.Name, in.Type) + } + out.Type = typ + + // Mode conversion. Repeated trumps required. + out.Mode = storagepb.TableFieldSchema_NULLABLE + if in.Repeated { + out.Mode = storagepb.TableFieldSchema_REPEATED + } + if !in.Repeated && in.Required { + out.Mode = storagepb.TableFieldSchema_REQUIRED + } + + for _, s := range in.Schema { + subField, err := bqFieldToProto(s) + if err != nil { + return nil, err + } + out.Fields = append(out.Fields, subField) + } + return out, nil +} + +func protoToBQField(in *storagepb.TableFieldSchema) (*bigquery.FieldSchema, error) { + if in == nil { + return nil, nil + } + out := &bigquery.FieldSchema{ + Name: in.GetName(), + Description: in.GetDescription(), + Repeated: in.GetMode() == storagepb.TableFieldSchema_REPEATED, + Required: in.GetMode() == storagepb.TableFieldSchema_REQUIRED, + } + + typeResolved := false + for k, v := range fieldTypeMap { + if v == in.GetType() { + out.Type = k + typeResolved = true + break + } + } + if !typeResolved { + return nil, fmt.Errorf("could not convert proto type to bigquery type: %v", in.GetType().String()) + } + + for _, s := range in.Fields { + subField, err := protoToBQField(s) + if err != nil { + return nil, err + } + out.Schema = append(out.Schema, subField) + } + return out, nil +} + +// BQSchemaToStorageTableSchema converts a bigquery Schema into the protobuf-based TableSchema used +// by the BigQuery Storage WriteClient. +func BQSchemaToStorageTableSchema(in bigquery.Schema) (*storagepb.TableSchema, error) { + if in == nil { + return nil, nil + } + out := &storagepb.TableSchema{} + for _, s := range in { + converted, err := bqFieldToProto(s) + if err != nil { + return nil, err + } + out.Fields = append(out.Fields, converted) + } + return out, nil +} + +// StorageTableSchemaToBQSchema converts a TableSchema from the BigQuery Storage WriteClient +// into the equivalent BigQuery Schema. +func StorageTableSchemaToBQSchema(in *storagepb.TableSchema) (bigquery.Schema, error) { + if in == nil { + return nil, nil + } + var out bigquery.Schema + for _, s := range in.Fields { + converted, err := protoToBQField(s) + if err != nil { + return nil, err + } + out = append(out, converted) + } + return out, nil +} diff --git a/bigquery/storage/managedwriter/adapt/schemaconversion_test.go b/bigquery/storage/managedwriter/adapt/schemaconversion_test.go new file mode 100644 index 00000000000..aab85fa9072 --- /dev/null +++ b/bigquery/storage/managedwriter/adapt/schemaconversion_test.go @@ -0,0 +1,203 @@ +// 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. + +package adapt + +import ( + "testing" + + "cloud.google.com/go/bigquery" + "cloud.google.com/go/internal/testutil" + "github.com/google/go-cmp/cmp" + storagepb "google.golang.org/genproto/googleapis/cloud/bigquery/storage/v1beta2" + "google.golang.org/protobuf/testing/protocmp" +) + +func TestFieldConversions(t *testing.T) { + testCases := []struct { + desc string + bq *bigquery.FieldSchema + proto *storagepb.TableFieldSchema + }{ + { + desc: "nil", + bq: nil, + proto: nil, + }, + { + desc: "string field", + bq: &bigquery.FieldSchema{ + Name: "name", + Type: bigquery.StringFieldType, + Description: "description", + }, + proto: &storagepb.TableFieldSchema{ + Name: "name", + Type: storagepb.TableFieldSchema_STRING, + Description: "description", + Mode: storagepb.TableFieldSchema_NULLABLE, + }, + }, + { + desc: "required integer field", + bq: &bigquery.FieldSchema{ + Name: "name", + Type: bigquery.IntegerFieldType, + Description: "description", + Required: true, + }, + proto: &storagepb.TableFieldSchema{ + Name: "name", + Type: storagepb.TableFieldSchema_INT64, + Description: "description", + Mode: storagepb.TableFieldSchema_REQUIRED, + }, + }, + { + desc: "struct with repeated bytes subfield", + bq: &bigquery.FieldSchema{ + Name: "name", + Type: bigquery.RecordFieldType, + Description: "description", + Required: true, + Schema: bigquery.Schema{ + &bigquery.FieldSchema{ + Name: "inner1", + Repeated: true, + Description: "repeat", + Type: bigquery.BytesFieldType, + }, + }, + }, + proto: &storagepb.TableFieldSchema{ + Name: "name", + Type: storagepb.TableFieldSchema_STRUCT, + Description: "description", + Mode: storagepb.TableFieldSchema_REQUIRED, + Fields: []*storagepb.TableFieldSchema{ + { + Name: "inner1", + Mode: storagepb.TableFieldSchema_REPEATED, + Description: "repeat", + Type: storagepb.TableFieldSchema_BYTES, + }, + }, + }, + }, + } + + for _, tc := range testCases { + // first, bq to proto + converted, err := bqFieldToProto(tc.bq) + if err != nil { + t.Errorf("case (%s) failed conversion from bq: %v", tc.desc, err) + } + if diff := cmp.Diff(converted, tc.proto, protocmp.Transform()); diff != "" { + t.Errorf("conversion to proto diff (%s):\n%v", tc.desc, diff) + } + // reverse conversion, proto to bq + reverse, err := protoToBQField(tc.proto) + if err != nil { + t.Errorf("case (%s) failed conversion from proto: %v", tc.desc, err) + } + if diff := cmp.Diff(reverse, tc.bq); diff != "" { + t.Errorf("conversion to BQ diff (%s):\n%v", tc.desc, diff) + } + } +} + +func TestSchemaConversion(t *testing.T) { + + testCases := []struct { + description string + bqSchema bigquery.Schema + storageSchema *storagepb.TableSchema + }{ + { + description: "nil", + bqSchema: nil, + storageSchema: nil, + }, + { + description: "scalars", + bqSchema: bigquery.Schema{ + {Name: "f1", Type: bigquery.StringFieldType}, + {Name: "f2", Type: bigquery.IntegerFieldType}, + {Name: "f3", Type: bigquery.BooleanFieldType}, + }, + storageSchema: &storagepb.TableSchema{ + Fields: []*storagepb.TableFieldSchema{ + {Name: "f1", Type: storagepb.TableFieldSchema_STRING, Mode: storagepb.TableFieldSchema_NULLABLE}, + {Name: "f2", Type: storagepb.TableFieldSchema_INT64, Mode: storagepb.TableFieldSchema_NULLABLE}, + {Name: "f3", Type: storagepb.TableFieldSchema_BOOL, Mode: storagepb.TableFieldSchema_NULLABLE}, + }, + }, + }, + { + description: "array", + bqSchema: bigquery.Schema{ + {Name: "arr", Type: bigquery.NumericFieldType, Repeated: true}, + {Name: "big", Type: bigquery.BigNumericFieldType, Required: true}, + }, + storageSchema: &storagepb.TableSchema{ + Fields: []*storagepb.TableFieldSchema{ + {Name: "arr", Type: storagepb.TableFieldSchema_NUMERIC, Mode: storagepb.TableFieldSchema_REPEATED}, + {Name: "big", Type: storagepb.TableFieldSchema_BIGNUMERIC, Mode: storagepb.TableFieldSchema_REQUIRED}, + }, + }, + }, + { + description: "nested", + bqSchema: bigquery.Schema{ + {Name: "struct1", Type: bigquery.RecordFieldType, Schema: []*bigquery.FieldSchema{ + {Name: "leaf1", Type: bigquery.DateFieldType}, + {Name: "leaf2", Type: bigquery.DateTimeFieldType}, + }}, + {Name: "field2", Type: bigquery.StringFieldType}, + }, + storageSchema: &storagepb.TableSchema{ + Fields: []*storagepb.TableFieldSchema{ + {Name: "struct1", + Type: storagepb.TableFieldSchema_STRUCT, + Mode: storagepb.TableFieldSchema_NULLABLE, + Fields: []*storagepb.TableFieldSchema{ + {Name: "leaf1", Type: storagepb.TableFieldSchema_DATE, Mode: storagepb.TableFieldSchema_NULLABLE}, + {Name: "leaf2", Type: storagepb.TableFieldSchema_DATETIME, Mode: storagepb.TableFieldSchema_NULLABLE}, + }}, + {Name: "field2", Type: storagepb.TableFieldSchema_STRING, Mode: storagepb.TableFieldSchema_NULLABLE}, + }, + }, + }, + } + for _, tc := range testCases { + + // BQ -> Storage + storageS, err := BQSchemaToStorageTableSchema(tc.bqSchema) + if err != nil { + t.Errorf("BQSchemaToStorageTableSchema(%s): %v", tc.description, err) + } + if diff := testutil.Diff(storageS, tc.storageSchema); diff != "" { + t.Fatalf("BQSchemaToStorageTableSchema(%s): -got, +want:\n%s", tc.description, diff) + } + + // Storage -> BQ + bqS, err := StorageTableSchemaToBQSchema(tc.storageSchema) + if err != nil { + t.Errorf("StorageTableSchemaToBQSchema(%s): %v", tc.description, err) + } + if diff := testutil.Diff(bqS, tc.bqSchema); diff != "" { + t.Fatalf("StorageTableSchemaToBQSchema(%s): -got, +want:\n%s", tc.description, diff) + } + } +} diff --git a/bigquery/storage/managedwriter/doc.go b/bigquery/storage/managedwriter/doc.go new file mode 100644 index 00000000000..a8e580bd90c --- /dev/null +++ b/bigquery/storage/managedwriter/doc.go @@ -0,0 +1,22 @@ +// 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. + +// Package managedwriter will be a thick client around the storage API's BigQueryWriteClient. +// +// It is EXPERIMENTAL and subject to change or removal without notice. +// +// Currently, the BigQueryWriteClient this library targets is exposed in the storage v1beta2 endpoint, and is +// a successor to the streaming interface. API method tabledata.insertAll is the primary backend method, and +// the Inserter abstraction is the equivalent to this in the cloud.google.com/go/bigquery package. +package managedwriter diff --git a/bigtable/bigtable.go b/bigtable/bigtable.go index 26384139fba..a0ba9dfbf0a 100644 --- a/bigtable/bigtable.go +++ b/bigtable/bigtable.go @@ -79,9 +79,7 @@ func NewClientWithConfig(ctx context.Context, project, instance string, config C option.WithGRPCConnectionPool(4), // Set the max size to correspond to server-side limits. option.WithGRPCDialOption(grpc.WithDefaultCallOptions(grpc.MaxCallSendMsgSize(1<<28), grpc.MaxCallRecvMsgSize(1<<28))), - // TODO(grpc/grpc-go#1388) using connection pool without WithBlock - // can cause RPCs to fail randomly. We can delete this after the issue is fixed. - option.WithGRPCDialOption(grpc.WithBlock())) + ) // Attempts direct access to spanner service over gRPC to improve throughput, // whether the attempt is allowed is totally controlled by service owner. o = append(o, internaloption.EnableDirectPath(true)) diff --git a/bigtable/go.mod b/bigtable/go.mod index 1f1f5c7d763..a8eaf5a94a1 100644 --- a/bigtable/go.mod +++ b/bigtable/go.mod @@ -8,11 +8,11 @@ require ( github.com/google/btree v1.0.1 github.com/google/go-cmp v0.5.6 github.com/googleapis/gax-go/v2 v2.0.5 - golang.org/x/oauth2 v0.0.0-20210615190721-d04028783cf1 + golang.org/x/oauth2 v0.0.0-20210628180205-a41e5a781914 golang.org/x/sys v0.0.0-20210616094352-59db8d763f22 - google.golang.org/api v0.48.0 - google.golang.org/genproto v0.0.0-20210608205507-b6d2f5bf0d7d + google.golang.org/api v0.50.0 + google.golang.org/genproto v0.0.0-20210630183607-d20f26d13c79 google.golang.org/grpc v1.38.0 - google.golang.org/protobuf v1.26.0 + google.golang.org/protobuf v1.27.1 rsc.io/binaryregexp v0.2.0 ) diff --git a/bigtable/go.sum b/bigtable/go.sum index 9f40c0a6a8f..d9e76a2b746 100644 --- a/bigtable/go.sum +++ b/bigtable/go.sum @@ -251,8 +251,8 @@ golang.org/x/oauth2 v0.0.0-20210218202405-ba52d332ba99/go.mod h1:KelEdhl1UZF7XfJ golang.org/x/oauth2 v0.0.0-20210220000619-9bb904979d93/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= golang.org/x/oauth2 v0.0.0-20210313182246-cd4f82c27b84/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= golang.org/x/oauth2 v0.0.0-20210514164344-f6687ab2804c/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= -golang.org/x/oauth2 v0.0.0-20210615190721-d04028783cf1 h1:x622Z2o4hgCr/4CiKWc51jHVKaWdtVpBNmEI8wI9Qns= -golang.org/x/oauth2 v0.0.0-20210615190721-d04028783cf1/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= +golang.org/x/oauth2 v0.0.0-20210628180205-a41e5a781914 h1:3B43BWw0xEBsLZ/NO1VALz6fppU3481pik+2Ksv45z8= +golang.org/x/oauth2 v0.0.0-20210628180205-a41e5a781914/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= @@ -366,8 +366,10 @@ golang.org/x/tools v0.0.0-20201208233053-a543418bbed2/go.mod h1:emZCQorbCU4vsT4f golang.org/x/tools v0.0.0-20210105154028-b0ab187a4818/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0= golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= -golang.org/x/tools v0.1.2 h1:kRBLX7v7Af8W7Gdbbc908OJcdgtK8bOz9Uaj8/F1ACA= golang.org/x/tools v0.1.2/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= +golang.org/x/tools v0.1.3/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= +golang.org/x/tools v0.1.4 h1:cVngSRcfgyZCzys3KYOpCFa+4dqX/Oub9tAq00ttGVs= +golang.org/x/tools v0.1.4/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= @@ -395,8 +397,9 @@ google.golang.org/api v0.40.0/go.mod h1:fYKFpnQN0DsDSKRVRcQSDQNtqWPfM9i+zNPxepjR google.golang.org/api v0.41.0/go.mod h1:RkxM5lITDfTzmyKFPt+wGrCJbVfniCr2ool8kTBzRTU= google.golang.org/api v0.43.0/go.mod h1:nQsDGjRXMo4lvh5hP0TKqF244gqhGcr/YSIykhUk/94= google.golang.org/api v0.47.0/go.mod h1:Wbvgpq1HddcWVtzsVLyfLp8lDg6AA241LmgIL59tHXo= -google.golang.org/api v0.48.0 h1:RDAPWfNFY06dffEXfn7hZF5Fr1ZbnChzfQZAPyBd1+I= google.golang.org/api v0.48.0/go.mod h1:71Pr1vy+TAZRPkPs/xlCf5SsU8WjuAWv1Pfjbtukyy4= +google.golang.org/api v0.50.0 h1:LX7NFCFYOHzr7WHaYiRUpeipZe9o5L8T+2F4Z798VDw= +google.golang.org/api v0.50.0/go.mod h1:4bNT5pAuq5ji4SRZm+5QIkjny9JAyVD/3gaSihNefaw= google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= google.golang.org/appengine v1.5.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= @@ -447,8 +450,10 @@ google.golang.org/genproto v0.0.0-20210402141018-6c239bbf2bb1/go.mod h1:9lPAdzaE google.golang.org/genproto v0.0.0-20210513213006-bf773b8c8384/go.mod h1:P3QM42oQyzQSnHPnZ/vqoCdDmzH28fzWByN9asMeM8A= google.golang.org/genproto v0.0.0-20210602131652-f16073e35f0c/go.mod h1:UODoCrxHCcBojKKwX1terBiRUaqAsFqJiF615XL43r0= google.golang.org/genproto v0.0.0-20210604141403-392c879c8b08/go.mod h1:UODoCrxHCcBojKKwX1terBiRUaqAsFqJiF615XL43r0= -google.golang.org/genproto v0.0.0-20210608205507-b6d2f5bf0d7d h1:KzwjikDymrEmYYbdyfievTwjEeGlu+OM6oiKBkF3Jfg= google.golang.org/genproto v0.0.0-20210608205507-b6d2f5bf0d7d/go.mod h1:UODoCrxHCcBojKKwX1terBiRUaqAsFqJiF615XL43r0= +google.golang.org/genproto v0.0.0-20210624195500-8bfb893ecb84/go.mod h1:SzzZ/N+nwJDaO1kznhnlzqS8ocJICar6hYhVyhi++24= +google.golang.org/genproto v0.0.0-20210630183607-d20f26d13c79 h1:s1jFTXJryg4a1mew7xv03VZD8N9XjxFhk1o4Js4WvPQ= +google.golang.org/genproto v0.0.0-20210630183607-d20f26d13c79/go.mod h1:yiaVoXHpRzHGyxV3o4DktVWY4mSUErTKaeEOq6C3t3U= google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38= google.golang.org/grpc v1.21.1/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM= @@ -483,8 +488,9 @@ google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpAD google.golang.org/protobuf v1.24.0/go.mod h1:r/3tXBNzIEhYS9I1OUVjXDlt8tc493IdKGjtUeSXeh4= google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c= google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= -google.golang.org/protobuf v1.26.0 h1:bxAC2xTBsZGibn2RTntX0oH50xLsqy1OxA9tTL3p/lk= google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= +google.golang.org/protobuf v1.27.1 h1:SnqbnDw1V7RiZcXPx5MEeqPv2s79L9i7BJUlG/+RurQ= +google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= diff --git a/billing/apiv1/cloud_billing_client.go b/billing/apiv1/cloud_billing_client.go index 0509ca2b2d0..bc013828f46 100644 --- a/billing/apiv1/cloud_billing_client.go +++ b/billing/apiv1/cloud_billing_client.go @@ -23,7 +23,6 @@ import ( "net/url" "time" - "github.com/golang/protobuf/proto" gax "github.com/googleapis/gax-go/v2" "google.golang.org/api/iterator" "google.golang.org/api/option" @@ -34,6 +33,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newCloudBillingClientHook clientHook @@ -58,6 +58,7 @@ func defaultCloudBillingGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("cloudbilling.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://cloudbilling.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/billing/apiv1/cloud_catalog_client.go b/billing/apiv1/cloud_catalog_client.go index 25f70f25e50..302e5881473 100644 --- a/billing/apiv1/cloud_catalog_client.go +++ b/billing/apiv1/cloud_catalog_client.go @@ -22,7 +22,6 @@ import ( "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" @@ -31,6 +30,7 @@ import ( billingpb "google.golang.org/genproto/googleapis/cloud/billing/v1" "google.golang.org/grpc" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newCloudCatalogClientHook clientHook @@ -47,6 +47,7 @@ func defaultCloudCatalogGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("cloudbilling.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://cloudbilling.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/billing/apiv1/doc.go b/billing/apiv1/doc.go index 4a1cf2a2134..deece9709c2 100644 --- a/billing/apiv1/doc.go +++ b/billing/apiv1/doc.go @@ -49,7 +49,7 @@ import ( type clientHookParams struct{} type clientHook func(context.Context, clientHookParams) ([]option.ClientOption, error) -const versionClient = "20210612" +const versionClient = "20210701" func insertMetadata(ctx context.Context, mds ...metadata.MD) context.Context { out, _ := metadata.FromOutgoingContext(ctx) diff --git a/billing/budgets/apiv1/budget_client.go b/billing/budgets/apiv1/budget_client.go index f0617c0261c..3def9224369 100644 --- a/billing/budgets/apiv1/budget_client.go +++ b/billing/budgets/apiv1/budget_client.go @@ -23,7 +23,6 @@ import ( "net/url" "time" - "github.com/golang/protobuf/proto" gax "github.com/googleapis/gax-go/v2" "google.golang.org/api/iterator" "google.golang.org/api/option" @@ -33,6 +32,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newBudgetClientHook clientHook @@ -52,6 +52,7 @@ func defaultBudgetGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("billingbudgets.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://billingbudgets.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/billing/budgets/apiv1/doc.go b/billing/budgets/apiv1/doc.go index c667ee6f31f..c451523c8d6 100644 --- a/billing/budgets/apiv1/doc.go +++ b/billing/budgets/apiv1/doc.go @@ -50,7 +50,7 @@ import ( type clientHookParams struct{} type clientHook func(context.Context, clientHookParams) ([]option.ClientOption, error) -const versionClient = "20210612" +const versionClient = "20210701" func insertMetadata(ctx context.Context, mds ...metadata.MD) context.Context { out, _ := metadata.FromOutgoingContext(ctx) diff --git a/billing/budgets/apiv1beta1/budget_client.go b/billing/budgets/apiv1beta1/budget_client.go index 7159f1fe497..fc0901098bd 100644 --- a/billing/budgets/apiv1beta1/budget_client.go +++ b/billing/budgets/apiv1beta1/budget_client.go @@ -23,7 +23,6 @@ import ( "net/url" "time" - "github.com/golang/protobuf/proto" gax "github.com/googleapis/gax-go/v2" "google.golang.org/api/iterator" "google.golang.org/api/option" @@ -33,6 +32,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newBudgetClientHook clientHook @@ -52,6 +52,7 @@ func defaultBudgetGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("billingbudgets.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://billingbudgets.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/billing/budgets/apiv1beta1/doc.go b/billing/budgets/apiv1beta1/doc.go index 580edd612ec..db1fb0a076d 100644 --- a/billing/budgets/apiv1beta1/doc.go +++ b/billing/budgets/apiv1beta1/doc.go @@ -52,7 +52,7 @@ import ( type clientHookParams struct{} type clientHook func(context.Context, clientHookParams) ([]option.ClientOption, error) -const versionClient = "20210612" +const versionClient = "20210701" func insertMetadata(ctx context.Context, mds ...metadata.MD) context.Context { out, _ := metadata.FromOutgoingContext(ctx) diff --git a/binaryauthorization/apiv1beta1/binauthz_management_service_v1_beta1_client.go b/binaryauthorization/apiv1beta1/binauthz_management_service_v1_beta1_client.go index afc4b567714..d5461764464 100644 --- a/binaryauthorization/apiv1beta1/binauthz_management_service_v1_beta1_client.go +++ b/binaryauthorization/apiv1beta1/binauthz_management_service_v1_beta1_client.go @@ -23,7 +23,6 @@ import ( "net/url" "time" - "github.com/golang/protobuf/proto" gax "github.com/googleapis/gax-go/v2" "google.golang.org/api/iterator" "google.golang.org/api/option" @@ -33,6 +32,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newBinauthzManagementServiceV1Beta1ClientHook clientHook @@ -54,6 +54,7 @@ func defaultBinauthzManagementServiceV1Beta1GRPCClientOptions() []option.ClientO internaloption.WithDefaultMTLSEndpoint("binaryauthorization.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://binaryauthorization.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/binaryauthorization/apiv1beta1/doc.go b/binaryauthorization/apiv1beta1/doc.go index 49ab883d13b..bae4dabd1d0 100644 --- a/binaryauthorization/apiv1beta1/doc.go +++ b/binaryauthorization/apiv1beta1/doc.go @@ -51,7 +51,7 @@ import ( type clientHookParams struct{} type clientHook func(context.Context, clientHookParams) ([]option.ClientOption, error) -const versionClient = "20210612" +const versionClient = "20210701" func insertMetadata(ctx context.Context, mds ...metadata.MD) context.Context { out, _ := metadata.FromOutgoingContext(ctx) diff --git a/channel/apiv1/cloud_channel_client.go b/channel/apiv1/cloud_channel_client.go index 61de846bc2d..c42f798684c 100644 --- a/channel/apiv1/cloud_channel_client.go +++ b/channel/apiv1/cloud_channel_client.go @@ -25,7 +25,6 @@ import ( "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" @@ -36,6 +35,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newCloudChannelClientHook clientHook @@ -84,6 +84,7 @@ func defaultCloudChannelGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("cloudchannel.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://cloudchannel.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/channel/apiv1/doc.go b/channel/apiv1/doc.go index 128dd42287a..61e96c5bf75 100644 --- a/channel/apiv1/doc.go +++ b/channel/apiv1/doc.go @@ -46,7 +46,7 @@ import ( type clientHookParams struct{} type clientHook func(context.Context, clientHookParams) ([]option.ClientOption, error) -const versionClient = "20210612" +const versionClient = "20210701" func insertMetadata(ctx context.Context, mds ...metadata.MD) context.Context { out, _ := metadata.FromOutgoingContext(ctx) diff --git a/cloudbuild/apiv1/doc.go b/cloudbuild/apiv1/doc.go index c7f6781ec6c..c108da5d84c 100644 --- a/cloudbuild/apiv1/doc.go +++ b/cloudbuild/apiv1/doc.go @@ -96,4 +96,4 @@ func versionGo() string { return "UNKNOWN" } -const versionClient = "20210612" +const versionClient = "20210624" diff --git a/cloudbuild/apiv1/v2/cloud_build_client.go b/cloudbuild/apiv1/v2/cloud_build_client.go index c7e27e0fa73..9cbf64437f1 100644 --- a/cloudbuild/apiv1/v2/cloud_build_client.go +++ b/cloudbuild/apiv1/v2/cloud_build_client.go @@ -25,7 +25,6 @@ import ( "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" @@ -36,6 +35,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newClientHook clientHook @@ -67,6 +67,7 @@ func defaultGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("cloudbuild.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://cloudbuild.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), @@ -644,7 +645,7 @@ func (c *gRPCClient) CreateBuildTrigger(ctx context.Context, req *cloudbuildpb.C defer cancel() ctx = cctx } - md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "project_id", url.QueryEscape(req.GetProjectId()))) + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v&%s=%v", "project_id", url.QueryEscape(req.GetProjectId()), "parent", url.QueryEscape(req.GetParent()))) ctx = insertMetadata(ctx, c.xGoogMetadata, md) opts = append((*c.CallOptions).CreateBuildTrigger[0:len((*c.CallOptions).CreateBuildTrigger):len((*c.CallOptions).CreateBuildTrigger)], opts...) var resp *cloudbuildpb.BuildTrigger @@ -665,7 +666,7 @@ func (c *gRPCClient) GetBuildTrigger(ctx context.Context, req *cloudbuildpb.GetB defer cancel() ctx = cctx } - md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v&%s=%v", "project_id", url.QueryEscape(req.GetProjectId()), "trigger_id", url.QueryEscape(req.GetTriggerId()))) + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v&%s=%v&%s=%v", "project_id", url.QueryEscape(req.GetProjectId()), "trigger_id", url.QueryEscape(req.GetTriggerId()), "name", url.QueryEscape(req.GetName()))) ctx = insertMetadata(ctx, c.xGoogMetadata, md) opts = append((*c.CallOptions).GetBuildTrigger[0:len((*c.CallOptions).GetBuildTrigger):len((*c.CallOptions).GetBuildTrigger)], opts...) var resp *cloudbuildpb.BuildTrigger @@ -681,7 +682,7 @@ func (c *gRPCClient) GetBuildTrigger(ctx context.Context, req *cloudbuildpb.GetB } func (c *gRPCClient) ListBuildTriggers(ctx context.Context, req *cloudbuildpb.ListBuildTriggersRequest, opts ...gax.CallOption) *BuildTriggerIterator { - md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "project_id", url.QueryEscape(req.GetProjectId()))) + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v&%s=%v", "project_id", url.QueryEscape(req.GetProjectId()), "parent", url.QueryEscape(req.GetParent()))) ctx = insertMetadata(ctx, c.xGoogMetadata, md) opts = append((*c.CallOptions).ListBuildTriggers[0:len((*c.CallOptions).ListBuildTriggers):len((*c.CallOptions).ListBuildTriggers)], opts...) it := &BuildTriggerIterator{} @@ -726,7 +727,7 @@ func (c *gRPCClient) DeleteBuildTrigger(ctx context.Context, req *cloudbuildpb.D defer cancel() ctx = cctx } - md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v&%s=%v", "project_id", url.QueryEscape(req.GetProjectId()), "trigger_id", url.QueryEscape(req.GetTriggerId()))) + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v&%s=%v&%s=%v", "project_id", url.QueryEscape(req.GetProjectId()), "trigger_id", url.QueryEscape(req.GetTriggerId()), "name", url.QueryEscape(req.GetName()))) ctx = insertMetadata(ctx, c.xGoogMetadata, md) opts = append((*c.CallOptions).DeleteBuildTrigger[0:len((*c.CallOptions).DeleteBuildTrigger):len((*c.CallOptions).DeleteBuildTrigger)], opts...) err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { @@ -743,7 +744,7 @@ func (c *gRPCClient) UpdateBuildTrigger(ctx context.Context, req *cloudbuildpb.U defer cancel() ctx = cctx } - md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v&%s=%v", "project_id", url.QueryEscape(req.GetProjectId()), "trigger_id", url.QueryEscape(req.GetTriggerId()))) + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v&%s=%v&%s=%v", "project_id", url.QueryEscape(req.GetProjectId()), "trigger_id", url.QueryEscape(req.GetTriggerId()), "trigger.resource_name", url.QueryEscape(req.GetTrigger().GetResourceName()))) ctx = insertMetadata(ctx, c.xGoogMetadata, md) opts = append((*c.CallOptions).UpdateBuildTrigger[0:len((*c.CallOptions).UpdateBuildTrigger):len((*c.CallOptions).UpdateBuildTrigger)], opts...) var resp *cloudbuildpb.BuildTrigger @@ -764,7 +765,7 @@ func (c *gRPCClient) RunBuildTrigger(ctx context.Context, req *cloudbuildpb.RunB defer cancel() ctx = cctx } - md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v&%s=%v", "project_id", url.QueryEscape(req.GetProjectId()), "trigger_id", url.QueryEscape(req.GetTriggerId()))) + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v&%s=%v&%s=%v", "project_id", url.QueryEscape(req.GetProjectId()), "trigger_id", url.QueryEscape(req.GetTriggerId()), "name", url.QueryEscape(req.GetName()))) ctx = insertMetadata(ctx, c.xGoogMetadata, md) opts = append((*c.CallOptions).RunBuildTrigger[0:len((*c.CallOptions).RunBuildTrigger):len((*c.CallOptions).RunBuildTrigger)], opts...) var resp *longrunningpb.Operation @@ -782,7 +783,7 @@ func (c *gRPCClient) RunBuildTrigger(ctx context.Context, req *cloudbuildpb.RunB } func (c *gRPCClient) ReceiveTriggerWebhook(ctx context.Context, req *cloudbuildpb.ReceiveTriggerWebhookRequest, opts ...gax.CallOption) (*cloudbuildpb.ReceiveTriggerWebhookResponse, error) { - md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v&%s=%v", "project_id", url.QueryEscape(req.GetProjectId()), "trigger", url.QueryEscape(req.GetTrigger()))) + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v&%s=%v&%s=%v", "project_id", url.QueryEscape(req.GetProjectId()), "trigger", url.QueryEscape(req.GetTrigger()), "name", url.QueryEscape(req.GetName()))) ctx = insertMetadata(ctx, c.xGoogMetadata, md) opts = append((*c.CallOptions).ReceiveTriggerWebhook[0:len((*c.CallOptions).ReceiveTriggerWebhook):len((*c.CallOptions).ReceiveTriggerWebhook)], opts...) var resp *cloudbuildpb.ReceiveTriggerWebhookResponse diff --git a/cloudbuild/apiv1/v2/doc.go b/cloudbuild/apiv1/v2/doc.go index 4b2296fd359..6f01792adde 100644 --- a/cloudbuild/apiv1/v2/doc.go +++ b/cloudbuild/apiv1/v2/doc.go @@ -48,7 +48,7 @@ import ( type clientHookParams struct{} type clientHook func(context.Context, clientHookParams) ([]option.ClientOption, error) -const versionClient = "20210612" +const versionClient = "20210701" func insertMetadata(ctx context.Context, mds ...metadata.MD) context.Context { out, _ := metadata.FromOutgoingContext(ctx) diff --git a/clouddms/apiv1/data_migration_client.go b/clouddms/apiv1/data_migration_client.go index 39b5f813403..c8bb77072c1 100644 --- a/clouddms/apiv1/data_migration_client.go +++ b/clouddms/apiv1/data_migration_client.go @@ -25,7 +25,6 @@ import ( "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" @@ -35,6 +34,7 @@ import ( longrunningpb "google.golang.org/genproto/googleapis/longrunning" "google.golang.org/grpc" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newDataMigrationClientHook clientHook @@ -66,6 +66,7 @@ func defaultDataMigrationGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("datamigration.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://datamigration.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/clouddms/apiv1/doc.go b/clouddms/apiv1/doc.go index 48c71c65fd5..ade8234dd7b 100644 --- a/clouddms/apiv1/doc.go +++ b/clouddms/apiv1/doc.go @@ -20,8 +20,6 @@ // Manage Cloud Database Migration Service resources on Google Cloud // Platform. // -// 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 @@ -51,7 +49,7 @@ import ( type clientHookParams struct{} type clientHook func(context.Context, clientHookParams) ([]option.ClientOption, error) -const versionClient = "20210612" +const versionClient = "20210701" func insertMetadata(ctx context.Context, mds ...metadata.MD) context.Context { out, _ := metadata.FromOutgoingContext(ctx) diff --git a/cloudtasks/apiv2/cloud_tasks_client.go b/cloudtasks/apiv2/cloud_tasks_client.go index 6621ffa21e6..62eac06b08e 100644 --- a/cloudtasks/apiv2/cloud_tasks_client.go +++ b/cloudtasks/apiv2/cloud_tasks_client.go @@ -23,7 +23,6 @@ import ( "net/url" "time" - "github.com/golang/protobuf/proto" gax "github.com/googleapis/gax-go/v2" "google.golang.org/api/iterator" "google.golang.org/api/option" @@ -34,6 +33,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newClientHook clientHook @@ -64,6 +64,7 @@ func defaultGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("cloudtasks.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://cloudtasks.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/cloudtasks/apiv2/doc.go b/cloudtasks/apiv2/doc.go index 0e42750ee41..6c085c3411f 100644 --- a/cloudtasks/apiv2/doc.go +++ b/cloudtasks/apiv2/doc.go @@ -48,7 +48,7 @@ import ( type clientHookParams struct{} type clientHook func(context.Context, clientHookParams) ([]option.ClientOption, error) -const versionClient = "20210612" +const versionClient = "20210701" func insertMetadata(ctx context.Context, mds ...metadata.MD) context.Context { out, _ := metadata.FromOutgoingContext(ctx) diff --git a/cloudtasks/apiv2beta2/cloud_tasks_client.go b/cloudtasks/apiv2beta2/cloud_tasks_client.go index a03bc302d4b..a07f21d6395 100644 --- a/cloudtasks/apiv2beta2/cloud_tasks_client.go +++ b/cloudtasks/apiv2beta2/cloud_tasks_client.go @@ -23,7 +23,6 @@ import ( "net/url" "time" - "github.com/golang/protobuf/proto" gax "github.com/googleapis/gax-go/v2" "google.golang.org/api/iterator" "google.golang.org/api/option" @@ -34,6 +33,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newClientHook clientHook @@ -68,6 +68,7 @@ func defaultGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("cloudtasks.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://cloudtasks.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/cloudtasks/apiv2beta2/doc.go b/cloudtasks/apiv2beta2/doc.go index a798f5da526..dc193f5d535 100644 --- a/cloudtasks/apiv2beta2/doc.go +++ b/cloudtasks/apiv2beta2/doc.go @@ -50,7 +50,7 @@ import ( type clientHookParams struct{} type clientHook func(context.Context, clientHookParams) ([]option.ClientOption, error) -const versionClient = "20210612" +const versionClient = "20210701" func insertMetadata(ctx context.Context, mds ...metadata.MD) context.Context { out, _ := metadata.FromOutgoingContext(ctx) diff --git a/cloudtasks/apiv2beta3/cloud_tasks_client.go b/cloudtasks/apiv2beta3/cloud_tasks_client.go index dc15053a726..95e97209664 100644 --- a/cloudtasks/apiv2beta3/cloud_tasks_client.go +++ b/cloudtasks/apiv2beta3/cloud_tasks_client.go @@ -23,7 +23,6 @@ import ( "net/url" "time" - "github.com/golang/protobuf/proto" gax "github.com/googleapis/gax-go/v2" "google.golang.org/api/iterator" "google.golang.org/api/option" @@ -34,6 +33,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newClientHook clientHook @@ -64,6 +64,7 @@ func defaultGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("cloudtasks.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://cloudtasks.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/cloudtasks/apiv2beta3/doc.go b/cloudtasks/apiv2beta3/doc.go index c5d2f9e742e..9c040fa674b 100644 --- a/cloudtasks/apiv2beta3/doc.go +++ b/cloudtasks/apiv2beta3/doc.go @@ -50,7 +50,7 @@ import ( type clientHookParams struct{} type clientHook func(context.Context, clientHookParams) ([]option.ClientOption, error) -const versionClient = "20210612" +const versionClient = "20210701" func insertMetadata(ctx context.Context, mds ...metadata.MD) context.Context { out, _ := metadata.FromOutgoingContext(ctx) diff --git a/compute/apiv1/accelerator_types_client.go b/compute/apiv1/accelerator_types_client.go new file mode 100644 index 00000000000..ebb96df0ed2 --- /dev/null +++ b/compute/apiv1/accelerator_types_client.go @@ -0,0 +1,341 @@ +// 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 compute + +import ( + "bytes" + "context" + "fmt" + "io/ioutil" + "net/http" + "net/url" + + gax "github.com/googleapis/gax-go/v2" + "google.golang.org/api/option" + "google.golang.org/api/option/internaloption" + httptransport "google.golang.org/api/transport/http" + computepb "google.golang.org/genproto/googleapis/cloud/compute/v1" + "google.golang.org/grpc" + "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/encoding/protojson" +) + +var newAcceleratorTypesClientHook clientHook + +// AcceleratorTypesCallOptions contains the retry settings for each method of AcceleratorTypesClient. +type AcceleratorTypesCallOptions struct { + AggregatedList []gax.CallOption + Get []gax.CallOption + List []gax.CallOption +} + +// internalAcceleratorTypesClient is an interface that defines the methods availaible from Google Compute Engine API. +type internalAcceleratorTypesClient interface { + Close() error + setGoogleClientInfo(...string) + Connection() *grpc.ClientConn + AggregatedList(context.Context, *computepb.AggregatedListAcceleratorTypesRequest, ...gax.CallOption) (*computepb.AcceleratorTypeAggregatedList, error) + Get(context.Context, *computepb.GetAcceleratorTypeRequest, ...gax.CallOption) (*computepb.AcceleratorType, error) + List(context.Context, *computepb.ListAcceleratorTypesRequest, ...gax.CallOption) (*computepb.AcceleratorTypeList, error) +} + +// AcceleratorTypesClient is a client for interacting with Google Compute Engine API. +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +// +// Services +// +// The AcceleratorTypes API. +type AcceleratorTypesClient struct { + // The internal transport-dependent client. + internalClient internalAcceleratorTypesClient + + // The call options for this service. + CallOptions *AcceleratorTypesCallOptions +} + +// 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 *AcceleratorTypesClient) 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 *AcceleratorTypesClient) setGoogleClientInfo(keyval ...string) { + c.internalClient.setGoogleClientInfo(keyval...) +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *AcceleratorTypesClient) Connection() *grpc.ClientConn { + return c.internalClient.Connection() +} + +// AggregatedList retrieves an aggregated list of accelerator types. +func (c *AcceleratorTypesClient) AggregatedList(ctx context.Context, req *computepb.AggregatedListAcceleratorTypesRequest, opts ...gax.CallOption) (*computepb.AcceleratorTypeAggregatedList, error) { + return c.internalClient.AggregatedList(ctx, req, opts...) +} + +// Get returns the specified accelerator type. +func (c *AcceleratorTypesClient) Get(ctx context.Context, req *computepb.GetAcceleratorTypeRequest, opts ...gax.CallOption) (*computepb.AcceleratorType, error) { + return c.internalClient.Get(ctx, req, opts...) +} + +// List retrieves a list of accelerator types that are available to the specified project. +func (c *AcceleratorTypesClient) List(ctx context.Context, req *computepb.ListAcceleratorTypesRequest, opts ...gax.CallOption) (*computepb.AcceleratorTypeList, error) { + return c.internalClient.List(ctx, req, opts...) +} + +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +type acceleratorTypesRESTClient struct { + // The http endpoint to connect to. + endpoint string + + // The http client. + httpClient *http.Client + + // The x-goog-* metadata to be sent with each request. + xGoogMetadata metadata.MD +} + +// NewAcceleratorTypesRESTClient creates a new accelerator types rest client. +// +// Services +// +// The AcceleratorTypes API. +func NewAcceleratorTypesRESTClient(ctx context.Context, opts ...option.ClientOption) (*AcceleratorTypesClient, error) { + clientOpts := append(defaultAcceleratorTypesRESTClientOptions(), opts...) + httpClient, endpoint, err := httptransport.NewClient(ctx, clientOpts...) + if err != nil { + return nil, err + } + + c := &acceleratorTypesRESTClient{ + endpoint: endpoint, + httpClient: httpClient, + } + c.setGoogleClientInfo() + + return &AcceleratorTypesClient{internalClient: c, CallOptions: &AcceleratorTypesCallOptions{}}, nil +} + +func defaultAcceleratorTypesRESTClientOptions() []option.ClientOption { + return []option.ClientOption{ + internaloption.WithDefaultEndpoint("compute.googleapis.com"), + internaloption.WithDefaultMTLSEndpoint("compute.mtls.googleapis.com"), + internaloption.WithDefaultAudience("https://compute.googleapis.com/"), + internaloption.WithDefaultScopes(DefaultAuthScopes()...), + } +} + +// 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 *acceleratorTypesRESTClient) setGoogleClientInfo(keyval ...string) { + kv := append([]string{"gl-go", versionGo()}, keyval...) + kv = append(kv, "gapic", versionClient, "gax", gax.Version, "rest", "UNKNOWN") + 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 *acceleratorTypesRESTClient) Close() error { + // Replace httpClient with nil to force cleanup. + c.httpClient = nil + return nil +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *acceleratorTypesRESTClient) Connection() *grpc.ClientConn { + return nil +} + +// AggregatedList retrieves an aggregated list of accelerator types. +func (c *acceleratorTypesRESTClient) AggregatedList(ctx context.Context, req *computepb.AggregatedListAcceleratorTypesRequest, opts ...gax.CallOption) (*computepb.AcceleratorTypeAggregatedList, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/aggregated/acceleratorTypes", req.GetProject()) + + params := url.Values{} + if req != nil && req.Filter != nil { + params.Add("filter", fmt.Sprintf("%v", req.GetFilter())) + } + if req != nil && req.IncludeAllScopes != nil { + params.Add("includeAllScopes", fmt.Sprintf("%v", req.GetIncludeAllScopes())) + } + if req != nil && req.MaxResults != nil { + params.Add("maxResults", fmt.Sprintf("%v", req.GetMaxResults())) + } + if req != nil && req.OrderBy != nil { + params.Add("orderBy", fmt.Sprintf("%v", req.GetOrderBy())) + } + if req != nil && req.PageToken != nil { + params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) + } + if req != nil && req.ReturnPartialSuccess != nil { + params.Add("returnPartialSuccess", fmt.Sprintf("%v", req.GetReturnPartialSuccess())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.AcceleratorTypeAggregatedList{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Get returns the specified accelerator type. +func (c *acceleratorTypesRESTClient) Get(ctx context.Context, req *computepb.GetAcceleratorTypeRequest, opts ...gax.CallOption) (*computepb.AcceleratorType, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/zones/%v/acceleratorTypes/%v", req.GetProject(), req.GetZone(), req.GetAcceleratorType()) + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.AcceleratorType{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// List retrieves a list of accelerator types that are available to the specified project. +func (c *acceleratorTypesRESTClient) List(ctx context.Context, req *computepb.ListAcceleratorTypesRequest, opts ...gax.CallOption) (*computepb.AcceleratorTypeList, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/zones/%v/acceleratorTypes", req.GetProject(), req.GetZone()) + + params := url.Values{} + if req != nil && req.Filter != nil { + params.Add("filter", fmt.Sprintf("%v", req.GetFilter())) + } + if req != nil && req.MaxResults != nil { + params.Add("maxResults", fmt.Sprintf("%v", req.GetMaxResults())) + } + if req != nil && req.OrderBy != nil { + params.Add("orderBy", fmt.Sprintf("%v", req.GetOrderBy())) + } + if req != nil && req.PageToken != nil { + params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) + } + if req != nil && req.ReturnPartialSuccess != nil { + params.Add("returnPartialSuccess", fmt.Sprintf("%v", req.GetReturnPartialSuccess())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.AcceleratorTypeList{} + + return rsp, unm.Unmarshal(buf, rsp) +} diff --git a/compute/apiv1/accelerator_types_client_example_test.go b/compute/apiv1/accelerator_types_client_example_test.go new file mode 100644 index 00000000000..ddb62c81c7c --- /dev/null +++ b/compute/apiv1/accelerator_types_client_example_test.go @@ -0,0 +1,93 @@ +// 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 compute_test + +import ( + "context" + + compute "cloud.google.com/go/compute/apiv1" + computepb "google.golang.org/genproto/googleapis/cloud/compute/v1" +) + +func ExampleNewAcceleratorTypesRESTClient() { + ctx := context.Background() + c, err := compute.NewAcceleratorTypesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + // TODO: Use client. + _ = c +} + +func ExampleAcceleratorTypesClient_AggregatedList() { + ctx := context.Background() + c, err := compute.NewAcceleratorTypesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.AggregatedListAcceleratorTypesRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.AggregatedList(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleAcceleratorTypesClient_Get() { + ctx := context.Background() + c, err := compute.NewAcceleratorTypesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.GetAcceleratorTypeRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Get(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleAcceleratorTypesClient_List() { + ctx := context.Background() + c, err := compute.NewAcceleratorTypesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.ListAcceleratorTypesRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.List(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} diff --git a/compute/apiv1/addresses_client.go b/compute/apiv1/addresses_client.go new file mode 100644 index 00000000000..023436436bd --- /dev/null +++ b/compute/apiv1/addresses_client.go @@ -0,0 +1,452 @@ +// 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 compute + +import ( + "bytes" + "context" + "fmt" + "io/ioutil" + "net/http" + "net/url" + + gax "github.com/googleapis/gax-go/v2" + "google.golang.org/api/option" + "google.golang.org/api/option/internaloption" + httptransport "google.golang.org/api/transport/http" + computepb "google.golang.org/genproto/googleapis/cloud/compute/v1" + "google.golang.org/grpc" + "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/encoding/protojson" +) + +var newAddressesClientHook clientHook + +// AddressesCallOptions contains the retry settings for each method of AddressesClient. +type AddressesCallOptions struct { + AggregatedList []gax.CallOption + Delete []gax.CallOption + Get []gax.CallOption + Insert []gax.CallOption + List []gax.CallOption +} + +// internalAddressesClient is an interface that defines the methods availaible from Google Compute Engine API. +type internalAddressesClient interface { + Close() error + setGoogleClientInfo(...string) + Connection() *grpc.ClientConn + AggregatedList(context.Context, *computepb.AggregatedListAddressesRequest, ...gax.CallOption) (*computepb.AddressAggregatedList, error) + Delete(context.Context, *computepb.DeleteAddressRequest, ...gax.CallOption) (*computepb.Operation, error) + Get(context.Context, *computepb.GetAddressRequest, ...gax.CallOption) (*computepb.Address, error) + Insert(context.Context, *computepb.InsertAddressRequest, ...gax.CallOption) (*computepb.Operation, error) + List(context.Context, *computepb.ListAddressesRequest, ...gax.CallOption) (*computepb.AddressList, error) +} + +// AddressesClient is a client for interacting with Google Compute Engine API. +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +// +// The Addresses API. +type AddressesClient struct { + // The internal transport-dependent client. + internalClient internalAddressesClient + + // The call options for this service. + CallOptions *AddressesCallOptions +} + +// 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 *AddressesClient) 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 *AddressesClient) setGoogleClientInfo(keyval ...string) { + c.internalClient.setGoogleClientInfo(keyval...) +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *AddressesClient) Connection() *grpc.ClientConn { + return c.internalClient.Connection() +} + +// AggregatedList retrieves an aggregated list of addresses. +func (c *AddressesClient) AggregatedList(ctx context.Context, req *computepb.AggregatedListAddressesRequest, opts ...gax.CallOption) (*computepb.AddressAggregatedList, error) { + return c.internalClient.AggregatedList(ctx, req, opts...) +} + +// Delete deletes the specified address resource. +func (c *AddressesClient) Delete(ctx context.Context, req *computepb.DeleteAddressRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.Delete(ctx, req, opts...) +} + +// Get returns the specified address resource. +func (c *AddressesClient) Get(ctx context.Context, req *computepb.GetAddressRequest, opts ...gax.CallOption) (*computepb.Address, error) { + return c.internalClient.Get(ctx, req, opts...) +} + +// Insert creates an address resource in the specified project by using the data included in the request. +func (c *AddressesClient) Insert(ctx context.Context, req *computepb.InsertAddressRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.Insert(ctx, req, opts...) +} + +// List retrieves a list of addresses contained within the specified region. +func (c *AddressesClient) List(ctx context.Context, req *computepb.ListAddressesRequest, opts ...gax.CallOption) (*computepb.AddressList, error) { + return c.internalClient.List(ctx, req, opts...) +} + +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +type addressesRESTClient struct { + // The http endpoint to connect to. + endpoint string + + // The http client. + httpClient *http.Client + + // The x-goog-* metadata to be sent with each request. + xGoogMetadata metadata.MD +} + +// NewAddressesRESTClient creates a new addresses rest client. +// +// The Addresses API. +func NewAddressesRESTClient(ctx context.Context, opts ...option.ClientOption) (*AddressesClient, error) { + clientOpts := append(defaultAddressesRESTClientOptions(), opts...) + httpClient, endpoint, err := httptransport.NewClient(ctx, clientOpts...) + if err != nil { + return nil, err + } + + c := &addressesRESTClient{ + endpoint: endpoint, + httpClient: httpClient, + } + c.setGoogleClientInfo() + + return &AddressesClient{internalClient: c, CallOptions: &AddressesCallOptions{}}, nil +} + +func defaultAddressesRESTClientOptions() []option.ClientOption { + return []option.ClientOption{ + internaloption.WithDefaultEndpoint("compute.googleapis.com"), + internaloption.WithDefaultMTLSEndpoint("compute.mtls.googleapis.com"), + internaloption.WithDefaultAudience("https://compute.googleapis.com/"), + internaloption.WithDefaultScopes(DefaultAuthScopes()...), + } +} + +// 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 *addressesRESTClient) setGoogleClientInfo(keyval ...string) { + kv := append([]string{"gl-go", versionGo()}, keyval...) + kv = append(kv, "gapic", versionClient, "gax", gax.Version, "rest", "UNKNOWN") + 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 *addressesRESTClient) Close() error { + // Replace httpClient with nil to force cleanup. + c.httpClient = nil + return nil +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *addressesRESTClient) Connection() *grpc.ClientConn { + return nil +} + +// AggregatedList retrieves an aggregated list of addresses. +func (c *addressesRESTClient) AggregatedList(ctx context.Context, req *computepb.AggregatedListAddressesRequest, opts ...gax.CallOption) (*computepb.AddressAggregatedList, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/aggregated/addresses", req.GetProject()) + + params := url.Values{} + if req != nil && req.Filter != nil { + params.Add("filter", fmt.Sprintf("%v", req.GetFilter())) + } + if req != nil && req.IncludeAllScopes != nil { + params.Add("includeAllScopes", fmt.Sprintf("%v", req.GetIncludeAllScopes())) + } + if req != nil && req.MaxResults != nil { + params.Add("maxResults", fmt.Sprintf("%v", req.GetMaxResults())) + } + if req != nil && req.OrderBy != nil { + params.Add("orderBy", fmt.Sprintf("%v", req.GetOrderBy())) + } + if req != nil && req.PageToken != nil { + params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) + } + if req != nil && req.ReturnPartialSuccess != nil { + params.Add("returnPartialSuccess", fmt.Sprintf("%v", req.GetReturnPartialSuccess())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.AddressAggregatedList{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Delete deletes the specified address resource. +func (c *addressesRESTClient) Delete(ctx context.Context, req *computepb.DeleteAddressRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/regions/%v/addresses/%v", req.GetProject(), req.GetRegion(), req.GetAddress()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("DELETE", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Get returns the specified address resource. +func (c *addressesRESTClient) Get(ctx context.Context, req *computepb.GetAddressRequest, opts ...gax.CallOption) (*computepb.Address, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/regions/%v/addresses/%v", req.GetProject(), req.GetRegion(), req.GetAddress()) + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Address{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Insert creates an address resource in the specified project by using the data included in the request. +func (c *addressesRESTClient) Insert(ctx context.Context, req *computepb.InsertAddressRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetAddressResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/regions/%v/addresses", req.GetProject(), req.GetRegion()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// List retrieves a list of addresses contained within the specified region. +func (c *addressesRESTClient) List(ctx context.Context, req *computepb.ListAddressesRequest, opts ...gax.CallOption) (*computepb.AddressList, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/regions/%v/addresses", req.GetProject(), req.GetRegion()) + + params := url.Values{} + if req != nil && req.Filter != nil { + params.Add("filter", fmt.Sprintf("%v", req.GetFilter())) + } + if req != nil && req.MaxResults != nil { + params.Add("maxResults", fmt.Sprintf("%v", req.GetMaxResults())) + } + if req != nil && req.OrderBy != nil { + params.Add("orderBy", fmt.Sprintf("%v", req.GetOrderBy())) + } + if req != nil && req.PageToken != nil { + params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) + } + if req != nil && req.ReturnPartialSuccess != nil { + params.Add("returnPartialSuccess", fmt.Sprintf("%v", req.GetReturnPartialSuccess())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.AddressList{} + + return rsp, unm.Unmarshal(buf, rsp) +} diff --git a/compute/apiv1/addresses_client_example_test.go b/compute/apiv1/addresses_client_example_test.go new file mode 100644 index 00000000000..8349df07d7b --- /dev/null +++ b/compute/apiv1/addresses_client_example_test.go @@ -0,0 +1,131 @@ +// 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 compute_test + +import ( + "context" + + compute "cloud.google.com/go/compute/apiv1" + computepb "google.golang.org/genproto/googleapis/cloud/compute/v1" +) + +func ExampleNewAddressesRESTClient() { + ctx := context.Background() + c, err := compute.NewAddressesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + // TODO: Use client. + _ = c +} + +func ExampleAddressesClient_AggregatedList() { + ctx := context.Background() + c, err := compute.NewAddressesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.AggregatedListAddressesRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.AggregatedList(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleAddressesClient_Delete() { + ctx := context.Background() + c, err := compute.NewAddressesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.DeleteAddressRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Delete(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleAddressesClient_Get() { + ctx := context.Background() + c, err := compute.NewAddressesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.GetAddressRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Get(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleAddressesClient_Insert() { + ctx := context.Background() + c, err := compute.NewAddressesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.InsertAddressRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Insert(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleAddressesClient_List() { + ctx := context.Background() + c, err := compute.NewAddressesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.ListAddressesRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.List(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} diff --git a/compute/apiv1/autoscalers_client.go b/compute/apiv1/autoscalers_client.go new file mode 100644 index 00000000000..771438a9284 --- /dev/null +++ b/compute/apiv1/autoscalers_client.go @@ -0,0 +1,580 @@ +// 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 compute + +import ( + "bytes" + "context" + "fmt" + "io/ioutil" + "net/http" + "net/url" + + gax "github.com/googleapis/gax-go/v2" + "google.golang.org/api/option" + "google.golang.org/api/option/internaloption" + httptransport "google.golang.org/api/transport/http" + computepb "google.golang.org/genproto/googleapis/cloud/compute/v1" + "google.golang.org/grpc" + "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/encoding/protojson" +) + +var newAutoscalersClientHook clientHook + +// AutoscalersCallOptions contains the retry settings for each method of AutoscalersClient. +type AutoscalersCallOptions struct { + AggregatedList []gax.CallOption + Delete []gax.CallOption + Get []gax.CallOption + Insert []gax.CallOption + List []gax.CallOption + Patch []gax.CallOption + Update []gax.CallOption +} + +// internalAutoscalersClient is an interface that defines the methods availaible from Google Compute Engine API. +type internalAutoscalersClient interface { + Close() error + setGoogleClientInfo(...string) + Connection() *grpc.ClientConn + AggregatedList(context.Context, *computepb.AggregatedListAutoscalersRequest, ...gax.CallOption) (*computepb.AutoscalerAggregatedList, error) + Delete(context.Context, *computepb.DeleteAutoscalerRequest, ...gax.CallOption) (*computepb.Operation, error) + Get(context.Context, *computepb.GetAutoscalerRequest, ...gax.CallOption) (*computepb.Autoscaler, error) + Insert(context.Context, *computepb.InsertAutoscalerRequest, ...gax.CallOption) (*computepb.Operation, error) + List(context.Context, *computepb.ListAutoscalersRequest, ...gax.CallOption) (*computepb.AutoscalerList, error) + Patch(context.Context, *computepb.PatchAutoscalerRequest, ...gax.CallOption) (*computepb.Operation, error) + Update(context.Context, *computepb.UpdateAutoscalerRequest, ...gax.CallOption) (*computepb.Operation, error) +} + +// AutoscalersClient is a client for interacting with Google Compute Engine API. +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +// +// The Autoscalers API. +type AutoscalersClient struct { + // The internal transport-dependent client. + internalClient internalAutoscalersClient + + // The call options for this service. + CallOptions *AutoscalersCallOptions +} + +// 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 *AutoscalersClient) 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 *AutoscalersClient) setGoogleClientInfo(keyval ...string) { + c.internalClient.setGoogleClientInfo(keyval...) +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *AutoscalersClient) Connection() *grpc.ClientConn { + return c.internalClient.Connection() +} + +// AggregatedList retrieves an aggregated list of autoscalers. +func (c *AutoscalersClient) AggregatedList(ctx context.Context, req *computepb.AggregatedListAutoscalersRequest, opts ...gax.CallOption) (*computepb.AutoscalerAggregatedList, error) { + return c.internalClient.AggregatedList(ctx, req, opts...) +} + +// Delete deletes the specified autoscaler. +func (c *AutoscalersClient) Delete(ctx context.Context, req *computepb.DeleteAutoscalerRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.Delete(ctx, req, opts...) +} + +// Get returns the specified autoscaler resource. Gets a list of available autoscalers by making a list() request. +func (c *AutoscalersClient) Get(ctx context.Context, req *computepb.GetAutoscalerRequest, opts ...gax.CallOption) (*computepb.Autoscaler, error) { + return c.internalClient.Get(ctx, req, opts...) +} + +// Insert creates an autoscaler in the specified project using the data included in the request. +func (c *AutoscalersClient) Insert(ctx context.Context, req *computepb.InsertAutoscalerRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.Insert(ctx, req, opts...) +} + +// List retrieves a list of autoscalers contained within the specified zone. +func (c *AutoscalersClient) List(ctx context.Context, req *computepb.ListAutoscalersRequest, opts ...gax.CallOption) (*computepb.AutoscalerList, error) { + return c.internalClient.List(ctx, req, opts...) +} + +// Patch updates an autoscaler in the specified project using the data included in the request. This method supports PATCH semantics and uses the JSON merge patch format and processing rules. +func (c *AutoscalersClient) Patch(ctx context.Context, req *computepb.PatchAutoscalerRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.Patch(ctx, req, opts...) +} + +// Update updates an autoscaler in the specified project using the data included in the request. +func (c *AutoscalersClient) Update(ctx context.Context, req *computepb.UpdateAutoscalerRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.Update(ctx, req, opts...) +} + +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +type autoscalersRESTClient struct { + // The http endpoint to connect to. + endpoint string + + // The http client. + httpClient *http.Client + + // The x-goog-* metadata to be sent with each request. + xGoogMetadata metadata.MD +} + +// NewAutoscalersRESTClient creates a new autoscalers rest client. +// +// The Autoscalers API. +func NewAutoscalersRESTClient(ctx context.Context, opts ...option.ClientOption) (*AutoscalersClient, error) { + clientOpts := append(defaultAutoscalersRESTClientOptions(), opts...) + httpClient, endpoint, err := httptransport.NewClient(ctx, clientOpts...) + if err != nil { + return nil, err + } + + c := &autoscalersRESTClient{ + endpoint: endpoint, + httpClient: httpClient, + } + c.setGoogleClientInfo() + + return &AutoscalersClient{internalClient: c, CallOptions: &AutoscalersCallOptions{}}, nil +} + +func defaultAutoscalersRESTClientOptions() []option.ClientOption { + return []option.ClientOption{ + internaloption.WithDefaultEndpoint("compute.googleapis.com"), + internaloption.WithDefaultMTLSEndpoint("compute.mtls.googleapis.com"), + internaloption.WithDefaultAudience("https://compute.googleapis.com/"), + internaloption.WithDefaultScopes(DefaultAuthScopes()...), + } +} + +// 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 *autoscalersRESTClient) setGoogleClientInfo(keyval ...string) { + kv := append([]string{"gl-go", versionGo()}, keyval...) + kv = append(kv, "gapic", versionClient, "gax", gax.Version, "rest", "UNKNOWN") + 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 *autoscalersRESTClient) Close() error { + // Replace httpClient with nil to force cleanup. + c.httpClient = nil + return nil +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *autoscalersRESTClient) Connection() *grpc.ClientConn { + return nil +} + +// AggregatedList retrieves an aggregated list of autoscalers. +func (c *autoscalersRESTClient) AggregatedList(ctx context.Context, req *computepb.AggregatedListAutoscalersRequest, opts ...gax.CallOption) (*computepb.AutoscalerAggregatedList, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/aggregated/autoscalers", req.GetProject()) + + params := url.Values{} + if req != nil && req.Filter != nil { + params.Add("filter", fmt.Sprintf("%v", req.GetFilter())) + } + if req != nil && req.IncludeAllScopes != nil { + params.Add("includeAllScopes", fmt.Sprintf("%v", req.GetIncludeAllScopes())) + } + if req != nil && req.MaxResults != nil { + params.Add("maxResults", fmt.Sprintf("%v", req.GetMaxResults())) + } + if req != nil && req.OrderBy != nil { + params.Add("orderBy", fmt.Sprintf("%v", req.GetOrderBy())) + } + if req != nil && req.PageToken != nil { + params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) + } + if req != nil && req.ReturnPartialSuccess != nil { + params.Add("returnPartialSuccess", fmt.Sprintf("%v", req.GetReturnPartialSuccess())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.AutoscalerAggregatedList{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Delete deletes the specified autoscaler. +func (c *autoscalersRESTClient) Delete(ctx context.Context, req *computepb.DeleteAutoscalerRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/zones/%v/autoscalers/%v", req.GetProject(), req.GetZone(), req.GetAutoscaler()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("DELETE", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Get returns the specified autoscaler resource. Gets a list of available autoscalers by making a list() request. +func (c *autoscalersRESTClient) Get(ctx context.Context, req *computepb.GetAutoscalerRequest, opts ...gax.CallOption) (*computepb.Autoscaler, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/zones/%v/autoscalers/%v", req.GetProject(), req.GetZone(), req.GetAutoscaler()) + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Autoscaler{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Insert creates an autoscaler in the specified project using the data included in the request. +func (c *autoscalersRESTClient) Insert(ctx context.Context, req *computepb.InsertAutoscalerRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetAutoscalerResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/zones/%v/autoscalers", req.GetProject(), req.GetZone()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// List retrieves a list of autoscalers contained within the specified zone. +func (c *autoscalersRESTClient) List(ctx context.Context, req *computepb.ListAutoscalersRequest, opts ...gax.CallOption) (*computepb.AutoscalerList, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/zones/%v/autoscalers", req.GetProject(), req.GetZone()) + + params := url.Values{} + if req != nil && req.Filter != nil { + params.Add("filter", fmt.Sprintf("%v", req.GetFilter())) + } + if req != nil && req.MaxResults != nil { + params.Add("maxResults", fmt.Sprintf("%v", req.GetMaxResults())) + } + if req != nil && req.OrderBy != nil { + params.Add("orderBy", fmt.Sprintf("%v", req.GetOrderBy())) + } + if req != nil && req.PageToken != nil { + params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) + } + if req != nil && req.ReturnPartialSuccess != nil { + params.Add("returnPartialSuccess", fmt.Sprintf("%v", req.GetReturnPartialSuccess())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.AutoscalerList{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Patch updates an autoscaler in the specified project using the data included in the request. This method supports PATCH semantics and uses the JSON merge patch format and processing rules. +func (c *autoscalersRESTClient) Patch(ctx context.Context, req *computepb.PatchAutoscalerRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetAutoscalerResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/zones/%v/autoscalers", req.GetProject(), req.GetZone()) + + params := url.Values{} + if req != nil && req.Autoscaler != nil { + params.Add("autoscaler", fmt.Sprintf("%v", req.GetAutoscaler())) + } + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("PATCH", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Update updates an autoscaler in the specified project using the data included in the request. +func (c *autoscalersRESTClient) Update(ctx context.Context, req *computepb.UpdateAutoscalerRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetAutoscalerResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("") + + params := url.Values{} + if req != nil && req.Autoscaler != nil { + params.Add("autoscaler", fmt.Sprintf("%v", req.GetAutoscaler())) + } + if req.GetProject() != "" { + params.Add("project", fmt.Sprintf("%v", req.GetProject())) + } + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + if req.GetZone() != "" { + params.Add("zone", fmt.Sprintf("%v", req.GetZone())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("PUT", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} diff --git a/compute/apiv1/autoscalers_client_example_test.go b/compute/apiv1/autoscalers_client_example_test.go new file mode 100644 index 00000000000..48fa08ea659 --- /dev/null +++ b/compute/apiv1/autoscalers_client_example_test.go @@ -0,0 +1,169 @@ +// 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 compute_test + +import ( + "context" + + compute "cloud.google.com/go/compute/apiv1" + computepb "google.golang.org/genproto/googleapis/cloud/compute/v1" +) + +func ExampleNewAutoscalersRESTClient() { + ctx := context.Background() + c, err := compute.NewAutoscalersRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + // TODO: Use client. + _ = c +} + +func ExampleAutoscalersClient_AggregatedList() { + ctx := context.Background() + c, err := compute.NewAutoscalersRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.AggregatedListAutoscalersRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.AggregatedList(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleAutoscalersClient_Delete() { + ctx := context.Background() + c, err := compute.NewAutoscalersRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.DeleteAutoscalerRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Delete(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleAutoscalersClient_Get() { + ctx := context.Background() + c, err := compute.NewAutoscalersRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.GetAutoscalerRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Get(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleAutoscalersClient_Insert() { + ctx := context.Background() + c, err := compute.NewAutoscalersRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.InsertAutoscalerRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Insert(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleAutoscalersClient_List() { + ctx := context.Background() + c, err := compute.NewAutoscalersRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.ListAutoscalersRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.List(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleAutoscalersClient_Patch() { + ctx := context.Background() + c, err := compute.NewAutoscalersRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.PatchAutoscalerRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Patch(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleAutoscalersClient_Update() { + ctx := context.Background() + c, err := compute.NewAutoscalersRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.UpdateAutoscalerRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Update(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} diff --git a/compute/apiv1/backend_buckets_client.go b/compute/apiv1/backend_buckets_client.go new file mode 100644 index 00000000000..89286c9d461 --- /dev/null +++ b/compute/apiv1/backend_buckets_client.go @@ -0,0 +1,620 @@ +// 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 compute + +import ( + "bytes" + "context" + "fmt" + "io/ioutil" + "net/http" + "net/url" + + gax "github.com/googleapis/gax-go/v2" + "google.golang.org/api/option" + "google.golang.org/api/option/internaloption" + httptransport "google.golang.org/api/transport/http" + computepb "google.golang.org/genproto/googleapis/cloud/compute/v1" + "google.golang.org/grpc" + "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/encoding/protojson" +) + +var newBackendBucketsClientHook clientHook + +// BackendBucketsCallOptions contains the retry settings for each method of BackendBucketsClient. +type BackendBucketsCallOptions struct { + AddSignedUrlKey []gax.CallOption + Delete []gax.CallOption + DeleteSignedUrlKey []gax.CallOption + Get []gax.CallOption + Insert []gax.CallOption + List []gax.CallOption + Patch []gax.CallOption + Update []gax.CallOption +} + +// internalBackendBucketsClient is an interface that defines the methods availaible from Google Compute Engine API. +type internalBackendBucketsClient interface { + Close() error + setGoogleClientInfo(...string) + Connection() *grpc.ClientConn + AddSignedUrlKey(context.Context, *computepb.AddSignedUrlKeyBackendBucketRequest, ...gax.CallOption) (*computepb.Operation, error) + Delete(context.Context, *computepb.DeleteBackendBucketRequest, ...gax.CallOption) (*computepb.Operation, error) + DeleteSignedUrlKey(context.Context, *computepb.DeleteSignedUrlKeyBackendBucketRequest, ...gax.CallOption) (*computepb.Operation, error) + Get(context.Context, *computepb.GetBackendBucketRequest, ...gax.CallOption) (*computepb.BackendBucket, error) + Insert(context.Context, *computepb.InsertBackendBucketRequest, ...gax.CallOption) (*computepb.Operation, error) + List(context.Context, *computepb.ListBackendBucketsRequest, ...gax.CallOption) (*computepb.BackendBucketList, error) + Patch(context.Context, *computepb.PatchBackendBucketRequest, ...gax.CallOption) (*computepb.Operation, error) + Update(context.Context, *computepb.UpdateBackendBucketRequest, ...gax.CallOption) (*computepb.Operation, error) +} + +// BackendBucketsClient is a client for interacting with Google Compute Engine API. +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +// +// The BackendBuckets API. +type BackendBucketsClient struct { + // The internal transport-dependent client. + internalClient internalBackendBucketsClient + + // The call options for this service. + CallOptions *BackendBucketsCallOptions +} + +// 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 *BackendBucketsClient) 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 *BackendBucketsClient) setGoogleClientInfo(keyval ...string) { + c.internalClient.setGoogleClientInfo(keyval...) +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *BackendBucketsClient) Connection() *grpc.ClientConn { + return c.internalClient.Connection() +} + +// AddSignedUrlKey adds a key for validating requests with signed URLs for this backend bucket. +func (c *BackendBucketsClient) AddSignedUrlKey(ctx context.Context, req *computepb.AddSignedUrlKeyBackendBucketRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.AddSignedUrlKey(ctx, req, opts...) +} + +// Delete deletes the specified BackendBucket resource. +func (c *BackendBucketsClient) Delete(ctx context.Context, req *computepb.DeleteBackendBucketRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.Delete(ctx, req, opts...) +} + +// DeleteSignedUrlKey deletes a key for validating requests with signed URLs for this backend bucket. +func (c *BackendBucketsClient) DeleteSignedUrlKey(ctx context.Context, req *computepb.DeleteSignedUrlKeyBackendBucketRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.DeleteSignedUrlKey(ctx, req, opts...) +} + +// Get returns the specified BackendBucket resource. Gets a list of available backend buckets by making a list() request. +func (c *BackendBucketsClient) Get(ctx context.Context, req *computepb.GetBackendBucketRequest, opts ...gax.CallOption) (*computepb.BackendBucket, error) { + return c.internalClient.Get(ctx, req, opts...) +} + +// Insert creates a BackendBucket resource in the specified project using the data included in the request. +func (c *BackendBucketsClient) Insert(ctx context.Context, req *computepb.InsertBackendBucketRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.Insert(ctx, req, opts...) +} + +// List retrieves the list of BackendBucket resources available to the specified project. +func (c *BackendBucketsClient) List(ctx context.Context, req *computepb.ListBackendBucketsRequest, opts ...gax.CallOption) (*computepb.BackendBucketList, error) { + return c.internalClient.List(ctx, req, opts...) +} + +// Patch updates the specified BackendBucket resource with the data included in the request. This method supports PATCH semantics and uses the JSON merge patch format and processing rules. +func (c *BackendBucketsClient) Patch(ctx context.Context, req *computepb.PatchBackendBucketRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.Patch(ctx, req, opts...) +} + +// Update updates the specified BackendBucket resource with the data included in the request. +func (c *BackendBucketsClient) Update(ctx context.Context, req *computepb.UpdateBackendBucketRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.Update(ctx, req, opts...) +} + +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +type backendBucketsRESTClient struct { + // The http endpoint to connect to. + endpoint string + + // The http client. + httpClient *http.Client + + // The x-goog-* metadata to be sent with each request. + xGoogMetadata metadata.MD +} + +// NewBackendBucketsRESTClient creates a new backend buckets rest client. +// +// The BackendBuckets API. +func NewBackendBucketsRESTClient(ctx context.Context, opts ...option.ClientOption) (*BackendBucketsClient, error) { + clientOpts := append(defaultBackendBucketsRESTClientOptions(), opts...) + httpClient, endpoint, err := httptransport.NewClient(ctx, clientOpts...) + if err != nil { + return nil, err + } + + c := &backendBucketsRESTClient{ + endpoint: endpoint, + httpClient: httpClient, + } + c.setGoogleClientInfo() + + return &BackendBucketsClient{internalClient: c, CallOptions: &BackendBucketsCallOptions{}}, nil +} + +func defaultBackendBucketsRESTClientOptions() []option.ClientOption { + return []option.ClientOption{ + internaloption.WithDefaultEndpoint("compute.googleapis.com"), + internaloption.WithDefaultMTLSEndpoint("compute.mtls.googleapis.com"), + internaloption.WithDefaultAudience("https://compute.googleapis.com/"), + internaloption.WithDefaultScopes(DefaultAuthScopes()...), + } +} + +// 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 *backendBucketsRESTClient) setGoogleClientInfo(keyval ...string) { + kv := append([]string{"gl-go", versionGo()}, keyval...) + kv = append(kv, "gapic", versionClient, "gax", gax.Version, "rest", "UNKNOWN") + 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 *backendBucketsRESTClient) Close() error { + // Replace httpClient with nil to force cleanup. + c.httpClient = nil + return nil +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *backendBucketsRESTClient) Connection() *grpc.ClientConn { + return nil +} + +// AddSignedUrlKey adds a key for validating requests with signed URLs for this backend bucket. +func (c *backendBucketsRESTClient) AddSignedUrlKey(ctx context.Context, req *computepb.AddSignedUrlKeyBackendBucketRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetSignedUrlKeyResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/backendBuckets/%v/addSignedUrlKey", req.GetProject(), req.GetBackendBucket()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Delete deletes the specified BackendBucket resource. +func (c *backendBucketsRESTClient) Delete(ctx context.Context, req *computepb.DeleteBackendBucketRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/backendBuckets/%v", req.GetProject(), req.GetBackendBucket()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("DELETE", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// DeleteSignedUrlKey deletes a key for validating requests with signed URLs for this backend bucket. +func (c *backendBucketsRESTClient) DeleteSignedUrlKey(ctx context.Context, req *computepb.DeleteSignedUrlKeyBackendBucketRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/backendBuckets/%v/deleteSignedUrlKey", req.GetProject(), req.GetBackendBucket()) + + params := url.Values{} + if req.GetKeyName() != "" { + params.Add("keyName", fmt.Sprintf("%v", req.GetKeyName())) + } + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Get returns the specified BackendBucket resource. Gets a list of available backend buckets by making a list() request. +func (c *backendBucketsRESTClient) Get(ctx context.Context, req *computepb.GetBackendBucketRequest, opts ...gax.CallOption) (*computepb.BackendBucket, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/backendBuckets/%v", req.GetProject(), req.GetBackendBucket()) + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.BackendBucket{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Insert creates a BackendBucket resource in the specified project using the data included in the request. +func (c *backendBucketsRESTClient) Insert(ctx context.Context, req *computepb.InsertBackendBucketRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetBackendBucketResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/backendBuckets", req.GetProject()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// List retrieves the list of BackendBucket resources available to the specified project. +func (c *backendBucketsRESTClient) List(ctx context.Context, req *computepb.ListBackendBucketsRequest, opts ...gax.CallOption) (*computepb.BackendBucketList, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/backendBuckets", req.GetProject()) + + params := url.Values{} + if req != nil && req.Filter != nil { + params.Add("filter", fmt.Sprintf("%v", req.GetFilter())) + } + if req != nil && req.MaxResults != nil { + params.Add("maxResults", fmt.Sprintf("%v", req.GetMaxResults())) + } + if req != nil && req.OrderBy != nil { + params.Add("orderBy", fmt.Sprintf("%v", req.GetOrderBy())) + } + if req != nil && req.PageToken != nil { + params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) + } + if req != nil && req.ReturnPartialSuccess != nil { + params.Add("returnPartialSuccess", fmt.Sprintf("%v", req.GetReturnPartialSuccess())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.BackendBucketList{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Patch updates the specified BackendBucket resource with the data included in the request. This method supports PATCH semantics and uses the JSON merge patch format and processing rules. +func (c *backendBucketsRESTClient) Patch(ctx context.Context, req *computepb.PatchBackendBucketRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetBackendBucketResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/backendBuckets/%v", req.GetProject(), req.GetBackendBucket()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("PATCH", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Update updates the specified BackendBucket resource with the data included in the request. +func (c *backendBucketsRESTClient) Update(ctx context.Context, req *computepb.UpdateBackendBucketRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetBackendBucketResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("") + + params := url.Values{} + if req.GetBackendBucket() != "" { + params.Add("backendBucket", fmt.Sprintf("%v", req.GetBackendBucket())) + } + if req.GetProject() != "" { + params.Add("project", fmt.Sprintf("%v", req.GetProject())) + } + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("PUT", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} diff --git a/compute/apiv1/backend_buckets_client_example_test.go b/compute/apiv1/backend_buckets_client_example_test.go new file mode 100644 index 00000000000..1a7f3526506 --- /dev/null +++ b/compute/apiv1/backend_buckets_client_example_test.go @@ -0,0 +1,188 @@ +// 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 compute_test + +import ( + "context" + + compute "cloud.google.com/go/compute/apiv1" + computepb "google.golang.org/genproto/googleapis/cloud/compute/v1" +) + +func ExampleNewBackendBucketsRESTClient() { + ctx := context.Background() + c, err := compute.NewBackendBucketsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + // TODO: Use client. + _ = c +} + +func ExampleBackendBucketsClient_AddSignedUrlKey() { + ctx := context.Background() + c, err := compute.NewBackendBucketsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.AddSignedUrlKeyBackendBucketRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.AddSignedUrlKey(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleBackendBucketsClient_Delete() { + ctx := context.Background() + c, err := compute.NewBackendBucketsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.DeleteBackendBucketRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Delete(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleBackendBucketsClient_DeleteSignedUrlKey() { + ctx := context.Background() + c, err := compute.NewBackendBucketsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.DeleteSignedUrlKeyBackendBucketRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.DeleteSignedUrlKey(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleBackendBucketsClient_Get() { + ctx := context.Background() + c, err := compute.NewBackendBucketsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.GetBackendBucketRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Get(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleBackendBucketsClient_Insert() { + ctx := context.Background() + c, err := compute.NewBackendBucketsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.InsertBackendBucketRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Insert(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleBackendBucketsClient_List() { + ctx := context.Background() + c, err := compute.NewBackendBucketsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.ListBackendBucketsRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.List(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleBackendBucketsClient_Patch() { + ctx := context.Background() + c, err := compute.NewBackendBucketsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.PatchBackendBucketRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Patch(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleBackendBucketsClient_Update() { + ctx := context.Background() + c, err := compute.NewBackendBucketsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.UpdateBackendBucketRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Update(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} diff --git a/compute/apiv1/backend_services_client.go b/compute/apiv1/backend_services_client.go new file mode 100644 index 00000000000..b6dc5e585b4 --- /dev/null +++ b/compute/apiv1/backend_services_client.go @@ -0,0 +1,809 @@ +// 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 compute + +import ( + "bytes" + "context" + "fmt" + "io/ioutil" + "net/http" + "net/url" + + gax "github.com/googleapis/gax-go/v2" + "google.golang.org/api/option" + "google.golang.org/api/option/internaloption" + httptransport "google.golang.org/api/transport/http" + computepb "google.golang.org/genproto/googleapis/cloud/compute/v1" + "google.golang.org/grpc" + "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/encoding/protojson" +) + +var newBackendServicesClientHook clientHook + +// BackendServicesCallOptions contains the retry settings for each method of BackendServicesClient. +type BackendServicesCallOptions struct { + AddSignedUrlKey []gax.CallOption + AggregatedList []gax.CallOption + Delete []gax.CallOption + DeleteSignedUrlKey []gax.CallOption + Get []gax.CallOption + GetHealth []gax.CallOption + Insert []gax.CallOption + List []gax.CallOption + Patch []gax.CallOption + SetSecurityPolicy []gax.CallOption + Update []gax.CallOption +} + +// internalBackendServicesClient is an interface that defines the methods availaible from Google Compute Engine API. +type internalBackendServicesClient interface { + Close() error + setGoogleClientInfo(...string) + Connection() *grpc.ClientConn + AddSignedUrlKey(context.Context, *computepb.AddSignedUrlKeyBackendServiceRequest, ...gax.CallOption) (*computepb.Operation, error) + AggregatedList(context.Context, *computepb.AggregatedListBackendServicesRequest, ...gax.CallOption) (*computepb.BackendServiceAggregatedList, error) + Delete(context.Context, *computepb.DeleteBackendServiceRequest, ...gax.CallOption) (*computepb.Operation, error) + DeleteSignedUrlKey(context.Context, *computepb.DeleteSignedUrlKeyBackendServiceRequest, ...gax.CallOption) (*computepb.Operation, error) + Get(context.Context, *computepb.GetBackendServiceRequest, ...gax.CallOption) (*computepb.BackendService, error) + GetHealth(context.Context, *computepb.GetHealthBackendServiceRequest, ...gax.CallOption) (*computepb.BackendServiceGroupHealth, error) + Insert(context.Context, *computepb.InsertBackendServiceRequest, ...gax.CallOption) (*computepb.Operation, error) + List(context.Context, *computepb.ListBackendServicesRequest, ...gax.CallOption) (*computepb.BackendServiceList, error) + Patch(context.Context, *computepb.PatchBackendServiceRequest, ...gax.CallOption) (*computepb.Operation, error) + SetSecurityPolicy(context.Context, *computepb.SetSecurityPolicyBackendServiceRequest, ...gax.CallOption) (*computepb.Operation, error) + Update(context.Context, *computepb.UpdateBackendServiceRequest, ...gax.CallOption) (*computepb.Operation, error) +} + +// BackendServicesClient is a client for interacting with Google Compute Engine API. +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +// +// The BackendServices API. +type BackendServicesClient struct { + // The internal transport-dependent client. + internalClient internalBackendServicesClient + + // The call options for this service. + CallOptions *BackendServicesCallOptions +} + +// 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 *BackendServicesClient) 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 *BackendServicesClient) setGoogleClientInfo(keyval ...string) { + c.internalClient.setGoogleClientInfo(keyval...) +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *BackendServicesClient) Connection() *grpc.ClientConn { + return c.internalClient.Connection() +} + +// AddSignedUrlKey adds a key for validating requests with signed URLs for this backend service. +func (c *BackendServicesClient) AddSignedUrlKey(ctx context.Context, req *computepb.AddSignedUrlKeyBackendServiceRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.AddSignedUrlKey(ctx, req, opts...) +} + +// AggregatedList retrieves the list of all BackendService resources, regional and global, available to the specified project. +func (c *BackendServicesClient) AggregatedList(ctx context.Context, req *computepb.AggregatedListBackendServicesRequest, opts ...gax.CallOption) (*computepb.BackendServiceAggregatedList, error) { + return c.internalClient.AggregatedList(ctx, req, opts...) +} + +// Delete deletes the specified BackendService resource. +func (c *BackendServicesClient) Delete(ctx context.Context, req *computepb.DeleteBackendServiceRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.Delete(ctx, req, opts...) +} + +// DeleteSignedUrlKey deletes a key for validating requests with signed URLs for this backend service. +func (c *BackendServicesClient) DeleteSignedUrlKey(ctx context.Context, req *computepb.DeleteSignedUrlKeyBackendServiceRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.DeleteSignedUrlKey(ctx, req, opts...) +} + +// Get returns the specified BackendService resource. Gets a list of available backend services. +func (c *BackendServicesClient) Get(ctx context.Context, req *computepb.GetBackendServiceRequest, opts ...gax.CallOption) (*computepb.BackendService, error) { + return c.internalClient.Get(ctx, req, opts...) +} + +// GetHealth gets the most recent health check results for this BackendService. +// +// Example request body: +// +// { “group”: “/zones/us-east1-b/instanceGroups/lb-backend-example” } +func (c *BackendServicesClient) GetHealth(ctx context.Context, req *computepb.GetHealthBackendServiceRequest, opts ...gax.CallOption) (*computepb.BackendServiceGroupHealth, error) { + return c.internalClient.GetHealth(ctx, req, opts...) +} + +// Insert creates a BackendService resource in the specified project using the data included in the request. For more information, see Backend services overview. +func (c *BackendServicesClient) Insert(ctx context.Context, req *computepb.InsertBackendServiceRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.Insert(ctx, req, opts...) +} + +// List retrieves the list of BackendService resources available to the specified project. +func (c *BackendServicesClient) List(ctx context.Context, req *computepb.ListBackendServicesRequest, opts ...gax.CallOption) (*computepb.BackendServiceList, error) { + return c.internalClient.List(ctx, req, opts...) +} + +// Patch patches the specified BackendService resource with the data included in the request. For more information, see Backend services overview. This method supports PATCH semantics and uses the JSON merge patch format and processing rules. +func (c *BackendServicesClient) Patch(ctx context.Context, req *computepb.PatchBackendServiceRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.Patch(ctx, req, opts...) +} + +// SetSecurityPolicy sets the Google Cloud Armor security policy for the specified backend service. For more information, see Google Cloud Armor Overview +func (c *BackendServicesClient) SetSecurityPolicy(ctx context.Context, req *computepb.SetSecurityPolicyBackendServiceRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.SetSecurityPolicy(ctx, req, opts...) +} + +// Update updates the specified BackendService resource with the data included in the request. For more information, see Backend services overview. +func (c *BackendServicesClient) Update(ctx context.Context, req *computepb.UpdateBackendServiceRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.Update(ctx, req, opts...) +} + +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +type backendServicesRESTClient struct { + // The http endpoint to connect to. + endpoint string + + // The http client. + httpClient *http.Client + + // The x-goog-* metadata to be sent with each request. + xGoogMetadata metadata.MD +} + +// NewBackendServicesRESTClient creates a new backend services rest client. +// +// The BackendServices API. +func NewBackendServicesRESTClient(ctx context.Context, opts ...option.ClientOption) (*BackendServicesClient, error) { + clientOpts := append(defaultBackendServicesRESTClientOptions(), opts...) + httpClient, endpoint, err := httptransport.NewClient(ctx, clientOpts...) + if err != nil { + return nil, err + } + + c := &backendServicesRESTClient{ + endpoint: endpoint, + httpClient: httpClient, + } + c.setGoogleClientInfo() + + return &BackendServicesClient{internalClient: c, CallOptions: &BackendServicesCallOptions{}}, nil +} + +func defaultBackendServicesRESTClientOptions() []option.ClientOption { + return []option.ClientOption{ + internaloption.WithDefaultEndpoint("compute.googleapis.com"), + internaloption.WithDefaultMTLSEndpoint("compute.mtls.googleapis.com"), + internaloption.WithDefaultAudience("https://compute.googleapis.com/"), + internaloption.WithDefaultScopes(DefaultAuthScopes()...), + } +} + +// 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 *backendServicesRESTClient) setGoogleClientInfo(keyval ...string) { + kv := append([]string{"gl-go", versionGo()}, keyval...) + kv = append(kv, "gapic", versionClient, "gax", gax.Version, "rest", "UNKNOWN") + 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 *backendServicesRESTClient) Close() error { + // Replace httpClient with nil to force cleanup. + c.httpClient = nil + return nil +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *backendServicesRESTClient) Connection() *grpc.ClientConn { + return nil +} + +// AddSignedUrlKey adds a key for validating requests with signed URLs for this backend service. +func (c *backendServicesRESTClient) AddSignedUrlKey(ctx context.Context, req *computepb.AddSignedUrlKeyBackendServiceRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetSignedUrlKeyResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/backendServices/%v/addSignedUrlKey", req.GetProject(), req.GetBackendService()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// AggregatedList retrieves the list of all BackendService resources, regional and global, available to the specified project. +func (c *backendServicesRESTClient) AggregatedList(ctx context.Context, req *computepb.AggregatedListBackendServicesRequest, opts ...gax.CallOption) (*computepb.BackendServiceAggregatedList, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/aggregated/backendServices", req.GetProject()) + + params := url.Values{} + if req != nil && req.Filter != nil { + params.Add("filter", fmt.Sprintf("%v", req.GetFilter())) + } + if req != nil && req.IncludeAllScopes != nil { + params.Add("includeAllScopes", fmt.Sprintf("%v", req.GetIncludeAllScopes())) + } + if req != nil && req.MaxResults != nil { + params.Add("maxResults", fmt.Sprintf("%v", req.GetMaxResults())) + } + if req != nil && req.OrderBy != nil { + params.Add("orderBy", fmt.Sprintf("%v", req.GetOrderBy())) + } + if req != nil && req.PageToken != nil { + params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) + } + if req != nil && req.ReturnPartialSuccess != nil { + params.Add("returnPartialSuccess", fmt.Sprintf("%v", req.GetReturnPartialSuccess())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.BackendServiceAggregatedList{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Delete deletes the specified BackendService resource. +func (c *backendServicesRESTClient) Delete(ctx context.Context, req *computepb.DeleteBackendServiceRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/backendServices/%v", req.GetProject(), req.GetBackendService()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("DELETE", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// DeleteSignedUrlKey deletes a key for validating requests with signed URLs for this backend service. +func (c *backendServicesRESTClient) DeleteSignedUrlKey(ctx context.Context, req *computepb.DeleteSignedUrlKeyBackendServiceRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/backendServices/%v/deleteSignedUrlKey", req.GetProject(), req.GetBackendService()) + + params := url.Values{} + if req.GetKeyName() != "" { + params.Add("keyName", fmt.Sprintf("%v", req.GetKeyName())) + } + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Get returns the specified BackendService resource. Gets a list of available backend services. +func (c *backendServicesRESTClient) Get(ctx context.Context, req *computepb.GetBackendServiceRequest, opts ...gax.CallOption) (*computepb.BackendService, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/backendServices/%v", req.GetProject(), req.GetBackendService()) + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.BackendService{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// GetHealth gets the most recent health check results for this BackendService. +// +// Example request body: +// +// { “group”: “/zones/us-east1-b/instanceGroups/lb-backend-example” } +func (c *backendServicesRESTClient) GetHealth(ctx context.Context, req *computepb.GetHealthBackendServiceRequest, opts ...gax.CallOption) (*computepb.BackendServiceGroupHealth, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetResourceGroupReferenceResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/backendServices/%v/getHealth", req.GetProject(), req.GetBackendService()) + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.BackendServiceGroupHealth{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Insert creates a BackendService resource in the specified project using the data included in the request. For more information, see Backend services overview. +func (c *backendServicesRESTClient) Insert(ctx context.Context, req *computepb.InsertBackendServiceRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetBackendServiceResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/backendServices", req.GetProject()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// List retrieves the list of BackendService resources available to the specified project. +func (c *backendServicesRESTClient) List(ctx context.Context, req *computepb.ListBackendServicesRequest, opts ...gax.CallOption) (*computepb.BackendServiceList, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/backendServices", req.GetProject()) + + params := url.Values{} + if req != nil && req.Filter != nil { + params.Add("filter", fmt.Sprintf("%v", req.GetFilter())) + } + if req != nil && req.MaxResults != nil { + params.Add("maxResults", fmt.Sprintf("%v", req.GetMaxResults())) + } + if req != nil && req.OrderBy != nil { + params.Add("orderBy", fmt.Sprintf("%v", req.GetOrderBy())) + } + if req != nil && req.PageToken != nil { + params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) + } + if req != nil && req.ReturnPartialSuccess != nil { + params.Add("returnPartialSuccess", fmt.Sprintf("%v", req.GetReturnPartialSuccess())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.BackendServiceList{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Patch patches the specified BackendService resource with the data included in the request. For more information, see Backend services overview. This method supports PATCH semantics and uses the JSON merge patch format and processing rules. +func (c *backendServicesRESTClient) Patch(ctx context.Context, req *computepb.PatchBackendServiceRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetBackendServiceResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/backendServices/%v", req.GetProject(), req.GetBackendService()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("PATCH", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// SetSecurityPolicy sets the Google Cloud Armor security policy for the specified backend service. For more information, see Google Cloud Armor Overview +func (c *backendServicesRESTClient) SetSecurityPolicy(ctx context.Context, req *computepb.SetSecurityPolicyBackendServiceRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetSecurityPolicyReferenceResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/backendServices/%v/setSecurityPolicy", req.GetProject(), req.GetBackendService()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Update updates the specified BackendService resource with the data included in the request. For more information, see Backend services overview. +func (c *backendServicesRESTClient) Update(ctx context.Context, req *computepb.UpdateBackendServiceRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetBackendServiceResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("") + + params := url.Values{} + if req.GetBackendService() != "" { + params.Add("backendService", fmt.Sprintf("%v", req.GetBackendService())) + } + if req.GetProject() != "" { + params.Add("project", fmt.Sprintf("%v", req.GetProject())) + } + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("PUT", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} diff --git a/compute/apiv1/backend_services_client_example_test.go b/compute/apiv1/backend_services_client_example_test.go new file mode 100644 index 00000000000..6bdbd1e68e1 --- /dev/null +++ b/compute/apiv1/backend_services_client_example_test.go @@ -0,0 +1,245 @@ +// 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 compute_test + +import ( + "context" + + compute "cloud.google.com/go/compute/apiv1" + computepb "google.golang.org/genproto/googleapis/cloud/compute/v1" +) + +func ExampleNewBackendServicesRESTClient() { + ctx := context.Background() + c, err := compute.NewBackendServicesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + // TODO: Use client. + _ = c +} + +func ExampleBackendServicesClient_AddSignedUrlKey() { + ctx := context.Background() + c, err := compute.NewBackendServicesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.AddSignedUrlKeyBackendServiceRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.AddSignedUrlKey(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleBackendServicesClient_AggregatedList() { + ctx := context.Background() + c, err := compute.NewBackendServicesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.AggregatedListBackendServicesRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.AggregatedList(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleBackendServicesClient_Delete() { + ctx := context.Background() + c, err := compute.NewBackendServicesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.DeleteBackendServiceRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Delete(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleBackendServicesClient_DeleteSignedUrlKey() { + ctx := context.Background() + c, err := compute.NewBackendServicesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.DeleteSignedUrlKeyBackendServiceRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.DeleteSignedUrlKey(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleBackendServicesClient_Get() { + ctx := context.Background() + c, err := compute.NewBackendServicesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.GetBackendServiceRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Get(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleBackendServicesClient_GetHealth() { + ctx := context.Background() + c, err := compute.NewBackendServicesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.GetHealthBackendServiceRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.GetHealth(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleBackendServicesClient_Insert() { + ctx := context.Background() + c, err := compute.NewBackendServicesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.InsertBackendServiceRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Insert(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleBackendServicesClient_List() { + ctx := context.Background() + c, err := compute.NewBackendServicesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.ListBackendServicesRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.List(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleBackendServicesClient_Patch() { + ctx := context.Background() + c, err := compute.NewBackendServicesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.PatchBackendServiceRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Patch(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleBackendServicesClient_SetSecurityPolicy() { + ctx := context.Background() + c, err := compute.NewBackendServicesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.SetSecurityPolicyBackendServiceRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.SetSecurityPolicy(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleBackendServicesClient_Update() { + ctx := context.Background() + c, err := compute.NewBackendServicesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.UpdateBackendServiceRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Update(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} diff --git a/compute/apiv1/disk_types_client.go b/compute/apiv1/disk_types_client.go new file mode 100644 index 00000000000..aeb5487e614 --- /dev/null +++ b/compute/apiv1/disk_types_client.go @@ -0,0 +1,337 @@ +// 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 compute + +import ( + "bytes" + "context" + "fmt" + "io/ioutil" + "net/http" + "net/url" + + gax "github.com/googleapis/gax-go/v2" + "google.golang.org/api/option" + "google.golang.org/api/option/internaloption" + httptransport "google.golang.org/api/transport/http" + computepb "google.golang.org/genproto/googleapis/cloud/compute/v1" + "google.golang.org/grpc" + "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/encoding/protojson" +) + +var newDiskTypesClientHook clientHook + +// DiskTypesCallOptions contains the retry settings for each method of DiskTypesClient. +type DiskTypesCallOptions struct { + AggregatedList []gax.CallOption + Get []gax.CallOption + List []gax.CallOption +} + +// internalDiskTypesClient is an interface that defines the methods availaible from Google Compute Engine API. +type internalDiskTypesClient interface { + Close() error + setGoogleClientInfo(...string) + Connection() *grpc.ClientConn + AggregatedList(context.Context, *computepb.AggregatedListDiskTypesRequest, ...gax.CallOption) (*computepb.DiskTypeAggregatedList, error) + Get(context.Context, *computepb.GetDiskTypeRequest, ...gax.CallOption) (*computepb.DiskType, error) + List(context.Context, *computepb.ListDiskTypesRequest, ...gax.CallOption) (*computepb.DiskTypeList, error) +} + +// DiskTypesClient is a client for interacting with Google Compute Engine API. +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +// +// The DiskTypes API. +type DiskTypesClient struct { + // The internal transport-dependent client. + internalClient internalDiskTypesClient + + // The call options for this service. + CallOptions *DiskTypesCallOptions +} + +// 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 *DiskTypesClient) 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 *DiskTypesClient) setGoogleClientInfo(keyval ...string) { + c.internalClient.setGoogleClientInfo(keyval...) +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *DiskTypesClient) Connection() *grpc.ClientConn { + return c.internalClient.Connection() +} + +// AggregatedList retrieves an aggregated list of disk types. +func (c *DiskTypesClient) AggregatedList(ctx context.Context, req *computepb.AggregatedListDiskTypesRequest, opts ...gax.CallOption) (*computepb.DiskTypeAggregatedList, error) { + return c.internalClient.AggregatedList(ctx, req, opts...) +} + +// Get returns the specified disk type. Gets a list of available disk types by making a list() request. +func (c *DiskTypesClient) Get(ctx context.Context, req *computepb.GetDiskTypeRequest, opts ...gax.CallOption) (*computepb.DiskType, error) { + return c.internalClient.Get(ctx, req, opts...) +} + +// List retrieves a list of disk types available to the specified project. +func (c *DiskTypesClient) List(ctx context.Context, req *computepb.ListDiskTypesRequest, opts ...gax.CallOption) (*computepb.DiskTypeList, error) { + return c.internalClient.List(ctx, req, opts...) +} + +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +type diskTypesRESTClient struct { + // The http endpoint to connect to. + endpoint string + + // The http client. + httpClient *http.Client + + // The x-goog-* metadata to be sent with each request. + xGoogMetadata metadata.MD +} + +// NewDiskTypesRESTClient creates a new disk types rest client. +// +// The DiskTypes API. +func NewDiskTypesRESTClient(ctx context.Context, opts ...option.ClientOption) (*DiskTypesClient, error) { + clientOpts := append(defaultDiskTypesRESTClientOptions(), opts...) + httpClient, endpoint, err := httptransport.NewClient(ctx, clientOpts...) + if err != nil { + return nil, err + } + + c := &diskTypesRESTClient{ + endpoint: endpoint, + httpClient: httpClient, + } + c.setGoogleClientInfo() + + return &DiskTypesClient{internalClient: c, CallOptions: &DiskTypesCallOptions{}}, nil +} + +func defaultDiskTypesRESTClientOptions() []option.ClientOption { + return []option.ClientOption{ + internaloption.WithDefaultEndpoint("compute.googleapis.com"), + internaloption.WithDefaultMTLSEndpoint("compute.mtls.googleapis.com"), + internaloption.WithDefaultAudience("https://compute.googleapis.com/"), + internaloption.WithDefaultScopes(DefaultAuthScopes()...), + } +} + +// 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 *diskTypesRESTClient) setGoogleClientInfo(keyval ...string) { + kv := append([]string{"gl-go", versionGo()}, keyval...) + kv = append(kv, "gapic", versionClient, "gax", gax.Version, "rest", "UNKNOWN") + 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 *diskTypesRESTClient) Close() error { + // Replace httpClient with nil to force cleanup. + c.httpClient = nil + return nil +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *diskTypesRESTClient) Connection() *grpc.ClientConn { + return nil +} + +// AggregatedList retrieves an aggregated list of disk types. +func (c *diskTypesRESTClient) AggregatedList(ctx context.Context, req *computepb.AggregatedListDiskTypesRequest, opts ...gax.CallOption) (*computepb.DiskTypeAggregatedList, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/aggregated/diskTypes", req.GetProject()) + + params := url.Values{} + if req != nil && req.Filter != nil { + params.Add("filter", fmt.Sprintf("%v", req.GetFilter())) + } + if req != nil && req.IncludeAllScopes != nil { + params.Add("includeAllScopes", fmt.Sprintf("%v", req.GetIncludeAllScopes())) + } + if req != nil && req.MaxResults != nil { + params.Add("maxResults", fmt.Sprintf("%v", req.GetMaxResults())) + } + if req != nil && req.OrderBy != nil { + params.Add("orderBy", fmt.Sprintf("%v", req.GetOrderBy())) + } + if req != nil && req.PageToken != nil { + params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) + } + if req != nil && req.ReturnPartialSuccess != nil { + params.Add("returnPartialSuccess", fmt.Sprintf("%v", req.GetReturnPartialSuccess())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.DiskTypeAggregatedList{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Get returns the specified disk type. Gets a list of available disk types by making a list() request. +func (c *diskTypesRESTClient) Get(ctx context.Context, req *computepb.GetDiskTypeRequest, opts ...gax.CallOption) (*computepb.DiskType, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/zones/%v/diskTypes/%v", req.GetProject(), req.GetZone(), req.GetDiskType()) + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.DiskType{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// List retrieves a list of disk types available to the specified project. +func (c *diskTypesRESTClient) List(ctx context.Context, req *computepb.ListDiskTypesRequest, opts ...gax.CallOption) (*computepb.DiskTypeList, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/zones/%v/diskTypes", req.GetProject(), req.GetZone()) + + params := url.Values{} + if req != nil && req.Filter != nil { + params.Add("filter", fmt.Sprintf("%v", req.GetFilter())) + } + if req != nil && req.MaxResults != nil { + params.Add("maxResults", fmt.Sprintf("%v", req.GetMaxResults())) + } + if req != nil && req.OrderBy != nil { + params.Add("orderBy", fmt.Sprintf("%v", req.GetOrderBy())) + } + if req != nil && req.PageToken != nil { + params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) + } + if req != nil && req.ReturnPartialSuccess != nil { + params.Add("returnPartialSuccess", fmt.Sprintf("%v", req.GetReturnPartialSuccess())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.DiskTypeList{} + + return rsp, unm.Unmarshal(buf, rsp) +} diff --git a/compute/apiv1/disk_types_client_example_test.go b/compute/apiv1/disk_types_client_example_test.go new file mode 100644 index 00000000000..db2c18bb93e --- /dev/null +++ b/compute/apiv1/disk_types_client_example_test.go @@ -0,0 +1,93 @@ +// 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 compute_test + +import ( + "context" + + compute "cloud.google.com/go/compute/apiv1" + computepb "google.golang.org/genproto/googleapis/cloud/compute/v1" +) + +func ExampleNewDiskTypesRESTClient() { + ctx := context.Background() + c, err := compute.NewDiskTypesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + // TODO: Use client. + _ = c +} + +func ExampleDiskTypesClient_AggregatedList() { + ctx := context.Background() + c, err := compute.NewDiskTypesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.AggregatedListDiskTypesRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.AggregatedList(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleDiskTypesClient_Get() { + ctx := context.Background() + c, err := compute.NewDiskTypesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.GetDiskTypeRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Get(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleDiskTypesClient_List() { + ctx := context.Background() + c, err := compute.NewDiskTypesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.ListDiskTypesRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.List(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} diff --git a/compute/apiv1/disks_client.go b/compute/apiv1/disks_client.go new file mode 100644 index 00000000000..60e3f5e44dc --- /dev/null +++ b/compute/apiv1/disks_client.go @@ -0,0 +1,907 @@ +// 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 compute + +import ( + "bytes" + "context" + "fmt" + "io/ioutil" + "net/http" + "net/url" + + gax "github.com/googleapis/gax-go/v2" + "google.golang.org/api/option" + "google.golang.org/api/option/internaloption" + httptransport "google.golang.org/api/transport/http" + computepb "google.golang.org/genproto/googleapis/cloud/compute/v1" + "google.golang.org/grpc" + "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/encoding/protojson" +) + +var newDisksClientHook clientHook + +// DisksCallOptions contains the retry settings for each method of DisksClient. +type DisksCallOptions struct { + AddResourcePolicies []gax.CallOption + AggregatedList []gax.CallOption + CreateSnapshot []gax.CallOption + Delete []gax.CallOption + Get []gax.CallOption + GetIamPolicy []gax.CallOption + Insert []gax.CallOption + List []gax.CallOption + RemoveResourcePolicies []gax.CallOption + Resize []gax.CallOption + SetIamPolicy []gax.CallOption + SetLabels []gax.CallOption + TestIamPermissions []gax.CallOption +} + +// internalDisksClient is an interface that defines the methods availaible from Google Compute Engine API. +type internalDisksClient interface { + Close() error + setGoogleClientInfo(...string) + Connection() *grpc.ClientConn + AddResourcePolicies(context.Context, *computepb.AddResourcePoliciesDiskRequest, ...gax.CallOption) (*computepb.Operation, error) + AggregatedList(context.Context, *computepb.AggregatedListDisksRequest, ...gax.CallOption) (*computepb.DiskAggregatedList, error) + CreateSnapshot(context.Context, *computepb.CreateSnapshotDiskRequest, ...gax.CallOption) (*computepb.Operation, error) + Delete(context.Context, *computepb.DeleteDiskRequest, ...gax.CallOption) (*computepb.Operation, error) + Get(context.Context, *computepb.GetDiskRequest, ...gax.CallOption) (*computepb.Disk, error) + GetIamPolicy(context.Context, *computepb.GetIamPolicyDiskRequest, ...gax.CallOption) (*computepb.Policy, error) + Insert(context.Context, *computepb.InsertDiskRequest, ...gax.CallOption) (*computepb.Operation, error) + List(context.Context, *computepb.ListDisksRequest, ...gax.CallOption) (*computepb.DiskList, error) + RemoveResourcePolicies(context.Context, *computepb.RemoveResourcePoliciesDiskRequest, ...gax.CallOption) (*computepb.Operation, error) + Resize(context.Context, *computepb.ResizeDiskRequest, ...gax.CallOption) (*computepb.Operation, error) + SetIamPolicy(context.Context, *computepb.SetIamPolicyDiskRequest, ...gax.CallOption) (*computepb.Policy, error) + SetLabels(context.Context, *computepb.SetLabelsDiskRequest, ...gax.CallOption) (*computepb.Operation, error) + TestIamPermissions(context.Context, *computepb.TestIamPermissionsDiskRequest, ...gax.CallOption) (*computepb.TestPermissionsResponse, error) +} + +// DisksClient is a client for interacting with Google Compute Engine API. +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +// +// The Disks API. +type DisksClient struct { + // The internal transport-dependent client. + internalClient internalDisksClient + + // The call options for this service. + CallOptions *DisksCallOptions +} + +// 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 *DisksClient) 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 *DisksClient) setGoogleClientInfo(keyval ...string) { + c.internalClient.setGoogleClientInfo(keyval...) +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *DisksClient) Connection() *grpc.ClientConn { + return c.internalClient.Connection() +} + +// AddResourcePolicies adds existing resource policies to a disk. You can only add one policy which will be applied to this disk for scheduling snapshot creation. +func (c *DisksClient) AddResourcePolicies(ctx context.Context, req *computepb.AddResourcePoliciesDiskRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.AddResourcePolicies(ctx, req, opts...) +} + +// AggregatedList retrieves an aggregated list of persistent disks. +func (c *DisksClient) AggregatedList(ctx context.Context, req *computepb.AggregatedListDisksRequest, opts ...gax.CallOption) (*computepb.DiskAggregatedList, error) { + return c.internalClient.AggregatedList(ctx, req, opts...) +} + +// CreateSnapshot creates a snapshot of a specified persistent disk. +func (c *DisksClient) CreateSnapshot(ctx context.Context, req *computepb.CreateSnapshotDiskRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.CreateSnapshot(ctx, req, opts...) +} + +// Delete deletes the specified persistent disk. Deleting a disk removes its data permanently and is irreversible. However, deleting a disk does not delete any snapshots previously made from the disk. You must separately delete snapshots. +func (c *DisksClient) Delete(ctx context.Context, req *computepb.DeleteDiskRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.Delete(ctx, req, opts...) +} + +// Get returns a specified persistent disk. Gets a list of available persistent disks by making a list() request. +func (c *DisksClient) Get(ctx context.Context, req *computepb.GetDiskRequest, opts ...gax.CallOption) (*computepb.Disk, error) { + return c.internalClient.Get(ctx, req, opts...) +} + +// GetIamPolicy gets the access control policy for a resource. May be empty if no such policy or resource exists. +func (c *DisksClient) GetIamPolicy(ctx context.Context, req *computepb.GetIamPolicyDiskRequest, opts ...gax.CallOption) (*computepb.Policy, error) { + return c.internalClient.GetIamPolicy(ctx, req, opts...) +} + +// Insert creates a persistent disk in the specified project using the data in the request. You can create a disk from a source (sourceImage, sourceSnapshot, or sourceDisk) or create an empty 500 GB data disk by omitting all properties. You can also create a disk that is larger than the default size by specifying the sizeGb property. +func (c *DisksClient) Insert(ctx context.Context, req *computepb.InsertDiskRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.Insert(ctx, req, opts...) +} + +// List retrieves a list of persistent disks contained within the specified zone. +func (c *DisksClient) List(ctx context.Context, req *computepb.ListDisksRequest, opts ...gax.CallOption) (*computepb.DiskList, error) { + return c.internalClient.List(ctx, req, opts...) +} + +// RemoveResourcePolicies removes resource policies from a disk. +func (c *DisksClient) RemoveResourcePolicies(ctx context.Context, req *computepb.RemoveResourcePoliciesDiskRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.RemoveResourcePolicies(ctx, req, opts...) +} + +// Resize resizes the specified persistent disk. You can only increase the size of the disk. +func (c *DisksClient) Resize(ctx context.Context, req *computepb.ResizeDiskRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.Resize(ctx, req, opts...) +} + +// SetIamPolicy sets the access control policy on the specified resource. Replaces any existing policy. +func (c *DisksClient) SetIamPolicy(ctx context.Context, req *computepb.SetIamPolicyDiskRequest, opts ...gax.CallOption) (*computepb.Policy, error) { + return c.internalClient.SetIamPolicy(ctx, req, opts...) +} + +// SetLabels sets the labels on a disk. To learn more about labels, read the Labeling Resources documentation. +func (c *DisksClient) SetLabels(ctx context.Context, req *computepb.SetLabelsDiskRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.SetLabels(ctx, req, opts...) +} + +// TestIamPermissions returns permissions that a caller has on the specified resource. +func (c *DisksClient) TestIamPermissions(ctx context.Context, req *computepb.TestIamPermissionsDiskRequest, opts ...gax.CallOption) (*computepb.TestPermissionsResponse, error) { + return c.internalClient.TestIamPermissions(ctx, req, opts...) +} + +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +type disksRESTClient struct { + // The http endpoint to connect to. + endpoint string + + // The http client. + httpClient *http.Client + + // The x-goog-* metadata to be sent with each request. + xGoogMetadata metadata.MD +} + +// NewDisksRESTClient creates a new disks rest client. +// +// The Disks API. +func NewDisksRESTClient(ctx context.Context, opts ...option.ClientOption) (*DisksClient, error) { + clientOpts := append(defaultDisksRESTClientOptions(), opts...) + httpClient, endpoint, err := httptransport.NewClient(ctx, clientOpts...) + if err != nil { + return nil, err + } + + c := &disksRESTClient{ + endpoint: endpoint, + httpClient: httpClient, + } + c.setGoogleClientInfo() + + return &DisksClient{internalClient: c, CallOptions: &DisksCallOptions{}}, nil +} + +func defaultDisksRESTClientOptions() []option.ClientOption { + return []option.ClientOption{ + internaloption.WithDefaultEndpoint("compute.googleapis.com"), + internaloption.WithDefaultMTLSEndpoint("compute.mtls.googleapis.com"), + internaloption.WithDefaultAudience("https://compute.googleapis.com/"), + internaloption.WithDefaultScopes(DefaultAuthScopes()...), + } +} + +// 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 *disksRESTClient) setGoogleClientInfo(keyval ...string) { + kv := append([]string{"gl-go", versionGo()}, keyval...) + kv = append(kv, "gapic", versionClient, "gax", gax.Version, "rest", "UNKNOWN") + 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 *disksRESTClient) Close() error { + // Replace httpClient with nil to force cleanup. + c.httpClient = nil + return nil +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *disksRESTClient) Connection() *grpc.ClientConn { + return nil +} + +// AddResourcePolicies adds existing resource policies to a disk. You can only add one policy which will be applied to this disk for scheduling snapshot creation. +func (c *disksRESTClient) AddResourcePolicies(ctx context.Context, req *computepb.AddResourcePoliciesDiskRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetDisksAddResourcePoliciesRequestResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/zones/%v/disks/%v/addResourcePolicies", req.GetProject(), req.GetZone(), req.GetDisk()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// AggregatedList retrieves an aggregated list of persistent disks. +func (c *disksRESTClient) AggregatedList(ctx context.Context, req *computepb.AggregatedListDisksRequest, opts ...gax.CallOption) (*computepb.DiskAggregatedList, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/aggregated/disks", req.GetProject()) + + params := url.Values{} + if req != nil && req.Filter != nil { + params.Add("filter", fmt.Sprintf("%v", req.GetFilter())) + } + if req != nil && req.IncludeAllScopes != nil { + params.Add("includeAllScopes", fmt.Sprintf("%v", req.GetIncludeAllScopes())) + } + if req != nil && req.MaxResults != nil { + params.Add("maxResults", fmt.Sprintf("%v", req.GetMaxResults())) + } + if req != nil && req.OrderBy != nil { + params.Add("orderBy", fmt.Sprintf("%v", req.GetOrderBy())) + } + if req != nil && req.PageToken != nil { + params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) + } + if req != nil && req.ReturnPartialSuccess != nil { + params.Add("returnPartialSuccess", fmt.Sprintf("%v", req.GetReturnPartialSuccess())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.DiskAggregatedList{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// CreateSnapshot creates a snapshot of a specified persistent disk. +func (c *disksRESTClient) CreateSnapshot(ctx context.Context, req *computepb.CreateSnapshotDiskRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetSnapshotResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/zones/%v/disks/%v/createSnapshot", req.GetProject(), req.GetZone(), req.GetDisk()) + + params := url.Values{} + if req != nil && req.GuestFlush != nil { + params.Add("guestFlush", fmt.Sprintf("%v", req.GetGuestFlush())) + } + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Delete deletes the specified persistent disk. Deleting a disk removes its data permanently and is irreversible. However, deleting a disk does not delete any snapshots previously made from the disk. You must separately delete snapshots. +func (c *disksRESTClient) Delete(ctx context.Context, req *computepb.DeleteDiskRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/zones/%v/disks/%v", req.GetProject(), req.GetZone(), req.GetDisk()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("DELETE", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Get returns a specified persistent disk. Gets a list of available persistent disks by making a list() request. +func (c *disksRESTClient) Get(ctx context.Context, req *computepb.GetDiskRequest, opts ...gax.CallOption) (*computepb.Disk, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/zones/%v/disks/%v", req.GetProject(), req.GetZone(), req.GetDisk()) + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Disk{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// GetIamPolicy gets the access control policy for a resource. May be empty if no such policy or resource exists. +func (c *disksRESTClient) GetIamPolicy(ctx context.Context, req *computepb.GetIamPolicyDiskRequest, opts ...gax.CallOption) (*computepb.Policy, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/zones/%v/disks/%v/getIamPolicy", req.GetProject(), req.GetZone(), req.GetResource()) + + params := url.Values{} + if req != nil && req.OptionsRequestedPolicyVersion != nil { + params.Add("optionsRequestedPolicyVersion", fmt.Sprintf("%v", req.GetOptionsRequestedPolicyVersion())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Policy{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Insert creates a persistent disk in the specified project using the data in the request. You can create a disk from a source (sourceImage, sourceSnapshot, or sourceDisk) or create an empty 500 GB data disk by omitting all properties. You can also create a disk that is larger than the default size by specifying the sizeGb property. +func (c *disksRESTClient) Insert(ctx context.Context, req *computepb.InsertDiskRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetDiskResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/zones/%v/disks", req.GetProject(), req.GetZone()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + if req != nil && req.SourceImage != nil { + params.Add("sourceImage", fmt.Sprintf("%v", req.GetSourceImage())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// List retrieves a list of persistent disks contained within the specified zone. +func (c *disksRESTClient) List(ctx context.Context, req *computepb.ListDisksRequest, opts ...gax.CallOption) (*computepb.DiskList, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/zones/%v/disks", req.GetProject(), req.GetZone()) + + params := url.Values{} + if req != nil && req.Filter != nil { + params.Add("filter", fmt.Sprintf("%v", req.GetFilter())) + } + if req != nil && req.MaxResults != nil { + params.Add("maxResults", fmt.Sprintf("%v", req.GetMaxResults())) + } + if req != nil && req.OrderBy != nil { + params.Add("orderBy", fmt.Sprintf("%v", req.GetOrderBy())) + } + if req != nil && req.PageToken != nil { + params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) + } + if req != nil && req.ReturnPartialSuccess != nil { + params.Add("returnPartialSuccess", fmt.Sprintf("%v", req.GetReturnPartialSuccess())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.DiskList{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// RemoveResourcePolicies removes resource policies from a disk. +func (c *disksRESTClient) RemoveResourcePolicies(ctx context.Context, req *computepb.RemoveResourcePoliciesDiskRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetDisksRemoveResourcePoliciesRequestResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/zones/%v/disks/%v/removeResourcePolicies", req.GetProject(), req.GetZone(), req.GetDisk()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Resize resizes the specified persistent disk. You can only increase the size of the disk. +func (c *disksRESTClient) Resize(ctx context.Context, req *computepb.ResizeDiskRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetDisksResizeRequestResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/zones/%v/disks/%v/resize", req.GetProject(), req.GetZone(), req.GetDisk()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// SetIamPolicy sets the access control policy on the specified resource. Replaces any existing policy. +func (c *disksRESTClient) SetIamPolicy(ctx context.Context, req *computepb.SetIamPolicyDiskRequest, opts ...gax.CallOption) (*computepb.Policy, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetZoneSetPolicyRequestResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/zones/%v/disks/%v/setIamPolicy", req.GetProject(), req.GetZone(), req.GetResource()) + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Policy{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// SetLabels sets the labels on a disk. To learn more about labels, read the Labeling Resources documentation. +func (c *disksRESTClient) SetLabels(ctx context.Context, req *computepb.SetLabelsDiskRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetZoneSetLabelsRequestResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/zones/%v/disks/%v/setLabels", req.GetProject(), req.GetZone(), req.GetResource()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// TestIamPermissions returns permissions that a caller has on the specified resource. +func (c *disksRESTClient) TestIamPermissions(ctx context.Context, req *computepb.TestIamPermissionsDiskRequest, opts ...gax.CallOption) (*computepb.TestPermissionsResponse, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetTestPermissionsRequestResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/zones/%v/disks/%v/testIamPermissions", req.GetProject(), req.GetZone(), req.GetResource()) + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.TestPermissionsResponse{} + + return rsp, unm.Unmarshal(buf, rsp) +} diff --git a/compute/apiv1/disks_client_example_test.go b/compute/apiv1/disks_client_example_test.go new file mode 100644 index 00000000000..cbdcd918b75 --- /dev/null +++ b/compute/apiv1/disks_client_example_test.go @@ -0,0 +1,283 @@ +// 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 compute_test + +import ( + "context" + + compute "cloud.google.com/go/compute/apiv1" + computepb "google.golang.org/genproto/googleapis/cloud/compute/v1" +) + +func ExampleNewDisksRESTClient() { + ctx := context.Background() + c, err := compute.NewDisksRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + // TODO: Use client. + _ = c +} + +func ExampleDisksClient_AddResourcePolicies() { + ctx := context.Background() + c, err := compute.NewDisksRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.AddResourcePoliciesDiskRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.AddResourcePolicies(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleDisksClient_AggregatedList() { + ctx := context.Background() + c, err := compute.NewDisksRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.AggregatedListDisksRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.AggregatedList(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleDisksClient_CreateSnapshot() { + ctx := context.Background() + c, err := compute.NewDisksRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.CreateSnapshotDiskRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.CreateSnapshot(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleDisksClient_Delete() { + ctx := context.Background() + c, err := compute.NewDisksRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.DeleteDiskRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Delete(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleDisksClient_Get() { + ctx := context.Background() + c, err := compute.NewDisksRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.GetDiskRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Get(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleDisksClient_GetIamPolicy() { + ctx := context.Background() + c, err := compute.NewDisksRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.GetIamPolicyDiskRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.GetIamPolicy(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleDisksClient_Insert() { + ctx := context.Background() + c, err := compute.NewDisksRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.InsertDiskRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Insert(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleDisksClient_List() { + ctx := context.Background() + c, err := compute.NewDisksRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.ListDisksRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.List(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleDisksClient_RemoveResourcePolicies() { + ctx := context.Background() + c, err := compute.NewDisksRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.RemoveResourcePoliciesDiskRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.RemoveResourcePolicies(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleDisksClient_Resize() { + ctx := context.Background() + c, err := compute.NewDisksRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.ResizeDiskRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Resize(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleDisksClient_SetIamPolicy() { + ctx := context.Background() + c, err := compute.NewDisksRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.SetIamPolicyDiskRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.SetIamPolicy(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleDisksClient_SetLabels() { + ctx := context.Background() + c, err := compute.NewDisksRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.SetLabelsDiskRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.SetLabels(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleDisksClient_TestIamPermissions() { + ctx := context.Background() + c, err := compute.NewDisksRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.TestIamPermissionsDiskRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.TestIamPermissions(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} diff --git a/compute/apiv1/doc.go b/compute/apiv1/doc.go new file mode 100644 index 00000000000..4b6efeb2d7e --- /dev/null +++ b/compute/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 compute is an auto-generated package for the +// Google Compute Engine API. +// +// NOTE: This package is in alpha. It is not stable, and is likely to change. +// +// 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 compute // import "cloud.google.com/go/compute/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 = "20210701" + +func insertMetadata(ctx context.Context, mds ...metadata.MD) context.Context { + out, _ := metadata.FromOutgoingContext(ctx) + out = out.Copy() + for _, md := range mds { + for k, v := range md { + out[k] = append(out[k], v...) + } + } + return metadata.NewOutgoingContext(ctx, out) +} + +func checkDisableDeadlines() (bool, error) { + raw, ok := os.LookupEnv("GOOGLE_API_GO_EXPERIMENTAL_DISABLE_DEFAULT_DEADLINE") + if !ok { + return false, nil + } + + b, err := strconv.ParseBool(raw) + return b, err +} + +// DefaultAuthScopes reports the default set of authentication scopes to use with this package. +func DefaultAuthScopes() []string { + return []string{ + "https://www.googleapis.com/auth/cloud-platform", + "https://www.googleapis.com/auth/compute", + "https://www.googleapis.com/auth/compute.readonly", + } +} + +// versionGo returns the Go runtime version. The returned string +// has no whitespace, suitable for reporting in header. +func versionGo() string { + const develPrefix = "devel +" + + s := runtime.Version() + if strings.HasPrefix(s, develPrefix) { + s = s[len(develPrefix):] + if p := strings.IndexFunc(s, unicode.IsSpace); p >= 0 { + s = s[:p] + } + return s + } + + notSemverRune := func(r rune) bool { + return !strings.ContainsRune("0123456789.", r) + } + + if strings.HasPrefix(s, "go1") { + s = s[2:] + var prerelease string + if p := strings.IndexFunc(s, notSemverRune); p >= 0 { + s, prerelease = s[:p], s[p:] + } + if strings.HasSuffix(s, ".") { + s += "0" + } else if strings.Count(s, ".") < 2 { + s += ".0" + } + if prerelease != "" { + s += "-" + prerelease + } + return s + } + return "UNKNOWN" +} diff --git a/compute/apiv1/external_vpn_gateways_client.go b/compute/apiv1/external_vpn_gateways_client.go new file mode 100644 index 00000000000..00311af9054 --- /dev/null +++ b/compute/apiv1/external_vpn_gateways_client.go @@ -0,0 +1,482 @@ +// 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 compute + +import ( + "bytes" + "context" + "fmt" + "io/ioutil" + "net/http" + "net/url" + + gax "github.com/googleapis/gax-go/v2" + "google.golang.org/api/option" + "google.golang.org/api/option/internaloption" + httptransport "google.golang.org/api/transport/http" + computepb "google.golang.org/genproto/googleapis/cloud/compute/v1" + "google.golang.org/grpc" + "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/encoding/protojson" +) + +var newExternalVpnGatewaysClientHook clientHook + +// ExternalVpnGatewaysCallOptions contains the retry settings for each method of ExternalVpnGatewaysClient. +type ExternalVpnGatewaysCallOptions struct { + Delete []gax.CallOption + Get []gax.CallOption + Insert []gax.CallOption + List []gax.CallOption + SetLabels []gax.CallOption + TestIamPermissions []gax.CallOption +} + +// internalExternalVpnGatewaysClient is an interface that defines the methods availaible from Google Compute Engine API. +type internalExternalVpnGatewaysClient interface { + Close() error + setGoogleClientInfo(...string) + Connection() *grpc.ClientConn + Delete(context.Context, *computepb.DeleteExternalVpnGatewayRequest, ...gax.CallOption) (*computepb.Operation, error) + Get(context.Context, *computepb.GetExternalVpnGatewayRequest, ...gax.CallOption) (*computepb.ExternalVpnGateway, error) + Insert(context.Context, *computepb.InsertExternalVpnGatewayRequest, ...gax.CallOption) (*computepb.Operation, error) + List(context.Context, *computepb.ListExternalVpnGatewaysRequest, ...gax.CallOption) (*computepb.ExternalVpnGatewayList, error) + SetLabels(context.Context, *computepb.SetLabelsExternalVpnGatewayRequest, ...gax.CallOption) (*computepb.Operation, error) + TestIamPermissions(context.Context, *computepb.TestIamPermissionsExternalVpnGatewayRequest, ...gax.CallOption) (*computepb.TestPermissionsResponse, error) +} + +// ExternalVpnGatewaysClient is a client for interacting with Google Compute Engine API. +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +// +// The ExternalVpnGateways API. +type ExternalVpnGatewaysClient struct { + // The internal transport-dependent client. + internalClient internalExternalVpnGatewaysClient + + // The call options for this service. + CallOptions *ExternalVpnGatewaysCallOptions +} + +// 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 *ExternalVpnGatewaysClient) 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 *ExternalVpnGatewaysClient) setGoogleClientInfo(keyval ...string) { + c.internalClient.setGoogleClientInfo(keyval...) +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *ExternalVpnGatewaysClient) Connection() *grpc.ClientConn { + return c.internalClient.Connection() +} + +// Delete deletes the specified externalVpnGateway. +func (c *ExternalVpnGatewaysClient) Delete(ctx context.Context, req *computepb.DeleteExternalVpnGatewayRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.Delete(ctx, req, opts...) +} + +// Get returns the specified externalVpnGateway. Get a list of available externalVpnGateways by making a list() request. +func (c *ExternalVpnGatewaysClient) Get(ctx context.Context, req *computepb.GetExternalVpnGatewayRequest, opts ...gax.CallOption) (*computepb.ExternalVpnGateway, error) { + return c.internalClient.Get(ctx, req, opts...) +} + +// Insert creates a ExternalVpnGateway in the specified project using the data included in the request. +func (c *ExternalVpnGatewaysClient) Insert(ctx context.Context, req *computepb.InsertExternalVpnGatewayRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.Insert(ctx, req, opts...) +} + +// List retrieves the list of ExternalVpnGateway available to the specified project. +func (c *ExternalVpnGatewaysClient) List(ctx context.Context, req *computepb.ListExternalVpnGatewaysRequest, opts ...gax.CallOption) (*computepb.ExternalVpnGatewayList, error) { + return c.internalClient.List(ctx, req, opts...) +} + +// SetLabels sets the labels on an ExternalVpnGateway. To learn more about labels, read the Labeling Resources documentation. +func (c *ExternalVpnGatewaysClient) SetLabels(ctx context.Context, req *computepb.SetLabelsExternalVpnGatewayRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.SetLabels(ctx, req, opts...) +} + +// TestIamPermissions returns permissions that a caller has on the specified resource. +func (c *ExternalVpnGatewaysClient) TestIamPermissions(ctx context.Context, req *computepb.TestIamPermissionsExternalVpnGatewayRequest, opts ...gax.CallOption) (*computepb.TestPermissionsResponse, error) { + return c.internalClient.TestIamPermissions(ctx, req, opts...) +} + +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +type externalVpnGatewaysRESTClient struct { + // The http endpoint to connect to. + endpoint string + + // The http client. + httpClient *http.Client + + // The x-goog-* metadata to be sent with each request. + xGoogMetadata metadata.MD +} + +// NewExternalVpnGatewaysRESTClient creates a new external vpn gateways rest client. +// +// The ExternalVpnGateways API. +func NewExternalVpnGatewaysRESTClient(ctx context.Context, opts ...option.ClientOption) (*ExternalVpnGatewaysClient, error) { + clientOpts := append(defaultExternalVpnGatewaysRESTClientOptions(), opts...) + httpClient, endpoint, err := httptransport.NewClient(ctx, clientOpts...) + if err != nil { + return nil, err + } + + c := &externalVpnGatewaysRESTClient{ + endpoint: endpoint, + httpClient: httpClient, + } + c.setGoogleClientInfo() + + return &ExternalVpnGatewaysClient{internalClient: c, CallOptions: &ExternalVpnGatewaysCallOptions{}}, nil +} + +func defaultExternalVpnGatewaysRESTClientOptions() []option.ClientOption { + return []option.ClientOption{ + internaloption.WithDefaultEndpoint("compute.googleapis.com"), + internaloption.WithDefaultMTLSEndpoint("compute.mtls.googleapis.com"), + internaloption.WithDefaultAudience("https://compute.googleapis.com/"), + internaloption.WithDefaultScopes(DefaultAuthScopes()...), + } +} + +// 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 *externalVpnGatewaysRESTClient) setGoogleClientInfo(keyval ...string) { + kv := append([]string{"gl-go", versionGo()}, keyval...) + kv = append(kv, "gapic", versionClient, "gax", gax.Version, "rest", "UNKNOWN") + 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 *externalVpnGatewaysRESTClient) Close() error { + // Replace httpClient with nil to force cleanup. + c.httpClient = nil + return nil +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *externalVpnGatewaysRESTClient) Connection() *grpc.ClientConn { + return nil +} + +// Delete deletes the specified externalVpnGateway. +func (c *externalVpnGatewaysRESTClient) Delete(ctx context.Context, req *computepb.DeleteExternalVpnGatewayRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/externalVpnGateways/%v", req.GetProject(), req.GetExternalVpnGateway()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("DELETE", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Get returns the specified externalVpnGateway. Get a list of available externalVpnGateways by making a list() request. +func (c *externalVpnGatewaysRESTClient) Get(ctx context.Context, req *computepb.GetExternalVpnGatewayRequest, opts ...gax.CallOption) (*computepb.ExternalVpnGateway, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/externalVpnGateways/%v", req.GetProject(), req.GetExternalVpnGateway()) + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.ExternalVpnGateway{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Insert creates a ExternalVpnGateway in the specified project using the data included in the request. +func (c *externalVpnGatewaysRESTClient) Insert(ctx context.Context, req *computepb.InsertExternalVpnGatewayRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetExternalVpnGatewayResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/externalVpnGateways", req.GetProject()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// List retrieves the list of ExternalVpnGateway available to the specified project. +func (c *externalVpnGatewaysRESTClient) List(ctx context.Context, req *computepb.ListExternalVpnGatewaysRequest, opts ...gax.CallOption) (*computepb.ExternalVpnGatewayList, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/externalVpnGateways", req.GetProject()) + + params := url.Values{} + if req != nil && req.Filter != nil { + params.Add("filter", fmt.Sprintf("%v", req.GetFilter())) + } + if req != nil && req.MaxResults != nil { + params.Add("maxResults", fmt.Sprintf("%v", req.GetMaxResults())) + } + if req != nil && req.OrderBy != nil { + params.Add("orderBy", fmt.Sprintf("%v", req.GetOrderBy())) + } + if req != nil && req.PageToken != nil { + params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) + } + if req != nil && req.ReturnPartialSuccess != nil { + params.Add("returnPartialSuccess", fmt.Sprintf("%v", req.GetReturnPartialSuccess())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.ExternalVpnGatewayList{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// SetLabels sets the labels on an ExternalVpnGateway. To learn more about labels, read the Labeling Resources documentation. +func (c *externalVpnGatewaysRESTClient) SetLabels(ctx context.Context, req *computepb.SetLabelsExternalVpnGatewayRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetGlobalSetLabelsRequestResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/externalVpnGateways/%v/setLabels", req.GetProject(), req.GetResource()) + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// TestIamPermissions returns permissions that a caller has on the specified resource. +func (c *externalVpnGatewaysRESTClient) TestIamPermissions(ctx context.Context, req *computepb.TestIamPermissionsExternalVpnGatewayRequest, opts ...gax.CallOption) (*computepb.TestPermissionsResponse, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetTestPermissionsRequestResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/externalVpnGateways/%v/testIamPermissions", req.GetProject(), req.GetResource()) + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.TestPermissionsResponse{} + + return rsp, unm.Unmarshal(buf, rsp) +} diff --git a/compute/apiv1/external_vpn_gateways_client_example_test.go b/compute/apiv1/external_vpn_gateways_client_example_test.go new file mode 100644 index 00000000000..820c2c0a3fb --- /dev/null +++ b/compute/apiv1/external_vpn_gateways_client_example_test.go @@ -0,0 +1,150 @@ +// 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 compute_test + +import ( + "context" + + compute "cloud.google.com/go/compute/apiv1" + computepb "google.golang.org/genproto/googleapis/cloud/compute/v1" +) + +func ExampleNewExternalVpnGatewaysRESTClient() { + ctx := context.Background() + c, err := compute.NewExternalVpnGatewaysRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + // TODO: Use client. + _ = c +} + +func ExampleExternalVpnGatewaysClient_Delete() { + ctx := context.Background() + c, err := compute.NewExternalVpnGatewaysRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.DeleteExternalVpnGatewayRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Delete(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleExternalVpnGatewaysClient_Get() { + ctx := context.Background() + c, err := compute.NewExternalVpnGatewaysRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.GetExternalVpnGatewayRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Get(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleExternalVpnGatewaysClient_Insert() { + ctx := context.Background() + c, err := compute.NewExternalVpnGatewaysRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.InsertExternalVpnGatewayRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Insert(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleExternalVpnGatewaysClient_List() { + ctx := context.Background() + c, err := compute.NewExternalVpnGatewaysRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.ListExternalVpnGatewaysRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.List(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleExternalVpnGatewaysClient_SetLabels() { + ctx := context.Background() + c, err := compute.NewExternalVpnGatewaysRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.SetLabelsExternalVpnGatewayRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.SetLabels(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleExternalVpnGatewaysClient_TestIamPermissions() { + ctx := context.Background() + c, err := compute.NewExternalVpnGatewaysRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.TestIamPermissionsExternalVpnGatewayRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.TestIamPermissions(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} diff --git a/compute/apiv1/firewall_policies_client.go b/compute/apiv1/firewall_policies_client.go new file mode 100644 index 00000000000..4b224a975c3 --- /dev/null +++ b/compute/apiv1/firewall_policies_client.go @@ -0,0 +1,1194 @@ +// 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 compute + +import ( + "bytes" + "context" + "fmt" + "io/ioutil" + "net/http" + "net/url" + + gax "github.com/googleapis/gax-go/v2" + "google.golang.org/api/option" + "google.golang.org/api/option/internaloption" + httptransport "google.golang.org/api/transport/http" + computepb "google.golang.org/genproto/googleapis/cloud/compute/v1" + "google.golang.org/grpc" + "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/encoding/protojson" +) + +var newFirewallPoliciesClientHook clientHook + +// FirewallPoliciesCallOptions contains the retry settings for each method of FirewallPoliciesClient. +type FirewallPoliciesCallOptions struct { + AddAssociation []gax.CallOption + AddRule []gax.CallOption + CloneRules []gax.CallOption + Delete []gax.CallOption + Get []gax.CallOption + GetAssociation []gax.CallOption + GetIamPolicy []gax.CallOption + GetRule []gax.CallOption + Insert []gax.CallOption + List []gax.CallOption + ListAssociations []gax.CallOption + Move []gax.CallOption + Patch []gax.CallOption + PatchRule []gax.CallOption + RemoveAssociation []gax.CallOption + RemoveRule []gax.CallOption + SetIamPolicy []gax.CallOption + TestIamPermissions []gax.CallOption +} + +// internalFirewallPoliciesClient is an interface that defines the methods availaible from Google Compute Engine API. +type internalFirewallPoliciesClient interface { + Close() error + setGoogleClientInfo(...string) + Connection() *grpc.ClientConn + AddAssociation(context.Context, *computepb.AddAssociationFirewallPolicyRequest, ...gax.CallOption) (*computepb.Operation, error) + AddRule(context.Context, *computepb.AddRuleFirewallPolicyRequest, ...gax.CallOption) (*computepb.Operation, error) + CloneRules(context.Context, *computepb.CloneRulesFirewallPolicyRequest, ...gax.CallOption) (*computepb.Operation, error) + Delete(context.Context, *computepb.DeleteFirewallPolicyRequest, ...gax.CallOption) (*computepb.Operation, error) + Get(context.Context, *computepb.GetFirewallPolicyRequest, ...gax.CallOption) (*computepb.FirewallPolicy, error) + GetAssociation(context.Context, *computepb.GetAssociationFirewallPolicyRequest, ...gax.CallOption) (*computepb.FirewallPolicyAssociation, error) + GetIamPolicy(context.Context, *computepb.GetIamPolicyFirewallPolicyRequest, ...gax.CallOption) (*computepb.Policy, error) + GetRule(context.Context, *computepb.GetRuleFirewallPolicyRequest, ...gax.CallOption) (*computepb.FirewallPolicyRule, error) + Insert(context.Context, *computepb.InsertFirewallPolicyRequest, ...gax.CallOption) (*computepb.Operation, error) + List(context.Context, *computepb.ListFirewallPoliciesRequest, ...gax.CallOption) (*computepb.FirewallPolicyList, error) + ListAssociations(context.Context, *computepb.ListAssociationsFirewallPolicyRequest, ...gax.CallOption) (*computepb.FirewallPoliciesListAssociationsResponse, error) + Move(context.Context, *computepb.MoveFirewallPolicyRequest, ...gax.CallOption) (*computepb.Operation, error) + Patch(context.Context, *computepb.PatchFirewallPolicyRequest, ...gax.CallOption) (*computepb.Operation, error) + PatchRule(context.Context, *computepb.PatchRuleFirewallPolicyRequest, ...gax.CallOption) (*computepb.Operation, error) + RemoveAssociation(context.Context, *computepb.RemoveAssociationFirewallPolicyRequest, ...gax.CallOption) (*computepb.Operation, error) + RemoveRule(context.Context, *computepb.RemoveRuleFirewallPolicyRequest, ...gax.CallOption) (*computepb.Operation, error) + SetIamPolicy(context.Context, *computepb.SetIamPolicyFirewallPolicyRequest, ...gax.CallOption) (*computepb.Policy, error) + TestIamPermissions(context.Context, *computepb.TestIamPermissionsFirewallPolicyRequest, ...gax.CallOption) (*computepb.TestPermissionsResponse, error) +} + +// FirewallPoliciesClient is a client for interacting with Google Compute Engine API. +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +// +// The FirewallPolicies API. +type FirewallPoliciesClient struct { + // The internal transport-dependent client. + internalClient internalFirewallPoliciesClient + + // The call options for this service. + CallOptions *FirewallPoliciesCallOptions +} + +// 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 *FirewallPoliciesClient) 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 *FirewallPoliciesClient) setGoogleClientInfo(keyval ...string) { + c.internalClient.setGoogleClientInfo(keyval...) +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *FirewallPoliciesClient) Connection() *grpc.ClientConn { + return c.internalClient.Connection() +} + +// AddAssociation inserts an association for the specified firewall policy. +func (c *FirewallPoliciesClient) AddAssociation(ctx context.Context, req *computepb.AddAssociationFirewallPolicyRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.AddAssociation(ctx, req, opts...) +} + +// AddRule inserts a rule into a firewall policy. +func (c *FirewallPoliciesClient) AddRule(ctx context.Context, req *computepb.AddRuleFirewallPolicyRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.AddRule(ctx, req, opts...) +} + +// CloneRules copies rules to the specified firewall policy. +func (c *FirewallPoliciesClient) CloneRules(ctx context.Context, req *computepb.CloneRulesFirewallPolicyRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.CloneRules(ctx, req, opts...) +} + +// Delete deletes the specified policy. +func (c *FirewallPoliciesClient) Delete(ctx context.Context, req *computepb.DeleteFirewallPolicyRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.Delete(ctx, req, opts...) +} + +// Get returns the specified firewall policy. +func (c *FirewallPoliciesClient) Get(ctx context.Context, req *computepb.GetFirewallPolicyRequest, opts ...gax.CallOption) (*computepb.FirewallPolicy, error) { + return c.internalClient.Get(ctx, req, opts...) +} + +// GetAssociation gets an association with the specified name. +func (c *FirewallPoliciesClient) GetAssociation(ctx context.Context, req *computepb.GetAssociationFirewallPolicyRequest, opts ...gax.CallOption) (*computepb.FirewallPolicyAssociation, error) { + return c.internalClient.GetAssociation(ctx, req, opts...) +} + +// GetIamPolicy gets the access control policy for a resource. May be empty if no such policy or resource exists. +func (c *FirewallPoliciesClient) GetIamPolicy(ctx context.Context, req *computepb.GetIamPolicyFirewallPolicyRequest, opts ...gax.CallOption) (*computepb.Policy, error) { + return c.internalClient.GetIamPolicy(ctx, req, opts...) +} + +// GetRule gets a rule of the specified priority. +func (c *FirewallPoliciesClient) GetRule(ctx context.Context, req *computepb.GetRuleFirewallPolicyRequest, opts ...gax.CallOption) (*computepb.FirewallPolicyRule, error) { + return c.internalClient.GetRule(ctx, req, opts...) +} + +// Insert creates a new policy in the specified project using the data included in the request. +func (c *FirewallPoliciesClient) Insert(ctx context.Context, req *computepb.InsertFirewallPolicyRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.Insert(ctx, req, opts...) +} + +// List lists all the policies that have been configured for the specified project. +func (c *FirewallPoliciesClient) List(ctx context.Context, req *computepb.ListFirewallPoliciesRequest, opts ...gax.CallOption) (*computepb.FirewallPolicyList, error) { + return c.internalClient.List(ctx, req, opts...) +} + +// ListAssociations lists associations of a specified target, i.e., organization or folder. +func (c *FirewallPoliciesClient) ListAssociations(ctx context.Context, req *computepb.ListAssociationsFirewallPolicyRequest, opts ...gax.CallOption) (*computepb.FirewallPoliciesListAssociationsResponse, error) { + return c.internalClient.ListAssociations(ctx, req, opts...) +} + +// Move moves the specified firewall policy. +func (c *FirewallPoliciesClient) Move(ctx context.Context, req *computepb.MoveFirewallPolicyRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.Move(ctx, req, opts...) +} + +// Patch patches the specified policy with the data included in the request. +func (c *FirewallPoliciesClient) Patch(ctx context.Context, req *computepb.PatchFirewallPolicyRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.Patch(ctx, req, opts...) +} + +// PatchRule patches a rule of the specified priority. +func (c *FirewallPoliciesClient) PatchRule(ctx context.Context, req *computepb.PatchRuleFirewallPolicyRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.PatchRule(ctx, req, opts...) +} + +// RemoveAssociation removes an association for the specified firewall policy. +func (c *FirewallPoliciesClient) RemoveAssociation(ctx context.Context, req *computepb.RemoveAssociationFirewallPolicyRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.RemoveAssociation(ctx, req, opts...) +} + +// RemoveRule deletes a rule of the specified priority. +func (c *FirewallPoliciesClient) RemoveRule(ctx context.Context, req *computepb.RemoveRuleFirewallPolicyRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.RemoveRule(ctx, req, opts...) +} + +// SetIamPolicy sets the access control policy on the specified resource. Replaces any existing policy. +func (c *FirewallPoliciesClient) SetIamPolicy(ctx context.Context, req *computepb.SetIamPolicyFirewallPolicyRequest, opts ...gax.CallOption) (*computepb.Policy, error) { + return c.internalClient.SetIamPolicy(ctx, req, opts...) +} + +// TestIamPermissions returns permissions that a caller has on the specified resource. +func (c *FirewallPoliciesClient) TestIamPermissions(ctx context.Context, req *computepb.TestIamPermissionsFirewallPolicyRequest, opts ...gax.CallOption) (*computepb.TestPermissionsResponse, error) { + return c.internalClient.TestIamPermissions(ctx, req, opts...) +} + +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +type firewallPoliciesRESTClient struct { + // The http endpoint to connect to. + endpoint string + + // The http client. + httpClient *http.Client + + // The x-goog-* metadata to be sent with each request. + xGoogMetadata metadata.MD +} + +// NewFirewallPoliciesRESTClient creates a new firewall policies rest client. +// +// The FirewallPolicies API. +func NewFirewallPoliciesRESTClient(ctx context.Context, opts ...option.ClientOption) (*FirewallPoliciesClient, error) { + clientOpts := append(defaultFirewallPoliciesRESTClientOptions(), opts...) + httpClient, endpoint, err := httptransport.NewClient(ctx, clientOpts...) + if err != nil { + return nil, err + } + + c := &firewallPoliciesRESTClient{ + endpoint: endpoint, + httpClient: httpClient, + } + c.setGoogleClientInfo() + + return &FirewallPoliciesClient{internalClient: c, CallOptions: &FirewallPoliciesCallOptions{}}, nil +} + +func defaultFirewallPoliciesRESTClientOptions() []option.ClientOption { + return []option.ClientOption{ + internaloption.WithDefaultEndpoint("compute.googleapis.com"), + internaloption.WithDefaultMTLSEndpoint("compute.mtls.googleapis.com"), + internaloption.WithDefaultAudience("https://compute.googleapis.com/"), + internaloption.WithDefaultScopes(DefaultAuthScopes()...), + } +} + +// 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 *firewallPoliciesRESTClient) setGoogleClientInfo(keyval ...string) { + kv := append([]string{"gl-go", versionGo()}, keyval...) + kv = append(kv, "gapic", versionClient, "gax", gax.Version, "rest", "UNKNOWN") + 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 *firewallPoliciesRESTClient) Close() error { + // Replace httpClient with nil to force cleanup. + c.httpClient = nil + return nil +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *firewallPoliciesRESTClient) Connection() *grpc.ClientConn { + return nil +} + +// AddAssociation inserts an association for the specified firewall policy. +func (c *firewallPoliciesRESTClient) AddAssociation(ctx context.Context, req *computepb.AddAssociationFirewallPolicyRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetFirewallPolicyAssociationResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/locations/global/firewallPolicies/%v/addAssociation", req.GetFirewallPolicy()) + + params := url.Values{} + if req != nil && req.ReplaceExistingAssociation != nil { + params.Add("replaceExistingAssociation", fmt.Sprintf("%v", req.GetReplaceExistingAssociation())) + } + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// AddRule inserts a rule into a firewall policy. +func (c *firewallPoliciesRESTClient) AddRule(ctx context.Context, req *computepb.AddRuleFirewallPolicyRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetFirewallPolicyRuleResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/locations/global/firewallPolicies/%v/addRule", req.GetFirewallPolicy()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// CloneRules copies rules to the specified firewall policy. +func (c *firewallPoliciesRESTClient) CloneRules(ctx context.Context, req *computepb.CloneRulesFirewallPolicyRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/locations/global/firewallPolicies/%v/cloneRules", req.GetFirewallPolicy()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + if req != nil && req.SourceFirewallPolicy != nil { + params.Add("sourceFirewallPolicy", fmt.Sprintf("%v", req.GetSourceFirewallPolicy())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Delete deletes the specified policy. +func (c *firewallPoliciesRESTClient) Delete(ctx context.Context, req *computepb.DeleteFirewallPolicyRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/locations/global/firewallPolicies/%v", req.GetFirewallPolicy()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("DELETE", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Get returns the specified firewall policy. +func (c *firewallPoliciesRESTClient) Get(ctx context.Context, req *computepb.GetFirewallPolicyRequest, opts ...gax.CallOption) (*computepb.FirewallPolicy, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/locations/global/firewallPolicies/%v", req.GetFirewallPolicy()) + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.FirewallPolicy{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// GetAssociation gets an association with the specified name. +func (c *firewallPoliciesRESTClient) GetAssociation(ctx context.Context, req *computepb.GetAssociationFirewallPolicyRequest, opts ...gax.CallOption) (*computepb.FirewallPolicyAssociation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/locations/global/firewallPolicies/%v/getAssociation", req.GetFirewallPolicy()) + + params := url.Values{} + if req != nil && req.Name != nil { + params.Add("name", fmt.Sprintf("%v", req.GetName())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.FirewallPolicyAssociation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// GetIamPolicy gets the access control policy for a resource. May be empty if no such policy or resource exists. +func (c *firewallPoliciesRESTClient) GetIamPolicy(ctx context.Context, req *computepb.GetIamPolicyFirewallPolicyRequest, opts ...gax.CallOption) (*computepb.Policy, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/locations/global/firewallPolicies/%v/getIamPolicy", req.GetResource()) + + params := url.Values{} + if req != nil && req.OptionsRequestedPolicyVersion != nil { + params.Add("optionsRequestedPolicyVersion", fmt.Sprintf("%v", req.GetOptionsRequestedPolicyVersion())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Policy{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// GetRule gets a rule of the specified priority. +func (c *firewallPoliciesRESTClient) GetRule(ctx context.Context, req *computepb.GetRuleFirewallPolicyRequest, opts ...gax.CallOption) (*computepb.FirewallPolicyRule, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/locations/global/firewallPolicies/%v/getRule", req.GetFirewallPolicy()) + + params := url.Values{} + if req != nil && req.Priority != nil { + params.Add("priority", fmt.Sprintf("%v", req.GetPriority())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.FirewallPolicyRule{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Insert creates a new policy in the specified project using the data included in the request. +func (c *firewallPoliciesRESTClient) Insert(ctx context.Context, req *computepb.InsertFirewallPolicyRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetFirewallPolicyResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/locations/global/firewallPolicies") + + params := url.Values{} + if req != nil && req.ParentId != nil { + params.Add("parentId", fmt.Sprintf("%v", req.GetParentId())) + } + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// List lists all the policies that have been configured for the specified project. +func (c *firewallPoliciesRESTClient) List(ctx context.Context, req *computepb.ListFirewallPoliciesRequest, opts ...gax.CallOption) (*computepb.FirewallPolicyList, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/locations/global/firewallPolicies") + + params := url.Values{} + if req != nil && req.Filter != nil { + params.Add("filter", fmt.Sprintf("%v", req.GetFilter())) + } + if req != nil && req.MaxResults != nil { + params.Add("maxResults", fmt.Sprintf("%v", req.GetMaxResults())) + } + if req != nil && req.OrderBy != nil { + params.Add("orderBy", fmt.Sprintf("%v", req.GetOrderBy())) + } + if req != nil && req.PageToken != nil { + params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) + } + if req != nil && req.ParentId != nil { + params.Add("parentId", fmt.Sprintf("%v", req.GetParentId())) + } + if req != nil && req.ReturnPartialSuccess != nil { + params.Add("returnPartialSuccess", fmt.Sprintf("%v", req.GetReturnPartialSuccess())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.FirewallPolicyList{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// ListAssociations lists associations of a specified target, i.e., organization or folder. +func (c *firewallPoliciesRESTClient) ListAssociations(ctx context.Context, req *computepb.ListAssociationsFirewallPolicyRequest, opts ...gax.CallOption) (*computepb.FirewallPoliciesListAssociationsResponse, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/locations/global/firewallPolicies/listAssociations") + + params := url.Values{} + if req != nil && req.TargetResource != nil { + params.Add("targetResource", fmt.Sprintf("%v", req.GetTargetResource())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.FirewallPoliciesListAssociationsResponse{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Move moves the specified firewall policy. +func (c *firewallPoliciesRESTClient) Move(ctx context.Context, req *computepb.MoveFirewallPolicyRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/locations/global/firewallPolicies/%v/move", req.GetFirewallPolicy()) + + params := url.Values{} + if req != nil && req.ParentId != nil { + params.Add("parentId", fmt.Sprintf("%v", req.GetParentId())) + } + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Patch patches the specified policy with the data included in the request. +func (c *firewallPoliciesRESTClient) Patch(ctx context.Context, req *computepb.PatchFirewallPolicyRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetFirewallPolicyResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/locations/global/firewallPolicies/%v", req.GetFirewallPolicy()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("PATCH", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// PatchRule patches a rule of the specified priority. +func (c *firewallPoliciesRESTClient) PatchRule(ctx context.Context, req *computepb.PatchRuleFirewallPolicyRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetFirewallPolicyRuleResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/locations/global/firewallPolicies/%v/patchRule", req.GetFirewallPolicy()) + + params := url.Values{} + if req != nil && req.Priority != nil { + params.Add("priority", fmt.Sprintf("%v", req.GetPriority())) + } + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// RemoveAssociation removes an association for the specified firewall policy. +func (c *firewallPoliciesRESTClient) RemoveAssociation(ctx context.Context, req *computepb.RemoveAssociationFirewallPolicyRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/locations/global/firewallPolicies/%v/removeAssociation", req.GetFirewallPolicy()) + + params := url.Values{} + if req != nil && req.Name != nil { + params.Add("name", fmt.Sprintf("%v", req.GetName())) + } + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// RemoveRule deletes a rule of the specified priority. +func (c *firewallPoliciesRESTClient) RemoveRule(ctx context.Context, req *computepb.RemoveRuleFirewallPolicyRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/locations/global/firewallPolicies/%v/removeRule", req.GetFirewallPolicy()) + + params := url.Values{} + if req != nil && req.Priority != nil { + params.Add("priority", fmt.Sprintf("%v", req.GetPriority())) + } + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// SetIamPolicy sets the access control policy on the specified resource. Replaces any existing policy. +func (c *firewallPoliciesRESTClient) SetIamPolicy(ctx context.Context, req *computepb.SetIamPolicyFirewallPolicyRequest, opts ...gax.CallOption) (*computepb.Policy, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetGlobalOrganizationSetPolicyRequestResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/locations/global/firewallPolicies/%v/setIamPolicy", req.GetResource()) + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Policy{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// TestIamPermissions returns permissions that a caller has on the specified resource. +func (c *firewallPoliciesRESTClient) TestIamPermissions(ctx context.Context, req *computepb.TestIamPermissionsFirewallPolicyRequest, opts ...gax.CallOption) (*computepb.TestPermissionsResponse, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetTestPermissionsRequestResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/locations/global/firewallPolicies/%v/testIamPermissions", req.GetResource()) + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.TestPermissionsResponse{} + + return rsp, unm.Unmarshal(buf, rsp) +} diff --git a/compute/apiv1/firewall_policies_client_example_test.go b/compute/apiv1/firewall_policies_client_example_test.go new file mode 100644 index 00000000000..787e486ebd1 --- /dev/null +++ b/compute/apiv1/firewall_policies_client_example_test.go @@ -0,0 +1,378 @@ +// 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 compute_test + +import ( + "context" + + compute "cloud.google.com/go/compute/apiv1" + computepb "google.golang.org/genproto/googleapis/cloud/compute/v1" +) + +func ExampleNewFirewallPoliciesRESTClient() { + ctx := context.Background() + c, err := compute.NewFirewallPoliciesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + // TODO: Use client. + _ = c +} + +func ExampleFirewallPoliciesClient_AddAssociation() { + ctx := context.Background() + c, err := compute.NewFirewallPoliciesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.AddAssociationFirewallPolicyRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.AddAssociation(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleFirewallPoliciesClient_AddRule() { + ctx := context.Background() + c, err := compute.NewFirewallPoliciesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.AddRuleFirewallPolicyRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.AddRule(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleFirewallPoliciesClient_CloneRules() { + ctx := context.Background() + c, err := compute.NewFirewallPoliciesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.CloneRulesFirewallPolicyRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.CloneRules(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleFirewallPoliciesClient_Delete() { + ctx := context.Background() + c, err := compute.NewFirewallPoliciesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.DeleteFirewallPolicyRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Delete(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleFirewallPoliciesClient_Get() { + ctx := context.Background() + c, err := compute.NewFirewallPoliciesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.GetFirewallPolicyRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Get(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleFirewallPoliciesClient_GetAssociation() { + ctx := context.Background() + c, err := compute.NewFirewallPoliciesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.GetAssociationFirewallPolicyRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.GetAssociation(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleFirewallPoliciesClient_GetIamPolicy() { + ctx := context.Background() + c, err := compute.NewFirewallPoliciesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.GetIamPolicyFirewallPolicyRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.GetIamPolicy(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleFirewallPoliciesClient_GetRule() { + ctx := context.Background() + c, err := compute.NewFirewallPoliciesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.GetRuleFirewallPolicyRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.GetRule(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleFirewallPoliciesClient_Insert() { + ctx := context.Background() + c, err := compute.NewFirewallPoliciesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.InsertFirewallPolicyRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Insert(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleFirewallPoliciesClient_List() { + ctx := context.Background() + c, err := compute.NewFirewallPoliciesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.ListFirewallPoliciesRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.List(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleFirewallPoliciesClient_ListAssociations() { + ctx := context.Background() + c, err := compute.NewFirewallPoliciesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.ListAssociationsFirewallPolicyRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.ListAssociations(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleFirewallPoliciesClient_Move() { + ctx := context.Background() + c, err := compute.NewFirewallPoliciesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.MoveFirewallPolicyRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Move(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleFirewallPoliciesClient_Patch() { + ctx := context.Background() + c, err := compute.NewFirewallPoliciesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.PatchFirewallPolicyRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Patch(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleFirewallPoliciesClient_PatchRule() { + ctx := context.Background() + c, err := compute.NewFirewallPoliciesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.PatchRuleFirewallPolicyRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.PatchRule(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleFirewallPoliciesClient_RemoveAssociation() { + ctx := context.Background() + c, err := compute.NewFirewallPoliciesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.RemoveAssociationFirewallPolicyRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.RemoveAssociation(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleFirewallPoliciesClient_RemoveRule() { + ctx := context.Background() + c, err := compute.NewFirewallPoliciesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.RemoveRuleFirewallPolicyRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.RemoveRule(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleFirewallPoliciesClient_SetIamPolicy() { + ctx := context.Background() + c, err := compute.NewFirewallPoliciesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.SetIamPolicyFirewallPolicyRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.SetIamPolicy(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleFirewallPoliciesClient_TestIamPermissions() { + ctx := context.Background() + c, err := compute.NewFirewallPoliciesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.TestIamPermissionsFirewallPolicyRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.TestIamPermissions(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} diff --git a/compute/apiv1/firewalls_client.go b/compute/apiv1/firewalls_client.go new file mode 100644 index 00000000000..2d764796b19 --- /dev/null +++ b/compute/apiv1/firewalls_client.go @@ -0,0 +1,502 @@ +// 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 compute + +import ( + "bytes" + "context" + "fmt" + "io/ioutil" + "net/http" + "net/url" + + gax "github.com/googleapis/gax-go/v2" + "google.golang.org/api/option" + "google.golang.org/api/option/internaloption" + httptransport "google.golang.org/api/transport/http" + computepb "google.golang.org/genproto/googleapis/cloud/compute/v1" + "google.golang.org/grpc" + "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/encoding/protojson" +) + +var newFirewallsClientHook clientHook + +// FirewallsCallOptions contains the retry settings for each method of FirewallsClient. +type FirewallsCallOptions struct { + Delete []gax.CallOption + Get []gax.CallOption + Insert []gax.CallOption + List []gax.CallOption + Patch []gax.CallOption + Update []gax.CallOption +} + +// internalFirewallsClient is an interface that defines the methods availaible from Google Compute Engine API. +type internalFirewallsClient interface { + Close() error + setGoogleClientInfo(...string) + Connection() *grpc.ClientConn + Delete(context.Context, *computepb.DeleteFirewallRequest, ...gax.CallOption) (*computepb.Operation, error) + Get(context.Context, *computepb.GetFirewallRequest, ...gax.CallOption) (*computepb.Firewall, error) + Insert(context.Context, *computepb.InsertFirewallRequest, ...gax.CallOption) (*computepb.Operation, error) + List(context.Context, *computepb.ListFirewallsRequest, ...gax.CallOption) (*computepb.FirewallList, error) + Patch(context.Context, *computepb.PatchFirewallRequest, ...gax.CallOption) (*computepb.Operation, error) + Update(context.Context, *computepb.UpdateFirewallRequest, ...gax.CallOption) (*computepb.Operation, error) +} + +// FirewallsClient is a client for interacting with Google Compute Engine API. +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +// +// The Firewalls API. +type FirewallsClient struct { + // The internal transport-dependent client. + internalClient internalFirewallsClient + + // The call options for this service. + CallOptions *FirewallsCallOptions +} + +// 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 *FirewallsClient) 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 *FirewallsClient) setGoogleClientInfo(keyval ...string) { + c.internalClient.setGoogleClientInfo(keyval...) +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *FirewallsClient) Connection() *grpc.ClientConn { + return c.internalClient.Connection() +} + +// Delete deletes the specified firewall. +func (c *FirewallsClient) Delete(ctx context.Context, req *computepb.DeleteFirewallRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.Delete(ctx, req, opts...) +} + +// Get returns the specified firewall. +func (c *FirewallsClient) Get(ctx context.Context, req *computepb.GetFirewallRequest, opts ...gax.CallOption) (*computepb.Firewall, error) { + return c.internalClient.Get(ctx, req, opts...) +} + +// Insert creates a firewall rule in the specified project using the data included in the request. +func (c *FirewallsClient) Insert(ctx context.Context, req *computepb.InsertFirewallRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.Insert(ctx, req, opts...) +} + +// List retrieves the list of firewall rules available to the specified project. +func (c *FirewallsClient) List(ctx context.Context, req *computepb.ListFirewallsRequest, opts ...gax.CallOption) (*computepb.FirewallList, error) { + return c.internalClient.List(ctx, req, opts...) +} + +// Patch updates the specified firewall rule with the data included in the request. This method supports PATCH semantics and uses the JSON merge patch format and processing rules. +func (c *FirewallsClient) Patch(ctx context.Context, req *computepb.PatchFirewallRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.Patch(ctx, req, opts...) +} + +// Update updates the specified firewall rule with the data included in the request. Note that all fields will be updated if using PUT, even fields that are not specified. To update individual fields, please use PATCH instead. +func (c *FirewallsClient) Update(ctx context.Context, req *computepb.UpdateFirewallRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.Update(ctx, req, opts...) +} + +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +type firewallsRESTClient struct { + // The http endpoint to connect to. + endpoint string + + // The http client. + httpClient *http.Client + + // The x-goog-* metadata to be sent with each request. + xGoogMetadata metadata.MD +} + +// NewFirewallsRESTClient creates a new firewalls rest client. +// +// The Firewalls API. +func NewFirewallsRESTClient(ctx context.Context, opts ...option.ClientOption) (*FirewallsClient, error) { + clientOpts := append(defaultFirewallsRESTClientOptions(), opts...) + httpClient, endpoint, err := httptransport.NewClient(ctx, clientOpts...) + if err != nil { + return nil, err + } + + c := &firewallsRESTClient{ + endpoint: endpoint, + httpClient: httpClient, + } + c.setGoogleClientInfo() + + return &FirewallsClient{internalClient: c, CallOptions: &FirewallsCallOptions{}}, nil +} + +func defaultFirewallsRESTClientOptions() []option.ClientOption { + return []option.ClientOption{ + internaloption.WithDefaultEndpoint("compute.googleapis.com"), + internaloption.WithDefaultMTLSEndpoint("compute.mtls.googleapis.com"), + internaloption.WithDefaultAudience("https://compute.googleapis.com/"), + internaloption.WithDefaultScopes(DefaultAuthScopes()...), + } +} + +// 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 *firewallsRESTClient) setGoogleClientInfo(keyval ...string) { + kv := append([]string{"gl-go", versionGo()}, keyval...) + kv = append(kv, "gapic", versionClient, "gax", gax.Version, "rest", "UNKNOWN") + 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 *firewallsRESTClient) Close() error { + // Replace httpClient with nil to force cleanup. + c.httpClient = nil + return nil +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *firewallsRESTClient) Connection() *grpc.ClientConn { + return nil +} + +// Delete deletes the specified firewall. +func (c *firewallsRESTClient) Delete(ctx context.Context, req *computepb.DeleteFirewallRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/firewalls/%v", req.GetProject(), req.GetFirewall()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("DELETE", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Get returns the specified firewall. +func (c *firewallsRESTClient) Get(ctx context.Context, req *computepb.GetFirewallRequest, opts ...gax.CallOption) (*computepb.Firewall, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/firewalls/%v", req.GetProject(), req.GetFirewall()) + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Firewall{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Insert creates a firewall rule in the specified project using the data included in the request. +func (c *firewallsRESTClient) Insert(ctx context.Context, req *computepb.InsertFirewallRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetFirewallResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/firewalls", req.GetProject()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// List retrieves the list of firewall rules available to the specified project. +func (c *firewallsRESTClient) List(ctx context.Context, req *computepb.ListFirewallsRequest, opts ...gax.CallOption) (*computepb.FirewallList, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/firewalls", req.GetProject()) + + params := url.Values{} + if req != nil && req.Filter != nil { + params.Add("filter", fmt.Sprintf("%v", req.GetFilter())) + } + if req != nil && req.MaxResults != nil { + params.Add("maxResults", fmt.Sprintf("%v", req.GetMaxResults())) + } + if req != nil && req.OrderBy != nil { + params.Add("orderBy", fmt.Sprintf("%v", req.GetOrderBy())) + } + if req != nil && req.PageToken != nil { + params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) + } + if req != nil && req.ReturnPartialSuccess != nil { + params.Add("returnPartialSuccess", fmt.Sprintf("%v", req.GetReturnPartialSuccess())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.FirewallList{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Patch updates the specified firewall rule with the data included in the request. This method supports PATCH semantics and uses the JSON merge patch format and processing rules. +func (c *firewallsRESTClient) Patch(ctx context.Context, req *computepb.PatchFirewallRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetFirewallResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/firewalls/%v", req.GetProject(), req.GetFirewall()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("PATCH", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Update updates the specified firewall rule with the data included in the request. Note that all fields will be updated if using PUT, even fields that are not specified. To update individual fields, please use PATCH instead. +func (c *firewallsRESTClient) Update(ctx context.Context, req *computepb.UpdateFirewallRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetFirewallResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("") + + params := url.Values{} + if req.GetFirewall() != "" { + params.Add("firewall", fmt.Sprintf("%v", req.GetFirewall())) + } + if req.GetProject() != "" { + params.Add("project", fmt.Sprintf("%v", req.GetProject())) + } + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("PUT", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} diff --git a/compute/apiv1/firewalls_client_example_test.go b/compute/apiv1/firewalls_client_example_test.go new file mode 100644 index 00000000000..e1db038fb2e --- /dev/null +++ b/compute/apiv1/firewalls_client_example_test.go @@ -0,0 +1,150 @@ +// 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 compute_test + +import ( + "context" + + compute "cloud.google.com/go/compute/apiv1" + computepb "google.golang.org/genproto/googleapis/cloud/compute/v1" +) + +func ExampleNewFirewallsRESTClient() { + ctx := context.Background() + c, err := compute.NewFirewallsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + // TODO: Use client. + _ = c +} + +func ExampleFirewallsClient_Delete() { + ctx := context.Background() + c, err := compute.NewFirewallsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.DeleteFirewallRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Delete(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleFirewallsClient_Get() { + ctx := context.Background() + c, err := compute.NewFirewallsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.GetFirewallRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Get(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleFirewallsClient_Insert() { + ctx := context.Background() + c, err := compute.NewFirewallsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.InsertFirewallRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Insert(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleFirewallsClient_List() { + ctx := context.Background() + c, err := compute.NewFirewallsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.ListFirewallsRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.List(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleFirewallsClient_Patch() { + ctx := context.Background() + c, err := compute.NewFirewallsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.PatchFirewallRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Patch(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleFirewallsClient_Update() { + ctx := context.Background() + c, err := compute.NewFirewallsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.UpdateFirewallRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Update(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} diff --git a/compute/apiv1/forwarding_rules_client.go b/compute/apiv1/forwarding_rules_client.go new file mode 100644 index 00000000000..de0011546a5 --- /dev/null +++ b/compute/apiv1/forwarding_rules_client.go @@ -0,0 +1,626 @@ +// 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 compute + +import ( + "bytes" + "context" + "fmt" + "io/ioutil" + "net/http" + "net/url" + + gax "github.com/googleapis/gax-go/v2" + "google.golang.org/api/option" + "google.golang.org/api/option/internaloption" + httptransport "google.golang.org/api/transport/http" + computepb "google.golang.org/genproto/googleapis/cloud/compute/v1" + "google.golang.org/grpc" + "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/encoding/protojson" +) + +var newForwardingRulesClientHook clientHook + +// ForwardingRulesCallOptions contains the retry settings for each method of ForwardingRulesClient. +type ForwardingRulesCallOptions struct { + AggregatedList []gax.CallOption + Delete []gax.CallOption + Get []gax.CallOption + Insert []gax.CallOption + List []gax.CallOption + Patch []gax.CallOption + SetLabels []gax.CallOption + SetTarget []gax.CallOption +} + +// internalForwardingRulesClient is an interface that defines the methods availaible from Google Compute Engine API. +type internalForwardingRulesClient interface { + Close() error + setGoogleClientInfo(...string) + Connection() *grpc.ClientConn + AggregatedList(context.Context, *computepb.AggregatedListForwardingRulesRequest, ...gax.CallOption) (*computepb.ForwardingRuleAggregatedList, error) + Delete(context.Context, *computepb.DeleteForwardingRuleRequest, ...gax.CallOption) (*computepb.Operation, error) + Get(context.Context, *computepb.GetForwardingRuleRequest, ...gax.CallOption) (*computepb.ForwardingRule, error) + Insert(context.Context, *computepb.InsertForwardingRuleRequest, ...gax.CallOption) (*computepb.Operation, error) + List(context.Context, *computepb.ListForwardingRulesRequest, ...gax.CallOption) (*computepb.ForwardingRuleList, error) + Patch(context.Context, *computepb.PatchForwardingRuleRequest, ...gax.CallOption) (*computepb.Operation, error) + SetLabels(context.Context, *computepb.SetLabelsForwardingRuleRequest, ...gax.CallOption) (*computepb.Operation, error) + SetTarget(context.Context, *computepb.SetTargetForwardingRuleRequest, ...gax.CallOption) (*computepb.Operation, error) +} + +// ForwardingRulesClient is a client for interacting with Google Compute Engine API. +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +// +// The ForwardingRules API. +type ForwardingRulesClient struct { + // The internal transport-dependent client. + internalClient internalForwardingRulesClient + + // The call options for this service. + CallOptions *ForwardingRulesCallOptions +} + +// 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 *ForwardingRulesClient) 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 *ForwardingRulesClient) setGoogleClientInfo(keyval ...string) { + c.internalClient.setGoogleClientInfo(keyval...) +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *ForwardingRulesClient) Connection() *grpc.ClientConn { + return c.internalClient.Connection() +} + +// AggregatedList retrieves an aggregated list of forwarding rules. +func (c *ForwardingRulesClient) AggregatedList(ctx context.Context, req *computepb.AggregatedListForwardingRulesRequest, opts ...gax.CallOption) (*computepb.ForwardingRuleAggregatedList, error) { + return c.internalClient.AggregatedList(ctx, req, opts...) +} + +// Delete deletes the specified ForwardingRule resource. +func (c *ForwardingRulesClient) Delete(ctx context.Context, req *computepb.DeleteForwardingRuleRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.Delete(ctx, req, opts...) +} + +// Get returns the specified ForwardingRule resource. +func (c *ForwardingRulesClient) Get(ctx context.Context, req *computepb.GetForwardingRuleRequest, opts ...gax.CallOption) (*computepb.ForwardingRule, error) { + return c.internalClient.Get(ctx, req, opts...) +} + +// Insert creates a ForwardingRule resource in the specified project and region using the data included in the request. +func (c *ForwardingRulesClient) Insert(ctx context.Context, req *computepb.InsertForwardingRuleRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.Insert(ctx, req, opts...) +} + +// List retrieves a list of ForwardingRule resources available to the specified project and region. +func (c *ForwardingRulesClient) List(ctx context.Context, req *computepb.ListForwardingRulesRequest, opts ...gax.CallOption) (*computepb.ForwardingRuleList, error) { + return c.internalClient.List(ctx, req, opts...) +} + +// Patch updates the specified forwarding rule with the data included in the request. This method supports PATCH semantics and uses the JSON merge patch format and processing rules. Currently, you can only patch the network_tier field. +func (c *ForwardingRulesClient) Patch(ctx context.Context, req *computepb.PatchForwardingRuleRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.Patch(ctx, req, opts...) +} + +// SetLabels sets the labels on the specified resource. To learn more about labels, read the Labeling Resources documentation. +func (c *ForwardingRulesClient) SetLabels(ctx context.Context, req *computepb.SetLabelsForwardingRuleRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.SetLabels(ctx, req, opts...) +} + +// SetTarget changes target URL for forwarding rule. The new target should be of the same type as the old target. +func (c *ForwardingRulesClient) SetTarget(ctx context.Context, req *computepb.SetTargetForwardingRuleRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.SetTarget(ctx, req, opts...) +} + +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +type forwardingRulesRESTClient struct { + // The http endpoint to connect to. + endpoint string + + // The http client. + httpClient *http.Client + + // The x-goog-* metadata to be sent with each request. + xGoogMetadata metadata.MD +} + +// NewForwardingRulesRESTClient creates a new forwarding rules rest client. +// +// The ForwardingRules API. +func NewForwardingRulesRESTClient(ctx context.Context, opts ...option.ClientOption) (*ForwardingRulesClient, error) { + clientOpts := append(defaultForwardingRulesRESTClientOptions(), opts...) + httpClient, endpoint, err := httptransport.NewClient(ctx, clientOpts...) + if err != nil { + return nil, err + } + + c := &forwardingRulesRESTClient{ + endpoint: endpoint, + httpClient: httpClient, + } + c.setGoogleClientInfo() + + return &ForwardingRulesClient{internalClient: c, CallOptions: &ForwardingRulesCallOptions{}}, nil +} + +func defaultForwardingRulesRESTClientOptions() []option.ClientOption { + return []option.ClientOption{ + internaloption.WithDefaultEndpoint("compute.googleapis.com"), + internaloption.WithDefaultMTLSEndpoint("compute.mtls.googleapis.com"), + internaloption.WithDefaultAudience("https://compute.googleapis.com/"), + internaloption.WithDefaultScopes(DefaultAuthScopes()...), + } +} + +// 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 *forwardingRulesRESTClient) setGoogleClientInfo(keyval ...string) { + kv := append([]string{"gl-go", versionGo()}, keyval...) + kv = append(kv, "gapic", versionClient, "gax", gax.Version, "rest", "UNKNOWN") + 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 *forwardingRulesRESTClient) Close() error { + // Replace httpClient with nil to force cleanup. + c.httpClient = nil + return nil +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *forwardingRulesRESTClient) Connection() *grpc.ClientConn { + return nil +} + +// AggregatedList retrieves an aggregated list of forwarding rules. +func (c *forwardingRulesRESTClient) AggregatedList(ctx context.Context, req *computepb.AggregatedListForwardingRulesRequest, opts ...gax.CallOption) (*computepb.ForwardingRuleAggregatedList, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/aggregated/forwardingRules", req.GetProject()) + + params := url.Values{} + if req != nil && req.Filter != nil { + params.Add("filter", fmt.Sprintf("%v", req.GetFilter())) + } + if req != nil && req.IncludeAllScopes != nil { + params.Add("includeAllScopes", fmt.Sprintf("%v", req.GetIncludeAllScopes())) + } + if req != nil && req.MaxResults != nil { + params.Add("maxResults", fmt.Sprintf("%v", req.GetMaxResults())) + } + if req != nil && req.OrderBy != nil { + params.Add("orderBy", fmt.Sprintf("%v", req.GetOrderBy())) + } + if req != nil && req.PageToken != nil { + params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) + } + if req != nil && req.ReturnPartialSuccess != nil { + params.Add("returnPartialSuccess", fmt.Sprintf("%v", req.GetReturnPartialSuccess())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.ForwardingRuleAggregatedList{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Delete deletes the specified ForwardingRule resource. +func (c *forwardingRulesRESTClient) Delete(ctx context.Context, req *computepb.DeleteForwardingRuleRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/regions/%v/forwardingRules/%v", req.GetProject(), req.GetRegion(), req.GetForwardingRule()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("DELETE", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Get returns the specified ForwardingRule resource. +func (c *forwardingRulesRESTClient) Get(ctx context.Context, req *computepb.GetForwardingRuleRequest, opts ...gax.CallOption) (*computepb.ForwardingRule, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/regions/%v/forwardingRules/%v", req.GetProject(), req.GetRegion(), req.GetForwardingRule()) + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.ForwardingRule{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Insert creates a ForwardingRule resource in the specified project and region using the data included in the request. +func (c *forwardingRulesRESTClient) Insert(ctx context.Context, req *computepb.InsertForwardingRuleRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetForwardingRuleResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/regions/%v/forwardingRules", req.GetProject(), req.GetRegion()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// List retrieves a list of ForwardingRule resources available to the specified project and region. +func (c *forwardingRulesRESTClient) List(ctx context.Context, req *computepb.ListForwardingRulesRequest, opts ...gax.CallOption) (*computepb.ForwardingRuleList, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/regions/%v/forwardingRules", req.GetProject(), req.GetRegion()) + + params := url.Values{} + if req != nil && req.Filter != nil { + params.Add("filter", fmt.Sprintf("%v", req.GetFilter())) + } + if req != nil && req.MaxResults != nil { + params.Add("maxResults", fmt.Sprintf("%v", req.GetMaxResults())) + } + if req != nil && req.OrderBy != nil { + params.Add("orderBy", fmt.Sprintf("%v", req.GetOrderBy())) + } + if req != nil && req.PageToken != nil { + params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) + } + if req != nil && req.ReturnPartialSuccess != nil { + params.Add("returnPartialSuccess", fmt.Sprintf("%v", req.GetReturnPartialSuccess())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.ForwardingRuleList{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Patch updates the specified forwarding rule with the data included in the request. This method supports PATCH semantics and uses the JSON merge patch format and processing rules. Currently, you can only patch the network_tier field. +func (c *forwardingRulesRESTClient) Patch(ctx context.Context, req *computepb.PatchForwardingRuleRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetForwardingRuleResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/regions/%v/forwardingRules/%v", req.GetProject(), req.GetRegion(), req.GetForwardingRule()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("PATCH", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// SetLabels sets the labels on the specified resource. To learn more about labels, read the Labeling Resources documentation. +func (c *forwardingRulesRESTClient) SetLabels(ctx context.Context, req *computepb.SetLabelsForwardingRuleRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetRegionSetLabelsRequestResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/regions/%v/forwardingRules/%v/setLabels", req.GetProject(), req.GetRegion(), req.GetResource()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// SetTarget changes target URL for forwarding rule. The new target should be of the same type as the old target. +func (c *forwardingRulesRESTClient) SetTarget(ctx context.Context, req *computepb.SetTargetForwardingRuleRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetTargetReferenceResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/regions/%v/forwardingRules/%v/setTarget", req.GetProject(), req.GetRegion(), req.GetForwardingRule()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} diff --git a/compute/apiv1/forwarding_rules_client_example_test.go b/compute/apiv1/forwarding_rules_client_example_test.go new file mode 100644 index 00000000000..1a2a9a5495f --- /dev/null +++ b/compute/apiv1/forwarding_rules_client_example_test.go @@ -0,0 +1,188 @@ +// 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 compute_test + +import ( + "context" + + compute "cloud.google.com/go/compute/apiv1" + computepb "google.golang.org/genproto/googleapis/cloud/compute/v1" +) + +func ExampleNewForwardingRulesRESTClient() { + ctx := context.Background() + c, err := compute.NewForwardingRulesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + // TODO: Use client. + _ = c +} + +func ExampleForwardingRulesClient_AggregatedList() { + ctx := context.Background() + c, err := compute.NewForwardingRulesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.AggregatedListForwardingRulesRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.AggregatedList(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleForwardingRulesClient_Delete() { + ctx := context.Background() + c, err := compute.NewForwardingRulesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.DeleteForwardingRuleRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Delete(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleForwardingRulesClient_Get() { + ctx := context.Background() + c, err := compute.NewForwardingRulesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.GetForwardingRuleRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Get(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleForwardingRulesClient_Insert() { + ctx := context.Background() + c, err := compute.NewForwardingRulesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.InsertForwardingRuleRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Insert(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleForwardingRulesClient_List() { + ctx := context.Background() + c, err := compute.NewForwardingRulesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.ListForwardingRulesRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.List(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleForwardingRulesClient_Patch() { + ctx := context.Background() + c, err := compute.NewForwardingRulesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.PatchForwardingRuleRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Patch(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleForwardingRulesClient_SetLabels() { + ctx := context.Background() + c, err := compute.NewForwardingRulesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.SetLabelsForwardingRuleRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.SetLabels(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleForwardingRulesClient_SetTarget() { + ctx := context.Background() + c, err := compute.NewForwardingRulesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.SetTargetForwardingRuleRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.SetTarget(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} diff --git a/compute/apiv1/gapic_metadata.json b/compute/apiv1/gapic_metadata.json new file mode 100644 index 00000000000..6474e15ecd9 --- /dev/null +++ b/compute/apiv1/gapic_metadata.json @@ -0,0 +1,3581 @@ +{ + "schema": "1.0", + "comment": "This file maps proto services/RPCs to the corresponding library clients/methods.", + "language": "go", + "protoPackage": "google.cloud.compute.v1", + "libraryPackage": "cloud.google.com/go/compute/apiv1", + "services": { + "AcceleratorTypes": { + "clients": { + "rest": { + "libraryClient": "AcceleratorTypesClient", + "rpcs": { + "AggregatedList": { + "methods": [ + "AggregatedList" + ] + }, + "Get": { + "methods": [ + "Get" + ] + }, + "List": { + "methods": [ + "List" + ] + } + } + } + } + }, + "Addresses": { + "clients": { + "rest": { + "libraryClient": "AddressesClient", + "rpcs": { + "AggregatedList": { + "methods": [ + "AggregatedList" + ] + }, + "Delete": { + "methods": [ + "Delete" + ] + }, + "Get": { + "methods": [ + "Get" + ] + }, + "Insert": { + "methods": [ + "Insert" + ] + }, + "List": { + "methods": [ + "List" + ] + } + } + } + } + }, + "Autoscalers": { + "clients": { + "rest": { + "libraryClient": "AutoscalersClient", + "rpcs": { + "AggregatedList": { + "methods": [ + "AggregatedList" + ] + }, + "Delete": { + "methods": [ + "Delete" + ] + }, + "Get": { + "methods": [ + "Get" + ] + }, + "Insert": { + "methods": [ + "Insert" + ] + }, + "List": { + "methods": [ + "List" + ] + }, + "Patch": { + "methods": [ + "Patch" + ] + }, + "Update": { + "methods": [ + "Update" + ] + } + } + } + } + }, + "BackendBuckets": { + "clients": { + "rest": { + "libraryClient": "BackendBucketsClient", + "rpcs": { + "AddSignedUrlKey": { + "methods": [ + "AddSignedUrlKey" + ] + }, + "Delete": { + "methods": [ + "Delete" + ] + }, + "DeleteSignedUrlKey": { + "methods": [ + "DeleteSignedUrlKey" + ] + }, + "Get": { + "methods": [ + "Get" + ] + }, + "Insert": { + "methods": [ + "Insert" + ] + }, + "List": { + "methods": [ + "List" + ] + }, + "Patch": { + "methods": [ + "Patch" + ] + }, + "Update": { + "methods": [ + "Update" + ] + } + } + } + } + }, + "BackendServices": { + "clients": { + "rest": { + "libraryClient": "BackendServicesClient", + "rpcs": { + "AddSignedUrlKey": { + "methods": [ + "AddSignedUrlKey" + ] + }, + "AggregatedList": { + "methods": [ + "AggregatedList" + ] + }, + "Delete": { + "methods": [ + "Delete" + ] + }, + "DeleteSignedUrlKey": { + "methods": [ + "DeleteSignedUrlKey" + ] + }, + "Get": { + "methods": [ + "Get" + ] + }, + "GetHealth": { + "methods": [ + "GetHealth" + ] + }, + "Insert": { + "methods": [ + "Insert" + ] + }, + "List": { + "methods": [ + "List" + ] + }, + "Patch": { + "methods": [ + "Patch" + ] + }, + "SetSecurityPolicy": { + "methods": [ + "SetSecurityPolicy" + ] + }, + "Update": { + "methods": [ + "Update" + ] + } + } + } + } + }, + "DiskTypes": { + "clients": { + "rest": { + "libraryClient": "DiskTypesClient", + "rpcs": { + "AggregatedList": { + "methods": [ + "AggregatedList" + ] + }, + "Get": { + "methods": [ + "Get" + ] + }, + "List": { + "methods": [ + "List" + ] + } + } + } + } + }, + "Disks": { + "clients": { + "rest": { + "libraryClient": "DisksClient", + "rpcs": { + "AddResourcePolicies": { + "methods": [ + "AddResourcePolicies" + ] + }, + "AggregatedList": { + "methods": [ + "AggregatedList" + ] + }, + "CreateSnapshot": { + "methods": [ + "CreateSnapshot" + ] + }, + "Delete": { + "methods": [ + "Delete" + ] + }, + "Get": { + "methods": [ + "Get" + ] + }, + "GetIamPolicy": { + "methods": [ + "GetIamPolicy" + ] + }, + "Insert": { + "methods": [ + "Insert" + ] + }, + "List": { + "methods": [ + "List" + ] + }, + "RemoveResourcePolicies": { + "methods": [ + "RemoveResourcePolicies" + ] + }, + "Resize": { + "methods": [ + "Resize" + ] + }, + "SetIamPolicy": { + "methods": [ + "SetIamPolicy" + ] + }, + "SetLabels": { + "methods": [ + "SetLabels" + ] + }, + "TestIamPermissions": { + "methods": [ + "TestIamPermissions" + ] + } + } + } + } + }, + "ExternalVpnGateways": { + "clients": { + "rest": { + "libraryClient": "ExternalVpnGatewaysClient", + "rpcs": { + "Delete": { + "methods": [ + "Delete" + ] + }, + "Get": { + "methods": [ + "Get" + ] + }, + "Insert": { + "methods": [ + "Insert" + ] + }, + "List": { + "methods": [ + "List" + ] + }, + "SetLabels": { + "methods": [ + "SetLabels" + ] + }, + "TestIamPermissions": { + "methods": [ + "TestIamPermissions" + ] + } + } + } + } + }, + "FirewallPolicies": { + "clients": { + "rest": { + "libraryClient": "FirewallPoliciesClient", + "rpcs": { + "AddAssociation": { + "methods": [ + "AddAssociation" + ] + }, + "AddRule": { + "methods": [ + "AddRule" + ] + }, + "CloneRules": { + "methods": [ + "CloneRules" + ] + }, + "Delete": { + "methods": [ + "Delete" + ] + }, + "Get": { + "methods": [ + "Get" + ] + }, + "GetAssociation": { + "methods": [ + "GetAssociation" + ] + }, + "GetIamPolicy": { + "methods": [ + "GetIamPolicy" + ] + }, + "GetRule": { + "methods": [ + "GetRule" + ] + }, + "Insert": { + "methods": [ + "Insert" + ] + }, + "List": { + "methods": [ + "List" + ] + }, + "ListAssociations": { + "methods": [ + "ListAssociations" + ] + }, + "Move": { + "methods": [ + "Move" + ] + }, + "Patch": { + "methods": [ + "Patch" + ] + }, + "PatchRule": { + "methods": [ + "PatchRule" + ] + }, + "RemoveAssociation": { + "methods": [ + "RemoveAssociation" + ] + }, + "RemoveRule": { + "methods": [ + "RemoveRule" + ] + }, + "SetIamPolicy": { + "methods": [ + "SetIamPolicy" + ] + }, + "TestIamPermissions": { + "methods": [ + "TestIamPermissions" + ] + } + } + } + } + }, + "Firewalls": { + "clients": { + "rest": { + "libraryClient": "FirewallsClient", + "rpcs": { + "Delete": { + "methods": [ + "Delete" + ] + }, + "Get": { + "methods": [ + "Get" + ] + }, + "Insert": { + "methods": [ + "Insert" + ] + }, + "List": { + "methods": [ + "List" + ] + }, + "Patch": { + "methods": [ + "Patch" + ] + }, + "Update": { + "methods": [ + "Update" + ] + } + } + } + } + }, + "ForwardingRules": { + "clients": { + "rest": { + "libraryClient": "ForwardingRulesClient", + "rpcs": { + "AggregatedList": { + "methods": [ + "AggregatedList" + ] + }, + "Delete": { + "methods": [ + "Delete" + ] + }, + "Get": { + "methods": [ + "Get" + ] + }, + "Insert": { + "methods": [ + "Insert" + ] + }, + "List": { + "methods": [ + "List" + ] + }, + "Patch": { + "methods": [ + "Patch" + ] + }, + "SetLabels": { + "methods": [ + "SetLabels" + ] + }, + "SetTarget": { + "methods": [ + "SetTarget" + ] + } + } + } + } + }, + "GlobalAddresses": { + "clients": { + "rest": { + "libraryClient": "GlobalAddressesClient", + "rpcs": { + "Delete": { + "methods": [ + "Delete" + ] + }, + "Get": { + "methods": [ + "Get" + ] + }, + "Insert": { + "methods": [ + "Insert" + ] + }, + "List": { + "methods": [ + "List" + ] + } + } + } + } + }, + "GlobalForwardingRules": { + "clients": { + "rest": { + "libraryClient": "GlobalForwardingRulesClient", + "rpcs": { + "Delete": { + "methods": [ + "Delete" + ] + }, + "Get": { + "methods": [ + "Get" + ] + }, + "Insert": { + "methods": [ + "Insert" + ] + }, + "List": { + "methods": [ + "List" + ] + }, + "Patch": { + "methods": [ + "Patch" + ] + }, + "SetLabels": { + "methods": [ + "SetLabels" + ] + }, + "SetTarget": { + "methods": [ + "SetTarget" + ] + } + } + } + } + }, + "GlobalNetworkEndpointGroups": { + "clients": { + "rest": { + "libraryClient": "GlobalNetworkEndpointGroupsClient", + "rpcs": { + "AttachNetworkEndpoints": { + "methods": [ + "AttachNetworkEndpoints" + ] + }, + "Delete": { + "methods": [ + "Delete" + ] + }, + "DetachNetworkEndpoints": { + "methods": [ + "DetachNetworkEndpoints" + ] + }, + "Get": { + "methods": [ + "Get" + ] + }, + "Insert": { + "methods": [ + "Insert" + ] + }, + "List": { + "methods": [ + "List" + ] + }, + "ListNetworkEndpoints": { + "methods": [ + "ListNetworkEndpoints" + ] + } + } + } + } + }, + "GlobalOperations": { + "clients": { + "rest": { + "libraryClient": "GlobalOperationsClient", + "rpcs": { + "AggregatedList": { + "methods": [ + "AggregatedList" + ] + }, + "Delete": { + "methods": [ + "Delete" + ] + }, + "Get": { + "methods": [ + "Get" + ] + }, + "List": { + "methods": [ + "List" + ] + }, + "Wait": { + "methods": [ + "Wait" + ] + } + } + } + } + }, + "GlobalOrganizationOperations": { + "clients": { + "rest": { + "libraryClient": "GlobalOrganizationOperationsClient", + "rpcs": { + "Delete": { + "methods": [ + "Delete" + ] + }, + "Get": { + "methods": [ + "Get" + ] + }, + "List": { + "methods": [ + "List" + ] + } + } + } + } + }, + "GlobalPublicDelegatedPrefixes": { + "clients": { + "rest": { + "libraryClient": "GlobalPublicDelegatedPrefixesClient", + "rpcs": { + "Delete": { + "methods": [ + "Delete" + ] + }, + "Get": { + "methods": [ + "Get" + ] + }, + "Insert": { + "methods": [ + "Insert" + ] + }, + "List": { + "methods": [ + "List" + ] + }, + "Patch": { + "methods": [ + "Patch" + ] + } + } + } + } + }, + "HealthChecks": { + "clients": { + "rest": { + "libraryClient": "HealthChecksClient", + "rpcs": { + "AggregatedList": { + "methods": [ + "AggregatedList" + ] + }, + "Delete": { + "methods": [ + "Delete" + ] + }, + "Get": { + "methods": [ + "Get" + ] + }, + "Insert": { + "methods": [ + "Insert" + ] + }, + "List": { + "methods": [ + "List" + ] + }, + "Patch": { + "methods": [ + "Patch" + ] + }, + "Update": { + "methods": [ + "Update" + ] + } + } + } + } + }, + "Images": { + "clients": { + "rest": { + "libraryClient": "ImagesClient", + "rpcs": { + "Delete": { + "methods": [ + "Delete" + ] + }, + "Deprecate": { + "methods": [ + "Deprecate" + ] + }, + "Get": { + "methods": [ + "Get" + ] + }, + "GetFromFamily": { + "methods": [ + "GetFromFamily" + ] + }, + "GetIamPolicy": { + "methods": [ + "GetIamPolicy" + ] + }, + "Insert": { + "methods": [ + "Insert" + ] + }, + "List": { + "methods": [ + "List" + ] + }, + "Patch": { + "methods": [ + "Patch" + ] + }, + "SetIamPolicy": { + "methods": [ + "SetIamPolicy" + ] + }, + "SetLabels": { + "methods": [ + "SetLabels" + ] + }, + "TestIamPermissions": { + "methods": [ + "TestIamPermissions" + ] + } + } + } + } + }, + "InstanceGroupManagers": { + "clients": { + "rest": { + "libraryClient": "InstanceGroupManagersClient", + "rpcs": { + "AbandonInstances": { + "methods": [ + "AbandonInstances" + ] + }, + "AggregatedList": { + "methods": [ + "AggregatedList" + ] + }, + "ApplyUpdatesToInstances": { + "methods": [ + "ApplyUpdatesToInstances" + ] + }, + "CreateInstances": { + "methods": [ + "CreateInstances" + ] + }, + "Delete": { + "methods": [ + "Delete" + ] + }, + "DeleteInstances": { + "methods": [ + "DeleteInstances" + ] + }, + "DeletePerInstanceConfigs": { + "methods": [ + "DeletePerInstanceConfigs" + ] + }, + "Get": { + "methods": [ + "Get" + ] + }, + "Insert": { + "methods": [ + "Insert" + ] + }, + "List": { + "methods": [ + "List" + ] + }, + "ListErrors": { + "methods": [ + "ListErrors" + ] + }, + "ListManagedInstances": { + "methods": [ + "ListManagedInstances" + ] + }, + "ListPerInstanceConfigs": { + "methods": [ + "ListPerInstanceConfigs" + ] + }, + "Patch": { + "methods": [ + "Patch" + ] + }, + "PatchPerInstanceConfigs": { + "methods": [ + "PatchPerInstanceConfigs" + ] + }, + "RecreateInstances": { + "methods": [ + "RecreateInstances" + ] + }, + "Resize": { + "methods": [ + "Resize" + ] + }, + "SetInstanceTemplate": { + "methods": [ + "SetInstanceTemplate" + ] + }, + "SetTargetPools": { + "methods": [ + "SetTargetPools" + ] + }, + "UpdatePerInstanceConfigs": { + "methods": [ + "UpdatePerInstanceConfigs" + ] + } + } + } + } + }, + "InstanceGroups": { + "clients": { + "rest": { + "libraryClient": "InstanceGroupsClient", + "rpcs": { + "AddInstances": { + "methods": [ + "AddInstances" + ] + }, + "AggregatedList": { + "methods": [ + "AggregatedList" + ] + }, + "Delete": { + "methods": [ + "Delete" + ] + }, + "Get": { + "methods": [ + "Get" + ] + }, + "Insert": { + "methods": [ + "Insert" + ] + }, + "List": { + "methods": [ + "List" + ] + }, + "ListInstances": { + "methods": [ + "ListInstances" + ] + }, + "RemoveInstances": { + "methods": [ + "RemoveInstances" + ] + }, + "SetNamedPorts": { + "methods": [ + "SetNamedPorts" + ] + } + } + } + } + }, + "InstanceTemplates": { + "clients": { + "rest": { + "libraryClient": "InstanceTemplatesClient", + "rpcs": { + "Delete": { + "methods": [ + "Delete" + ] + }, + "Get": { + "methods": [ + "Get" + ] + }, + "GetIamPolicy": { + "methods": [ + "GetIamPolicy" + ] + }, + "Insert": { + "methods": [ + "Insert" + ] + }, + "List": { + "methods": [ + "List" + ] + }, + "SetIamPolicy": { + "methods": [ + "SetIamPolicy" + ] + }, + "TestIamPermissions": { + "methods": [ + "TestIamPermissions" + ] + } + } + } + } + }, + "Instances": { + "clients": { + "rest": { + "libraryClient": "InstancesClient", + "rpcs": { + "AddAccessConfig": { + "methods": [ + "AddAccessConfig" + ] + }, + "AddResourcePolicies": { + "methods": [ + "AddResourcePolicies" + ] + }, + "AggregatedList": { + "methods": [ + "AggregatedList" + ] + }, + "AttachDisk": { + "methods": [ + "AttachDisk" + ] + }, + "BulkInsert": { + "methods": [ + "BulkInsert" + ] + }, + "Delete": { + "methods": [ + "Delete" + ] + }, + "DeleteAccessConfig": { + "methods": [ + "DeleteAccessConfig" + ] + }, + "DetachDisk": { + "methods": [ + "DetachDisk" + ] + }, + "Get": { + "methods": [ + "Get" + ] + }, + "GetEffectiveFirewalls": { + "methods": [ + "GetEffectiveFirewalls" + ] + }, + "GetGuestAttributes": { + "methods": [ + "GetGuestAttributes" + ] + }, + "GetIamPolicy": { + "methods": [ + "GetIamPolicy" + ] + }, + "GetScreenshot": { + "methods": [ + "GetScreenshot" + ] + }, + "GetSerialPortOutput": { + "methods": [ + "GetSerialPortOutput" + ] + }, + "GetShieldedInstanceIdentity": { + "methods": [ + "GetShieldedInstanceIdentity" + ] + }, + "Insert": { + "methods": [ + "Insert" + ] + }, + "List": { + "methods": [ + "List" + ] + }, + "ListReferrers": { + "methods": [ + "ListReferrers" + ] + }, + "RemoveResourcePolicies": { + "methods": [ + "RemoveResourcePolicies" + ] + }, + "Reset": { + "methods": [ + "Reset" + ] + }, + "SetDeletionProtection": { + "methods": [ + "SetDeletionProtection" + ] + }, + "SetDiskAutoDelete": { + "methods": [ + "SetDiskAutoDelete" + ] + }, + "SetIamPolicy": { + "methods": [ + "SetIamPolicy" + ] + }, + "SetLabels": { + "methods": [ + "SetLabels" + ] + }, + "SetMachineResources": { + "methods": [ + "SetMachineResources" + ] + }, + "SetMachineType": { + "methods": [ + "SetMachineType" + ] + }, + "SetMetadata": { + "methods": [ + "SetMetadata" + ] + }, + "SetMinCpuPlatform": { + "methods": [ + "SetMinCpuPlatform" + ] + }, + "SetScheduling": { + "methods": [ + "SetScheduling" + ] + }, + "SetServiceAccount": { + "methods": [ + "SetServiceAccount" + ] + }, + "SetShieldedInstanceIntegrityPolicy": { + "methods": [ + "SetShieldedInstanceIntegrityPolicy" + ] + }, + "SetTags": { + "methods": [ + "SetTags" + ] + }, + "SimulateMaintenanceEvent": { + "methods": [ + "SimulateMaintenanceEvent" + ] + }, + "Start": { + "methods": [ + "Start" + ] + }, + "StartWithEncryptionKey": { + "methods": [ + "StartWithEncryptionKey" + ] + }, + "Stop": { + "methods": [ + "Stop" + ] + }, + "TestIamPermissions": { + "methods": [ + "TestIamPermissions" + ] + }, + "Update": { + "methods": [ + "Update" + ] + }, + "UpdateAccessConfig": { + "methods": [ + "UpdateAccessConfig" + ] + }, + "UpdateDisplayDevice": { + "methods": [ + "UpdateDisplayDevice" + ] + }, + "UpdateNetworkInterface": { + "methods": [ + "UpdateNetworkInterface" + ] + }, + "UpdateShieldedInstanceConfig": { + "methods": [ + "UpdateShieldedInstanceConfig" + ] + } + } + } + } + }, + "InterconnectAttachments": { + "clients": { + "rest": { + "libraryClient": "InterconnectAttachmentsClient", + "rpcs": { + "AggregatedList": { + "methods": [ + "AggregatedList" + ] + }, + "Delete": { + "methods": [ + "Delete" + ] + }, + "Get": { + "methods": [ + "Get" + ] + }, + "Insert": { + "methods": [ + "Insert" + ] + }, + "List": { + "methods": [ + "List" + ] + }, + "Patch": { + "methods": [ + "Patch" + ] + } + } + } + } + }, + "InterconnectLocations": { + "clients": { + "rest": { + "libraryClient": "InterconnectLocationsClient", + "rpcs": { + "Get": { + "methods": [ + "Get" + ] + }, + "List": { + "methods": [ + "List" + ] + } + } + } + } + }, + "Interconnects": { + "clients": { + "rest": { + "libraryClient": "InterconnectsClient", + "rpcs": { + "Delete": { + "methods": [ + "Delete" + ] + }, + "Get": { + "methods": [ + "Get" + ] + }, + "GetDiagnostics": { + "methods": [ + "GetDiagnostics" + ] + }, + "Insert": { + "methods": [ + "Insert" + ] + }, + "List": { + "methods": [ + "List" + ] + }, + "Patch": { + "methods": [ + "Patch" + ] + } + } + } + } + }, + "LicenseCodes": { + "clients": { + "rest": { + "libraryClient": "LicenseCodesClient", + "rpcs": { + "Get": { + "methods": [ + "Get" + ] + }, + "TestIamPermissions": { + "methods": [ + "TestIamPermissions" + ] + } + } + } + } + }, + "Licenses": { + "clients": { + "rest": { + "libraryClient": "LicensesClient", + "rpcs": { + "Delete": { + "methods": [ + "Delete" + ] + }, + "Get": { + "methods": [ + "Get" + ] + }, + "GetIamPolicy": { + "methods": [ + "GetIamPolicy" + ] + }, + "Insert": { + "methods": [ + "Insert" + ] + }, + "List": { + "methods": [ + "List" + ] + }, + "SetIamPolicy": { + "methods": [ + "SetIamPolicy" + ] + }, + "TestIamPermissions": { + "methods": [ + "TestIamPermissions" + ] + } + } + } + } + }, + "MachineTypes": { + "clients": { + "rest": { + "libraryClient": "MachineTypesClient", + "rpcs": { + "AggregatedList": { + "methods": [ + "AggregatedList" + ] + }, + "Get": { + "methods": [ + "Get" + ] + }, + "List": { + "methods": [ + "List" + ] + } + } + } + } + }, + "NetworkEndpointGroups": { + "clients": { + "rest": { + "libraryClient": "NetworkEndpointGroupsClient", + "rpcs": { + "AggregatedList": { + "methods": [ + "AggregatedList" + ] + }, + "AttachNetworkEndpoints": { + "methods": [ + "AttachNetworkEndpoints" + ] + }, + "Delete": { + "methods": [ + "Delete" + ] + }, + "DetachNetworkEndpoints": { + "methods": [ + "DetachNetworkEndpoints" + ] + }, + "Get": { + "methods": [ + "Get" + ] + }, + "Insert": { + "methods": [ + "Insert" + ] + }, + "List": { + "methods": [ + "List" + ] + }, + "ListNetworkEndpoints": { + "methods": [ + "ListNetworkEndpoints" + ] + }, + "TestIamPermissions": { + "methods": [ + "TestIamPermissions" + ] + } + } + } + } + }, + "Networks": { + "clients": { + "rest": { + "libraryClient": "NetworksClient", + "rpcs": { + "AddPeering": { + "methods": [ + "AddPeering" + ] + }, + "Delete": { + "methods": [ + "Delete" + ] + }, + "Get": { + "methods": [ + "Get" + ] + }, + "GetEffectiveFirewalls": { + "methods": [ + "GetEffectiveFirewalls" + ] + }, + "Insert": { + "methods": [ + "Insert" + ] + }, + "List": { + "methods": [ + "List" + ] + }, + "ListPeeringRoutes": { + "methods": [ + "ListPeeringRoutes" + ] + }, + "Patch": { + "methods": [ + "Patch" + ] + }, + "RemovePeering": { + "methods": [ + "RemovePeering" + ] + }, + "SwitchToCustomMode": { + "methods": [ + "SwitchToCustomMode" + ] + }, + "UpdatePeering": { + "methods": [ + "UpdatePeering" + ] + } + } + } + } + }, + "NodeGroups": { + "clients": { + "rest": { + "libraryClient": "NodeGroupsClient", + "rpcs": { + "AddNodes": { + "methods": [ + "AddNodes" + ] + }, + "AggregatedList": { + "methods": [ + "AggregatedList" + ] + }, + "Delete": { + "methods": [ + "Delete" + ] + }, + "DeleteNodes": { + "methods": [ + "DeleteNodes" + ] + }, + "Get": { + "methods": [ + "Get" + ] + }, + "GetIamPolicy": { + "methods": [ + "GetIamPolicy" + ] + }, + "Insert": { + "methods": [ + "Insert" + ] + }, + "List": { + "methods": [ + "List" + ] + }, + "ListNodes": { + "methods": [ + "ListNodes" + ] + }, + "Patch": { + "methods": [ + "Patch" + ] + }, + "SetIamPolicy": { + "methods": [ + "SetIamPolicy" + ] + }, + "SetNodeTemplate": { + "methods": [ + "SetNodeTemplate" + ] + }, + "TestIamPermissions": { + "methods": [ + "TestIamPermissions" + ] + } + } + } + } + }, + "NodeTemplates": { + "clients": { + "rest": { + "libraryClient": "NodeTemplatesClient", + "rpcs": { + "AggregatedList": { + "methods": [ + "AggregatedList" + ] + }, + "Delete": { + "methods": [ + "Delete" + ] + }, + "Get": { + "methods": [ + "Get" + ] + }, + "GetIamPolicy": { + "methods": [ + "GetIamPolicy" + ] + }, + "Insert": { + "methods": [ + "Insert" + ] + }, + "List": { + "methods": [ + "List" + ] + }, + "SetIamPolicy": { + "methods": [ + "SetIamPolicy" + ] + }, + "TestIamPermissions": { + "methods": [ + "TestIamPermissions" + ] + } + } + } + } + }, + "NodeTypes": { + "clients": { + "rest": { + "libraryClient": "NodeTypesClient", + "rpcs": { + "AggregatedList": { + "methods": [ + "AggregatedList" + ] + }, + "Get": { + "methods": [ + "Get" + ] + }, + "List": { + "methods": [ + "List" + ] + } + } + } + } + }, + "PacketMirrorings": { + "clients": { + "rest": { + "libraryClient": "PacketMirroringsClient", + "rpcs": { + "AggregatedList": { + "methods": [ + "AggregatedList" + ] + }, + "Delete": { + "methods": [ + "Delete" + ] + }, + "Get": { + "methods": [ + "Get" + ] + }, + "Insert": { + "methods": [ + "Insert" + ] + }, + "List": { + "methods": [ + "List" + ] + }, + "Patch": { + "methods": [ + "Patch" + ] + }, + "TestIamPermissions": { + "methods": [ + "TestIamPermissions" + ] + } + } + } + } + }, + "Projects": { + "clients": { + "rest": { + "libraryClient": "ProjectsClient", + "rpcs": { + "DisableXpnHost": { + "methods": [ + "DisableXpnHost" + ] + }, + "DisableXpnResource": { + "methods": [ + "DisableXpnResource" + ] + }, + "EnableXpnHost": { + "methods": [ + "EnableXpnHost" + ] + }, + "EnableXpnResource": { + "methods": [ + "EnableXpnResource" + ] + }, + "Get": { + "methods": [ + "Get" + ] + }, + "GetXpnHost": { + "methods": [ + "GetXpnHost" + ] + }, + "GetXpnResources": { + "methods": [ + "GetXpnResources" + ] + }, + "ListXpnHosts": { + "methods": [ + "ListXpnHosts" + ] + }, + "MoveDisk": { + "methods": [ + "MoveDisk" + ] + }, + "MoveInstance": { + "methods": [ + "MoveInstance" + ] + }, + "SetCommonInstanceMetadata": { + "methods": [ + "SetCommonInstanceMetadata" + ] + }, + "SetDefaultNetworkTier": { + "methods": [ + "SetDefaultNetworkTier" + ] + }, + "SetUsageExportBucket": { + "methods": [ + "SetUsageExportBucket" + ] + } + } + } + } + }, + "PublicAdvertisedPrefixes": { + "clients": { + "rest": { + "libraryClient": "PublicAdvertisedPrefixesClient", + "rpcs": { + "Delete": { + "methods": [ + "Delete" + ] + }, + "Get": { + "methods": [ + "Get" + ] + }, + "Insert": { + "methods": [ + "Insert" + ] + }, + "List": { + "methods": [ + "List" + ] + }, + "Patch": { + "methods": [ + "Patch" + ] + } + } + } + } + }, + "PublicDelegatedPrefixes": { + "clients": { + "rest": { + "libraryClient": "PublicDelegatedPrefixesClient", + "rpcs": { + "AggregatedList": { + "methods": [ + "AggregatedList" + ] + }, + "Delete": { + "methods": [ + "Delete" + ] + }, + "Get": { + "methods": [ + "Get" + ] + }, + "Insert": { + "methods": [ + "Insert" + ] + }, + "List": { + "methods": [ + "List" + ] + }, + "Patch": { + "methods": [ + "Patch" + ] + } + } + } + } + }, + "RegionAutoscalers": { + "clients": { + "rest": { + "libraryClient": "RegionAutoscalersClient", + "rpcs": { + "Delete": { + "methods": [ + "Delete" + ] + }, + "Get": { + "methods": [ + "Get" + ] + }, + "Insert": { + "methods": [ + "Insert" + ] + }, + "List": { + "methods": [ + "List" + ] + }, + "Patch": { + "methods": [ + "Patch" + ] + }, + "Update": { + "methods": [ + "Update" + ] + } + } + } + } + }, + "RegionBackendServices": { + "clients": { + "rest": { + "libraryClient": "RegionBackendServicesClient", + "rpcs": { + "Delete": { + "methods": [ + "Delete" + ] + }, + "Get": { + "methods": [ + "Get" + ] + }, + "GetHealth": { + "methods": [ + "GetHealth" + ] + }, + "Insert": { + "methods": [ + "Insert" + ] + }, + "List": { + "methods": [ + "List" + ] + }, + "Patch": { + "methods": [ + "Patch" + ] + }, + "Update": { + "methods": [ + "Update" + ] + } + } + } + } + }, + "RegionCommitments": { + "clients": { + "rest": { + "libraryClient": "RegionCommitmentsClient", + "rpcs": { + "AggregatedList": { + "methods": [ + "AggregatedList" + ] + }, + "Get": { + "methods": [ + "Get" + ] + }, + "Insert": { + "methods": [ + "Insert" + ] + }, + "List": { + "methods": [ + "List" + ] + } + } + } + } + }, + "RegionDiskTypes": { + "clients": { + "rest": { + "libraryClient": "RegionDiskTypesClient", + "rpcs": { + "Get": { + "methods": [ + "Get" + ] + }, + "List": { + "methods": [ + "List" + ] + } + } + } + } + }, + "RegionDisks": { + "clients": { + "rest": { + "libraryClient": "RegionDisksClient", + "rpcs": { + "AddResourcePolicies": { + "methods": [ + "AddResourcePolicies" + ] + }, + "CreateSnapshot": { + "methods": [ + "CreateSnapshot" + ] + }, + "Delete": { + "methods": [ + "Delete" + ] + }, + "Get": { + "methods": [ + "Get" + ] + }, + "GetIamPolicy": { + "methods": [ + "GetIamPolicy" + ] + }, + "Insert": { + "methods": [ + "Insert" + ] + }, + "List": { + "methods": [ + "List" + ] + }, + "RemoveResourcePolicies": { + "methods": [ + "RemoveResourcePolicies" + ] + }, + "Resize": { + "methods": [ + "Resize" + ] + }, + "SetIamPolicy": { + "methods": [ + "SetIamPolicy" + ] + }, + "SetLabels": { + "methods": [ + "SetLabels" + ] + }, + "TestIamPermissions": { + "methods": [ + "TestIamPermissions" + ] + } + } + } + } + }, + "RegionHealthCheckServices": { + "clients": { + "rest": { + "libraryClient": "RegionHealthCheckServicesClient", + "rpcs": { + "Delete": { + "methods": [ + "Delete" + ] + }, + "Get": { + "methods": [ + "Get" + ] + }, + "Insert": { + "methods": [ + "Insert" + ] + }, + "List": { + "methods": [ + "List" + ] + }, + "Patch": { + "methods": [ + "Patch" + ] + } + } + } + } + }, + "RegionHealthChecks": { + "clients": { + "rest": { + "libraryClient": "RegionHealthChecksClient", + "rpcs": { + "Delete": { + "methods": [ + "Delete" + ] + }, + "Get": { + "methods": [ + "Get" + ] + }, + "Insert": { + "methods": [ + "Insert" + ] + }, + "List": { + "methods": [ + "List" + ] + }, + "Patch": { + "methods": [ + "Patch" + ] + }, + "Update": { + "methods": [ + "Update" + ] + } + } + } + } + }, + "RegionInstanceGroupManagers": { + "clients": { + "rest": { + "libraryClient": "RegionInstanceGroupManagersClient", + "rpcs": { + "AbandonInstances": { + "methods": [ + "AbandonInstances" + ] + }, + "ApplyUpdatesToInstances": { + "methods": [ + "ApplyUpdatesToInstances" + ] + }, + "CreateInstances": { + "methods": [ + "CreateInstances" + ] + }, + "Delete": { + "methods": [ + "Delete" + ] + }, + "DeleteInstances": { + "methods": [ + "DeleteInstances" + ] + }, + "DeletePerInstanceConfigs": { + "methods": [ + "DeletePerInstanceConfigs" + ] + }, + "Get": { + "methods": [ + "Get" + ] + }, + "Insert": { + "methods": [ + "Insert" + ] + }, + "List": { + "methods": [ + "List" + ] + }, + "ListErrors": { + "methods": [ + "ListErrors" + ] + }, + "ListManagedInstances": { + "methods": [ + "ListManagedInstances" + ] + }, + "ListPerInstanceConfigs": { + "methods": [ + "ListPerInstanceConfigs" + ] + }, + "Patch": { + "methods": [ + "Patch" + ] + }, + "PatchPerInstanceConfigs": { + "methods": [ + "PatchPerInstanceConfigs" + ] + }, + "RecreateInstances": { + "methods": [ + "RecreateInstances" + ] + }, + "Resize": { + "methods": [ + "Resize" + ] + }, + "SetInstanceTemplate": { + "methods": [ + "SetInstanceTemplate" + ] + }, + "SetTargetPools": { + "methods": [ + "SetTargetPools" + ] + }, + "UpdatePerInstanceConfigs": { + "methods": [ + "UpdatePerInstanceConfigs" + ] + } + } + } + } + }, + "RegionInstanceGroups": { + "clients": { + "rest": { + "libraryClient": "RegionInstanceGroupsClient", + "rpcs": { + "Get": { + "methods": [ + "Get" + ] + }, + "List": { + "methods": [ + "List" + ] + }, + "ListInstances": { + "methods": [ + "ListInstances" + ] + }, + "SetNamedPorts": { + "methods": [ + "SetNamedPorts" + ] + } + } + } + } + }, + "RegionInstances": { + "clients": { + "rest": { + "libraryClient": "RegionInstancesClient", + "rpcs": { + "BulkInsert": { + "methods": [ + "BulkInsert" + ] + } + } + } + } + }, + "RegionNetworkEndpointGroups": { + "clients": { + "rest": { + "libraryClient": "RegionNetworkEndpointGroupsClient", + "rpcs": { + "Delete": { + "methods": [ + "Delete" + ] + }, + "Get": { + "methods": [ + "Get" + ] + }, + "Insert": { + "methods": [ + "Insert" + ] + }, + "List": { + "methods": [ + "List" + ] + } + } + } + } + }, + "RegionNotificationEndpoints": { + "clients": { + "rest": { + "libraryClient": "RegionNotificationEndpointsClient", + "rpcs": { + "Delete": { + "methods": [ + "Delete" + ] + }, + "Get": { + "methods": [ + "Get" + ] + }, + "Insert": { + "methods": [ + "Insert" + ] + }, + "List": { + "methods": [ + "List" + ] + } + } + } + } + }, + "RegionOperations": { + "clients": { + "rest": { + "libraryClient": "RegionOperationsClient", + "rpcs": { + "Delete": { + "methods": [ + "Delete" + ] + }, + "Get": { + "methods": [ + "Get" + ] + }, + "List": { + "methods": [ + "List" + ] + }, + "Wait": { + "methods": [ + "Wait" + ] + } + } + } + } + }, + "RegionSslCertificates": { + "clients": { + "rest": { + "libraryClient": "RegionSslCertificatesClient", + "rpcs": { + "Delete": { + "methods": [ + "Delete" + ] + }, + "Get": { + "methods": [ + "Get" + ] + }, + "Insert": { + "methods": [ + "Insert" + ] + }, + "List": { + "methods": [ + "List" + ] + } + } + } + } + }, + "RegionTargetHttpProxies": { + "clients": { + "rest": { + "libraryClient": "RegionTargetHttpProxiesClient", + "rpcs": { + "Delete": { + "methods": [ + "Delete" + ] + }, + "Get": { + "methods": [ + "Get" + ] + }, + "Insert": { + "methods": [ + "Insert" + ] + }, + "List": { + "methods": [ + "List" + ] + }, + "SetUrlMap": { + "methods": [ + "SetUrlMap" + ] + } + } + } + } + }, + "RegionTargetHttpsProxies": { + "clients": { + "rest": { + "libraryClient": "RegionTargetHttpsProxiesClient", + "rpcs": { + "Delete": { + "methods": [ + "Delete" + ] + }, + "Get": { + "methods": [ + "Get" + ] + }, + "Insert": { + "methods": [ + "Insert" + ] + }, + "List": { + "methods": [ + "List" + ] + }, + "SetSslCertificates": { + "methods": [ + "SetSslCertificates" + ] + }, + "SetUrlMap": { + "methods": [ + "SetUrlMap" + ] + } + } + } + } + }, + "RegionUrlMaps": { + "clients": { + "rest": { + "libraryClient": "RegionUrlMapsClient", + "rpcs": { + "Delete": { + "methods": [ + "Delete" + ] + }, + "Get": { + "methods": [ + "Get" + ] + }, + "Insert": { + "methods": [ + "Insert" + ] + }, + "List": { + "methods": [ + "List" + ] + }, + "Patch": { + "methods": [ + "Patch" + ] + }, + "Update": { + "methods": [ + "Update" + ] + }, + "Validate": { + "methods": [ + "Validate" + ] + } + } + } + } + }, + "Regions": { + "clients": { + "rest": { + "libraryClient": "RegionsClient", + "rpcs": { + "Get": { + "methods": [ + "Get" + ] + }, + "List": { + "methods": [ + "List" + ] + } + } + } + } + }, + "Reservations": { + "clients": { + "rest": { + "libraryClient": "ReservationsClient", + "rpcs": { + "AggregatedList": { + "methods": [ + "AggregatedList" + ] + }, + "Delete": { + "methods": [ + "Delete" + ] + }, + "Get": { + "methods": [ + "Get" + ] + }, + "GetIamPolicy": { + "methods": [ + "GetIamPolicy" + ] + }, + "Insert": { + "methods": [ + "Insert" + ] + }, + "List": { + "methods": [ + "List" + ] + }, + "Resize": { + "methods": [ + "Resize" + ] + }, + "SetIamPolicy": { + "methods": [ + "SetIamPolicy" + ] + }, + "TestIamPermissions": { + "methods": [ + "TestIamPermissions" + ] + } + } + } + } + }, + "ResourcePolicies": { + "clients": { + "rest": { + "libraryClient": "ResourcePoliciesClient", + "rpcs": { + "AggregatedList": { + "methods": [ + "AggregatedList" + ] + }, + "Delete": { + "methods": [ + "Delete" + ] + }, + "Get": { + "methods": [ + "Get" + ] + }, + "GetIamPolicy": { + "methods": [ + "GetIamPolicy" + ] + }, + "Insert": { + "methods": [ + "Insert" + ] + }, + "List": { + "methods": [ + "List" + ] + }, + "SetIamPolicy": { + "methods": [ + "SetIamPolicy" + ] + }, + "TestIamPermissions": { + "methods": [ + "TestIamPermissions" + ] + } + } + } + } + }, + "Routers": { + "clients": { + "rest": { + "libraryClient": "RoutersClient", + "rpcs": { + "AggregatedList": { + "methods": [ + "AggregatedList" + ] + }, + "Delete": { + "methods": [ + "Delete" + ] + }, + "Get": { + "methods": [ + "Get" + ] + }, + "GetNatMappingInfo": { + "methods": [ + "GetNatMappingInfo" + ] + }, + "GetRouterStatus": { + "methods": [ + "GetRouterStatus" + ] + }, + "Insert": { + "methods": [ + "Insert" + ] + }, + "List": { + "methods": [ + "List" + ] + }, + "Patch": { + "methods": [ + "Patch" + ] + }, + "Preview": { + "methods": [ + "Preview" + ] + }, + "Update": { + "methods": [ + "Update" + ] + } + } + } + } + }, + "Routes": { + "clients": { + "rest": { + "libraryClient": "RoutesClient", + "rpcs": { + "Delete": { + "methods": [ + "Delete" + ] + }, + "Get": { + "methods": [ + "Get" + ] + }, + "Insert": { + "methods": [ + "Insert" + ] + }, + "List": { + "methods": [ + "List" + ] + } + } + } + } + }, + "SecurityPolicies": { + "clients": { + "rest": { + "libraryClient": "SecurityPoliciesClient", + "rpcs": { + "AddRule": { + "methods": [ + "AddRule" + ] + }, + "Delete": { + "methods": [ + "Delete" + ] + }, + "Get": { + "methods": [ + "Get" + ] + }, + "GetRule": { + "methods": [ + "GetRule" + ] + }, + "Insert": { + "methods": [ + "Insert" + ] + }, + "List": { + "methods": [ + "List" + ] + }, + "ListPreconfiguredExpressionSets": { + "methods": [ + "ListPreconfiguredExpressionSets" + ] + }, + "Patch": { + "methods": [ + "Patch" + ] + }, + "PatchRule": { + "methods": [ + "PatchRule" + ] + }, + "RemoveRule": { + "methods": [ + "RemoveRule" + ] + } + } + } + } + }, + "Snapshots": { + "clients": { + "rest": { + "libraryClient": "SnapshotsClient", + "rpcs": { + "Delete": { + "methods": [ + "Delete" + ] + }, + "Get": { + "methods": [ + "Get" + ] + }, + "GetIamPolicy": { + "methods": [ + "GetIamPolicy" + ] + }, + "List": { + "methods": [ + "List" + ] + }, + "SetIamPolicy": { + "methods": [ + "SetIamPolicy" + ] + }, + "SetLabels": { + "methods": [ + "SetLabels" + ] + }, + "TestIamPermissions": { + "methods": [ + "TestIamPermissions" + ] + } + } + } + } + }, + "SslCertificates": { + "clients": { + "rest": { + "libraryClient": "SslCertificatesClient", + "rpcs": { + "AggregatedList": { + "methods": [ + "AggregatedList" + ] + }, + "Delete": { + "methods": [ + "Delete" + ] + }, + "Get": { + "methods": [ + "Get" + ] + }, + "Insert": { + "methods": [ + "Insert" + ] + }, + "List": { + "methods": [ + "List" + ] + } + } + } + } + }, + "SslPolicies": { + "clients": { + "rest": { + "libraryClient": "SslPoliciesClient", + "rpcs": { + "Delete": { + "methods": [ + "Delete" + ] + }, + "Get": { + "methods": [ + "Get" + ] + }, + "Insert": { + "methods": [ + "Insert" + ] + }, + "List": { + "methods": [ + "List" + ] + }, + "ListAvailableFeatures": { + "methods": [ + "ListAvailableFeatures" + ] + }, + "Patch": { + "methods": [ + "Patch" + ] + } + } + } + } + }, + "Subnetworks": { + "clients": { + "rest": { + "libraryClient": "SubnetworksClient", + "rpcs": { + "AggregatedList": { + "methods": [ + "AggregatedList" + ] + }, + "Delete": { + "methods": [ + "Delete" + ] + }, + "ExpandIpCidrRange": { + "methods": [ + "ExpandIpCidrRange" + ] + }, + "Get": { + "methods": [ + "Get" + ] + }, + "GetIamPolicy": { + "methods": [ + "GetIamPolicy" + ] + }, + "Insert": { + "methods": [ + "Insert" + ] + }, + "List": { + "methods": [ + "List" + ] + }, + "ListUsable": { + "methods": [ + "ListUsable" + ] + }, + "Patch": { + "methods": [ + "Patch" + ] + }, + "SetIamPolicy": { + "methods": [ + "SetIamPolicy" + ] + }, + "SetPrivateIpGoogleAccess": { + "methods": [ + "SetPrivateIpGoogleAccess" + ] + }, + "TestIamPermissions": { + "methods": [ + "TestIamPermissions" + ] + } + } + } + } + }, + "TargetGrpcProxies": { + "clients": { + "rest": { + "libraryClient": "TargetGrpcProxiesClient", + "rpcs": { + "Delete": { + "methods": [ + "Delete" + ] + }, + "Get": { + "methods": [ + "Get" + ] + }, + "Insert": { + "methods": [ + "Insert" + ] + }, + "List": { + "methods": [ + "List" + ] + }, + "Patch": { + "methods": [ + "Patch" + ] + } + } + } + } + }, + "TargetHttpProxies": { + "clients": { + "rest": { + "libraryClient": "TargetHttpProxiesClient", + "rpcs": { + "AggregatedList": { + "methods": [ + "AggregatedList" + ] + }, + "Delete": { + "methods": [ + "Delete" + ] + }, + "Get": { + "methods": [ + "Get" + ] + }, + "Insert": { + "methods": [ + "Insert" + ] + }, + "List": { + "methods": [ + "List" + ] + }, + "Patch": { + "methods": [ + "Patch" + ] + }, + "SetUrlMap": { + "methods": [ + "SetUrlMap" + ] + } + } + } + } + }, + "TargetHttpsProxies": { + "clients": { + "rest": { + "libraryClient": "TargetHttpsProxiesClient", + "rpcs": { + "AggregatedList": { + "methods": [ + "AggregatedList" + ] + }, + "Delete": { + "methods": [ + "Delete" + ] + }, + "Get": { + "methods": [ + "Get" + ] + }, + "Insert": { + "methods": [ + "Insert" + ] + }, + "List": { + "methods": [ + "List" + ] + }, + "Patch": { + "methods": [ + "Patch" + ] + }, + "SetQuicOverride": { + "methods": [ + "SetQuicOverride" + ] + }, + "SetSslCertificates": { + "methods": [ + "SetSslCertificates" + ] + }, + "SetSslPolicy": { + "methods": [ + "SetSslPolicy" + ] + }, + "SetUrlMap": { + "methods": [ + "SetUrlMap" + ] + } + } + } + } + }, + "TargetInstances": { + "clients": { + "rest": { + "libraryClient": "TargetInstancesClient", + "rpcs": { + "AggregatedList": { + "methods": [ + "AggregatedList" + ] + }, + "Delete": { + "methods": [ + "Delete" + ] + }, + "Get": { + "methods": [ + "Get" + ] + }, + "Insert": { + "methods": [ + "Insert" + ] + }, + "List": { + "methods": [ + "List" + ] + } + } + } + } + }, + "TargetPools": { + "clients": { + "rest": { + "libraryClient": "TargetPoolsClient", + "rpcs": { + "AddHealthCheck": { + "methods": [ + "AddHealthCheck" + ] + }, + "AddInstance": { + "methods": [ + "AddInstance" + ] + }, + "AggregatedList": { + "methods": [ + "AggregatedList" + ] + }, + "Delete": { + "methods": [ + "Delete" + ] + }, + "Get": { + "methods": [ + "Get" + ] + }, + "GetHealth": { + "methods": [ + "GetHealth" + ] + }, + "Insert": { + "methods": [ + "Insert" + ] + }, + "List": { + "methods": [ + "List" + ] + }, + "RemoveHealthCheck": { + "methods": [ + "RemoveHealthCheck" + ] + }, + "RemoveInstance": { + "methods": [ + "RemoveInstance" + ] + }, + "SetBackup": { + "methods": [ + "SetBackup" + ] + } + } + } + } + }, + "TargetSslProxies": { + "clients": { + "rest": { + "libraryClient": "TargetSslProxiesClient", + "rpcs": { + "Delete": { + "methods": [ + "Delete" + ] + }, + "Get": { + "methods": [ + "Get" + ] + }, + "Insert": { + "methods": [ + "Insert" + ] + }, + "List": { + "methods": [ + "List" + ] + }, + "SetBackendService": { + "methods": [ + "SetBackendService" + ] + }, + "SetProxyHeader": { + "methods": [ + "SetProxyHeader" + ] + }, + "SetSslCertificates": { + "methods": [ + "SetSslCertificates" + ] + }, + "SetSslPolicy": { + "methods": [ + "SetSslPolicy" + ] + } + } + } + } + }, + "TargetTcpProxies": { + "clients": { + "rest": { + "libraryClient": "TargetTcpProxiesClient", + "rpcs": { + "Delete": { + "methods": [ + "Delete" + ] + }, + "Get": { + "methods": [ + "Get" + ] + }, + "Insert": { + "methods": [ + "Insert" + ] + }, + "List": { + "methods": [ + "List" + ] + }, + "SetBackendService": { + "methods": [ + "SetBackendService" + ] + }, + "SetProxyHeader": { + "methods": [ + "SetProxyHeader" + ] + } + } + } + } + }, + "TargetVpnGateways": { + "clients": { + "rest": { + "libraryClient": "TargetVpnGatewaysClient", + "rpcs": { + "AggregatedList": { + "methods": [ + "AggregatedList" + ] + }, + "Delete": { + "methods": [ + "Delete" + ] + }, + "Get": { + "methods": [ + "Get" + ] + }, + "Insert": { + "methods": [ + "Insert" + ] + }, + "List": { + "methods": [ + "List" + ] + } + } + } + } + }, + "UrlMaps": { + "clients": { + "rest": { + "libraryClient": "UrlMapsClient", + "rpcs": { + "AggregatedList": { + "methods": [ + "AggregatedList" + ] + }, + "Delete": { + "methods": [ + "Delete" + ] + }, + "Get": { + "methods": [ + "Get" + ] + }, + "Insert": { + "methods": [ + "Insert" + ] + }, + "InvalidateCache": { + "methods": [ + "InvalidateCache" + ] + }, + "List": { + "methods": [ + "List" + ] + }, + "Patch": { + "methods": [ + "Patch" + ] + }, + "Update": { + "methods": [ + "Update" + ] + }, + "Validate": { + "methods": [ + "Validate" + ] + } + } + } + } + }, + "VpnGateways": { + "clients": { + "rest": { + "libraryClient": "VpnGatewaysClient", + "rpcs": { + "AggregatedList": { + "methods": [ + "AggregatedList" + ] + }, + "Delete": { + "methods": [ + "Delete" + ] + }, + "Get": { + "methods": [ + "Get" + ] + }, + "GetStatus": { + "methods": [ + "GetStatus" + ] + }, + "Insert": { + "methods": [ + "Insert" + ] + }, + "List": { + "methods": [ + "List" + ] + }, + "SetLabels": { + "methods": [ + "SetLabels" + ] + }, + "TestIamPermissions": { + "methods": [ + "TestIamPermissions" + ] + } + } + } + } + }, + "VpnTunnels": { + "clients": { + "rest": { + "libraryClient": "VpnTunnelsClient", + "rpcs": { + "AggregatedList": { + "methods": [ + "AggregatedList" + ] + }, + "Delete": { + "methods": [ + "Delete" + ] + }, + "Get": { + "methods": [ + "Get" + ] + }, + "Insert": { + "methods": [ + "Insert" + ] + }, + "List": { + "methods": [ + "List" + ] + } + } + } + } + }, + "ZoneOperations": { + "clients": { + "rest": { + "libraryClient": "ZoneOperationsClient", + "rpcs": { + "Delete": { + "methods": [ + "Delete" + ] + }, + "Get": { + "methods": [ + "Get" + ] + }, + "List": { + "methods": [ + "List" + ] + }, + "Wait": { + "methods": [ + "Wait" + ] + } + } + } + } + }, + "Zones": { + "clients": { + "rest": { + "libraryClient": "ZonesClient", + "rpcs": { + "Get": { + "methods": [ + "Get" + ] + }, + "List": { + "methods": [ + "List" + ] + } + } + } + } + } + } +} diff --git a/compute/apiv1/global_addresses_client.go b/compute/apiv1/global_addresses_client.go new file mode 100644 index 00000000000..cc877465301 --- /dev/null +++ b/compute/apiv1/global_addresses_client.go @@ -0,0 +1,380 @@ +// 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 compute + +import ( + "bytes" + "context" + "fmt" + "io/ioutil" + "net/http" + "net/url" + + gax "github.com/googleapis/gax-go/v2" + "google.golang.org/api/option" + "google.golang.org/api/option/internaloption" + httptransport "google.golang.org/api/transport/http" + computepb "google.golang.org/genproto/googleapis/cloud/compute/v1" + "google.golang.org/grpc" + "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/encoding/protojson" +) + +var newGlobalAddressesClientHook clientHook + +// GlobalAddressesCallOptions contains the retry settings for each method of GlobalAddressesClient. +type GlobalAddressesCallOptions struct { + Delete []gax.CallOption + Get []gax.CallOption + Insert []gax.CallOption + List []gax.CallOption +} + +// internalGlobalAddressesClient is an interface that defines the methods availaible from Google Compute Engine API. +type internalGlobalAddressesClient interface { + Close() error + setGoogleClientInfo(...string) + Connection() *grpc.ClientConn + Delete(context.Context, *computepb.DeleteGlobalAddressRequest, ...gax.CallOption) (*computepb.Operation, error) + Get(context.Context, *computepb.GetGlobalAddressRequest, ...gax.CallOption) (*computepb.Address, error) + Insert(context.Context, *computepb.InsertGlobalAddressRequest, ...gax.CallOption) (*computepb.Operation, error) + List(context.Context, *computepb.ListGlobalAddressesRequest, ...gax.CallOption) (*computepb.AddressList, error) +} + +// GlobalAddressesClient is a client for interacting with Google Compute Engine API. +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +// +// The GlobalAddresses API. +type GlobalAddressesClient struct { + // The internal transport-dependent client. + internalClient internalGlobalAddressesClient + + // The call options for this service. + CallOptions *GlobalAddressesCallOptions +} + +// 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 *GlobalAddressesClient) 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 *GlobalAddressesClient) setGoogleClientInfo(keyval ...string) { + c.internalClient.setGoogleClientInfo(keyval...) +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *GlobalAddressesClient) Connection() *grpc.ClientConn { + return c.internalClient.Connection() +} + +// Delete deletes the specified address resource. +func (c *GlobalAddressesClient) Delete(ctx context.Context, req *computepb.DeleteGlobalAddressRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.Delete(ctx, req, opts...) +} + +// Get returns the specified address resource. Gets a list of available addresses by making a list() request. +func (c *GlobalAddressesClient) Get(ctx context.Context, req *computepb.GetGlobalAddressRequest, opts ...gax.CallOption) (*computepb.Address, error) { + return c.internalClient.Get(ctx, req, opts...) +} + +// Insert creates an address resource in the specified project by using the data included in the request. +func (c *GlobalAddressesClient) Insert(ctx context.Context, req *computepb.InsertGlobalAddressRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.Insert(ctx, req, opts...) +} + +// List retrieves a list of global addresses. +func (c *GlobalAddressesClient) List(ctx context.Context, req *computepb.ListGlobalAddressesRequest, opts ...gax.CallOption) (*computepb.AddressList, error) { + return c.internalClient.List(ctx, req, opts...) +} + +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +type globalAddressesRESTClient struct { + // The http endpoint to connect to. + endpoint string + + // The http client. + httpClient *http.Client + + // The x-goog-* metadata to be sent with each request. + xGoogMetadata metadata.MD +} + +// NewGlobalAddressesRESTClient creates a new global addresses rest client. +// +// The GlobalAddresses API. +func NewGlobalAddressesRESTClient(ctx context.Context, opts ...option.ClientOption) (*GlobalAddressesClient, error) { + clientOpts := append(defaultGlobalAddressesRESTClientOptions(), opts...) + httpClient, endpoint, err := httptransport.NewClient(ctx, clientOpts...) + if err != nil { + return nil, err + } + + c := &globalAddressesRESTClient{ + endpoint: endpoint, + httpClient: httpClient, + } + c.setGoogleClientInfo() + + return &GlobalAddressesClient{internalClient: c, CallOptions: &GlobalAddressesCallOptions{}}, nil +} + +func defaultGlobalAddressesRESTClientOptions() []option.ClientOption { + return []option.ClientOption{ + internaloption.WithDefaultEndpoint("compute.googleapis.com"), + internaloption.WithDefaultMTLSEndpoint("compute.mtls.googleapis.com"), + internaloption.WithDefaultAudience("https://compute.googleapis.com/"), + internaloption.WithDefaultScopes(DefaultAuthScopes()...), + } +} + +// 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 *globalAddressesRESTClient) setGoogleClientInfo(keyval ...string) { + kv := append([]string{"gl-go", versionGo()}, keyval...) + kv = append(kv, "gapic", versionClient, "gax", gax.Version, "rest", "UNKNOWN") + 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 *globalAddressesRESTClient) Close() error { + // Replace httpClient with nil to force cleanup. + c.httpClient = nil + return nil +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *globalAddressesRESTClient) Connection() *grpc.ClientConn { + return nil +} + +// Delete deletes the specified address resource. +func (c *globalAddressesRESTClient) Delete(ctx context.Context, req *computepb.DeleteGlobalAddressRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/addresses/%v", req.GetProject(), req.GetAddress()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("DELETE", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Get returns the specified address resource. Gets a list of available addresses by making a list() request. +func (c *globalAddressesRESTClient) Get(ctx context.Context, req *computepb.GetGlobalAddressRequest, opts ...gax.CallOption) (*computepb.Address, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/addresses/%v", req.GetProject(), req.GetAddress()) + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Address{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Insert creates an address resource in the specified project by using the data included in the request. +func (c *globalAddressesRESTClient) Insert(ctx context.Context, req *computepb.InsertGlobalAddressRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetAddressResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/addresses", req.GetProject()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// List retrieves a list of global addresses. +func (c *globalAddressesRESTClient) List(ctx context.Context, req *computepb.ListGlobalAddressesRequest, opts ...gax.CallOption) (*computepb.AddressList, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/addresses", req.GetProject()) + + params := url.Values{} + if req != nil && req.Filter != nil { + params.Add("filter", fmt.Sprintf("%v", req.GetFilter())) + } + if req != nil && req.MaxResults != nil { + params.Add("maxResults", fmt.Sprintf("%v", req.GetMaxResults())) + } + if req != nil && req.OrderBy != nil { + params.Add("orderBy", fmt.Sprintf("%v", req.GetOrderBy())) + } + if req != nil && req.PageToken != nil { + params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) + } + if req != nil && req.ReturnPartialSuccess != nil { + params.Add("returnPartialSuccess", fmt.Sprintf("%v", req.GetReturnPartialSuccess())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.AddressList{} + + return rsp, unm.Unmarshal(buf, rsp) +} diff --git a/compute/apiv1/global_addresses_client_example_test.go b/compute/apiv1/global_addresses_client_example_test.go new file mode 100644 index 00000000000..a226879e957 --- /dev/null +++ b/compute/apiv1/global_addresses_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 compute_test + +import ( + "context" + + compute "cloud.google.com/go/compute/apiv1" + computepb "google.golang.org/genproto/googleapis/cloud/compute/v1" +) + +func ExampleNewGlobalAddressesRESTClient() { + ctx := context.Background() + c, err := compute.NewGlobalAddressesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + // TODO: Use client. + _ = c +} + +func ExampleGlobalAddressesClient_Delete() { + ctx := context.Background() + c, err := compute.NewGlobalAddressesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.DeleteGlobalAddressRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Delete(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleGlobalAddressesClient_Get() { + ctx := context.Background() + c, err := compute.NewGlobalAddressesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.GetGlobalAddressRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Get(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleGlobalAddressesClient_Insert() { + ctx := context.Background() + c, err := compute.NewGlobalAddressesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.InsertGlobalAddressRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Insert(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleGlobalAddressesClient_List() { + ctx := context.Background() + c, err := compute.NewGlobalAddressesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.ListGlobalAddressesRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.List(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} diff --git a/compute/apiv1/global_forwarding_rules_client.go b/compute/apiv1/global_forwarding_rules_client.go new file mode 100644 index 00000000000..31126501041 --- /dev/null +++ b/compute/apiv1/global_forwarding_rules_client.go @@ -0,0 +1,547 @@ +// 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 compute + +import ( + "bytes" + "context" + "fmt" + "io/ioutil" + "net/http" + "net/url" + + gax "github.com/googleapis/gax-go/v2" + "google.golang.org/api/option" + "google.golang.org/api/option/internaloption" + httptransport "google.golang.org/api/transport/http" + computepb "google.golang.org/genproto/googleapis/cloud/compute/v1" + "google.golang.org/grpc" + "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/encoding/protojson" +) + +var newGlobalForwardingRulesClientHook clientHook + +// GlobalForwardingRulesCallOptions contains the retry settings for each method of GlobalForwardingRulesClient. +type GlobalForwardingRulesCallOptions struct { + Delete []gax.CallOption + Get []gax.CallOption + Insert []gax.CallOption + List []gax.CallOption + Patch []gax.CallOption + SetLabels []gax.CallOption + SetTarget []gax.CallOption +} + +// internalGlobalForwardingRulesClient is an interface that defines the methods availaible from Google Compute Engine API. +type internalGlobalForwardingRulesClient interface { + Close() error + setGoogleClientInfo(...string) + Connection() *grpc.ClientConn + Delete(context.Context, *computepb.DeleteGlobalForwardingRuleRequest, ...gax.CallOption) (*computepb.Operation, error) + Get(context.Context, *computepb.GetGlobalForwardingRuleRequest, ...gax.CallOption) (*computepb.ForwardingRule, error) + Insert(context.Context, *computepb.InsertGlobalForwardingRuleRequest, ...gax.CallOption) (*computepb.Operation, error) + List(context.Context, *computepb.ListGlobalForwardingRulesRequest, ...gax.CallOption) (*computepb.ForwardingRuleList, error) + Patch(context.Context, *computepb.PatchGlobalForwardingRuleRequest, ...gax.CallOption) (*computepb.Operation, error) + SetLabels(context.Context, *computepb.SetLabelsGlobalForwardingRuleRequest, ...gax.CallOption) (*computepb.Operation, error) + SetTarget(context.Context, *computepb.SetTargetGlobalForwardingRuleRequest, ...gax.CallOption) (*computepb.Operation, error) +} + +// GlobalForwardingRulesClient is a client for interacting with Google Compute Engine API. +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +// +// The GlobalForwardingRules API. +type GlobalForwardingRulesClient struct { + // The internal transport-dependent client. + internalClient internalGlobalForwardingRulesClient + + // The call options for this service. + CallOptions *GlobalForwardingRulesCallOptions +} + +// 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 *GlobalForwardingRulesClient) 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 *GlobalForwardingRulesClient) setGoogleClientInfo(keyval ...string) { + c.internalClient.setGoogleClientInfo(keyval...) +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *GlobalForwardingRulesClient) Connection() *grpc.ClientConn { + return c.internalClient.Connection() +} + +// Delete deletes the specified GlobalForwardingRule resource. +func (c *GlobalForwardingRulesClient) Delete(ctx context.Context, req *computepb.DeleteGlobalForwardingRuleRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.Delete(ctx, req, opts...) +} + +// Get returns the specified GlobalForwardingRule resource. Gets a list of available forwarding rules by making a list() request. +func (c *GlobalForwardingRulesClient) Get(ctx context.Context, req *computepb.GetGlobalForwardingRuleRequest, opts ...gax.CallOption) (*computepb.ForwardingRule, error) { + return c.internalClient.Get(ctx, req, opts...) +} + +// Insert creates a GlobalForwardingRule resource in the specified project using the data included in the request. +func (c *GlobalForwardingRulesClient) Insert(ctx context.Context, req *computepb.InsertGlobalForwardingRuleRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.Insert(ctx, req, opts...) +} + +// List retrieves a list of GlobalForwardingRule resources available to the specified project. +func (c *GlobalForwardingRulesClient) List(ctx context.Context, req *computepb.ListGlobalForwardingRulesRequest, opts ...gax.CallOption) (*computepb.ForwardingRuleList, error) { + return c.internalClient.List(ctx, req, opts...) +} + +// Patch updates the specified forwarding rule with the data included in the request. This method supports PATCH semantics and uses the JSON merge patch format and processing rules. Currently, you can only patch the network_tier field. +func (c *GlobalForwardingRulesClient) Patch(ctx context.Context, req *computepb.PatchGlobalForwardingRuleRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.Patch(ctx, req, opts...) +} + +// SetLabels sets the labels on the specified resource. To learn more about labels, read the Labeling Resources documentation. +func (c *GlobalForwardingRulesClient) SetLabels(ctx context.Context, req *computepb.SetLabelsGlobalForwardingRuleRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.SetLabels(ctx, req, opts...) +} + +// SetTarget changes target URL for the GlobalForwardingRule resource. The new target should be of the same type as the old target. +func (c *GlobalForwardingRulesClient) SetTarget(ctx context.Context, req *computepb.SetTargetGlobalForwardingRuleRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.SetTarget(ctx, req, opts...) +} + +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +type globalForwardingRulesRESTClient struct { + // The http endpoint to connect to. + endpoint string + + // The http client. + httpClient *http.Client + + // The x-goog-* metadata to be sent with each request. + xGoogMetadata metadata.MD +} + +// NewGlobalForwardingRulesRESTClient creates a new global forwarding rules rest client. +// +// The GlobalForwardingRules API. +func NewGlobalForwardingRulesRESTClient(ctx context.Context, opts ...option.ClientOption) (*GlobalForwardingRulesClient, error) { + clientOpts := append(defaultGlobalForwardingRulesRESTClientOptions(), opts...) + httpClient, endpoint, err := httptransport.NewClient(ctx, clientOpts...) + if err != nil { + return nil, err + } + + c := &globalForwardingRulesRESTClient{ + endpoint: endpoint, + httpClient: httpClient, + } + c.setGoogleClientInfo() + + return &GlobalForwardingRulesClient{internalClient: c, CallOptions: &GlobalForwardingRulesCallOptions{}}, nil +} + +func defaultGlobalForwardingRulesRESTClientOptions() []option.ClientOption { + return []option.ClientOption{ + internaloption.WithDefaultEndpoint("compute.googleapis.com"), + internaloption.WithDefaultMTLSEndpoint("compute.mtls.googleapis.com"), + internaloption.WithDefaultAudience("https://compute.googleapis.com/"), + internaloption.WithDefaultScopes(DefaultAuthScopes()...), + } +} + +// 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 *globalForwardingRulesRESTClient) setGoogleClientInfo(keyval ...string) { + kv := append([]string{"gl-go", versionGo()}, keyval...) + kv = append(kv, "gapic", versionClient, "gax", gax.Version, "rest", "UNKNOWN") + 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 *globalForwardingRulesRESTClient) Close() error { + // Replace httpClient with nil to force cleanup. + c.httpClient = nil + return nil +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *globalForwardingRulesRESTClient) Connection() *grpc.ClientConn { + return nil +} + +// Delete deletes the specified GlobalForwardingRule resource. +func (c *globalForwardingRulesRESTClient) Delete(ctx context.Context, req *computepb.DeleteGlobalForwardingRuleRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/forwardingRules/%v", req.GetProject(), req.GetForwardingRule()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("DELETE", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Get returns the specified GlobalForwardingRule resource. Gets a list of available forwarding rules by making a list() request. +func (c *globalForwardingRulesRESTClient) Get(ctx context.Context, req *computepb.GetGlobalForwardingRuleRequest, opts ...gax.CallOption) (*computepb.ForwardingRule, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/forwardingRules/%v", req.GetProject(), req.GetForwardingRule()) + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.ForwardingRule{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Insert creates a GlobalForwardingRule resource in the specified project using the data included in the request. +func (c *globalForwardingRulesRESTClient) Insert(ctx context.Context, req *computepb.InsertGlobalForwardingRuleRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetForwardingRuleResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/forwardingRules", req.GetProject()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// List retrieves a list of GlobalForwardingRule resources available to the specified project. +func (c *globalForwardingRulesRESTClient) List(ctx context.Context, req *computepb.ListGlobalForwardingRulesRequest, opts ...gax.CallOption) (*computepb.ForwardingRuleList, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/forwardingRules", req.GetProject()) + + params := url.Values{} + if req != nil && req.Filter != nil { + params.Add("filter", fmt.Sprintf("%v", req.GetFilter())) + } + if req != nil && req.MaxResults != nil { + params.Add("maxResults", fmt.Sprintf("%v", req.GetMaxResults())) + } + if req != nil && req.OrderBy != nil { + params.Add("orderBy", fmt.Sprintf("%v", req.GetOrderBy())) + } + if req != nil && req.PageToken != nil { + params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) + } + if req != nil && req.ReturnPartialSuccess != nil { + params.Add("returnPartialSuccess", fmt.Sprintf("%v", req.GetReturnPartialSuccess())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.ForwardingRuleList{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Patch updates the specified forwarding rule with the data included in the request. This method supports PATCH semantics and uses the JSON merge patch format and processing rules. Currently, you can only patch the network_tier field. +func (c *globalForwardingRulesRESTClient) Patch(ctx context.Context, req *computepb.PatchGlobalForwardingRuleRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetForwardingRuleResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/forwardingRules/%v", req.GetProject(), req.GetForwardingRule()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("PATCH", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// SetLabels sets the labels on the specified resource. To learn more about labels, read the Labeling Resources documentation. +func (c *globalForwardingRulesRESTClient) SetLabels(ctx context.Context, req *computepb.SetLabelsGlobalForwardingRuleRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetGlobalSetLabelsRequestResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/forwardingRules/%v/setLabels", req.GetProject(), req.GetResource()) + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// SetTarget changes target URL for the GlobalForwardingRule resource. The new target should be of the same type as the old target. +func (c *globalForwardingRulesRESTClient) SetTarget(ctx context.Context, req *computepb.SetTargetGlobalForwardingRuleRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetTargetReferenceResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/forwardingRules/%v/setTarget", req.GetProject(), req.GetForwardingRule()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} diff --git a/compute/apiv1/global_forwarding_rules_client_example_test.go b/compute/apiv1/global_forwarding_rules_client_example_test.go new file mode 100644 index 00000000000..13f8bce3d6b --- /dev/null +++ b/compute/apiv1/global_forwarding_rules_client_example_test.go @@ -0,0 +1,169 @@ +// 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 compute_test + +import ( + "context" + + compute "cloud.google.com/go/compute/apiv1" + computepb "google.golang.org/genproto/googleapis/cloud/compute/v1" +) + +func ExampleNewGlobalForwardingRulesRESTClient() { + ctx := context.Background() + c, err := compute.NewGlobalForwardingRulesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + // TODO: Use client. + _ = c +} + +func ExampleGlobalForwardingRulesClient_Delete() { + ctx := context.Background() + c, err := compute.NewGlobalForwardingRulesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.DeleteGlobalForwardingRuleRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Delete(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleGlobalForwardingRulesClient_Get() { + ctx := context.Background() + c, err := compute.NewGlobalForwardingRulesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.GetGlobalForwardingRuleRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Get(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleGlobalForwardingRulesClient_Insert() { + ctx := context.Background() + c, err := compute.NewGlobalForwardingRulesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.InsertGlobalForwardingRuleRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Insert(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleGlobalForwardingRulesClient_List() { + ctx := context.Background() + c, err := compute.NewGlobalForwardingRulesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.ListGlobalForwardingRulesRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.List(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleGlobalForwardingRulesClient_Patch() { + ctx := context.Background() + c, err := compute.NewGlobalForwardingRulesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.PatchGlobalForwardingRuleRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Patch(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleGlobalForwardingRulesClient_SetLabels() { + ctx := context.Background() + c, err := compute.NewGlobalForwardingRulesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.SetLabelsGlobalForwardingRuleRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.SetLabels(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleGlobalForwardingRulesClient_SetTarget() { + ctx := context.Background() + c, err := compute.NewGlobalForwardingRulesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.SetTargetGlobalForwardingRuleRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.SetTarget(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} diff --git a/compute/apiv1/global_network_endpoint_groups_client.go b/compute/apiv1/global_network_endpoint_groups_client.go new file mode 100644 index 00000000000..54f22cccf5d --- /dev/null +++ b/compute/apiv1/global_network_endpoint_groups_client.go @@ -0,0 +1,565 @@ +// 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 compute + +import ( + "bytes" + "context" + "fmt" + "io/ioutil" + "net/http" + "net/url" + + gax "github.com/googleapis/gax-go/v2" + "google.golang.org/api/option" + "google.golang.org/api/option/internaloption" + httptransport "google.golang.org/api/transport/http" + computepb "google.golang.org/genproto/googleapis/cloud/compute/v1" + "google.golang.org/grpc" + "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/encoding/protojson" +) + +var newGlobalNetworkEndpointGroupsClientHook clientHook + +// GlobalNetworkEndpointGroupsCallOptions contains the retry settings for each method of GlobalNetworkEndpointGroupsClient. +type GlobalNetworkEndpointGroupsCallOptions struct { + AttachNetworkEndpoints []gax.CallOption + Delete []gax.CallOption + DetachNetworkEndpoints []gax.CallOption + Get []gax.CallOption + Insert []gax.CallOption + List []gax.CallOption + ListNetworkEndpoints []gax.CallOption +} + +// internalGlobalNetworkEndpointGroupsClient is an interface that defines the methods availaible from Google Compute Engine API. +type internalGlobalNetworkEndpointGroupsClient interface { + Close() error + setGoogleClientInfo(...string) + Connection() *grpc.ClientConn + AttachNetworkEndpoints(context.Context, *computepb.AttachNetworkEndpointsGlobalNetworkEndpointGroupRequest, ...gax.CallOption) (*computepb.Operation, error) + Delete(context.Context, *computepb.DeleteGlobalNetworkEndpointGroupRequest, ...gax.CallOption) (*computepb.Operation, error) + DetachNetworkEndpoints(context.Context, *computepb.DetachNetworkEndpointsGlobalNetworkEndpointGroupRequest, ...gax.CallOption) (*computepb.Operation, error) + Get(context.Context, *computepb.GetGlobalNetworkEndpointGroupRequest, ...gax.CallOption) (*computepb.NetworkEndpointGroup, error) + Insert(context.Context, *computepb.InsertGlobalNetworkEndpointGroupRequest, ...gax.CallOption) (*computepb.Operation, error) + List(context.Context, *computepb.ListGlobalNetworkEndpointGroupsRequest, ...gax.CallOption) (*computepb.NetworkEndpointGroupList, error) + ListNetworkEndpoints(context.Context, *computepb.ListNetworkEndpointsGlobalNetworkEndpointGroupsRequest, ...gax.CallOption) (*computepb.NetworkEndpointGroupsListNetworkEndpoints, error) +} + +// GlobalNetworkEndpointGroupsClient is a client for interacting with Google Compute Engine API. +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +// +// The GlobalNetworkEndpointGroups API. +type GlobalNetworkEndpointGroupsClient struct { + // The internal transport-dependent client. + internalClient internalGlobalNetworkEndpointGroupsClient + + // The call options for this service. + CallOptions *GlobalNetworkEndpointGroupsCallOptions +} + +// 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 *GlobalNetworkEndpointGroupsClient) 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 *GlobalNetworkEndpointGroupsClient) setGoogleClientInfo(keyval ...string) { + c.internalClient.setGoogleClientInfo(keyval...) +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *GlobalNetworkEndpointGroupsClient) Connection() *grpc.ClientConn { + return c.internalClient.Connection() +} + +// AttachNetworkEndpoints attach a network endpoint to the specified network endpoint group. +func (c *GlobalNetworkEndpointGroupsClient) AttachNetworkEndpoints(ctx context.Context, req *computepb.AttachNetworkEndpointsGlobalNetworkEndpointGroupRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.AttachNetworkEndpoints(ctx, req, opts...) +} + +// Delete deletes the specified network endpoint group.Note that the NEG cannot be deleted if there are backend services referencing it. +func (c *GlobalNetworkEndpointGroupsClient) Delete(ctx context.Context, req *computepb.DeleteGlobalNetworkEndpointGroupRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.Delete(ctx, req, opts...) +} + +// DetachNetworkEndpoints detach the network endpoint from the specified network endpoint group. +func (c *GlobalNetworkEndpointGroupsClient) DetachNetworkEndpoints(ctx context.Context, req *computepb.DetachNetworkEndpointsGlobalNetworkEndpointGroupRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.DetachNetworkEndpoints(ctx, req, opts...) +} + +// Get returns the specified network endpoint group. Gets a list of available network endpoint groups by making a list() request. +func (c *GlobalNetworkEndpointGroupsClient) Get(ctx context.Context, req *computepb.GetGlobalNetworkEndpointGroupRequest, opts ...gax.CallOption) (*computepb.NetworkEndpointGroup, error) { + return c.internalClient.Get(ctx, req, opts...) +} + +// Insert creates a network endpoint group in the specified project using the parameters that are included in the request. +func (c *GlobalNetworkEndpointGroupsClient) Insert(ctx context.Context, req *computepb.InsertGlobalNetworkEndpointGroupRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.Insert(ctx, req, opts...) +} + +// List retrieves the list of network endpoint groups that are located in the specified project. +func (c *GlobalNetworkEndpointGroupsClient) List(ctx context.Context, req *computepb.ListGlobalNetworkEndpointGroupsRequest, opts ...gax.CallOption) (*computepb.NetworkEndpointGroupList, error) { + return c.internalClient.List(ctx, req, opts...) +} + +// ListNetworkEndpoints lists the network endpoints in the specified network endpoint group. +func (c *GlobalNetworkEndpointGroupsClient) ListNetworkEndpoints(ctx context.Context, req *computepb.ListNetworkEndpointsGlobalNetworkEndpointGroupsRequest, opts ...gax.CallOption) (*computepb.NetworkEndpointGroupsListNetworkEndpoints, error) { + return c.internalClient.ListNetworkEndpoints(ctx, req, opts...) +} + +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +type globalNetworkEndpointGroupsRESTClient struct { + // The http endpoint to connect to. + endpoint string + + // The http client. + httpClient *http.Client + + // The x-goog-* metadata to be sent with each request. + xGoogMetadata metadata.MD +} + +// NewGlobalNetworkEndpointGroupsRESTClient creates a new global network endpoint groups rest client. +// +// The GlobalNetworkEndpointGroups API. +func NewGlobalNetworkEndpointGroupsRESTClient(ctx context.Context, opts ...option.ClientOption) (*GlobalNetworkEndpointGroupsClient, error) { + clientOpts := append(defaultGlobalNetworkEndpointGroupsRESTClientOptions(), opts...) + httpClient, endpoint, err := httptransport.NewClient(ctx, clientOpts...) + if err != nil { + return nil, err + } + + c := &globalNetworkEndpointGroupsRESTClient{ + endpoint: endpoint, + httpClient: httpClient, + } + c.setGoogleClientInfo() + + return &GlobalNetworkEndpointGroupsClient{internalClient: c, CallOptions: &GlobalNetworkEndpointGroupsCallOptions{}}, nil +} + +func defaultGlobalNetworkEndpointGroupsRESTClientOptions() []option.ClientOption { + return []option.ClientOption{ + internaloption.WithDefaultEndpoint("compute.googleapis.com"), + internaloption.WithDefaultMTLSEndpoint("compute.mtls.googleapis.com"), + internaloption.WithDefaultAudience("https://compute.googleapis.com/"), + internaloption.WithDefaultScopes(DefaultAuthScopes()...), + } +} + +// 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 *globalNetworkEndpointGroupsRESTClient) setGoogleClientInfo(keyval ...string) { + kv := append([]string{"gl-go", versionGo()}, keyval...) + kv = append(kv, "gapic", versionClient, "gax", gax.Version, "rest", "UNKNOWN") + 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 *globalNetworkEndpointGroupsRESTClient) Close() error { + // Replace httpClient with nil to force cleanup. + c.httpClient = nil + return nil +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *globalNetworkEndpointGroupsRESTClient) Connection() *grpc.ClientConn { + return nil +} + +// AttachNetworkEndpoints attach a network endpoint to the specified network endpoint group. +func (c *globalNetworkEndpointGroupsRESTClient) AttachNetworkEndpoints(ctx context.Context, req *computepb.AttachNetworkEndpointsGlobalNetworkEndpointGroupRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetGlobalNetworkEndpointGroupsAttachEndpointsRequestResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/networkEndpointGroups/%v/attachNetworkEndpoints", req.GetProject(), req.GetNetworkEndpointGroup()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Delete deletes the specified network endpoint group.Note that the NEG cannot be deleted if there are backend services referencing it. +func (c *globalNetworkEndpointGroupsRESTClient) Delete(ctx context.Context, req *computepb.DeleteGlobalNetworkEndpointGroupRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/networkEndpointGroups/%v", req.GetProject(), req.GetNetworkEndpointGroup()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("DELETE", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// DetachNetworkEndpoints detach the network endpoint from the specified network endpoint group. +func (c *globalNetworkEndpointGroupsRESTClient) DetachNetworkEndpoints(ctx context.Context, req *computepb.DetachNetworkEndpointsGlobalNetworkEndpointGroupRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetGlobalNetworkEndpointGroupsDetachEndpointsRequestResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/networkEndpointGroups/%v/detachNetworkEndpoints", req.GetProject(), req.GetNetworkEndpointGroup()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Get returns the specified network endpoint group. Gets a list of available network endpoint groups by making a list() request. +func (c *globalNetworkEndpointGroupsRESTClient) Get(ctx context.Context, req *computepb.GetGlobalNetworkEndpointGroupRequest, opts ...gax.CallOption) (*computepb.NetworkEndpointGroup, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/networkEndpointGroups/%v", req.GetProject(), req.GetNetworkEndpointGroup()) + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.NetworkEndpointGroup{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Insert creates a network endpoint group in the specified project using the parameters that are included in the request. +func (c *globalNetworkEndpointGroupsRESTClient) Insert(ctx context.Context, req *computepb.InsertGlobalNetworkEndpointGroupRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetNetworkEndpointGroupResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/networkEndpointGroups", req.GetProject()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// List retrieves the list of network endpoint groups that are located in the specified project. +func (c *globalNetworkEndpointGroupsRESTClient) List(ctx context.Context, req *computepb.ListGlobalNetworkEndpointGroupsRequest, opts ...gax.CallOption) (*computepb.NetworkEndpointGroupList, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/networkEndpointGroups", req.GetProject()) + + params := url.Values{} + if req != nil && req.Filter != nil { + params.Add("filter", fmt.Sprintf("%v", req.GetFilter())) + } + if req != nil && req.MaxResults != nil { + params.Add("maxResults", fmt.Sprintf("%v", req.GetMaxResults())) + } + if req != nil && req.OrderBy != nil { + params.Add("orderBy", fmt.Sprintf("%v", req.GetOrderBy())) + } + if req != nil && req.PageToken != nil { + params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) + } + if req != nil && req.ReturnPartialSuccess != nil { + params.Add("returnPartialSuccess", fmt.Sprintf("%v", req.GetReturnPartialSuccess())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.NetworkEndpointGroupList{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// ListNetworkEndpoints lists the network endpoints in the specified network endpoint group. +func (c *globalNetworkEndpointGroupsRESTClient) ListNetworkEndpoints(ctx context.Context, req *computepb.ListNetworkEndpointsGlobalNetworkEndpointGroupsRequest, opts ...gax.CallOption) (*computepb.NetworkEndpointGroupsListNetworkEndpoints, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/networkEndpointGroups/%v/listNetworkEndpoints", req.GetProject(), req.GetNetworkEndpointGroup()) + + params := url.Values{} + if req != nil && req.Filter != nil { + params.Add("filter", fmt.Sprintf("%v", req.GetFilter())) + } + if req != nil && req.MaxResults != nil { + params.Add("maxResults", fmt.Sprintf("%v", req.GetMaxResults())) + } + if req != nil && req.OrderBy != nil { + params.Add("orderBy", fmt.Sprintf("%v", req.GetOrderBy())) + } + if req != nil && req.PageToken != nil { + params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) + } + if req != nil && req.ReturnPartialSuccess != nil { + params.Add("returnPartialSuccess", fmt.Sprintf("%v", req.GetReturnPartialSuccess())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.NetworkEndpointGroupsListNetworkEndpoints{} + + return rsp, unm.Unmarshal(buf, rsp) +} diff --git a/compute/apiv1/global_network_endpoint_groups_client_example_test.go b/compute/apiv1/global_network_endpoint_groups_client_example_test.go new file mode 100644 index 00000000000..80361d6d06e --- /dev/null +++ b/compute/apiv1/global_network_endpoint_groups_client_example_test.go @@ -0,0 +1,169 @@ +// 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 compute_test + +import ( + "context" + + compute "cloud.google.com/go/compute/apiv1" + computepb "google.golang.org/genproto/googleapis/cloud/compute/v1" +) + +func ExampleNewGlobalNetworkEndpointGroupsRESTClient() { + ctx := context.Background() + c, err := compute.NewGlobalNetworkEndpointGroupsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + // TODO: Use client. + _ = c +} + +func ExampleGlobalNetworkEndpointGroupsClient_AttachNetworkEndpoints() { + ctx := context.Background() + c, err := compute.NewGlobalNetworkEndpointGroupsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.AttachNetworkEndpointsGlobalNetworkEndpointGroupRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.AttachNetworkEndpoints(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleGlobalNetworkEndpointGroupsClient_Delete() { + ctx := context.Background() + c, err := compute.NewGlobalNetworkEndpointGroupsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.DeleteGlobalNetworkEndpointGroupRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Delete(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleGlobalNetworkEndpointGroupsClient_DetachNetworkEndpoints() { + ctx := context.Background() + c, err := compute.NewGlobalNetworkEndpointGroupsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.DetachNetworkEndpointsGlobalNetworkEndpointGroupRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.DetachNetworkEndpoints(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleGlobalNetworkEndpointGroupsClient_Get() { + ctx := context.Background() + c, err := compute.NewGlobalNetworkEndpointGroupsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.GetGlobalNetworkEndpointGroupRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Get(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleGlobalNetworkEndpointGroupsClient_Insert() { + ctx := context.Background() + c, err := compute.NewGlobalNetworkEndpointGroupsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.InsertGlobalNetworkEndpointGroupRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Insert(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleGlobalNetworkEndpointGroupsClient_List() { + ctx := context.Background() + c, err := compute.NewGlobalNetworkEndpointGroupsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.ListGlobalNetworkEndpointGroupsRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.List(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleGlobalNetworkEndpointGroupsClient_ListNetworkEndpoints() { + ctx := context.Background() + c, err := compute.NewGlobalNetworkEndpointGroupsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.ListNetworkEndpointsGlobalNetworkEndpointGroupsRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.ListNetworkEndpoints(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} diff --git a/compute/apiv1/global_operations_client.go b/compute/apiv1/global_operations_client.go new file mode 100644 index 00000000000..928eedface2 --- /dev/null +++ b/compute/apiv1/global_operations_client.go @@ -0,0 +1,449 @@ +// 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 compute + +import ( + "bytes" + "context" + "fmt" + "io/ioutil" + "net/http" + "net/url" + + gax "github.com/googleapis/gax-go/v2" + "google.golang.org/api/option" + "google.golang.org/api/option/internaloption" + httptransport "google.golang.org/api/transport/http" + computepb "google.golang.org/genproto/googleapis/cloud/compute/v1" + "google.golang.org/grpc" + "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/encoding/protojson" +) + +var newGlobalOperationsClientHook clientHook + +// GlobalOperationsCallOptions contains the retry settings for each method of GlobalOperationsClient. +type GlobalOperationsCallOptions struct { + AggregatedList []gax.CallOption + Delete []gax.CallOption + Get []gax.CallOption + List []gax.CallOption + Wait []gax.CallOption +} + +// internalGlobalOperationsClient is an interface that defines the methods availaible from Google Compute Engine API. +type internalGlobalOperationsClient interface { + Close() error + setGoogleClientInfo(...string) + Connection() *grpc.ClientConn + AggregatedList(context.Context, *computepb.AggregatedListGlobalOperationsRequest, ...gax.CallOption) (*computepb.OperationAggregatedList, error) + Delete(context.Context, *computepb.DeleteGlobalOperationRequest, ...gax.CallOption) (*computepb.DeleteGlobalOperationResponse, error) + Get(context.Context, *computepb.GetGlobalOperationRequest, ...gax.CallOption) (*computepb.Operation, error) + List(context.Context, *computepb.ListGlobalOperationsRequest, ...gax.CallOption) (*computepb.OperationList, error) + Wait(context.Context, *computepb.WaitGlobalOperationRequest, ...gax.CallOption) (*computepb.Operation, error) +} + +// GlobalOperationsClient is a client for interacting with Google Compute Engine API. +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +// +// The GlobalOperations API. +type GlobalOperationsClient struct { + // The internal transport-dependent client. + internalClient internalGlobalOperationsClient + + // The call options for this service. + CallOptions *GlobalOperationsCallOptions +} + +// 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 *GlobalOperationsClient) 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 *GlobalOperationsClient) setGoogleClientInfo(keyval ...string) { + c.internalClient.setGoogleClientInfo(keyval...) +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *GlobalOperationsClient) Connection() *grpc.ClientConn { + return c.internalClient.Connection() +} + +// AggregatedList retrieves an aggregated list of all operations. +func (c *GlobalOperationsClient) AggregatedList(ctx context.Context, req *computepb.AggregatedListGlobalOperationsRequest, opts ...gax.CallOption) (*computepb.OperationAggregatedList, error) { + return c.internalClient.AggregatedList(ctx, req, opts...) +} + +// Delete deletes the specified Operations resource. +func (c *GlobalOperationsClient) Delete(ctx context.Context, req *computepb.DeleteGlobalOperationRequest, opts ...gax.CallOption) (*computepb.DeleteGlobalOperationResponse, error) { + return c.internalClient.Delete(ctx, req, opts...) +} + +// Get retrieves the specified Operations resource. Gets a list of operations by making a list() request. +func (c *GlobalOperationsClient) Get(ctx context.Context, req *computepb.GetGlobalOperationRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.Get(ctx, req, opts...) +} + +// List retrieves a list of Operation resources contained within the specified project. +func (c *GlobalOperationsClient) List(ctx context.Context, req *computepb.ListGlobalOperationsRequest, opts ...gax.CallOption) (*computepb.OperationList, error) { + return c.internalClient.List(ctx, req, opts...) +} + +// Wait waits for the specified Operation resource to return as DONE or for the request to approach the 2 minute deadline, and retrieves the specified Operation resource. This method differs from the GET method in that it waits for no more than the default deadline (2 minutes) and then returns the current state of the operation, which might be DONE or still in progress. +// +// This method is called on a best-effort basis. Specifically: +// +// In uncommon cases, when the server is overloaded, the request might return before the default deadline is reached, or might return after zero seconds. +// +// If the default deadline is reached, there is no guarantee that the operation is actually done when the method returns. Be prepared to retry if the operation is not DONE. +func (c *GlobalOperationsClient) Wait(ctx context.Context, req *computepb.WaitGlobalOperationRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.Wait(ctx, req, opts...) +} + +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +type globalOperationsRESTClient struct { + // The http endpoint to connect to. + endpoint string + + // The http client. + httpClient *http.Client + + // The x-goog-* metadata to be sent with each request. + xGoogMetadata metadata.MD +} + +// NewGlobalOperationsRESTClient creates a new global operations rest client. +// +// The GlobalOperations API. +func NewGlobalOperationsRESTClient(ctx context.Context, opts ...option.ClientOption) (*GlobalOperationsClient, error) { + clientOpts := append(defaultGlobalOperationsRESTClientOptions(), opts...) + httpClient, endpoint, err := httptransport.NewClient(ctx, clientOpts...) + if err != nil { + return nil, err + } + + c := &globalOperationsRESTClient{ + endpoint: endpoint, + httpClient: httpClient, + } + c.setGoogleClientInfo() + + return &GlobalOperationsClient{internalClient: c, CallOptions: &GlobalOperationsCallOptions{}}, nil +} + +func defaultGlobalOperationsRESTClientOptions() []option.ClientOption { + return []option.ClientOption{ + internaloption.WithDefaultEndpoint("compute.googleapis.com"), + internaloption.WithDefaultMTLSEndpoint("compute.mtls.googleapis.com"), + internaloption.WithDefaultAudience("https://compute.googleapis.com/"), + internaloption.WithDefaultScopes(DefaultAuthScopes()...), + } +} + +// 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 *globalOperationsRESTClient) setGoogleClientInfo(keyval ...string) { + kv := append([]string{"gl-go", versionGo()}, keyval...) + kv = append(kv, "gapic", versionClient, "gax", gax.Version, "rest", "UNKNOWN") + 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 *globalOperationsRESTClient) Close() error { + // Replace httpClient with nil to force cleanup. + c.httpClient = nil + return nil +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *globalOperationsRESTClient) Connection() *grpc.ClientConn { + return nil +} + +// AggregatedList retrieves an aggregated list of all operations. +func (c *globalOperationsRESTClient) AggregatedList(ctx context.Context, req *computepb.AggregatedListGlobalOperationsRequest, opts ...gax.CallOption) (*computepb.OperationAggregatedList, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/aggregated/operations", req.GetProject()) + + params := url.Values{} + if req != nil && req.Filter != nil { + params.Add("filter", fmt.Sprintf("%v", req.GetFilter())) + } + if req != nil && req.IncludeAllScopes != nil { + params.Add("includeAllScopes", fmt.Sprintf("%v", req.GetIncludeAllScopes())) + } + if req != nil && req.MaxResults != nil { + params.Add("maxResults", fmt.Sprintf("%v", req.GetMaxResults())) + } + if req != nil && req.OrderBy != nil { + params.Add("orderBy", fmt.Sprintf("%v", req.GetOrderBy())) + } + if req != nil && req.PageToken != nil { + params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) + } + if req != nil && req.ReturnPartialSuccess != nil { + params.Add("returnPartialSuccess", fmt.Sprintf("%v", req.GetReturnPartialSuccess())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.OperationAggregatedList{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Delete deletes the specified Operations resource. +func (c *globalOperationsRESTClient) Delete(ctx context.Context, req *computepb.DeleteGlobalOperationRequest, opts ...gax.CallOption) (*computepb.DeleteGlobalOperationResponse, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/operations/%v", req.GetProject(), req.GetOperation()) + + httpReq, err := http.NewRequest("DELETE", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.DeleteGlobalOperationResponse{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Get retrieves the specified Operations resource. Gets a list of operations by making a list() request. +func (c *globalOperationsRESTClient) Get(ctx context.Context, req *computepb.GetGlobalOperationRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/operations/%v", req.GetProject(), req.GetOperation()) + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// List retrieves a list of Operation resources contained within the specified project. +func (c *globalOperationsRESTClient) List(ctx context.Context, req *computepb.ListGlobalOperationsRequest, opts ...gax.CallOption) (*computepb.OperationList, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/operations", req.GetProject()) + + params := url.Values{} + if req != nil && req.Filter != nil { + params.Add("filter", fmt.Sprintf("%v", req.GetFilter())) + } + if req != nil && req.MaxResults != nil { + params.Add("maxResults", fmt.Sprintf("%v", req.GetMaxResults())) + } + if req != nil && req.OrderBy != nil { + params.Add("orderBy", fmt.Sprintf("%v", req.GetOrderBy())) + } + if req != nil && req.PageToken != nil { + params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) + } + if req != nil && req.ReturnPartialSuccess != nil { + params.Add("returnPartialSuccess", fmt.Sprintf("%v", req.GetReturnPartialSuccess())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.OperationList{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Wait waits for the specified Operation resource to return as DONE or for the request to approach the 2 minute deadline, and retrieves the specified Operation resource. This method differs from the GET method in that it waits for no more than the default deadline (2 minutes) and then returns the current state of the operation, which might be DONE or still in progress. +// +// This method is called on a best-effort basis. Specifically: +// +// In uncommon cases, when the server is overloaded, the request might return before the default deadline is reached, or might return after zero seconds. +// +// If the default deadline is reached, there is no guarantee that the operation is actually done when the method returns. Be prepared to retry if the operation is not DONE. +func (c *globalOperationsRESTClient) Wait(ctx context.Context, req *computepb.WaitGlobalOperationRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/operations/%v/wait", req.GetProject(), req.GetOperation()) + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} diff --git a/compute/apiv1/global_operations_client_example_test.go b/compute/apiv1/global_operations_client_example_test.go new file mode 100644 index 00000000000..4cb6a7867b3 --- /dev/null +++ b/compute/apiv1/global_operations_client_example_test.go @@ -0,0 +1,131 @@ +// 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 compute_test + +import ( + "context" + + compute "cloud.google.com/go/compute/apiv1" + computepb "google.golang.org/genproto/googleapis/cloud/compute/v1" +) + +func ExampleNewGlobalOperationsRESTClient() { + ctx := context.Background() + c, err := compute.NewGlobalOperationsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + // TODO: Use client. + _ = c +} + +func ExampleGlobalOperationsClient_AggregatedList() { + ctx := context.Background() + c, err := compute.NewGlobalOperationsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.AggregatedListGlobalOperationsRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.AggregatedList(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleGlobalOperationsClient_Delete() { + ctx := context.Background() + c, err := compute.NewGlobalOperationsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.DeleteGlobalOperationRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Delete(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleGlobalOperationsClient_Get() { + ctx := context.Background() + c, err := compute.NewGlobalOperationsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.GetGlobalOperationRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Get(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleGlobalOperationsClient_List() { + ctx := context.Background() + c, err := compute.NewGlobalOperationsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.ListGlobalOperationsRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.List(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleGlobalOperationsClient_Wait() { + ctx := context.Background() + c, err := compute.NewGlobalOperationsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.WaitGlobalOperationRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Wait(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} diff --git a/compute/apiv1/global_organization_operations_client.go b/compute/apiv1/global_organization_operations_client.go new file mode 100644 index 00000000000..94cec22cbfc --- /dev/null +++ b/compute/apiv1/global_organization_operations_client.go @@ -0,0 +1,332 @@ +// 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 compute + +import ( + "bytes" + "context" + "fmt" + "io/ioutil" + "net/http" + "net/url" + + gax "github.com/googleapis/gax-go/v2" + "google.golang.org/api/option" + "google.golang.org/api/option/internaloption" + httptransport "google.golang.org/api/transport/http" + computepb "google.golang.org/genproto/googleapis/cloud/compute/v1" + "google.golang.org/grpc" + "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/encoding/protojson" +) + +var newGlobalOrganizationOperationsClientHook clientHook + +// GlobalOrganizationOperationsCallOptions contains the retry settings for each method of GlobalOrganizationOperationsClient. +type GlobalOrganizationOperationsCallOptions struct { + Delete []gax.CallOption + Get []gax.CallOption + List []gax.CallOption +} + +// internalGlobalOrganizationOperationsClient is an interface that defines the methods availaible from Google Compute Engine API. +type internalGlobalOrganizationOperationsClient interface { + Close() error + setGoogleClientInfo(...string) + Connection() *grpc.ClientConn + Delete(context.Context, *computepb.DeleteGlobalOrganizationOperationRequest, ...gax.CallOption) (*computepb.DeleteGlobalOrganizationOperationResponse, error) + Get(context.Context, *computepb.GetGlobalOrganizationOperationRequest, ...gax.CallOption) (*computepb.Operation, error) + List(context.Context, *computepb.ListGlobalOrganizationOperationsRequest, ...gax.CallOption) (*computepb.OperationList, error) +} + +// GlobalOrganizationOperationsClient is a client for interacting with Google Compute Engine API. +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +// +// The GlobalOrganizationOperations API. +type GlobalOrganizationOperationsClient struct { + // The internal transport-dependent client. + internalClient internalGlobalOrganizationOperationsClient + + // The call options for this service. + CallOptions *GlobalOrganizationOperationsCallOptions +} + +// 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 *GlobalOrganizationOperationsClient) 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 *GlobalOrganizationOperationsClient) setGoogleClientInfo(keyval ...string) { + c.internalClient.setGoogleClientInfo(keyval...) +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *GlobalOrganizationOperationsClient) Connection() *grpc.ClientConn { + return c.internalClient.Connection() +} + +// Delete deletes the specified Operations resource. +func (c *GlobalOrganizationOperationsClient) Delete(ctx context.Context, req *computepb.DeleteGlobalOrganizationOperationRequest, opts ...gax.CallOption) (*computepb.DeleteGlobalOrganizationOperationResponse, error) { + return c.internalClient.Delete(ctx, req, opts...) +} + +// Get retrieves the specified Operations resource. Gets a list of operations by making a list() request. +func (c *GlobalOrganizationOperationsClient) Get(ctx context.Context, req *computepb.GetGlobalOrganizationOperationRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.Get(ctx, req, opts...) +} + +// List retrieves a list of Operation resources contained within the specified organization. +func (c *GlobalOrganizationOperationsClient) List(ctx context.Context, req *computepb.ListGlobalOrganizationOperationsRequest, opts ...gax.CallOption) (*computepb.OperationList, error) { + return c.internalClient.List(ctx, req, opts...) +} + +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +type globalOrganizationOperationsRESTClient struct { + // The http endpoint to connect to. + endpoint string + + // The http client. + httpClient *http.Client + + // The x-goog-* metadata to be sent with each request. + xGoogMetadata metadata.MD +} + +// NewGlobalOrganizationOperationsRESTClient creates a new global organization operations rest client. +// +// The GlobalOrganizationOperations API. +func NewGlobalOrganizationOperationsRESTClient(ctx context.Context, opts ...option.ClientOption) (*GlobalOrganizationOperationsClient, error) { + clientOpts := append(defaultGlobalOrganizationOperationsRESTClientOptions(), opts...) + httpClient, endpoint, err := httptransport.NewClient(ctx, clientOpts...) + if err != nil { + return nil, err + } + + c := &globalOrganizationOperationsRESTClient{ + endpoint: endpoint, + httpClient: httpClient, + } + c.setGoogleClientInfo() + + return &GlobalOrganizationOperationsClient{internalClient: c, CallOptions: &GlobalOrganizationOperationsCallOptions{}}, nil +} + +func defaultGlobalOrganizationOperationsRESTClientOptions() []option.ClientOption { + return []option.ClientOption{ + internaloption.WithDefaultEndpoint("compute.googleapis.com"), + internaloption.WithDefaultMTLSEndpoint("compute.mtls.googleapis.com"), + internaloption.WithDefaultAudience("https://compute.googleapis.com/"), + internaloption.WithDefaultScopes(DefaultAuthScopes()...), + } +} + +// 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 *globalOrganizationOperationsRESTClient) setGoogleClientInfo(keyval ...string) { + kv := append([]string{"gl-go", versionGo()}, keyval...) + kv = append(kv, "gapic", versionClient, "gax", gax.Version, "rest", "UNKNOWN") + 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 *globalOrganizationOperationsRESTClient) Close() error { + // Replace httpClient with nil to force cleanup. + c.httpClient = nil + return nil +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *globalOrganizationOperationsRESTClient) Connection() *grpc.ClientConn { + return nil +} + +// Delete deletes the specified Operations resource. +func (c *globalOrganizationOperationsRESTClient) Delete(ctx context.Context, req *computepb.DeleteGlobalOrganizationOperationRequest, opts ...gax.CallOption) (*computepb.DeleteGlobalOrganizationOperationResponse, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/locations/global/operations/%v", req.GetOperation()) + + params := url.Values{} + if req != nil && req.ParentId != nil { + params.Add("parentId", fmt.Sprintf("%v", req.GetParentId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("DELETE", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.DeleteGlobalOrganizationOperationResponse{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Get retrieves the specified Operations resource. Gets a list of operations by making a list() request. +func (c *globalOrganizationOperationsRESTClient) Get(ctx context.Context, req *computepb.GetGlobalOrganizationOperationRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/locations/global/operations/%v", req.GetOperation()) + + params := url.Values{} + if req != nil && req.ParentId != nil { + params.Add("parentId", fmt.Sprintf("%v", req.GetParentId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// List retrieves a list of Operation resources contained within the specified organization. +func (c *globalOrganizationOperationsRESTClient) List(ctx context.Context, req *computepb.ListGlobalOrganizationOperationsRequest, opts ...gax.CallOption) (*computepb.OperationList, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/locations/global/operations") + + params := url.Values{} + if req != nil && req.Filter != nil { + params.Add("filter", fmt.Sprintf("%v", req.GetFilter())) + } + if req != nil && req.MaxResults != nil { + params.Add("maxResults", fmt.Sprintf("%v", req.GetMaxResults())) + } + if req != nil && req.OrderBy != nil { + params.Add("orderBy", fmt.Sprintf("%v", req.GetOrderBy())) + } + if req != nil && req.PageToken != nil { + params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) + } + if req != nil && req.ParentId != nil { + params.Add("parentId", fmt.Sprintf("%v", req.GetParentId())) + } + if req != nil && req.ReturnPartialSuccess != nil { + params.Add("returnPartialSuccess", fmt.Sprintf("%v", req.GetReturnPartialSuccess())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.OperationList{} + + return rsp, unm.Unmarshal(buf, rsp) +} diff --git a/compute/apiv1/global_organization_operations_client_example_test.go b/compute/apiv1/global_organization_operations_client_example_test.go new file mode 100644 index 00000000000..1018ba67433 --- /dev/null +++ b/compute/apiv1/global_organization_operations_client_example_test.go @@ -0,0 +1,93 @@ +// 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 compute_test + +import ( + "context" + + compute "cloud.google.com/go/compute/apiv1" + computepb "google.golang.org/genproto/googleapis/cloud/compute/v1" +) + +func ExampleNewGlobalOrganizationOperationsRESTClient() { + ctx := context.Background() + c, err := compute.NewGlobalOrganizationOperationsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + // TODO: Use client. + _ = c +} + +func ExampleGlobalOrganizationOperationsClient_Delete() { + ctx := context.Background() + c, err := compute.NewGlobalOrganizationOperationsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.DeleteGlobalOrganizationOperationRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Delete(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleGlobalOrganizationOperationsClient_Get() { + ctx := context.Background() + c, err := compute.NewGlobalOrganizationOperationsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.GetGlobalOrganizationOperationRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Get(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleGlobalOrganizationOperationsClient_List() { + ctx := context.Background() + c, err := compute.NewGlobalOrganizationOperationsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.ListGlobalOrganizationOperationsRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.List(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} diff --git a/compute/apiv1/global_public_delegated_prefixes_client.go b/compute/apiv1/global_public_delegated_prefixes_client.go new file mode 100644 index 00000000000..b0e0fc7cc99 --- /dev/null +++ b/compute/apiv1/global_public_delegated_prefixes_client.go @@ -0,0 +1,438 @@ +// 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 compute + +import ( + "bytes" + "context" + "fmt" + "io/ioutil" + "net/http" + "net/url" + + gax "github.com/googleapis/gax-go/v2" + "google.golang.org/api/option" + "google.golang.org/api/option/internaloption" + httptransport "google.golang.org/api/transport/http" + computepb "google.golang.org/genproto/googleapis/cloud/compute/v1" + "google.golang.org/grpc" + "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/encoding/protojson" +) + +var newGlobalPublicDelegatedPrefixesClientHook clientHook + +// GlobalPublicDelegatedPrefixesCallOptions contains the retry settings for each method of GlobalPublicDelegatedPrefixesClient. +type GlobalPublicDelegatedPrefixesCallOptions struct { + Delete []gax.CallOption + Get []gax.CallOption + Insert []gax.CallOption + List []gax.CallOption + Patch []gax.CallOption +} + +// internalGlobalPublicDelegatedPrefixesClient is an interface that defines the methods availaible from Google Compute Engine API. +type internalGlobalPublicDelegatedPrefixesClient interface { + Close() error + setGoogleClientInfo(...string) + Connection() *grpc.ClientConn + Delete(context.Context, *computepb.DeleteGlobalPublicDelegatedPrefixeRequest, ...gax.CallOption) (*computepb.Operation, error) + Get(context.Context, *computepb.GetGlobalPublicDelegatedPrefixeRequest, ...gax.CallOption) (*computepb.PublicDelegatedPrefix, error) + Insert(context.Context, *computepb.InsertGlobalPublicDelegatedPrefixeRequest, ...gax.CallOption) (*computepb.Operation, error) + List(context.Context, *computepb.ListGlobalPublicDelegatedPrefixesRequest, ...gax.CallOption) (*computepb.PublicDelegatedPrefixList, error) + Patch(context.Context, *computepb.PatchGlobalPublicDelegatedPrefixeRequest, ...gax.CallOption) (*computepb.Operation, error) +} + +// GlobalPublicDelegatedPrefixesClient is a client for interacting with Google Compute Engine API. +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +// +// The GlobalPublicDelegatedPrefixes API. +type GlobalPublicDelegatedPrefixesClient struct { + // The internal transport-dependent client. + internalClient internalGlobalPublicDelegatedPrefixesClient + + // The call options for this service. + CallOptions *GlobalPublicDelegatedPrefixesCallOptions +} + +// 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 *GlobalPublicDelegatedPrefixesClient) 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 *GlobalPublicDelegatedPrefixesClient) setGoogleClientInfo(keyval ...string) { + c.internalClient.setGoogleClientInfo(keyval...) +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *GlobalPublicDelegatedPrefixesClient) Connection() *grpc.ClientConn { + return c.internalClient.Connection() +} + +// Delete deletes the specified global PublicDelegatedPrefix. +func (c *GlobalPublicDelegatedPrefixesClient) Delete(ctx context.Context, req *computepb.DeleteGlobalPublicDelegatedPrefixeRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.Delete(ctx, req, opts...) +} + +// Get returns the specified global PublicDelegatedPrefix resource. +func (c *GlobalPublicDelegatedPrefixesClient) Get(ctx context.Context, req *computepb.GetGlobalPublicDelegatedPrefixeRequest, opts ...gax.CallOption) (*computepb.PublicDelegatedPrefix, error) { + return c.internalClient.Get(ctx, req, opts...) +} + +// Insert creates a global PublicDelegatedPrefix in the specified project using the parameters that are included in the request. +func (c *GlobalPublicDelegatedPrefixesClient) Insert(ctx context.Context, req *computepb.InsertGlobalPublicDelegatedPrefixeRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.Insert(ctx, req, opts...) +} + +// List lists the global PublicDelegatedPrefixes for a project. +func (c *GlobalPublicDelegatedPrefixesClient) List(ctx context.Context, req *computepb.ListGlobalPublicDelegatedPrefixesRequest, opts ...gax.CallOption) (*computepb.PublicDelegatedPrefixList, error) { + return c.internalClient.List(ctx, req, opts...) +} + +// Patch patches the specified global PublicDelegatedPrefix resource with the data included in the request. This method supports PATCH semantics and uses JSON merge patch format and processing rules. +func (c *GlobalPublicDelegatedPrefixesClient) Patch(ctx context.Context, req *computepb.PatchGlobalPublicDelegatedPrefixeRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.Patch(ctx, req, opts...) +} + +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +type globalPublicDelegatedPrefixesRESTClient struct { + // The http endpoint to connect to. + endpoint string + + // The http client. + httpClient *http.Client + + // The x-goog-* metadata to be sent with each request. + xGoogMetadata metadata.MD +} + +// NewGlobalPublicDelegatedPrefixesRESTClient creates a new global public delegated prefixes rest client. +// +// The GlobalPublicDelegatedPrefixes API. +func NewGlobalPublicDelegatedPrefixesRESTClient(ctx context.Context, opts ...option.ClientOption) (*GlobalPublicDelegatedPrefixesClient, error) { + clientOpts := append(defaultGlobalPublicDelegatedPrefixesRESTClientOptions(), opts...) + httpClient, endpoint, err := httptransport.NewClient(ctx, clientOpts...) + if err != nil { + return nil, err + } + + c := &globalPublicDelegatedPrefixesRESTClient{ + endpoint: endpoint, + httpClient: httpClient, + } + c.setGoogleClientInfo() + + return &GlobalPublicDelegatedPrefixesClient{internalClient: c, CallOptions: &GlobalPublicDelegatedPrefixesCallOptions{}}, nil +} + +func defaultGlobalPublicDelegatedPrefixesRESTClientOptions() []option.ClientOption { + return []option.ClientOption{ + internaloption.WithDefaultEndpoint("compute.googleapis.com"), + internaloption.WithDefaultMTLSEndpoint("compute.mtls.googleapis.com"), + internaloption.WithDefaultAudience("https://compute.googleapis.com/"), + internaloption.WithDefaultScopes(DefaultAuthScopes()...), + } +} + +// 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 *globalPublicDelegatedPrefixesRESTClient) setGoogleClientInfo(keyval ...string) { + kv := append([]string{"gl-go", versionGo()}, keyval...) + kv = append(kv, "gapic", versionClient, "gax", gax.Version, "rest", "UNKNOWN") + 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 *globalPublicDelegatedPrefixesRESTClient) Close() error { + // Replace httpClient with nil to force cleanup. + c.httpClient = nil + return nil +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *globalPublicDelegatedPrefixesRESTClient) Connection() *grpc.ClientConn { + return nil +} + +// Delete deletes the specified global PublicDelegatedPrefix. +func (c *globalPublicDelegatedPrefixesRESTClient) Delete(ctx context.Context, req *computepb.DeleteGlobalPublicDelegatedPrefixeRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/publicDelegatedPrefixes/%v", req.GetProject(), req.GetPublicDelegatedPrefix()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("DELETE", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Get returns the specified global PublicDelegatedPrefix resource. +func (c *globalPublicDelegatedPrefixesRESTClient) Get(ctx context.Context, req *computepb.GetGlobalPublicDelegatedPrefixeRequest, opts ...gax.CallOption) (*computepb.PublicDelegatedPrefix, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/publicDelegatedPrefixes/%v", req.GetProject(), req.GetPublicDelegatedPrefix()) + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.PublicDelegatedPrefix{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Insert creates a global PublicDelegatedPrefix in the specified project using the parameters that are included in the request. +func (c *globalPublicDelegatedPrefixesRESTClient) Insert(ctx context.Context, req *computepb.InsertGlobalPublicDelegatedPrefixeRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetPublicDelegatedPrefixResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/publicDelegatedPrefixes", req.GetProject()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// List lists the global PublicDelegatedPrefixes for a project. +func (c *globalPublicDelegatedPrefixesRESTClient) List(ctx context.Context, req *computepb.ListGlobalPublicDelegatedPrefixesRequest, opts ...gax.CallOption) (*computepb.PublicDelegatedPrefixList, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/publicDelegatedPrefixes", req.GetProject()) + + params := url.Values{} + if req != nil && req.Filter != nil { + params.Add("filter", fmt.Sprintf("%v", req.GetFilter())) + } + if req != nil && req.MaxResults != nil { + params.Add("maxResults", fmt.Sprintf("%v", req.GetMaxResults())) + } + if req != nil && req.OrderBy != nil { + params.Add("orderBy", fmt.Sprintf("%v", req.GetOrderBy())) + } + if req != nil && req.PageToken != nil { + params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) + } + if req != nil && req.ReturnPartialSuccess != nil { + params.Add("returnPartialSuccess", fmt.Sprintf("%v", req.GetReturnPartialSuccess())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.PublicDelegatedPrefixList{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Patch patches the specified global PublicDelegatedPrefix resource with the data included in the request. This method supports PATCH semantics and uses JSON merge patch format and processing rules. +func (c *globalPublicDelegatedPrefixesRESTClient) Patch(ctx context.Context, req *computepb.PatchGlobalPublicDelegatedPrefixeRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetPublicDelegatedPrefixResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/publicDelegatedPrefixes/%v", req.GetProject(), req.GetPublicDelegatedPrefix()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("PATCH", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} diff --git a/compute/apiv1/global_public_delegated_prefixes_client_example_test.go b/compute/apiv1/global_public_delegated_prefixes_client_example_test.go new file mode 100644 index 00000000000..dc9f1da0034 --- /dev/null +++ b/compute/apiv1/global_public_delegated_prefixes_client_example_test.go @@ -0,0 +1,131 @@ +// 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 compute_test + +import ( + "context" + + compute "cloud.google.com/go/compute/apiv1" + computepb "google.golang.org/genproto/googleapis/cloud/compute/v1" +) + +func ExampleNewGlobalPublicDelegatedPrefixesRESTClient() { + ctx := context.Background() + c, err := compute.NewGlobalPublicDelegatedPrefixesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + // TODO: Use client. + _ = c +} + +func ExampleGlobalPublicDelegatedPrefixesClient_Delete() { + ctx := context.Background() + c, err := compute.NewGlobalPublicDelegatedPrefixesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.DeleteGlobalPublicDelegatedPrefixeRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Delete(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleGlobalPublicDelegatedPrefixesClient_Get() { + ctx := context.Background() + c, err := compute.NewGlobalPublicDelegatedPrefixesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.GetGlobalPublicDelegatedPrefixeRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Get(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleGlobalPublicDelegatedPrefixesClient_Insert() { + ctx := context.Background() + c, err := compute.NewGlobalPublicDelegatedPrefixesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.InsertGlobalPublicDelegatedPrefixeRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Insert(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleGlobalPublicDelegatedPrefixesClient_List() { + ctx := context.Background() + c, err := compute.NewGlobalPublicDelegatedPrefixesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.ListGlobalPublicDelegatedPrefixesRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.List(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleGlobalPublicDelegatedPrefixesClient_Patch() { + ctx := context.Background() + c, err := compute.NewGlobalPublicDelegatedPrefixesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.PatchGlobalPublicDelegatedPrefixeRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Patch(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} diff --git a/compute/apiv1/health_checks_client.go b/compute/apiv1/health_checks_client.go new file mode 100644 index 00000000000..887b7c4a853 --- /dev/null +++ b/compute/apiv1/health_checks_client.go @@ -0,0 +1,574 @@ +// 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 compute + +import ( + "bytes" + "context" + "fmt" + "io/ioutil" + "net/http" + "net/url" + + gax "github.com/googleapis/gax-go/v2" + "google.golang.org/api/option" + "google.golang.org/api/option/internaloption" + httptransport "google.golang.org/api/transport/http" + computepb "google.golang.org/genproto/googleapis/cloud/compute/v1" + "google.golang.org/grpc" + "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/encoding/protojson" +) + +var newHealthChecksClientHook clientHook + +// HealthChecksCallOptions contains the retry settings for each method of HealthChecksClient. +type HealthChecksCallOptions struct { + AggregatedList []gax.CallOption + Delete []gax.CallOption + Get []gax.CallOption + Insert []gax.CallOption + List []gax.CallOption + Patch []gax.CallOption + Update []gax.CallOption +} + +// internalHealthChecksClient is an interface that defines the methods availaible from Google Compute Engine API. +type internalHealthChecksClient interface { + Close() error + setGoogleClientInfo(...string) + Connection() *grpc.ClientConn + AggregatedList(context.Context, *computepb.AggregatedListHealthChecksRequest, ...gax.CallOption) (*computepb.HealthChecksAggregatedList, error) + Delete(context.Context, *computepb.DeleteHealthCheckRequest, ...gax.CallOption) (*computepb.Operation, error) + Get(context.Context, *computepb.GetHealthCheckRequest, ...gax.CallOption) (*computepb.HealthCheck, error) + Insert(context.Context, *computepb.InsertHealthCheckRequest, ...gax.CallOption) (*computepb.Operation, error) + List(context.Context, *computepb.ListHealthChecksRequest, ...gax.CallOption) (*computepb.HealthCheckList, error) + Patch(context.Context, *computepb.PatchHealthCheckRequest, ...gax.CallOption) (*computepb.Operation, error) + Update(context.Context, *computepb.UpdateHealthCheckRequest, ...gax.CallOption) (*computepb.Operation, error) +} + +// HealthChecksClient is a client for interacting with Google Compute Engine API. +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +// +// The HealthChecks API. +type HealthChecksClient struct { + // The internal transport-dependent client. + internalClient internalHealthChecksClient + + // The call options for this service. + CallOptions *HealthChecksCallOptions +} + +// 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 *HealthChecksClient) 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 *HealthChecksClient) setGoogleClientInfo(keyval ...string) { + c.internalClient.setGoogleClientInfo(keyval...) +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *HealthChecksClient) Connection() *grpc.ClientConn { + return c.internalClient.Connection() +} + +// AggregatedList retrieves the list of all HealthCheck resources, regional and global, available to the specified project. +func (c *HealthChecksClient) AggregatedList(ctx context.Context, req *computepb.AggregatedListHealthChecksRequest, opts ...gax.CallOption) (*computepb.HealthChecksAggregatedList, error) { + return c.internalClient.AggregatedList(ctx, req, opts...) +} + +// Delete deletes the specified HealthCheck resource. +func (c *HealthChecksClient) Delete(ctx context.Context, req *computepb.DeleteHealthCheckRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.Delete(ctx, req, opts...) +} + +// Get returns the specified HealthCheck resource. Gets a list of available health checks by making a list() request. +func (c *HealthChecksClient) Get(ctx context.Context, req *computepb.GetHealthCheckRequest, opts ...gax.CallOption) (*computepb.HealthCheck, error) { + return c.internalClient.Get(ctx, req, opts...) +} + +// Insert creates a HealthCheck resource in the specified project using the data included in the request. +func (c *HealthChecksClient) Insert(ctx context.Context, req *computepb.InsertHealthCheckRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.Insert(ctx, req, opts...) +} + +// List retrieves the list of HealthCheck resources available to the specified project. +func (c *HealthChecksClient) List(ctx context.Context, req *computepb.ListHealthChecksRequest, opts ...gax.CallOption) (*computepb.HealthCheckList, error) { + return c.internalClient.List(ctx, req, opts...) +} + +// Patch updates a HealthCheck resource in the specified project using the data included in the request. This method supports PATCH semantics and uses the JSON merge patch format and processing rules. +func (c *HealthChecksClient) Patch(ctx context.Context, req *computepb.PatchHealthCheckRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.Patch(ctx, req, opts...) +} + +// Update updates a HealthCheck resource in the specified project using the data included in the request. +func (c *HealthChecksClient) Update(ctx context.Context, req *computepb.UpdateHealthCheckRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.Update(ctx, req, opts...) +} + +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +type healthChecksRESTClient struct { + // The http endpoint to connect to. + endpoint string + + // The http client. + httpClient *http.Client + + // The x-goog-* metadata to be sent with each request. + xGoogMetadata metadata.MD +} + +// NewHealthChecksRESTClient creates a new health checks rest client. +// +// The HealthChecks API. +func NewHealthChecksRESTClient(ctx context.Context, opts ...option.ClientOption) (*HealthChecksClient, error) { + clientOpts := append(defaultHealthChecksRESTClientOptions(), opts...) + httpClient, endpoint, err := httptransport.NewClient(ctx, clientOpts...) + if err != nil { + return nil, err + } + + c := &healthChecksRESTClient{ + endpoint: endpoint, + httpClient: httpClient, + } + c.setGoogleClientInfo() + + return &HealthChecksClient{internalClient: c, CallOptions: &HealthChecksCallOptions{}}, nil +} + +func defaultHealthChecksRESTClientOptions() []option.ClientOption { + return []option.ClientOption{ + internaloption.WithDefaultEndpoint("compute.googleapis.com"), + internaloption.WithDefaultMTLSEndpoint("compute.mtls.googleapis.com"), + internaloption.WithDefaultAudience("https://compute.googleapis.com/"), + internaloption.WithDefaultScopes(DefaultAuthScopes()...), + } +} + +// 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 *healthChecksRESTClient) setGoogleClientInfo(keyval ...string) { + kv := append([]string{"gl-go", versionGo()}, keyval...) + kv = append(kv, "gapic", versionClient, "gax", gax.Version, "rest", "UNKNOWN") + 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 *healthChecksRESTClient) Close() error { + // Replace httpClient with nil to force cleanup. + c.httpClient = nil + return nil +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *healthChecksRESTClient) Connection() *grpc.ClientConn { + return nil +} + +// AggregatedList retrieves the list of all HealthCheck resources, regional and global, available to the specified project. +func (c *healthChecksRESTClient) AggregatedList(ctx context.Context, req *computepb.AggregatedListHealthChecksRequest, opts ...gax.CallOption) (*computepb.HealthChecksAggregatedList, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/aggregated/healthChecks", req.GetProject()) + + params := url.Values{} + if req != nil && req.Filter != nil { + params.Add("filter", fmt.Sprintf("%v", req.GetFilter())) + } + if req != nil && req.IncludeAllScopes != nil { + params.Add("includeAllScopes", fmt.Sprintf("%v", req.GetIncludeAllScopes())) + } + if req != nil && req.MaxResults != nil { + params.Add("maxResults", fmt.Sprintf("%v", req.GetMaxResults())) + } + if req != nil && req.OrderBy != nil { + params.Add("orderBy", fmt.Sprintf("%v", req.GetOrderBy())) + } + if req != nil && req.PageToken != nil { + params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) + } + if req != nil && req.ReturnPartialSuccess != nil { + params.Add("returnPartialSuccess", fmt.Sprintf("%v", req.GetReturnPartialSuccess())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.HealthChecksAggregatedList{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Delete deletes the specified HealthCheck resource. +func (c *healthChecksRESTClient) Delete(ctx context.Context, req *computepb.DeleteHealthCheckRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/healthChecks/%v", req.GetProject(), req.GetHealthCheck()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("DELETE", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Get returns the specified HealthCheck resource. Gets a list of available health checks by making a list() request. +func (c *healthChecksRESTClient) Get(ctx context.Context, req *computepb.GetHealthCheckRequest, opts ...gax.CallOption) (*computepb.HealthCheck, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/healthChecks/%v", req.GetProject(), req.GetHealthCheck()) + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.HealthCheck{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Insert creates a HealthCheck resource in the specified project using the data included in the request. +func (c *healthChecksRESTClient) Insert(ctx context.Context, req *computepb.InsertHealthCheckRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetHealthCheckResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/healthChecks", req.GetProject()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// List retrieves the list of HealthCheck resources available to the specified project. +func (c *healthChecksRESTClient) List(ctx context.Context, req *computepb.ListHealthChecksRequest, opts ...gax.CallOption) (*computepb.HealthCheckList, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/healthChecks", req.GetProject()) + + params := url.Values{} + if req != nil && req.Filter != nil { + params.Add("filter", fmt.Sprintf("%v", req.GetFilter())) + } + if req != nil && req.MaxResults != nil { + params.Add("maxResults", fmt.Sprintf("%v", req.GetMaxResults())) + } + if req != nil && req.OrderBy != nil { + params.Add("orderBy", fmt.Sprintf("%v", req.GetOrderBy())) + } + if req != nil && req.PageToken != nil { + params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) + } + if req != nil && req.ReturnPartialSuccess != nil { + params.Add("returnPartialSuccess", fmt.Sprintf("%v", req.GetReturnPartialSuccess())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.HealthCheckList{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Patch updates a HealthCheck resource in the specified project using the data included in the request. This method supports PATCH semantics and uses the JSON merge patch format and processing rules. +func (c *healthChecksRESTClient) Patch(ctx context.Context, req *computepb.PatchHealthCheckRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetHealthCheckResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/healthChecks/%v", req.GetProject(), req.GetHealthCheck()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("PATCH", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Update updates a HealthCheck resource in the specified project using the data included in the request. +func (c *healthChecksRESTClient) Update(ctx context.Context, req *computepb.UpdateHealthCheckRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetHealthCheckResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("") + + params := url.Values{} + if req.GetHealthCheck() != "" { + params.Add("healthCheck", fmt.Sprintf("%v", req.GetHealthCheck())) + } + if req.GetProject() != "" { + params.Add("project", fmt.Sprintf("%v", req.GetProject())) + } + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("PUT", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} diff --git a/compute/apiv1/health_checks_client_example_test.go b/compute/apiv1/health_checks_client_example_test.go new file mode 100644 index 00000000000..fe6aeb7fe68 --- /dev/null +++ b/compute/apiv1/health_checks_client_example_test.go @@ -0,0 +1,169 @@ +// 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 compute_test + +import ( + "context" + + compute "cloud.google.com/go/compute/apiv1" + computepb "google.golang.org/genproto/googleapis/cloud/compute/v1" +) + +func ExampleNewHealthChecksRESTClient() { + ctx := context.Background() + c, err := compute.NewHealthChecksRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + // TODO: Use client. + _ = c +} + +func ExampleHealthChecksClient_AggregatedList() { + ctx := context.Background() + c, err := compute.NewHealthChecksRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.AggregatedListHealthChecksRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.AggregatedList(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleHealthChecksClient_Delete() { + ctx := context.Background() + c, err := compute.NewHealthChecksRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.DeleteHealthCheckRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Delete(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleHealthChecksClient_Get() { + ctx := context.Background() + c, err := compute.NewHealthChecksRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.GetHealthCheckRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Get(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleHealthChecksClient_Insert() { + ctx := context.Background() + c, err := compute.NewHealthChecksRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.InsertHealthCheckRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Insert(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleHealthChecksClient_List() { + ctx := context.Background() + c, err := compute.NewHealthChecksRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.ListHealthChecksRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.List(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleHealthChecksClient_Patch() { + ctx := context.Background() + c, err := compute.NewHealthChecksRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.PatchHealthCheckRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Patch(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleHealthChecksClient_Update() { + ctx := context.Background() + c, err := compute.NewHealthChecksRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.UpdateHealthCheckRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Update(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} diff --git a/compute/apiv1/images_client.go b/compute/apiv1/images_client.go new file mode 100644 index 00000000000..8fbfa02a672 --- /dev/null +++ b/compute/apiv1/images_client.go @@ -0,0 +1,763 @@ +// 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 compute + +import ( + "bytes" + "context" + "fmt" + "io/ioutil" + "net/http" + "net/url" + + gax "github.com/googleapis/gax-go/v2" + "google.golang.org/api/option" + "google.golang.org/api/option/internaloption" + httptransport "google.golang.org/api/transport/http" + computepb "google.golang.org/genproto/googleapis/cloud/compute/v1" + "google.golang.org/grpc" + "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/encoding/protojson" +) + +var newImagesClientHook clientHook + +// ImagesCallOptions contains the retry settings for each method of ImagesClient. +type ImagesCallOptions struct { + Delete []gax.CallOption + Deprecate []gax.CallOption + Get []gax.CallOption + GetFromFamily []gax.CallOption + GetIamPolicy []gax.CallOption + Insert []gax.CallOption + List []gax.CallOption + Patch []gax.CallOption + SetIamPolicy []gax.CallOption + SetLabels []gax.CallOption + TestIamPermissions []gax.CallOption +} + +// internalImagesClient is an interface that defines the methods availaible from Google Compute Engine API. +type internalImagesClient interface { + Close() error + setGoogleClientInfo(...string) + Connection() *grpc.ClientConn + Delete(context.Context, *computepb.DeleteImageRequest, ...gax.CallOption) (*computepb.Operation, error) + Deprecate(context.Context, *computepb.DeprecateImageRequest, ...gax.CallOption) (*computepb.Operation, error) + Get(context.Context, *computepb.GetImageRequest, ...gax.CallOption) (*computepb.Image, error) + GetFromFamily(context.Context, *computepb.GetFromFamilyImageRequest, ...gax.CallOption) (*computepb.Image, error) + GetIamPolicy(context.Context, *computepb.GetIamPolicyImageRequest, ...gax.CallOption) (*computepb.Policy, error) + Insert(context.Context, *computepb.InsertImageRequest, ...gax.CallOption) (*computepb.Operation, error) + List(context.Context, *computepb.ListImagesRequest, ...gax.CallOption) (*computepb.ImageList, error) + Patch(context.Context, *computepb.PatchImageRequest, ...gax.CallOption) (*computepb.Operation, error) + SetIamPolicy(context.Context, *computepb.SetIamPolicyImageRequest, ...gax.CallOption) (*computepb.Policy, error) + SetLabels(context.Context, *computepb.SetLabelsImageRequest, ...gax.CallOption) (*computepb.Operation, error) + TestIamPermissions(context.Context, *computepb.TestIamPermissionsImageRequest, ...gax.CallOption) (*computepb.TestPermissionsResponse, error) +} + +// ImagesClient is a client for interacting with Google Compute Engine API. +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +// +// The Images API. +type ImagesClient struct { + // The internal transport-dependent client. + internalClient internalImagesClient + + // The call options for this service. + CallOptions *ImagesCallOptions +} + +// 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 *ImagesClient) 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 *ImagesClient) setGoogleClientInfo(keyval ...string) { + c.internalClient.setGoogleClientInfo(keyval...) +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *ImagesClient) Connection() *grpc.ClientConn { + return c.internalClient.Connection() +} + +// Delete deletes the specified image. +func (c *ImagesClient) Delete(ctx context.Context, req *computepb.DeleteImageRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.Delete(ctx, req, opts...) +} + +// Deprecate sets the deprecation status of an image. +// +// If an empty request body is given, clears the deprecation status instead. +func (c *ImagesClient) Deprecate(ctx context.Context, req *computepb.DeprecateImageRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.Deprecate(ctx, req, opts...) +} + +// Get returns the specified image. Gets a list of available images by making a list() request. +func (c *ImagesClient) Get(ctx context.Context, req *computepb.GetImageRequest, opts ...gax.CallOption) (*computepb.Image, error) { + return c.internalClient.Get(ctx, req, opts...) +} + +// GetFromFamily returns the latest image that is part of an image family and is not deprecated. +func (c *ImagesClient) GetFromFamily(ctx context.Context, req *computepb.GetFromFamilyImageRequest, opts ...gax.CallOption) (*computepb.Image, error) { + return c.internalClient.GetFromFamily(ctx, req, opts...) +} + +// GetIamPolicy gets the access control policy for a resource. May be empty if no such policy or resource exists. +func (c *ImagesClient) GetIamPolicy(ctx context.Context, req *computepb.GetIamPolicyImageRequest, opts ...gax.CallOption) (*computepb.Policy, error) { + return c.internalClient.GetIamPolicy(ctx, req, opts...) +} + +// Insert creates an image in the specified project using the data included in the request. +func (c *ImagesClient) Insert(ctx context.Context, req *computepb.InsertImageRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.Insert(ctx, req, opts...) +} + +// List retrieves the list of custom images available to the specified project. Custom images are images you create that belong to your project. This method does not get any images that belong to other projects, including publicly-available images, like Debian 8. If you want to get a list of publicly-available images, use this method to make a request to the respective image project, such as debian-cloud or windows-cloud. +func (c *ImagesClient) List(ctx context.Context, req *computepb.ListImagesRequest, opts ...gax.CallOption) (*computepb.ImageList, error) { + return c.internalClient.List(ctx, req, opts...) +} + +// Patch patches the specified image with the data included in the request. Only the following fields can be modified: family, description, deprecation status. +func (c *ImagesClient) Patch(ctx context.Context, req *computepb.PatchImageRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.Patch(ctx, req, opts...) +} + +// SetIamPolicy sets the access control policy on the specified resource. Replaces any existing policy. +func (c *ImagesClient) SetIamPolicy(ctx context.Context, req *computepb.SetIamPolicyImageRequest, opts ...gax.CallOption) (*computepb.Policy, error) { + return c.internalClient.SetIamPolicy(ctx, req, opts...) +} + +// SetLabels sets the labels on an image. To learn more about labels, read the Labeling Resources documentation. +func (c *ImagesClient) SetLabels(ctx context.Context, req *computepb.SetLabelsImageRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.SetLabels(ctx, req, opts...) +} + +// TestIamPermissions returns permissions that a caller has on the specified resource. +func (c *ImagesClient) TestIamPermissions(ctx context.Context, req *computepb.TestIamPermissionsImageRequest, opts ...gax.CallOption) (*computepb.TestPermissionsResponse, error) { + return c.internalClient.TestIamPermissions(ctx, req, opts...) +} + +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +type imagesRESTClient struct { + // The http endpoint to connect to. + endpoint string + + // The http client. + httpClient *http.Client + + // The x-goog-* metadata to be sent with each request. + xGoogMetadata metadata.MD +} + +// NewImagesRESTClient creates a new images rest client. +// +// The Images API. +func NewImagesRESTClient(ctx context.Context, opts ...option.ClientOption) (*ImagesClient, error) { + clientOpts := append(defaultImagesRESTClientOptions(), opts...) + httpClient, endpoint, err := httptransport.NewClient(ctx, clientOpts...) + if err != nil { + return nil, err + } + + c := &imagesRESTClient{ + endpoint: endpoint, + httpClient: httpClient, + } + c.setGoogleClientInfo() + + return &ImagesClient{internalClient: c, CallOptions: &ImagesCallOptions{}}, nil +} + +func defaultImagesRESTClientOptions() []option.ClientOption { + return []option.ClientOption{ + internaloption.WithDefaultEndpoint("compute.googleapis.com"), + internaloption.WithDefaultMTLSEndpoint("compute.mtls.googleapis.com"), + internaloption.WithDefaultAudience("https://compute.googleapis.com/"), + internaloption.WithDefaultScopes(DefaultAuthScopes()...), + } +} + +// 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 *imagesRESTClient) setGoogleClientInfo(keyval ...string) { + kv := append([]string{"gl-go", versionGo()}, keyval...) + kv = append(kv, "gapic", versionClient, "gax", gax.Version, "rest", "UNKNOWN") + 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 *imagesRESTClient) Close() error { + // Replace httpClient with nil to force cleanup. + c.httpClient = nil + return nil +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *imagesRESTClient) Connection() *grpc.ClientConn { + return nil +} + +// Delete deletes the specified image. +func (c *imagesRESTClient) Delete(ctx context.Context, req *computepb.DeleteImageRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/images/%v", req.GetProject(), req.GetImage()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("DELETE", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Deprecate sets the deprecation status of an image. +// +// If an empty request body is given, clears the deprecation status instead. +func (c *imagesRESTClient) Deprecate(ctx context.Context, req *computepb.DeprecateImageRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetDeprecationStatusResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/images/%v/deprecate", req.GetProject(), req.GetImage()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Get returns the specified image. Gets a list of available images by making a list() request. +func (c *imagesRESTClient) Get(ctx context.Context, req *computepb.GetImageRequest, opts ...gax.CallOption) (*computepb.Image, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/images/%v", req.GetProject(), req.GetImage()) + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Image{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// GetFromFamily returns the latest image that is part of an image family and is not deprecated. +func (c *imagesRESTClient) GetFromFamily(ctx context.Context, req *computepb.GetFromFamilyImageRequest, opts ...gax.CallOption) (*computepb.Image, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/images/family/%v", req.GetProject(), req.GetFamily()) + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Image{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// GetIamPolicy gets the access control policy for a resource. May be empty if no such policy or resource exists. +func (c *imagesRESTClient) GetIamPolicy(ctx context.Context, req *computepb.GetIamPolicyImageRequest, opts ...gax.CallOption) (*computepb.Policy, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/images/%v/getIamPolicy", req.GetProject(), req.GetResource()) + + params := url.Values{} + if req != nil && req.OptionsRequestedPolicyVersion != nil { + params.Add("optionsRequestedPolicyVersion", fmt.Sprintf("%v", req.GetOptionsRequestedPolicyVersion())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Policy{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Insert creates an image in the specified project using the data included in the request. +func (c *imagesRESTClient) Insert(ctx context.Context, req *computepb.InsertImageRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetImageResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/images", req.GetProject()) + + params := url.Values{} + if req != nil && req.ForceCreate != nil { + params.Add("forceCreate", fmt.Sprintf("%v", req.GetForceCreate())) + } + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// List retrieves the list of custom images available to the specified project. Custom images are images you create that belong to your project. This method does not get any images that belong to other projects, including publicly-available images, like Debian 8. If you want to get a list of publicly-available images, use this method to make a request to the respective image project, such as debian-cloud or windows-cloud. +func (c *imagesRESTClient) List(ctx context.Context, req *computepb.ListImagesRequest, opts ...gax.CallOption) (*computepb.ImageList, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/images", req.GetProject()) + + params := url.Values{} + if req != nil && req.Filter != nil { + params.Add("filter", fmt.Sprintf("%v", req.GetFilter())) + } + if req != nil && req.MaxResults != nil { + params.Add("maxResults", fmt.Sprintf("%v", req.GetMaxResults())) + } + if req != nil && req.OrderBy != nil { + params.Add("orderBy", fmt.Sprintf("%v", req.GetOrderBy())) + } + if req != nil && req.PageToken != nil { + params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) + } + if req != nil && req.ReturnPartialSuccess != nil { + params.Add("returnPartialSuccess", fmt.Sprintf("%v", req.GetReturnPartialSuccess())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.ImageList{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Patch patches the specified image with the data included in the request. Only the following fields can be modified: family, description, deprecation status. +func (c *imagesRESTClient) Patch(ctx context.Context, req *computepb.PatchImageRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetImageResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/images/%v", req.GetProject(), req.GetImage()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("PATCH", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// SetIamPolicy sets the access control policy on the specified resource. Replaces any existing policy. +func (c *imagesRESTClient) SetIamPolicy(ctx context.Context, req *computepb.SetIamPolicyImageRequest, opts ...gax.CallOption) (*computepb.Policy, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetGlobalSetPolicyRequestResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/images/%v/setIamPolicy", req.GetProject(), req.GetResource()) + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Policy{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// SetLabels sets the labels on an image. To learn more about labels, read the Labeling Resources documentation. +func (c *imagesRESTClient) SetLabels(ctx context.Context, req *computepb.SetLabelsImageRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetGlobalSetLabelsRequestResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/images/%v/setLabels", req.GetProject(), req.GetResource()) + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// TestIamPermissions returns permissions that a caller has on the specified resource. +func (c *imagesRESTClient) TestIamPermissions(ctx context.Context, req *computepb.TestIamPermissionsImageRequest, opts ...gax.CallOption) (*computepb.TestPermissionsResponse, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetTestPermissionsRequestResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/images/%v/testIamPermissions", req.GetProject(), req.GetResource()) + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.TestPermissionsResponse{} + + return rsp, unm.Unmarshal(buf, rsp) +} diff --git a/compute/apiv1/images_client_example_test.go b/compute/apiv1/images_client_example_test.go new file mode 100644 index 00000000000..30c38152544 --- /dev/null +++ b/compute/apiv1/images_client_example_test.go @@ -0,0 +1,245 @@ +// 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 compute_test + +import ( + "context" + + compute "cloud.google.com/go/compute/apiv1" + computepb "google.golang.org/genproto/googleapis/cloud/compute/v1" +) + +func ExampleNewImagesRESTClient() { + ctx := context.Background() + c, err := compute.NewImagesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + // TODO: Use client. + _ = c +} + +func ExampleImagesClient_Delete() { + ctx := context.Background() + c, err := compute.NewImagesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.DeleteImageRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Delete(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleImagesClient_Deprecate() { + ctx := context.Background() + c, err := compute.NewImagesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.DeprecateImageRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Deprecate(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleImagesClient_Get() { + ctx := context.Background() + c, err := compute.NewImagesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.GetImageRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Get(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleImagesClient_GetFromFamily() { + ctx := context.Background() + c, err := compute.NewImagesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.GetFromFamilyImageRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.GetFromFamily(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleImagesClient_GetIamPolicy() { + ctx := context.Background() + c, err := compute.NewImagesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.GetIamPolicyImageRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.GetIamPolicy(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleImagesClient_Insert() { + ctx := context.Background() + c, err := compute.NewImagesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.InsertImageRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Insert(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleImagesClient_List() { + ctx := context.Background() + c, err := compute.NewImagesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.ListImagesRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.List(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleImagesClient_Patch() { + ctx := context.Background() + c, err := compute.NewImagesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.PatchImageRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Patch(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleImagesClient_SetIamPolicy() { + ctx := context.Background() + c, err := compute.NewImagesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.SetIamPolicyImageRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.SetIamPolicy(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleImagesClient_SetLabels() { + ctx := context.Background() + c, err := compute.NewImagesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.SetLabelsImageRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.SetLabels(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleImagesClient_TestIamPermissions() { + ctx := context.Background() + c, err := compute.NewImagesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.TestIamPermissionsImageRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.TestIamPermissions(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} diff --git a/compute/apiv1/instance_group_managers_client.go b/compute/apiv1/instance_group_managers_client.go new file mode 100644 index 00000000000..63039526088 --- /dev/null +++ b/compute/apiv1/instance_group_managers_client.go @@ -0,0 +1,1387 @@ +// 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 compute + +import ( + "bytes" + "context" + "fmt" + "io/ioutil" + "net/http" + "net/url" + + gax "github.com/googleapis/gax-go/v2" + "google.golang.org/api/option" + "google.golang.org/api/option/internaloption" + httptransport "google.golang.org/api/transport/http" + computepb "google.golang.org/genproto/googleapis/cloud/compute/v1" + "google.golang.org/grpc" + "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/encoding/protojson" +) + +var newInstanceGroupManagersClientHook clientHook + +// InstanceGroupManagersCallOptions contains the retry settings for each method of InstanceGroupManagersClient. +type InstanceGroupManagersCallOptions struct { + AbandonInstances []gax.CallOption + AggregatedList []gax.CallOption + ApplyUpdatesToInstances []gax.CallOption + CreateInstances []gax.CallOption + Delete []gax.CallOption + DeleteInstances []gax.CallOption + DeletePerInstanceConfigs []gax.CallOption + Get []gax.CallOption + Insert []gax.CallOption + List []gax.CallOption + ListErrors []gax.CallOption + ListManagedInstances []gax.CallOption + ListPerInstanceConfigs []gax.CallOption + Patch []gax.CallOption + PatchPerInstanceConfigs []gax.CallOption + RecreateInstances []gax.CallOption + Resize []gax.CallOption + SetInstanceTemplate []gax.CallOption + SetTargetPools []gax.CallOption + UpdatePerInstanceConfigs []gax.CallOption +} + +// internalInstanceGroupManagersClient is an interface that defines the methods availaible from Google Compute Engine API. +type internalInstanceGroupManagersClient interface { + Close() error + setGoogleClientInfo(...string) + Connection() *grpc.ClientConn + AbandonInstances(context.Context, *computepb.AbandonInstancesInstanceGroupManagerRequest, ...gax.CallOption) (*computepb.Operation, error) + AggregatedList(context.Context, *computepb.AggregatedListInstanceGroupManagersRequest, ...gax.CallOption) (*computepb.InstanceGroupManagerAggregatedList, error) + ApplyUpdatesToInstances(context.Context, *computepb.ApplyUpdatesToInstancesInstanceGroupManagerRequest, ...gax.CallOption) (*computepb.Operation, error) + CreateInstances(context.Context, *computepb.CreateInstancesInstanceGroupManagerRequest, ...gax.CallOption) (*computepb.Operation, error) + Delete(context.Context, *computepb.DeleteInstanceGroupManagerRequest, ...gax.CallOption) (*computepb.Operation, error) + DeleteInstances(context.Context, *computepb.DeleteInstancesInstanceGroupManagerRequest, ...gax.CallOption) (*computepb.Operation, error) + DeletePerInstanceConfigs(context.Context, *computepb.DeletePerInstanceConfigsInstanceGroupManagerRequest, ...gax.CallOption) (*computepb.Operation, error) + Get(context.Context, *computepb.GetInstanceGroupManagerRequest, ...gax.CallOption) (*computepb.InstanceGroupManager, error) + Insert(context.Context, *computepb.InsertInstanceGroupManagerRequest, ...gax.CallOption) (*computepb.Operation, error) + List(context.Context, *computepb.ListInstanceGroupManagersRequest, ...gax.CallOption) (*computepb.InstanceGroupManagerList, error) + ListErrors(context.Context, *computepb.ListErrorsInstanceGroupManagersRequest, ...gax.CallOption) (*computepb.InstanceGroupManagersListErrorsResponse, error) + ListManagedInstances(context.Context, *computepb.ListManagedInstancesInstanceGroupManagersRequest, ...gax.CallOption) (*computepb.InstanceGroupManagersListManagedInstancesResponse, error) + ListPerInstanceConfigs(context.Context, *computepb.ListPerInstanceConfigsInstanceGroupManagersRequest, ...gax.CallOption) (*computepb.InstanceGroupManagersListPerInstanceConfigsResp, error) + Patch(context.Context, *computepb.PatchInstanceGroupManagerRequest, ...gax.CallOption) (*computepb.Operation, error) + PatchPerInstanceConfigs(context.Context, *computepb.PatchPerInstanceConfigsInstanceGroupManagerRequest, ...gax.CallOption) (*computepb.Operation, error) + RecreateInstances(context.Context, *computepb.RecreateInstancesInstanceGroupManagerRequest, ...gax.CallOption) (*computepb.Operation, error) + Resize(context.Context, *computepb.ResizeInstanceGroupManagerRequest, ...gax.CallOption) (*computepb.Operation, error) + SetInstanceTemplate(context.Context, *computepb.SetInstanceTemplateInstanceGroupManagerRequest, ...gax.CallOption) (*computepb.Operation, error) + SetTargetPools(context.Context, *computepb.SetTargetPoolsInstanceGroupManagerRequest, ...gax.CallOption) (*computepb.Operation, error) + UpdatePerInstanceConfigs(context.Context, *computepb.UpdatePerInstanceConfigsInstanceGroupManagerRequest, ...gax.CallOption) (*computepb.Operation, error) +} + +// InstanceGroupManagersClient is a client for interacting with Google Compute Engine API. +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +// +// The InstanceGroupManagers API. +type InstanceGroupManagersClient struct { + // The internal transport-dependent client. + internalClient internalInstanceGroupManagersClient + + // The call options for this service. + CallOptions *InstanceGroupManagersCallOptions +} + +// 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 *InstanceGroupManagersClient) 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 *InstanceGroupManagersClient) setGoogleClientInfo(keyval ...string) { + c.internalClient.setGoogleClientInfo(keyval...) +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *InstanceGroupManagersClient) Connection() *grpc.ClientConn { + return c.internalClient.Connection() +} + +// AbandonInstances flags the specified instances to be removed from the managed instance group. Abandoning an instance does not delete the instance, but it does remove the instance from any target pools that are applied by the managed instance group. This method reduces the targetSize of the managed instance group by the number of instances that you abandon. This operation is marked as DONE when the action is scheduled even if the instances have not yet been removed from the group. You must separately verify the status of the abandoning action with the listmanagedinstances method. +// +// If the group is part of a backend service that has enabled connection draining, it can take up to 60 seconds after the connection draining duration has elapsed before the VM instance is removed or deleted. +// +// You can specify a maximum of 1000 instances with this method per request. +func (c *InstanceGroupManagersClient) AbandonInstances(ctx context.Context, req *computepb.AbandonInstancesInstanceGroupManagerRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.AbandonInstances(ctx, req, opts...) +} + +// AggregatedList retrieves the list of managed instance groups and groups them by zone. +func (c *InstanceGroupManagersClient) AggregatedList(ctx context.Context, req *computepb.AggregatedListInstanceGroupManagersRequest, opts ...gax.CallOption) (*computepb.InstanceGroupManagerAggregatedList, error) { + return c.internalClient.AggregatedList(ctx, req, opts...) +} + +// ApplyUpdatesToInstances applies changes to selected instances on the managed instance group. This method can be used to apply new overrides and/or new versions. +func (c *InstanceGroupManagersClient) ApplyUpdatesToInstances(ctx context.Context, req *computepb.ApplyUpdatesToInstancesInstanceGroupManagerRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.ApplyUpdatesToInstances(ctx, req, opts...) +} + +// CreateInstances creates instances with per-instance configs in this managed instance group. Instances are created using the current instance template. The create instances operation is marked DONE if the createInstances request is successful. The underlying actions take additional time. You must separately verify the status of the creating or actions with the listmanagedinstances method. +func (c *InstanceGroupManagersClient) CreateInstances(ctx context.Context, req *computepb.CreateInstancesInstanceGroupManagerRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.CreateInstances(ctx, req, opts...) +} + +// Delete deletes the specified managed instance group and all of the instances in that group. Note that the instance group must not belong to a backend service. Read Deleting an instance group for more information. +func (c *InstanceGroupManagersClient) Delete(ctx context.Context, req *computepb.DeleteInstanceGroupManagerRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.Delete(ctx, req, opts...) +} + +// DeleteInstances flags the specified instances in the managed instance group for immediate deletion. The instances are also removed from any target pools of which they were a member. This method reduces the targetSize of the managed instance group by the number of instances that you delete. This operation is marked as DONE when the action is scheduled even if the instances are still being deleted. You must separately verify the status of the deleting action with the listmanagedinstances method. +// +// If the group is part of a backend service that has enabled connection draining, it can take up to 60 seconds after the connection draining duration has elapsed before the VM instance is removed or deleted. +// +// You can specify a maximum of 1000 instances with this method per request. +func (c *InstanceGroupManagersClient) DeleteInstances(ctx context.Context, req *computepb.DeleteInstancesInstanceGroupManagerRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.DeleteInstances(ctx, req, opts...) +} + +// DeletePerInstanceConfigs deletes selected per-instance configs for the managed instance group. +func (c *InstanceGroupManagersClient) DeletePerInstanceConfigs(ctx context.Context, req *computepb.DeletePerInstanceConfigsInstanceGroupManagerRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.DeletePerInstanceConfigs(ctx, req, opts...) +} + +// Get returns all of the details about the specified managed instance group. Gets a list of available managed instance groups by making a list() request. +func (c *InstanceGroupManagersClient) Get(ctx context.Context, req *computepb.GetInstanceGroupManagerRequest, opts ...gax.CallOption) (*computepb.InstanceGroupManager, error) { + return c.internalClient.Get(ctx, req, opts...) +} + +// Insert creates a managed instance group using the information that you specify in the request. After the group is created, instances in the group are created using the specified instance template. This operation is marked as DONE when the group is created even if the instances in the group have not yet been created. You must separately verify the status of the individual instances with the listmanagedinstances method. +// +// A managed instance group can have up to 1000 VM instances per group. Please contact Cloud Support if you need an increase in this limit. +func (c *InstanceGroupManagersClient) Insert(ctx context.Context, req *computepb.InsertInstanceGroupManagerRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.Insert(ctx, req, opts...) +} + +// List retrieves a list of managed instance groups that are contained within the specified project and zone. +func (c *InstanceGroupManagersClient) List(ctx context.Context, req *computepb.ListInstanceGroupManagersRequest, opts ...gax.CallOption) (*computepb.InstanceGroupManagerList, error) { + return c.internalClient.List(ctx, req, opts...) +} + +// ListErrors lists all errors thrown by actions on instances for a given managed instance group. The filter and orderBy query parameters are not supported. +func (c *InstanceGroupManagersClient) ListErrors(ctx context.Context, req *computepb.ListErrorsInstanceGroupManagersRequest, opts ...gax.CallOption) (*computepb.InstanceGroupManagersListErrorsResponse, error) { + return c.internalClient.ListErrors(ctx, req, opts...) +} + +// ListManagedInstances lists all of the instances in the managed instance group. Each instance in the list has a currentAction, which indicates the action that the managed instance group is performing on the instance. For example, if the group is still creating an instance, the currentAction is CREATING. If a previous action failed, the list displays the errors for that failed action. The orderBy query parameter is not supported. +func (c *InstanceGroupManagersClient) ListManagedInstances(ctx context.Context, req *computepb.ListManagedInstancesInstanceGroupManagersRequest, opts ...gax.CallOption) (*computepb.InstanceGroupManagersListManagedInstancesResponse, error) { + return c.internalClient.ListManagedInstances(ctx, req, opts...) +} + +// ListPerInstanceConfigs lists all of the per-instance configs defined for the managed instance group. The orderBy query parameter is not supported. +func (c *InstanceGroupManagersClient) ListPerInstanceConfigs(ctx context.Context, req *computepb.ListPerInstanceConfigsInstanceGroupManagersRequest, opts ...gax.CallOption) (*computepb.InstanceGroupManagersListPerInstanceConfigsResp, error) { + return c.internalClient.ListPerInstanceConfigs(ctx, req, opts...) +} + +// Patch updates a managed instance group using the information that you specify in the request. This operation is marked as DONE when the group is patched even if the instances in the group are still in the process of being patched. You must separately verify the status of the individual instances with the listManagedInstances method. This method supports PATCH semantics and uses the JSON merge patch format and processing rules. +func (c *InstanceGroupManagersClient) Patch(ctx context.Context, req *computepb.PatchInstanceGroupManagerRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.Patch(ctx, req, opts...) +} + +// PatchPerInstanceConfigs inserts or patches per-instance configs for the managed instance group. perInstanceConfig.name (at http://perInstanceConfig.name) serves as a key used to distinguish whether to perform insert or patch. +func (c *InstanceGroupManagersClient) PatchPerInstanceConfigs(ctx context.Context, req *computepb.PatchPerInstanceConfigsInstanceGroupManagerRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.PatchPerInstanceConfigs(ctx, req, opts...) +} + +// RecreateInstances flags the specified VM instances in the managed instance group to be immediately recreated. Each instance is recreated using the group’s current configuration. This operation is marked as DONE when the flag is set even if the instances have not yet been recreated. You must separately verify the status of each instance by checking its currentAction field; for more information, see Checking the status of managed instances. +// +// If the group is part of a backend service that has enabled connection draining, it can take up to 60 seconds after the connection draining duration has elapsed before the VM instance is removed or deleted. +// +// You can specify a maximum of 1000 instances with this method per request. +func (c *InstanceGroupManagersClient) RecreateInstances(ctx context.Context, req *computepb.RecreateInstancesInstanceGroupManagerRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.RecreateInstances(ctx, req, opts...) +} + +// Resize resizes the managed instance group. If you increase the size, the group creates new instances using the current instance template. If you decrease the size, the group deletes instances. The resize operation is marked DONE when the resize actions are scheduled even if the group has not yet added or deleted any instances. You must separately verify the status of the creating or deleting actions with the listmanagedinstances method. +// +// When resizing down, the instance group arbitrarily chooses the order in which VMs are deleted. The group takes into account some VM attributes when making the selection including: +// +// The status of the VM instance. + The health of the VM instance. + The instance template version the VM is based on. + For regional managed instance groups, the location of the VM instance. +// +// This list is subject to change. +// +// If the group is part of a backend service that has enabled connection draining, it can take up to 60 seconds after the connection draining duration has elapsed before the VM instance is removed or deleted. +func (c *InstanceGroupManagersClient) Resize(ctx context.Context, req *computepb.ResizeInstanceGroupManagerRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.Resize(ctx, req, opts...) +} + +// SetInstanceTemplate specifies the instance template to use when creating new instances in this group. The templates for existing instances in the group do not change unless you run recreateInstances, run applyUpdatesToInstances, or set the group’s updatePolicy.type to PROACTIVE. +func (c *InstanceGroupManagersClient) SetInstanceTemplate(ctx context.Context, req *computepb.SetInstanceTemplateInstanceGroupManagerRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.SetInstanceTemplate(ctx, req, opts...) +} + +// SetTargetPools modifies the target pools to which all instances in this managed instance group are assigned. The target pools automatically apply to all of the instances in the managed instance group. This operation is marked DONE when you make the request even if the instances have not yet been added to their target pools. The change might take some time to apply to all of the instances in the group depending on the size of the group. +func (c *InstanceGroupManagersClient) SetTargetPools(ctx context.Context, req *computepb.SetTargetPoolsInstanceGroupManagerRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.SetTargetPools(ctx, req, opts...) +} + +// UpdatePerInstanceConfigs inserts or updates per-instance configs for the managed instance group. perInstanceConfig.name (at http://perInstanceConfig.name) serves as a key used to distinguish whether to perform insert or patch. +func (c *InstanceGroupManagersClient) UpdatePerInstanceConfigs(ctx context.Context, req *computepb.UpdatePerInstanceConfigsInstanceGroupManagerRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.UpdatePerInstanceConfigs(ctx, req, opts...) +} + +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +type instanceGroupManagersRESTClient struct { + // The http endpoint to connect to. + endpoint string + + // The http client. + httpClient *http.Client + + // The x-goog-* metadata to be sent with each request. + xGoogMetadata metadata.MD +} + +// NewInstanceGroupManagersRESTClient creates a new instance group managers rest client. +// +// The InstanceGroupManagers API. +func NewInstanceGroupManagersRESTClient(ctx context.Context, opts ...option.ClientOption) (*InstanceGroupManagersClient, error) { + clientOpts := append(defaultInstanceGroupManagersRESTClientOptions(), opts...) + httpClient, endpoint, err := httptransport.NewClient(ctx, clientOpts...) + if err != nil { + return nil, err + } + + c := &instanceGroupManagersRESTClient{ + endpoint: endpoint, + httpClient: httpClient, + } + c.setGoogleClientInfo() + + return &InstanceGroupManagersClient{internalClient: c, CallOptions: &InstanceGroupManagersCallOptions{}}, nil +} + +func defaultInstanceGroupManagersRESTClientOptions() []option.ClientOption { + return []option.ClientOption{ + internaloption.WithDefaultEndpoint("compute.googleapis.com"), + internaloption.WithDefaultMTLSEndpoint("compute.mtls.googleapis.com"), + internaloption.WithDefaultAudience("https://compute.googleapis.com/"), + internaloption.WithDefaultScopes(DefaultAuthScopes()...), + } +} + +// 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 *instanceGroupManagersRESTClient) setGoogleClientInfo(keyval ...string) { + kv := append([]string{"gl-go", versionGo()}, keyval...) + kv = append(kv, "gapic", versionClient, "gax", gax.Version, "rest", "UNKNOWN") + 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 *instanceGroupManagersRESTClient) Close() error { + // Replace httpClient with nil to force cleanup. + c.httpClient = nil + return nil +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *instanceGroupManagersRESTClient) Connection() *grpc.ClientConn { + return nil +} + +// AbandonInstances flags the specified instances to be removed from the managed instance group. Abandoning an instance does not delete the instance, but it does remove the instance from any target pools that are applied by the managed instance group. This method reduces the targetSize of the managed instance group by the number of instances that you abandon. This operation is marked as DONE when the action is scheduled even if the instances have not yet been removed from the group. You must separately verify the status of the abandoning action with the listmanagedinstances method. +// +// If the group is part of a backend service that has enabled connection draining, it can take up to 60 seconds after the connection draining duration has elapsed before the VM instance is removed or deleted. +// +// You can specify a maximum of 1000 instances with this method per request. +func (c *instanceGroupManagersRESTClient) AbandonInstances(ctx context.Context, req *computepb.AbandonInstancesInstanceGroupManagerRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetInstanceGroupManagersAbandonInstancesRequestResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/zones/%v/instanceGroupManagers/%v/abandonInstances", req.GetProject(), req.GetZone(), req.GetInstanceGroupManager()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// AggregatedList retrieves the list of managed instance groups and groups them by zone. +func (c *instanceGroupManagersRESTClient) AggregatedList(ctx context.Context, req *computepb.AggregatedListInstanceGroupManagersRequest, opts ...gax.CallOption) (*computepb.InstanceGroupManagerAggregatedList, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/aggregated/instanceGroupManagers", req.GetProject()) + + params := url.Values{} + if req != nil && req.Filter != nil { + params.Add("filter", fmt.Sprintf("%v", req.GetFilter())) + } + if req != nil && req.IncludeAllScopes != nil { + params.Add("includeAllScopes", fmt.Sprintf("%v", req.GetIncludeAllScopes())) + } + if req != nil && req.MaxResults != nil { + params.Add("maxResults", fmt.Sprintf("%v", req.GetMaxResults())) + } + if req != nil && req.OrderBy != nil { + params.Add("orderBy", fmt.Sprintf("%v", req.GetOrderBy())) + } + if req != nil && req.PageToken != nil { + params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) + } + if req != nil && req.ReturnPartialSuccess != nil { + params.Add("returnPartialSuccess", fmt.Sprintf("%v", req.GetReturnPartialSuccess())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.InstanceGroupManagerAggregatedList{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// ApplyUpdatesToInstances applies changes to selected instances on the managed instance group. This method can be used to apply new overrides and/or new versions. +func (c *instanceGroupManagersRESTClient) ApplyUpdatesToInstances(ctx context.Context, req *computepb.ApplyUpdatesToInstancesInstanceGroupManagerRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetInstanceGroupManagersApplyUpdatesRequestResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/zones/%v/instanceGroupManagers/%v/applyUpdatesToInstances", req.GetProject(), req.GetZone(), req.GetInstanceGroupManager()) + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// CreateInstances creates instances with per-instance configs in this managed instance group. Instances are created using the current instance template. The create instances operation is marked DONE if the createInstances request is successful. The underlying actions take additional time. You must separately verify the status of the creating or actions with the listmanagedinstances method. +func (c *instanceGroupManagersRESTClient) CreateInstances(ctx context.Context, req *computepb.CreateInstancesInstanceGroupManagerRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetInstanceGroupManagersCreateInstancesRequestResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/zones/%v/instanceGroupManagers/%v/createInstances", req.GetProject(), req.GetZone(), req.GetInstanceGroupManager()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Delete deletes the specified managed instance group and all of the instances in that group. Note that the instance group must not belong to a backend service. Read Deleting an instance group for more information. +func (c *instanceGroupManagersRESTClient) Delete(ctx context.Context, req *computepb.DeleteInstanceGroupManagerRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/zones/%v/instanceGroupManagers/%v", req.GetProject(), req.GetZone(), req.GetInstanceGroupManager()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("DELETE", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// DeleteInstances flags the specified instances in the managed instance group for immediate deletion. The instances are also removed from any target pools of which they were a member. This method reduces the targetSize of the managed instance group by the number of instances that you delete. This operation is marked as DONE when the action is scheduled even if the instances are still being deleted. You must separately verify the status of the deleting action with the listmanagedinstances method. +// +// If the group is part of a backend service that has enabled connection draining, it can take up to 60 seconds after the connection draining duration has elapsed before the VM instance is removed or deleted. +// +// You can specify a maximum of 1000 instances with this method per request. +func (c *instanceGroupManagersRESTClient) DeleteInstances(ctx context.Context, req *computepb.DeleteInstancesInstanceGroupManagerRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetInstanceGroupManagersDeleteInstancesRequestResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/zones/%v/instanceGroupManagers/%v/deleteInstances", req.GetProject(), req.GetZone(), req.GetInstanceGroupManager()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// DeletePerInstanceConfigs deletes selected per-instance configs for the managed instance group. +func (c *instanceGroupManagersRESTClient) DeletePerInstanceConfigs(ctx context.Context, req *computepb.DeletePerInstanceConfigsInstanceGroupManagerRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetInstanceGroupManagersDeletePerInstanceConfigsReqResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/zones/%v/instanceGroupManagers/%v/deletePerInstanceConfigs", req.GetProject(), req.GetZone(), req.GetInstanceGroupManager()) + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Get returns all of the details about the specified managed instance group. Gets a list of available managed instance groups by making a list() request. +func (c *instanceGroupManagersRESTClient) Get(ctx context.Context, req *computepb.GetInstanceGroupManagerRequest, opts ...gax.CallOption) (*computepb.InstanceGroupManager, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/zones/%v/instanceGroupManagers/%v", req.GetProject(), req.GetZone(), req.GetInstanceGroupManager()) + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.InstanceGroupManager{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Insert creates a managed instance group using the information that you specify in the request. After the group is created, instances in the group are created using the specified instance template. This operation is marked as DONE when the group is created even if the instances in the group have not yet been created. You must separately verify the status of the individual instances with the listmanagedinstances method. +// +// A managed instance group can have up to 1000 VM instances per group. Please contact Cloud Support if you need an increase in this limit. +func (c *instanceGroupManagersRESTClient) Insert(ctx context.Context, req *computepb.InsertInstanceGroupManagerRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetInstanceGroupManagerResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/zones/%v/instanceGroupManagers", req.GetProject(), req.GetZone()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// List retrieves a list of managed instance groups that are contained within the specified project and zone. +func (c *instanceGroupManagersRESTClient) List(ctx context.Context, req *computepb.ListInstanceGroupManagersRequest, opts ...gax.CallOption) (*computepb.InstanceGroupManagerList, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/zones/%v/instanceGroupManagers", req.GetProject(), req.GetZone()) + + params := url.Values{} + if req != nil && req.Filter != nil { + params.Add("filter", fmt.Sprintf("%v", req.GetFilter())) + } + if req != nil && req.MaxResults != nil { + params.Add("maxResults", fmt.Sprintf("%v", req.GetMaxResults())) + } + if req != nil && req.OrderBy != nil { + params.Add("orderBy", fmt.Sprintf("%v", req.GetOrderBy())) + } + if req != nil && req.PageToken != nil { + params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) + } + if req != nil && req.ReturnPartialSuccess != nil { + params.Add("returnPartialSuccess", fmt.Sprintf("%v", req.GetReturnPartialSuccess())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.InstanceGroupManagerList{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// ListErrors lists all errors thrown by actions on instances for a given managed instance group. The filter and orderBy query parameters are not supported. +func (c *instanceGroupManagersRESTClient) ListErrors(ctx context.Context, req *computepb.ListErrorsInstanceGroupManagersRequest, opts ...gax.CallOption) (*computepb.InstanceGroupManagersListErrorsResponse, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/zones/%v/instanceGroupManagers/%v/listErrors", req.GetProject(), req.GetZone(), req.GetInstanceGroupManager()) + + params := url.Values{} + if req != nil && req.Filter != nil { + params.Add("filter", fmt.Sprintf("%v", req.GetFilter())) + } + if req != nil && req.MaxResults != nil { + params.Add("maxResults", fmt.Sprintf("%v", req.GetMaxResults())) + } + if req != nil && req.OrderBy != nil { + params.Add("orderBy", fmt.Sprintf("%v", req.GetOrderBy())) + } + if req != nil && req.PageToken != nil { + params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) + } + if req != nil && req.ReturnPartialSuccess != nil { + params.Add("returnPartialSuccess", fmt.Sprintf("%v", req.GetReturnPartialSuccess())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.InstanceGroupManagersListErrorsResponse{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// ListManagedInstances lists all of the instances in the managed instance group. Each instance in the list has a currentAction, which indicates the action that the managed instance group is performing on the instance. For example, if the group is still creating an instance, the currentAction is CREATING. If a previous action failed, the list displays the errors for that failed action. The orderBy query parameter is not supported. +func (c *instanceGroupManagersRESTClient) ListManagedInstances(ctx context.Context, req *computepb.ListManagedInstancesInstanceGroupManagersRequest, opts ...gax.CallOption) (*computepb.InstanceGroupManagersListManagedInstancesResponse, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/zones/%v/instanceGroupManagers/%v/listManagedInstances", req.GetProject(), req.GetZone(), req.GetInstanceGroupManager()) + + params := url.Values{} + if req != nil && req.Filter != nil { + params.Add("filter", fmt.Sprintf("%v", req.GetFilter())) + } + if req != nil && req.MaxResults != nil { + params.Add("maxResults", fmt.Sprintf("%v", req.GetMaxResults())) + } + if req != nil && req.OrderBy != nil { + params.Add("orderBy", fmt.Sprintf("%v", req.GetOrderBy())) + } + if req != nil && req.PageToken != nil { + params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) + } + if req != nil && req.ReturnPartialSuccess != nil { + params.Add("returnPartialSuccess", fmt.Sprintf("%v", req.GetReturnPartialSuccess())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.InstanceGroupManagersListManagedInstancesResponse{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// ListPerInstanceConfigs lists all of the per-instance configs defined for the managed instance group. The orderBy query parameter is not supported. +func (c *instanceGroupManagersRESTClient) ListPerInstanceConfigs(ctx context.Context, req *computepb.ListPerInstanceConfigsInstanceGroupManagersRequest, opts ...gax.CallOption) (*computepb.InstanceGroupManagersListPerInstanceConfigsResp, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/zones/%v/instanceGroupManagers/%v/listPerInstanceConfigs", req.GetProject(), req.GetZone(), req.GetInstanceGroupManager()) + + params := url.Values{} + if req != nil && req.Filter != nil { + params.Add("filter", fmt.Sprintf("%v", req.GetFilter())) + } + if req != nil && req.MaxResults != nil { + params.Add("maxResults", fmt.Sprintf("%v", req.GetMaxResults())) + } + if req != nil && req.OrderBy != nil { + params.Add("orderBy", fmt.Sprintf("%v", req.GetOrderBy())) + } + if req != nil && req.PageToken != nil { + params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) + } + if req != nil && req.ReturnPartialSuccess != nil { + params.Add("returnPartialSuccess", fmt.Sprintf("%v", req.GetReturnPartialSuccess())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.InstanceGroupManagersListPerInstanceConfigsResp{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Patch updates a managed instance group using the information that you specify in the request. This operation is marked as DONE when the group is patched even if the instances in the group are still in the process of being patched. You must separately verify the status of the individual instances with the listManagedInstances method. This method supports PATCH semantics and uses the JSON merge patch format and processing rules. +func (c *instanceGroupManagersRESTClient) Patch(ctx context.Context, req *computepb.PatchInstanceGroupManagerRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetInstanceGroupManagerResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/zones/%v/instanceGroupManagers/%v", req.GetProject(), req.GetZone(), req.GetInstanceGroupManager()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("PATCH", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// PatchPerInstanceConfigs inserts or patches per-instance configs for the managed instance group. perInstanceConfig.name (at http://perInstanceConfig.name) serves as a key used to distinguish whether to perform insert or patch. +func (c *instanceGroupManagersRESTClient) PatchPerInstanceConfigs(ctx context.Context, req *computepb.PatchPerInstanceConfigsInstanceGroupManagerRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetInstanceGroupManagersPatchPerInstanceConfigsReqResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/zones/%v/instanceGroupManagers/%v/patchPerInstanceConfigs", req.GetProject(), req.GetZone(), req.GetInstanceGroupManager()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// RecreateInstances flags the specified VM instances in the managed instance group to be immediately recreated. Each instance is recreated using the group’s current configuration. This operation is marked as DONE when the flag is set even if the instances have not yet been recreated. You must separately verify the status of each instance by checking its currentAction field; for more information, see Checking the status of managed instances. +// +// If the group is part of a backend service that has enabled connection draining, it can take up to 60 seconds after the connection draining duration has elapsed before the VM instance is removed or deleted. +// +// You can specify a maximum of 1000 instances with this method per request. +func (c *instanceGroupManagersRESTClient) RecreateInstances(ctx context.Context, req *computepb.RecreateInstancesInstanceGroupManagerRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetInstanceGroupManagersRecreateInstancesRequestResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/zones/%v/instanceGroupManagers/%v/recreateInstances", req.GetProject(), req.GetZone(), req.GetInstanceGroupManager()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Resize resizes the managed instance group. If you increase the size, the group creates new instances using the current instance template. If you decrease the size, the group deletes instances. The resize operation is marked DONE when the resize actions are scheduled even if the group has not yet added or deleted any instances. You must separately verify the status of the creating or deleting actions with the listmanagedinstances method. +// +// When resizing down, the instance group arbitrarily chooses the order in which VMs are deleted. The group takes into account some VM attributes when making the selection including: +// +// The status of the VM instance. + The health of the VM instance. + The instance template version the VM is based on. + For regional managed instance groups, the location of the VM instance. +// +// This list is subject to change. +// +// If the group is part of a backend service that has enabled connection draining, it can take up to 60 seconds after the connection draining duration has elapsed before the VM instance is removed or deleted. +func (c *instanceGroupManagersRESTClient) Resize(ctx context.Context, req *computepb.ResizeInstanceGroupManagerRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/zones/%v/instanceGroupManagers/%v/resize", req.GetProject(), req.GetZone(), req.GetInstanceGroupManager()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + if req.GetSize() != 0 { + params.Add("size", fmt.Sprintf("%v", req.GetSize())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// SetInstanceTemplate specifies the instance template to use when creating new instances in this group. The templates for existing instances in the group do not change unless you run recreateInstances, run applyUpdatesToInstances, or set the group’s updatePolicy.type to PROACTIVE. +func (c *instanceGroupManagersRESTClient) SetInstanceTemplate(ctx context.Context, req *computepb.SetInstanceTemplateInstanceGroupManagerRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetInstanceGroupManagersSetInstanceTemplateRequestResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/zones/%v/instanceGroupManagers/%v/setInstanceTemplate", req.GetProject(), req.GetZone(), req.GetInstanceGroupManager()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// SetTargetPools modifies the target pools to which all instances in this managed instance group are assigned. The target pools automatically apply to all of the instances in the managed instance group. This operation is marked DONE when you make the request even if the instances have not yet been added to their target pools. The change might take some time to apply to all of the instances in the group depending on the size of the group. +func (c *instanceGroupManagersRESTClient) SetTargetPools(ctx context.Context, req *computepb.SetTargetPoolsInstanceGroupManagerRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetInstanceGroupManagersSetTargetPoolsRequestResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/zones/%v/instanceGroupManagers/%v/setTargetPools", req.GetProject(), req.GetZone(), req.GetInstanceGroupManager()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// UpdatePerInstanceConfigs inserts or updates per-instance configs for the managed instance group. perInstanceConfig.name (at http://perInstanceConfig.name) serves as a key used to distinguish whether to perform insert or patch. +func (c *instanceGroupManagersRESTClient) UpdatePerInstanceConfigs(ctx context.Context, req *computepb.UpdatePerInstanceConfigsInstanceGroupManagerRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetInstanceGroupManagersUpdatePerInstanceConfigsReqResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/zones/%v/instanceGroupManagers/%v/updatePerInstanceConfigs", req.GetProject(), req.GetZone(), req.GetInstanceGroupManager()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} diff --git a/compute/apiv1/instance_group_managers_client_example_test.go b/compute/apiv1/instance_group_managers_client_example_test.go new file mode 100644 index 00000000000..d5602e70117 --- /dev/null +++ b/compute/apiv1/instance_group_managers_client_example_test.go @@ -0,0 +1,416 @@ +// 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 compute_test + +import ( + "context" + + compute "cloud.google.com/go/compute/apiv1" + computepb "google.golang.org/genproto/googleapis/cloud/compute/v1" +) + +func ExampleNewInstanceGroupManagersRESTClient() { + ctx := context.Background() + c, err := compute.NewInstanceGroupManagersRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + // TODO: Use client. + _ = c +} + +func ExampleInstanceGroupManagersClient_AbandonInstances() { + ctx := context.Background() + c, err := compute.NewInstanceGroupManagersRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.AbandonInstancesInstanceGroupManagerRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.AbandonInstances(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleInstanceGroupManagersClient_AggregatedList() { + ctx := context.Background() + c, err := compute.NewInstanceGroupManagersRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.AggregatedListInstanceGroupManagersRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.AggregatedList(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleInstanceGroupManagersClient_ApplyUpdatesToInstances() { + ctx := context.Background() + c, err := compute.NewInstanceGroupManagersRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.ApplyUpdatesToInstancesInstanceGroupManagerRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.ApplyUpdatesToInstances(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleInstanceGroupManagersClient_CreateInstances() { + ctx := context.Background() + c, err := compute.NewInstanceGroupManagersRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.CreateInstancesInstanceGroupManagerRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.CreateInstances(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleInstanceGroupManagersClient_Delete() { + ctx := context.Background() + c, err := compute.NewInstanceGroupManagersRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.DeleteInstanceGroupManagerRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Delete(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleInstanceGroupManagersClient_DeleteInstances() { + ctx := context.Background() + c, err := compute.NewInstanceGroupManagersRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.DeleteInstancesInstanceGroupManagerRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.DeleteInstances(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleInstanceGroupManagersClient_DeletePerInstanceConfigs() { + ctx := context.Background() + c, err := compute.NewInstanceGroupManagersRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.DeletePerInstanceConfigsInstanceGroupManagerRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.DeletePerInstanceConfigs(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleInstanceGroupManagersClient_Get() { + ctx := context.Background() + c, err := compute.NewInstanceGroupManagersRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.GetInstanceGroupManagerRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Get(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleInstanceGroupManagersClient_Insert() { + ctx := context.Background() + c, err := compute.NewInstanceGroupManagersRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.InsertInstanceGroupManagerRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Insert(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleInstanceGroupManagersClient_List() { + ctx := context.Background() + c, err := compute.NewInstanceGroupManagersRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.ListInstanceGroupManagersRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.List(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleInstanceGroupManagersClient_ListErrors() { + ctx := context.Background() + c, err := compute.NewInstanceGroupManagersRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.ListErrorsInstanceGroupManagersRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.ListErrors(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleInstanceGroupManagersClient_ListManagedInstances() { + ctx := context.Background() + c, err := compute.NewInstanceGroupManagersRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.ListManagedInstancesInstanceGroupManagersRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.ListManagedInstances(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleInstanceGroupManagersClient_ListPerInstanceConfigs() { + ctx := context.Background() + c, err := compute.NewInstanceGroupManagersRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.ListPerInstanceConfigsInstanceGroupManagersRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.ListPerInstanceConfigs(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleInstanceGroupManagersClient_Patch() { + ctx := context.Background() + c, err := compute.NewInstanceGroupManagersRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.PatchInstanceGroupManagerRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Patch(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleInstanceGroupManagersClient_PatchPerInstanceConfigs() { + ctx := context.Background() + c, err := compute.NewInstanceGroupManagersRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.PatchPerInstanceConfigsInstanceGroupManagerRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.PatchPerInstanceConfigs(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleInstanceGroupManagersClient_RecreateInstances() { + ctx := context.Background() + c, err := compute.NewInstanceGroupManagersRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.RecreateInstancesInstanceGroupManagerRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.RecreateInstances(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleInstanceGroupManagersClient_Resize() { + ctx := context.Background() + c, err := compute.NewInstanceGroupManagersRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.ResizeInstanceGroupManagerRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Resize(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleInstanceGroupManagersClient_SetInstanceTemplate() { + ctx := context.Background() + c, err := compute.NewInstanceGroupManagersRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.SetInstanceTemplateInstanceGroupManagerRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.SetInstanceTemplate(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleInstanceGroupManagersClient_SetTargetPools() { + ctx := context.Background() + c, err := compute.NewInstanceGroupManagersRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.SetTargetPoolsInstanceGroupManagerRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.SetTargetPools(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleInstanceGroupManagersClient_UpdatePerInstanceConfigs() { + ctx := context.Background() + c, err := compute.NewInstanceGroupManagersRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.UpdatePerInstanceConfigsInstanceGroupManagerRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.UpdatePerInstanceConfigs(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} diff --git a/compute/apiv1/instance_groups_client.go b/compute/apiv1/instance_groups_client.go new file mode 100644 index 00000000000..0d57cd32151 --- /dev/null +++ b/compute/apiv1/instance_groups_client.go @@ -0,0 +1,708 @@ +// 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 compute + +import ( + "bytes" + "context" + "fmt" + "io/ioutil" + "net/http" + "net/url" + + gax "github.com/googleapis/gax-go/v2" + "google.golang.org/api/option" + "google.golang.org/api/option/internaloption" + httptransport "google.golang.org/api/transport/http" + computepb "google.golang.org/genproto/googleapis/cloud/compute/v1" + "google.golang.org/grpc" + "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/encoding/protojson" +) + +var newInstanceGroupsClientHook clientHook + +// InstanceGroupsCallOptions contains the retry settings for each method of InstanceGroupsClient. +type InstanceGroupsCallOptions struct { + AddInstances []gax.CallOption + AggregatedList []gax.CallOption + Delete []gax.CallOption + Get []gax.CallOption + Insert []gax.CallOption + List []gax.CallOption + ListInstances []gax.CallOption + RemoveInstances []gax.CallOption + SetNamedPorts []gax.CallOption +} + +// internalInstanceGroupsClient is an interface that defines the methods availaible from Google Compute Engine API. +type internalInstanceGroupsClient interface { + Close() error + setGoogleClientInfo(...string) + Connection() *grpc.ClientConn + AddInstances(context.Context, *computepb.AddInstancesInstanceGroupRequest, ...gax.CallOption) (*computepb.Operation, error) + AggregatedList(context.Context, *computepb.AggregatedListInstanceGroupsRequest, ...gax.CallOption) (*computepb.InstanceGroupAggregatedList, error) + Delete(context.Context, *computepb.DeleteInstanceGroupRequest, ...gax.CallOption) (*computepb.Operation, error) + Get(context.Context, *computepb.GetInstanceGroupRequest, ...gax.CallOption) (*computepb.InstanceGroup, error) + Insert(context.Context, *computepb.InsertInstanceGroupRequest, ...gax.CallOption) (*computepb.Operation, error) + List(context.Context, *computepb.ListInstanceGroupsRequest, ...gax.CallOption) (*computepb.InstanceGroupList, error) + ListInstances(context.Context, *computepb.ListInstancesInstanceGroupsRequest, ...gax.CallOption) (*computepb.InstanceGroupsListInstances, error) + RemoveInstances(context.Context, *computepb.RemoveInstancesInstanceGroupRequest, ...gax.CallOption) (*computepb.Operation, error) + SetNamedPorts(context.Context, *computepb.SetNamedPortsInstanceGroupRequest, ...gax.CallOption) (*computepb.Operation, error) +} + +// InstanceGroupsClient is a client for interacting with Google Compute Engine API. +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +// +// The InstanceGroups API. +type InstanceGroupsClient struct { + // The internal transport-dependent client. + internalClient internalInstanceGroupsClient + + // The call options for this service. + CallOptions *InstanceGroupsCallOptions +} + +// 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 *InstanceGroupsClient) 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 *InstanceGroupsClient) setGoogleClientInfo(keyval ...string) { + c.internalClient.setGoogleClientInfo(keyval...) +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *InstanceGroupsClient) Connection() *grpc.ClientConn { + return c.internalClient.Connection() +} + +// AddInstances adds a list of instances to the specified instance group. All of the instances in the instance group must be in the same network/subnetwork. Read Adding instances for more information. +func (c *InstanceGroupsClient) AddInstances(ctx context.Context, req *computepb.AddInstancesInstanceGroupRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.AddInstances(ctx, req, opts...) +} + +// AggregatedList retrieves the list of instance groups and sorts them by zone. +func (c *InstanceGroupsClient) AggregatedList(ctx context.Context, req *computepb.AggregatedListInstanceGroupsRequest, opts ...gax.CallOption) (*computepb.InstanceGroupAggregatedList, error) { + return c.internalClient.AggregatedList(ctx, req, opts...) +} + +// Delete deletes the specified instance group. The instances in the group are not deleted. Note that instance group must not belong to a backend service. Read Deleting an instance group for more information. +func (c *InstanceGroupsClient) Delete(ctx context.Context, req *computepb.DeleteInstanceGroupRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.Delete(ctx, req, opts...) +} + +// Get returns the specified zonal instance group. Get a list of available zonal instance groups by making a list() request. +// +// For managed instance groups, use the instanceGroupManagers or regionInstanceGroupManagers methods instead. +func (c *InstanceGroupsClient) Get(ctx context.Context, req *computepb.GetInstanceGroupRequest, opts ...gax.CallOption) (*computepb.InstanceGroup, error) { + return c.internalClient.Get(ctx, req, opts...) +} + +// Insert creates an instance group in the specified project using the parameters that are included in the request. +func (c *InstanceGroupsClient) Insert(ctx context.Context, req *computepb.InsertInstanceGroupRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.Insert(ctx, req, opts...) +} + +// List retrieves the list of zonal instance group resources contained within the specified zone. +// +// For managed instance groups, use the instanceGroupManagers or regionInstanceGroupManagers methods instead. +func (c *InstanceGroupsClient) List(ctx context.Context, req *computepb.ListInstanceGroupsRequest, opts ...gax.CallOption) (*computepb.InstanceGroupList, error) { + return c.internalClient.List(ctx, req, opts...) +} + +// ListInstances lists the instances in the specified instance group. The orderBy query parameter is not supported. +func (c *InstanceGroupsClient) ListInstances(ctx context.Context, req *computepb.ListInstancesInstanceGroupsRequest, opts ...gax.CallOption) (*computepb.InstanceGroupsListInstances, error) { + return c.internalClient.ListInstances(ctx, req, opts...) +} + +// RemoveInstances removes one or more instances from the specified instance group, but does not delete those instances. +// +// If the group is part of a backend service that has enabled connection draining, it can take up to 60 seconds after the connection draining duration before the VM instance is removed or deleted. +func (c *InstanceGroupsClient) RemoveInstances(ctx context.Context, req *computepb.RemoveInstancesInstanceGroupRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.RemoveInstances(ctx, req, opts...) +} + +// SetNamedPorts sets the named ports for the specified instance group. +func (c *InstanceGroupsClient) SetNamedPorts(ctx context.Context, req *computepb.SetNamedPortsInstanceGroupRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.SetNamedPorts(ctx, req, opts...) +} + +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +type instanceGroupsRESTClient struct { + // The http endpoint to connect to. + endpoint string + + // The http client. + httpClient *http.Client + + // The x-goog-* metadata to be sent with each request. + xGoogMetadata metadata.MD +} + +// NewInstanceGroupsRESTClient creates a new instance groups rest client. +// +// The InstanceGroups API. +func NewInstanceGroupsRESTClient(ctx context.Context, opts ...option.ClientOption) (*InstanceGroupsClient, error) { + clientOpts := append(defaultInstanceGroupsRESTClientOptions(), opts...) + httpClient, endpoint, err := httptransport.NewClient(ctx, clientOpts...) + if err != nil { + return nil, err + } + + c := &instanceGroupsRESTClient{ + endpoint: endpoint, + httpClient: httpClient, + } + c.setGoogleClientInfo() + + return &InstanceGroupsClient{internalClient: c, CallOptions: &InstanceGroupsCallOptions{}}, nil +} + +func defaultInstanceGroupsRESTClientOptions() []option.ClientOption { + return []option.ClientOption{ + internaloption.WithDefaultEndpoint("compute.googleapis.com"), + internaloption.WithDefaultMTLSEndpoint("compute.mtls.googleapis.com"), + internaloption.WithDefaultAudience("https://compute.googleapis.com/"), + internaloption.WithDefaultScopes(DefaultAuthScopes()...), + } +} + +// 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 *instanceGroupsRESTClient) setGoogleClientInfo(keyval ...string) { + kv := append([]string{"gl-go", versionGo()}, keyval...) + kv = append(kv, "gapic", versionClient, "gax", gax.Version, "rest", "UNKNOWN") + 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 *instanceGroupsRESTClient) Close() error { + // Replace httpClient with nil to force cleanup. + c.httpClient = nil + return nil +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *instanceGroupsRESTClient) Connection() *grpc.ClientConn { + return nil +} + +// AddInstances adds a list of instances to the specified instance group. All of the instances in the instance group must be in the same network/subnetwork. Read Adding instances for more information. +func (c *instanceGroupsRESTClient) AddInstances(ctx context.Context, req *computepb.AddInstancesInstanceGroupRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetInstanceGroupsAddInstancesRequestResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/zones/%v/instanceGroups/%v/addInstances", req.GetProject(), req.GetZone(), req.GetInstanceGroup()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// AggregatedList retrieves the list of instance groups and sorts them by zone. +func (c *instanceGroupsRESTClient) AggregatedList(ctx context.Context, req *computepb.AggregatedListInstanceGroupsRequest, opts ...gax.CallOption) (*computepb.InstanceGroupAggregatedList, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/aggregated/instanceGroups", req.GetProject()) + + params := url.Values{} + if req != nil && req.Filter != nil { + params.Add("filter", fmt.Sprintf("%v", req.GetFilter())) + } + if req != nil && req.IncludeAllScopes != nil { + params.Add("includeAllScopes", fmt.Sprintf("%v", req.GetIncludeAllScopes())) + } + if req != nil && req.MaxResults != nil { + params.Add("maxResults", fmt.Sprintf("%v", req.GetMaxResults())) + } + if req != nil && req.OrderBy != nil { + params.Add("orderBy", fmt.Sprintf("%v", req.GetOrderBy())) + } + if req != nil && req.PageToken != nil { + params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) + } + if req != nil && req.ReturnPartialSuccess != nil { + params.Add("returnPartialSuccess", fmt.Sprintf("%v", req.GetReturnPartialSuccess())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.InstanceGroupAggregatedList{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Delete deletes the specified instance group. The instances in the group are not deleted. Note that instance group must not belong to a backend service. Read Deleting an instance group for more information. +func (c *instanceGroupsRESTClient) Delete(ctx context.Context, req *computepb.DeleteInstanceGroupRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/zones/%v/instanceGroups/%v", req.GetProject(), req.GetZone(), req.GetInstanceGroup()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("DELETE", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Get returns the specified zonal instance group. Get a list of available zonal instance groups by making a list() request. +// +// For managed instance groups, use the instanceGroupManagers or regionInstanceGroupManagers methods instead. +func (c *instanceGroupsRESTClient) Get(ctx context.Context, req *computepb.GetInstanceGroupRequest, opts ...gax.CallOption) (*computepb.InstanceGroup, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/zones/%v/instanceGroups/%v", req.GetProject(), req.GetZone(), req.GetInstanceGroup()) + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.InstanceGroup{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Insert creates an instance group in the specified project using the parameters that are included in the request. +func (c *instanceGroupsRESTClient) Insert(ctx context.Context, req *computepb.InsertInstanceGroupRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetInstanceGroupResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/zones/%v/instanceGroups", req.GetProject(), req.GetZone()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// List retrieves the list of zonal instance group resources contained within the specified zone. +// +// For managed instance groups, use the instanceGroupManagers or regionInstanceGroupManagers methods instead. +func (c *instanceGroupsRESTClient) List(ctx context.Context, req *computepb.ListInstanceGroupsRequest, opts ...gax.CallOption) (*computepb.InstanceGroupList, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/zones/%v/instanceGroups", req.GetProject(), req.GetZone()) + + params := url.Values{} + if req != nil && req.Filter != nil { + params.Add("filter", fmt.Sprintf("%v", req.GetFilter())) + } + if req != nil && req.MaxResults != nil { + params.Add("maxResults", fmt.Sprintf("%v", req.GetMaxResults())) + } + if req != nil && req.OrderBy != nil { + params.Add("orderBy", fmt.Sprintf("%v", req.GetOrderBy())) + } + if req != nil && req.PageToken != nil { + params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) + } + if req != nil && req.ReturnPartialSuccess != nil { + params.Add("returnPartialSuccess", fmt.Sprintf("%v", req.GetReturnPartialSuccess())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.InstanceGroupList{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// ListInstances lists the instances in the specified instance group. The orderBy query parameter is not supported. +func (c *instanceGroupsRESTClient) ListInstances(ctx context.Context, req *computepb.ListInstancesInstanceGroupsRequest, opts ...gax.CallOption) (*computepb.InstanceGroupsListInstances, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetInstanceGroupsListInstancesRequestResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/zones/%v/instanceGroups/%v/listInstances", req.GetProject(), req.GetZone(), req.GetInstanceGroup()) + + params := url.Values{} + if req != nil && req.Filter != nil { + params.Add("filter", fmt.Sprintf("%v", req.GetFilter())) + } + if req != nil && req.MaxResults != nil { + params.Add("maxResults", fmt.Sprintf("%v", req.GetMaxResults())) + } + if req != nil && req.OrderBy != nil { + params.Add("orderBy", fmt.Sprintf("%v", req.GetOrderBy())) + } + if req != nil && req.PageToken != nil { + params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) + } + if req != nil && req.ReturnPartialSuccess != nil { + params.Add("returnPartialSuccess", fmt.Sprintf("%v", req.GetReturnPartialSuccess())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.InstanceGroupsListInstances{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// RemoveInstances removes one or more instances from the specified instance group, but does not delete those instances. +// +// If the group is part of a backend service that has enabled connection draining, it can take up to 60 seconds after the connection draining duration before the VM instance is removed or deleted. +func (c *instanceGroupsRESTClient) RemoveInstances(ctx context.Context, req *computepb.RemoveInstancesInstanceGroupRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetInstanceGroupsRemoveInstancesRequestResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/zones/%v/instanceGroups/%v/removeInstances", req.GetProject(), req.GetZone(), req.GetInstanceGroup()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// SetNamedPorts sets the named ports for the specified instance group. +func (c *instanceGroupsRESTClient) SetNamedPorts(ctx context.Context, req *computepb.SetNamedPortsInstanceGroupRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetInstanceGroupsSetNamedPortsRequestResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/zones/%v/instanceGroups/%v/setNamedPorts", req.GetProject(), req.GetZone(), req.GetInstanceGroup()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} diff --git a/compute/apiv1/instance_groups_client_example_test.go b/compute/apiv1/instance_groups_client_example_test.go new file mode 100644 index 00000000000..8e646affefb --- /dev/null +++ b/compute/apiv1/instance_groups_client_example_test.go @@ -0,0 +1,207 @@ +// 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 compute_test + +import ( + "context" + + compute "cloud.google.com/go/compute/apiv1" + computepb "google.golang.org/genproto/googleapis/cloud/compute/v1" +) + +func ExampleNewInstanceGroupsRESTClient() { + ctx := context.Background() + c, err := compute.NewInstanceGroupsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + // TODO: Use client. + _ = c +} + +func ExampleInstanceGroupsClient_AddInstances() { + ctx := context.Background() + c, err := compute.NewInstanceGroupsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.AddInstancesInstanceGroupRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.AddInstances(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleInstanceGroupsClient_AggregatedList() { + ctx := context.Background() + c, err := compute.NewInstanceGroupsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.AggregatedListInstanceGroupsRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.AggregatedList(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleInstanceGroupsClient_Delete() { + ctx := context.Background() + c, err := compute.NewInstanceGroupsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.DeleteInstanceGroupRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Delete(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleInstanceGroupsClient_Get() { + ctx := context.Background() + c, err := compute.NewInstanceGroupsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.GetInstanceGroupRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Get(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleInstanceGroupsClient_Insert() { + ctx := context.Background() + c, err := compute.NewInstanceGroupsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.InsertInstanceGroupRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Insert(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleInstanceGroupsClient_List() { + ctx := context.Background() + c, err := compute.NewInstanceGroupsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.ListInstanceGroupsRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.List(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleInstanceGroupsClient_ListInstances() { + ctx := context.Background() + c, err := compute.NewInstanceGroupsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.ListInstancesInstanceGroupsRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.ListInstances(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleInstanceGroupsClient_RemoveInstances() { + ctx := context.Background() + c, err := compute.NewInstanceGroupsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.RemoveInstancesInstanceGroupRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.RemoveInstances(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleInstanceGroupsClient_SetNamedPorts() { + ctx := context.Background() + c, err := compute.NewInstanceGroupsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.SetNamedPortsInstanceGroupRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.SetNamedPorts(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} diff --git a/compute/apiv1/instance_templates_client.go b/compute/apiv1/instance_templates_client.go new file mode 100644 index 00000000000..2003c355cf0 --- /dev/null +++ b/compute/apiv1/instance_templates_client.go @@ -0,0 +1,539 @@ +// 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 compute + +import ( + "bytes" + "context" + "fmt" + "io/ioutil" + "net/http" + "net/url" + + gax "github.com/googleapis/gax-go/v2" + "google.golang.org/api/option" + "google.golang.org/api/option/internaloption" + httptransport "google.golang.org/api/transport/http" + computepb "google.golang.org/genproto/googleapis/cloud/compute/v1" + "google.golang.org/grpc" + "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/encoding/protojson" +) + +var newInstanceTemplatesClientHook clientHook + +// InstanceTemplatesCallOptions contains the retry settings for each method of InstanceTemplatesClient. +type InstanceTemplatesCallOptions struct { + Delete []gax.CallOption + Get []gax.CallOption + GetIamPolicy []gax.CallOption + Insert []gax.CallOption + List []gax.CallOption + SetIamPolicy []gax.CallOption + TestIamPermissions []gax.CallOption +} + +// internalInstanceTemplatesClient is an interface that defines the methods availaible from Google Compute Engine API. +type internalInstanceTemplatesClient interface { + Close() error + setGoogleClientInfo(...string) + Connection() *grpc.ClientConn + Delete(context.Context, *computepb.DeleteInstanceTemplateRequest, ...gax.CallOption) (*computepb.Operation, error) + Get(context.Context, *computepb.GetInstanceTemplateRequest, ...gax.CallOption) (*computepb.InstanceTemplate, error) + GetIamPolicy(context.Context, *computepb.GetIamPolicyInstanceTemplateRequest, ...gax.CallOption) (*computepb.Policy, error) + Insert(context.Context, *computepb.InsertInstanceTemplateRequest, ...gax.CallOption) (*computepb.Operation, error) + List(context.Context, *computepb.ListInstanceTemplatesRequest, ...gax.CallOption) (*computepb.InstanceTemplateList, error) + SetIamPolicy(context.Context, *computepb.SetIamPolicyInstanceTemplateRequest, ...gax.CallOption) (*computepb.Policy, error) + TestIamPermissions(context.Context, *computepb.TestIamPermissionsInstanceTemplateRequest, ...gax.CallOption) (*computepb.TestPermissionsResponse, error) +} + +// InstanceTemplatesClient is a client for interacting with Google Compute Engine API. +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +// +// The InstanceTemplates API. +type InstanceTemplatesClient struct { + // The internal transport-dependent client. + internalClient internalInstanceTemplatesClient + + // The call options for this service. + CallOptions *InstanceTemplatesCallOptions +} + +// 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 *InstanceTemplatesClient) 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 *InstanceTemplatesClient) setGoogleClientInfo(keyval ...string) { + c.internalClient.setGoogleClientInfo(keyval...) +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *InstanceTemplatesClient) Connection() *grpc.ClientConn { + return c.internalClient.Connection() +} + +// Delete deletes the specified instance template. Deleting an instance template is permanent and cannot be undone. It is not possible to delete templates that are already in use by a managed instance group. +func (c *InstanceTemplatesClient) Delete(ctx context.Context, req *computepb.DeleteInstanceTemplateRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.Delete(ctx, req, opts...) +} + +// Get returns the specified instance template. Gets a list of available instance templates by making a list() request. +func (c *InstanceTemplatesClient) Get(ctx context.Context, req *computepb.GetInstanceTemplateRequest, opts ...gax.CallOption) (*computepb.InstanceTemplate, error) { + return c.internalClient.Get(ctx, req, opts...) +} + +// GetIamPolicy gets the access control policy for a resource. May be empty if no such policy or resource exists. +func (c *InstanceTemplatesClient) GetIamPolicy(ctx context.Context, req *computepb.GetIamPolicyInstanceTemplateRequest, opts ...gax.CallOption) (*computepb.Policy, error) { + return c.internalClient.GetIamPolicy(ctx, req, opts...) +} + +// Insert creates an instance template in the specified project using the data that is included in the request. If you are creating a new template to update an existing instance group, your new instance template must use the same network or, if applicable, the same subnetwork as the original template. +func (c *InstanceTemplatesClient) Insert(ctx context.Context, req *computepb.InsertInstanceTemplateRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.Insert(ctx, req, opts...) +} + +// List retrieves a list of instance templates that are contained within the specified project. +func (c *InstanceTemplatesClient) List(ctx context.Context, req *computepb.ListInstanceTemplatesRequest, opts ...gax.CallOption) (*computepb.InstanceTemplateList, error) { + return c.internalClient.List(ctx, req, opts...) +} + +// SetIamPolicy sets the access control policy on the specified resource. Replaces any existing policy. +func (c *InstanceTemplatesClient) SetIamPolicy(ctx context.Context, req *computepb.SetIamPolicyInstanceTemplateRequest, opts ...gax.CallOption) (*computepb.Policy, error) { + return c.internalClient.SetIamPolicy(ctx, req, opts...) +} + +// TestIamPermissions returns permissions that a caller has on the specified resource. +func (c *InstanceTemplatesClient) TestIamPermissions(ctx context.Context, req *computepb.TestIamPermissionsInstanceTemplateRequest, opts ...gax.CallOption) (*computepb.TestPermissionsResponse, error) { + return c.internalClient.TestIamPermissions(ctx, req, opts...) +} + +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +type instanceTemplatesRESTClient struct { + // The http endpoint to connect to. + endpoint string + + // The http client. + httpClient *http.Client + + // The x-goog-* metadata to be sent with each request. + xGoogMetadata metadata.MD +} + +// NewInstanceTemplatesRESTClient creates a new instance templates rest client. +// +// The InstanceTemplates API. +func NewInstanceTemplatesRESTClient(ctx context.Context, opts ...option.ClientOption) (*InstanceTemplatesClient, error) { + clientOpts := append(defaultInstanceTemplatesRESTClientOptions(), opts...) + httpClient, endpoint, err := httptransport.NewClient(ctx, clientOpts...) + if err != nil { + return nil, err + } + + c := &instanceTemplatesRESTClient{ + endpoint: endpoint, + httpClient: httpClient, + } + c.setGoogleClientInfo() + + return &InstanceTemplatesClient{internalClient: c, CallOptions: &InstanceTemplatesCallOptions{}}, nil +} + +func defaultInstanceTemplatesRESTClientOptions() []option.ClientOption { + return []option.ClientOption{ + internaloption.WithDefaultEndpoint("compute.googleapis.com"), + internaloption.WithDefaultMTLSEndpoint("compute.mtls.googleapis.com"), + internaloption.WithDefaultAudience("https://compute.googleapis.com/"), + internaloption.WithDefaultScopes(DefaultAuthScopes()...), + } +} + +// 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 *instanceTemplatesRESTClient) setGoogleClientInfo(keyval ...string) { + kv := append([]string{"gl-go", versionGo()}, keyval...) + kv = append(kv, "gapic", versionClient, "gax", gax.Version, "rest", "UNKNOWN") + 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 *instanceTemplatesRESTClient) Close() error { + // Replace httpClient with nil to force cleanup. + c.httpClient = nil + return nil +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *instanceTemplatesRESTClient) Connection() *grpc.ClientConn { + return nil +} + +// Delete deletes the specified instance template. Deleting an instance template is permanent and cannot be undone. It is not possible to delete templates that are already in use by a managed instance group. +func (c *instanceTemplatesRESTClient) Delete(ctx context.Context, req *computepb.DeleteInstanceTemplateRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/instanceTemplates/%v", req.GetProject(), req.GetInstanceTemplate()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("DELETE", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Get returns the specified instance template. Gets a list of available instance templates by making a list() request. +func (c *instanceTemplatesRESTClient) Get(ctx context.Context, req *computepb.GetInstanceTemplateRequest, opts ...gax.CallOption) (*computepb.InstanceTemplate, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/instanceTemplates/%v", req.GetProject(), req.GetInstanceTemplate()) + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.InstanceTemplate{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// GetIamPolicy gets the access control policy for a resource. May be empty if no such policy or resource exists. +func (c *instanceTemplatesRESTClient) GetIamPolicy(ctx context.Context, req *computepb.GetIamPolicyInstanceTemplateRequest, opts ...gax.CallOption) (*computepb.Policy, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/instanceTemplates/%v/getIamPolicy", req.GetProject(), req.GetResource()) + + params := url.Values{} + if req != nil && req.OptionsRequestedPolicyVersion != nil { + params.Add("optionsRequestedPolicyVersion", fmt.Sprintf("%v", req.GetOptionsRequestedPolicyVersion())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Policy{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Insert creates an instance template in the specified project using the data that is included in the request. If you are creating a new template to update an existing instance group, your new instance template must use the same network or, if applicable, the same subnetwork as the original template. +func (c *instanceTemplatesRESTClient) Insert(ctx context.Context, req *computepb.InsertInstanceTemplateRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetInstanceTemplateResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/instanceTemplates", req.GetProject()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// List retrieves a list of instance templates that are contained within the specified project. +func (c *instanceTemplatesRESTClient) List(ctx context.Context, req *computepb.ListInstanceTemplatesRequest, opts ...gax.CallOption) (*computepb.InstanceTemplateList, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/instanceTemplates", req.GetProject()) + + params := url.Values{} + if req != nil && req.Filter != nil { + params.Add("filter", fmt.Sprintf("%v", req.GetFilter())) + } + if req != nil && req.MaxResults != nil { + params.Add("maxResults", fmt.Sprintf("%v", req.GetMaxResults())) + } + if req != nil && req.OrderBy != nil { + params.Add("orderBy", fmt.Sprintf("%v", req.GetOrderBy())) + } + if req != nil && req.PageToken != nil { + params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) + } + if req != nil && req.ReturnPartialSuccess != nil { + params.Add("returnPartialSuccess", fmt.Sprintf("%v", req.GetReturnPartialSuccess())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.InstanceTemplateList{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// SetIamPolicy sets the access control policy on the specified resource. Replaces any existing policy. +func (c *instanceTemplatesRESTClient) SetIamPolicy(ctx context.Context, req *computepb.SetIamPolicyInstanceTemplateRequest, opts ...gax.CallOption) (*computepb.Policy, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetGlobalSetPolicyRequestResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/instanceTemplates/%v/setIamPolicy", req.GetProject(), req.GetResource()) + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Policy{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// TestIamPermissions returns permissions that a caller has on the specified resource. +func (c *instanceTemplatesRESTClient) TestIamPermissions(ctx context.Context, req *computepb.TestIamPermissionsInstanceTemplateRequest, opts ...gax.CallOption) (*computepb.TestPermissionsResponse, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetTestPermissionsRequestResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/instanceTemplates/%v/testIamPermissions", req.GetProject(), req.GetResource()) + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.TestPermissionsResponse{} + + return rsp, unm.Unmarshal(buf, rsp) +} diff --git a/compute/apiv1/instance_templates_client_example_test.go b/compute/apiv1/instance_templates_client_example_test.go new file mode 100644 index 00000000000..3cdbbabf56d --- /dev/null +++ b/compute/apiv1/instance_templates_client_example_test.go @@ -0,0 +1,169 @@ +// 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 compute_test + +import ( + "context" + + compute "cloud.google.com/go/compute/apiv1" + computepb "google.golang.org/genproto/googleapis/cloud/compute/v1" +) + +func ExampleNewInstanceTemplatesRESTClient() { + ctx := context.Background() + c, err := compute.NewInstanceTemplatesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + // TODO: Use client. + _ = c +} + +func ExampleInstanceTemplatesClient_Delete() { + ctx := context.Background() + c, err := compute.NewInstanceTemplatesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.DeleteInstanceTemplateRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Delete(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleInstanceTemplatesClient_Get() { + ctx := context.Background() + c, err := compute.NewInstanceTemplatesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.GetInstanceTemplateRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Get(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleInstanceTemplatesClient_GetIamPolicy() { + ctx := context.Background() + c, err := compute.NewInstanceTemplatesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.GetIamPolicyInstanceTemplateRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.GetIamPolicy(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleInstanceTemplatesClient_Insert() { + ctx := context.Background() + c, err := compute.NewInstanceTemplatesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.InsertInstanceTemplateRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Insert(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleInstanceTemplatesClient_List() { + ctx := context.Background() + c, err := compute.NewInstanceTemplatesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.ListInstanceTemplatesRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.List(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleInstanceTemplatesClient_SetIamPolicy() { + ctx := context.Background() + c, err := compute.NewInstanceTemplatesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.SetIamPolicyInstanceTemplateRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.SetIamPolicy(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleInstanceTemplatesClient_TestIamPermissions() { + ctx := context.Background() + c, err := compute.NewInstanceTemplatesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.TestIamPermissionsInstanceTemplateRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.TestIamPermissions(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} diff --git a/compute/apiv1/instances_client.go b/compute/apiv1/instances_client.go new file mode 100644 index 00000000000..365b3efe4fc --- /dev/null +++ b/compute/apiv1/instances_client.go @@ -0,0 +1,2614 @@ +// 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 compute + +import ( + "bytes" + "context" + "fmt" + "io/ioutil" + "net/http" + "net/url" + + gax "github.com/googleapis/gax-go/v2" + "google.golang.org/api/option" + "google.golang.org/api/option/internaloption" + httptransport "google.golang.org/api/transport/http" + computepb "google.golang.org/genproto/googleapis/cloud/compute/v1" + "google.golang.org/grpc" + "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/encoding/protojson" +) + +var newInstancesClientHook clientHook + +// InstancesCallOptions contains the retry settings for each method of InstancesClient. +type InstancesCallOptions struct { + AddAccessConfig []gax.CallOption + AddResourcePolicies []gax.CallOption + AggregatedList []gax.CallOption + AttachDisk []gax.CallOption + BulkInsert []gax.CallOption + Delete []gax.CallOption + DeleteAccessConfig []gax.CallOption + DetachDisk []gax.CallOption + Get []gax.CallOption + GetEffectiveFirewalls []gax.CallOption + GetGuestAttributes []gax.CallOption + GetIamPolicy []gax.CallOption + GetScreenshot []gax.CallOption + GetSerialPortOutput []gax.CallOption + GetShieldedInstanceIdentity []gax.CallOption + Insert []gax.CallOption + List []gax.CallOption + ListReferrers []gax.CallOption + RemoveResourcePolicies []gax.CallOption + Reset []gax.CallOption + SetDeletionProtection []gax.CallOption + SetDiskAutoDelete []gax.CallOption + SetIamPolicy []gax.CallOption + SetLabels []gax.CallOption + SetMachineResources []gax.CallOption + SetMachineType []gax.CallOption + SetMetadata []gax.CallOption + SetMinCpuPlatform []gax.CallOption + SetScheduling []gax.CallOption + SetServiceAccount []gax.CallOption + SetShieldedInstanceIntegrityPolicy []gax.CallOption + SetTags []gax.CallOption + SimulateMaintenanceEvent []gax.CallOption + Start []gax.CallOption + StartWithEncryptionKey []gax.CallOption + Stop []gax.CallOption + TestIamPermissions []gax.CallOption + Update []gax.CallOption + UpdateAccessConfig []gax.CallOption + UpdateDisplayDevice []gax.CallOption + UpdateNetworkInterface []gax.CallOption + UpdateShieldedInstanceConfig []gax.CallOption +} + +// internalInstancesClient is an interface that defines the methods availaible from Google Compute Engine API. +type internalInstancesClient interface { + Close() error + setGoogleClientInfo(...string) + Connection() *grpc.ClientConn + AddAccessConfig(context.Context, *computepb.AddAccessConfigInstanceRequest, ...gax.CallOption) (*computepb.Operation, error) + AddResourcePolicies(context.Context, *computepb.AddResourcePoliciesInstanceRequest, ...gax.CallOption) (*computepb.Operation, error) + AggregatedList(context.Context, *computepb.AggregatedListInstancesRequest, ...gax.CallOption) (*computepb.InstanceAggregatedList, error) + AttachDisk(context.Context, *computepb.AttachDiskInstanceRequest, ...gax.CallOption) (*computepb.Operation, error) + BulkInsert(context.Context, *computepb.BulkInsertInstanceRequest, ...gax.CallOption) (*computepb.Operation, error) + Delete(context.Context, *computepb.DeleteInstanceRequest, ...gax.CallOption) (*computepb.Operation, error) + DeleteAccessConfig(context.Context, *computepb.DeleteAccessConfigInstanceRequest, ...gax.CallOption) (*computepb.Operation, error) + DetachDisk(context.Context, *computepb.DetachDiskInstanceRequest, ...gax.CallOption) (*computepb.Operation, error) + Get(context.Context, *computepb.GetInstanceRequest, ...gax.CallOption) (*computepb.Instance, error) + GetEffectiveFirewalls(context.Context, *computepb.GetEffectiveFirewallsInstanceRequest, ...gax.CallOption) (*computepb.InstancesGetEffectiveFirewallsResponse, error) + GetGuestAttributes(context.Context, *computepb.GetGuestAttributesInstanceRequest, ...gax.CallOption) (*computepb.GuestAttributes, error) + GetIamPolicy(context.Context, *computepb.GetIamPolicyInstanceRequest, ...gax.CallOption) (*computepb.Policy, error) + GetScreenshot(context.Context, *computepb.GetScreenshotInstanceRequest, ...gax.CallOption) (*computepb.Screenshot, error) + GetSerialPortOutput(context.Context, *computepb.GetSerialPortOutputInstanceRequest, ...gax.CallOption) (*computepb.SerialPortOutput, error) + GetShieldedInstanceIdentity(context.Context, *computepb.GetShieldedInstanceIdentityInstanceRequest, ...gax.CallOption) (*computepb.ShieldedInstanceIdentity, error) + Insert(context.Context, *computepb.InsertInstanceRequest, ...gax.CallOption) (*computepb.Operation, error) + List(context.Context, *computepb.ListInstancesRequest, ...gax.CallOption) (*computepb.InstanceList, error) + ListReferrers(context.Context, *computepb.ListReferrersInstancesRequest, ...gax.CallOption) (*computepb.InstanceListReferrers, error) + RemoveResourcePolicies(context.Context, *computepb.RemoveResourcePoliciesInstanceRequest, ...gax.CallOption) (*computepb.Operation, error) + Reset(context.Context, *computepb.ResetInstanceRequest, ...gax.CallOption) (*computepb.Operation, error) + SetDeletionProtection(context.Context, *computepb.SetDeletionProtectionInstanceRequest, ...gax.CallOption) (*computepb.Operation, error) + SetDiskAutoDelete(context.Context, *computepb.SetDiskAutoDeleteInstanceRequest, ...gax.CallOption) (*computepb.Operation, error) + SetIamPolicy(context.Context, *computepb.SetIamPolicyInstanceRequest, ...gax.CallOption) (*computepb.Policy, error) + SetLabels(context.Context, *computepb.SetLabelsInstanceRequest, ...gax.CallOption) (*computepb.Operation, error) + SetMachineResources(context.Context, *computepb.SetMachineResourcesInstanceRequest, ...gax.CallOption) (*computepb.Operation, error) + SetMachineType(context.Context, *computepb.SetMachineTypeInstanceRequest, ...gax.CallOption) (*computepb.Operation, error) + SetMetadata(context.Context, *computepb.SetMetadataInstanceRequest, ...gax.CallOption) (*computepb.Operation, error) + SetMinCpuPlatform(context.Context, *computepb.SetMinCpuPlatformInstanceRequest, ...gax.CallOption) (*computepb.Operation, error) + SetScheduling(context.Context, *computepb.SetSchedulingInstanceRequest, ...gax.CallOption) (*computepb.Operation, error) + SetServiceAccount(context.Context, *computepb.SetServiceAccountInstanceRequest, ...gax.CallOption) (*computepb.Operation, error) + SetShieldedInstanceIntegrityPolicy(context.Context, *computepb.SetShieldedInstanceIntegrityPolicyInstanceRequest, ...gax.CallOption) (*computepb.Operation, error) + SetTags(context.Context, *computepb.SetTagsInstanceRequest, ...gax.CallOption) (*computepb.Operation, error) + SimulateMaintenanceEvent(context.Context, *computepb.SimulateMaintenanceEventInstanceRequest, ...gax.CallOption) (*computepb.Operation, error) + Start(context.Context, *computepb.StartInstanceRequest, ...gax.CallOption) (*computepb.Operation, error) + StartWithEncryptionKey(context.Context, *computepb.StartWithEncryptionKeyInstanceRequest, ...gax.CallOption) (*computepb.Operation, error) + Stop(context.Context, *computepb.StopInstanceRequest, ...gax.CallOption) (*computepb.Operation, error) + TestIamPermissions(context.Context, *computepb.TestIamPermissionsInstanceRequest, ...gax.CallOption) (*computepb.TestPermissionsResponse, error) + Update(context.Context, *computepb.UpdateInstanceRequest, ...gax.CallOption) (*computepb.Operation, error) + UpdateAccessConfig(context.Context, *computepb.UpdateAccessConfigInstanceRequest, ...gax.CallOption) (*computepb.Operation, error) + UpdateDisplayDevice(context.Context, *computepb.UpdateDisplayDeviceInstanceRequest, ...gax.CallOption) (*computepb.Operation, error) + UpdateNetworkInterface(context.Context, *computepb.UpdateNetworkInterfaceInstanceRequest, ...gax.CallOption) (*computepb.Operation, error) + UpdateShieldedInstanceConfig(context.Context, *computepb.UpdateShieldedInstanceConfigInstanceRequest, ...gax.CallOption) (*computepb.Operation, error) +} + +// InstancesClient is a client for interacting with Google Compute Engine API. +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +// +// The Instances API. +type InstancesClient struct { + // The internal transport-dependent client. + internalClient internalInstancesClient + + // The call options for this service. + CallOptions *InstancesCallOptions +} + +// 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 *InstancesClient) 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 *InstancesClient) setGoogleClientInfo(keyval ...string) { + c.internalClient.setGoogleClientInfo(keyval...) +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *InstancesClient) Connection() *grpc.ClientConn { + return c.internalClient.Connection() +} + +// AddAccessConfig adds an access config to an instance’s network interface. +func (c *InstancesClient) AddAccessConfig(ctx context.Context, req *computepb.AddAccessConfigInstanceRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.AddAccessConfig(ctx, req, opts...) +} + +// AddResourcePolicies adds existing resource policies to an instance. You can only add one policy right now which will be applied to this instance for scheduling live migrations. +func (c *InstancesClient) AddResourcePolicies(ctx context.Context, req *computepb.AddResourcePoliciesInstanceRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.AddResourcePolicies(ctx, req, opts...) +} + +// AggregatedList retrieves aggregated list of all of the instances in your project across all regions and zones. +func (c *InstancesClient) AggregatedList(ctx context.Context, req *computepb.AggregatedListInstancesRequest, opts ...gax.CallOption) (*computepb.InstanceAggregatedList, error) { + return c.internalClient.AggregatedList(ctx, req, opts...) +} + +// AttachDisk attaches an existing Disk resource to an instance. You must first create the disk before you can attach it. It is not possible to create and attach a disk at the same time. For more information, read Adding a persistent disk to your instance. +func (c *InstancesClient) AttachDisk(ctx context.Context, req *computepb.AttachDiskInstanceRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.AttachDisk(ctx, req, opts...) +} + +// BulkInsert creates multiple instances. Count specifies the number of instances to create. +func (c *InstancesClient) BulkInsert(ctx context.Context, req *computepb.BulkInsertInstanceRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.BulkInsert(ctx, req, opts...) +} + +// Delete deletes the specified Instance resource. For more information, see Deleting an instance. +func (c *InstancesClient) Delete(ctx context.Context, req *computepb.DeleteInstanceRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.Delete(ctx, req, opts...) +} + +// DeleteAccessConfig deletes an access config from an instance’s network interface. +func (c *InstancesClient) DeleteAccessConfig(ctx context.Context, req *computepb.DeleteAccessConfigInstanceRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.DeleteAccessConfig(ctx, req, opts...) +} + +// DetachDisk detaches a disk from an instance. +func (c *InstancesClient) DetachDisk(ctx context.Context, req *computepb.DetachDiskInstanceRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.DetachDisk(ctx, req, opts...) +} + +// Get returns the specified Instance resource. Gets a list of available instances by making a list() request. +func (c *InstancesClient) Get(ctx context.Context, req *computepb.GetInstanceRequest, opts ...gax.CallOption) (*computepb.Instance, error) { + return c.internalClient.Get(ctx, req, opts...) +} + +// GetEffectiveFirewalls returns effective firewalls applied to an interface of the instance. +func (c *InstancesClient) GetEffectiveFirewalls(ctx context.Context, req *computepb.GetEffectiveFirewallsInstanceRequest, opts ...gax.CallOption) (*computepb.InstancesGetEffectiveFirewallsResponse, error) { + return c.internalClient.GetEffectiveFirewalls(ctx, req, opts...) +} + +// GetGuestAttributes returns the specified guest attributes entry. +func (c *InstancesClient) GetGuestAttributes(ctx context.Context, req *computepb.GetGuestAttributesInstanceRequest, opts ...gax.CallOption) (*computepb.GuestAttributes, error) { + return c.internalClient.GetGuestAttributes(ctx, req, opts...) +} + +// GetIamPolicy gets the access control policy for a resource. May be empty if no such policy or resource exists. +func (c *InstancesClient) GetIamPolicy(ctx context.Context, req *computepb.GetIamPolicyInstanceRequest, opts ...gax.CallOption) (*computepb.Policy, error) { + return c.internalClient.GetIamPolicy(ctx, req, opts...) +} + +// GetScreenshot returns the screenshot from the specified instance. +func (c *InstancesClient) GetScreenshot(ctx context.Context, req *computepb.GetScreenshotInstanceRequest, opts ...gax.CallOption) (*computepb.Screenshot, error) { + return c.internalClient.GetScreenshot(ctx, req, opts...) +} + +// GetSerialPortOutput returns the last 1 MB of serial port output from the specified instance. +func (c *InstancesClient) GetSerialPortOutput(ctx context.Context, req *computepb.GetSerialPortOutputInstanceRequest, opts ...gax.CallOption) (*computepb.SerialPortOutput, error) { + return c.internalClient.GetSerialPortOutput(ctx, req, opts...) +} + +// GetShieldedInstanceIdentity returns the Shielded Instance Identity of an instance +func (c *InstancesClient) GetShieldedInstanceIdentity(ctx context.Context, req *computepb.GetShieldedInstanceIdentityInstanceRequest, opts ...gax.CallOption) (*computepb.ShieldedInstanceIdentity, error) { + return c.internalClient.GetShieldedInstanceIdentity(ctx, req, opts...) +} + +// Insert creates an instance resource in the specified project using the data included in the request. +func (c *InstancesClient) Insert(ctx context.Context, req *computepb.InsertInstanceRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.Insert(ctx, req, opts...) +} + +// List retrieves the list of instances contained within the specified zone. +func (c *InstancesClient) List(ctx context.Context, req *computepb.ListInstancesRequest, opts ...gax.CallOption) (*computepb.InstanceList, error) { + return c.internalClient.List(ctx, req, opts...) +} + +// ListReferrers retrieves a list of resources that refer to the VM instance specified in the request. For example, if the VM instance is part of a managed or unmanaged instance group, the referrers list includes the instance group. For more information, read Viewing referrers to VM instances. +func (c *InstancesClient) ListReferrers(ctx context.Context, req *computepb.ListReferrersInstancesRequest, opts ...gax.CallOption) (*computepb.InstanceListReferrers, error) { + return c.internalClient.ListReferrers(ctx, req, opts...) +} + +// RemoveResourcePolicies removes resource policies from an instance. +func (c *InstancesClient) RemoveResourcePolicies(ctx context.Context, req *computepb.RemoveResourcePoliciesInstanceRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.RemoveResourcePolicies(ctx, req, opts...) +} + +// Reset performs a reset on the instance. This is a hard reset the VM does not do a graceful shutdown. For more information, see Resetting an instance. +func (c *InstancesClient) Reset(ctx context.Context, req *computepb.ResetInstanceRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.Reset(ctx, req, opts...) +} + +// SetDeletionProtection sets deletion protection on the instance. +func (c *InstancesClient) SetDeletionProtection(ctx context.Context, req *computepb.SetDeletionProtectionInstanceRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.SetDeletionProtection(ctx, req, opts...) +} + +// SetDiskAutoDelete sets the auto-delete flag for a disk attached to an instance. +func (c *InstancesClient) SetDiskAutoDelete(ctx context.Context, req *computepb.SetDiskAutoDeleteInstanceRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.SetDiskAutoDelete(ctx, req, opts...) +} + +// SetIamPolicy sets the access control policy on the specified resource. Replaces any existing policy. +func (c *InstancesClient) SetIamPolicy(ctx context.Context, req *computepb.SetIamPolicyInstanceRequest, opts ...gax.CallOption) (*computepb.Policy, error) { + return c.internalClient.SetIamPolicy(ctx, req, opts...) +} + +// SetLabels sets labels on an instance. To learn more about labels, read the Labeling Resources documentation. +func (c *InstancesClient) SetLabels(ctx context.Context, req *computepb.SetLabelsInstanceRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.SetLabels(ctx, req, opts...) +} + +// SetMachineResources changes the number and/or type of accelerator for a stopped instance to the values specified in the request. +func (c *InstancesClient) SetMachineResources(ctx context.Context, req *computepb.SetMachineResourcesInstanceRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.SetMachineResources(ctx, req, opts...) +} + +// SetMachineType changes the machine type for a stopped instance to the machine type specified in the request. +func (c *InstancesClient) SetMachineType(ctx context.Context, req *computepb.SetMachineTypeInstanceRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.SetMachineType(ctx, req, opts...) +} + +// SetMetadata sets metadata for the specified instance to the data included in the request. +func (c *InstancesClient) SetMetadata(ctx context.Context, req *computepb.SetMetadataInstanceRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.SetMetadata(ctx, req, opts...) +} + +// SetMinCpuPlatform changes the minimum CPU platform that this instance should use. This method can only be called on a stopped instance. For more information, read Specifying a Minimum CPU Platform. +func (c *InstancesClient) SetMinCpuPlatform(ctx context.Context, req *computepb.SetMinCpuPlatformInstanceRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.SetMinCpuPlatform(ctx, req, opts...) +} + +// SetScheduling sets an instance’s scheduling options. You can only call this method on a stopped instance, that is, a VM instance that is in a TERMINATED state. See Instance Life Cycle for more information on the possible instance states. +func (c *InstancesClient) SetScheduling(ctx context.Context, req *computepb.SetSchedulingInstanceRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.SetScheduling(ctx, req, opts...) +} + +// SetServiceAccount sets the service account on the instance. For more information, read Changing the service account and access scopes for an instance. +func (c *InstancesClient) SetServiceAccount(ctx context.Context, req *computepb.SetServiceAccountInstanceRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.SetServiceAccount(ctx, req, opts...) +} + +// SetShieldedInstanceIntegrityPolicy sets the Shielded Instance integrity policy for an instance. You can only use this method on a running instance. This method supports PATCH semantics and uses the JSON merge patch format and processing rules. +func (c *InstancesClient) SetShieldedInstanceIntegrityPolicy(ctx context.Context, req *computepb.SetShieldedInstanceIntegrityPolicyInstanceRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.SetShieldedInstanceIntegrityPolicy(ctx, req, opts...) +} + +// SetTags sets network tags for the specified instance to the data included in the request. +func (c *InstancesClient) SetTags(ctx context.Context, req *computepb.SetTagsInstanceRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.SetTags(ctx, req, opts...) +} + +// SimulateMaintenanceEvent simulates a maintenance event on the instance. +func (c *InstancesClient) SimulateMaintenanceEvent(ctx context.Context, req *computepb.SimulateMaintenanceEventInstanceRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.SimulateMaintenanceEvent(ctx, req, opts...) +} + +// Start starts an instance that was stopped using the instances().stop method. For more information, see Restart an instance. +func (c *InstancesClient) Start(ctx context.Context, req *computepb.StartInstanceRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.Start(ctx, req, opts...) +} + +// StartWithEncryptionKey starts an instance that was stopped using the instances().stop method. For more information, see Restart an instance. +func (c *InstancesClient) StartWithEncryptionKey(ctx context.Context, req *computepb.StartWithEncryptionKeyInstanceRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.StartWithEncryptionKey(ctx, req, opts...) +} + +// Stop stops a running instance, shutting it down cleanly, and allows you to restart the instance at a later time. Stopped instances do not incur VM usage charges while they are stopped. However, resources that the VM is using, such as persistent disks and static IP addresses, will continue to be charged until they are deleted. For more information, see Stopping an instance. +func (c *InstancesClient) Stop(ctx context.Context, req *computepb.StopInstanceRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.Stop(ctx, req, opts...) +} + +// TestIamPermissions returns permissions that a caller has on the specified resource. +func (c *InstancesClient) TestIamPermissions(ctx context.Context, req *computepb.TestIamPermissionsInstanceRequest, opts ...gax.CallOption) (*computepb.TestPermissionsResponse, error) { + return c.internalClient.TestIamPermissions(ctx, req, opts...) +} + +// Update updates an instance only if the necessary resources are available. This method can update only a specific set of instance properties. See Updating a running instance for a list of updatable instance properties. +func (c *InstancesClient) Update(ctx context.Context, req *computepb.UpdateInstanceRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.Update(ctx, req, opts...) +} + +// UpdateAccessConfig updates the specified access config from an instance’s network interface with the data included in the request. This method supports PATCH semantics and uses the JSON merge patch format and processing rules. +func (c *InstancesClient) UpdateAccessConfig(ctx context.Context, req *computepb.UpdateAccessConfigInstanceRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.UpdateAccessConfig(ctx, req, opts...) +} + +// UpdateDisplayDevice updates the Display config for a VM instance. You can only use this method on a stopped VM instance. This method supports PATCH semantics and uses the JSON merge patch format and processing rules. +func (c *InstancesClient) UpdateDisplayDevice(ctx context.Context, req *computepb.UpdateDisplayDeviceInstanceRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.UpdateDisplayDevice(ctx, req, opts...) +} + +// UpdateNetworkInterface updates an instance’s network interface. This method can only update an interface’s alias IP range and attached network. See Modifying alias IP ranges for an existing instance for instructions on changing alias IP ranges. See Migrating a VM between networks for instructions on migrating an interface. This method follows PATCH semantics. +func (c *InstancesClient) UpdateNetworkInterface(ctx context.Context, req *computepb.UpdateNetworkInterfaceInstanceRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.UpdateNetworkInterface(ctx, req, opts...) +} + +// UpdateShieldedInstanceConfig updates the Shielded Instance config for an instance. You can only use this method on a stopped instance. This method supports PATCH semantics and uses the JSON merge patch format and processing rules. +func (c *InstancesClient) UpdateShieldedInstanceConfig(ctx context.Context, req *computepb.UpdateShieldedInstanceConfigInstanceRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.UpdateShieldedInstanceConfig(ctx, req, opts...) +} + +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +type instancesRESTClient struct { + // The http endpoint to connect to. + endpoint string + + // The http client. + httpClient *http.Client + + // The x-goog-* metadata to be sent with each request. + xGoogMetadata metadata.MD +} + +// NewInstancesRESTClient creates a new instances rest client. +// +// The Instances API. +func NewInstancesRESTClient(ctx context.Context, opts ...option.ClientOption) (*InstancesClient, error) { + clientOpts := append(defaultInstancesRESTClientOptions(), opts...) + httpClient, endpoint, err := httptransport.NewClient(ctx, clientOpts...) + if err != nil { + return nil, err + } + + c := &instancesRESTClient{ + endpoint: endpoint, + httpClient: httpClient, + } + c.setGoogleClientInfo() + + return &InstancesClient{internalClient: c, CallOptions: &InstancesCallOptions{}}, nil +} + +func defaultInstancesRESTClientOptions() []option.ClientOption { + return []option.ClientOption{ + internaloption.WithDefaultEndpoint("compute.googleapis.com"), + internaloption.WithDefaultMTLSEndpoint("compute.mtls.googleapis.com"), + internaloption.WithDefaultAudience("https://compute.googleapis.com/"), + internaloption.WithDefaultScopes(DefaultAuthScopes()...), + } +} + +// 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 *instancesRESTClient) setGoogleClientInfo(keyval ...string) { + kv := append([]string{"gl-go", versionGo()}, keyval...) + kv = append(kv, "gapic", versionClient, "gax", gax.Version, "rest", "UNKNOWN") + 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 *instancesRESTClient) Close() error { + // Replace httpClient with nil to force cleanup. + c.httpClient = nil + return nil +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *instancesRESTClient) Connection() *grpc.ClientConn { + return nil +} + +// AddAccessConfig adds an access config to an instance’s network interface. +func (c *instancesRESTClient) AddAccessConfig(ctx context.Context, req *computepb.AddAccessConfigInstanceRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetAccessConfigResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/zones/%v/instances/%v/addAccessConfig", req.GetProject(), req.GetZone(), req.GetInstance()) + + params := url.Values{} + if req.GetNetworkInterface() != "" { + params.Add("networkInterface", fmt.Sprintf("%v", req.GetNetworkInterface())) + } + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// AddResourcePolicies adds existing resource policies to an instance. You can only add one policy right now which will be applied to this instance for scheduling live migrations. +func (c *instancesRESTClient) AddResourcePolicies(ctx context.Context, req *computepb.AddResourcePoliciesInstanceRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetInstancesAddResourcePoliciesRequestResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/zones/%v/instances/%v/addResourcePolicies", req.GetProject(), req.GetZone(), req.GetInstance()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// AggregatedList retrieves aggregated list of all of the instances in your project across all regions and zones. +func (c *instancesRESTClient) AggregatedList(ctx context.Context, req *computepb.AggregatedListInstancesRequest, opts ...gax.CallOption) (*computepb.InstanceAggregatedList, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/aggregated/instances", req.GetProject()) + + params := url.Values{} + if req != nil && req.Filter != nil { + params.Add("filter", fmt.Sprintf("%v", req.GetFilter())) + } + if req != nil && req.IncludeAllScopes != nil { + params.Add("includeAllScopes", fmt.Sprintf("%v", req.GetIncludeAllScopes())) + } + if req != nil && req.MaxResults != nil { + params.Add("maxResults", fmt.Sprintf("%v", req.GetMaxResults())) + } + if req != nil && req.OrderBy != nil { + params.Add("orderBy", fmt.Sprintf("%v", req.GetOrderBy())) + } + if req != nil && req.PageToken != nil { + params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) + } + if req != nil && req.ReturnPartialSuccess != nil { + params.Add("returnPartialSuccess", fmt.Sprintf("%v", req.GetReturnPartialSuccess())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.InstanceAggregatedList{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// AttachDisk attaches an existing Disk resource to an instance. You must first create the disk before you can attach it. It is not possible to create and attach a disk at the same time. For more information, read Adding a persistent disk to your instance. +func (c *instancesRESTClient) AttachDisk(ctx context.Context, req *computepb.AttachDiskInstanceRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetAttachedDiskResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/zones/%v/instances/%v/attachDisk", req.GetProject(), req.GetZone(), req.GetInstance()) + + params := url.Values{} + if req != nil && req.ForceAttach != nil { + params.Add("forceAttach", fmt.Sprintf("%v", req.GetForceAttach())) + } + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// BulkInsert creates multiple instances. Count specifies the number of instances to create. +func (c *instancesRESTClient) BulkInsert(ctx context.Context, req *computepb.BulkInsertInstanceRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetBulkInsertInstanceResourceResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/zones/%v/instances/bulkInsert", req.GetProject(), req.GetZone()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Delete deletes the specified Instance resource. For more information, see Deleting an instance. +func (c *instancesRESTClient) Delete(ctx context.Context, req *computepb.DeleteInstanceRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/zones/%v/instances/%v", req.GetProject(), req.GetZone(), req.GetInstance()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("DELETE", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// DeleteAccessConfig deletes an access config from an instance’s network interface. +func (c *instancesRESTClient) DeleteAccessConfig(ctx context.Context, req *computepb.DeleteAccessConfigInstanceRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/zones/%v/instances/%v/deleteAccessConfig", req.GetProject(), req.GetZone(), req.GetInstance()) + + params := url.Values{} + if req.GetAccessConfig() != "" { + params.Add("accessConfig", fmt.Sprintf("%v", req.GetAccessConfig())) + } + if req.GetNetworkInterface() != "" { + params.Add("networkInterface", fmt.Sprintf("%v", req.GetNetworkInterface())) + } + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// DetachDisk detaches a disk from an instance. +func (c *instancesRESTClient) DetachDisk(ctx context.Context, req *computepb.DetachDiskInstanceRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/zones/%v/instances/%v/detachDisk", req.GetProject(), req.GetZone(), req.GetInstance()) + + params := url.Values{} + if req.GetDeviceName() != "" { + params.Add("deviceName", fmt.Sprintf("%v", req.GetDeviceName())) + } + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Get returns the specified Instance resource. Gets a list of available instances by making a list() request. +func (c *instancesRESTClient) Get(ctx context.Context, req *computepb.GetInstanceRequest, opts ...gax.CallOption) (*computepb.Instance, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/zones/%v/instances/%v", req.GetProject(), req.GetZone(), req.GetInstance()) + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Instance{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// GetEffectiveFirewalls returns effective firewalls applied to an interface of the instance. +func (c *instancesRESTClient) GetEffectiveFirewalls(ctx context.Context, req *computepb.GetEffectiveFirewallsInstanceRequest, opts ...gax.CallOption) (*computepb.InstancesGetEffectiveFirewallsResponse, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/zones/%v/instances/%v/getEffectiveFirewalls", req.GetProject(), req.GetZone(), req.GetInstance()) + + params := url.Values{} + if req.GetNetworkInterface() != "" { + params.Add("networkInterface", fmt.Sprintf("%v", req.GetNetworkInterface())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.InstancesGetEffectiveFirewallsResponse{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// GetGuestAttributes returns the specified guest attributes entry. +func (c *instancesRESTClient) GetGuestAttributes(ctx context.Context, req *computepb.GetGuestAttributesInstanceRequest, opts ...gax.CallOption) (*computepb.GuestAttributes, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/zones/%v/instances/%v/getGuestAttributes", req.GetProject(), req.GetZone(), req.GetInstance()) + + params := url.Values{} + if req != nil && req.QueryPath != nil { + params.Add("queryPath", fmt.Sprintf("%v", req.GetQueryPath())) + } + if req != nil && req.VariableKey != nil { + params.Add("variableKey", fmt.Sprintf("%v", req.GetVariableKey())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.GuestAttributes{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// GetIamPolicy gets the access control policy for a resource. May be empty if no such policy or resource exists. +func (c *instancesRESTClient) GetIamPolicy(ctx context.Context, req *computepb.GetIamPolicyInstanceRequest, opts ...gax.CallOption) (*computepb.Policy, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/zones/%v/instances/%v/getIamPolicy", req.GetProject(), req.GetZone(), req.GetResource()) + + params := url.Values{} + if req != nil && req.OptionsRequestedPolicyVersion != nil { + params.Add("optionsRequestedPolicyVersion", fmt.Sprintf("%v", req.GetOptionsRequestedPolicyVersion())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Policy{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// GetScreenshot returns the screenshot from the specified instance. +func (c *instancesRESTClient) GetScreenshot(ctx context.Context, req *computepb.GetScreenshotInstanceRequest, opts ...gax.CallOption) (*computepb.Screenshot, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/zones/%v/instances/%v/screenshot", req.GetProject(), req.GetZone(), req.GetInstance()) + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Screenshot{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// GetSerialPortOutput returns the last 1 MB of serial port output from the specified instance. +func (c *instancesRESTClient) GetSerialPortOutput(ctx context.Context, req *computepb.GetSerialPortOutputInstanceRequest, opts ...gax.CallOption) (*computepb.SerialPortOutput, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/zones/%v/instances/%v/serialPort", req.GetProject(), req.GetZone(), req.GetInstance()) + + params := url.Values{} + if req != nil && req.Port != nil { + params.Add("port", fmt.Sprintf("%v", req.GetPort())) + } + if req != nil && req.Start != nil { + params.Add("start", fmt.Sprintf("%v", req.GetStart())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.SerialPortOutput{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// GetShieldedInstanceIdentity returns the Shielded Instance Identity of an instance +func (c *instancesRESTClient) GetShieldedInstanceIdentity(ctx context.Context, req *computepb.GetShieldedInstanceIdentityInstanceRequest, opts ...gax.CallOption) (*computepb.ShieldedInstanceIdentity, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/zones/%v/instances/%v/getShieldedInstanceIdentity", req.GetProject(), req.GetZone(), req.GetInstance()) + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.ShieldedInstanceIdentity{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Insert creates an instance resource in the specified project using the data included in the request. +func (c *instancesRESTClient) Insert(ctx context.Context, req *computepb.InsertInstanceRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetInstanceResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/zones/%v/instances", req.GetProject(), req.GetZone()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + if req != nil && req.SourceInstanceTemplate != nil { + params.Add("sourceInstanceTemplate", fmt.Sprintf("%v", req.GetSourceInstanceTemplate())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// List retrieves the list of instances contained within the specified zone. +func (c *instancesRESTClient) List(ctx context.Context, req *computepb.ListInstancesRequest, opts ...gax.CallOption) (*computepb.InstanceList, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/zones/%v/instances", req.GetProject(), req.GetZone()) + + params := url.Values{} + if req != nil && req.Filter != nil { + params.Add("filter", fmt.Sprintf("%v", req.GetFilter())) + } + if req != nil && req.MaxResults != nil { + params.Add("maxResults", fmt.Sprintf("%v", req.GetMaxResults())) + } + if req != nil && req.OrderBy != nil { + params.Add("orderBy", fmt.Sprintf("%v", req.GetOrderBy())) + } + if req != nil && req.PageToken != nil { + params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) + } + if req != nil && req.ReturnPartialSuccess != nil { + params.Add("returnPartialSuccess", fmt.Sprintf("%v", req.GetReturnPartialSuccess())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.InstanceList{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// ListReferrers retrieves a list of resources that refer to the VM instance specified in the request. For example, if the VM instance is part of a managed or unmanaged instance group, the referrers list includes the instance group. For more information, read Viewing referrers to VM instances. +func (c *instancesRESTClient) ListReferrers(ctx context.Context, req *computepb.ListReferrersInstancesRequest, opts ...gax.CallOption) (*computepb.InstanceListReferrers, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/zones/%v/instances/%v/referrers", req.GetProject(), req.GetZone(), req.GetInstance()) + + params := url.Values{} + if req != nil && req.Filter != nil { + params.Add("filter", fmt.Sprintf("%v", req.GetFilter())) + } + if req != nil && req.MaxResults != nil { + params.Add("maxResults", fmt.Sprintf("%v", req.GetMaxResults())) + } + if req != nil && req.OrderBy != nil { + params.Add("orderBy", fmt.Sprintf("%v", req.GetOrderBy())) + } + if req != nil && req.PageToken != nil { + params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) + } + if req != nil && req.ReturnPartialSuccess != nil { + params.Add("returnPartialSuccess", fmt.Sprintf("%v", req.GetReturnPartialSuccess())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.InstanceListReferrers{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// RemoveResourcePolicies removes resource policies from an instance. +func (c *instancesRESTClient) RemoveResourcePolicies(ctx context.Context, req *computepb.RemoveResourcePoliciesInstanceRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetInstancesRemoveResourcePoliciesRequestResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/zones/%v/instances/%v/removeResourcePolicies", req.GetProject(), req.GetZone(), req.GetInstance()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Reset performs a reset on the instance. This is a hard reset the VM does not do a graceful shutdown. For more information, see Resetting an instance. +func (c *instancesRESTClient) Reset(ctx context.Context, req *computepb.ResetInstanceRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/zones/%v/instances/%v/reset", req.GetProject(), req.GetZone(), req.GetInstance()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// SetDeletionProtection sets deletion protection on the instance. +func (c *instancesRESTClient) SetDeletionProtection(ctx context.Context, req *computepb.SetDeletionProtectionInstanceRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/zones/%v/instances/%v/setDeletionProtection", req.GetProject(), req.GetZone(), req.GetResource()) + + params := url.Values{} + if req != nil && req.DeletionProtection != nil { + params.Add("deletionProtection", fmt.Sprintf("%v", req.GetDeletionProtection())) + } + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// SetDiskAutoDelete sets the auto-delete flag for a disk attached to an instance. +func (c *instancesRESTClient) SetDiskAutoDelete(ctx context.Context, req *computepb.SetDiskAutoDeleteInstanceRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/zones/%v/instances/%v/setDiskAutoDelete", req.GetProject(), req.GetZone(), req.GetInstance()) + + params := url.Values{} + if req.GetAutoDelete() { + params.Add("autoDelete", fmt.Sprintf("%v", req.GetAutoDelete())) + } + if req.GetDeviceName() != "" { + params.Add("deviceName", fmt.Sprintf("%v", req.GetDeviceName())) + } + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// SetIamPolicy sets the access control policy on the specified resource. Replaces any existing policy. +func (c *instancesRESTClient) SetIamPolicy(ctx context.Context, req *computepb.SetIamPolicyInstanceRequest, opts ...gax.CallOption) (*computepb.Policy, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetZoneSetPolicyRequestResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/zones/%v/instances/%v/setIamPolicy", req.GetProject(), req.GetZone(), req.GetResource()) + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Policy{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// SetLabels sets labels on an instance. To learn more about labels, read the Labeling Resources documentation. +func (c *instancesRESTClient) SetLabels(ctx context.Context, req *computepb.SetLabelsInstanceRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetInstancesSetLabelsRequestResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/zones/%v/instances/%v/setLabels", req.GetProject(), req.GetZone(), req.GetInstance()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// SetMachineResources changes the number and/or type of accelerator for a stopped instance to the values specified in the request. +func (c *instancesRESTClient) SetMachineResources(ctx context.Context, req *computepb.SetMachineResourcesInstanceRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetInstancesSetMachineResourcesRequestResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/zones/%v/instances/%v/setMachineResources", req.GetProject(), req.GetZone(), req.GetInstance()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// SetMachineType changes the machine type for a stopped instance to the machine type specified in the request. +func (c *instancesRESTClient) SetMachineType(ctx context.Context, req *computepb.SetMachineTypeInstanceRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetInstancesSetMachineTypeRequestResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/zones/%v/instances/%v/setMachineType", req.GetProject(), req.GetZone(), req.GetInstance()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// SetMetadata sets metadata for the specified instance to the data included in the request. +func (c *instancesRESTClient) SetMetadata(ctx context.Context, req *computepb.SetMetadataInstanceRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetMetadataResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/zones/%v/instances/%v/setMetadata", req.GetProject(), req.GetZone(), req.GetInstance()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// SetMinCpuPlatform changes the minimum CPU platform that this instance should use. This method can only be called on a stopped instance. For more information, read Specifying a Minimum CPU Platform. +func (c *instancesRESTClient) SetMinCpuPlatform(ctx context.Context, req *computepb.SetMinCpuPlatformInstanceRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetInstancesSetMinCpuPlatformRequestResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/zones/%v/instances/%v/setMinCpuPlatform", req.GetProject(), req.GetZone(), req.GetInstance()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// SetScheduling sets an instance’s scheduling options. You can only call this method on a stopped instance, that is, a VM instance that is in a TERMINATED state. See Instance Life Cycle for more information on the possible instance states. +func (c *instancesRESTClient) SetScheduling(ctx context.Context, req *computepb.SetSchedulingInstanceRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetSchedulingResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/zones/%v/instances/%v/setScheduling", req.GetProject(), req.GetZone(), req.GetInstance()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// SetServiceAccount sets the service account on the instance. For more information, read Changing the service account and access scopes for an instance. +func (c *instancesRESTClient) SetServiceAccount(ctx context.Context, req *computepb.SetServiceAccountInstanceRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetInstancesSetServiceAccountRequestResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/zones/%v/instances/%v/setServiceAccount", req.GetProject(), req.GetZone(), req.GetInstance()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// SetShieldedInstanceIntegrityPolicy sets the Shielded Instance integrity policy for an instance. You can only use this method on a running instance. This method supports PATCH semantics and uses the JSON merge patch format and processing rules. +func (c *instancesRESTClient) SetShieldedInstanceIntegrityPolicy(ctx context.Context, req *computepb.SetShieldedInstanceIntegrityPolicyInstanceRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetShieldedInstanceIntegrityPolicyResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/zones/%v/instances/%v/setShieldedInstanceIntegrityPolicy", req.GetProject(), req.GetZone(), req.GetInstance()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("PATCH", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// SetTags sets network tags for the specified instance to the data included in the request. +func (c *instancesRESTClient) SetTags(ctx context.Context, req *computepb.SetTagsInstanceRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetTagsResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/zones/%v/instances/%v/setTags", req.GetProject(), req.GetZone(), req.GetInstance()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// SimulateMaintenanceEvent simulates a maintenance event on the instance. +func (c *instancesRESTClient) SimulateMaintenanceEvent(ctx context.Context, req *computepb.SimulateMaintenanceEventInstanceRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/zones/%v/instances/%v/simulateMaintenanceEvent", req.GetProject(), req.GetZone(), req.GetInstance()) + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Start starts an instance that was stopped using the instances().stop method. For more information, see Restart an instance. +func (c *instancesRESTClient) Start(ctx context.Context, req *computepb.StartInstanceRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/zones/%v/instances/%v/start", req.GetProject(), req.GetZone(), req.GetInstance()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// StartWithEncryptionKey starts an instance that was stopped using the instances().stop method. For more information, see Restart an instance. +func (c *instancesRESTClient) StartWithEncryptionKey(ctx context.Context, req *computepb.StartWithEncryptionKeyInstanceRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetInstancesStartWithEncryptionKeyRequestResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/zones/%v/instances/%v/startWithEncryptionKey", req.GetProject(), req.GetZone(), req.GetInstance()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Stop stops a running instance, shutting it down cleanly, and allows you to restart the instance at a later time. Stopped instances do not incur VM usage charges while they are stopped. However, resources that the VM is using, such as persistent disks and static IP addresses, will continue to be charged until they are deleted. For more information, see Stopping an instance. +func (c *instancesRESTClient) Stop(ctx context.Context, req *computepb.StopInstanceRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/zones/%v/instances/%v/stop", req.GetProject(), req.GetZone(), req.GetInstance()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// TestIamPermissions returns permissions that a caller has on the specified resource. +func (c *instancesRESTClient) TestIamPermissions(ctx context.Context, req *computepb.TestIamPermissionsInstanceRequest, opts ...gax.CallOption) (*computepb.TestPermissionsResponse, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetTestPermissionsRequestResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/zones/%v/instances/%v/testIamPermissions", req.GetProject(), req.GetZone(), req.GetResource()) + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.TestPermissionsResponse{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Update updates an instance only if the necessary resources are available. This method can update only a specific set of instance properties. See Updating a running instance for a list of updatable instance properties. +func (c *instancesRESTClient) Update(ctx context.Context, req *computepb.UpdateInstanceRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetInstanceResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("") + + params := url.Values{} + if req.GetInstance() != "" { + params.Add("instance", fmt.Sprintf("%v", req.GetInstance())) + } + if req != nil && req.MinimalAction != nil { + params.Add("minimalAction", fmt.Sprintf("%v", req.GetMinimalAction())) + } + if req != nil && req.MostDisruptiveAllowedAction != nil { + params.Add("mostDisruptiveAllowedAction", fmt.Sprintf("%v", req.GetMostDisruptiveAllowedAction())) + } + if req.GetProject() != "" { + params.Add("project", fmt.Sprintf("%v", req.GetProject())) + } + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + if req.GetZone() != "" { + params.Add("zone", fmt.Sprintf("%v", req.GetZone())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("PUT", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// UpdateAccessConfig updates the specified access config from an instance’s network interface with the data included in the request. This method supports PATCH semantics and uses the JSON merge patch format and processing rules. +func (c *instancesRESTClient) UpdateAccessConfig(ctx context.Context, req *computepb.UpdateAccessConfigInstanceRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetAccessConfigResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/zones/%v/instances/%v/updateAccessConfig", req.GetProject(), req.GetZone(), req.GetInstance()) + + params := url.Values{} + if req.GetNetworkInterface() != "" { + params.Add("networkInterface", fmt.Sprintf("%v", req.GetNetworkInterface())) + } + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// UpdateDisplayDevice updates the Display config for a VM instance. You can only use this method on a stopped VM instance. This method supports PATCH semantics and uses the JSON merge patch format and processing rules. +func (c *instancesRESTClient) UpdateDisplayDevice(ctx context.Context, req *computepb.UpdateDisplayDeviceInstanceRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetDisplayDeviceResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/zones/%v/instances/%v/updateDisplayDevice", req.GetProject(), req.GetZone(), req.GetInstance()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("PATCH", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// UpdateNetworkInterface updates an instance’s network interface. This method can only update an interface’s alias IP range and attached network. See Modifying alias IP ranges for an existing instance for instructions on changing alias IP ranges. See Migrating a VM between networks for instructions on migrating an interface. This method follows PATCH semantics. +func (c *instancesRESTClient) UpdateNetworkInterface(ctx context.Context, req *computepb.UpdateNetworkInterfaceInstanceRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetNetworkInterfaceResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/zones/%v/instances/%v/updateNetworkInterface", req.GetProject(), req.GetZone(), req.GetInstance()) + + params := url.Values{} + if req.GetNetworkInterface() != "" { + params.Add("networkInterface", fmt.Sprintf("%v", req.GetNetworkInterface())) + } + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("PATCH", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// UpdateShieldedInstanceConfig updates the Shielded Instance config for an instance. You can only use this method on a stopped instance. This method supports PATCH semantics and uses the JSON merge patch format and processing rules. +func (c *instancesRESTClient) UpdateShieldedInstanceConfig(ctx context.Context, req *computepb.UpdateShieldedInstanceConfigInstanceRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetShieldedInstanceConfigResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/zones/%v/instances/%v/updateShieldedInstanceConfig", req.GetProject(), req.GetZone(), req.GetInstance()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("PATCH", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} diff --git a/compute/apiv1/instances_client_example_test.go b/compute/apiv1/instances_client_example_test.go new file mode 100644 index 00000000000..3728bb87319 --- /dev/null +++ b/compute/apiv1/instances_client_example_test.go @@ -0,0 +1,834 @@ +// 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 compute_test + +import ( + "context" + + compute "cloud.google.com/go/compute/apiv1" + computepb "google.golang.org/genproto/googleapis/cloud/compute/v1" +) + +func ExampleNewInstancesRESTClient() { + ctx := context.Background() + c, err := compute.NewInstancesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + // TODO: Use client. + _ = c +} + +func ExampleInstancesClient_AddAccessConfig() { + ctx := context.Background() + c, err := compute.NewInstancesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.AddAccessConfigInstanceRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.AddAccessConfig(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleInstancesClient_AddResourcePolicies() { + ctx := context.Background() + c, err := compute.NewInstancesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.AddResourcePoliciesInstanceRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.AddResourcePolicies(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleInstancesClient_AggregatedList() { + ctx := context.Background() + c, err := compute.NewInstancesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.AggregatedListInstancesRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.AggregatedList(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleInstancesClient_AttachDisk() { + ctx := context.Background() + c, err := compute.NewInstancesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.AttachDiskInstanceRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.AttachDisk(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleInstancesClient_BulkInsert() { + ctx := context.Background() + c, err := compute.NewInstancesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.BulkInsertInstanceRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.BulkInsert(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleInstancesClient_Delete() { + ctx := context.Background() + c, err := compute.NewInstancesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.DeleteInstanceRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Delete(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleInstancesClient_DeleteAccessConfig() { + ctx := context.Background() + c, err := compute.NewInstancesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.DeleteAccessConfigInstanceRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.DeleteAccessConfig(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleInstancesClient_DetachDisk() { + ctx := context.Background() + c, err := compute.NewInstancesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.DetachDiskInstanceRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.DetachDisk(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleInstancesClient_Get() { + ctx := context.Background() + c, err := compute.NewInstancesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.GetInstanceRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Get(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleInstancesClient_GetEffectiveFirewalls() { + ctx := context.Background() + c, err := compute.NewInstancesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.GetEffectiveFirewallsInstanceRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.GetEffectiveFirewalls(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleInstancesClient_GetGuestAttributes() { + ctx := context.Background() + c, err := compute.NewInstancesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.GetGuestAttributesInstanceRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.GetGuestAttributes(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleInstancesClient_GetIamPolicy() { + ctx := context.Background() + c, err := compute.NewInstancesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.GetIamPolicyInstanceRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.GetIamPolicy(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleInstancesClient_GetScreenshot() { + ctx := context.Background() + c, err := compute.NewInstancesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.GetScreenshotInstanceRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.GetScreenshot(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleInstancesClient_GetSerialPortOutput() { + ctx := context.Background() + c, err := compute.NewInstancesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.GetSerialPortOutputInstanceRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.GetSerialPortOutput(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleInstancesClient_GetShieldedInstanceIdentity() { + ctx := context.Background() + c, err := compute.NewInstancesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.GetShieldedInstanceIdentityInstanceRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.GetShieldedInstanceIdentity(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleInstancesClient_Insert() { + ctx := context.Background() + c, err := compute.NewInstancesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.InsertInstanceRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Insert(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleInstancesClient_List() { + ctx := context.Background() + c, err := compute.NewInstancesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.ListInstancesRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.List(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleInstancesClient_ListReferrers() { + ctx := context.Background() + c, err := compute.NewInstancesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.ListReferrersInstancesRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.ListReferrers(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleInstancesClient_RemoveResourcePolicies() { + ctx := context.Background() + c, err := compute.NewInstancesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.RemoveResourcePoliciesInstanceRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.RemoveResourcePolicies(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleInstancesClient_Reset() { + ctx := context.Background() + c, err := compute.NewInstancesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.ResetInstanceRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Reset(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleInstancesClient_SetDeletionProtection() { + ctx := context.Background() + c, err := compute.NewInstancesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.SetDeletionProtectionInstanceRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.SetDeletionProtection(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleInstancesClient_SetDiskAutoDelete() { + ctx := context.Background() + c, err := compute.NewInstancesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.SetDiskAutoDeleteInstanceRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.SetDiskAutoDelete(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleInstancesClient_SetIamPolicy() { + ctx := context.Background() + c, err := compute.NewInstancesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.SetIamPolicyInstanceRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.SetIamPolicy(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleInstancesClient_SetLabels() { + ctx := context.Background() + c, err := compute.NewInstancesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.SetLabelsInstanceRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.SetLabels(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleInstancesClient_SetMachineResources() { + ctx := context.Background() + c, err := compute.NewInstancesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.SetMachineResourcesInstanceRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.SetMachineResources(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleInstancesClient_SetMachineType() { + ctx := context.Background() + c, err := compute.NewInstancesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.SetMachineTypeInstanceRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.SetMachineType(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleInstancesClient_SetMetadata() { + ctx := context.Background() + c, err := compute.NewInstancesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.SetMetadataInstanceRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.SetMetadata(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleInstancesClient_SetMinCpuPlatform() { + ctx := context.Background() + c, err := compute.NewInstancesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.SetMinCpuPlatformInstanceRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.SetMinCpuPlatform(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleInstancesClient_SetScheduling() { + ctx := context.Background() + c, err := compute.NewInstancesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.SetSchedulingInstanceRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.SetScheduling(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleInstancesClient_SetServiceAccount() { + ctx := context.Background() + c, err := compute.NewInstancesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.SetServiceAccountInstanceRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.SetServiceAccount(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleInstancesClient_SetShieldedInstanceIntegrityPolicy() { + ctx := context.Background() + c, err := compute.NewInstancesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.SetShieldedInstanceIntegrityPolicyInstanceRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.SetShieldedInstanceIntegrityPolicy(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleInstancesClient_SetTags() { + ctx := context.Background() + c, err := compute.NewInstancesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.SetTagsInstanceRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.SetTags(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleInstancesClient_SimulateMaintenanceEvent() { + ctx := context.Background() + c, err := compute.NewInstancesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.SimulateMaintenanceEventInstanceRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.SimulateMaintenanceEvent(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleInstancesClient_Start() { + ctx := context.Background() + c, err := compute.NewInstancesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.StartInstanceRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Start(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleInstancesClient_StartWithEncryptionKey() { + ctx := context.Background() + c, err := compute.NewInstancesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.StartWithEncryptionKeyInstanceRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.StartWithEncryptionKey(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleInstancesClient_Stop() { + ctx := context.Background() + c, err := compute.NewInstancesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.StopInstanceRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Stop(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleInstancesClient_TestIamPermissions() { + ctx := context.Background() + c, err := compute.NewInstancesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.TestIamPermissionsInstanceRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.TestIamPermissions(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleInstancesClient_Update() { + ctx := context.Background() + c, err := compute.NewInstancesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.UpdateInstanceRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Update(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleInstancesClient_UpdateAccessConfig() { + ctx := context.Background() + c, err := compute.NewInstancesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.UpdateAccessConfigInstanceRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.UpdateAccessConfig(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleInstancesClient_UpdateDisplayDevice() { + ctx := context.Background() + c, err := compute.NewInstancesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.UpdateDisplayDeviceInstanceRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.UpdateDisplayDevice(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleInstancesClient_UpdateNetworkInterface() { + ctx := context.Background() + c, err := compute.NewInstancesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.UpdateNetworkInterfaceInstanceRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.UpdateNetworkInterface(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleInstancesClient_UpdateShieldedInstanceConfig() { + ctx := context.Background() + c, err := compute.NewInstancesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.UpdateShieldedInstanceConfigInstanceRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.UpdateShieldedInstanceConfig(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} diff --git a/compute/apiv1/interconnect_attachments_client.go b/compute/apiv1/interconnect_attachments_client.go new file mode 100644 index 00000000000..017f933fde0 --- /dev/null +++ b/compute/apiv1/interconnect_attachments_client.go @@ -0,0 +1,513 @@ +// 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 compute + +import ( + "bytes" + "context" + "fmt" + "io/ioutil" + "net/http" + "net/url" + + gax "github.com/googleapis/gax-go/v2" + "google.golang.org/api/option" + "google.golang.org/api/option/internaloption" + httptransport "google.golang.org/api/transport/http" + computepb "google.golang.org/genproto/googleapis/cloud/compute/v1" + "google.golang.org/grpc" + "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/encoding/protojson" +) + +var newInterconnectAttachmentsClientHook clientHook + +// InterconnectAttachmentsCallOptions contains the retry settings for each method of InterconnectAttachmentsClient. +type InterconnectAttachmentsCallOptions struct { + AggregatedList []gax.CallOption + Delete []gax.CallOption + Get []gax.CallOption + Insert []gax.CallOption + List []gax.CallOption + Patch []gax.CallOption +} + +// internalInterconnectAttachmentsClient is an interface that defines the methods availaible from Google Compute Engine API. +type internalInterconnectAttachmentsClient interface { + Close() error + setGoogleClientInfo(...string) + Connection() *grpc.ClientConn + AggregatedList(context.Context, *computepb.AggregatedListInterconnectAttachmentsRequest, ...gax.CallOption) (*computepb.InterconnectAttachmentAggregatedList, error) + Delete(context.Context, *computepb.DeleteInterconnectAttachmentRequest, ...gax.CallOption) (*computepb.Operation, error) + Get(context.Context, *computepb.GetInterconnectAttachmentRequest, ...gax.CallOption) (*computepb.InterconnectAttachment, error) + Insert(context.Context, *computepb.InsertInterconnectAttachmentRequest, ...gax.CallOption) (*computepb.Operation, error) + List(context.Context, *computepb.ListInterconnectAttachmentsRequest, ...gax.CallOption) (*computepb.InterconnectAttachmentList, error) + Patch(context.Context, *computepb.PatchInterconnectAttachmentRequest, ...gax.CallOption) (*computepb.Operation, error) +} + +// InterconnectAttachmentsClient is a client for interacting with Google Compute Engine API. +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +// +// The InterconnectAttachments API. +type InterconnectAttachmentsClient struct { + // The internal transport-dependent client. + internalClient internalInterconnectAttachmentsClient + + // The call options for this service. + CallOptions *InterconnectAttachmentsCallOptions +} + +// 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 *InterconnectAttachmentsClient) 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 *InterconnectAttachmentsClient) setGoogleClientInfo(keyval ...string) { + c.internalClient.setGoogleClientInfo(keyval...) +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *InterconnectAttachmentsClient) Connection() *grpc.ClientConn { + return c.internalClient.Connection() +} + +// AggregatedList retrieves an aggregated list of interconnect attachments. +func (c *InterconnectAttachmentsClient) AggregatedList(ctx context.Context, req *computepb.AggregatedListInterconnectAttachmentsRequest, opts ...gax.CallOption) (*computepb.InterconnectAttachmentAggregatedList, error) { + return c.internalClient.AggregatedList(ctx, req, opts...) +} + +// Delete deletes the specified interconnect attachment. +func (c *InterconnectAttachmentsClient) Delete(ctx context.Context, req *computepb.DeleteInterconnectAttachmentRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.Delete(ctx, req, opts...) +} + +// Get returns the specified interconnect attachment. +func (c *InterconnectAttachmentsClient) Get(ctx context.Context, req *computepb.GetInterconnectAttachmentRequest, opts ...gax.CallOption) (*computepb.InterconnectAttachment, error) { + return c.internalClient.Get(ctx, req, opts...) +} + +// Insert creates an InterconnectAttachment in the specified project using the data included in the request. +func (c *InterconnectAttachmentsClient) Insert(ctx context.Context, req *computepb.InsertInterconnectAttachmentRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.Insert(ctx, req, opts...) +} + +// List retrieves the list of interconnect attachments contained within the specified region. +func (c *InterconnectAttachmentsClient) List(ctx context.Context, req *computepb.ListInterconnectAttachmentsRequest, opts ...gax.CallOption) (*computepb.InterconnectAttachmentList, error) { + return c.internalClient.List(ctx, req, opts...) +} + +// Patch updates the specified interconnect attachment with the data included in the request. This method supports PATCH semantics and uses the JSON merge patch format and processing rules. +func (c *InterconnectAttachmentsClient) Patch(ctx context.Context, req *computepb.PatchInterconnectAttachmentRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.Patch(ctx, req, opts...) +} + +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +type interconnectAttachmentsRESTClient struct { + // The http endpoint to connect to. + endpoint string + + // The http client. + httpClient *http.Client + + // The x-goog-* metadata to be sent with each request. + xGoogMetadata metadata.MD +} + +// NewInterconnectAttachmentsRESTClient creates a new interconnect attachments rest client. +// +// The InterconnectAttachments API. +func NewInterconnectAttachmentsRESTClient(ctx context.Context, opts ...option.ClientOption) (*InterconnectAttachmentsClient, error) { + clientOpts := append(defaultInterconnectAttachmentsRESTClientOptions(), opts...) + httpClient, endpoint, err := httptransport.NewClient(ctx, clientOpts...) + if err != nil { + return nil, err + } + + c := &interconnectAttachmentsRESTClient{ + endpoint: endpoint, + httpClient: httpClient, + } + c.setGoogleClientInfo() + + return &InterconnectAttachmentsClient{internalClient: c, CallOptions: &InterconnectAttachmentsCallOptions{}}, nil +} + +func defaultInterconnectAttachmentsRESTClientOptions() []option.ClientOption { + return []option.ClientOption{ + internaloption.WithDefaultEndpoint("compute.googleapis.com"), + internaloption.WithDefaultMTLSEndpoint("compute.mtls.googleapis.com"), + internaloption.WithDefaultAudience("https://compute.googleapis.com/"), + internaloption.WithDefaultScopes(DefaultAuthScopes()...), + } +} + +// 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 *interconnectAttachmentsRESTClient) setGoogleClientInfo(keyval ...string) { + kv := append([]string{"gl-go", versionGo()}, keyval...) + kv = append(kv, "gapic", versionClient, "gax", gax.Version, "rest", "UNKNOWN") + 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 *interconnectAttachmentsRESTClient) Close() error { + // Replace httpClient with nil to force cleanup. + c.httpClient = nil + return nil +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *interconnectAttachmentsRESTClient) Connection() *grpc.ClientConn { + return nil +} + +// AggregatedList retrieves an aggregated list of interconnect attachments. +func (c *interconnectAttachmentsRESTClient) AggregatedList(ctx context.Context, req *computepb.AggregatedListInterconnectAttachmentsRequest, opts ...gax.CallOption) (*computepb.InterconnectAttachmentAggregatedList, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/aggregated/interconnectAttachments", req.GetProject()) + + params := url.Values{} + if req != nil && req.Filter != nil { + params.Add("filter", fmt.Sprintf("%v", req.GetFilter())) + } + if req != nil && req.IncludeAllScopes != nil { + params.Add("includeAllScopes", fmt.Sprintf("%v", req.GetIncludeAllScopes())) + } + if req != nil && req.MaxResults != nil { + params.Add("maxResults", fmt.Sprintf("%v", req.GetMaxResults())) + } + if req != nil && req.OrderBy != nil { + params.Add("orderBy", fmt.Sprintf("%v", req.GetOrderBy())) + } + if req != nil && req.PageToken != nil { + params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) + } + if req != nil && req.ReturnPartialSuccess != nil { + params.Add("returnPartialSuccess", fmt.Sprintf("%v", req.GetReturnPartialSuccess())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.InterconnectAttachmentAggregatedList{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Delete deletes the specified interconnect attachment. +func (c *interconnectAttachmentsRESTClient) Delete(ctx context.Context, req *computepb.DeleteInterconnectAttachmentRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/regions/%v/interconnectAttachments/%v", req.GetProject(), req.GetRegion(), req.GetInterconnectAttachment()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("DELETE", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Get returns the specified interconnect attachment. +func (c *interconnectAttachmentsRESTClient) Get(ctx context.Context, req *computepb.GetInterconnectAttachmentRequest, opts ...gax.CallOption) (*computepb.InterconnectAttachment, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/regions/%v/interconnectAttachments/%v", req.GetProject(), req.GetRegion(), req.GetInterconnectAttachment()) + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.InterconnectAttachment{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Insert creates an InterconnectAttachment in the specified project using the data included in the request. +func (c *interconnectAttachmentsRESTClient) Insert(ctx context.Context, req *computepb.InsertInterconnectAttachmentRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetInterconnectAttachmentResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/regions/%v/interconnectAttachments", req.GetProject(), req.GetRegion()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + if req != nil && req.ValidateOnly != nil { + params.Add("validateOnly", fmt.Sprintf("%v", req.GetValidateOnly())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// List retrieves the list of interconnect attachments contained within the specified region. +func (c *interconnectAttachmentsRESTClient) List(ctx context.Context, req *computepb.ListInterconnectAttachmentsRequest, opts ...gax.CallOption) (*computepb.InterconnectAttachmentList, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/regions/%v/interconnectAttachments", req.GetProject(), req.GetRegion()) + + params := url.Values{} + if req != nil && req.Filter != nil { + params.Add("filter", fmt.Sprintf("%v", req.GetFilter())) + } + if req != nil && req.MaxResults != nil { + params.Add("maxResults", fmt.Sprintf("%v", req.GetMaxResults())) + } + if req != nil && req.OrderBy != nil { + params.Add("orderBy", fmt.Sprintf("%v", req.GetOrderBy())) + } + if req != nil && req.PageToken != nil { + params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) + } + if req != nil && req.ReturnPartialSuccess != nil { + params.Add("returnPartialSuccess", fmt.Sprintf("%v", req.GetReturnPartialSuccess())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.InterconnectAttachmentList{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Patch updates the specified interconnect attachment with the data included in the request. This method supports PATCH semantics and uses the JSON merge patch format and processing rules. +func (c *interconnectAttachmentsRESTClient) Patch(ctx context.Context, req *computepb.PatchInterconnectAttachmentRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetInterconnectAttachmentResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/regions/%v/interconnectAttachments/%v", req.GetProject(), req.GetRegion(), req.GetInterconnectAttachment()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("PATCH", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} diff --git a/compute/apiv1/interconnect_attachments_client_example_test.go b/compute/apiv1/interconnect_attachments_client_example_test.go new file mode 100644 index 00000000000..0f480c1a58a --- /dev/null +++ b/compute/apiv1/interconnect_attachments_client_example_test.go @@ -0,0 +1,150 @@ +// 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 compute_test + +import ( + "context" + + compute "cloud.google.com/go/compute/apiv1" + computepb "google.golang.org/genproto/googleapis/cloud/compute/v1" +) + +func ExampleNewInterconnectAttachmentsRESTClient() { + ctx := context.Background() + c, err := compute.NewInterconnectAttachmentsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + // TODO: Use client. + _ = c +} + +func ExampleInterconnectAttachmentsClient_AggregatedList() { + ctx := context.Background() + c, err := compute.NewInterconnectAttachmentsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.AggregatedListInterconnectAttachmentsRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.AggregatedList(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleInterconnectAttachmentsClient_Delete() { + ctx := context.Background() + c, err := compute.NewInterconnectAttachmentsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.DeleteInterconnectAttachmentRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Delete(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleInterconnectAttachmentsClient_Get() { + ctx := context.Background() + c, err := compute.NewInterconnectAttachmentsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.GetInterconnectAttachmentRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Get(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleInterconnectAttachmentsClient_Insert() { + ctx := context.Background() + c, err := compute.NewInterconnectAttachmentsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.InsertInterconnectAttachmentRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Insert(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleInterconnectAttachmentsClient_List() { + ctx := context.Background() + c, err := compute.NewInterconnectAttachmentsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.ListInterconnectAttachmentsRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.List(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleInterconnectAttachmentsClient_Patch() { + ctx := context.Background() + c, err := compute.NewInterconnectAttachmentsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.PatchInterconnectAttachmentRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Patch(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} diff --git a/compute/apiv1/interconnect_locations_client.go b/compute/apiv1/interconnect_locations_client.go new file mode 100644 index 00000000000..cf535f106e4 --- /dev/null +++ b/compute/apiv1/interconnect_locations_client.go @@ -0,0 +1,265 @@ +// 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 compute + +import ( + "bytes" + "context" + "fmt" + "io/ioutil" + "net/http" + "net/url" + + gax "github.com/googleapis/gax-go/v2" + "google.golang.org/api/option" + "google.golang.org/api/option/internaloption" + httptransport "google.golang.org/api/transport/http" + computepb "google.golang.org/genproto/googleapis/cloud/compute/v1" + "google.golang.org/grpc" + "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/encoding/protojson" +) + +var newInterconnectLocationsClientHook clientHook + +// InterconnectLocationsCallOptions contains the retry settings for each method of InterconnectLocationsClient. +type InterconnectLocationsCallOptions struct { + Get []gax.CallOption + List []gax.CallOption +} + +// internalInterconnectLocationsClient is an interface that defines the methods availaible from Google Compute Engine API. +type internalInterconnectLocationsClient interface { + Close() error + setGoogleClientInfo(...string) + Connection() *grpc.ClientConn + Get(context.Context, *computepb.GetInterconnectLocationRequest, ...gax.CallOption) (*computepb.InterconnectLocation, error) + List(context.Context, *computepb.ListInterconnectLocationsRequest, ...gax.CallOption) (*computepb.InterconnectLocationList, error) +} + +// InterconnectLocationsClient is a client for interacting with Google Compute Engine API. +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +// +// The InterconnectLocations API. +type InterconnectLocationsClient struct { + // The internal transport-dependent client. + internalClient internalInterconnectLocationsClient + + // The call options for this service. + CallOptions *InterconnectLocationsCallOptions +} + +// 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 *InterconnectLocationsClient) 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 *InterconnectLocationsClient) setGoogleClientInfo(keyval ...string) { + c.internalClient.setGoogleClientInfo(keyval...) +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *InterconnectLocationsClient) Connection() *grpc.ClientConn { + return c.internalClient.Connection() +} + +// Get returns the details for the specified interconnect location. Gets a list of available interconnect locations by making a list() request. +func (c *InterconnectLocationsClient) Get(ctx context.Context, req *computepb.GetInterconnectLocationRequest, opts ...gax.CallOption) (*computepb.InterconnectLocation, error) { + return c.internalClient.Get(ctx, req, opts...) +} + +// List retrieves the list of interconnect locations available to the specified project. +func (c *InterconnectLocationsClient) List(ctx context.Context, req *computepb.ListInterconnectLocationsRequest, opts ...gax.CallOption) (*computepb.InterconnectLocationList, error) { + return c.internalClient.List(ctx, req, opts...) +} + +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +type interconnectLocationsRESTClient struct { + // The http endpoint to connect to. + endpoint string + + // The http client. + httpClient *http.Client + + // The x-goog-* metadata to be sent with each request. + xGoogMetadata metadata.MD +} + +// NewInterconnectLocationsRESTClient creates a new interconnect locations rest client. +// +// The InterconnectLocations API. +func NewInterconnectLocationsRESTClient(ctx context.Context, opts ...option.ClientOption) (*InterconnectLocationsClient, error) { + clientOpts := append(defaultInterconnectLocationsRESTClientOptions(), opts...) + httpClient, endpoint, err := httptransport.NewClient(ctx, clientOpts...) + if err != nil { + return nil, err + } + + c := &interconnectLocationsRESTClient{ + endpoint: endpoint, + httpClient: httpClient, + } + c.setGoogleClientInfo() + + return &InterconnectLocationsClient{internalClient: c, CallOptions: &InterconnectLocationsCallOptions{}}, nil +} + +func defaultInterconnectLocationsRESTClientOptions() []option.ClientOption { + return []option.ClientOption{ + internaloption.WithDefaultEndpoint("compute.googleapis.com"), + internaloption.WithDefaultMTLSEndpoint("compute.mtls.googleapis.com"), + internaloption.WithDefaultAudience("https://compute.googleapis.com/"), + internaloption.WithDefaultScopes(DefaultAuthScopes()...), + } +} + +// 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 *interconnectLocationsRESTClient) setGoogleClientInfo(keyval ...string) { + kv := append([]string{"gl-go", versionGo()}, keyval...) + kv = append(kv, "gapic", versionClient, "gax", gax.Version, "rest", "UNKNOWN") + 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 *interconnectLocationsRESTClient) Close() error { + // Replace httpClient with nil to force cleanup. + c.httpClient = nil + return nil +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *interconnectLocationsRESTClient) Connection() *grpc.ClientConn { + return nil +} + +// Get returns the details for the specified interconnect location. Gets a list of available interconnect locations by making a list() request. +func (c *interconnectLocationsRESTClient) Get(ctx context.Context, req *computepb.GetInterconnectLocationRequest, opts ...gax.CallOption) (*computepb.InterconnectLocation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/interconnectLocations/%v", req.GetProject(), req.GetInterconnectLocation()) + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.InterconnectLocation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// List retrieves the list of interconnect locations available to the specified project. +func (c *interconnectLocationsRESTClient) List(ctx context.Context, req *computepb.ListInterconnectLocationsRequest, opts ...gax.CallOption) (*computepb.InterconnectLocationList, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/interconnectLocations", req.GetProject()) + + params := url.Values{} + if req != nil && req.Filter != nil { + params.Add("filter", fmt.Sprintf("%v", req.GetFilter())) + } + if req != nil && req.MaxResults != nil { + params.Add("maxResults", fmt.Sprintf("%v", req.GetMaxResults())) + } + if req != nil && req.OrderBy != nil { + params.Add("orderBy", fmt.Sprintf("%v", req.GetOrderBy())) + } + if req != nil && req.PageToken != nil { + params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) + } + if req != nil && req.ReturnPartialSuccess != nil { + params.Add("returnPartialSuccess", fmt.Sprintf("%v", req.GetReturnPartialSuccess())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.InterconnectLocationList{} + + return rsp, unm.Unmarshal(buf, rsp) +} diff --git a/compute/apiv1/interconnect_locations_client_example_test.go b/compute/apiv1/interconnect_locations_client_example_test.go new file mode 100644 index 00000000000..2c48d43fbb8 --- /dev/null +++ b/compute/apiv1/interconnect_locations_client_example_test.go @@ -0,0 +1,74 @@ +// 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 compute_test + +import ( + "context" + + compute "cloud.google.com/go/compute/apiv1" + computepb "google.golang.org/genproto/googleapis/cloud/compute/v1" +) + +func ExampleNewInterconnectLocationsRESTClient() { + ctx := context.Background() + c, err := compute.NewInterconnectLocationsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + // TODO: Use client. + _ = c +} + +func ExampleInterconnectLocationsClient_Get() { + ctx := context.Background() + c, err := compute.NewInterconnectLocationsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.GetInterconnectLocationRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Get(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleInterconnectLocationsClient_List() { + ctx := context.Background() + c, err := compute.NewInterconnectLocationsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.ListInterconnectLocationsRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.List(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} diff --git a/compute/apiv1/interconnects_client.go b/compute/apiv1/interconnects_client.go new file mode 100644 index 00000000000..26fa2f16ccb --- /dev/null +++ b/compute/apiv1/interconnects_client.go @@ -0,0 +1,488 @@ +// 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 compute + +import ( + "bytes" + "context" + "fmt" + "io/ioutil" + "net/http" + "net/url" + + gax "github.com/googleapis/gax-go/v2" + "google.golang.org/api/option" + "google.golang.org/api/option/internaloption" + httptransport "google.golang.org/api/transport/http" + computepb "google.golang.org/genproto/googleapis/cloud/compute/v1" + "google.golang.org/grpc" + "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/encoding/protojson" +) + +var newInterconnectsClientHook clientHook + +// InterconnectsCallOptions contains the retry settings for each method of InterconnectsClient. +type InterconnectsCallOptions struct { + Delete []gax.CallOption + Get []gax.CallOption + GetDiagnostics []gax.CallOption + Insert []gax.CallOption + List []gax.CallOption + Patch []gax.CallOption +} + +// internalInterconnectsClient is an interface that defines the methods availaible from Google Compute Engine API. +type internalInterconnectsClient interface { + Close() error + setGoogleClientInfo(...string) + Connection() *grpc.ClientConn + Delete(context.Context, *computepb.DeleteInterconnectRequest, ...gax.CallOption) (*computepb.Operation, error) + Get(context.Context, *computepb.GetInterconnectRequest, ...gax.CallOption) (*computepb.Interconnect, error) + GetDiagnostics(context.Context, *computepb.GetDiagnosticsInterconnectRequest, ...gax.CallOption) (*computepb.InterconnectsGetDiagnosticsResponse, error) + Insert(context.Context, *computepb.InsertInterconnectRequest, ...gax.CallOption) (*computepb.Operation, error) + List(context.Context, *computepb.ListInterconnectsRequest, ...gax.CallOption) (*computepb.InterconnectList, error) + Patch(context.Context, *computepb.PatchInterconnectRequest, ...gax.CallOption) (*computepb.Operation, error) +} + +// InterconnectsClient is a client for interacting with Google Compute Engine API. +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +// +// The Interconnects API. +type InterconnectsClient struct { + // The internal transport-dependent client. + internalClient internalInterconnectsClient + + // The call options for this service. + CallOptions *InterconnectsCallOptions +} + +// 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 *InterconnectsClient) 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 *InterconnectsClient) setGoogleClientInfo(keyval ...string) { + c.internalClient.setGoogleClientInfo(keyval...) +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *InterconnectsClient) Connection() *grpc.ClientConn { + return c.internalClient.Connection() +} + +// Delete deletes the specified interconnect. +func (c *InterconnectsClient) Delete(ctx context.Context, req *computepb.DeleteInterconnectRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.Delete(ctx, req, opts...) +} + +// Get returns the specified interconnect. Get a list of available interconnects by making a list() request. +func (c *InterconnectsClient) Get(ctx context.Context, req *computepb.GetInterconnectRequest, opts ...gax.CallOption) (*computepb.Interconnect, error) { + return c.internalClient.Get(ctx, req, opts...) +} + +// GetDiagnostics returns the interconnectDiagnostics for the specified interconnect. +func (c *InterconnectsClient) GetDiagnostics(ctx context.Context, req *computepb.GetDiagnosticsInterconnectRequest, opts ...gax.CallOption) (*computepb.InterconnectsGetDiagnosticsResponse, error) { + return c.internalClient.GetDiagnostics(ctx, req, opts...) +} + +// Insert creates a Interconnect in the specified project using the data included in the request. +func (c *InterconnectsClient) Insert(ctx context.Context, req *computepb.InsertInterconnectRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.Insert(ctx, req, opts...) +} + +// List retrieves the list of interconnect available to the specified project. +func (c *InterconnectsClient) List(ctx context.Context, req *computepb.ListInterconnectsRequest, opts ...gax.CallOption) (*computepb.InterconnectList, error) { + return c.internalClient.List(ctx, req, opts...) +} + +// Patch updates the specified interconnect with the data included in the request. This method supports PATCH semantics and uses the JSON merge patch format and processing rules. +func (c *InterconnectsClient) Patch(ctx context.Context, req *computepb.PatchInterconnectRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.Patch(ctx, req, opts...) +} + +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +type interconnectsRESTClient struct { + // The http endpoint to connect to. + endpoint string + + // The http client. + httpClient *http.Client + + // The x-goog-* metadata to be sent with each request. + xGoogMetadata metadata.MD +} + +// NewInterconnectsRESTClient creates a new interconnects rest client. +// +// The Interconnects API. +func NewInterconnectsRESTClient(ctx context.Context, opts ...option.ClientOption) (*InterconnectsClient, error) { + clientOpts := append(defaultInterconnectsRESTClientOptions(), opts...) + httpClient, endpoint, err := httptransport.NewClient(ctx, clientOpts...) + if err != nil { + return nil, err + } + + c := &interconnectsRESTClient{ + endpoint: endpoint, + httpClient: httpClient, + } + c.setGoogleClientInfo() + + return &InterconnectsClient{internalClient: c, CallOptions: &InterconnectsCallOptions{}}, nil +} + +func defaultInterconnectsRESTClientOptions() []option.ClientOption { + return []option.ClientOption{ + internaloption.WithDefaultEndpoint("compute.googleapis.com"), + internaloption.WithDefaultMTLSEndpoint("compute.mtls.googleapis.com"), + internaloption.WithDefaultAudience("https://compute.googleapis.com/"), + internaloption.WithDefaultScopes(DefaultAuthScopes()...), + } +} + +// 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 *interconnectsRESTClient) setGoogleClientInfo(keyval ...string) { + kv := append([]string{"gl-go", versionGo()}, keyval...) + kv = append(kv, "gapic", versionClient, "gax", gax.Version, "rest", "UNKNOWN") + 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 *interconnectsRESTClient) Close() error { + // Replace httpClient with nil to force cleanup. + c.httpClient = nil + return nil +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *interconnectsRESTClient) Connection() *grpc.ClientConn { + return nil +} + +// Delete deletes the specified interconnect. +func (c *interconnectsRESTClient) Delete(ctx context.Context, req *computepb.DeleteInterconnectRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/interconnects/%v", req.GetProject(), req.GetInterconnect()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("DELETE", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Get returns the specified interconnect. Get a list of available interconnects by making a list() request. +func (c *interconnectsRESTClient) Get(ctx context.Context, req *computepb.GetInterconnectRequest, opts ...gax.CallOption) (*computepb.Interconnect, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/interconnects/%v", req.GetProject(), req.GetInterconnect()) + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Interconnect{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// GetDiagnostics returns the interconnectDiagnostics for the specified interconnect. +func (c *interconnectsRESTClient) GetDiagnostics(ctx context.Context, req *computepb.GetDiagnosticsInterconnectRequest, opts ...gax.CallOption) (*computepb.InterconnectsGetDiagnosticsResponse, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/interconnects/%v/getDiagnostics", req.GetProject(), req.GetInterconnect()) + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.InterconnectsGetDiagnosticsResponse{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Insert creates a Interconnect in the specified project using the data included in the request. +func (c *interconnectsRESTClient) Insert(ctx context.Context, req *computepb.InsertInterconnectRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetInterconnectResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/interconnects", req.GetProject()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// List retrieves the list of interconnect available to the specified project. +func (c *interconnectsRESTClient) List(ctx context.Context, req *computepb.ListInterconnectsRequest, opts ...gax.CallOption) (*computepb.InterconnectList, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/interconnects", req.GetProject()) + + params := url.Values{} + if req != nil && req.Filter != nil { + params.Add("filter", fmt.Sprintf("%v", req.GetFilter())) + } + if req != nil && req.MaxResults != nil { + params.Add("maxResults", fmt.Sprintf("%v", req.GetMaxResults())) + } + if req != nil && req.OrderBy != nil { + params.Add("orderBy", fmt.Sprintf("%v", req.GetOrderBy())) + } + if req != nil && req.PageToken != nil { + params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) + } + if req != nil && req.ReturnPartialSuccess != nil { + params.Add("returnPartialSuccess", fmt.Sprintf("%v", req.GetReturnPartialSuccess())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.InterconnectList{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Patch updates the specified interconnect with the data included in the request. This method supports PATCH semantics and uses the JSON merge patch format and processing rules. +func (c *interconnectsRESTClient) Patch(ctx context.Context, req *computepb.PatchInterconnectRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetInterconnectResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/interconnects/%v", req.GetProject(), req.GetInterconnect()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("PATCH", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} diff --git a/compute/apiv1/interconnects_client_example_test.go b/compute/apiv1/interconnects_client_example_test.go new file mode 100644 index 00000000000..dca1482656b --- /dev/null +++ b/compute/apiv1/interconnects_client_example_test.go @@ -0,0 +1,150 @@ +// 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 compute_test + +import ( + "context" + + compute "cloud.google.com/go/compute/apiv1" + computepb "google.golang.org/genproto/googleapis/cloud/compute/v1" +) + +func ExampleNewInterconnectsRESTClient() { + ctx := context.Background() + c, err := compute.NewInterconnectsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + // TODO: Use client. + _ = c +} + +func ExampleInterconnectsClient_Delete() { + ctx := context.Background() + c, err := compute.NewInterconnectsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.DeleteInterconnectRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Delete(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleInterconnectsClient_Get() { + ctx := context.Background() + c, err := compute.NewInterconnectsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.GetInterconnectRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Get(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleInterconnectsClient_GetDiagnostics() { + ctx := context.Background() + c, err := compute.NewInterconnectsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.GetDiagnosticsInterconnectRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.GetDiagnostics(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleInterconnectsClient_Insert() { + ctx := context.Background() + c, err := compute.NewInterconnectsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.InsertInterconnectRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Insert(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleInterconnectsClient_List() { + ctx := context.Background() + c, err := compute.NewInterconnectsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.ListInterconnectsRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.List(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleInterconnectsClient_Patch() { + ctx := context.Background() + c, err := compute.NewInterconnectsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.PatchInterconnectRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Patch(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} diff --git a/compute/apiv1/license_codes_client.go b/compute/apiv1/license_codes_client.go new file mode 100644 index 00000000000..b87bb61e79e --- /dev/null +++ b/compute/apiv1/license_codes_client.go @@ -0,0 +1,247 @@ +// 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 compute + +import ( + "bytes" + "context" + "fmt" + "io/ioutil" + "net/http" + "net/url" + + gax "github.com/googleapis/gax-go/v2" + "google.golang.org/api/option" + "google.golang.org/api/option/internaloption" + httptransport "google.golang.org/api/transport/http" + computepb "google.golang.org/genproto/googleapis/cloud/compute/v1" + "google.golang.org/grpc" + "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/encoding/protojson" +) + +var newLicenseCodesClientHook clientHook + +// LicenseCodesCallOptions contains the retry settings for each method of LicenseCodesClient. +type LicenseCodesCallOptions struct { + Get []gax.CallOption + TestIamPermissions []gax.CallOption +} + +// internalLicenseCodesClient is an interface that defines the methods availaible from Google Compute Engine API. +type internalLicenseCodesClient interface { + Close() error + setGoogleClientInfo(...string) + Connection() *grpc.ClientConn + Get(context.Context, *computepb.GetLicenseCodeRequest, ...gax.CallOption) (*computepb.LicenseCode, error) + TestIamPermissions(context.Context, *computepb.TestIamPermissionsLicenseCodeRequest, ...gax.CallOption) (*computepb.TestPermissionsResponse, error) +} + +// LicenseCodesClient is a client for interacting with Google Compute Engine API. +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +// +// The LicenseCodes API. +type LicenseCodesClient struct { + // The internal transport-dependent client. + internalClient internalLicenseCodesClient + + // The call options for this service. + CallOptions *LicenseCodesCallOptions +} + +// 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 *LicenseCodesClient) 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 *LicenseCodesClient) setGoogleClientInfo(keyval ...string) { + c.internalClient.setGoogleClientInfo(keyval...) +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *LicenseCodesClient) Connection() *grpc.ClientConn { + return c.internalClient.Connection() +} + +// Get return a specified license code. License codes are mirrored across all projects that have permissions to read the License Code. Caution This resource is intended for use only by third-party partners who are creating Cloud Marketplace images. +func (c *LicenseCodesClient) Get(ctx context.Context, req *computepb.GetLicenseCodeRequest, opts ...gax.CallOption) (*computepb.LicenseCode, error) { + return c.internalClient.Get(ctx, req, opts...) +} + +// TestIamPermissions returns permissions that a caller has on the specified resource. Caution This resource is intended for use only by third-party partners who are creating Cloud Marketplace images. +func (c *LicenseCodesClient) TestIamPermissions(ctx context.Context, req *computepb.TestIamPermissionsLicenseCodeRequest, opts ...gax.CallOption) (*computepb.TestPermissionsResponse, error) { + return c.internalClient.TestIamPermissions(ctx, req, opts...) +} + +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +type licenseCodesRESTClient struct { + // The http endpoint to connect to. + endpoint string + + // The http client. + httpClient *http.Client + + // The x-goog-* metadata to be sent with each request. + xGoogMetadata metadata.MD +} + +// NewLicenseCodesRESTClient creates a new license codes rest client. +// +// The LicenseCodes API. +func NewLicenseCodesRESTClient(ctx context.Context, opts ...option.ClientOption) (*LicenseCodesClient, error) { + clientOpts := append(defaultLicenseCodesRESTClientOptions(), opts...) + httpClient, endpoint, err := httptransport.NewClient(ctx, clientOpts...) + if err != nil { + return nil, err + } + + c := &licenseCodesRESTClient{ + endpoint: endpoint, + httpClient: httpClient, + } + c.setGoogleClientInfo() + + return &LicenseCodesClient{internalClient: c, CallOptions: &LicenseCodesCallOptions{}}, nil +} + +func defaultLicenseCodesRESTClientOptions() []option.ClientOption { + return []option.ClientOption{ + internaloption.WithDefaultEndpoint("compute.googleapis.com"), + internaloption.WithDefaultMTLSEndpoint("compute.mtls.googleapis.com"), + internaloption.WithDefaultAudience("https://compute.googleapis.com/"), + internaloption.WithDefaultScopes(DefaultAuthScopes()...), + } +} + +// 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 *licenseCodesRESTClient) setGoogleClientInfo(keyval ...string) { + kv := append([]string{"gl-go", versionGo()}, keyval...) + kv = append(kv, "gapic", versionClient, "gax", gax.Version, "rest", "UNKNOWN") + 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 *licenseCodesRESTClient) Close() error { + // Replace httpClient with nil to force cleanup. + c.httpClient = nil + return nil +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *licenseCodesRESTClient) Connection() *grpc.ClientConn { + return nil +} + +// Get return a specified license code. License codes are mirrored across all projects that have permissions to read the License Code. Caution This resource is intended for use only by third-party partners who are creating Cloud Marketplace images. +func (c *licenseCodesRESTClient) Get(ctx context.Context, req *computepb.GetLicenseCodeRequest, opts ...gax.CallOption) (*computepb.LicenseCode, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/licenseCodes/%v", req.GetProject(), req.GetLicenseCode()) + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.LicenseCode{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// TestIamPermissions returns permissions that a caller has on the specified resource. Caution This resource is intended for use only by third-party partners who are creating Cloud Marketplace images. +func (c *licenseCodesRESTClient) TestIamPermissions(ctx context.Context, req *computepb.TestIamPermissionsLicenseCodeRequest, opts ...gax.CallOption) (*computepb.TestPermissionsResponse, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetTestPermissionsRequestResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/licenseCodes/%v/testIamPermissions", req.GetProject(), req.GetResource()) + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.TestPermissionsResponse{} + + return rsp, unm.Unmarshal(buf, rsp) +} diff --git a/compute/apiv1/license_codes_client_example_test.go b/compute/apiv1/license_codes_client_example_test.go new file mode 100644 index 00000000000..a0b54d391df --- /dev/null +++ b/compute/apiv1/license_codes_client_example_test.go @@ -0,0 +1,74 @@ +// 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 compute_test + +import ( + "context" + + compute "cloud.google.com/go/compute/apiv1" + computepb "google.golang.org/genproto/googleapis/cloud/compute/v1" +) + +func ExampleNewLicenseCodesRESTClient() { + ctx := context.Background() + c, err := compute.NewLicenseCodesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + // TODO: Use client. + _ = c +} + +func ExampleLicenseCodesClient_Get() { + ctx := context.Background() + c, err := compute.NewLicenseCodesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.GetLicenseCodeRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Get(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleLicenseCodesClient_TestIamPermissions() { + ctx := context.Background() + c, err := compute.NewLicenseCodesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.TestIamPermissionsLicenseCodeRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.TestIamPermissions(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} diff --git a/compute/apiv1/licenses_client.go b/compute/apiv1/licenses_client.go new file mode 100644 index 00000000000..f2f2ed9c292 --- /dev/null +++ b/compute/apiv1/licenses_client.go @@ -0,0 +1,539 @@ +// 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 compute + +import ( + "bytes" + "context" + "fmt" + "io/ioutil" + "net/http" + "net/url" + + gax "github.com/googleapis/gax-go/v2" + "google.golang.org/api/option" + "google.golang.org/api/option/internaloption" + httptransport "google.golang.org/api/transport/http" + computepb "google.golang.org/genproto/googleapis/cloud/compute/v1" + "google.golang.org/grpc" + "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/encoding/protojson" +) + +var newLicensesClientHook clientHook + +// LicensesCallOptions contains the retry settings for each method of LicensesClient. +type LicensesCallOptions struct { + Delete []gax.CallOption + Get []gax.CallOption + GetIamPolicy []gax.CallOption + Insert []gax.CallOption + List []gax.CallOption + SetIamPolicy []gax.CallOption + TestIamPermissions []gax.CallOption +} + +// internalLicensesClient is an interface that defines the methods availaible from Google Compute Engine API. +type internalLicensesClient interface { + Close() error + setGoogleClientInfo(...string) + Connection() *grpc.ClientConn + Delete(context.Context, *computepb.DeleteLicenseRequest, ...gax.CallOption) (*computepb.Operation, error) + Get(context.Context, *computepb.GetLicenseRequest, ...gax.CallOption) (*computepb.License, error) + GetIamPolicy(context.Context, *computepb.GetIamPolicyLicenseRequest, ...gax.CallOption) (*computepb.Policy, error) + Insert(context.Context, *computepb.InsertLicenseRequest, ...gax.CallOption) (*computepb.Operation, error) + List(context.Context, *computepb.ListLicensesRequest, ...gax.CallOption) (*computepb.LicensesListResponse, error) + SetIamPolicy(context.Context, *computepb.SetIamPolicyLicenseRequest, ...gax.CallOption) (*computepb.Policy, error) + TestIamPermissions(context.Context, *computepb.TestIamPermissionsLicenseRequest, ...gax.CallOption) (*computepb.TestPermissionsResponse, error) +} + +// LicensesClient is a client for interacting with Google Compute Engine API. +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +// +// The Licenses API. +type LicensesClient struct { + // The internal transport-dependent client. + internalClient internalLicensesClient + + // The call options for this service. + CallOptions *LicensesCallOptions +} + +// 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 *LicensesClient) 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 *LicensesClient) setGoogleClientInfo(keyval ...string) { + c.internalClient.setGoogleClientInfo(keyval...) +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *LicensesClient) Connection() *grpc.ClientConn { + return c.internalClient.Connection() +} + +// Delete deletes the specified license. Caution This resource is intended for use only by third-party partners who are creating Cloud Marketplace images. +func (c *LicensesClient) Delete(ctx context.Context, req *computepb.DeleteLicenseRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.Delete(ctx, req, opts...) +} + +// Get returns the specified License resource. Caution This resource is intended for use only by third-party partners who are creating Cloud Marketplace images. +func (c *LicensesClient) Get(ctx context.Context, req *computepb.GetLicenseRequest, opts ...gax.CallOption) (*computepb.License, error) { + return c.internalClient.Get(ctx, req, opts...) +} + +// GetIamPolicy gets the access control policy for a resource. May be empty if no such policy or resource exists. Caution This resource is intended for use only by third-party partners who are creating Cloud Marketplace images. +func (c *LicensesClient) GetIamPolicy(ctx context.Context, req *computepb.GetIamPolicyLicenseRequest, opts ...gax.CallOption) (*computepb.Policy, error) { + return c.internalClient.GetIamPolicy(ctx, req, opts...) +} + +// Insert create a License resource in the specified project. Caution This resource is intended for use only by third-party partners who are creating Cloud Marketplace images. +func (c *LicensesClient) Insert(ctx context.Context, req *computepb.InsertLicenseRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.Insert(ctx, req, opts...) +} + +// List retrieves the list of licenses available in the specified project. This method does not get any licenses that belong to other projects, including licenses attached to publicly-available images, like Debian 9. If you want to get a list of publicly-available licenses, use this method to make a request to the respective image project, such as debian-cloud or windows-cloud. Caution This resource is intended for use only by third-party partners who are creating Cloud Marketplace images. +func (c *LicensesClient) List(ctx context.Context, req *computepb.ListLicensesRequest, opts ...gax.CallOption) (*computepb.LicensesListResponse, error) { + return c.internalClient.List(ctx, req, opts...) +} + +// SetIamPolicy sets the access control policy on the specified resource. Replaces any existing policy. Caution This resource is intended for use only by third-party partners who are creating Cloud Marketplace images. +func (c *LicensesClient) SetIamPolicy(ctx context.Context, req *computepb.SetIamPolicyLicenseRequest, opts ...gax.CallOption) (*computepb.Policy, error) { + return c.internalClient.SetIamPolicy(ctx, req, opts...) +} + +// TestIamPermissions returns permissions that a caller has on the specified resource. Caution This resource is intended for use only by third-party partners who are creating Cloud Marketplace images. +func (c *LicensesClient) TestIamPermissions(ctx context.Context, req *computepb.TestIamPermissionsLicenseRequest, opts ...gax.CallOption) (*computepb.TestPermissionsResponse, error) { + return c.internalClient.TestIamPermissions(ctx, req, opts...) +} + +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +type licensesRESTClient struct { + // The http endpoint to connect to. + endpoint string + + // The http client. + httpClient *http.Client + + // The x-goog-* metadata to be sent with each request. + xGoogMetadata metadata.MD +} + +// NewLicensesRESTClient creates a new licenses rest client. +// +// The Licenses API. +func NewLicensesRESTClient(ctx context.Context, opts ...option.ClientOption) (*LicensesClient, error) { + clientOpts := append(defaultLicensesRESTClientOptions(), opts...) + httpClient, endpoint, err := httptransport.NewClient(ctx, clientOpts...) + if err != nil { + return nil, err + } + + c := &licensesRESTClient{ + endpoint: endpoint, + httpClient: httpClient, + } + c.setGoogleClientInfo() + + return &LicensesClient{internalClient: c, CallOptions: &LicensesCallOptions{}}, nil +} + +func defaultLicensesRESTClientOptions() []option.ClientOption { + return []option.ClientOption{ + internaloption.WithDefaultEndpoint("compute.googleapis.com"), + internaloption.WithDefaultMTLSEndpoint("compute.mtls.googleapis.com"), + internaloption.WithDefaultAudience("https://compute.googleapis.com/"), + internaloption.WithDefaultScopes(DefaultAuthScopes()...), + } +} + +// 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 *licensesRESTClient) setGoogleClientInfo(keyval ...string) { + kv := append([]string{"gl-go", versionGo()}, keyval...) + kv = append(kv, "gapic", versionClient, "gax", gax.Version, "rest", "UNKNOWN") + 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 *licensesRESTClient) Close() error { + // Replace httpClient with nil to force cleanup. + c.httpClient = nil + return nil +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *licensesRESTClient) Connection() *grpc.ClientConn { + return nil +} + +// Delete deletes the specified license. Caution This resource is intended for use only by third-party partners who are creating Cloud Marketplace images. +func (c *licensesRESTClient) Delete(ctx context.Context, req *computepb.DeleteLicenseRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/licenses/%v", req.GetProject(), req.GetLicense()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("DELETE", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Get returns the specified License resource. Caution This resource is intended for use only by third-party partners who are creating Cloud Marketplace images. +func (c *licensesRESTClient) Get(ctx context.Context, req *computepb.GetLicenseRequest, opts ...gax.CallOption) (*computepb.License, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/licenses/%v", req.GetProject(), req.GetLicense()) + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.License{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// GetIamPolicy gets the access control policy for a resource. May be empty if no such policy or resource exists. Caution This resource is intended for use only by third-party partners who are creating Cloud Marketplace images. +func (c *licensesRESTClient) GetIamPolicy(ctx context.Context, req *computepb.GetIamPolicyLicenseRequest, opts ...gax.CallOption) (*computepb.Policy, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/licenses/%v/getIamPolicy", req.GetProject(), req.GetResource()) + + params := url.Values{} + if req != nil && req.OptionsRequestedPolicyVersion != nil { + params.Add("optionsRequestedPolicyVersion", fmt.Sprintf("%v", req.GetOptionsRequestedPolicyVersion())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Policy{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Insert create a License resource in the specified project. Caution This resource is intended for use only by third-party partners who are creating Cloud Marketplace images. +func (c *licensesRESTClient) Insert(ctx context.Context, req *computepb.InsertLicenseRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetLicenseResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/licenses", req.GetProject()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// List retrieves the list of licenses available in the specified project. This method does not get any licenses that belong to other projects, including licenses attached to publicly-available images, like Debian 9. If you want to get a list of publicly-available licenses, use this method to make a request to the respective image project, such as debian-cloud or windows-cloud. Caution This resource is intended for use only by third-party partners who are creating Cloud Marketplace images. +func (c *licensesRESTClient) List(ctx context.Context, req *computepb.ListLicensesRequest, opts ...gax.CallOption) (*computepb.LicensesListResponse, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/licenses", req.GetProject()) + + params := url.Values{} + if req != nil && req.Filter != nil { + params.Add("filter", fmt.Sprintf("%v", req.GetFilter())) + } + if req != nil && req.MaxResults != nil { + params.Add("maxResults", fmt.Sprintf("%v", req.GetMaxResults())) + } + if req != nil && req.OrderBy != nil { + params.Add("orderBy", fmt.Sprintf("%v", req.GetOrderBy())) + } + if req != nil && req.PageToken != nil { + params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) + } + if req != nil && req.ReturnPartialSuccess != nil { + params.Add("returnPartialSuccess", fmt.Sprintf("%v", req.GetReturnPartialSuccess())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.LicensesListResponse{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// SetIamPolicy sets the access control policy on the specified resource. Replaces any existing policy. Caution This resource is intended for use only by third-party partners who are creating Cloud Marketplace images. +func (c *licensesRESTClient) SetIamPolicy(ctx context.Context, req *computepb.SetIamPolicyLicenseRequest, opts ...gax.CallOption) (*computepb.Policy, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetGlobalSetPolicyRequestResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/licenses/%v/setIamPolicy", req.GetProject(), req.GetResource()) + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Policy{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// TestIamPermissions returns permissions that a caller has on the specified resource. Caution This resource is intended for use only by third-party partners who are creating Cloud Marketplace images. +func (c *licensesRESTClient) TestIamPermissions(ctx context.Context, req *computepb.TestIamPermissionsLicenseRequest, opts ...gax.CallOption) (*computepb.TestPermissionsResponse, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetTestPermissionsRequestResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/licenses/%v/testIamPermissions", req.GetProject(), req.GetResource()) + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.TestPermissionsResponse{} + + return rsp, unm.Unmarshal(buf, rsp) +} diff --git a/compute/apiv1/licenses_client_example_test.go b/compute/apiv1/licenses_client_example_test.go new file mode 100644 index 00000000000..82f80b1944f --- /dev/null +++ b/compute/apiv1/licenses_client_example_test.go @@ -0,0 +1,169 @@ +// 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 compute_test + +import ( + "context" + + compute "cloud.google.com/go/compute/apiv1" + computepb "google.golang.org/genproto/googleapis/cloud/compute/v1" +) + +func ExampleNewLicensesRESTClient() { + ctx := context.Background() + c, err := compute.NewLicensesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + // TODO: Use client. + _ = c +} + +func ExampleLicensesClient_Delete() { + ctx := context.Background() + c, err := compute.NewLicensesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.DeleteLicenseRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Delete(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleLicensesClient_Get() { + ctx := context.Background() + c, err := compute.NewLicensesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.GetLicenseRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Get(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleLicensesClient_GetIamPolicy() { + ctx := context.Background() + c, err := compute.NewLicensesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.GetIamPolicyLicenseRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.GetIamPolicy(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleLicensesClient_Insert() { + ctx := context.Background() + c, err := compute.NewLicensesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.InsertLicenseRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Insert(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleLicensesClient_List() { + ctx := context.Background() + c, err := compute.NewLicensesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.ListLicensesRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.List(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleLicensesClient_SetIamPolicy() { + ctx := context.Background() + c, err := compute.NewLicensesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.SetIamPolicyLicenseRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.SetIamPolicy(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleLicensesClient_TestIamPermissions() { + ctx := context.Background() + c, err := compute.NewLicensesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.TestIamPermissionsLicenseRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.TestIamPermissions(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} diff --git a/compute/apiv1/machine_types_client.go b/compute/apiv1/machine_types_client.go new file mode 100644 index 00000000000..b888cabec5b --- /dev/null +++ b/compute/apiv1/machine_types_client.go @@ -0,0 +1,337 @@ +// 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 compute + +import ( + "bytes" + "context" + "fmt" + "io/ioutil" + "net/http" + "net/url" + + gax "github.com/googleapis/gax-go/v2" + "google.golang.org/api/option" + "google.golang.org/api/option/internaloption" + httptransport "google.golang.org/api/transport/http" + computepb "google.golang.org/genproto/googleapis/cloud/compute/v1" + "google.golang.org/grpc" + "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/encoding/protojson" +) + +var newMachineTypesClientHook clientHook + +// MachineTypesCallOptions contains the retry settings for each method of MachineTypesClient. +type MachineTypesCallOptions struct { + AggregatedList []gax.CallOption + Get []gax.CallOption + List []gax.CallOption +} + +// internalMachineTypesClient is an interface that defines the methods availaible from Google Compute Engine API. +type internalMachineTypesClient interface { + Close() error + setGoogleClientInfo(...string) + Connection() *grpc.ClientConn + AggregatedList(context.Context, *computepb.AggregatedListMachineTypesRequest, ...gax.CallOption) (*computepb.MachineTypeAggregatedList, error) + Get(context.Context, *computepb.GetMachineTypeRequest, ...gax.CallOption) (*computepb.MachineType, error) + List(context.Context, *computepb.ListMachineTypesRequest, ...gax.CallOption) (*computepb.MachineTypeList, error) +} + +// MachineTypesClient is a client for interacting with Google Compute Engine API. +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +// +// The MachineTypes API. +type MachineTypesClient struct { + // The internal transport-dependent client. + internalClient internalMachineTypesClient + + // The call options for this service. + CallOptions *MachineTypesCallOptions +} + +// 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 *MachineTypesClient) 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 *MachineTypesClient) setGoogleClientInfo(keyval ...string) { + c.internalClient.setGoogleClientInfo(keyval...) +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *MachineTypesClient) Connection() *grpc.ClientConn { + return c.internalClient.Connection() +} + +// AggregatedList retrieves an aggregated list of machine types. +func (c *MachineTypesClient) AggregatedList(ctx context.Context, req *computepb.AggregatedListMachineTypesRequest, opts ...gax.CallOption) (*computepb.MachineTypeAggregatedList, error) { + return c.internalClient.AggregatedList(ctx, req, opts...) +} + +// Get returns the specified machine type. Gets a list of available machine types by making a list() request. +func (c *MachineTypesClient) Get(ctx context.Context, req *computepb.GetMachineTypeRequest, opts ...gax.CallOption) (*computepb.MachineType, error) { + return c.internalClient.Get(ctx, req, opts...) +} + +// List retrieves a list of machine types available to the specified project. +func (c *MachineTypesClient) List(ctx context.Context, req *computepb.ListMachineTypesRequest, opts ...gax.CallOption) (*computepb.MachineTypeList, error) { + return c.internalClient.List(ctx, req, opts...) +} + +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +type machineTypesRESTClient struct { + // The http endpoint to connect to. + endpoint string + + // The http client. + httpClient *http.Client + + // The x-goog-* metadata to be sent with each request. + xGoogMetadata metadata.MD +} + +// NewMachineTypesRESTClient creates a new machine types rest client. +// +// The MachineTypes API. +func NewMachineTypesRESTClient(ctx context.Context, opts ...option.ClientOption) (*MachineTypesClient, error) { + clientOpts := append(defaultMachineTypesRESTClientOptions(), opts...) + httpClient, endpoint, err := httptransport.NewClient(ctx, clientOpts...) + if err != nil { + return nil, err + } + + c := &machineTypesRESTClient{ + endpoint: endpoint, + httpClient: httpClient, + } + c.setGoogleClientInfo() + + return &MachineTypesClient{internalClient: c, CallOptions: &MachineTypesCallOptions{}}, nil +} + +func defaultMachineTypesRESTClientOptions() []option.ClientOption { + return []option.ClientOption{ + internaloption.WithDefaultEndpoint("compute.googleapis.com"), + internaloption.WithDefaultMTLSEndpoint("compute.mtls.googleapis.com"), + internaloption.WithDefaultAudience("https://compute.googleapis.com/"), + internaloption.WithDefaultScopes(DefaultAuthScopes()...), + } +} + +// 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 *machineTypesRESTClient) setGoogleClientInfo(keyval ...string) { + kv := append([]string{"gl-go", versionGo()}, keyval...) + kv = append(kv, "gapic", versionClient, "gax", gax.Version, "rest", "UNKNOWN") + 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 *machineTypesRESTClient) Close() error { + // Replace httpClient with nil to force cleanup. + c.httpClient = nil + return nil +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *machineTypesRESTClient) Connection() *grpc.ClientConn { + return nil +} + +// AggregatedList retrieves an aggregated list of machine types. +func (c *machineTypesRESTClient) AggregatedList(ctx context.Context, req *computepb.AggregatedListMachineTypesRequest, opts ...gax.CallOption) (*computepb.MachineTypeAggregatedList, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/aggregated/machineTypes", req.GetProject()) + + params := url.Values{} + if req != nil && req.Filter != nil { + params.Add("filter", fmt.Sprintf("%v", req.GetFilter())) + } + if req != nil && req.IncludeAllScopes != nil { + params.Add("includeAllScopes", fmt.Sprintf("%v", req.GetIncludeAllScopes())) + } + if req != nil && req.MaxResults != nil { + params.Add("maxResults", fmt.Sprintf("%v", req.GetMaxResults())) + } + if req != nil && req.OrderBy != nil { + params.Add("orderBy", fmt.Sprintf("%v", req.GetOrderBy())) + } + if req != nil && req.PageToken != nil { + params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) + } + if req != nil && req.ReturnPartialSuccess != nil { + params.Add("returnPartialSuccess", fmt.Sprintf("%v", req.GetReturnPartialSuccess())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.MachineTypeAggregatedList{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Get returns the specified machine type. Gets a list of available machine types by making a list() request. +func (c *machineTypesRESTClient) Get(ctx context.Context, req *computepb.GetMachineTypeRequest, opts ...gax.CallOption) (*computepb.MachineType, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/zones/%v/machineTypes/%v", req.GetProject(), req.GetZone(), req.GetMachineType()) + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.MachineType{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// List retrieves a list of machine types available to the specified project. +func (c *machineTypesRESTClient) List(ctx context.Context, req *computepb.ListMachineTypesRequest, opts ...gax.CallOption) (*computepb.MachineTypeList, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/zones/%v/machineTypes", req.GetProject(), req.GetZone()) + + params := url.Values{} + if req != nil && req.Filter != nil { + params.Add("filter", fmt.Sprintf("%v", req.GetFilter())) + } + if req != nil && req.MaxResults != nil { + params.Add("maxResults", fmt.Sprintf("%v", req.GetMaxResults())) + } + if req != nil && req.OrderBy != nil { + params.Add("orderBy", fmt.Sprintf("%v", req.GetOrderBy())) + } + if req != nil && req.PageToken != nil { + params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) + } + if req != nil && req.ReturnPartialSuccess != nil { + params.Add("returnPartialSuccess", fmt.Sprintf("%v", req.GetReturnPartialSuccess())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.MachineTypeList{} + + return rsp, unm.Unmarshal(buf, rsp) +} diff --git a/compute/apiv1/machine_types_client_example_test.go b/compute/apiv1/machine_types_client_example_test.go new file mode 100644 index 00000000000..858b4032b5c --- /dev/null +++ b/compute/apiv1/machine_types_client_example_test.go @@ -0,0 +1,93 @@ +// 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 compute_test + +import ( + "context" + + compute "cloud.google.com/go/compute/apiv1" + computepb "google.golang.org/genproto/googleapis/cloud/compute/v1" +) + +func ExampleNewMachineTypesRESTClient() { + ctx := context.Background() + c, err := compute.NewMachineTypesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + // TODO: Use client. + _ = c +} + +func ExampleMachineTypesClient_AggregatedList() { + ctx := context.Background() + c, err := compute.NewMachineTypesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.AggregatedListMachineTypesRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.AggregatedList(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleMachineTypesClient_Get() { + ctx := context.Background() + c, err := compute.NewMachineTypesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.GetMachineTypeRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Get(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleMachineTypesClient_List() { + ctx := context.Background() + c, err := compute.NewMachineTypesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.ListMachineTypesRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.List(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} diff --git a/compute/apiv1/network_endpoint_groups_client.go b/compute/apiv1/network_endpoint_groups_client.go new file mode 100644 index 00000000000..f9da210d93a --- /dev/null +++ b/compute/apiv1/network_endpoint_groups_client.go @@ -0,0 +1,689 @@ +// 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 compute + +import ( + "bytes" + "context" + "fmt" + "io/ioutil" + "net/http" + "net/url" + + gax "github.com/googleapis/gax-go/v2" + "google.golang.org/api/option" + "google.golang.org/api/option/internaloption" + httptransport "google.golang.org/api/transport/http" + computepb "google.golang.org/genproto/googleapis/cloud/compute/v1" + "google.golang.org/grpc" + "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/encoding/protojson" +) + +var newNetworkEndpointGroupsClientHook clientHook + +// NetworkEndpointGroupsCallOptions contains the retry settings for each method of NetworkEndpointGroupsClient. +type NetworkEndpointGroupsCallOptions struct { + AggregatedList []gax.CallOption + AttachNetworkEndpoints []gax.CallOption + Delete []gax.CallOption + DetachNetworkEndpoints []gax.CallOption + Get []gax.CallOption + Insert []gax.CallOption + List []gax.CallOption + ListNetworkEndpoints []gax.CallOption + TestIamPermissions []gax.CallOption +} + +// internalNetworkEndpointGroupsClient is an interface that defines the methods availaible from Google Compute Engine API. +type internalNetworkEndpointGroupsClient interface { + Close() error + setGoogleClientInfo(...string) + Connection() *grpc.ClientConn + AggregatedList(context.Context, *computepb.AggregatedListNetworkEndpointGroupsRequest, ...gax.CallOption) (*computepb.NetworkEndpointGroupAggregatedList, error) + AttachNetworkEndpoints(context.Context, *computepb.AttachNetworkEndpointsNetworkEndpointGroupRequest, ...gax.CallOption) (*computepb.Operation, error) + Delete(context.Context, *computepb.DeleteNetworkEndpointGroupRequest, ...gax.CallOption) (*computepb.Operation, error) + DetachNetworkEndpoints(context.Context, *computepb.DetachNetworkEndpointsNetworkEndpointGroupRequest, ...gax.CallOption) (*computepb.Operation, error) + Get(context.Context, *computepb.GetNetworkEndpointGroupRequest, ...gax.CallOption) (*computepb.NetworkEndpointGroup, error) + Insert(context.Context, *computepb.InsertNetworkEndpointGroupRequest, ...gax.CallOption) (*computepb.Operation, error) + List(context.Context, *computepb.ListNetworkEndpointGroupsRequest, ...gax.CallOption) (*computepb.NetworkEndpointGroupList, error) + ListNetworkEndpoints(context.Context, *computepb.ListNetworkEndpointsNetworkEndpointGroupsRequest, ...gax.CallOption) (*computepb.NetworkEndpointGroupsListNetworkEndpoints, error) + TestIamPermissions(context.Context, *computepb.TestIamPermissionsNetworkEndpointGroupRequest, ...gax.CallOption) (*computepb.TestPermissionsResponse, error) +} + +// NetworkEndpointGroupsClient is a client for interacting with Google Compute Engine API. +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +// +// The NetworkEndpointGroups API. +type NetworkEndpointGroupsClient struct { + // The internal transport-dependent client. + internalClient internalNetworkEndpointGroupsClient + + // The call options for this service. + CallOptions *NetworkEndpointGroupsCallOptions +} + +// 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 *NetworkEndpointGroupsClient) 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 *NetworkEndpointGroupsClient) setGoogleClientInfo(keyval ...string) { + c.internalClient.setGoogleClientInfo(keyval...) +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *NetworkEndpointGroupsClient) Connection() *grpc.ClientConn { + return c.internalClient.Connection() +} + +// AggregatedList retrieves the list of network endpoint groups and sorts them by zone. +func (c *NetworkEndpointGroupsClient) AggregatedList(ctx context.Context, req *computepb.AggregatedListNetworkEndpointGroupsRequest, opts ...gax.CallOption) (*computepb.NetworkEndpointGroupAggregatedList, error) { + return c.internalClient.AggregatedList(ctx, req, opts...) +} + +// AttachNetworkEndpoints attach a list of network endpoints to the specified network endpoint group. +func (c *NetworkEndpointGroupsClient) AttachNetworkEndpoints(ctx context.Context, req *computepb.AttachNetworkEndpointsNetworkEndpointGroupRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.AttachNetworkEndpoints(ctx, req, opts...) +} + +// Delete deletes the specified network endpoint group. The network endpoints in the NEG and the VM instances they belong to are not terminated when the NEG is deleted. Note that the NEG cannot be deleted if there are backend services referencing it. +func (c *NetworkEndpointGroupsClient) Delete(ctx context.Context, req *computepb.DeleteNetworkEndpointGroupRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.Delete(ctx, req, opts...) +} + +// DetachNetworkEndpoints detach a list of network endpoints from the specified network endpoint group. +func (c *NetworkEndpointGroupsClient) DetachNetworkEndpoints(ctx context.Context, req *computepb.DetachNetworkEndpointsNetworkEndpointGroupRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.DetachNetworkEndpoints(ctx, req, opts...) +} + +// Get returns the specified network endpoint group. Gets a list of available network endpoint groups by making a list() request. +func (c *NetworkEndpointGroupsClient) Get(ctx context.Context, req *computepb.GetNetworkEndpointGroupRequest, opts ...gax.CallOption) (*computepb.NetworkEndpointGroup, error) { + return c.internalClient.Get(ctx, req, opts...) +} + +// Insert creates a network endpoint group in the specified project using the parameters that are included in the request. +func (c *NetworkEndpointGroupsClient) Insert(ctx context.Context, req *computepb.InsertNetworkEndpointGroupRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.Insert(ctx, req, opts...) +} + +// List retrieves the list of network endpoint groups that are located in the specified project and zone. +func (c *NetworkEndpointGroupsClient) List(ctx context.Context, req *computepb.ListNetworkEndpointGroupsRequest, opts ...gax.CallOption) (*computepb.NetworkEndpointGroupList, error) { + return c.internalClient.List(ctx, req, opts...) +} + +// ListNetworkEndpoints lists the network endpoints in the specified network endpoint group. +func (c *NetworkEndpointGroupsClient) ListNetworkEndpoints(ctx context.Context, req *computepb.ListNetworkEndpointsNetworkEndpointGroupsRequest, opts ...gax.CallOption) (*computepb.NetworkEndpointGroupsListNetworkEndpoints, error) { + return c.internalClient.ListNetworkEndpoints(ctx, req, opts...) +} + +// TestIamPermissions returns permissions that a caller has on the specified resource. +func (c *NetworkEndpointGroupsClient) TestIamPermissions(ctx context.Context, req *computepb.TestIamPermissionsNetworkEndpointGroupRequest, opts ...gax.CallOption) (*computepb.TestPermissionsResponse, error) { + return c.internalClient.TestIamPermissions(ctx, req, opts...) +} + +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +type networkEndpointGroupsRESTClient struct { + // The http endpoint to connect to. + endpoint string + + // The http client. + httpClient *http.Client + + // The x-goog-* metadata to be sent with each request. + xGoogMetadata metadata.MD +} + +// NewNetworkEndpointGroupsRESTClient creates a new network endpoint groups rest client. +// +// The NetworkEndpointGroups API. +func NewNetworkEndpointGroupsRESTClient(ctx context.Context, opts ...option.ClientOption) (*NetworkEndpointGroupsClient, error) { + clientOpts := append(defaultNetworkEndpointGroupsRESTClientOptions(), opts...) + httpClient, endpoint, err := httptransport.NewClient(ctx, clientOpts...) + if err != nil { + return nil, err + } + + c := &networkEndpointGroupsRESTClient{ + endpoint: endpoint, + httpClient: httpClient, + } + c.setGoogleClientInfo() + + return &NetworkEndpointGroupsClient{internalClient: c, CallOptions: &NetworkEndpointGroupsCallOptions{}}, nil +} + +func defaultNetworkEndpointGroupsRESTClientOptions() []option.ClientOption { + return []option.ClientOption{ + internaloption.WithDefaultEndpoint("compute.googleapis.com"), + internaloption.WithDefaultMTLSEndpoint("compute.mtls.googleapis.com"), + internaloption.WithDefaultAudience("https://compute.googleapis.com/"), + internaloption.WithDefaultScopes(DefaultAuthScopes()...), + } +} + +// 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 *networkEndpointGroupsRESTClient) setGoogleClientInfo(keyval ...string) { + kv := append([]string{"gl-go", versionGo()}, keyval...) + kv = append(kv, "gapic", versionClient, "gax", gax.Version, "rest", "UNKNOWN") + 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 *networkEndpointGroupsRESTClient) Close() error { + // Replace httpClient with nil to force cleanup. + c.httpClient = nil + return nil +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *networkEndpointGroupsRESTClient) Connection() *grpc.ClientConn { + return nil +} + +// AggregatedList retrieves the list of network endpoint groups and sorts them by zone. +func (c *networkEndpointGroupsRESTClient) AggregatedList(ctx context.Context, req *computepb.AggregatedListNetworkEndpointGroupsRequest, opts ...gax.CallOption) (*computepb.NetworkEndpointGroupAggregatedList, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/aggregated/networkEndpointGroups", req.GetProject()) + + params := url.Values{} + if req != nil && req.Filter != nil { + params.Add("filter", fmt.Sprintf("%v", req.GetFilter())) + } + if req != nil && req.IncludeAllScopes != nil { + params.Add("includeAllScopes", fmt.Sprintf("%v", req.GetIncludeAllScopes())) + } + if req != nil && req.MaxResults != nil { + params.Add("maxResults", fmt.Sprintf("%v", req.GetMaxResults())) + } + if req != nil && req.OrderBy != nil { + params.Add("orderBy", fmt.Sprintf("%v", req.GetOrderBy())) + } + if req != nil && req.PageToken != nil { + params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) + } + if req != nil && req.ReturnPartialSuccess != nil { + params.Add("returnPartialSuccess", fmt.Sprintf("%v", req.GetReturnPartialSuccess())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.NetworkEndpointGroupAggregatedList{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// AttachNetworkEndpoints attach a list of network endpoints to the specified network endpoint group. +func (c *networkEndpointGroupsRESTClient) AttachNetworkEndpoints(ctx context.Context, req *computepb.AttachNetworkEndpointsNetworkEndpointGroupRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetNetworkEndpointGroupsAttachEndpointsRequestResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/zones/%v/networkEndpointGroups/%v/attachNetworkEndpoints", req.GetProject(), req.GetZone(), req.GetNetworkEndpointGroup()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Delete deletes the specified network endpoint group. The network endpoints in the NEG and the VM instances they belong to are not terminated when the NEG is deleted. Note that the NEG cannot be deleted if there are backend services referencing it. +func (c *networkEndpointGroupsRESTClient) Delete(ctx context.Context, req *computepb.DeleteNetworkEndpointGroupRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/zones/%v/networkEndpointGroups/%v", req.GetProject(), req.GetZone(), req.GetNetworkEndpointGroup()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("DELETE", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// DetachNetworkEndpoints detach a list of network endpoints from the specified network endpoint group. +func (c *networkEndpointGroupsRESTClient) DetachNetworkEndpoints(ctx context.Context, req *computepb.DetachNetworkEndpointsNetworkEndpointGroupRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetNetworkEndpointGroupsDetachEndpointsRequestResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/zones/%v/networkEndpointGroups/%v/detachNetworkEndpoints", req.GetProject(), req.GetZone(), req.GetNetworkEndpointGroup()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Get returns the specified network endpoint group. Gets a list of available network endpoint groups by making a list() request. +func (c *networkEndpointGroupsRESTClient) Get(ctx context.Context, req *computepb.GetNetworkEndpointGroupRequest, opts ...gax.CallOption) (*computepb.NetworkEndpointGroup, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/zones/%v/networkEndpointGroups/%v", req.GetProject(), req.GetZone(), req.GetNetworkEndpointGroup()) + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.NetworkEndpointGroup{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Insert creates a network endpoint group in the specified project using the parameters that are included in the request. +func (c *networkEndpointGroupsRESTClient) Insert(ctx context.Context, req *computepb.InsertNetworkEndpointGroupRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetNetworkEndpointGroupResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/zones/%v/networkEndpointGroups", req.GetProject(), req.GetZone()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// List retrieves the list of network endpoint groups that are located in the specified project and zone. +func (c *networkEndpointGroupsRESTClient) List(ctx context.Context, req *computepb.ListNetworkEndpointGroupsRequest, opts ...gax.CallOption) (*computepb.NetworkEndpointGroupList, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/zones/%v/networkEndpointGroups", req.GetProject(), req.GetZone()) + + params := url.Values{} + if req != nil && req.Filter != nil { + params.Add("filter", fmt.Sprintf("%v", req.GetFilter())) + } + if req != nil && req.MaxResults != nil { + params.Add("maxResults", fmt.Sprintf("%v", req.GetMaxResults())) + } + if req != nil && req.OrderBy != nil { + params.Add("orderBy", fmt.Sprintf("%v", req.GetOrderBy())) + } + if req != nil && req.PageToken != nil { + params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) + } + if req != nil && req.ReturnPartialSuccess != nil { + params.Add("returnPartialSuccess", fmt.Sprintf("%v", req.GetReturnPartialSuccess())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.NetworkEndpointGroupList{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// ListNetworkEndpoints lists the network endpoints in the specified network endpoint group. +func (c *networkEndpointGroupsRESTClient) ListNetworkEndpoints(ctx context.Context, req *computepb.ListNetworkEndpointsNetworkEndpointGroupsRequest, opts ...gax.CallOption) (*computepb.NetworkEndpointGroupsListNetworkEndpoints, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetNetworkEndpointGroupsListEndpointsRequestResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/zones/%v/networkEndpointGroups/%v/listNetworkEndpoints", req.GetProject(), req.GetZone(), req.GetNetworkEndpointGroup()) + + params := url.Values{} + if req != nil && req.Filter != nil { + params.Add("filter", fmt.Sprintf("%v", req.GetFilter())) + } + if req != nil && req.MaxResults != nil { + params.Add("maxResults", fmt.Sprintf("%v", req.GetMaxResults())) + } + if req != nil && req.OrderBy != nil { + params.Add("orderBy", fmt.Sprintf("%v", req.GetOrderBy())) + } + if req != nil && req.PageToken != nil { + params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) + } + if req != nil && req.ReturnPartialSuccess != nil { + params.Add("returnPartialSuccess", fmt.Sprintf("%v", req.GetReturnPartialSuccess())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.NetworkEndpointGroupsListNetworkEndpoints{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// TestIamPermissions returns permissions that a caller has on the specified resource. +func (c *networkEndpointGroupsRESTClient) TestIamPermissions(ctx context.Context, req *computepb.TestIamPermissionsNetworkEndpointGroupRequest, opts ...gax.CallOption) (*computepb.TestPermissionsResponse, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetTestPermissionsRequestResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/zones/%v/networkEndpointGroups/%v/testIamPermissions", req.GetProject(), req.GetZone(), req.GetResource()) + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.TestPermissionsResponse{} + + return rsp, unm.Unmarshal(buf, rsp) +} diff --git a/compute/apiv1/network_endpoint_groups_client_example_test.go b/compute/apiv1/network_endpoint_groups_client_example_test.go new file mode 100644 index 00000000000..5c370298c7a --- /dev/null +++ b/compute/apiv1/network_endpoint_groups_client_example_test.go @@ -0,0 +1,207 @@ +// 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 compute_test + +import ( + "context" + + compute "cloud.google.com/go/compute/apiv1" + computepb "google.golang.org/genproto/googleapis/cloud/compute/v1" +) + +func ExampleNewNetworkEndpointGroupsRESTClient() { + ctx := context.Background() + c, err := compute.NewNetworkEndpointGroupsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + // TODO: Use client. + _ = c +} + +func ExampleNetworkEndpointGroupsClient_AggregatedList() { + ctx := context.Background() + c, err := compute.NewNetworkEndpointGroupsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.AggregatedListNetworkEndpointGroupsRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.AggregatedList(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleNetworkEndpointGroupsClient_AttachNetworkEndpoints() { + ctx := context.Background() + c, err := compute.NewNetworkEndpointGroupsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.AttachNetworkEndpointsNetworkEndpointGroupRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.AttachNetworkEndpoints(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleNetworkEndpointGroupsClient_Delete() { + ctx := context.Background() + c, err := compute.NewNetworkEndpointGroupsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.DeleteNetworkEndpointGroupRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Delete(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleNetworkEndpointGroupsClient_DetachNetworkEndpoints() { + ctx := context.Background() + c, err := compute.NewNetworkEndpointGroupsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.DetachNetworkEndpointsNetworkEndpointGroupRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.DetachNetworkEndpoints(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleNetworkEndpointGroupsClient_Get() { + ctx := context.Background() + c, err := compute.NewNetworkEndpointGroupsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.GetNetworkEndpointGroupRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Get(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleNetworkEndpointGroupsClient_Insert() { + ctx := context.Background() + c, err := compute.NewNetworkEndpointGroupsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.InsertNetworkEndpointGroupRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Insert(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleNetworkEndpointGroupsClient_List() { + ctx := context.Background() + c, err := compute.NewNetworkEndpointGroupsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.ListNetworkEndpointGroupsRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.List(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleNetworkEndpointGroupsClient_ListNetworkEndpoints() { + ctx := context.Background() + c, err := compute.NewNetworkEndpointGroupsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.ListNetworkEndpointsNetworkEndpointGroupsRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.ListNetworkEndpoints(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleNetworkEndpointGroupsClient_TestIamPermissions() { + ctx := context.Background() + c, err := compute.NewNetworkEndpointGroupsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.TestIamPermissionsNetworkEndpointGroupRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.TestIamPermissions(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} diff --git a/compute/apiv1/networks_client.go b/compute/apiv1/networks_client.go new file mode 100644 index 00000000000..432e0e8047f --- /dev/null +++ b/compute/apiv1/networks_client.go @@ -0,0 +1,797 @@ +// 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 compute + +import ( + "bytes" + "context" + "fmt" + "io/ioutil" + "net/http" + "net/url" + + gax "github.com/googleapis/gax-go/v2" + "google.golang.org/api/option" + "google.golang.org/api/option/internaloption" + httptransport "google.golang.org/api/transport/http" + computepb "google.golang.org/genproto/googleapis/cloud/compute/v1" + "google.golang.org/grpc" + "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/encoding/protojson" +) + +var newNetworksClientHook clientHook + +// NetworksCallOptions contains the retry settings for each method of NetworksClient. +type NetworksCallOptions struct { + AddPeering []gax.CallOption + Delete []gax.CallOption + Get []gax.CallOption + GetEffectiveFirewalls []gax.CallOption + Insert []gax.CallOption + List []gax.CallOption + ListPeeringRoutes []gax.CallOption + Patch []gax.CallOption + RemovePeering []gax.CallOption + SwitchToCustomMode []gax.CallOption + UpdatePeering []gax.CallOption +} + +// internalNetworksClient is an interface that defines the methods availaible from Google Compute Engine API. +type internalNetworksClient interface { + Close() error + setGoogleClientInfo(...string) + Connection() *grpc.ClientConn + AddPeering(context.Context, *computepb.AddPeeringNetworkRequest, ...gax.CallOption) (*computepb.Operation, error) + Delete(context.Context, *computepb.DeleteNetworkRequest, ...gax.CallOption) (*computepb.Operation, error) + Get(context.Context, *computepb.GetNetworkRequest, ...gax.CallOption) (*computepb.Network, error) + GetEffectiveFirewalls(context.Context, *computepb.GetEffectiveFirewallsNetworkRequest, ...gax.CallOption) (*computepb.NetworksGetEffectiveFirewallsResponse, error) + Insert(context.Context, *computepb.InsertNetworkRequest, ...gax.CallOption) (*computepb.Operation, error) + List(context.Context, *computepb.ListNetworksRequest, ...gax.CallOption) (*computepb.NetworkList, error) + ListPeeringRoutes(context.Context, *computepb.ListPeeringRoutesNetworksRequest, ...gax.CallOption) (*computepb.ExchangedPeeringRoutesList, error) + Patch(context.Context, *computepb.PatchNetworkRequest, ...gax.CallOption) (*computepb.Operation, error) + RemovePeering(context.Context, *computepb.RemovePeeringNetworkRequest, ...gax.CallOption) (*computepb.Operation, error) + SwitchToCustomMode(context.Context, *computepb.SwitchToCustomModeNetworkRequest, ...gax.CallOption) (*computepb.Operation, error) + UpdatePeering(context.Context, *computepb.UpdatePeeringNetworkRequest, ...gax.CallOption) (*computepb.Operation, error) +} + +// NetworksClient is a client for interacting with Google Compute Engine API. +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +// +// The Networks API. +type NetworksClient struct { + // The internal transport-dependent client. + internalClient internalNetworksClient + + // The call options for this service. + CallOptions *NetworksCallOptions +} + +// 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 *NetworksClient) 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 *NetworksClient) setGoogleClientInfo(keyval ...string) { + c.internalClient.setGoogleClientInfo(keyval...) +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *NetworksClient) Connection() *grpc.ClientConn { + return c.internalClient.Connection() +} + +// AddPeering adds a peering to the specified network. +func (c *NetworksClient) AddPeering(ctx context.Context, req *computepb.AddPeeringNetworkRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.AddPeering(ctx, req, opts...) +} + +// Delete deletes the specified network. +func (c *NetworksClient) Delete(ctx context.Context, req *computepb.DeleteNetworkRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.Delete(ctx, req, opts...) +} + +// Get returns the specified network. Gets a list of available networks by making a list() request. +func (c *NetworksClient) Get(ctx context.Context, req *computepb.GetNetworkRequest, opts ...gax.CallOption) (*computepb.Network, error) { + return c.internalClient.Get(ctx, req, opts...) +} + +// GetEffectiveFirewalls returns the effective firewalls on a given network. +func (c *NetworksClient) GetEffectiveFirewalls(ctx context.Context, req *computepb.GetEffectiveFirewallsNetworkRequest, opts ...gax.CallOption) (*computepb.NetworksGetEffectiveFirewallsResponse, error) { + return c.internalClient.GetEffectiveFirewalls(ctx, req, opts...) +} + +// Insert creates a network in the specified project using the data included in the request. +func (c *NetworksClient) Insert(ctx context.Context, req *computepb.InsertNetworkRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.Insert(ctx, req, opts...) +} + +// List retrieves the list of networks available to the specified project. +func (c *NetworksClient) List(ctx context.Context, req *computepb.ListNetworksRequest, opts ...gax.CallOption) (*computepb.NetworkList, error) { + return c.internalClient.List(ctx, req, opts...) +} + +// ListPeeringRoutes lists the peering routes exchanged over peering connection. +func (c *NetworksClient) ListPeeringRoutes(ctx context.Context, req *computepb.ListPeeringRoutesNetworksRequest, opts ...gax.CallOption) (*computepb.ExchangedPeeringRoutesList, error) { + return c.internalClient.ListPeeringRoutes(ctx, req, opts...) +} + +// Patch patches the specified network with the data included in the request. Only the following fields can be modified: routingConfig.routingMode. +func (c *NetworksClient) Patch(ctx context.Context, req *computepb.PatchNetworkRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.Patch(ctx, req, opts...) +} + +// RemovePeering removes a peering from the specified network. +func (c *NetworksClient) RemovePeering(ctx context.Context, req *computepb.RemovePeeringNetworkRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.RemovePeering(ctx, req, opts...) +} + +// SwitchToCustomMode switches the network mode from auto subnet mode to custom subnet mode. +func (c *NetworksClient) SwitchToCustomMode(ctx context.Context, req *computepb.SwitchToCustomModeNetworkRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.SwitchToCustomMode(ctx, req, opts...) +} + +// UpdatePeering updates the specified network peering with the data included in the request Only the following fields can be modified: NetworkPeering.export_custom_routes, and NetworkPeering.import_custom_routes +func (c *NetworksClient) UpdatePeering(ctx context.Context, req *computepb.UpdatePeeringNetworkRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.UpdatePeering(ctx, req, opts...) +} + +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +type networksRESTClient struct { + // The http endpoint to connect to. + endpoint string + + // The http client. + httpClient *http.Client + + // The x-goog-* metadata to be sent with each request. + xGoogMetadata metadata.MD +} + +// NewNetworksRESTClient creates a new networks rest client. +// +// The Networks API. +func NewNetworksRESTClient(ctx context.Context, opts ...option.ClientOption) (*NetworksClient, error) { + clientOpts := append(defaultNetworksRESTClientOptions(), opts...) + httpClient, endpoint, err := httptransport.NewClient(ctx, clientOpts...) + if err != nil { + return nil, err + } + + c := &networksRESTClient{ + endpoint: endpoint, + httpClient: httpClient, + } + c.setGoogleClientInfo() + + return &NetworksClient{internalClient: c, CallOptions: &NetworksCallOptions{}}, nil +} + +func defaultNetworksRESTClientOptions() []option.ClientOption { + return []option.ClientOption{ + internaloption.WithDefaultEndpoint("compute.googleapis.com"), + internaloption.WithDefaultMTLSEndpoint("compute.mtls.googleapis.com"), + internaloption.WithDefaultAudience("https://compute.googleapis.com/"), + internaloption.WithDefaultScopes(DefaultAuthScopes()...), + } +} + +// 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 *networksRESTClient) setGoogleClientInfo(keyval ...string) { + kv := append([]string{"gl-go", versionGo()}, keyval...) + kv = append(kv, "gapic", versionClient, "gax", gax.Version, "rest", "UNKNOWN") + 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 *networksRESTClient) Close() error { + // Replace httpClient with nil to force cleanup. + c.httpClient = nil + return nil +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *networksRESTClient) Connection() *grpc.ClientConn { + return nil +} + +// AddPeering adds a peering to the specified network. +func (c *networksRESTClient) AddPeering(ctx context.Context, req *computepb.AddPeeringNetworkRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetNetworksAddPeeringRequestResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/networks/%v/addPeering", req.GetProject(), req.GetNetwork()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Delete deletes the specified network. +func (c *networksRESTClient) Delete(ctx context.Context, req *computepb.DeleteNetworkRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/networks/%v", req.GetProject(), req.GetNetwork()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("DELETE", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Get returns the specified network. Gets a list of available networks by making a list() request. +func (c *networksRESTClient) Get(ctx context.Context, req *computepb.GetNetworkRequest, opts ...gax.CallOption) (*computepb.Network, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/networks/%v", req.GetProject(), req.GetNetwork()) + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Network{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// GetEffectiveFirewalls returns the effective firewalls on a given network. +func (c *networksRESTClient) GetEffectiveFirewalls(ctx context.Context, req *computepb.GetEffectiveFirewallsNetworkRequest, opts ...gax.CallOption) (*computepb.NetworksGetEffectiveFirewallsResponse, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/networks/%v/getEffectiveFirewalls", req.GetProject(), req.GetNetwork()) + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.NetworksGetEffectiveFirewallsResponse{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Insert creates a network in the specified project using the data included in the request. +func (c *networksRESTClient) Insert(ctx context.Context, req *computepb.InsertNetworkRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetNetworkResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/networks", req.GetProject()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// List retrieves the list of networks available to the specified project. +func (c *networksRESTClient) List(ctx context.Context, req *computepb.ListNetworksRequest, opts ...gax.CallOption) (*computepb.NetworkList, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/networks", req.GetProject()) + + params := url.Values{} + if req != nil && req.Filter != nil { + params.Add("filter", fmt.Sprintf("%v", req.GetFilter())) + } + if req != nil && req.MaxResults != nil { + params.Add("maxResults", fmt.Sprintf("%v", req.GetMaxResults())) + } + if req != nil && req.OrderBy != nil { + params.Add("orderBy", fmt.Sprintf("%v", req.GetOrderBy())) + } + if req != nil && req.PageToken != nil { + params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) + } + if req != nil && req.ReturnPartialSuccess != nil { + params.Add("returnPartialSuccess", fmt.Sprintf("%v", req.GetReturnPartialSuccess())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.NetworkList{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// ListPeeringRoutes lists the peering routes exchanged over peering connection. +func (c *networksRESTClient) ListPeeringRoutes(ctx context.Context, req *computepb.ListPeeringRoutesNetworksRequest, opts ...gax.CallOption) (*computepb.ExchangedPeeringRoutesList, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/networks/%v/listPeeringRoutes", req.GetProject(), req.GetNetwork()) + + params := url.Values{} + if req != nil && req.Direction != nil { + params.Add("direction", fmt.Sprintf("%v", req.GetDirection())) + } + if req != nil && req.Filter != nil { + params.Add("filter", fmt.Sprintf("%v", req.GetFilter())) + } + if req != nil && req.MaxResults != nil { + params.Add("maxResults", fmt.Sprintf("%v", req.GetMaxResults())) + } + if req != nil && req.OrderBy != nil { + params.Add("orderBy", fmt.Sprintf("%v", req.GetOrderBy())) + } + if req != nil && req.PageToken != nil { + params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) + } + if req != nil && req.PeeringName != nil { + params.Add("peeringName", fmt.Sprintf("%v", req.GetPeeringName())) + } + if req != nil && req.Region != nil { + params.Add("region", fmt.Sprintf("%v", req.GetRegion())) + } + if req != nil && req.ReturnPartialSuccess != nil { + params.Add("returnPartialSuccess", fmt.Sprintf("%v", req.GetReturnPartialSuccess())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.ExchangedPeeringRoutesList{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Patch patches the specified network with the data included in the request. Only the following fields can be modified: routingConfig.routingMode. +func (c *networksRESTClient) Patch(ctx context.Context, req *computepb.PatchNetworkRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetNetworkResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/networks/%v", req.GetProject(), req.GetNetwork()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("PATCH", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// RemovePeering removes a peering from the specified network. +func (c *networksRESTClient) RemovePeering(ctx context.Context, req *computepb.RemovePeeringNetworkRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetNetworksRemovePeeringRequestResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/networks/%v/removePeering", req.GetProject(), req.GetNetwork()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// SwitchToCustomMode switches the network mode from auto subnet mode to custom subnet mode. +func (c *networksRESTClient) SwitchToCustomMode(ctx context.Context, req *computepb.SwitchToCustomModeNetworkRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/networks/%v/switchToCustomMode", req.GetProject(), req.GetNetwork()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// UpdatePeering updates the specified network peering with the data included in the request Only the following fields can be modified: NetworkPeering.export_custom_routes, and NetworkPeering.import_custom_routes +func (c *networksRESTClient) UpdatePeering(ctx context.Context, req *computepb.UpdatePeeringNetworkRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetNetworksUpdatePeeringRequestResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/networks/%v/updatePeering", req.GetProject(), req.GetNetwork()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("PATCH", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} diff --git a/compute/apiv1/networks_client_example_test.go b/compute/apiv1/networks_client_example_test.go new file mode 100644 index 00000000000..74578fdc389 --- /dev/null +++ b/compute/apiv1/networks_client_example_test.go @@ -0,0 +1,245 @@ +// 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 compute_test + +import ( + "context" + + compute "cloud.google.com/go/compute/apiv1" + computepb "google.golang.org/genproto/googleapis/cloud/compute/v1" +) + +func ExampleNewNetworksRESTClient() { + ctx := context.Background() + c, err := compute.NewNetworksRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + // TODO: Use client. + _ = c +} + +func ExampleNetworksClient_AddPeering() { + ctx := context.Background() + c, err := compute.NewNetworksRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.AddPeeringNetworkRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.AddPeering(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleNetworksClient_Delete() { + ctx := context.Background() + c, err := compute.NewNetworksRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.DeleteNetworkRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Delete(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleNetworksClient_Get() { + ctx := context.Background() + c, err := compute.NewNetworksRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.GetNetworkRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Get(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleNetworksClient_GetEffectiveFirewalls() { + ctx := context.Background() + c, err := compute.NewNetworksRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.GetEffectiveFirewallsNetworkRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.GetEffectiveFirewalls(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleNetworksClient_Insert() { + ctx := context.Background() + c, err := compute.NewNetworksRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.InsertNetworkRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Insert(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleNetworksClient_List() { + ctx := context.Background() + c, err := compute.NewNetworksRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.ListNetworksRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.List(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleNetworksClient_ListPeeringRoutes() { + ctx := context.Background() + c, err := compute.NewNetworksRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.ListPeeringRoutesNetworksRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.ListPeeringRoutes(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleNetworksClient_Patch() { + ctx := context.Background() + c, err := compute.NewNetworksRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.PatchNetworkRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Patch(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleNetworksClient_RemovePeering() { + ctx := context.Background() + c, err := compute.NewNetworksRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.RemovePeeringNetworkRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.RemovePeering(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleNetworksClient_SwitchToCustomMode() { + ctx := context.Background() + c, err := compute.NewNetworksRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.SwitchToCustomModeNetworkRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.SwitchToCustomMode(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleNetworksClient_UpdatePeering() { + ctx := context.Background() + c, err := compute.NewNetworksRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.UpdatePeeringNetworkRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.UpdatePeering(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} diff --git a/compute/apiv1/node_groups_client.go b/compute/apiv1/node_groups_client.go new file mode 100644 index 00000000000..64563885daa --- /dev/null +++ b/compute/apiv1/node_groups_client.go @@ -0,0 +1,915 @@ +// 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 compute + +import ( + "bytes" + "context" + "fmt" + "io/ioutil" + "net/http" + "net/url" + + gax "github.com/googleapis/gax-go/v2" + "google.golang.org/api/option" + "google.golang.org/api/option/internaloption" + httptransport "google.golang.org/api/transport/http" + computepb "google.golang.org/genproto/googleapis/cloud/compute/v1" + "google.golang.org/grpc" + "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/encoding/protojson" +) + +var newNodeGroupsClientHook clientHook + +// NodeGroupsCallOptions contains the retry settings for each method of NodeGroupsClient. +type NodeGroupsCallOptions struct { + AddNodes []gax.CallOption + AggregatedList []gax.CallOption + Delete []gax.CallOption + DeleteNodes []gax.CallOption + Get []gax.CallOption + GetIamPolicy []gax.CallOption + Insert []gax.CallOption + List []gax.CallOption + ListNodes []gax.CallOption + Patch []gax.CallOption + SetIamPolicy []gax.CallOption + SetNodeTemplate []gax.CallOption + TestIamPermissions []gax.CallOption +} + +// internalNodeGroupsClient is an interface that defines the methods availaible from Google Compute Engine API. +type internalNodeGroupsClient interface { + Close() error + setGoogleClientInfo(...string) + Connection() *grpc.ClientConn + AddNodes(context.Context, *computepb.AddNodesNodeGroupRequest, ...gax.CallOption) (*computepb.Operation, error) + AggregatedList(context.Context, *computepb.AggregatedListNodeGroupsRequest, ...gax.CallOption) (*computepb.NodeGroupAggregatedList, error) + Delete(context.Context, *computepb.DeleteNodeGroupRequest, ...gax.CallOption) (*computepb.Operation, error) + DeleteNodes(context.Context, *computepb.DeleteNodesNodeGroupRequest, ...gax.CallOption) (*computepb.Operation, error) + Get(context.Context, *computepb.GetNodeGroupRequest, ...gax.CallOption) (*computepb.NodeGroup, error) + GetIamPolicy(context.Context, *computepb.GetIamPolicyNodeGroupRequest, ...gax.CallOption) (*computepb.Policy, error) + Insert(context.Context, *computepb.InsertNodeGroupRequest, ...gax.CallOption) (*computepb.Operation, error) + List(context.Context, *computepb.ListNodeGroupsRequest, ...gax.CallOption) (*computepb.NodeGroupList, error) + ListNodes(context.Context, *computepb.ListNodesNodeGroupsRequest, ...gax.CallOption) (*computepb.NodeGroupsListNodes, error) + Patch(context.Context, *computepb.PatchNodeGroupRequest, ...gax.CallOption) (*computepb.Operation, error) + SetIamPolicy(context.Context, *computepb.SetIamPolicyNodeGroupRequest, ...gax.CallOption) (*computepb.Policy, error) + SetNodeTemplate(context.Context, *computepb.SetNodeTemplateNodeGroupRequest, ...gax.CallOption) (*computepb.Operation, error) + TestIamPermissions(context.Context, *computepb.TestIamPermissionsNodeGroupRequest, ...gax.CallOption) (*computepb.TestPermissionsResponse, error) +} + +// NodeGroupsClient is a client for interacting with Google Compute Engine API. +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +// +// The NodeGroups API. +type NodeGroupsClient struct { + // The internal transport-dependent client. + internalClient internalNodeGroupsClient + + // The call options for this service. + CallOptions *NodeGroupsCallOptions +} + +// 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 *NodeGroupsClient) 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 *NodeGroupsClient) setGoogleClientInfo(keyval ...string) { + c.internalClient.setGoogleClientInfo(keyval...) +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *NodeGroupsClient) Connection() *grpc.ClientConn { + return c.internalClient.Connection() +} + +// AddNodes adds specified number of nodes to the node group. +func (c *NodeGroupsClient) AddNodes(ctx context.Context, req *computepb.AddNodesNodeGroupRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.AddNodes(ctx, req, opts...) +} + +// AggregatedList retrieves an aggregated list of node groups. Note: use nodeGroups.listNodes for more details about each group. +func (c *NodeGroupsClient) AggregatedList(ctx context.Context, req *computepb.AggregatedListNodeGroupsRequest, opts ...gax.CallOption) (*computepb.NodeGroupAggregatedList, error) { + return c.internalClient.AggregatedList(ctx, req, opts...) +} + +// Delete deletes the specified NodeGroup resource. +func (c *NodeGroupsClient) Delete(ctx context.Context, req *computepb.DeleteNodeGroupRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.Delete(ctx, req, opts...) +} + +// DeleteNodes deletes specified nodes from the node group. +func (c *NodeGroupsClient) DeleteNodes(ctx context.Context, req *computepb.DeleteNodesNodeGroupRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.DeleteNodes(ctx, req, opts...) +} + +// Get returns the specified NodeGroup. Get a list of available NodeGroups by making a list() request. Note: the “nodes” field should not be used. Use nodeGroups.listNodes instead. +func (c *NodeGroupsClient) Get(ctx context.Context, req *computepb.GetNodeGroupRequest, opts ...gax.CallOption) (*computepb.NodeGroup, error) { + return c.internalClient.Get(ctx, req, opts...) +} + +// GetIamPolicy gets the access control policy for a resource. May be empty if no such policy or resource exists. +func (c *NodeGroupsClient) GetIamPolicy(ctx context.Context, req *computepb.GetIamPolicyNodeGroupRequest, opts ...gax.CallOption) (*computepb.Policy, error) { + return c.internalClient.GetIamPolicy(ctx, req, opts...) +} + +// Insert creates a NodeGroup resource in the specified project using the data included in the request. +func (c *NodeGroupsClient) Insert(ctx context.Context, req *computepb.InsertNodeGroupRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.Insert(ctx, req, opts...) +} + +// List retrieves a list of node groups available to the specified project. Note: use nodeGroups.listNodes for more details about each group. +func (c *NodeGroupsClient) List(ctx context.Context, req *computepb.ListNodeGroupsRequest, opts ...gax.CallOption) (*computepb.NodeGroupList, error) { + return c.internalClient.List(ctx, req, opts...) +} + +// ListNodes lists nodes in the node group. +func (c *NodeGroupsClient) ListNodes(ctx context.Context, req *computepb.ListNodesNodeGroupsRequest, opts ...gax.CallOption) (*computepb.NodeGroupsListNodes, error) { + return c.internalClient.ListNodes(ctx, req, opts...) +} + +// Patch updates the specified node group. +func (c *NodeGroupsClient) Patch(ctx context.Context, req *computepb.PatchNodeGroupRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.Patch(ctx, req, opts...) +} + +// SetIamPolicy sets the access control policy on the specified resource. Replaces any existing policy. +func (c *NodeGroupsClient) SetIamPolicy(ctx context.Context, req *computepb.SetIamPolicyNodeGroupRequest, opts ...gax.CallOption) (*computepb.Policy, error) { + return c.internalClient.SetIamPolicy(ctx, req, opts...) +} + +// SetNodeTemplate updates the node template of the node group. +func (c *NodeGroupsClient) SetNodeTemplate(ctx context.Context, req *computepb.SetNodeTemplateNodeGroupRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.SetNodeTemplate(ctx, req, opts...) +} + +// TestIamPermissions returns permissions that a caller has on the specified resource. +func (c *NodeGroupsClient) TestIamPermissions(ctx context.Context, req *computepb.TestIamPermissionsNodeGroupRequest, opts ...gax.CallOption) (*computepb.TestPermissionsResponse, error) { + return c.internalClient.TestIamPermissions(ctx, req, opts...) +} + +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +type nodeGroupsRESTClient struct { + // The http endpoint to connect to. + endpoint string + + // The http client. + httpClient *http.Client + + // The x-goog-* metadata to be sent with each request. + xGoogMetadata metadata.MD +} + +// NewNodeGroupsRESTClient creates a new node groups rest client. +// +// The NodeGroups API. +func NewNodeGroupsRESTClient(ctx context.Context, opts ...option.ClientOption) (*NodeGroupsClient, error) { + clientOpts := append(defaultNodeGroupsRESTClientOptions(), opts...) + httpClient, endpoint, err := httptransport.NewClient(ctx, clientOpts...) + if err != nil { + return nil, err + } + + c := &nodeGroupsRESTClient{ + endpoint: endpoint, + httpClient: httpClient, + } + c.setGoogleClientInfo() + + return &NodeGroupsClient{internalClient: c, CallOptions: &NodeGroupsCallOptions{}}, nil +} + +func defaultNodeGroupsRESTClientOptions() []option.ClientOption { + return []option.ClientOption{ + internaloption.WithDefaultEndpoint("compute.googleapis.com"), + internaloption.WithDefaultMTLSEndpoint("compute.mtls.googleapis.com"), + internaloption.WithDefaultAudience("https://compute.googleapis.com/"), + internaloption.WithDefaultScopes(DefaultAuthScopes()...), + } +} + +// 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 *nodeGroupsRESTClient) setGoogleClientInfo(keyval ...string) { + kv := append([]string{"gl-go", versionGo()}, keyval...) + kv = append(kv, "gapic", versionClient, "gax", gax.Version, "rest", "UNKNOWN") + 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 *nodeGroupsRESTClient) Close() error { + // Replace httpClient with nil to force cleanup. + c.httpClient = nil + return nil +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *nodeGroupsRESTClient) Connection() *grpc.ClientConn { + return nil +} + +// AddNodes adds specified number of nodes to the node group. +func (c *nodeGroupsRESTClient) AddNodes(ctx context.Context, req *computepb.AddNodesNodeGroupRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetNodeGroupsAddNodesRequestResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/zones/%v/nodeGroups/%v/addNodes", req.GetProject(), req.GetZone(), req.GetNodeGroup()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// AggregatedList retrieves an aggregated list of node groups. Note: use nodeGroups.listNodes for more details about each group. +func (c *nodeGroupsRESTClient) AggregatedList(ctx context.Context, req *computepb.AggregatedListNodeGroupsRequest, opts ...gax.CallOption) (*computepb.NodeGroupAggregatedList, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/aggregated/nodeGroups", req.GetProject()) + + params := url.Values{} + if req != nil && req.Filter != nil { + params.Add("filter", fmt.Sprintf("%v", req.GetFilter())) + } + if req != nil && req.IncludeAllScopes != nil { + params.Add("includeAllScopes", fmt.Sprintf("%v", req.GetIncludeAllScopes())) + } + if req != nil && req.MaxResults != nil { + params.Add("maxResults", fmt.Sprintf("%v", req.GetMaxResults())) + } + if req != nil && req.OrderBy != nil { + params.Add("orderBy", fmt.Sprintf("%v", req.GetOrderBy())) + } + if req != nil && req.PageToken != nil { + params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) + } + if req != nil && req.ReturnPartialSuccess != nil { + params.Add("returnPartialSuccess", fmt.Sprintf("%v", req.GetReturnPartialSuccess())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.NodeGroupAggregatedList{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Delete deletes the specified NodeGroup resource. +func (c *nodeGroupsRESTClient) Delete(ctx context.Context, req *computepb.DeleteNodeGroupRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/zones/%v/nodeGroups/%v", req.GetProject(), req.GetZone(), req.GetNodeGroup()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("DELETE", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// DeleteNodes deletes specified nodes from the node group. +func (c *nodeGroupsRESTClient) DeleteNodes(ctx context.Context, req *computepb.DeleteNodesNodeGroupRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetNodeGroupsDeleteNodesRequestResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/zones/%v/nodeGroups/%v/deleteNodes", req.GetProject(), req.GetZone(), req.GetNodeGroup()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Get returns the specified NodeGroup. Get a list of available NodeGroups by making a list() request. Note: the “nodes” field should not be used. Use nodeGroups.listNodes instead. +func (c *nodeGroupsRESTClient) Get(ctx context.Context, req *computepb.GetNodeGroupRequest, opts ...gax.CallOption) (*computepb.NodeGroup, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/zones/%v/nodeGroups/%v", req.GetProject(), req.GetZone(), req.GetNodeGroup()) + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.NodeGroup{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// GetIamPolicy gets the access control policy for a resource. May be empty if no such policy or resource exists. +func (c *nodeGroupsRESTClient) GetIamPolicy(ctx context.Context, req *computepb.GetIamPolicyNodeGroupRequest, opts ...gax.CallOption) (*computepb.Policy, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/zones/%v/nodeGroups/%v/getIamPolicy", req.GetProject(), req.GetZone(), req.GetResource()) + + params := url.Values{} + if req != nil && req.OptionsRequestedPolicyVersion != nil { + params.Add("optionsRequestedPolicyVersion", fmt.Sprintf("%v", req.GetOptionsRequestedPolicyVersion())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Policy{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Insert creates a NodeGroup resource in the specified project using the data included in the request. +func (c *nodeGroupsRESTClient) Insert(ctx context.Context, req *computepb.InsertNodeGroupRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetNodeGroupResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/zones/%v/nodeGroups", req.GetProject(), req.GetZone()) + + params := url.Values{} + if req.GetInitialNodeCount() != 0 { + params.Add("initialNodeCount", fmt.Sprintf("%v", req.GetInitialNodeCount())) + } + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// List retrieves a list of node groups available to the specified project. Note: use nodeGroups.listNodes for more details about each group. +func (c *nodeGroupsRESTClient) List(ctx context.Context, req *computepb.ListNodeGroupsRequest, opts ...gax.CallOption) (*computepb.NodeGroupList, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/zones/%v/nodeGroups", req.GetProject(), req.GetZone()) + + params := url.Values{} + if req != nil && req.Filter != nil { + params.Add("filter", fmt.Sprintf("%v", req.GetFilter())) + } + if req != nil && req.MaxResults != nil { + params.Add("maxResults", fmt.Sprintf("%v", req.GetMaxResults())) + } + if req != nil && req.OrderBy != nil { + params.Add("orderBy", fmt.Sprintf("%v", req.GetOrderBy())) + } + if req != nil && req.PageToken != nil { + params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) + } + if req != nil && req.ReturnPartialSuccess != nil { + params.Add("returnPartialSuccess", fmt.Sprintf("%v", req.GetReturnPartialSuccess())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.NodeGroupList{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// ListNodes lists nodes in the node group. +func (c *nodeGroupsRESTClient) ListNodes(ctx context.Context, req *computepb.ListNodesNodeGroupsRequest, opts ...gax.CallOption) (*computepb.NodeGroupsListNodes, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/zones/%v/nodeGroups/%v/listNodes", req.GetProject(), req.GetZone(), req.GetNodeGroup()) + + params := url.Values{} + if req != nil && req.Filter != nil { + params.Add("filter", fmt.Sprintf("%v", req.GetFilter())) + } + if req != nil && req.MaxResults != nil { + params.Add("maxResults", fmt.Sprintf("%v", req.GetMaxResults())) + } + if req != nil && req.OrderBy != nil { + params.Add("orderBy", fmt.Sprintf("%v", req.GetOrderBy())) + } + if req != nil && req.PageToken != nil { + params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) + } + if req != nil && req.ReturnPartialSuccess != nil { + params.Add("returnPartialSuccess", fmt.Sprintf("%v", req.GetReturnPartialSuccess())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.NodeGroupsListNodes{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Patch updates the specified node group. +func (c *nodeGroupsRESTClient) Patch(ctx context.Context, req *computepb.PatchNodeGroupRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetNodeGroupResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/zones/%v/nodeGroups/%v", req.GetProject(), req.GetZone(), req.GetNodeGroup()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("PATCH", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// SetIamPolicy sets the access control policy on the specified resource. Replaces any existing policy. +func (c *nodeGroupsRESTClient) SetIamPolicy(ctx context.Context, req *computepb.SetIamPolicyNodeGroupRequest, opts ...gax.CallOption) (*computepb.Policy, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetZoneSetPolicyRequestResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/zones/%v/nodeGroups/%v/setIamPolicy", req.GetProject(), req.GetZone(), req.GetResource()) + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Policy{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// SetNodeTemplate updates the node template of the node group. +func (c *nodeGroupsRESTClient) SetNodeTemplate(ctx context.Context, req *computepb.SetNodeTemplateNodeGroupRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetNodeGroupsSetNodeTemplateRequestResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/zones/%v/nodeGroups/%v/setNodeTemplate", req.GetProject(), req.GetZone(), req.GetNodeGroup()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// TestIamPermissions returns permissions that a caller has on the specified resource. +func (c *nodeGroupsRESTClient) TestIamPermissions(ctx context.Context, req *computepb.TestIamPermissionsNodeGroupRequest, opts ...gax.CallOption) (*computepb.TestPermissionsResponse, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetTestPermissionsRequestResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/zones/%v/nodeGroups/%v/testIamPermissions", req.GetProject(), req.GetZone(), req.GetResource()) + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.TestPermissionsResponse{} + + return rsp, unm.Unmarshal(buf, rsp) +} diff --git a/compute/apiv1/node_groups_client_example_test.go b/compute/apiv1/node_groups_client_example_test.go new file mode 100644 index 00000000000..8cb69f98e69 --- /dev/null +++ b/compute/apiv1/node_groups_client_example_test.go @@ -0,0 +1,283 @@ +// 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 compute_test + +import ( + "context" + + compute "cloud.google.com/go/compute/apiv1" + computepb "google.golang.org/genproto/googleapis/cloud/compute/v1" +) + +func ExampleNewNodeGroupsRESTClient() { + ctx := context.Background() + c, err := compute.NewNodeGroupsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + // TODO: Use client. + _ = c +} + +func ExampleNodeGroupsClient_AddNodes() { + ctx := context.Background() + c, err := compute.NewNodeGroupsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.AddNodesNodeGroupRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.AddNodes(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleNodeGroupsClient_AggregatedList() { + ctx := context.Background() + c, err := compute.NewNodeGroupsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.AggregatedListNodeGroupsRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.AggregatedList(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleNodeGroupsClient_Delete() { + ctx := context.Background() + c, err := compute.NewNodeGroupsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.DeleteNodeGroupRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Delete(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleNodeGroupsClient_DeleteNodes() { + ctx := context.Background() + c, err := compute.NewNodeGroupsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.DeleteNodesNodeGroupRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.DeleteNodes(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleNodeGroupsClient_Get() { + ctx := context.Background() + c, err := compute.NewNodeGroupsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.GetNodeGroupRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Get(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleNodeGroupsClient_GetIamPolicy() { + ctx := context.Background() + c, err := compute.NewNodeGroupsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.GetIamPolicyNodeGroupRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.GetIamPolicy(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleNodeGroupsClient_Insert() { + ctx := context.Background() + c, err := compute.NewNodeGroupsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.InsertNodeGroupRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Insert(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleNodeGroupsClient_List() { + ctx := context.Background() + c, err := compute.NewNodeGroupsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.ListNodeGroupsRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.List(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleNodeGroupsClient_ListNodes() { + ctx := context.Background() + c, err := compute.NewNodeGroupsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.ListNodesNodeGroupsRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.ListNodes(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleNodeGroupsClient_Patch() { + ctx := context.Background() + c, err := compute.NewNodeGroupsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.PatchNodeGroupRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Patch(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleNodeGroupsClient_SetIamPolicy() { + ctx := context.Background() + c, err := compute.NewNodeGroupsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.SetIamPolicyNodeGroupRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.SetIamPolicy(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleNodeGroupsClient_SetNodeTemplate() { + ctx := context.Background() + c, err := compute.NewNodeGroupsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.SetNodeTemplateNodeGroupRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.SetNodeTemplate(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleNodeGroupsClient_TestIamPermissions() { + ctx := context.Background() + c, err := compute.NewNodeGroupsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.TestIamPermissionsNodeGroupRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.TestIamPermissions(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} diff --git a/compute/apiv1/node_templates_client.go b/compute/apiv1/node_templates_client.go new file mode 100644 index 00000000000..eebf6d2a0a0 --- /dev/null +++ b/compute/apiv1/node_templates_client.go @@ -0,0 +1,611 @@ +// 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 compute + +import ( + "bytes" + "context" + "fmt" + "io/ioutil" + "net/http" + "net/url" + + gax "github.com/googleapis/gax-go/v2" + "google.golang.org/api/option" + "google.golang.org/api/option/internaloption" + httptransport "google.golang.org/api/transport/http" + computepb "google.golang.org/genproto/googleapis/cloud/compute/v1" + "google.golang.org/grpc" + "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/encoding/protojson" +) + +var newNodeTemplatesClientHook clientHook + +// NodeTemplatesCallOptions contains the retry settings for each method of NodeTemplatesClient. +type NodeTemplatesCallOptions struct { + AggregatedList []gax.CallOption + Delete []gax.CallOption + Get []gax.CallOption + GetIamPolicy []gax.CallOption + Insert []gax.CallOption + List []gax.CallOption + SetIamPolicy []gax.CallOption + TestIamPermissions []gax.CallOption +} + +// internalNodeTemplatesClient is an interface that defines the methods availaible from Google Compute Engine API. +type internalNodeTemplatesClient interface { + Close() error + setGoogleClientInfo(...string) + Connection() *grpc.ClientConn + AggregatedList(context.Context, *computepb.AggregatedListNodeTemplatesRequest, ...gax.CallOption) (*computepb.NodeTemplateAggregatedList, error) + Delete(context.Context, *computepb.DeleteNodeTemplateRequest, ...gax.CallOption) (*computepb.Operation, error) + Get(context.Context, *computepb.GetNodeTemplateRequest, ...gax.CallOption) (*computepb.NodeTemplate, error) + GetIamPolicy(context.Context, *computepb.GetIamPolicyNodeTemplateRequest, ...gax.CallOption) (*computepb.Policy, error) + Insert(context.Context, *computepb.InsertNodeTemplateRequest, ...gax.CallOption) (*computepb.Operation, error) + List(context.Context, *computepb.ListNodeTemplatesRequest, ...gax.CallOption) (*computepb.NodeTemplateList, error) + SetIamPolicy(context.Context, *computepb.SetIamPolicyNodeTemplateRequest, ...gax.CallOption) (*computepb.Policy, error) + TestIamPermissions(context.Context, *computepb.TestIamPermissionsNodeTemplateRequest, ...gax.CallOption) (*computepb.TestPermissionsResponse, error) +} + +// NodeTemplatesClient is a client for interacting with Google Compute Engine API. +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +// +// The NodeTemplates API. +type NodeTemplatesClient struct { + // The internal transport-dependent client. + internalClient internalNodeTemplatesClient + + // The call options for this service. + CallOptions *NodeTemplatesCallOptions +} + +// 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 *NodeTemplatesClient) 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 *NodeTemplatesClient) setGoogleClientInfo(keyval ...string) { + c.internalClient.setGoogleClientInfo(keyval...) +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *NodeTemplatesClient) Connection() *grpc.ClientConn { + return c.internalClient.Connection() +} + +// AggregatedList retrieves an aggregated list of node templates. +func (c *NodeTemplatesClient) AggregatedList(ctx context.Context, req *computepb.AggregatedListNodeTemplatesRequest, opts ...gax.CallOption) (*computepb.NodeTemplateAggregatedList, error) { + return c.internalClient.AggregatedList(ctx, req, opts...) +} + +// Delete deletes the specified NodeTemplate resource. +func (c *NodeTemplatesClient) Delete(ctx context.Context, req *computepb.DeleteNodeTemplateRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.Delete(ctx, req, opts...) +} + +// Get returns the specified node template. Gets a list of available node templates by making a list() request. +func (c *NodeTemplatesClient) Get(ctx context.Context, req *computepb.GetNodeTemplateRequest, opts ...gax.CallOption) (*computepb.NodeTemplate, error) { + return c.internalClient.Get(ctx, req, opts...) +} + +// GetIamPolicy gets the access control policy for a resource. May be empty if no such policy or resource exists. +func (c *NodeTemplatesClient) GetIamPolicy(ctx context.Context, req *computepb.GetIamPolicyNodeTemplateRequest, opts ...gax.CallOption) (*computepb.Policy, error) { + return c.internalClient.GetIamPolicy(ctx, req, opts...) +} + +// Insert creates a NodeTemplate resource in the specified project using the data included in the request. +func (c *NodeTemplatesClient) Insert(ctx context.Context, req *computepb.InsertNodeTemplateRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.Insert(ctx, req, opts...) +} + +// List retrieves a list of node templates available to the specified project. +func (c *NodeTemplatesClient) List(ctx context.Context, req *computepb.ListNodeTemplatesRequest, opts ...gax.CallOption) (*computepb.NodeTemplateList, error) { + return c.internalClient.List(ctx, req, opts...) +} + +// SetIamPolicy sets the access control policy on the specified resource. Replaces any existing policy. +func (c *NodeTemplatesClient) SetIamPolicy(ctx context.Context, req *computepb.SetIamPolicyNodeTemplateRequest, opts ...gax.CallOption) (*computepb.Policy, error) { + return c.internalClient.SetIamPolicy(ctx, req, opts...) +} + +// TestIamPermissions returns permissions that a caller has on the specified resource. +func (c *NodeTemplatesClient) TestIamPermissions(ctx context.Context, req *computepb.TestIamPermissionsNodeTemplateRequest, opts ...gax.CallOption) (*computepb.TestPermissionsResponse, error) { + return c.internalClient.TestIamPermissions(ctx, req, opts...) +} + +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +type nodeTemplatesRESTClient struct { + // The http endpoint to connect to. + endpoint string + + // The http client. + httpClient *http.Client + + // The x-goog-* metadata to be sent with each request. + xGoogMetadata metadata.MD +} + +// NewNodeTemplatesRESTClient creates a new node templates rest client. +// +// The NodeTemplates API. +func NewNodeTemplatesRESTClient(ctx context.Context, opts ...option.ClientOption) (*NodeTemplatesClient, error) { + clientOpts := append(defaultNodeTemplatesRESTClientOptions(), opts...) + httpClient, endpoint, err := httptransport.NewClient(ctx, clientOpts...) + if err != nil { + return nil, err + } + + c := &nodeTemplatesRESTClient{ + endpoint: endpoint, + httpClient: httpClient, + } + c.setGoogleClientInfo() + + return &NodeTemplatesClient{internalClient: c, CallOptions: &NodeTemplatesCallOptions{}}, nil +} + +func defaultNodeTemplatesRESTClientOptions() []option.ClientOption { + return []option.ClientOption{ + internaloption.WithDefaultEndpoint("compute.googleapis.com"), + internaloption.WithDefaultMTLSEndpoint("compute.mtls.googleapis.com"), + internaloption.WithDefaultAudience("https://compute.googleapis.com/"), + internaloption.WithDefaultScopes(DefaultAuthScopes()...), + } +} + +// 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 *nodeTemplatesRESTClient) setGoogleClientInfo(keyval ...string) { + kv := append([]string{"gl-go", versionGo()}, keyval...) + kv = append(kv, "gapic", versionClient, "gax", gax.Version, "rest", "UNKNOWN") + 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 *nodeTemplatesRESTClient) Close() error { + // Replace httpClient with nil to force cleanup. + c.httpClient = nil + return nil +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *nodeTemplatesRESTClient) Connection() *grpc.ClientConn { + return nil +} + +// AggregatedList retrieves an aggregated list of node templates. +func (c *nodeTemplatesRESTClient) AggregatedList(ctx context.Context, req *computepb.AggregatedListNodeTemplatesRequest, opts ...gax.CallOption) (*computepb.NodeTemplateAggregatedList, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/aggregated/nodeTemplates", req.GetProject()) + + params := url.Values{} + if req != nil && req.Filter != nil { + params.Add("filter", fmt.Sprintf("%v", req.GetFilter())) + } + if req != nil && req.IncludeAllScopes != nil { + params.Add("includeAllScopes", fmt.Sprintf("%v", req.GetIncludeAllScopes())) + } + if req != nil && req.MaxResults != nil { + params.Add("maxResults", fmt.Sprintf("%v", req.GetMaxResults())) + } + if req != nil && req.OrderBy != nil { + params.Add("orderBy", fmt.Sprintf("%v", req.GetOrderBy())) + } + if req != nil && req.PageToken != nil { + params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) + } + if req != nil && req.ReturnPartialSuccess != nil { + params.Add("returnPartialSuccess", fmt.Sprintf("%v", req.GetReturnPartialSuccess())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.NodeTemplateAggregatedList{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Delete deletes the specified NodeTemplate resource. +func (c *nodeTemplatesRESTClient) Delete(ctx context.Context, req *computepb.DeleteNodeTemplateRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/regions/%v/nodeTemplates/%v", req.GetProject(), req.GetRegion(), req.GetNodeTemplate()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("DELETE", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Get returns the specified node template. Gets a list of available node templates by making a list() request. +func (c *nodeTemplatesRESTClient) Get(ctx context.Context, req *computepb.GetNodeTemplateRequest, opts ...gax.CallOption) (*computepb.NodeTemplate, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/regions/%v/nodeTemplates/%v", req.GetProject(), req.GetRegion(), req.GetNodeTemplate()) + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.NodeTemplate{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// GetIamPolicy gets the access control policy for a resource. May be empty if no such policy or resource exists. +func (c *nodeTemplatesRESTClient) GetIamPolicy(ctx context.Context, req *computepb.GetIamPolicyNodeTemplateRequest, opts ...gax.CallOption) (*computepb.Policy, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/regions/%v/nodeTemplates/%v/getIamPolicy", req.GetProject(), req.GetRegion(), req.GetResource()) + + params := url.Values{} + if req != nil && req.OptionsRequestedPolicyVersion != nil { + params.Add("optionsRequestedPolicyVersion", fmt.Sprintf("%v", req.GetOptionsRequestedPolicyVersion())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Policy{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Insert creates a NodeTemplate resource in the specified project using the data included in the request. +func (c *nodeTemplatesRESTClient) Insert(ctx context.Context, req *computepb.InsertNodeTemplateRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetNodeTemplateResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/regions/%v/nodeTemplates", req.GetProject(), req.GetRegion()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// List retrieves a list of node templates available to the specified project. +func (c *nodeTemplatesRESTClient) List(ctx context.Context, req *computepb.ListNodeTemplatesRequest, opts ...gax.CallOption) (*computepb.NodeTemplateList, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/regions/%v/nodeTemplates", req.GetProject(), req.GetRegion()) + + params := url.Values{} + if req != nil && req.Filter != nil { + params.Add("filter", fmt.Sprintf("%v", req.GetFilter())) + } + if req != nil && req.MaxResults != nil { + params.Add("maxResults", fmt.Sprintf("%v", req.GetMaxResults())) + } + if req != nil && req.OrderBy != nil { + params.Add("orderBy", fmt.Sprintf("%v", req.GetOrderBy())) + } + if req != nil && req.PageToken != nil { + params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) + } + if req != nil && req.ReturnPartialSuccess != nil { + params.Add("returnPartialSuccess", fmt.Sprintf("%v", req.GetReturnPartialSuccess())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.NodeTemplateList{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// SetIamPolicy sets the access control policy on the specified resource. Replaces any existing policy. +func (c *nodeTemplatesRESTClient) SetIamPolicy(ctx context.Context, req *computepb.SetIamPolicyNodeTemplateRequest, opts ...gax.CallOption) (*computepb.Policy, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetRegionSetPolicyRequestResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/regions/%v/nodeTemplates/%v/setIamPolicy", req.GetProject(), req.GetRegion(), req.GetResource()) + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Policy{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// TestIamPermissions returns permissions that a caller has on the specified resource. +func (c *nodeTemplatesRESTClient) TestIamPermissions(ctx context.Context, req *computepb.TestIamPermissionsNodeTemplateRequest, opts ...gax.CallOption) (*computepb.TestPermissionsResponse, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetTestPermissionsRequestResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/regions/%v/nodeTemplates/%v/testIamPermissions", req.GetProject(), req.GetRegion(), req.GetResource()) + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.TestPermissionsResponse{} + + return rsp, unm.Unmarshal(buf, rsp) +} diff --git a/compute/apiv1/node_templates_client_example_test.go b/compute/apiv1/node_templates_client_example_test.go new file mode 100644 index 00000000000..e589d2ededd --- /dev/null +++ b/compute/apiv1/node_templates_client_example_test.go @@ -0,0 +1,188 @@ +// 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 compute_test + +import ( + "context" + + compute "cloud.google.com/go/compute/apiv1" + computepb "google.golang.org/genproto/googleapis/cloud/compute/v1" +) + +func ExampleNewNodeTemplatesRESTClient() { + ctx := context.Background() + c, err := compute.NewNodeTemplatesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + // TODO: Use client. + _ = c +} + +func ExampleNodeTemplatesClient_AggregatedList() { + ctx := context.Background() + c, err := compute.NewNodeTemplatesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.AggregatedListNodeTemplatesRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.AggregatedList(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleNodeTemplatesClient_Delete() { + ctx := context.Background() + c, err := compute.NewNodeTemplatesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.DeleteNodeTemplateRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Delete(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleNodeTemplatesClient_Get() { + ctx := context.Background() + c, err := compute.NewNodeTemplatesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.GetNodeTemplateRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Get(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleNodeTemplatesClient_GetIamPolicy() { + ctx := context.Background() + c, err := compute.NewNodeTemplatesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.GetIamPolicyNodeTemplateRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.GetIamPolicy(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleNodeTemplatesClient_Insert() { + ctx := context.Background() + c, err := compute.NewNodeTemplatesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.InsertNodeTemplateRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Insert(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleNodeTemplatesClient_List() { + ctx := context.Background() + c, err := compute.NewNodeTemplatesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.ListNodeTemplatesRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.List(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleNodeTemplatesClient_SetIamPolicy() { + ctx := context.Background() + c, err := compute.NewNodeTemplatesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.SetIamPolicyNodeTemplateRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.SetIamPolicy(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleNodeTemplatesClient_TestIamPermissions() { + ctx := context.Background() + c, err := compute.NewNodeTemplatesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.TestIamPermissionsNodeTemplateRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.TestIamPermissions(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} diff --git a/compute/apiv1/node_types_client.go b/compute/apiv1/node_types_client.go new file mode 100644 index 00000000000..5c72753393b --- /dev/null +++ b/compute/apiv1/node_types_client.go @@ -0,0 +1,337 @@ +// 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 compute + +import ( + "bytes" + "context" + "fmt" + "io/ioutil" + "net/http" + "net/url" + + gax "github.com/googleapis/gax-go/v2" + "google.golang.org/api/option" + "google.golang.org/api/option/internaloption" + httptransport "google.golang.org/api/transport/http" + computepb "google.golang.org/genproto/googleapis/cloud/compute/v1" + "google.golang.org/grpc" + "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/encoding/protojson" +) + +var newNodeTypesClientHook clientHook + +// NodeTypesCallOptions contains the retry settings for each method of NodeTypesClient. +type NodeTypesCallOptions struct { + AggregatedList []gax.CallOption + Get []gax.CallOption + List []gax.CallOption +} + +// internalNodeTypesClient is an interface that defines the methods availaible from Google Compute Engine API. +type internalNodeTypesClient interface { + Close() error + setGoogleClientInfo(...string) + Connection() *grpc.ClientConn + AggregatedList(context.Context, *computepb.AggregatedListNodeTypesRequest, ...gax.CallOption) (*computepb.NodeTypeAggregatedList, error) + Get(context.Context, *computepb.GetNodeTypeRequest, ...gax.CallOption) (*computepb.NodeType, error) + List(context.Context, *computepb.ListNodeTypesRequest, ...gax.CallOption) (*computepb.NodeTypeList, error) +} + +// NodeTypesClient is a client for interacting with Google Compute Engine API. +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +// +// The NodeTypes API. +type NodeTypesClient struct { + // The internal transport-dependent client. + internalClient internalNodeTypesClient + + // The call options for this service. + CallOptions *NodeTypesCallOptions +} + +// 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 *NodeTypesClient) 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 *NodeTypesClient) setGoogleClientInfo(keyval ...string) { + c.internalClient.setGoogleClientInfo(keyval...) +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *NodeTypesClient) Connection() *grpc.ClientConn { + return c.internalClient.Connection() +} + +// AggregatedList retrieves an aggregated list of node types. +func (c *NodeTypesClient) AggregatedList(ctx context.Context, req *computepb.AggregatedListNodeTypesRequest, opts ...gax.CallOption) (*computepb.NodeTypeAggregatedList, error) { + return c.internalClient.AggregatedList(ctx, req, opts...) +} + +// Get returns the specified node type. Gets a list of available node types by making a list() request. +func (c *NodeTypesClient) Get(ctx context.Context, req *computepb.GetNodeTypeRequest, opts ...gax.CallOption) (*computepb.NodeType, error) { + return c.internalClient.Get(ctx, req, opts...) +} + +// List retrieves a list of node types available to the specified project. +func (c *NodeTypesClient) List(ctx context.Context, req *computepb.ListNodeTypesRequest, opts ...gax.CallOption) (*computepb.NodeTypeList, error) { + return c.internalClient.List(ctx, req, opts...) +} + +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +type nodeTypesRESTClient struct { + // The http endpoint to connect to. + endpoint string + + // The http client. + httpClient *http.Client + + // The x-goog-* metadata to be sent with each request. + xGoogMetadata metadata.MD +} + +// NewNodeTypesRESTClient creates a new node types rest client. +// +// The NodeTypes API. +func NewNodeTypesRESTClient(ctx context.Context, opts ...option.ClientOption) (*NodeTypesClient, error) { + clientOpts := append(defaultNodeTypesRESTClientOptions(), opts...) + httpClient, endpoint, err := httptransport.NewClient(ctx, clientOpts...) + if err != nil { + return nil, err + } + + c := &nodeTypesRESTClient{ + endpoint: endpoint, + httpClient: httpClient, + } + c.setGoogleClientInfo() + + return &NodeTypesClient{internalClient: c, CallOptions: &NodeTypesCallOptions{}}, nil +} + +func defaultNodeTypesRESTClientOptions() []option.ClientOption { + return []option.ClientOption{ + internaloption.WithDefaultEndpoint("compute.googleapis.com"), + internaloption.WithDefaultMTLSEndpoint("compute.mtls.googleapis.com"), + internaloption.WithDefaultAudience("https://compute.googleapis.com/"), + internaloption.WithDefaultScopes(DefaultAuthScopes()...), + } +} + +// 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 *nodeTypesRESTClient) setGoogleClientInfo(keyval ...string) { + kv := append([]string{"gl-go", versionGo()}, keyval...) + kv = append(kv, "gapic", versionClient, "gax", gax.Version, "rest", "UNKNOWN") + 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 *nodeTypesRESTClient) Close() error { + // Replace httpClient with nil to force cleanup. + c.httpClient = nil + return nil +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *nodeTypesRESTClient) Connection() *grpc.ClientConn { + return nil +} + +// AggregatedList retrieves an aggregated list of node types. +func (c *nodeTypesRESTClient) AggregatedList(ctx context.Context, req *computepb.AggregatedListNodeTypesRequest, opts ...gax.CallOption) (*computepb.NodeTypeAggregatedList, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/aggregated/nodeTypes", req.GetProject()) + + params := url.Values{} + if req != nil && req.Filter != nil { + params.Add("filter", fmt.Sprintf("%v", req.GetFilter())) + } + if req != nil && req.IncludeAllScopes != nil { + params.Add("includeAllScopes", fmt.Sprintf("%v", req.GetIncludeAllScopes())) + } + if req != nil && req.MaxResults != nil { + params.Add("maxResults", fmt.Sprintf("%v", req.GetMaxResults())) + } + if req != nil && req.OrderBy != nil { + params.Add("orderBy", fmt.Sprintf("%v", req.GetOrderBy())) + } + if req != nil && req.PageToken != nil { + params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) + } + if req != nil && req.ReturnPartialSuccess != nil { + params.Add("returnPartialSuccess", fmt.Sprintf("%v", req.GetReturnPartialSuccess())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.NodeTypeAggregatedList{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Get returns the specified node type. Gets a list of available node types by making a list() request. +func (c *nodeTypesRESTClient) Get(ctx context.Context, req *computepb.GetNodeTypeRequest, opts ...gax.CallOption) (*computepb.NodeType, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/zones/%v/nodeTypes/%v", req.GetProject(), req.GetZone(), req.GetNodeType()) + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.NodeType{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// List retrieves a list of node types available to the specified project. +func (c *nodeTypesRESTClient) List(ctx context.Context, req *computepb.ListNodeTypesRequest, opts ...gax.CallOption) (*computepb.NodeTypeList, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/zones/%v/nodeTypes", req.GetProject(), req.GetZone()) + + params := url.Values{} + if req != nil && req.Filter != nil { + params.Add("filter", fmt.Sprintf("%v", req.GetFilter())) + } + if req != nil && req.MaxResults != nil { + params.Add("maxResults", fmt.Sprintf("%v", req.GetMaxResults())) + } + if req != nil && req.OrderBy != nil { + params.Add("orderBy", fmt.Sprintf("%v", req.GetOrderBy())) + } + if req != nil && req.PageToken != nil { + params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) + } + if req != nil && req.ReturnPartialSuccess != nil { + params.Add("returnPartialSuccess", fmt.Sprintf("%v", req.GetReturnPartialSuccess())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.NodeTypeList{} + + return rsp, unm.Unmarshal(buf, rsp) +} diff --git a/compute/apiv1/node_types_client_example_test.go b/compute/apiv1/node_types_client_example_test.go new file mode 100644 index 00000000000..9f184468eac --- /dev/null +++ b/compute/apiv1/node_types_client_example_test.go @@ -0,0 +1,93 @@ +// 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 compute_test + +import ( + "context" + + compute "cloud.google.com/go/compute/apiv1" + computepb "google.golang.org/genproto/googleapis/cloud/compute/v1" +) + +func ExampleNewNodeTypesRESTClient() { + ctx := context.Background() + c, err := compute.NewNodeTypesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + // TODO: Use client. + _ = c +} + +func ExampleNodeTypesClient_AggregatedList() { + ctx := context.Background() + c, err := compute.NewNodeTypesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.AggregatedListNodeTypesRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.AggregatedList(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleNodeTypesClient_Get() { + ctx := context.Background() + c, err := compute.NewNodeTypesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.GetNodeTypeRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Get(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleNodeTypesClient_List() { + ctx := context.Background() + c, err := compute.NewNodeTypesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.ListNodeTypesRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.List(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} diff --git a/compute/apiv1/packet_mirrorings_client.go b/compute/apiv1/packet_mirrorings_client.go new file mode 100644 index 00000000000..2ddda96fccb --- /dev/null +++ b/compute/apiv1/packet_mirrorings_client.go @@ -0,0 +1,561 @@ +// 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 compute + +import ( + "bytes" + "context" + "fmt" + "io/ioutil" + "net/http" + "net/url" + + gax "github.com/googleapis/gax-go/v2" + "google.golang.org/api/option" + "google.golang.org/api/option/internaloption" + httptransport "google.golang.org/api/transport/http" + computepb "google.golang.org/genproto/googleapis/cloud/compute/v1" + "google.golang.org/grpc" + "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/encoding/protojson" +) + +var newPacketMirroringsClientHook clientHook + +// PacketMirroringsCallOptions contains the retry settings for each method of PacketMirroringsClient. +type PacketMirroringsCallOptions struct { + AggregatedList []gax.CallOption + Delete []gax.CallOption + Get []gax.CallOption + Insert []gax.CallOption + List []gax.CallOption + Patch []gax.CallOption + TestIamPermissions []gax.CallOption +} + +// internalPacketMirroringsClient is an interface that defines the methods availaible from Google Compute Engine API. +type internalPacketMirroringsClient interface { + Close() error + setGoogleClientInfo(...string) + Connection() *grpc.ClientConn + AggregatedList(context.Context, *computepb.AggregatedListPacketMirroringsRequest, ...gax.CallOption) (*computepb.PacketMirroringAggregatedList, error) + Delete(context.Context, *computepb.DeletePacketMirroringRequest, ...gax.CallOption) (*computepb.Operation, error) + Get(context.Context, *computepb.GetPacketMirroringRequest, ...gax.CallOption) (*computepb.PacketMirroring, error) + Insert(context.Context, *computepb.InsertPacketMirroringRequest, ...gax.CallOption) (*computepb.Operation, error) + List(context.Context, *computepb.ListPacketMirroringsRequest, ...gax.CallOption) (*computepb.PacketMirroringList, error) + Patch(context.Context, *computepb.PatchPacketMirroringRequest, ...gax.CallOption) (*computepb.Operation, error) + TestIamPermissions(context.Context, *computepb.TestIamPermissionsPacketMirroringRequest, ...gax.CallOption) (*computepb.TestPermissionsResponse, error) +} + +// PacketMirroringsClient is a client for interacting with Google Compute Engine API. +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +// +// The PacketMirrorings API. +type PacketMirroringsClient struct { + // The internal transport-dependent client. + internalClient internalPacketMirroringsClient + + // The call options for this service. + CallOptions *PacketMirroringsCallOptions +} + +// 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 *PacketMirroringsClient) 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 *PacketMirroringsClient) setGoogleClientInfo(keyval ...string) { + c.internalClient.setGoogleClientInfo(keyval...) +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *PacketMirroringsClient) Connection() *grpc.ClientConn { + return c.internalClient.Connection() +} + +// AggregatedList retrieves an aggregated list of packetMirrorings. +func (c *PacketMirroringsClient) AggregatedList(ctx context.Context, req *computepb.AggregatedListPacketMirroringsRequest, opts ...gax.CallOption) (*computepb.PacketMirroringAggregatedList, error) { + return c.internalClient.AggregatedList(ctx, req, opts...) +} + +// Delete deletes the specified PacketMirroring resource. +func (c *PacketMirroringsClient) Delete(ctx context.Context, req *computepb.DeletePacketMirroringRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.Delete(ctx, req, opts...) +} + +// Get returns the specified PacketMirroring resource. +func (c *PacketMirroringsClient) Get(ctx context.Context, req *computepb.GetPacketMirroringRequest, opts ...gax.CallOption) (*computepb.PacketMirroring, error) { + return c.internalClient.Get(ctx, req, opts...) +} + +// Insert creates a PacketMirroring resource in the specified project and region using the data included in the request. +func (c *PacketMirroringsClient) Insert(ctx context.Context, req *computepb.InsertPacketMirroringRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.Insert(ctx, req, opts...) +} + +// List retrieves a list of PacketMirroring resources available to the specified project and region. +func (c *PacketMirroringsClient) List(ctx context.Context, req *computepb.ListPacketMirroringsRequest, opts ...gax.CallOption) (*computepb.PacketMirroringList, error) { + return c.internalClient.List(ctx, req, opts...) +} + +// Patch patches the specified PacketMirroring resource with the data included in the request. This method supports PATCH semantics and uses JSON merge patch format and processing rules. +func (c *PacketMirroringsClient) Patch(ctx context.Context, req *computepb.PatchPacketMirroringRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.Patch(ctx, req, opts...) +} + +// TestIamPermissions returns permissions that a caller has on the specified resource. +func (c *PacketMirroringsClient) TestIamPermissions(ctx context.Context, req *computepb.TestIamPermissionsPacketMirroringRequest, opts ...gax.CallOption) (*computepb.TestPermissionsResponse, error) { + return c.internalClient.TestIamPermissions(ctx, req, opts...) +} + +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +type packetMirroringsRESTClient struct { + // The http endpoint to connect to. + endpoint string + + // The http client. + httpClient *http.Client + + // The x-goog-* metadata to be sent with each request. + xGoogMetadata metadata.MD +} + +// NewPacketMirroringsRESTClient creates a new packet mirrorings rest client. +// +// The PacketMirrorings API. +func NewPacketMirroringsRESTClient(ctx context.Context, opts ...option.ClientOption) (*PacketMirroringsClient, error) { + clientOpts := append(defaultPacketMirroringsRESTClientOptions(), opts...) + httpClient, endpoint, err := httptransport.NewClient(ctx, clientOpts...) + if err != nil { + return nil, err + } + + c := &packetMirroringsRESTClient{ + endpoint: endpoint, + httpClient: httpClient, + } + c.setGoogleClientInfo() + + return &PacketMirroringsClient{internalClient: c, CallOptions: &PacketMirroringsCallOptions{}}, nil +} + +func defaultPacketMirroringsRESTClientOptions() []option.ClientOption { + return []option.ClientOption{ + internaloption.WithDefaultEndpoint("compute.googleapis.com"), + internaloption.WithDefaultMTLSEndpoint("compute.mtls.googleapis.com"), + internaloption.WithDefaultAudience("https://compute.googleapis.com/"), + internaloption.WithDefaultScopes(DefaultAuthScopes()...), + } +} + +// 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 *packetMirroringsRESTClient) setGoogleClientInfo(keyval ...string) { + kv := append([]string{"gl-go", versionGo()}, keyval...) + kv = append(kv, "gapic", versionClient, "gax", gax.Version, "rest", "UNKNOWN") + 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 *packetMirroringsRESTClient) Close() error { + // Replace httpClient with nil to force cleanup. + c.httpClient = nil + return nil +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *packetMirroringsRESTClient) Connection() *grpc.ClientConn { + return nil +} + +// AggregatedList retrieves an aggregated list of packetMirrorings. +func (c *packetMirroringsRESTClient) AggregatedList(ctx context.Context, req *computepb.AggregatedListPacketMirroringsRequest, opts ...gax.CallOption) (*computepb.PacketMirroringAggregatedList, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/aggregated/packetMirrorings", req.GetProject()) + + params := url.Values{} + if req != nil && req.Filter != nil { + params.Add("filter", fmt.Sprintf("%v", req.GetFilter())) + } + if req != nil && req.IncludeAllScopes != nil { + params.Add("includeAllScopes", fmt.Sprintf("%v", req.GetIncludeAllScopes())) + } + if req != nil && req.MaxResults != nil { + params.Add("maxResults", fmt.Sprintf("%v", req.GetMaxResults())) + } + if req != nil && req.OrderBy != nil { + params.Add("orderBy", fmt.Sprintf("%v", req.GetOrderBy())) + } + if req != nil && req.PageToken != nil { + params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) + } + if req != nil && req.ReturnPartialSuccess != nil { + params.Add("returnPartialSuccess", fmt.Sprintf("%v", req.GetReturnPartialSuccess())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.PacketMirroringAggregatedList{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Delete deletes the specified PacketMirroring resource. +func (c *packetMirroringsRESTClient) Delete(ctx context.Context, req *computepb.DeletePacketMirroringRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/regions/%v/packetMirrorings/%v", req.GetProject(), req.GetRegion(), req.GetPacketMirroring()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("DELETE", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Get returns the specified PacketMirroring resource. +func (c *packetMirroringsRESTClient) Get(ctx context.Context, req *computepb.GetPacketMirroringRequest, opts ...gax.CallOption) (*computepb.PacketMirroring, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/regions/%v/packetMirrorings/%v", req.GetProject(), req.GetRegion(), req.GetPacketMirroring()) + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.PacketMirroring{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Insert creates a PacketMirroring resource in the specified project and region using the data included in the request. +func (c *packetMirroringsRESTClient) Insert(ctx context.Context, req *computepb.InsertPacketMirroringRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetPacketMirroringResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/regions/%v/packetMirrorings", req.GetProject(), req.GetRegion()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// List retrieves a list of PacketMirroring resources available to the specified project and region. +func (c *packetMirroringsRESTClient) List(ctx context.Context, req *computepb.ListPacketMirroringsRequest, opts ...gax.CallOption) (*computepb.PacketMirroringList, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/regions/%v/packetMirrorings", req.GetProject(), req.GetRegion()) + + params := url.Values{} + if req != nil && req.Filter != nil { + params.Add("filter", fmt.Sprintf("%v", req.GetFilter())) + } + if req != nil && req.MaxResults != nil { + params.Add("maxResults", fmt.Sprintf("%v", req.GetMaxResults())) + } + if req != nil && req.OrderBy != nil { + params.Add("orderBy", fmt.Sprintf("%v", req.GetOrderBy())) + } + if req != nil && req.PageToken != nil { + params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) + } + if req != nil && req.ReturnPartialSuccess != nil { + params.Add("returnPartialSuccess", fmt.Sprintf("%v", req.GetReturnPartialSuccess())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.PacketMirroringList{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Patch patches the specified PacketMirroring resource with the data included in the request. This method supports PATCH semantics and uses JSON merge patch format and processing rules. +func (c *packetMirroringsRESTClient) Patch(ctx context.Context, req *computepb.PatchPacketMirroringRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetPacketMirroringResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/regions/%v/packetMirrorings/%v", req.GetProject(), req.GetRegion(), req.GetPacketMirroring()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("PATCH", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// TestIamPermissions returns permissions that a caller has on the specified resource. +func (c *packetMirroringsRESTClient) TestIamPermissions(ctx context.Context, req *computepb.TestIamPermissionsPacketMirroringRequest, opts ...gax.CallOption) (*computepb.TestPermissionsResponse, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetTestPermissionsRequestResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/regions/%v/packetMirrorings/%v/testIamPermissions", req.GetProject(), req.GetRegion(), req.GetResource()) + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.TestPermissionsResponse{} + + return rsp, unm.Unmarshal(buf, rsp) +} diff --git a/compute/apiv1/packet_mirrorings_client_example_test.go b/compute/apiv1/packet_mirrorings_client_example_test.go new file mode 100644 index 00000000000..6ce5c37025e --- /dev/null +++ b/compute/apiv1/packet_mirrorings_client_example_test.go @@ -0,0 +1,169 @@ +// 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 compute_test + +import ( + "context" + + compute "cloud.google.com/go/compute/apiv1" + computepb "google.golang.org/genproto/googleapis/cloud/compute/v1" +) + +func ExampleNewPacketMirroringsRESTClient() { + ctx := context.Background() + c, err := compute.NewPacketMirroringsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + // TODO: Use client. + _ = c +} + +func ExamplePacketMirroringsClient_AggregatedList() { + ctx := context.Background() + c, err := compute.NewPacketMirroringsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.AggregatedListPacketMirroringsRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.AggregatedList(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExamplePacketMirroringsClient_Delete() { + ctx := context.Background() + c, err := compute.NewPacketMirroringsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.DeletePacketMirroringRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Delete(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExamplePacketMirroringsClient_Get() { + ctx := context.Background() + c, err := compute.NewPacketMirroringsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.GetPacketMirroringRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Get(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExamplePacketMirroringsClient_Insert() { + ctx := context.Background() + c, err := compute.NewPacketMirroringsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.InsertPacketMirroringRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Insert(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExamplePacketMirroringsClient_List() { + ctx := context.Background() + c, err := compute.NewPacketMirroringsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.ListPacketMirroringsRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.List(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExamplePacketMirroringsClient_Patch() { + ctx := context.Background() + c, err := compute.NewPacketMirroringsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.PatchPacketMirroringRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Patch(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExamplePacketMirroringsClient_TestIamPermissions() { + ctx := context.Background() + c, err := compute.NewPacketMirroringsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.TestIamPermissionsPacketMirroringRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.TestIamPermissions(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} diff --git a/compute/apiv1/projects_client.go b/compute/apiv1/projects_client.go new file mode 100644 index 00000000000..03d1aa434da --- /dev/null +++ b/compute/apiv1/projects_client.go @@ -0,0 +1,905 @@ +// 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 compute + +import ( + "bytes" + "context" + "fmt" + "io/ioutil" + "net/http" + "net/url" + + gax "github.com/googleapis/gax-go/v2" + "google.golang.org/api/option" + "google.golang.org/api/option/internaloption" + httptransport "google.golang.org/api/transport/http" + computepb "google.golang.org/genproto/googleapis/cloud/compute/v1" + "google.golang.org/grpc" + "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/encoding/protojson" +) + +var newProjectsClientHook clientHook + +// ProjectsCallOptions contains the retry settings for each method of ProjectsClient. +type ProjectsCallOptions struct { + DisableXpnHost []gax.CallOption + DisableXpnResource []gax.CallOption + EnableXpnHost []gax.CallOption + EnableXpnResource []gax.CallOption + Get []gax.CallOption + GetXpnHost []gax.CallOption + GetXpnResources []gax.CallOption + ListXpnHosts []gax.CallOption + MoveDisk []gax.CallOption + MoveInstance []gax.CallOption + SetCommonInstanceMetadata []gax.CallOption + SetDefaultNetworkTier []gax.CallOption + SetUsageExportBucket []gax.CallOption +} + +// internalProjectsClient is an interface that defines the methods availaible from Google Compute Engine API. +type internalProjectsClient interface { + Close() error + setGoogleClientInfo(...string) + Connection() *grpc.ClientConn + DisableXpnHost(context.Context, *computepb.DisableXpnHostProjectRequest, ...gax.CallOption) (*computepb.Operation, error) + DisableXpnResource(context.Context, *computepb.DisableXpnResourceProjectRequest, ...gax.CallOption) (*computepb.Operation, error) + EnableXpnHost(context.Context, *computepb.EnableXpnHostProjectRequest, ...gax.CallOption) (*computepb.Operation, error) + EnableXpnResource(context.Context, *computepb.EnableXpnResourceProjectRequest, ...gax.CallOption) (*computepb.Operation, error) + Get(context.Context, *computepb.GetProjectRequest, ...gax.CallOption) (*computepb.Project, error) + GetXpnHost(context.Context, *computepb.GetXpnHostProjectRequest, ...gax.CallOption) (*computepb.Project, error) + GetXpnResources(context.Context, *computepb.GetXpnResourcesProjectsRequest, ...gax.CallOption) (*computepb.ProjectsGetXpnResources, error) + ListXpnHosts(context.Context, *computepb.ListXpnHostsProjectsRequest, ...gax.CallOption) (*computepb.XpnHostList, error) + MoveDisk(context.Context, *computepb.MoveDiskProjectRequest, ...gax.CallOption) (*computepb.Operation, error) + MoveInstance(context.Context, *computepb.MoveInstanceProjectRequest, ...gax.CallOption) (*computepb.Operation, error) + SetCommonInstanceMetadata(context.Context, *computepb.SetCommonInstanceMetadataProjectRequest, ...gax.CallOption) (*computepb.Operation, error) + SetDefaultNetworkTier(context.Context, *computepb.SetDefaultNetworkTierProjectRequest, ...gax.CallOption) (*computepb.Operation, error) + SetUsageExportBucket(context.Context, *computepb.SetUsageExportBucketProjectRequest, ...gax.CallOption) (*computepb.Operation, error) +} + +// ProjectsClient is a client for interacting with Google Compute Engine API. +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +// +// The Projects API. +type ProjectsClient struct { + // The internal transport-dependent client. + internalClient internalProjectsClient + + // The call options for this service. + CallOptions *ProjectsCallOptions +} + +// 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 *ProjectsClient) 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 *ProjectsClient) setGoogleClientInfo(keyval ...string) { + c.internalClient.setGoogleClientInfo(keyval...) +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *ProjectsClient) Connection() *grpc.ClientConn { + return c.internalClient.Connection() +} + +// DisableXpnHost disable this project as a shared VPC host project. +func (c *ProjectsClient) DisableXpnHost(ctx context.Context, req *computepb.DisableXpnHostProjectRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.DisableXpnHost(ctx, req, opts...) +} + +// DisableXpnResource disable a service resource (also known as service project) associated with this host project. +func (c *ProjectsClient) DisableXpnResource(ctx context.Context, req *computepb.DisableXpnResourceProjectRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.DisableXpnResource(ctx, req, opts...) +} + +// EnableXpnHost enable this project as a shared VPC host project. +func (c *ProjectsClient) EnableXpnHost(ctx context.Context, req *computepb.EnableXpnHostProjectRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.EnableXpnHost(ctx, req, opts...) +} + +// EnableXpnResource enable service resource (a.k.a service project) for a host project, so that subnets in the host project can be used by instances in the service project. +func (c *ProjectsClient) EnableXpnResource(ctx context.Context, req *computepb.EnableXpnResourceProjectRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.EnableXpnResource(ctx, req, opts...) +} + +// Get returns the specified Project resource. +func (c *ProjectsClient) Get(ctx context.Context, req *computepb.GetProjectRequest, opts ...gax.CallOption) (*computepb.Project, error) { + return c.internalClient.Get(ctx, req, opts...) +} + +// GetXpnHost gets the shared VPC host project that this project links to. May be empty if no link exists. +func (c *ProjectsClient) GetXpnHost(ctx context.Context, req *computepb.GetXpnHostProjectRequest, opts ...gax.CallOption) (*computepb.Project, error) { + return c.internalClient.GetXpnHost(ctx, req, opts...) +} + +// GetXpnResources gets service resources (a.k.a service project) associated with this host project. +func (c *ProjectsClient) GetXpnResources(ctx context.Context, req *computepb.GetXpnResourcesProjectsRequest, opts ...gax.CallOption) (*computepb.ProjectsGetXpnResources, error) { + return c.internalClient.GetXpnResources(ctx, req, opts...) +} + +// ListXpnHosts lists all shared VPC host projects visible to the user in an organization. +func (c *ProjectsClient) ListXpnHosts(ctx context.Context, req *computepb.ListXpnHostsProjectsRequest, opts ...gax.CallOption) (*computepb.XpnHostList, error) { + return c.internalClient.ListXpnHosts(ctx, req, opts...) +} + +// MoveDisk moves a persistent disk from one zone to another. +func (c *ProjectsClient) MoveDisk(ctx context.Context, req *computepb.MoveDiskProjectRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.MoveDisk(ctx, req, opts...) +} + +// MoveInstance moves an instance and its attached persistent disks from one zone to another. +func (c *ProjectsClient) MoveInstance(ctx context.Context, req *computepb.MoveInstanceProjectRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.MoveInstance(ctx, req, opts...) +} + +// SetCommonInstanceMetadata sets metadata common to all instances within the specified project using the data included in the request. +func (c *ProjectsClient) SetCommonInstanceMetadata(ctx context.Context, req *computepb.SetCommonInstanceMetadataProjectRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.SetCommonInstanceMetadata(ctx, req, opts...) +} + +// SetDefaultNetworkTier sets the default network tier of the project. The default network tier is used when an address/forwardingRule/instance is created without specifying the network tier field. +func (c *ProjectsClient) SetDefaultNetworkTier(ctx context.Context, req *computepb.SetDefaultNetworkTierProjectRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.SetDefaultNetworkTier(ctx, req, opts...) +} + +// SetUsageExportBucket enables the usage export feature and sets the usage export bucket where reports are stored. If you provide an empty request body using this method, the usage export feature will be disabled. +func (c *ProjectsClient) SetUsageExportBucket(ctx context.Context, req *computepb.SetUsageExportBucketProjectRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.SetUsageExportBucket(ctx, req, opts...) +} + +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +type projectsRESTClient struct { + // The http endpoint to connect to. + endpoint string + + // The http client. + httpClient *http.Client + + // The x-goog-* metadata to be sent with each request. + xGoogMetadata metadata.MD +} + +// NewProjectsRESTClient creates a new projects rest client. +// +// The Projects API. +func NewProjectsRESTClient(ctx context.Context, opts ...option.ClientOption) (*ProjectsClient, error) { + clientOpts := append(defaultProjectsRESTClientOptions(), opts...) + httpClient, endpoint, err := httptransport.NewClient(ctx, clientOpts...) + if err != nil { + return nil, err + } + + c := &projectsRESTClient{ + endpoint: endpoint, + httpClient: httpClient, + } + c.setGoogleClientInfo() + + return &ProjectsClient{internalClient: c, CallOptions: &ProjectsCallOptions{}}, nil +} + +func defaultProjectsRESTClientOptions() []option.ClientOption { + return []option.ClientOption{ + internaloption.WithDefaultEndpoint("compute.googleapis.com"), + internaloption.WithDefaultMTLSEndpoint("compute.mtls.googleapis.com"), + internaloption.WithDefaultAudience("https://compute.googleapis.com/"), + internaloption.WithDefaultScopes(DefaultAuthScopes()...), + } +} + +// 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 *projectsRESTClient) setGoogleClientInfo(keyval ...string) { + kv := append([]string{"gl-go", versionGo()}, keyval...) + kv = append(kv, "gapic", versionClient, "gax", gax.Version, "rest", "UNKNOWN") + 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 *projectsRESTClient) Close() error { + // Replace httpClient with nil to force cleanup. + c.httpClient = nil + return nil +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *projectsRESTClient) Connection() *grpc.ClientConn { + return nil +} + +// DisableXpnHost disable this project as a shared VPC host project. +func (c *projectsRESTClient) DisableXpnHost(ctx context.Context, req *computepb.DisableXpnHostProjectRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/disableXpnHost", req.GetProject()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// DisableXpnResource disable a service resource (also known as service project) associated with this host project. +func (c *projectsRESTClient) DisableXpnResource(ctx context.Context, req *computepb.DisableXpnResourceProjectRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetProjectsDisableXpnResourceRequestResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/disableXpnResource", req.GetProject()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// EnableXpnHost enable this project as a shared VPC host project. +func (c *projectsRESTClient) EnableXpnHost(ctx context.Context, req *computepb.EnableXpnHostProjectRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/enableXpnHost", req.GetProject()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// EnableXpnResource enable service resource (a.k.a service project) for a host project, so that subnets in the host project can be used by instances in the service project. +func (c *projectsRESTClient) EnableXpnResource(ctx context.Context, req *computepb.EnableXpnResourceProjectRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetProjectsEnableXpnResourceRequestResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/enableXpnResource", req.GetProject()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Get returns the specified Project resource. +func (c *projectsRESTClient) Get(ctx context.Context, req *computepb.GetProjectRequest, opts ...gax.CallOption) (*computepb.Project, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v", req.GetProject()) + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Project{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// GetXpnHost gets the shared VPC host project that this project links to. May be empty if no link exists. +func (c *projectsRESTClient) GetXpnHost(ctx context.Context, req *computepb.GetXpnHostProjectRequest, opts ...gax.CallOption) (*computepb.Project, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/getXpnHost", req.GetProject()) + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Project{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// GetXpnResources gets service resources (a.k.a service project) associated with this host project. +func (c *projectsRESTClient) GetXpnResources(ctx context.Context, req *computepb.GetXpnResourcesProjectsRequest, opts ...gax.CallOption) (*computepb.ProjectsGetXpnResources, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/getXpnResources", req.GetProject()) + + params := url.Values{} + if req != nil && req.Filter != nil { + params.Add("filter", fmt.Sprintf("%v", req.GetFilter())) + } + if req != nil && req.MaxResults != nil { + params.Add("maxResults", fmt.Sprintf("%v", req.GetMaxResults())) + } + if req != nil && req.OrderBy != nil { + params.Add("orderBy", fmt.Sprintf("%v", req.GetOrderBy())) + } + if req != nil && req.PageToken != nil { + params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) + } + if req != nil && req.ReturnPartialSuccess != nil { + params.Add("returnPartialSuccess", fmt.Sprintf("%v", req.GetReturnPartialSuccess())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.ProjectsGetXpnResources{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// ListXpnHosts lists all shared VPC host projects visible to the user in an organization. +func (c *projectsRESTClient) ListXpnHosts(ctx context.Context, req *computepb.ListXpnHostsProjectsRequest, opts ...gax.CallOption) (*computepb.XpnHostList, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetProjectsListXpnHostsRequestResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/listXpnHosts", req.GetProject()) + + params := url.Values{} + if req != nil && req.Filter != nil { + params.Add("filter", fmt.Sprintf("%v", req.GetFilter())) + } + if req != nil && req.MaxResults != nil { + params.Add("maxResults", fmt.Sprintf("%v", req.GetMaxResults())) + } + if req != nil && req.OrderBy != nil { + params.Add("orderBy", fmt.Sprintf("%v", req.GetOrderBy())) + } + if req != nil && req.PageToken != nil { + params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) + } + if req != nil && req.ReturnPartialSuccess != nil { + params.Add("returnPartialSuccess", fmt.Sprintf("%v", req.GetReturnPartialSuccess())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.XpnHostList{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// MoveDisk moves a persistent disk from one zone to another. +func (c *projectsRESTClient) MoveDisk(ctx context.Context, req *computepb.MoveDiskProjectRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetDiskMoveRequestResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/moveDisk", req.GetProject()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// MoveInstance moves an instance and its attached persistent disks from one zone to another. +func (c *projectsRESTClient) MoveInstance(ctx context.Context, req *computepb.MoveInstanceProjectRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetInstanceMoveRequestResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/moveInstance", req.GetProject()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// SetCommonInstanceMetadata sets metadata common to all instances within the specified project using the data included in the request. +func (c *projectsRESTClient) SetCommonInstanceMetadata(ctx context.Context, req *computepb.SetCommonInstanceMetadataProjectRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetMetadataResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/setCommonInstanceMetadata", req.GetProject()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// SetDefaultNetworkTier sets the default network tier of the project. The default network tier is used when an address/forwardingRule/instance is created without specifying the network tier field. +func (c *projectsRESTClient) SetDefaultNetworkTier(ctx context.Context, req *computepb.SetDefaultNetworkTierProjectRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetProjectsSetDefaultNetworkTierRequestResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/setDefaultNetworkTier", req.GetProject()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// SetUsageExportBucket enables the usage export feature and sets the usage export bucket where reports are stored. If you provide an empty request body using this method, the usage export feature will be disabled. +func (c *projectsRESTClient) SetUsageExportBucket(ctx context.Context, req *computepb.SetUsageExportBucketProjectRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetUsageExportLocationResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/setUsageExportBucket", req.GetProject()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} diff --git a/compute/apiv1/projects_client_example_test.go b/compute/apiv1/projects_client_example_test.go new file mode 100644 index 00000000000..7ef81b62889 --- /dev/null +++ b/compute/apiv1/projects_client_example_test.go @@ -0,0 +1,283 @@ +// 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 compute_test + +import ( + "context" + + compute "cloud.google.com/go/compute/apiv1" + computepb "google.golang.org/genproto/googleapis/cloud/compute/v1" +) + +func ExampleNewProjectsRESTClient() { + ctx := context.Background() + c, err := compute.NewProjectsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + // TODO: Use client. + _ = c +} + +func ExampleProjectsClient_DisableXpnHost() { + ctx := context.Background() + c, err := compute.NewProjectsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.DisableXpnHostProjectRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.DisableXpnHost(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleProjectsClient_DisableXpnResource() { + ctx := context.Background() + c, err := compute.NewProjectsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.DisableXpnResourceProjectRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.DisableXpnResource(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleProjectsClient_EnableXpnHost() { + ctx := context.Background() + c, err := compute.NewProjectsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.EnableXpnHostProjectRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.EnableXpnHost(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleProjectsClient_EnableXpnResource() { + ctx := context.Background() + c, err := compute.NewProjectsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.EnableXpnResourceProjectRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.EnableXpnResource(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleProjectsClient_Get() { + ctx := context.Background() + c, err := compute.NewProjectsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.GetProjectRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Get(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleProjectsClient_GetXpnHost() { + ctx := context.Background() + c, err := compute.NewProjectsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.GetXpnHostProjectRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.GetXpnHost(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleProjectsClient_GetXpnResources() { + ctx := context.Background() + c, err := compute.NewProjectsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.GetXpnResourcesProjectsRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.GetXpnResources(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleProjectsClient_ListXpnHosts() { + ctx := context.Background() + c, err := compute.NewProjectsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.ListXpnHostsProjectsRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.ListXpnHosts(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleProjectsClient_MoveDisk() { + ctx := context.Background() + c, err := compute.NewProjectsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.MoveDiskProjectRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.MoveDisk(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleProjectsClient_MoveInstance() { + ctx := context.Background() + c, err := compute.NewProjectsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.MoveInstanceProjectRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.MoveInstance(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleProjectsClient_SetCommonInstanceMetadata() { + ctx := context.Background() + c, err := compute.NewProjectsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.SetCommonInstanceMetadataProjectRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.SetCommonInstanceMetadata(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleProjectsClient_SetDefaultNetworkTier() { + ctx := context.Background() + c, err := compute.NewProjectsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.SetDefaultNetworkTierProjectRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.SetDefaultNetworkTier(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleProjectsClient_SetUsageExportBucket() { + ctx := context.Background() + c, err := compute.NewProjectsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.SetUsageExportBucketProjectRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.SetUsageExportBucket(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} diff --git a/compute/apiv1/public_advertised_prefixes_client.go b/compute/apiv1/public_advertised_prefixes_client.go new file mode 100644 index 00000000000..01f9fa03d1e --- /dev/null +++ b/compute/apiv1/public_advertised_prefixes_client.go @@ -0,0 +1,438 @@ +// 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 compute + +import ( + "bytes" + "context" + "fmt" + "io/ioutil" + "net/http" + "net/url" + + gax "github.com/googleapis/gax-go/v2" + "google.golang.org/api/option" + "google.golang.org/api/option/internaloption" + httptransport "google.golang.org/api/transport/http" + computepb "google.golang.org/genproto/googleapis/cloud/compute/v1" + "google.golang.org/grpc" + "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/encoding/protojson" +) + +var newPublicAdvertisedPrefixesClientHook clientHook + +// PublicAdvertisedPrefixesCallOptions contains the retry settings for each method of PublicAdvertisedPrefixesClient. +type PublicAdvertisedPrefixesCallOptions struct { + Delete []gax.CallOption + Get []gax.CallOption + Insert []gax.CallOption + List []gax.CallOption + Patch []gax.CallOption +} + +// internalPublicAdvertisedPrefixesClient is an interface that defines the methods availaible from Google Compute Engine API. +type internalPublicAdvertisedPrefixesClient interface { + Close() error + setGoogleClientInfo(...string) + Connection() *grpc.ClientConn + Delete(context.Context, *computepb.DeletePublicAdvertisedPrefixeRequest, ...gax.CallOption) (*computepb.Operation, error) + Get(context.Context, *computepb.GetPublicAdvertisedPrefixeRequest, ...gax.CallOption) (*computepb.PublicAdvertisedPrefix, error) + Insert(context.Context, *computepb.InsertPublicAdvertisedPrefixeRequest, ...gax.CallOption) (*computepb.Operation, error) + List(context.Context, *computepb.ListPublicAdvertisedPrefixesRequest, ...gax.CallOption) (*computepb.PublicAdvertisedPrefixList, error) + Patch(context.Context, *computepb.PatchPublicAdvertisedPrefixeRequest, ...gax.CallOption) (*computepb.Operation, error) +} + +// PublicAdvertisedPrefixesClient is a client for interacting with Google Compute Engine API. +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +// +// The PublicAdvertisedPrefixes API. +type PublicAdvertisedPrefixesClient struct { + // The internal transport-dependent client. + internalClient internalPublicAdvertisedPrefixesClient + + // The call options for this service. + CallOptions *PublicAdvertisedPrefixesCallOptions +} + +// 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 *PublicAdvertisedPrefixesClient) 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 *PublicAdvertisedPrefixesClient) setGoogleClientInfo(keyval ...string) { + c.internalClient.setGoogleClientInfo(keyval...) +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *PublicAdvertisedPrefixesClient) Connection() *grpc.ClientConn { + return c.internalClient.Connection() +} + +// Delete deletes the specified PublicAdvertisedPrefix +func (c *PublicAdvertisedPrefixesClient) Delete(ctx context.Context, req *computepb.DeletePublicAdvertisedPrefixeRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.Delete(ctx, req, opts...) +} + +// Get returns the specified PublicAdvertisedPrefix resource. +func (c *PublicAdvertisedPrefixesClient) Get(ctx context.Context, req *computepb.GetPublicAdvertisedPrefixeRequest, opts ...gax.CallOption) (*computepb.PublicAdvertisedPrefix, error) { + return c.internalClient.Get(ctx, req, opts...) +} + +// Insert creates a PublicAdvertisedPrefix in the specified project using the parameters that are included in the request. +func (c *PublicAdvertisedPrefixesClient) Insert(ctx context.Context, req *computepb.InsertPublicAdvertisedPrefixeRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.Insert(ctx, req, opts...) +} + +// List lists the PublicAdvertisedPrefixes for a project. +func (c *PublicAdvertisedPrefixesClient) List(ctx context.Context, req *computepb.ListPublicAdvertisedPrefixesRequest, opts ...gax.CallOption) (*computepb.PublicAdvertisedPrefixList, error) { + return c.internalClient.List(ctx, req, opts...) +} + +// Patch patches the specified Router resource with the data included in the request. This method supports PATCH semantics and uses JSON merge patch format and processing rules. +func (c *PublicAdvertisedPrefixesClient) Patch(ctx context.Context, req *computepb.PatchPublicAdvertisedPrefixeRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.Patch(ctx, req, opts...) +} + +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +type publicAdvertisedPrefixesRESTClient struct { + // The http endpoint to connect to. + endpoint string + + // The http client. + httpClient *http.Client + + // The x-goog-* metadata to be sent with each request. + xGoogMetadata metadata.MD +} + +// NewPublicAdvertisedPrefixesRESTClient creates a new public advertised prefixes rest client. +// +// The PublicAdvertisedPrefixes API. +func NewPublicAdvertisedPrefixesRESTClient(ctx context.Context, opts ...option.ClientOption) (*PublicAdvertisedPrefixesClient, error) { + clientOpts := append(defaultPublicAdvertisedPrefixesRESTClientOptions(), opts...) + httpClient, endpoint, err := httptransport.NewClient(ctx, clientOpts...) + if err != nil { + return nil, err + } + + c := &publicAdvertisedPrefixesRESTClient{ + endpoint: endpoint, + httpClient: httpClient, + } + c.setGoogleClientInfo() + + return &PublicAdvertisedPrefixesClient{internalClient: c, CallOptions: &PublicAdvertisedPrefixesCallOptions{}}, nil +} + +func defaultPublicAdvertisedPrefixesRESTClientOptions() []option.ClientOption { + return []option.ClientOption{ + internaloption.WithDefaultEndpoint("compute.googleapis.com"), + internaloption.WithDefaultMTLSEndpoint("compute.mtls.googleapis.com"), + internaloption.WithDefaultAudience("https://compute.googleapis.com/"), + internaloption.WithDefaultScopes(DefaultAuthScopes()...), + } +} + +// 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 *publicAdvertisedPrefixesRESTClient) setGoogleClientInfo(keyval ...string) { + kv := append([]string{"gl-go", versionGo()}, keyval...) + kv = append(kv, "gapic", versionClient, "gax", gax.Version, "rest", "UNKNOWN") + 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 *publicAdvertisedPrefixesRESTClient) Close() error { + // Replace httpClient with nil to force cleanup. + c.httpClient = nil + return nil +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *publicAdvertisedPrefixesRESTClient) Connection() *grpc.ClientConn { + return nil +} + +// Delete deletes the specified PublicAdvertisedPrefix +func (c *publicAdvertisedPrefixesRESTClient) Delete(ctx context.Context, req *computepb.DeletePublicAdvertisedPrefixeRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/publicAdvertisedPrefixes/%v", req.GetProject(), req.GetPublicAdvertisedPrefix()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("DELETE", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Get returns the specified PublicAdvertisedPrefix resource. +func (c *publicAdvertisedPrefixesRESTClient) Get(ctx context.Context, req *computepb.GetPublicAdvertisedPrefixeRequest, opts ...gax.CallOption) (*computepb.PublicAdvertisedPrefix, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/publicAdvertisedPrefixes/%v", req.GetProject(), req.GetPublicAdvertisedPrefix()) + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.PublicAdvertisedPrefix{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Insert creates a PublicAdvertisedPrefix in the specified project using the parameters that are included in the request. +func (c *publicAdvertisedPrefixesRESTClient) Insert(ctx context.Context, req *computepb.InsertPublicAdvertisedPrefixeRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetPublicAdvertisedPrefixResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/publicAdvertisedPrefixes", req.GetProject()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// List lists the PublicAdvertisedPrefixes for a project. +func (c *publicAdvertisedPrefixesRESTClient) List(ctx context.Context, req *computepb.ListPublicAdvertisedPrefixesRequest, opts ...gax.CallOption) (*computepb.PublicAdvertisedPrefixList, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/publicAdvertisedPrefixes", req.GetProject()) + + params := url.Values{} + if req != nil && req.Filter != nil { + params.Add("filter", fmt.Sprintf("%v", req.GetFilter())) + } + if req != nil && req.MaxResults != nil { + params.Add("maxResults", fmt.Sprintf("%v", req.GetMaxResults())) + } + if req != nil && req.OrderBy != nil { + params.Add("orderBy", fmt.Sprintf("%v", req.GetOrderBy())) + } + if req != nil && req.PageToken != nil { + params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) + } + if req != nil && req.ReturnPartialSuccess != nil { + params.Add("returnPartialSuccess", fmt.Sprintf("%v", req.GetReturnPartialSuccess())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.PublicAdvertisedPrefixList{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Patch patches the specified Router resource with the data included in the request. This method supports PATCH semantics and uses JSON merge patch format and processing rules. +func (c *publicAdvertisedPrefixesRESTClient) Patch(ctx context.Context, req *computepb.PatchPublicAdvertisedPrefixeRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetPublicAdvertisedPrefixResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/publicAdvertisedPrefixes/%v", req.GetProject(), req.GetPublicAdvertisedPrefix()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("PATCH", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} diff --git a/compute/apiv1/public_advertised_prefixes_client_example_test.go b/compute/apiv1/public_advertised_prefixes_client_example_test.go new file mode 100644 index 00000000000..157318c0c4d --- /dev/null +++ b/compute/apiv1/public_advertised_prefixes_client_example_test.go @@ -0,0 +1,131 @@ +// 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 compute_test + +import ( + "context" + + compute "cloud.google.com/go/compute/apiv1" + computepb "google.golang.org/genproto/googleapis/cloud/compute/v1" +) + +func ExampleNewPublicAdvertisedPrefixesRESTClient() { + ctx := context.Background() + c, err := compute.NewPublicAdvertisedPrefixesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + // TODO: Use client. + _ = c +} + +func ExamplePublicAdvertisedPrefixesClient_Delete() { + ctx := context.Background() + c, err := compute.NewPublicAdvertisedPrefixesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.DeletePublicAdvertisedPrefixeRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Delete(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExamplePublicAdvertisedPrefixesClient_Get() { + ctx := context.Background() + c, err := compute.NewPublicAdvertisedPrefixesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.GetPublicAdvertisedPrefixeRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Get(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExamplePublicAdvertisedPrefixesClient_Insert() { + ctx := context.Background() + c, err := compute.NewPublicAdvertisedPrefixesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.InsertPublicAdvertisedPrefixeRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Insert(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExamplePublicAdvertisedPrefixesClient_List() { + ctx := context.Background() + c, err := compute.NewPublicAdvertisedPrefixesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.ListPublicAdvertisedPrefixesRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.List(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExamplePublicAdvertisedPrefixesClient_Patch() { + ctx := context.Background() + c, err := compute.NewPublicAdvertisedPrefixesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.PatchPublicAdvertisedPrefixeRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Patch(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} diff --git a/compute/apiv1/public_delegated_prefixes_client.go b/compute/apiv1/public_delegated_prefixes_client.go new file mode 100644 index 00000000000..5a186c8800e --- /dev/null +++ b/compute/apiv1/public_delegated_prefixes_client.go @@ -0,0 +1,510 @@ +// 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 compute + +import ( + "bytes" + "context" + "fmt" + "io/ioutil" + "net/http" + "net/url" + + gax "github.com/googleapis/gax-go/v2" + "google.golang.org/api/option" + "google.golang.org/api/option/internaloption" + httptransport "google.golang.org/api/transport/http" + computepb "google.golang.org/genproto/googleapis/cloud/compute/v1" + "google.golang.org/grpc" + "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/encoding/protojson" +) + +var newPublicDelegatedPrefixesClientHook clientHook + +// PublicDelegatedPrefixesCallOptions contains the retry settings for each method of PublicDelegatedPrefixesClient. +type PublicDelegatedPrefixesCallOptions struct { + AggregatedList []gax.CallOption + Delete []gax.CallOption + Get []gax.CallOption + Insert []gax.CallOption + List []gax.CallOption + Patch []gax.CallOption +} + +// internalPublicDelegatedPrefixesClient is an interface that defines the methods availaible from Google Compute Engine API. +type internalPublicDelegatedPrefixesClient interface { + Close() error + setGoogleClientInfo(...string) + Connection() *grpc.ClientConn + AggregatedList(context.Context, *computepb.AggregatedListPublicDelegatedPrefixesRequest, ...gax.CallOption) (*computepb.PublicDelegatedPrefixAggregatedList, error) + Delete(context.Context, *computepb.DeletePublicDelegatedPrefixeRequest, ...gax.CallOption) (*computepb.Operation, error) + Get(context.Context, *computepb.GetPublicDelegatedPrefixeRequest, ...gax.CallOption) (*computepb.PublicDelegatedPrefix, error) + Insert(context.Context, *computepb.InsertPublicDelegatedPrefixeRequest, ...gax.CallOption) (*computepb.Operation, error) + List(context.Context, *computepb.ListPublicDelegatedPrefixesRequest, ...gax.CallOption) (*computepb.PublicDelegatedPrefixList, error) + Patch(context.Context, *computepb.PatchPublicDelegatedPrefixeRequest, ...gax.CallOption) (*computepb.Operation, error) +} + +// PublicDelegatedPrefixesClient is a client for interacting with Google Compute Engine API. +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +// +// The PublicDelegatedPrefixes API. +type PublicDelegatedPrefixesClient struct { + // The internal transport-dependent client. + internalClient internalPublicDelegatedPrefixesClient + + // The call options for this service. + CallOptions *PublicDelegatedPrefixesCallOptions +} + +// 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 *PublicDelegatedPrefixesClient) 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 *PublicDelegatedPrefixesClient) setGoogleClientInfo(keyval ...string) { + c.internalClient.setGoogleClientInfo(keyval...) +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *PublicDelegatedPrefixesClient) Connection() *grpc.ClientConn { + return c.internalClient.Connection() +} + +// AggregatedList lists all PublicDelegatedPrefix resources owned by the specific project across all scopes. +func (c *PublicDelegatedPrefixesClient) AggregatedList(ctx context.Context, req *computepb.AggregatedListPublicDelegatedPrefixesRequest, opts ...gax.CallOption) (*computepb.PublicDelegatedPrefixAggregatedList, error) { + return c.internalClient.AggregatedList(ctx, req, opts...) +} + +// Delete deletes the specified PublicDelegatedPrefix in the given region. +func (c *PublicDelegatedPrefixesClient) Delete(ctx context.Context, req *computepb.DeletePublicDelegatedPrefixeRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.Delete(ctx, req, opts...) +} + +// Get returns the specified PublicDelegatedPrefix resource in the given region. +func (c *PublicDelegatedPrefixesClient) Get(ctx context.Context, req *computepb.GetPublicDelegatedPrefixeRequest, opts ...gax.CallOption) (*computepb.PublicDelegatedPrefix, error) { + return c.internalClient.Get(ctx, req, opts...) +} + +// Insert creates a PublicDelegatedPrefix in the specified project in the given region using the parameters that are included in the request. +func (c *PublicDelegatedPrefixesClient) Insert(ctx context.Context, req *computepb.InsertPublicDelegatedPrefixeRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.Insert(ctx, req, opts...) +} + +// List lists the PublicDelegatedPrefixes for a project in the given region. +func (c *PublicDelegatedPrefixesClient) List(ctx context.Context, req *computepb.ListPublicDelegatedPrefixesRequest, opts ...gax.CallOption) (*computepb.PublicDelegatedPrefixList, error) { + return c.internalClient.List(ctx, req, opts...) +} + +// Patch patches the specified PublicDelegatedPrefix resource with the data included in the request. This method supports PATCH semantics and uses JSON merge patch format and processing rules. +func (c *PublicDelegatedPrefixesClient) Patch(ctx context.Context, req *computepb.PatchPublicDelegatedPrefixeRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.Patch(ctx, req, opts...) +} + +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +type publicDelegatedPrefixesRESTClient struct { + // The http endpoint to connect to. + endpoint string + + // The http client. + httpClient *http.Client + + // The x-goog-* metadata to be sent with each request. + xGoogMetadata metadata.MD +} + +// NewPublicDelegatedPrefixesRESTClient creates a new public delegated prefixes rest client. +// +// The PublicDelegatedPrefixes API. +func NewPublicDelegatedPrefixesRESTClient(ctx context.Context, opts ...option.ClientOption) (*PublicDelegatedPrefixesClient, error) { + clientOpts := append(defaultPublicDelegatedPrefixesRESTClientOptions(), opts...) + httpClient, endpoint, err := httptransport.NewClient(ctx, clientOpts...) + if err != nil { + return nil, err + } + + c := &publicDelegatedPrefixesRESTClient{ + endpoint: endpoint, + httpClient: httpClient, + } + c.setGoogleClientInfo() + + return &PublicDelegatedPrefixesClient{internalClient: c, CallOptions: &PublicDelegatedPrefixesCallOptions{}}, nil +} + +func defaultPublicDelegatedPrefixesRESTClientOptions() []option.ClientOption { + return []option.ClientOption{ + internaloption.WithDefaultEndpoint("compute.googleapis.com"), + internaloption.WithDefaultMTLSEndpoint("compute.mtls.googleapis.com"), + internaloption.WithDefaultAudience("https://compute.googleapis.com/"), + internaloption.WithDefaultScopes(DefaultAuthScopes()...), + } +} + +// 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 *publicDelegatedPrefixesRESTClient) setGoogleClientInfo(keyval ...string) { + kv := append([]string{"gl-go", versionGo()}, keyval...) + kv = append(kv, "gapic", versionClient, "gax", gax.Version, "rest", "UNKNOWN") + 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 *publicDelegatedPrefixesRESTClient) Close() error { + // Replace httpClient with nil to force cleanup. + c.httpClient = nil + return nil +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *publicDelegatedPrefixesRESTClient) Connection() *grpc.ClientConn { + return nil +} + +// AggregatedList lists all PublicDelegatedPrefix resources owned by the specific project across all scopes. +func (c *publicDelegatedPrefixesRESTClient) AggregatedList(ctx context.Context, req *computepb.AggregatedListPublicDelegatedPrefixesRequest, opts ...gax.CallOption) (*computepb.PublicDelegatedPrefixAggregatedList, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/aggregated/publicDelegatedPrefixes", req.GetProject()) + + params := url.Values{} + if req != nil && req.Filter != nil { + params.Add("filter", fmt.Sprintf("%v", req.GetFilter())) + } + if req != nil && req.IncludeAllScopes != nil { + params.Add("includeAllScopes", fmt.Sprintf("%v", req.GetIncludeAllScopes())) + } + if req != nil && req.MaxResults != nil { + params.Add("maxResults", fmt.Sprintf("%v", req.GetMaxResults())) + } + if req != nil && req.OrderBy != nil { + params.Add("orderBy", fmt.Sprintf("%v", req.GetOrderBy())) + } + if req != nil && req.PageToken != nil { + params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) + } + if req != nil && req.ReturnPartialSuccess != nil { + params.Add("returnPartialSuccess", fmt.Sprintf("%v", req.GetReturnPartialSuccess())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.PublicDelegatedPrefixAggregatedList{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Delete deletes the specified PublicDelegatedPrefix in the given region. +func (c *publicDelegatedPrefixesRESTClient) Delete(ctx context.Context, req *computepb.DeletePublicDelegatedPrefixeRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/regions/%v/publicDelegatedPrefixes/%v", req.GetProject(), req.GetRegion(), req.GetPublicDelegatedPrefix()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("DELETE", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Get returns the specified PublicDelegatedPrefix resource in the given region. +func (c *publicDelegatedPrefixesRESTClient) Get(ctx context.Context, req *computepb.GetPublicDelegatedPrefixeRequest, opts ...gax.CallOption) (*computepb.PublicDelegatedPrefix, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/regions/%v/publicDelegatedPrefixes/%v", req.GetProject(), req.GetRegion(), req.GetPublicDelegatedPrefix()) + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.PublicDelegatedPrefix{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Insert creates a PublicDelegatedPrefix in the specified project in the given region using the parameters that are included in the request. +func (c *publicDelegatedPrefixesRESTClient) Insert(ctx context.Context, req *computepb.InsertPublicDelegatedPrefixeRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetPublicDelegatedPrefixResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/regions/%v/publicDelegatedPrefixes", req.GetProject(), req.GetRegion()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// List lists the PublicDelegatedPrefixes for a project in the given region. +func (c *publicDelegatedPrefixesRESTClient) List(ctx context.Context, req *computepb.ListPublicDelegatedPrefixesRequest, opts ...gax.CallOption) (*computepb.PublicDelegatedPrefixList, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/regions/%v/publicDelegatedPrefixes", req.GetProject(), req.GetRegion()) + + params := url.Values{} + if req != nil && req.Filter != nil { + params.Add("filter", fmt.Sprintf("%v", req.GetFilter())) + } + if req != nil && req.MaxResults != nil { + params.Add("maxResults", fmt.Sprintf("%v", req.GetMaxResults())) + } + if req != nil && req.OrderBy != nil { + params.Add("orderBy", fmt.Sprintf("%v", req.GetOrderBy())) + } + if req != nil && req.PageToken != nil { + params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) + } + if req != nil && req.ReturnPartialSuccess != nil { + params.Add("returnPartialSuccess", fmt.Sprintf("%v", req.GetReturnPartialSuccess())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.PublicDelegatedPrefixList{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Patch patches the specified PublicDelegatedPrefix resource with the data included in the request. This method supports PATCH semantics and uses JSON merge patch format and processing rules. +func (c *publicDelegatedPrefixesRESTClient) Patch(ctx context.Context, req *computepb.PatchPublicDelegatedPrefixeRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetPublicDelegatedPrefixResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/regions/%v/publicDelegatedPrefixes/%v", req.GetProject(), req.GetRegion(), req.GetPublicDelegatedPrefix()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("PATCH", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} diff --git a/compute/apiv1/public_delegated_prefixes_client_example_test.go b/compute/apiv1/public_delegated_prefixes_client_example_test.go new file mode 100644 index 00000000000..c17586ce868 --- /dev/null +++ b/compute/apiv1/public_delegated_prefixes_client_example_test.go @@ -0,0 +1,150 @@ +// 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 compute_test + +import ( + "context" + + compute "cloud.google.com/go/compute/apiv1" + computepb "google.golang.org/genproto/googleapis/cloud/compute/v1" +) + +func ExampleNewPublicDelegatedPrefixesRESTClient() { + ctx := context.Background() + c, err := compute.NewPublicDelegatedPrefixesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + // TODO: Use client. + _ = c +} + +func ExamplePublicDelegatedPrefixesClient_AggregatedList() { + ctx := context.Background() + c, err := compute.NewPublicDelegatedPrefixesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.AggregatedListPublicDelegatedPrefixesRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.AggregatedList(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExamplePublicDelegatedPrefixesClient_Delete() { + ctx := context.Background() + c, err := compute.NewPublicDelegatedPrefixesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.DeletePublicDelegatedPrefixeRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Delete(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExamplePublicDelegatedPrefixesClient_Get() { + ctx := context.Background() + c, err := compute.NewPublicDelegatedPrefixesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.GetPublicDelegatedPrefixeRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Get(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExamplePublicDelegatedPrefixesClient_Insert() { + ctx := context.Background() + c, err := compute.NewPublicDelegatedPrefixesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.InsertPublicDelegatedPrefixeRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Insert(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExamplePublicDelegatedPrefixesClient_List() { + ctx := context.Background() + c, err := compute.NewPublicDelegatedPrefixesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.ListPublicDelegatedPrefixesRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.List(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExamplePublicDelegatedPrefixesClient_Patch() { + ctx := context.Background() + c, err := compute.NewPublicDelegatedPrefixesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.PatchPublicDelegatedPrefixeRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Patch(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} diff --git a/compute/apiv1/region_autoscalers_client.go b/compute/apiv1/region_autoscalers_client.go new file mode 100644 index 00000000000..32c026f5dcc --- /dev/null +++ b/compute/apiv1/region_autoscalers_client.go @@ -0,0 +1,508 @@ +// 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 compute + +import ( + "bytes" + "context" + "fmt" + "io/ioutil" + "net/http" + "net/url" + + gax "github.com/googleapis/gax-go/v2" + "google.golang.org/api/option" + "google.golang.org/api/option/internaloption" + httptransport "google.golang.org/api/transport/http" + computepb "google.golang.org/genproto/googleapis/cloud/compute/v1" + "google.golang.org/grpc" + "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/encoding/protojson" +) + +var newRegionAutoscalersClientHook clientHook + +// RegionAutoscalersCallOptions contains the retry settings for each method of RegionAutoscalersClient. +type RegionAutoscalersCallOptions struct { + Delete []gax.CallOption + Get []gax.CallOption + Insert []gax.CallOption + List []gax.CallOption + Patch []gax.CallOption + Update []gax.CallOption +} + +// internalRegionAutoscalersClient is an interface that defines the methods availaible from Google Compute Engine API. +type internalRegionAutoscalersClient interface { + Close() error + setGoogleClientInfo(...string) + Connection() *grpc.ClientConn + Delete(context.Context, *computepb.DeleteRegionAutoscalerRequest, ...gax.CallOption) (*computepb.Operation, error) + Get(context.Context, *computepb.GetRegionAutoscalerRequest, ...gax.CallOption) (*computepb.Autoscaler, error) + Insert(context.Context, *computepb.InsertRegionAutoscalerRequest, ...gax.CallOption) (*computepb.Operation, error) + List(context.Context, *computepb.ListRegionAutoscalersRequest, ...gax.CallOption) (*computepb.RegionAutoscalerList, error) + Patch(context.Context, *computepb.PatchRegionAutoscalerRequest, ...gax.CallOption) (*computepb.Operation, error) + Update(context.Context, *computepb.UpdateRegionAutoscalerRequest, ...gax.CallOption) (*computepb.Operation, error) +} + +// RegionAutoscalersClient is a client for interacting with Google Compute Engine API. +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +// +// The RegionAutoscalers API. +type RegionAutoscalersClient struct { + // The internal transport-dependent client. + internalClient internalRegionAutoscalersClient + + // The call options for this service. + CallOptions *RegionAutoscalersCallOptions +} + +// 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 *RegionAutoscalersClient) 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 *RegionAutoscalersClient) setGoogleClientInfo(keyval ...string) { + c.internalClient.setGoogleClientInfo(keyval...) +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *RegionAutoscalersClient) Connection() *grpc.ClientConn { + return c.internalClient.Connection() +} + +// Delete deletes the specified autoscaler. +func (c *RegionAutoscalersClient) Delete(ctx context.Context, req *computepb.DeleteRegionAutoscalerRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.Delete(ctx, req, opts...) +} + +// Get returns the specified autoscaler. +func (c *RegionAutoscalersClient) Get(ctx context.Context, req *computepb.GetRegionAutoscalerRequest, opts ...gax.CallOption) (*computepb.Autoscaler, error) { + return c.internalClient.Get(ctx, req, opts...) +} + +// Insert creates an autoscaler in the specified project using the data included in the request. +func (c *RegionAutoscalersClient) Insert(ctx context.Context, req *computepb.InsertRegionAutoscalerRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.Insert(ctx, req, opts...) +} + +// List retrieves a list of autoscalers contained within the specified region. +func (c *RegionAutoscalersClient) List(ctx context.Context, req *computepb.ListRegionAutoscalersRequest, opts ...gax.CallOption) (*computepb.RegionAutoscalerList, error) { + return c.internalClient.List(ctx, req, opts...) +} + +// Patch updates an autoscaler in the specified project using the data included in the request. This method supports PATCH semantics and uses the JSON merge patch format and processing rules. +func (c *RegionAutoscalersClient) Patch(ctx context.Context, req *computepb.PatchRegionAutoscalerRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.Patch(ctx, req, opts...) +} + +// Update updates an autoscaler in the specified project using the data included in the request. +func (c *RegionAutoscalersClient) Update(ctx context.Context, req *computepb.UpdateRegionAutoscalerRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.Update(ctx, req, opts...) +} + +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +type regionAutoscalersRESTClient struct { + // The http endpoint to connect to. + endpoint string + + // The http client. + httpClient *http.Client + + // The x-goog-* metadata to be sent with each request. + xGoogMetadata metadata.MD +} + +// NewRegionAutoscalersRESTClient creates a new region autoscalers rest client. +// +// The RegionAutoscalers API. +func NewRegionAutoscalersRESTClient(ctx context.Context, opts ...option.ClientOption) (*RegionAutoscalersClient, error) { + clientOpts := append(defaultRegionAutoscalersRESTClientOptions(), opts...) + httpClient, endpoint, err := httptransport.NewClient(ctx, clientOpts...) + if err != nil { + return nil, err + } + + c := ®ionAutoscalersRESTClient{ + endpoint: endpoint, + httpClient: httpClient, + } + c.setGoogleClientInfo() + + return &RegionAutoscalersClient{internalClient: c, CallOptions: &RegionAutoscalersCallOptions{}}, nil +} + +func defaultRegionAutoscalersRESTClientOptions() []option.ClientOption { + return []option.ClientOption{ + internaloption.WithDefaultEndpoint("compute.googleapis.com"), + internaloption.WithDefaultMTLSEndpoint("compute.mtls.googleapis.com"), + internaloption.WithDefaultAudience("https://compute.googleapis.com/"), + internaloption.WithDefaultScopes(DefaultAuthScopes()...), + } +} + +// 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 *regionAutoscalersRESTClient) setGoogleClientInfo(keyval ...string) { + kv := append([]string{"gl-go", versionGo()}, keyval...) + kv = append(kv, "gapic", versionClient, "gax", gax.Version, "rest", "UNKNOWN") + 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 *regionAutoscalersRESTClient) Close() error { + // Replace httpClient with nil to force cleanup. + c.httpClient = nil + return nil +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *regionAutoscalersRESTClient) Connection() *grpc.ClientConn { + return nil +} + +// Delete deletes the specified autoscaler. +func (c *regionAutoscalersRESTClient) Delete(ctx context.Context, req *computepb.DeleteRegionAutoscalerRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/regions/%v/autoscalers/%v", req.GetProject(), req.GetRegion(), req.GetAutoscaler()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("DELETE", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Get returns the specified autoscaler. +func (c *regionAutoscalersRESTClient) Get(ctx context.Context, req *computepb.GetRegionAutoscalerRequest, opts ...gax.CallOption) (*computepb.Autoscaler, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/regions/%v/autoscalers/%v", req.GetProject(), req.GetRegion(), req.GetAutoscaler()) + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Autoscaler{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Insert creates an autoscaler in the specified project using the data included in the request. +func (c *regionAutoscalersRESTClient) Insert(ctx context.Context, req *computepb.InsertRegionAutoscalerRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetAutoscalerResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/regions/%v/autoscalers", req.GetProject(), req.GetRegion()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// List retrieves a list of autoscalers contained within the specified region. +func (c *regionAutoscalersRESTClient) List(ctx context.Context, req *computepb.ListRegionAutoscalersRequest, opts ...gax.CallOption) (*computepb.RegionAutoscalerList, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/regions/%v/autoscalers", req.GetProject(), req.GetRegion()) + + params := url.Values{} + if req != nil && req.Filter != nil { + params.Add("filter", fmt.Sprintf("%v", req.GetFilter())) + } + if req != nil && req.MaxResults != nil { + params.Add("maxResults", fmt.Sprintf("%v", req.GetMaxResults())) + } + if req != nil && req.OrderBy != nil { + params.Add("orderBy", fmt.Sprintf("%v", req.GetOrderBy())) + } + if req != nil && req.PageToken != nil { + params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) + } + if req != nil && req.ReturnPartialSuccess != nil { + params.Add("returnPartialSuccess", fmt.Sprintf("%v", req.GetReturnPartialSuccess())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.RegionAutoscalerList{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Patch updates an autoscaler in the specified project using the data included in the request. This method supports PATCH semantics and uses the JSON merge patch format and processing rules. +func (c *regionAutoscalersRESTClient) Patch(ctx context.Context, req *computepb.PatchRegionAutoscalerRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetAutoscalerResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/regions/%v/autoscalers", req.GetProject(), req.GetRegion()) + + params := url.Values{} + if req != nil && req.Autoscaler != nil { + params.Add("autoscaler", fmt.Sprintf("%v", req.GetAutoscaler())) + } + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("PATCH", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Update updates an autoscaler in the specified project using the data included in the request. +func (c *regionAutoscalersRESTClient) Update(ctx context.Context, req *computepb.UpdateRegionAutoscalerRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetAutoscalerResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("") + + params := url.Values{} + if req != nil && req.Autoscaler != nil { + params.Add("autoscaler", fmt.Sprintf("%v", req.GetAutoscaler())) + } + if req.GetProject() != "" { + params.Add("project", fmt.Sprintf("%v", req.GetProject())) + } + if req.GetRegion() != "" { + params.Add("region", fmt.Sprintf("%v", req.GetRegion())) + } + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("PUT", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} diff --git a/compute/apiv1/region_autoscalers_client_example_test.go b/compute/apiv1/region_autoscalers_client_example_test.go new file mode 100644 index 00000000000..b3cf73327a8 --- /dev/null +++ b/compute/apiv1/region_autoscalers_client_example_test.go @@ -0,0 +1,150 @@ +// 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 compute_test + +import ( + "context" + + compute "cloud.google.com/go/compute/apiv1" + computepb "google.golang.org/genproto/googleapis/cloud/compute/v1" +) + +func ExampleNewRegionAutoscalersRESTClient() { + ctx := context.Background() + c, err := compute.NewRegionAutoscalersRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + // TODO: Use client. + _ = c +} + +func ExampleRegionAutoscalersClient_Delete() { + ctx := context.Background() + c, err := compute.NewRegionAutoscalersRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.DeleteRegionAutoscalerRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Delete(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleRegionAutoscalersClient_Get() { + ctx := context.Background() + c, err := compute.NewRegionAutoscalersRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.GetRegionAutoscalerRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Get(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleRegionAutoscalersClient_Insert() { + ctx := context.Background() + c, err := compute.NewRegionAutoscalersRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.InsertRegionAutoscalerRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Insert(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleRegionAutoscalersClient_List() { + ctx := context.Background() + c, err := compute.NewRegionAutoscalersRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.ListRegionAutoscalersRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.List(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleRegionAutoscalersClient_Patch() { + ctx := context.Background() + c, err := compute.NewRegionAutoscalersRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.PatchRegionAutoscalerRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Patch(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleRegionAutoscalersClient_Update() { + ctx := context.Background() + c, err := compute.NewRegionAutoscalersRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.UpdateRegionAutoscalerRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Update(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} diff --git a/compute/apiv1/region_backend_services_client.go b/compute/apiv1/region_backend_services_client.go new file mode 100644 index 00000000000..eae95808d2e --- /dev/null +++ b/compute/apiv1/region_backend_services_client.go @@ -0,0 +1,556 @@ +// 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 compute + +import ( + "bytes" + "context" + "fmt" + "io/ioutil" + "net/http" + "net/url" + + gax "github.com/googleapis/gax-go/v2" + "google.golang.org/api/option" + "google.golang.org/api/option/internaloption" + httptransport "google.golang.org/api/transport/http" + computepb "google.golang.org/genproto/googleapis/cloud/compute/v1" + "google.golang.org/grpc" + "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/encoding/protojson" +) + +var newRegionBackendServicesClientHook clientHook + +// RegionBackendServicesCallOptions contains the retry settings for each method of RegionBackendServicesClient. +type RegionBackendServicesCallOptions struct { + Delete []gax.CallOption + Get []gax.CallOption + GetHealth []gax.CallOption + Insert []gax.CallOption + List []gax.CallOption + Patch []gax.CallOption + Update []gax.CallOption +} + +// internalRegionBackendServicesClient is an interface that defines the methods availaible from Google Compute Engine API. +type internalRegionBackendServicesClient interface { + Close() error + setGoogleClientInfo(...string) + Connection() *grpc.ClientConn + Delete(context.Context, *computepb.DeleteRegionBackendServiceRequest, ...gax.CallOption) (*computepb.Operation, error) + Get(context.Context, *computepb.GetRegionBackendServiceRequest, ...gax.CallOption) (*computepb.BackendService, error) + GetHealth(context.Context, *computepb.GetHealthRegionBackendServiceRequest, ...gax.CallOption) (*computepb.BackendServiceGroupHealth, error) + Insert(context.Context, *computepb.InsertRegionBackendServiceRequest, ...gax.CallOption) (*computepb.Operation, error) + List(context.Context, *computepb.ListRegionBackendServicesRequest, ...gax.CallOption) (*computepb.BackendServiceList, error) + Patch(context.Context, *computepb.PatchRegionBackendServiceRequest, ...gax.CallOption) (*computepb.Operation, error) + Update(context.Context, *computepb.UpdateRegionBackendServiceRequest, ...gax.CallOption) (*computepb.Operation, error) +} + +// RegionBackendServicesClient is a client for interacting with Google Compute Engine API. +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +// +// The RegionBackendServices API. +type RegionBackendServicesClient struct { + // The internal transport-dependent client. + internalClient internalRegionBackendServicesClient + + // The call options for this service. + CallOptions *RegionBackendServicesCallOptions +} + +// 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 *RegionBackendServicesClient) 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 *RegionBackendServicesClient) setGoogleClientInfo(keyval ...string) { + c.internalClient.setGoogleClientInfo(keyval...) +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *RegionBackendServicesClient) Connection() *grpc.ClientConn { + return c.internalClient.Connection() +} + +// Delete deletes the specified regional BackendService resource. +func (c *RegionBackendServicesClient) Delete(ctx context.Context, req *computepb.DeleteRegionBackendServiceRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.Delete(ctx, req, opts...) +} + +// Get returns the specified regional BackendService resource. +func (c *RegionBackendServicesClient) Get(ctx context.Context, req *computepb.GetRegionBackendServiceRequest, opts ...gax.CallOption) (*computepb.BackendService, error) { + return c.internalClient.Get(ctx, req, opts...) +} + +// GetHealth gets the most recent health check results for this regional BackendService. +func (c *RegionBackendServicesClient) GetHealth(ctx context.Context, req *computepb.GetHealthRegionBackendServiceRequest, opts ...gax.CallOption) (*computepb.BackendServiceGroupHealth, error) { + return c.internalClient.GetHealth(ctx, req, opts...) +} + +// Insert creates a regional BackendService resource in the specified project using the data included in the request. For more information, see Backend services overview. +func (c *RegionBackendServicesClient) Insert(ctx context.Context, req *computepb.InsertRegionBackendServiceRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.Insert(ctx, req, opts...) +} + +// List retrieves the list of regional BackendService resources available to the specified project in the given region. +func (c *RegionBackendServicesClient) List(ctx context.Context, req *computepb.ListRegionBackendServicesRequest, opts ...gax.CallOption) (*computepb.BackendServiceList, error) { + return c.internalClient.List(ctx, req, opts...) +} + +// Patch updates the specified regional BackendService resource with the data included in the request. For more information, see Understanding backend services This method supports PATCH semantics and uses the JSON merge patch format and processing rules. +func (c *RegionBackendServicesClient) Patch(ctx context.Context, req *computepb.PatchRegionBackendServiceRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.Patch(ctx, req, opts...) +} + +// Update updates the specified regional BackendService resource with the data included in the request. For more information, see Backend services overview. +func (c *RegionBackendServicesClient) Update(ctx context.Context, req *computepb.UpdateRegionBackendServiceRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.Update(ctx, req, opts...) +} + +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +type regionBackendServicesRESTClient struct { + // The http endpoint to connect to. + endpoint string + + // The http client. + httpClient *http.Client + + // The x-goog-* metadata to be sent with each request. + xGoogMetadata metadata.MD +} + +// NewRegionBackendServicesRESTClient creates a new region backend services rest client. +// +// The RegionBackendServices API. +func NewRegionBackendServicesRESTClient(ctx context.Context, opts ...option.ClientOption) (*RegionBackendServicesClient, error) { + clientOpts := append(defaultRegionBackendServicesRESTClientOptions(), opts...) + httpClient, endpoint, err := httptransport.NewClient(ctx, clientOpts...) + if err != nil { + return nil, err + } + + c := ®ionBackendServicesRESTClient{ + endpoint: endpoint, + httpClient: httpClient, + } + c.setGoogleClientInfo() + + return &RegionBackendServicesClient{internalClient: c, CallOptions: &RegionBackendServicesCallOptions{}}, nil +} + +func defaultRegionBackendServicesRESTClientOptions() []option.ClientOption { + return []option.ClientOption{ + internaloption.WithDefaultEndpoint("compute.googleapis.com"), + internaloption.WithDefaultMTLSEndpoint("compute.mtls.googleapis.com"), + internaloption.WithDefaultAudience("https://compute.googleapis.com/"), + internaloption.WithDefaultScopes(DefaultAuthScopes()...), + } +} + +// 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 *regionBackendServicesRESTClient) setGoogleClientInfo(keyval ...string) { + kv := append([]string{"gl-go", versionGo()}, keyval...) + kv = append(kv, "gapic", versionClient, "gax", gax.Version, "rest", "UNKNOWN") + 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 *regionBackendServicesRESTClient) Close() error { + // Replace httpClient with nil to force cleanup. + c.httpClient = nil + return nil +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *regionBackendServicesRESTClient) Connection() *grpc.ClientConn { + return nil +} + +// Delete deletes the specified regional BackendService resource. +func (c *regionBackendServicesRESTClient) Delete(ctx context.Context, req *computepb.DeleteRegionBackendServiceRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/regions/%v/backendServices/%v", req.GetProject(), req.GetRegion(), req.GetBackendService()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("DELETE", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Get returns the specified regional BackendService resource. +func (c *regionBackendServicesRESTClient) Get(ctx context.Context, req *computepb.GetRegionBackendServiceRequest, opts ...gax.CallOption) (*computepb.BackendService, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/regions/%v/backendServices/%v", req.GetProject(), req.GetRegion(), req.GetBackendService()) + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.BackendService{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// GetHealth gets the most recent health check results for this regional BackendService. +func (c *regionBackendServicesRESTClient) GetHealth(ctx context.Context, req *computepb.GetHealthRegionBackendServiceRequest, opts ...gax.CallOption) (*computepb.BackendServiceGroupHealth, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetResourceGroupReferenceResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/regions/%v/backendServices/%v/getHealth", req.GetProject(), req.GetRegion(), req.GetBackendService()) + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.BackendServiceGroupHealth{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Insert creates a regional BackendService resource in the specified project using the data included in the request. For more information, see Backend services overview. +func (c *regionBackendServicesRESTClient) Insert(ctx context.Context, req *computepb.InsertRegionBackendServiceRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetBackendServiceResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/regions/%v/backendServices", req.GetProject(), req.GetRegion()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// List retrieves the list of regional BackendService resources available to the specified project in the given region. +func (c *regionBackendServicesRESTClient) List(ctx context.Context, req *computepb.ListRegionBackendServicesRequest, opts ...gax.CallOption) (*computepb.BackendServiceList, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/regions/%v/backendServices", req.GetProject(), req.GetRegion()) + + params := url.Values{} + if req != nil && req.Filter != nil { + params.Add("filter", fmt.Sprintf("%v", req.GetFilter())) + } + if req != nil && req.MaxResults != nil { + params.Add("maxResults", fmt.Sprintf("%v", req.GetMaxResults())) + } + if req != nil && req.OrderBy != nil { + params.Add("orderBy", fmt.Sprintf("%v", req.GetOrderBy())) + } + if req != nil && req.PageToken != nil { + params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) + } + if req != nil && req.ReturnPartialSuccess != nil { + params.Add("returnPartialSuccess", fmt.Sprintf("%v", req.GetReturnPartialSuccess())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.BackendServiceList{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Patch updates the specified regional BackendService resource with the data included in the request. For more information, see Understanding backend services This method supports PATCH semantics and uses the JSON merge patch format and processing rules. +func (c *regionBackendServicesRESTClient) Patch(ctx context.Context, req *computepb.PatchRegionBackendServiceRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetBackendServiceResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/regions/%v/backendServices/%v", req.GetProject(), req.GetRegion(), req.GetBackendService()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("PATCH", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Update updates the specified regional BackendService resource with the data included in the request. For more information, see Backend services overview. +func (c *regionBackendServicesRESTClient) Update(ctx context.Context, req *computepb.UpdateRegionBackendServiceRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetBackendServiceResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("") + + params := url.Values{} + if req.GetBackendService() != "" { + params.Add("backendService", fmt.Sprintf("%v", req.GetBackendService())) + } + if req.GetProject() != "" { + params.Add("project", fmt.Sprintf("%v", req.GetProject())) + } + if req.GetRegion() != "" { + params.Add("region", fmt.Sprintf("%v", req.GetRegion())) + } + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("PUT", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} diff --git a/compute/apiv1/region_backend_services_client_example_test.go b/compute/apiv1/region_backend_services_client_example_test.go new file mode 100644 index 00000000000..389fa3210c5 --- /dev/null +++ b/compute/apiv1/region_backend_services_client_example_test.go @@ -0,0 +1,169 @@ +// 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 compute_test + +import ( + "context" + + compute "cloud.google.com/go/compute/apiv1" + computepb "google.golang.org/genproto/googleapis/cloud/compute/v1" +) + +func ExampleNewRegionBackendServicesRESTClient() { + ctx := context.Background() + c, err := compute.NewRegionBackendServicesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + // TODO: Use client. + _ = c +} + +func ExampleRegionBackendServicesClient_Delete() { + ctx := context.Background() + c, err := compute.NewRegionBackendServicesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.DeleteRegionBackendServiceRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Delete(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleRegionBackendServicesClient_Get() { + ctx := context.Background() + c, err := compute.NewRegionBackendServicesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.GetRegionBackendServiceRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Get(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleRegionBackendServicesClient_GetHealth() { + ctx := context.Background() + c, err := compute.NewRegionBackendServicesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.GetHealthRegionBackendServiceRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.GetHealth(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleRegionBackendServicesClient_Insert() { + ctx := context.Background() + c, err := compute.NewRegionBackendServicesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.InsertRegionBackendServiceRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Insert(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleRegionBackendServicesClient_List() { + ctx := context.Background() + c, err := compute.NewRegionBackendServicesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.ListRegionBackendServicesRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.List(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleRegionBackendServicesClient_Patch() { + ctx := context.Background() + c, err := compute.NewRegionBackendServicesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.PatchRegionBackendServiceRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Patch(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleRegionBackendServicesClient_Update() { + ctx := context.Background() + c, err := compute.NewRegionBackendServicesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.UpdateRegionBackendServiceRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Update(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} diff --git a/compute/apiv1/region_commitments_client.go b/compute/apiv1/region_commitments_client.go new file mode 100644 index 00000000000..c0990697de2 --- /dev/null +++ b/compute/apiv1/region_commitments_client.go @@ -0,0 +1,395 @@ +// 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 compute + +import ( + "bytes" + "context" + "fmt" + "io/ioutil" + "net/http" + "net/url" + + gax "github.com/googleapis/gax-go/v2" + "google.golang.org/api/option" + "google.golang.org/api/option/internaloption" + httptransport "google.golang.org/api/transport/http" + computepb "google.golang.org/genproto/googleapis/cloud/compute/v1" + "google.golang.org/grpc" + "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/encoding/protojson" +) + +var newRegionCommitmentsClientHook clientHook + +// RegionCommitmentsCallOptions contains the retry settings for each method of RegionCommitmentsClient. +type RegionCommitmentsCallOptions struct { + AggregatedList []gax.CallOption + Get []gax.CallOption + Insert []gax.CallOption + List []gax.CallOption +} + +// internalRegionCommitmentsClient is an interface that defines the methods availaible from Google Compute Engine API. +type internalRegionCommitmentsClient interface { + Close() error + setGoogleClientInfo(...string) + Connection() *grpc.ClientConn + AggregatedList(context.Context, *computepb.AggregatedListRegionCommitmentsRequest, ...gax.CallOption) (*computepb.CommitmentAggregatedList, error) + Get(context.Context, *computepb.GetRegionCommitmentRequest, ...gax.CallOption) (*computepb.Commitment, error) + Insert(context.Context, *computepb.InsertRegionCommitmentRequest, ...gax.CallOption) (*computepb.Operation, error) + List(context.Context, *computepb.ListRegionCommitmentsRequest, ...gax.CallOption) (*computepb.CommitmentList, error) +} + +// RegionCommitmentsClient is a client for interacting with Google Compute Engine API. +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +// +// The RegionCommitments API. +type RegionCommitmentsClient struct { + // The internal transport-dependent client. + internalClient internalRegionCommitmentsClient + + // The call options for this service. + CallOptions *RegionCommitmentsCallOptions +} + +// 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 *RegionCommitmentsClient) 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 *RegionCommitmentsClient) setGoogleClientInfo(keyval ...string) { + c.internalClient.setGoogleClientInfo(keyval...) +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *RegionCommitmentsClient) Connection() *grpc.ClientConn { + return c.internalClient.Connection() +} + +// AggregatedList retrieves an aggregated list of commitments. +func (c *RegionCommitmentsClient) AggregatedList(ctx context.Context, req *computepb.AggregatedListRegionCommitmentsRequest, opts ...gax.CallOption) (*computepb.CommitmentAggregatedList, error) { + return c.internalClient.AggregatedList(ctx, req, opts...) +} + +// Get returns the specified commitment resource. Gets a list of available commitments by making a list() request. +func (c *RegionCommitmentsClient) Get(ctx context.Context, req *computepb.GetRegionCommitmentRequest, opts ...gax.CallOption) (*computepb.Commitment, error) { + return c.internalClient.Get(ctx, req, opts...) +} + +// Insert creates a commitment in the specified project using the data included in the request. +func (c *RegionCommitmentsClient) Insert(ctx context.Context, req *computepb.InsertRegionCommitmentRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.Insert(ctx, req, opts...) +} + +// List retrieves a list of commitments contained within the specified region. +func (c *RegionCommitmentsClient) List(ctx context.Context, req *computepb.ListRegionCommitmentsRequest, opts ...gax.CallOption) (*computepb.CommitmentList, error) { + return c.internalClient.List(ctx, req, opts...) +} + +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +type regionCommitmentsRESTClient struct { + // The http endpoint to connect to. + endpoint string + + // The http client. + httpClient *http.Client + + // The x-goog-* metadata to be sent with each request. + xGoogMetadata metadata.MD +} + +// NewRegionCommitmentsRESTClient creates a new region commitments rest client. +// +// The RegionCommitments API. +func NewRegionCommitmentsRESTClient(ctx context.Context, opts ...option.ClientOption) (*RegionCommitmentsClient, error) { + clientOpts := append(defaultRegionCommitmentsRESTClientOptions(), opts...) + httpClient, endpoint, err := httptransport.NewClient(ctx, clientOpts...) + if err != nil { + return nil, err + } + + c := ®ionCommitmentsRESTClient{ + endpoint: endpoint, + httpClient: httpClient, + } + c.setGoogleClientInfo() + + return &RegionCommitmentsClient{internalClient: c, CallOptions: &RegionCommitmentsCallOptions{}}, nil +} + +func defaultRegionCommitmentsRESTClientOptions() []option.ClientOption { + return []option.ClientOption{ + internaloption.WithDefaultEndpoint("compute.googleapis.com"), + internaloption.WithDefaultMTLSEndpoint("compute.mtls.googleapis.com"), + internaloption.WithDefaultAudience("https://compute.googleapis.com/"), + internaloption.WithDefaultScopes(DefaultAuthScopes()...), + } +} + +// 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 *regionCommitmentsRESTClient) setGoogleClientInfo(keyval ...string) { + kv := append([]string{"gl-go", versionGo()}, keyval...) + kv = append(kv, "gapic", versionClient, "gax", gax.Version, "rest", "UNKNOWN") + 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 *regionCommitmentsRESTClient) Close() error { + // Replace httpClient with nil to force cleanup. + c.httpClient = nil + return nil +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *regionCommitmentsRESTClient) Connection() *grpc.ClientConn { + return nil +} + +// AggregatedList retrieves an aggregated list of commitments. +func (c *regionCommitmentsRESTClient) AggregatedList(ctx context.Context, req *computepb.AggregatedListRegionCommitmentsRequest, opts ...gax.CallOption) (*computepb.CommitmentAggregatedList, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/aggregated/commitments", req.GetProject()) + + params := url.Values{} + if req != nil && req.Filter != nil { + params.Add("filter", fmt.Sprintf("%v", req.GetFilter())) + } + if req != nil && req.IncludeAllScopes != nil { + params.Add("includeAllScopes", fmt.Sprintf("%v", req.GetIncludeAllScopes())) + } + if req != nil && req.MaxResults != nil { + params.Add("maxResults", fmt.Sprintf("%v", req.GetMaxResults())) + } + if req != nil && req.OrderBy != nil { + params.Add("orderBy", fmt.Sprintf("%v", req.GetOrderBy())) + } + if req != nil && req.PageToken != nil { + params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) + } + if req != nil && req.ReturnPartialSuccess != nil { + params.Add("returnPartialSuccess", fmt.Sprintf("%v", req.GetReturnPartialSuccess())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.CommitmentAggregatedList{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Get returns the specified commitment resource. Gets a list of available commitments by making a list() request. +func (c *regionCommitmentsRESTClient) Get(ctx context.Context, req *computepb.GetRegionCommitmentRequest, opts ...gax.CallOption) (*computepb.Commitment, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/regions/%v/commitments/%v", req.GetProject(), req.GetRegion(), req.GetCommitment()) + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Commitment{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Insert creates a commitment in the specified project using the data included in the request. +func (c *regionCommitmentsRESTClient) Insert(ctx context.Context, req *computepb.InsertRegionCommitmentRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetCommitmentResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/regions/%v/commitments", req.GetProject(), req.GetRegion()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// List retrieves a list of commitments contained within the specified region. +func (c *regionCommitmentsRESTClient) List(ctx context.Context, req *computepb.ListRegionCommitmentsRequest, opts ...gax.CallOption) (*computepb.CommitmentList, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/regions/%v/commitments", req.GetProject(), req.GetRegion()) + + params := url.Values{} + if req != nil && req.Filter != nil { + params.Add("filter", fmt.Sprintf("%v", req.GetFilter())) + } + if req != nil && req.MaxResults != nil { + params.Add("maxResults", fmt.Sprintf("%v", req.GetMaxResults())) + } + if req != nil && req.OrderBy != nil { + params.Add("orderBy", fmt.Sprintf("%v", req.GetOrderBy())) + } + if req != nil && req.PageToken != nil { + params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) + } + if req != nil && req.ReturnPartialSuccess != nil { + params.Add("returnPartialSuccess", fmt.Sprintf("%v", req.GetReturnPartialSuccess())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.CommitmentList{} + + return rsp, unm.Unmarshal(buf, rsp) +} diff --git a/compute/apiv1/region_commitments_client_example_test.go b/compute/apiv1/region_commitments_client_example_test.go new file mode 100644 index 00000000000..5cc685667d4 --- /dev/null +++ b/compute/apiv1/region_commitments_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 compute_test + +import ( + "context" + + compute "cloud.google.com/go/compute/apiv1" + computepb "google.golang.org/genproto/googleapis/cloud/compute/v1" +) + +func ExampleNewRegionCommitmentsRESTClient() { + ctx := context.Background() + c, err := compute.NewRegionCommitmentsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + // TODO: Use client. + _ = c +} + +func ExampleRegionCommitmentsClient_AggregatedList() { + ctx := context.Background() + c, err := compute.NewRegionCommitmentsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.AggregatedListRegionCommitmentsRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.AggregatedList(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleRegionCommitmentsClient_Get() { + ctx := context.Background() + c, err := compute.NewRegionCommitmentsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.GetRegionCommitmentRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Get(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleRegionCommitmentsClient_Insert() { + ctx := context.Background() + c, err := compute.NewRegionCommitmentsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.InsertRegionCommitmentRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Insert(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleRegionCommitmentsClient_List() { + ctx := context.Background() + c, err := compute.NewRegionCommitmentsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.ListRegionCommitmentsRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.List(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} diff --git a/compute/apiv1/region_disk_types_client.go b/compute/apiv1/region_disk_types_client.go new file mode 100644 index 00000000000..cc443bbbbfd --- /dev/null +++ b/compute/apiv1/region_disk_types_client.go @@ -0,0 +1,265 @@ +// 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 compute + +import ( + "bytes" + "context" + "fmt" + "io/ioutil" + "net/http" + "net/url" + + gax "github.com/googleapis/gax-go/v2" + "google.golang.org/api/option" + "google.golang.org/api/option/internaloption" + httptransport "google.golang.org/api/transport/http" + computepb "google.golang.org/genproto/googleapis/cloud/compute/v1" + "google.golang.org/grpc" + "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/encoding/protojson" +) + +var newRegionDiskTypesClientHook clientHook + +// RegionDiskTypesCallOptions contains the retry settings for each method of RegionDiskTypesClient. +type RegionDiskTypesCallOptions struct { + Get []gax.CallOption + List []gax.CallOption +} + +// internalRegionDiskTypesClient is an interface that defines the methods availaible from Google Compute Engine API. +type internalRegionDiskTypesClient interface { + Close() error + setGoogleClientInfo(...string) + Connection() *grpc.ClientConn + Get(context.Context, *computepb.GetRegionDiskTypeRequest, ...gax.CallOption) (*computepb.DiskType, error) + List(context.Context, *computepb.ListRegionDiskTypesRequest, ...gax.CallOption) (*computepb.RegionDiskTypeList, error) +} + +// RegionDiskTypesClient is a client for interacting with Google Compute Engine API. +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +// +// The RegionDiskTypes API. +type RegionDiskTypesClient struct { + // The internal transport-dependent client. + internalClient internalRegionDiskTypesClient + + // The call options for this service. + CallOptions *RegionDiskTypesCallOptions +} + +// 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 *RegionDiskTypesClient) 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 *RegionDiskTypesClient) setGoogleClientInfo(keyval ...string) { + c.internalClient.setGoogleClientInfo(keyval...) +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *RegionDiskTypesClient) Connection() *grpc.ClientConn { + return c.internalClient.Connection() +} + +// Get returns the specified regional disk type. Gets a list of available disk types by making a list() request. +func (c *RegionDiskTypesClient) Get(ctx context.Context, req *computepb.GetRegionDiskTypeRequest, opts ...gax.CallOption) (*computepb.DiskType, error) { + return c.internalClient.Get(ctx, req, opts...) +} + +// List retrieves a list of regional disk types available to the specified project. +func (c *RegionDiskTypesClient) List(ctx context.Context, req *computepb.ListRegionDiskTypesRequest, opts ...gax.CallOption) (*computepb.RegionDiskTypeList, error) { + return c.internalClient.List(ctx, req, opts...) +} + +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +type regionDiskTypesRESTClient struct { + // The http endpoint to connect to. + endpoint string + + // The http client. + httpClient *http.Client + + // The x-goog-* metadata to be sent with each request. + xGoogMetadata metadata.MD +} + +// NewRegionDiskTypesRESTClient creates a new region disk types rest client. +// +// The RegionDiskTypes API. +func NewRegionDiskTypesRESTClient(ctx context.Context, opts ...option.ClientOption) (*RegionDiskTypesClient, error) { + clientOpts := append(defaultRegionDiskTypesRESTClientOptions(), opts...) + httpClient, endpoint, err := httptransport.NewClient(ctx, clientOpts...) + if err != nil { + return nil, err + } + + c := ®ionDiskTypesRESTClient{ + endpoint: endpoint, + httpClient: httpClient, + } + c.setGoogleClientInfo() + + return &RegionDiskTypesClient{internalClient: c, CallOptions: &RegionDiskTypesCallOptions{}}, nil +} + +func defaultRegionDiskTypesRESTClientOptions() []option.ClientOption { + return []option.ClientOption{ + internaloption.WithDefaultEndpoint("compute.googleapis.com"), + internaloption.WithDefaultMTLSEndpoint("compute.mtls.googleapis.com"), + internaloption.WithDefaultAudience("https://compute.googleapis.com/"), + internaloption.WithDefaultScopes(DefaultAuthScopes()...), + } +} + +// 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 *regionDiskTypesRESTClient) setGoogleClientInfo(keyval ...string) { + kv := append([]string{"gl-go", versionGo()}, keyval...) + kv = append(kv, "gapic", versionClient, "gax", gax.Version, "rest", "UNKNOWN") + 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 *regionDiskTypesRESTClient) Close() error { + // Replace httpClient with nil to force cleanup. + c.httpClient = nil + return nil +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *regionDiskTypesRESTClient) Connection() *grpc.ClientConn { + return nil +} + +// Get returns the specified regional disk type. Gets a list of available disk types by making a list() request. +func (c *regionDiskTypesRESTClient) Get(ctx context.Context, req *computepb.GetRegionDiskTypeRequest, opts ...gax.CallOption) (*computepb.DiskType, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/regions/%v/diskTypes/%v", req.GetProject(), req.GetRegion(), req.GetDiskType()) + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.DiskType{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// List retrieves a list of regional disk types available to the specified project. +func (c *regionDiskTypesRESTClient) List(ctx context.Context, req *computepb.ListRegionDiskTypesRequest, opts ...gax.CallOption) (*computepb.RegionDiskTypeList, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/regions/%v/diskTypes", req.GetProject(), req.GetRegion()) + + params := url.Values{} + if req != nil && req.Filter != nil { + params.Add("filter", fmt.Sprintf("%v", req.GetFilter())) + } + if req != nil && req.MaxResults != nil { + params.Add("maxResults", fmt.Sprintf("%v", req.GetMaxResults())) + } + if req != nil && req.OrderBy != nil { + params.Add("orderBy", fmt.Sprintf("%v", req.GetOrderBy())) + } + if req != nil && req.PageToken != nil { + params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) + } + if req != nil && req.ReturnPartialSuccess != nil { + params.Add("returnPartialSuccess", fmt.Sprintf("%v", req.GetReturnPartialSuccess())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.RegionDiskTypeList{} + + return rsp, unm.Unmarshal(buf, rsp) +} diff --git a/compute/apiv1/region_disk_types_client_example_test.go b/compute/apiv1/region_disk_types_client_example_test.go new file mode 100644 index 00000000000..a7d34452891 --- /dev/null +++ b/compute/apiv1/region_disk_types_client_example_test.go @@ -0,0 +1,74 @@ +// 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 compute_test + +import ( + "context" + + compute "cloud.google.com/go/compute/apiv1" + computepb "google.golang.org/genproto/googleapis/cloud/compute/v1" +) + +func ExampleNewRegionDiskTypesRESTClient() { + ctx := context.Background() + c, err := compute.NewRegionDiskTypesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + // TODO: Use client. + _ = c +} + +func ExampleRegionDiskTypesClient_Get() { + ctx := context.Background() + c, err := compute.NewRegionDiskTypesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.GetRegionDiskTypeRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Get(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleRegionDiskTypesClient_List() { + ctx := context.Background() + c, err := compute.NewRegionDiskTypesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.ListRegionDiskTypesRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.List(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} diff --git a/compute/apiv1/region_disks_client.go b/compute/apiv1/region_disks_client.go new file mode 100644 index 00000000000..5707403df02 --- /dev/null +++ b/compute/apiv1/region_disks_client.go @@ -0,0 +1,832 @@ +// 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 compute + +import ( + "bytes" + "context" + "fmt" + "io/ioutil" + "net/http" + "net/url" + + gax "github.com/googleapis/gax-go/v2" + "google.golang.org/api/option" + "google.golang.org/api/option/internaloption" + httptransport "google.golang.org/api/transport/http" + computepb "google.golang.org/genproto/googleapis/cloud/compute/v1" + "google.golang.org/grpc" + "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/encoding/protojson" +) + +var newRegionDisksClientHook clientHook + +// RegionDisksCallOptions contains the retry settings for each method of RegionDisksClient. +type RegionDisksCallOptions struct { + AddResourcePolicies []gax.CallOption + CreateSnapshot []gax.CallOption + Delete []gax.CallOption + Get []gax.CallOption + GetIamPolicy []gax.CallOption + Insert []gax.CallOption + List []gax.CallOption + RemoveResourcePolicies []gax.CallOption + Resize []gax.CallOption + SetIamPolicy []gax.CallOption + SetLabels []gax.CallOption + TestIamPermissions []gax.CallOption +} + +// internalRegionDisksClient is an interface that defines the methods availaible from Google Compute Engine API. +type internalRegionDisksClient interface { + Close() error + setGoogleClientInfo(...string) + Connection() *grpc.ClientConn + AddResourcePolicies(context.Context, *computepb.AddResourcePoliciesRegionDiskRequest, ...gax.CallOption) (*computepb.Operation, error) + CreateSnapshot(context.Context, *computepb.CreateSnapshotRegionDiskRequest, ...gax.CallOption) (*computepb.Operation, error) + Delete(context.Context, *computepb.DeleteRegionDiskRequest, ...gax.CallOption) (*computepb.Operation, error) + Get(context.Context, *computepb.GetRegionDiskRequest, ...gax.CallOption) (*computepb.Disk, error) + GetIamPolicy(context.Context, *computepb.GetIamPolicyRegionDiskRequest, ...gax.CallOption) (*computepb.Policy, error) + Insert(context.Context, *computepb.InsertRegionDiskRequest, ...gax.CallOption) (*computepb.Operation, error) + List(context.Context, *computepb.ListRegionDisksRequest, ...gax.CallOption) (*computepb.DiskList, error) + RemoveResourcePolicies(context.Context, *computepb.RemoveResourcePoliciesRegionDiskRequest, ...gax.CallOption) (*computepb.Operation, error) + Resize(context.Context, *computepb.ResizeRegionDiskRequest, ...gax.CallOption) (*computepb.Operation, error) + SetIamPolicy(context.Context, *computepb.SetIamPolicyRegionDiskRequest, ...gax.CallOption) (*computepb.Policy, error) + SetLabels(context.Context, *computepb.SetLabelsRegionDiskRequest, ...gax.CallOption) (*computepb.Operation, error) + TestIamPermissions(context.Context, *computepb.TestIamPermissionsRegionDiskRequest, ...gax.CallOption) (*computepb.TestPermissionsResponse, error) +} + +// RegionDisksClient is a client for interacting with Google Compute Engine API. +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +// +// The RegionDisks API. +type RegionDisksClient struct { + // The internal transport-dependent client. + internalClient internalRegionDisksClient + + // The call options for this service. + CallOptions *RegionDisksCallOptions +} + +// 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 *RegionDisksClient) 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 *RegionDisksClient) setGoogleClientInfo(keyval ...string) { + c.internalClient.setGoogleClientInfo(keyval...) +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *RegionDisksClient) Connection() *grpc.ClientConn { + return c.internalClient.Connection() +} + +// AddResourcePolicies adds existing resource policies to a regional disk. You can only add one policy which will be applied to this disk for scheduling snapshot creation. +func (c *RegionDisksClient) AddResourcePolicies(ctx context.Context, req *computepb.AddResourcePoliciesRegionDiskRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.AddResourcePolicies(ctx, req, opts...) +} + +// CreateSnapshot creates a snapshot of this regional disk. +func (c *RegionDisksClient) CreateSnapshot(ctx context.Context, req *computepb.CreateSnapshotRegionDiskRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.CreateSnapshot(ctx, req, opts...) +} + +// Delete deletes the specified regional persistent disk. Deleting a regional disk removes all the replicas of its data permanently and is irreversible. However, deleting a disk does not delete any snapshots previously made from the disk. You must separately delete snapshots. +func (c *RegionDisksClient) Delete(ctx context.Context, req *computepb.DeleteRegionDiskRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.Delete(ctx, req, opts...) +} + +// Get returns a specified regional persistent disk. +func (c *RegionDisksClient) Get(ctx context.Context, req *computepb.GetRegionDiskRequest, opts ...gax.CallOption) (*computepb.Disk, error) { + return c.internalClient.Get(ctx, req, opts...) +} + +// GetIamPolicy gets the access control policy for a resource. May be empty if no such policy or resource exists. +func (c *RegionDisksClient) GetIamPolicy(ctx context.Context, req *computepb.GetIamPolicyRegionDiskRequest, opts ...gax.CallOption) (*computepb.Policy, error) { + return c.internalClient.GetIamPolicy(ctx, req, opts...) +} + +// Insert creates a persistent regional disk in the specified project using the data included in the request. +func (c *RegionDisksClient) Insert(ctx context.Context, req *computepb.InsertRegionDiskRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.Insert(ctx, req, opts...) +} + +// List retrieves the list of persistent disks contained within the specified region. +func (c *RegionDisksClient) List(ctx context.Context, req *computepb.ListRegionDisksRequest, opts ...gax.CallOption) (*computepb.DiskList, error) { + return c.internalClient.List(ctx, req, opts...) +} + +// RemoveResourcePolicies removes resource policies from a regional disk. +func (c *RegionDisksClient) RemoveResourcePolicies(ctx context.Context, req *computepb.RemoveResourcePoliciesRegionDiskRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.RemoveResourcePolicies(ctx, req, opts...) +} + +// Resize resizes the specified regional persistent disk. +func (c *RegionDisksClient) Resize(ctx context.Context, req *computepb.ResizeRegionDiskRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.Resize(ctx, req, opts...) +} + +// SetIamPolicy sets the access control policy on the specified resource. Replaces any existing policy. +func (c *RegionDisksClient) SetIamPolicy(ctx context.Context, req *computepb.SetIamPolicyRegionDiskRequest, opts ...gax.CallOption) (*computepb.Policy, error) { + return c.internalClient.SetIamPolicy(ctx, req, opts...) +} + +// SetLabels sets the labels on the target regional disk. +func (c *RegionDisksClient) SetLabels(ctx context.Context, req *computepb.SetLabelsRegionDiskRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.SetLabels(ctx, req, opts...) +} + +// TestIamPermissions returns permissions that a caller has on the specified resource. +func (c *RegionDisksClient) TestIamPermissions(ctx context.Context, req *computepb.TestIamPermissionsRegionDiskRequest, opts ...gax.CallOption) (*computepb.TestPermissionsResponse, error) { + return c.internalClient.TestIamPermissions(ctx, req, opts...) +} + +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +type regionDisksRESTClient struct { + // The http endpoint to connect to. + endpoint string + + // The http client. + httpClient *http.Client + + // The x-goog-* metadata to be sent with each request. + xGoogMetadata metadata.MD +} + +// NewRegionDisksRESTClient creates a new region disks rest client. +// +// The RegionDisks API. +func NewRegionDisksRESTClient(ctx context.Context, opts ...option.ClientOption) (*RegionDisksClient, error) { + clientOpts := append(defaultRegionDisksRESTClientOptions(), opts...) + httpClient, endpoint, err := httptransport.NewClient(ctx, clientOpts...) + if err != nil { + return nil, err + } + + c := ®ionDisksRESTClient{ + endpoint: endpoint, + httpClient: httpClient, + } + c.setGoogleClientInfo() + + return &RegionDisksClient{internalClient: c, CallOptions: &RegionDisksCallOptions{}}, nil +} + +func defaultRegionDisksRESTClientOptions() []option.ClientOption { + return []option.ClientOption{ + internaloption.WithDefaultEndpoint("compute.googleapis.com"), + internaloption.WithDefaultMTLSEndpoint("compute.mtls.googleapis.com"), + internaloption.WithDefaultAudience("https://compute.googleapis.com/"), + internaloption.WithDefaultScopes(DefaultAuthScopes()...), + } +} + +// 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 *regionDisksRESTClient) setGoogleClientInfo(keyval ...string) { + kv := append([]string{"gl-go", versionGo()}, keyval...) + kv = append(kv, "gapic", versionClient, "gax", gax.Version, "rest", "UNKNOWN") + 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 *regionDisksRESTClient) Close() error { + // Replace httpClient with nil to force cleanup. + c.httpClient = nil + return nil +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *regionDisksRESTClient) Connection() *grpc.ClientConn { + return nil +} + +// AddResourcePolicies adds existing resource policies to a regional disk. You can only add one policy which will be applied to this disk for scheduling snapshot creation. +func (c *regionDisksRESTClient) AddResourcePolicies(ctx context.Context, req *computepb.AddResourcePoliciesRegionDiskRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetRegionDisksAddResourcePoliciesRequestResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/regions/%v/disks/%v/addResourcePolicies", req.GetProject(), req.GetRegion(), req.GetDisk()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// CreateSnapshot creates a snapshot of this regional disk. +func (c *regionDisksRESTClient) CreateSnapshot(ctx context.Context, req *computepb.CreateSnapshotRegionDiskRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetSnapshotResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/regions/%v/disks/%v/createSnapshot", req.GetProject(), req.GetRegion(), req.GetDisk()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Delete deletes the specified regional persistent disk. Deleting a regional disk removes all the replicas of its data permanently and is irreversible. However, deleting a disk does not delete any snapshots previously made from the disk. You must separately delete snapshots. +func (c *regionDisksRESTClient) Delete(ctx context.Context, req *computepb.DeleteRegionDiskRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/regions/%v/disks/%v", req.GetProject(), req.GetRegion(), req.GetDisk()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("DELETE", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Get returns a specified regional persistent disk. +func (c *regionDisksRESTClient) Get(ctx context.Context, req *computepb.GetRegionDiskRequest, opts ...gax.CallOption) (*computepb.Disk, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/regions/%v/disks/%v", req.GetProject(), req.GetRegion(), req.GetDisk()) + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Disk{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// GetIamPolicy gets the access control policy for a resource. May be empty if no such policy or resource exists. +func (c *regionDisksRESTClient) GetIamPolicy(ctx context.Context, req *computepb.GetIamPolicyRegionDiskRequest, opts ...gax.CallOption) (*computepb.Policy, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/regions/%v/disks/%v/getIamPolicy", req.GetProject(), req.GetRegion(), req.GetResource()) + + params := url.Values{} + if req != nil && req.OptionsRequestedPolicyVersion != nil { + params.Add("optionsRequestedPolicyVersion", fmt.Sprintf("%v", req.GetOptionsRequestedPolicyVersion())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Policy{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Insert creates a persistent regional disk in the specified project using the data included in the request. +func (c *regionDisksRESTClient) Insert(ctx context.Context, req *computepb.InsertRegionDiskRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetDiskResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/regions/%v/disks", req.GetProject(), req.GetRegion()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + if req != nil && req.SourceImage != nil { + params.Add("sourceImage", fmt.Sprintf("%v", req.GetSourceImage())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// List retrieves the list of persistent disks contained within the specified region. +func (c *regionDisksRESTClient) List(ctx context.Context, req *computepb.ListRegionDisksRequest, opts ...gax.CallOption) (*computepb.DiskList, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/regions/%v/disks", req.GetProject(), req.GetRegion()) + + params := url.Values{} + if req != nil && req.Filter != nil { + params.Add("filter", fmt.Sprintf("%v", req.GetFilter())) + } + if req != nil && req.MaxResults != nil { + params.Add("maxResults", fmt.Sprintf("%v", req.GetMaxResults())) + } + if req != nil && req.OrderBy != nil { + params.Add("orderBy", fmt.Sprintf("%v", req.GetOrderBy())) + } + if req != nil && req.PageToken != nil { + params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) + } + if req != nil && req.ReturnPartialSuccess != nil { + params.Add("returnPartialSuccess", fmt.Sprintf("%v", req.GetReturnPartialSuccess())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.DiskList{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// RemoveResourcePolicies removes resource policies from a regional disk. +func (c *regionDisksRESTClient) RemoveResourcePolicies(ctx context.Context, req *computepb.RemoveResourcePoliciesRegionDiskRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetRegionDisksRemoveResourcePoliciesRequestResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/regions/%v/disks/%v/removeResourcePolicies", req.GetProject(), req.GetRegion(), req.GetDisk()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Resize resizes the specified regional persistent disk. +func (c *regionDisksRESTClient) Resize(ctx context.Context, req *computepb.ResizeRegionDiskRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetRegionDisksResizeRequestResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/regions/%v/disks/%v/resize", req.GetProject(), req.GetRegion(), req.GetDisk()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// SetIamPolicy sets the access control policy on the specified resource. Replaces any existing policy. +func (c *regionDisksRESTClient) SetIamPolicy(ctx context.Context, req *computepb.SetIamPolicyRegionDiskRequest, opts ...gax.CallOption) (*computepb.Policy, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetRegionSetPolicyRequestResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/regions/%v/disks/%v/setIamPolicy", req.GetProject(), req.GetRegion(), req.GetResource()) + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Policy{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// SetLabels sets the labels on the target regional disk. +func (c *regionDisksRESTClient) SetLabels(ctx context.Context, req *computepb.SetLabelsRegionDiskRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetRegionSetLabelsRequestResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/regions/%v/disks/%v/setLabels", req.GetProject(), req.GetRegion(), req.GetResource()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// TestIamPermissions returns permissions that a caller has on the specified resource. +func (c *regionDisksRESTClient) TestIamPermissions(ctx context.Context, req *computepb.TestIamPermissionsRegionDiskRequest, opts ...gax.CallOption) (*computepb.TestPermissionsResponse, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetTestPermissionsRequestResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/regions/%v/disks/%v/testIamPermissions", req.GetProject(), req.GetRegion(), req.GetResource()) + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.TestPermissionsResponse{} + + return rsp, unm.Unmarshal(buf, rsp) +} diff --git a/compute/apiv1/region_disks_client_example_test.go b/compute/apiv1/region_disks_client_example_test.go new file mode 100644 index 00000000000..fbef3946358 --- /dev/null +++ b/compute/apiv1/region_disks_client_example_test.go @@ -0,0 +1,264 @@ +// 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 compute_test + +import ( + "context" + + compute "cloud.google.com/go/compute/apiv1" + computepb "google.golang.org/genproto/googleapis/cloud/compute/v1" +) + +func ExampleNewRegionDisksRESTClient() { + ctx := context.Background() + c, err := compute.NewRegionDisksRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + // TODO: Use client. + _ = c +} + +func ExampleRegionDisksClient_AddResourcePolicies() { + ctx := context.Background() + c, err := compute.NewRegionDisksRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.AddResourcePoliciesRegionDiskRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.AddResourcePolicies(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleRegionDisksClient_CreateSnapshot() { + ctx := context.Background() + c, err := compute.NewRegionDisksRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.CreateSnapshotRegionDiskRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.CreateSnapshot(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleRegionDisksClient_Delete() { + ctx := context.Background() + c, err := compute.NewRegionDisksRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.DeleteRegionDiskRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Delete(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleRegionDisksClient_Get() { + ctx := context.Background() + c, err := compute.NewRegionDisksRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.GetRegionDiskRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Get(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleRegionDisksClient_GetIamPolicy() { + ctx := context.Background() + c, err := compute.NewRegionDisksRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.GetIamPolicyRegionDiskRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.GetIamPolicy(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleRegionDisksClient_Insert() { + ctx := context.Background() + c, err := compute.NewRegionDisksRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.InsertRegionDiskRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Insert(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleRegionDisksClient_List() { + ctx := context.Background() + c, err := compute.NewRegionDisksRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.ListRegionDisksRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.List(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleRegionDisksClient_RemoveResourcePolicies() { + ctx := context.Background() + c, err := compute.NewRegionDisksRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.RemoveResourcePoliciesRegionDiskRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.RemoveResourcePolicies(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleRegionDisksClient_Resize() { + ctx := context.Background() + c, err := compute.NewRegionDisksRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.ResizeRegionDiskRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Resize(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleRegionDisksClient_SetIamPolicy() { + ctx := context.Background() + c, err := compute.NewRegionDisksRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.SetIamPolicyRegionDiskRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.SetIamPolicy(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleRegionDisksClient_SetLabels() { + ctx := context.Background() + c, err := compute.NewRegionDisksRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.SetLabelsRegionDiskRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.SetLabels(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleRegionDisksClient_TestIamPermissions() { + ctx := context.Background() + c, err := compute.NewRegionDisksRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.TestIamPermissionsRegionDiskRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.TestIamPermissions(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} diff --git a/compute/apiv1/region_health_check_services_client.go b/compute/apiv1/region_health_check_services_client.go new file mode 100644 index 00000000000..7e7ece75de3 --- /dev/null +++ b/compute/apiv1/region_health_check_services_client.go @@ -0,0 +1,438 @@ +// 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 compute + +import ( + "bytes" + "context" + "fmt" + "io/ioutil" + "net/http" + "net/url" + + gax "github.com/googleapis/gax-go/v2" + "google.golang.org/api/option" + "google.golang.org/api/option/internaloption" + httptransport "google.golang.org/api/transport/http" + computepb "google.golang.org/genproto/googleapis/cloud/compute/v1" + "google.golang.org/grpc" + "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/encoding/protojson" +) + +var newRegionHealthCheckServicesClientHook clientHook + +// RegionHealthCheckServicesCallOptions contains the retry settings for each method of RegionHealthCheckServicesClient. +type RegionHealthCheckServicesCallOptions struct { + Delete []gax.CallOption + Get []gax.CallOption + Insert []gax.CallOption + List []gax.CallOption + Patch []gax.CallOption +} + +// internalRegionHealthCheckServicesClient is an interface that defines the methods availaible from Google Compute Engine API. +type internalRegionHealthCheckServicesClient interface { + Close() error + setGoogleClientInfo(...string) + Connection() *grpc.ClientConn + Delete(context.Context, *computepb.DeleteRegionHealthCheckServiceRequest, ...gax.CallOption) (*computepb.Operation, error) + Get(context.Context, *computepb.GetRegionHealthCheckServiceRequest, ...gax.CallOption) (*computepb.HealthCheckService, error) + Insert(context.Context, *computepb.InsertRegionHealthCheckServiceRequest, ...gax.CallOption) (*computepb.Operation, error) + List(context.Context, *computepb.ListRegionHealthCheckServicesRequest, ...gax.CallOption) (*computepb.HealthCheckServicesList, error) + Patch(context.Context, *computepb.PatchRegionHealthCheckServiceRequest, ...gax.CallOption) (*computepb.Operation, error) +} + +// RegionHealthCheckServicesClient is a client for interacting with Google Compute Engine API. +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +// +// The RegionHealthCheckServices API. +type RegionHealthCheckServicesClient struct { + // The internal transport-dependent client. + internalClient internalRegionHealthCheckServicesClient + + // The call options for this service. + CallOptions *RegionHealthCheckServicesCallOptions +} + +// 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 *RegionHealthCheckServicesClient) 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 *RegionHealthCheckServicesClient) setGoogleClientInfo(keyval ...string) { + c.internalClient.setGoogleClientInfo(keyval...) +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *RegionHealthCheckServicesClient) Connection() *grpc.ClientConn { + return c.internalClient.Connection() +} + +// Delete deletes the specified regional HealthCheckService. +func (c *RegionHealthCheckServicesClient) Delete(ctx context.Context, req *computepb.DeleteRegionHealthCheckServiceRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.Delete(ctx, req, opts...) +} + +// Get returns the specified regional HealthCheckService resource. +func (c *RegionHealthCheckServicesClient) Get(ctx context.Context, req *computepb.GetRegionHealthCheckServiceRequest, opts ...gax.CallOption) (*computepb.HealthCheckService, error) { + return c.internalClient.Get(ctx, req, opts...) +} + +// Insert creates a regional HealthCheckService resource in the specified project and region using the data included in the request. +func (c *RegionHealthCheckServicesClient) Insert(ctx context.Context, req *computepb.InsertRegionHealthCheckServiceRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.Insert(ctx, req, opts...) +} + +// List lists all the HealthCheckService resources that have been configured for the specified project in the given region. +func (c *RegionHealthCheckServicesClient) List(ctx context.Context, req *computepb.ListRegionHealthCheckServicesRequest, opts ...gax.CallOption) (*computepb.HealthCheckServicesList, error) { + return c.internalClient.List(ctx, req, opts...) +} + +// Patch updates the specified regional HealthCheckService resource with the data included in the request. This method supports PATCH semantics and uses the JSON merge patch format and processing rules. +func (c *RegionHealthCheckServicesClient) Patch(ctx context.Context, req *computepb.PatchRegionHealthCheckServiceRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.Patch(ctx, req, opts...) +} + +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +type regionHealthCheckServicesRESTClient struct { + // The http endpoint to connect to. + endpoint string + + // The http client. + httpClient *http.Client + + // The x-goog-* metadata to be sent with each request. + xGoogMetadata metadata.MD +} + +// NewRegionHealthCheckServicesRESTClient creates a new region health check services rest client. +// +// The RegionHealthCheckServices API. +func NewRegionHealthCheckServicesRESTClient(ctx context.Context, opts ...option.ClientOption) (*RegionHealthCheckServicesClient, error) { + clientOpts := append(defaultRegionHealthCheckServicesRESTClientOptions(), opts...) + httpClient, endpoint, err := httptransport.NewClient(ctx, clientOpts...) + if err != nil { + return nil, err + } + + c := ®ionHealthCheckServicesRESTClient{ + endpoint: endpoint, + httpClient: httpClient, + } + c.setGoogleClientInfo() + + return &RegionHealthCheckServicesClient{internalClient: c, CallOptions: &RegionHealthCheckServicesCallOptions{}}, nil +} + +func defaultRegionHealthCheckServicesRESTClientOptions() []option.ClientOption { + return []option.ClientOption{ + internaloption.WithDefaultEndpoint("compute.googleapis.com"), + internaloption.WithDefaultMTLSEndpoint("compute.mtls.googleapis.com"), + internaloption.WithDefaultAudience("https://compute.googleapis.com/"), + internaloption.WithDefaultScopes(DefaultAuthScopes()...), + } +} + +// 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 *regionHealthCheckServicesRESTClient) setGoogleClientInfo(keyval ...string) { + kv := append([]string{"gl-go", versionGo()}, keyval...) + kv = append(kv, "gapic", versionClient, "gax", gax.Version, "rest", "UNKNOWN") + 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 *regionHealthCheckServicesRESTClient) Close() error { + // Replace httpClient with nil to force cleanup. + c.httpClient = nil + return nil +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *regionHealthCheckServicesRESTClient) Connection() *grpc.ClientConn { + return nil +} + +// Delete deletes the specified regional HealthCheckService. +func (c *regionHealthCheckServicesRESTClient) Delete(ctx context.Context, req *computepb.DeleteRegionHealthCheckServiceRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/regions/%v/healthCheckServices/%v", req.GetProject(), req.GetRegion(), req.GetHealthCheckService()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("DELETE", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Get returns the specified regional HealthCheckService resource. +func (c *regionHealthCheckServicesRESTClient) Get(ctx context.Context, req *computepb.GetRegionHealthCheckServiceRequest, opts ...gax.CallOption) (*computepb.HealthCheckService, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/regions/%v/healthCheckServices/%v", req.GetProject(), req.GetRegion(), req.GetHealthCheckService()) + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.HealthCheckService{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Insert creates a regional HealthCheckService resource in the specified project and region using the data included in the request. +func (c *regionHealthCheckServicesRESTClient) Insert(ctx context.Context, req *computepb.InsertRegionHealthCheckServiceRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetHealthCheckServiceResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/regions/%v/healthCheckServices", req.GetProject(), req.GetRegion()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// List lists all the HealthCheckService resources that have been configured for the specified project in the given region. +func (c *regionHealthCheckServicesRESTClient) List(ctx context.Context, req *computepb.ListRegionHealthCheckServicesRequest, opts ...gax.CallOption) (*computepb.HealthCheckServicesList, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/regions/%v/healthCheckServices", req.GetProject(), req.GetRegion()) + + params := url.Values{} + if req != nil && req.Filter != nil { + params.Add("filter", fmt.Sprintf("%v", req.GetFilter())) + } + if req != nil && req.MaxResults != nil { + params.Add("maxResults", fmt.Sprintf("%v", req.GetMaxResults())) + } + if req != nil && req.OrderBy != nil { + params.Add("orderBy", fmt.Sprintf("%v", req.GetOrderBy())) + } + if req != nil && req.PageToken != nil { + params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) + } + if req != nil && req.ReturnPartialSuccess != nil { + params.Add("returnPartialSuccess", fmt.Sprintf("%v", req.GetReturnPartialSuccess())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.HealthCheckServicesList{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Patch updates the specified regional HealthCheckService resource with the data included in the request. This method supports PATCH semantics and uses the JSON merge patch format and processing rules. +func (c *regionHealthCheckServicesRESTClient) Patch(ctx context.Context, req *computepb.PatchRegionHealthCheckServiceRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetHealthCheckServiceResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/regions/%v/healthCheckServices/%v", req.GetProject(), req.GetRegion(), req.GetHealthCheckService()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("PATCH", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} diff --git a/compute/apiv1/region_health_check_services_client_example_test.go b/compute/apiv1/region_health_check_services_client_example_test.go new file mode 100644 index 00000000000..bbaf17d8152 --- /dev/null +++ b/compute/apiv1/region_health_check_services_client_example_test.go @@ -0,0 +1,131 @@ +// 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 compute_test + +import ( + "context" + + compute "cloud.google.com/go/compute/apiv1" + computepb "google.golang.org/genproto/googleapis/cloud/compute/v1" +) + +func ExampleNewRegionHealthCheckServicesRESTClient() { + ctx := context.Background() + c, err := compute.NewRegionHealthCheckServicesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + // TODO: Use client. + _ = c +} + +func ExampleRegionHealthCheckServicesClient_Delete() { + ctx := context.Background() + c, err := compute.NewRegionHealthCheckServicesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.DeleteRegionHealthCheckServiceRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Delete(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleRegionHealthCheckServicesClient_Get() { + ctx := context.Background() + c, err := compute.NewRegionHealthCheckServicesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.GetRegionHealthCheckServiceRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Get(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleRegionHealthCheckServicesClient_Insert() { + ctx := context.Background() + c, err := compute.NewRegionHealthCheckServicesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.InsertRegionHealthCheckServiceRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Insert(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleRegionHealthCheckServicesClient_List() { + ctx := context.Background() + c, err := compute.NewRegionHealthCheckServicesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.ListRegionHealthCheckServicesRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.List(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleRegionHealthCheckServicesClient_Patch() { + ctx := context.Background() + c, err := compute.NewRegionHealthCheckServicesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.PatchRegionHealthCheckServiceRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Patch(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} diff --git a/compute/apiv1/region_health_checks_client.go b/compute/apiv1/region_health_checks_client.go new file mode 100644 index 00000000000..18afaa3dbb3 --- /dev/null +++ b/compute/apiv1/region_health_checks_client.go @@ -0,0 +1,505 @@ +// 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 compute + +import ( + "bytes" + "context" + "fmt" + "io/ioutil" + "net/http" + "net/url" + + gax "github.com/googleapis/gax-go/v2" + "google.golang.org/api/option" + "google.golang.org/api/option/internaloption" + httptransport "google.golang.org/api/transport/http" + computepb "google.golang.org/genproto/googleapis/cloud/compute/v1" + "google.golang.org/grpc" + "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/encoding/protojson" +) + +var newRegionHealthChecksClientHook clientHook + +// RegionHealthChecksCallOptions contains the retry settings for each method of RegionHealthChecksClient. +type RegionHealthChecksCallOptions struct { + Delete []gax.CallOption + Get []gax.CallOption + Insert []gax.CallOption + List []gax.CallOption + Patch []gax.CallOption + Update []gax.CallOption +} + +// internalRegionHealthChecksClient is an interface that defines the methods availaible from Google Compute Engine API. +type internalRegionHealthChecksClient interface { + Close() error + setGoogleClientInfo(...string) + Connection() *grpc.ClientConn + Delete(context.Context, *computepb.DeleteRegionHealthCheckRequest, ...gax.CallOption) (*computepb.Operation, error) + Get(context.Context, *computepb.GetRegionHealthCheckRequest, ...gax.CallOption) (*computepb.HealthCheck, error) + Insert(context.Context, *computepb.InsertRegionHealthCheckRequest, ...gax.CallOption) (*computepb.Operation, error) + List(context.Context, *computepb.ListRegionHealthChecksRequest, ...gax.CallOption) (*computepb.HealthCheckList, error) + Patch(context.Context, *computepb.PatchRegionHealthCheckRequest, ...gax.CallOption) (*computepb.Operation, error) + Update(context.Context, *computepb.UpdateRegionHealthCheckRequest, ...gax.CallOption) (*computepb.Operation, error) +} + +// RegionHealthChecksClient is a client for interacting with Google Compute Engine API. +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +// +// The RegionHealthChecks API. +type RegionHealthChecksClient struct { + // The internal transport-dependent client. + internalClient internalRegionHealthChecksClient + + // The call options for this service. + CallOptions *RegionHealthChecksCallOptions +} + +// 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 *RegionHealthChecksClient) 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 *RegionHealthChecksClient) setGoogleClientInfo(keyval ...string) { + c.internalClient.setGoogleClientInfo(keyval...) +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *RegionHealthChecksClient) Connection() *grpc.ClientConn { + return c.internalClient.Connection() +} + +// Delete deletes the specified HealthCheck resource. +func (c *RegionHealthChecksClient) Delete(ctx context.Context, req *computepb.DeleteRegionHealthCheckRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.Delete(ctx, req, opts...) +} + +// Get returns the specified HealthCheck resource. Gets a list of available health checks by making a list() request. +func (c *RegionHealthChecksClient) Get(ctx context.Context, req *computepb.GetRegionHealthCheckRequest, opts ...gax.CallOption) (*computepb.HealthCheck, error) { + return c.internalClient.Get(ctx, req, opts...) +} + +// Insert creates a HealthCheck resource in the specified project using the data included in the request. +func (c *RegionHealthChecksClient) Insert(ctx context.Context, req *computepb.InsertRegionHealthCheckRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.Insert(ctx, req, opts...) +} + +// List retrieves the list of HealthCheck resources available to the specified project. +func (c *RegionHealthChecksClient) List(ctx context.Context, req *computepb.ListRegionHealthChecksRequest, opts ...gax.CallOption) (*computepb.HealthCheckList, error) { + return c.internalClient.List(ctx, req, opts...) +} + +// Patch updates a HealthCheck resource in the specified project using the data included in the request. This method supports PATCH semantics and uses the JSON merge patch format and processing rules. +func (c *RegionHealthChecksClient) Patch(ctx context.Context, req *computepb.PatchRegionHealthCheckRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.Patch(ctx, req, opts...) +} + +// Update updates a HealthCheck resource in the specified project using the data included in the request. +func (c *RegionHealthChecksClient) Update(ctx context.Context, req *computepb.UpdateRegionHealthCheckRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.Update(ctx, req, opts...) +} + +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +type regionHealthChecksRESTClient struct { + // The http endpoint to connect to. + endpoint string + + // The http client. + httpClient *http.Client + + // The x-goog-* metadata to be sent with each request. + xGoogMetadata metadata.MD +} + +// NewRegionHealthChecksRESTClient creates a new region health checks rest client. +// +// The RegionHealthChecks API. +func NewRegionHealthChecksRESTClient(ctx context.Context, opts ...option.ClientOption) (*RegionHealthChecksClient, error) { + clientOpts := append(defaultRegionHealthChecksRESTClientOptions(), opts...) + httpClient, endpoint, err := httptransport.NewClient(ctx, clientOpts...) + if err != nil { + return nil, err + } + + c := ®ionHealthChecksRESTClient{ + endpoint: endpoint, + httpClient: httpClient, + } + c.setGoogleClientInfo() + + return &RegionHealthChecksClient{internalClient: c, CallOptions: &RegionHealthChecksCallOptions{}}, nil +} + +func defaultRegionHealthChecksRESTClientOptions() []option.ClientOption { + return []option.ClientOption{ + internaloption.WithDefaultEndpoint("compute.googleapis.com"), + internaloption.WithDefaultMTLSEndpoint("compute.mtls.googleapis.com"), + internaloption.WithDefaultAudience("https://compute.googleapis.com/"), + internaloption.WithDefaultScopes(DefaultAuthScopes()...), + } +} + +// 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 *regionHealthChecksRESTClient) setGoogleClientInfo(keyval ...string) { + kv := append([]string{"gl-go", versionGo()}, keyval...) + kv = append(kv, "gapic", versionClient, "gax", gax.Version, "rest", "UNKNOWN") + 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 *regionHealthChecksRESTClient) Close() error { + // Replace httpClient with nil to force cleanup. + c.httpClient = nil + return nil +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *regionHealthChecksRESTClient) Connection() *grpc.ClientConn { + return nil +} + +// Delete deletes the specified HealthCheck resource. +func (c *regionHealthChecksRESTClient) Delete(ctx context.Context, req *computepb.DeleteRegionHealthCheckRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/regions/%v/healthChecks/%v", req.GetProject(), req.GetRegion(), req.GetHealthCheck()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("DELETE", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Get returns the specified HealthCheck resource. Gets a list of available health checks by making a list() request. +func (c *regionHealthChecksRESTClient) Get(ctx context.Context, req *computepb.GetRegionHealthCheckRequest, opts ...gax.CallOption) (*computepb.HealthCheck, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/regions/%v/healthChecks/%v", req.GetProject(), req.GetRegion(), req.GetHealthCheck()) + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.HealthCheck{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Insert creates a HealthCheck resource in the specified project using the data included in the request. +func (c *regionHealthChecksRESTClient) Insert(ctx context.Context, req *computepb.InsertRegionHealthCheckRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetHealthCheckResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/regions/%v/healthChecks", req.GetProject(), req.GetRegion()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// List retrieves the list of HealthCheck resources available to the specified project. +func (c *regionHealthChecksRESTClient) List(ctx context.Context, req *computepb.ListRegionHealthChecksRequest, opts ...gax.CallOption) (*computepb.HealthCheckList, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/regions/%v/healthChecks", req.GetProject(), req.GetRegion()) + + params := url.Values{} + if req != nil && req.Filter != nil { + params.Add("filter", fmt.Sprintf("%v", req.GetFilter())) + } + if req != nil && req.MaxResults != nil { + params.Add("maxResults", fmt.Sprintf("%v", req.GetMaxResults())) + } + if req != nil && req.OrderBy != nil { + params.Add("orderBy", fmt.Sprintf("%v", req.GetOrderBy())) + } + if req != nil && req.PageToken != nil { + params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) + } + if req != nil && req.ReturnPartialSuccess != nil { + params.Add("returnPartialSuccess", fmt.Sprintf("%v", req.GetReturnPartialSuccess())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.HealthCheckList{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Patch updates a HealthCheck resource in the specified project using the data included in the request. This method supports PATCH semantics and uses the JSON merge patch format and processing rules. +func (c *regionHealthChecksRESTClient) Patch(ctx context.Context, req *computepb.PatchRegionHealthCheckRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetHealthCheckResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/regions/%v/healthChecks/%v", req.GetProject(), req.GetRegion(), req.GetHealthCheck()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("PATCH", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Update updates a HealthCheck resource in the specified project using the data included in the request. +func (c *regionHealthChecksRESTClient) Update(ctx context.Context, req *computepb.UpdateRegionHealthCheckRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetHealthCheckResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("") + + params := url.Values{} + if req.GetHealthCheck() != "" { + params.Add("healthCheck", fmt.Sprintf("%v", req.GetHealthCheck())) + } + if req.GetProject() != "" { + params.Add("project", fmt.Sprintf("%v", req.GetProject())) + } + if req.GetRegion() != "" { + params.Add("region", fmt.Sprintf("%v", req.GetRegion())) + } + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("PUT", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} diff --git a/compute/apiv1/region_health_checks_client_example_test.go b/compute/apiv1/region_health_checks_client_example_test.go new file mode 100644 index 00000000000..2264ab8e671 --- /dev/null +++ b/compute/apiv1/region_health_checks_client_example_test.go @@ -0,0 +1,150 @@ +// 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 compute_test + +import ( + "context" + + compute "cloud.google.com/go/compute/apiv1" + computepb "google.golang.org/genproto/googleapis/cloud/compute/v1" +) + +func ExampleNewRegionHealthChecksRESTClient() { + ctx := context.Background() + c, err := compute.NewRegionHealthChecksRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + // TODO: Use client. + _ = c +} + +func ExampleRegionHealthChecksClient_Delete() { + ctx := context.Background() + c, err := compute.NewRegionHealthChecksRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.DeleteRegionHealthCheckRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Delete(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleRegionHealthChecksClient_Get() { + ctx := context.Background() + c, err := compute.NewRegionHealthChecksRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.GetRegionHealthCheckRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Get(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleRegionHealthChecksClient_Insert() { + ctx := context.Background() + c, err := compute.NewRegionHealthChecksRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.InsertRegionHealthCheckRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Insert(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleRegionHealthChecksClient_List() { + ctx := context.Background() + c, err := compute.NewRegionHealthChecksRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.ListRegionHealthChecksRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.List(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleRegionHealthChecksClient_Patch() { + ctx := context.Background() + c, err := compute.NewRegionHealthChecksRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.PatchRegionHealthCheckRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Patch(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleRegionHealthChecksClient_Update() { + ctx := context.Background() + c, err := compute.NewRegionHealthChecksRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.UpdateRegionHealthCheckRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Update(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} diff --git a/compute/apiv1/region_instance_group_managers_client.go b/compute/apiv1/region_instance_group_managers_client.go new file mode 100644 index 00000000000..4e108c40cd9 --- /dev/null +++ b/compute/apiv1/region_instance_group_managers_client.go @@ -0,0 +1,1307 @@ +// 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 compute + +import ( + "bytes" + "context" + "fmt" + "io/ioutil" + "net/http" + "net/url" + + gax "github.com/googleapis/gax-go/v2" + "google.golang.org/api/option" + "google.golang.org/api/option/internaloption" + httptransport "google.golang.org/api/transport/http" + computepb "google.golang.org/genproto/googleapis/cloud/compute/v1" + "google.golang.org/grpc" + "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/encoding/protojson" +) + +var newRegionInstanceGroupManagersClientHook clientHook + +// RegionInstanceGroupManagersCallOptions contains the retry settings for each method of RegionInstanceGroupManagersClient. +type RegionInstanceGroupManagersCallOptions struct { + AbandonInstances []gax.CallOption + ApplyUpdatesToInstances []gax.CallOption + CreateInstances []gax.CallOption + Delete []gax.CallOption + DeleteInstances []gax.CallOption + DeletePerInstanceConfigs []gax.CallOption + Get []gax.CallOption + Insert []gax.CallOption + List []gax.CallOption + ListErrors []gax.CallOption + ListManagedInstances []gax.CallOption + ListPerInstanceConfigs []gax.CallOption + Patch []gax.CallOption + PatchPerInstanceConfigs []gax.CallOption + RecreateInstances []gax.CallOption + Resize []gax.CallOption + SetInstanceTemplate []gax.CallOption + SetTargetPools []gax.CallOption + UpdatePerInstanceConfigs []gax.CallOption +} + +// internalRegionInstanceGroupManagersClient is an interface that defines the methods availaible from Google Compute Engine API. +type internalRegionInstanceGroupManagersClient interface { + Close() error + setGoogleClientInfo(...string) + Connection() *grpc.ClientConn + AbandonInstances(context.Context, *computepb.AbandonInstancesRegionInstanceGroupManagerRequest, ...gax.CallOption) (*computepb.Operation, error) + ApplyUpdatesToInstances(context.Context, *computepb.ApplyUpdatesToInstancesRegionInstanceGroupManagerRequest, ...gax.CallOption) (*computepb.Operation, error) + CreateInstances(context.Context, *computepb.CreateInstancesRegionInstanceGroupManagerRequest, ...gax.CallOption) (*computepb.Operation, error) + Delete(context.Context, *computepb.DeleteRegionInstanceGroupManagerRequest, ...gax.CallOption) (*computepb.Operation, error) + DeleteInstances(context.Context, *computepb.DeleteInstancesRegionInstanceGroupManagerRequest, ...gax.CallOption) (*computepb.Operation, error) + DeletePerInstanceConfigs(context.Context, *computepb.DeletePerInstanceConfigsRegionInstanceGroupManagerRequest, ...gax.CallOption) (*computepb.Operation, error) + Get(context.Context, *computepb.GetRegionInstanceGroupManagerRequest, ...gax.CallOption) (*computepb.InstanceGroupManager, error) + Insert(context.Context, *computepb.InsertRegionInstanceGroupManagerRequest, ...gax.CallOption) (*computepb.Operation, error) + List(context.Context, *computepb.ListRegionInstanceGroupManagersRequest, ...gax.CallOption) (*computepb.RegionInstanceGroupManagerList, error) + ListErrors(context.Context, *computepb.ListErrorsRegionInstanceGroupManagersRequest, ...gax.CallOption) (*computepb.RegionInstanceGroupManagersListErrorsResponse, error) + ListManagedInstances(context.Context, *computepb.ListManagedInstancesRegionInstanceGroupManagersRequest, ...gax.CallOption) (*computepb.RegionInstanceGroupManagersListInstancesResponse, error) + ListPerInstanceConfigs(context.Context, *computepb.ListPerInstanceConfigsRegionInstanceGroupManagersRequest, ...gax.CallOption) (*computepb.RegionInstanceGroupManagersListInstanceConfigsResp, error) + Patch(context.Context, *computepb.PatchRegionInstanceGroupManagerRequest, ...gax.CallOption) (*computepb.Operation, error) + PatchPerInstanceConfigs(context.Context, *computepb.PatchPerInstanceConfigsRegionInstanceGroupManagerRequest, ...gax.CallOption) (*computepb.Operation, error) + RecreateInstances(context.Context, *computepb.RecreateInstancesRegionInstanceGroupManagerRequest, ...gax.CallOption) (*computepb.Operation, error) + Resize(context.Context, *computepb.ResizeRegionInstanceGroupManagerRequest, ...gax.CallOption) (*computepb.Operation, error) + SetInstanceTemplate(context.Context, *computepb.SetInstanceTemplateRegionInstanceGroupManagerRequest, ...gax.CallOption) (*computepb.Operation, error) + SetTargetPools(context.Context, *computepb.SetTargetPoolsRegionInstanceGroupManagerRequest, ...gax.CallOption) (*computepb.Operation, error) + UpdatePerInstanceConfigs(context.Context, *computepb.UpdatePerInstanceConfigsRegionInstanceGroupManagerRequest, ...gax.CallOption) (*computepb.Operation, error) +} + +// RegionInstanceGroupManagersClient is a client for interacting with Google Compute Engine API. +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +// +// The RegionInstanceGroupManagers API. +type RegionInstanceGroupManagersClient struct { + // The internal transport-dependent client. + internalClient internalRegionInstanceGroupManagersClient + + // The call options for this service. + CallOptions *RegionInstanceGroupManagersCallOptions +} + +// 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 *RegionInstanceGroupManagersClient) 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 *RegionInstanceGroupManagersClient) setGoogleClientInfo(keyval ...string) { + c.internalClient.setGoogleClientInfo(keyval...) +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *RegionInstanceGroupManagersClient) Connection() *grpc.ClientConn { + return c.internalClient.Connection() +} + +// AbandonInstances flags the specified instances to be immediately removed from the managed instance group. Abandoning an instance does not delete the instance, but it does remove the instance from any target pools that are applied by the managed instance group. This method reduces the targetSize of the managed instance group by the number of instances that you abandon. This operation is marked as DONE when the action is scheduled even if the instances have not yet been removed from the group. You must separately verify the status of the abandoning action with the listmanagedinstances method. +// +// If the group is part of a backend service that has enabled connection draining, it can take up to 60 seconds after the connection draining duration has elapsed before the VM instance is removed or deleted. +// +// You can specify a maximum of 1000 instances with this method per request. +func (c *RegionInstanceGroupManagersClient) AbandonInstances(ctx context.Context, req *computepb.AbandonInstancesRegionInstanceGroupManagerRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.AbandonInstances(ctx, req, opts...) +} + +// ApplyUpdatesToInstances apply updates to selected instances the managed instance group. +func (c *RegionInstanceGroupManagersClient) ApplyUpdatesToInstances(ctx context.Context, req *computepb.ApplyUpdatesToInstancesRegionInstanceGroupManagerRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.ApplyUpdatesToInstances(ctx, req, opts...) +} + +// CreateInstances creates instances with per-instance configs in this regional managed instance group. Instances are created using the current instance template. The create instances operation is marked DONE if the createInstances request is successful. The underlying actions take additional time. You must separately verify the status of the creating or actions with the listmanagedinstances method. +func (c *RegionInstanceGroupManagersClient) CreateInstances(ctx context.Context, req *computepb.CreateInstancesRegionInstanceGroupManagerRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.CreateInstances(ctx, req, opts...) +} + +// Delete deletes the specified managed instance group and all of the instances in that group. +func (c *RegionInstanceGroupManagersClient) Delete(ctx context.Context, req *computepb.DeleteRegionInstanceGroupManagerRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.Delete(ctx, req, opts...) +} + +// DeleteInstances flags the specified instances in the managed instance group to be immediately deleted. The instances are also removed from any target pools of which they were a member. This method reduces the targetSize of the managed instance group by the number of instances that you delete. The deleteInstances operation is marked DONE if the deleteInstances request is successful. The underlying actions take additional time. You must separately verify the status of the deleting action with the listmanagedinstances method. +// +// If the group is part of a backend service that has enabled connection draining, it can take up to 60 seconds after the connection draining duration has elapsed before the VM instance is removed or deleted. +// +// You can specify a maximum of 1000 instances with this method per request. +func (c *RegionInstanceGroupManagersClient) DeleteInstances(ctx context.Context, req *computepb.DeleteInstancesRegionInstanceGroupManagerRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.DeleteInstances(ctx, req, opts...) +} + +// DeletePerInstanceConfigs deletes selected per-instance configs for the managed instance group. +func (c *RegionInstanceGroupManagersClient) DeletePerInstanceConfigs(ctx context.Context, req *computepb.DeletePerInstanceConfigsRegionInstanceGroupManagerRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.DeletePerInstanceConfigs(ctx, req, opts...) +} + +// Get returns all of the details about the specified managed instance group. +func (c *RegionInstanceGroupManagersClient) Get(ctx context.Context, req *computepb.GetRegionInstanceGroupManagerRequest, opts ...gax.CallOption) (*computepb.InstanceGroupManager, error) { + return c.internalClient.Get(ctx, req, opts...) +} + +// Insert creates a managed instance group using the information that you specify in the request. After the group is created, instances in the group are created using the specified instance template. This operation is marked as DONE when the group is created even if the instances in the group have not yet been created. You must separately verify the status of the individual instances with the listmanagedinstances method. +// +// A regional managed instance group can contain up to 2000 instances. +func (c *RegionInstanceGroupManagersClient) Insert(ctx context.Context, req *computepb.InsertRegionInstanceGroupManagerRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.Insert(ctx, req, opts...) +} + +// List retrieves the list of managed instance groups that are contained within the specified region. +func (c *RegionInstanceGroupManagersClient) List(ctx context.Context, req *computepb.ListRegionInstanceGroupManagersRequest, opts ...gax.CallOption) (*computepb.RegionInstanceGroupManagerList, error) { + return c.internalClient.List(ctx, req, opts...) +} + +// ListErrors lists all errors thrown by actions on instances for a given regional managed instance group. The filter and orderBy query parameters are not supported. +func (c *RegionInstanceGroupManagersClient) ListErrors(ctx context.Context, req *computepb.ListErrorsRegionInstanceGroupManagersRequest, opts ...gax.CallOption) (*computepb.RegionInstanceGroupManagersListErrorsResponse, error) { + return c.internalClient.ListErrors(ctx, req, opts...) +} + +// ListManagedInstances lists the instances in the managed instance group and instances that are scheduled to be created. The list includes any current actions that the group has scheduled for its instances. The orderBy query parameter is not supported. +func (c *RegionInstanceGroupManagersClient) ListManagedInstances(ctx context.Context, req *computepb.ListManagedInstancesRegionInstanceGroupManagersRequest, opts ...gax.CallOption) (*computepb.RegionInstanceGroupManagersListInstancesResponse, error) { + return c.internalClient.ListManagedInstances(ctx, req, opts...) +} + +// ListPerInstanceConfigs lists all of the per-instance configs defined for the managed instance group. The orderBy query parameter is not supported. +func (c *RegionInstanceGroupManagersClient) ListPerInstanceConfigs(ctx context.Context, req *computepb.ListPerInstanceConfigsRegionInstanceGroupManagersRequest, opts ...gax.CallOption) (*computepb.RegionInstanceGroupManagersListInstanceConfigsResp, error) { + return c.internalClient.ListPerInstanceConfigs(ctx, req, opts...) +} + +// Patch updates a managed instance group using the information that you specify in the request. This operation is marked as DONE when the group is patched even if the instances in the group are still in the process of being patched. You must separately verify the status of the individual instances with the listmanagedinstances method. This method supports PATCH semantics and uses the JSON merge patch format and processing rules. +func (c *RegionInstanceGroupManagersClient) Patch(ctx context.Context, req *computepb.PatchRegionInstanceGroupManagerRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.Patch(ctx, req, opts...) +} + +// PatchPerInstanceConfigs inserts or patches per-instance configs for the managed instance group. perInstanceConfig.name (at http://perInstanceConfig.name) serves as a key used to distinguish whether to perform insert or patch. +func (c *RegionInstanceGroupManagersClient) PatchPerInstanceConfigs(ctx context.Context, req *computepb.PatchPerInstanceConfigsRegionInstanceGroupManagerRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.PatchPerInstanceConfigs(ctx, req, opts...) +} + +// RecreateInstances flags the specified VM instances in the managed instance group to be immediately recreated. Each instance is recreated using the group’s current configuration. This operation is marked as DONE when the flag is set even if the instances have not yet been recreated. You must separately verify the status of each instance by checking its currentAction field; for more information, see Checking the status of managed instances. +// +// If the group is part of a backend service that has enabled connection draining, it can take up to 60 seconds after the connection draining duration has elapsed before the VM instance is removed or deleted. +// +// You can specify a maximum of 1000 instances with this method per request. +func (c *RegionInstanceGroupManagersClient) RecreateInstances(ctx context.Context, req *computepb.RecreateInstancesRegionInstanceGroupManagerRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.RecreateInstances(ctx, req, opts...) +} + +// Resize changes the intended size of the managed instance group. If you increase the size, the group creates new instances using the current instance template. If you decrease the size, the group deletes one or more instances. +// +// The resize operation is marked DONE if the resize request is successful. The underlying actions take additional time. You must separately verify the status of the creating or deleting actions with the listmanagedinstances method. +// +// If the group is part of a backend service that has enabled connection draining, it can take up to 60 seconds after the connection draining duration has elapsed before the VM instance is removed or deleted. +func (c *RegionInstanceGroupManagersClient) Resize(ctx context.Context, req *computepb.ResizeRegionInstanceGroupManagerRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.Resize(ctx, req, opts...) +} + +// SetInstanceTemplate sets the instance template to use when creating new instances or recreating instances in this group. Existing instances are not affected. +func (c *RegionInstanceGroupManagersClient) SetInstanceTemplate(ctx context.Context, req *computepb.SetInstanceTemplateRegionInstanceGroupManagerRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.SetInstanceTemplate(ctx, req, opts...) +} + +// SetTargetPools modifies the target pools to which all new instances in this group are assigned. Existing instances in the group are not affected. +func (c *RegionInstanceGroupManagersClient) SetTargetPools(ctx context.Context, req *computepb.SetTargetPoolsRegionInstanceGroupManagerRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.SetTargetPools(ctx, req, opts...) +} + +// UpdatePerInstanceConfigs inserts or updates per-instance configs for the managed instance group. perInstanceConfig.name (at http://perInstanceConfig.name) serves as a key used to distinguish whether to perform insert or patch. +func (c *RegionInstanceGroupManagersClient) UpdatePerInstanceConfigs(ctx context.Context, req *computepb.UpdatePerInstanceConfigsRegionInstanceGroupManagerRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.UpdatePerInstanceConfigs(ctx, req, opts...) +} + +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +type regionInstanceGroupManagersRESTClient struct { + // The http endpoint to connect to. + endpoint string + + // The http client. + httpClient *http.Client + + // The x-goog-* metadata to be sent with each request. + xGoogMetadata metadata.MD +} + +// NewRegionInstanceGroupManagersRESTClient creates a new region instance group managers rest client. +// +// The RegionInstanceGroupManagers API. +func NewRegionInstanceGroupManagersRESTClient(ctx context.Context, opts ...option.ClientOption) (*RegionInstanceGroupManagersClient, error) { + clientOpts := append(defaultRegionInstanceGroupManagersRESTClientOptions(), opts...) + httpClient, endpoint, err := httptransport.NewClient(ctx, clientOpts...) + if err != nil { + return nil, err + } + + c := ®ionInstanceGroupManagersRESTClient{ + endpoint: endpoint, + httpClient: httpClient, + } + c.setGoogleClientInfo() + + return &RegionInstanceGroupManagersClient{internalClient: c, CallOptions: &RegionInstanceGroupManagersCallOptions{}}, nil +} + +func defaultRegionInstanceGroupManagersRESTClientOptions() []option.ClientOption { + return []option.ClientOption{ + internaloption.WithDefaultEndpoint("compute.googleapis.com"), + internaloption.WithDefaultMTLSEndpoint("compute.mtls.googleapis.com"), + internaloption.WithDefaultAudience("https://compute.googleapis.com/"), + internaloption.WithDefaultScopes(DefaultAuthScopes()...), + } +} + +// 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 *regionInstanceGroupManagersRESTClient) setGoogleClientInfo(keyval ...string) { + kv := append([]string{"gl-go", versionGo()}, keyval...) + kv = append(kv, "gapic", versionClient, "gax", gax.Version, "rest", "UNKNOWN") + 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 *regionInstanceGroupManagersRESTClient) Close() error { + // Replace httpClient with nil to force cleanup. + c.httpClient = nil + return nil +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *regionInstanceGroupManagersRESTClient) Connection() *grpc.ClientConn { + return nil +} + +// AbandonInstances flags the specified instances to be immediately removed from the managed instance group. Abandoning an instance does not delete the instance, but it does remove the instance from any target pools that are applied by the managed instance group. This method reduces the targetSize of the managed instance group by the number of instances that you abandon. This operation is marked as DONE when the action is scheduled even if the instances have not yet been removed from the group. You must separately verify the status of the abandoning action with the listmanagedinstances method. +// +// If the group is part of a backend service that has enabled connection draining, it can take up to 60 seconds after the connection draining duration has elapsed before the VM instance is removed or deleted. +// +// You can specify a maximum of 1000 instances with this method per request. +func (c *regionInstanceGroupManagersRESTClient) AbandonInstances(ctx context.Context, req *computepb.AbandonInstancesRegionInstanceGroupManagerRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetRegionInstanceGroupManagersAbandonInstancesRequestResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/regions/%v/instanceGroupManagers/%v/abandonInstances", req.GetProject(), req.GetRegion(), req.GetInstanceGroupManager()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// ApplyUpdatesToInstances apply updates to selected instances the managed instance group. +func (c *regionInstanceGroupManagersRESTClient) ApplyUpdatesToInstances(ctx context.Context, req *computepb.ApplyUpdatesToInstancesRegionInstanceGroupManagerRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetRegionInstanceGroupManagersApplyUpdatesRequestResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/regions/%v/instanceGroupManagers/%v/applyUpdatesToInstances", req.GetProject(), req.GetRegion(), req.GetInstanceGroupManager()) + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// CreateInstances creates instances with per-instance configs in this regional managed instance group. Instances are created using the current instance template. The create instances operation is marked DONE if the createInstances request is successful. The underlying actions take additional time. You must separately verify the status of the creating or actions with the listmanagedinstances method. +func (c *regionInstanceGroupManagersRESTClient) CreateInstances(ctx context.Context, req *computepb.CreateInstancesRegionInstanceGroupManagerRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetRegionInstanceGroupManagersCreateInstancesRequestResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/regions/%v/instanceGroupManagers/%v/createInstances", req.GetProject(), req.GetRegion(), req.GetInstanceGroupManager()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Delete deletes the specified managed instance group and all of the instances in that group. +func (c *regionInstanceGroupManagersRESTClient) Delete(ctx context.Context, req *computepb.DeleteRegionInstanceGroupManagerRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/regions/%v/instanceGroupManagers/%v", req.GetProject(), req.GetRegion(), req.GetInstanceGroupManager()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("DELETE", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// DeleteInstances flags the specified instances in the managed instance group to be immediately deleted. The instances are also removed from any target pools of which they were a member. This method reduces the targetSize of the managed instance group by the number of instances that you delete. The deleteInstances operation is marked DONE if the deleteInstances request is successful. The underlying actions take additional time. You must separately verify the status of the deleting action with the listmanagedinstances method. +// +// If the group is part of a backend service that has enabled connection draining, it can take up to 60 seconds after the connection draining duration has elapsed before the VM instance is removed or deleted. +// +// You can specify a maximum of 1000 instances with this method per request. +func (c *regionInstanceGroupManagersRESTClient) DeleteInstances(ctx context.Context, req *computepb.DeleteInstancesRegionInstanceGroupManagerRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetRegionInstanceGroupManagersDeleteInstancesRequestResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/regions/%v/instanceGroupManagers/%v/deleteInstances", req.GetProject(), req.GetRegion(), req.GetInstanceGroupManager()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// DeletePerInstanceConfigs deletes selected per-instance configs for the managed instance group. +func (c *regionInstanceGroupManagersRESTClient) DeletePerInstanceConfigs(ctx context.Context, req *computepb.DeletePerInstanceConfigsRegionInstanceGroupManagerRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetRegionInstanceGroupManagerDeleteInstanceConfigReqResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/regions/%v/instanceGroupManagers/%v/deletePerInstanceConfigs", req.GetProject(), req.GetRegion(), req.GetInstanceGroupManager()) + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Get returns all of the details about the specified managed instance group. +func (c *regionInstanceGroupManagersRESTClient) Get(ctx context.Context, req *computepb.GetRegionInstanceGroupManagerRequest, opts ...gax.CallOption) (*computepb.InstanceGroupManager, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/regions/%v/instanceGroupManagers/%v", req.GetProject(), req.GetRegion(), req.GetInstanceGroupManager()) + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.InstanceGroupManager{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Insert creates a managed instance group using the information that you specify in the request. After the group is created, instances in the group are created using the specified instance template. This operation is marked as DONE when the group is created even if the instances in the group have not yet been created. You must separately verify the status of the individual instances with the listmanagedinstances method. +// +// A regional managed instance group can contain up to 2000 instances. +func (c *regionInstanceGroupManagersRESTClient) Insert(ctx context.Context, req *computepb.InsertRegionInstanceGroupManagerRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetInstanceGroupManagerResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/regions/%v/instanceGroupManagers", req.GetProject(), req.GetRegion()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// List retrieves the list of managed instance groups that are contained within the specified region. +func (c *regionInstanceGroupManagersRESTClient) List(ctx context.Context, req *computepb.ListRegionInstanceGroupManagersRequest, opts ...gax.CallOption) (*computepb.RegionInstanceGroupManagerList, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/regions/%v/instanceGroupManagers", req.GetProject(), req.GetRegion()) + + params := url.Values{} + if req != nil && req.Filter != nil { + params.Add("filter", fmt.Sprintf("%v", req.GetFilter())) + } + if req != nil && req.MaxResults != nil { + params.Add("maxResults", fmt.Sprintf("%v", req.GetMaxResults())) + } + if req != nil && req.OrderBy != nil { + params.Add("orderBy", fmt.Sprintf("%v", req.GetOrderBy())) + } + if req != nil && req.PageToken != nil { + params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) + } + if req != nil && req.ReturnPartialSuccess != nil { + params.Add("returnPartialSuccess", fmt.Sprintf("%v", req.GetReturnPartialSuccess())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.RegionInstanceGroupManagerList{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// ListErrors lists all errors thrown by actions on instances for a given regional managed instance group. The filter and orderBy query parameters are not supported. +func (c *regionInstanceGroupManagersRESTClient) ListErrors(ctx context.Context, req *computepb.ListErrorsRegionInstanceGroupManagersRequest, opts ...gax.CallOption) (*computepb.RegionInstanceGroupManagersListErrorsResponse, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/regions/%v/instanceGroupManagers/%v/listErrors", req.GetProject(), req.GetRegion(), req.GetInstanceGroupManager()) + + params := url.Values{} + if req != nil && req.Filter != nil { + params.Add("filter", fmt.Sprintf("%v", req.GetFilter())) + } + if req != nil && req.MaxResults != nil { + params.Add("maxResults", fmt.Sprintf("%v", req.GetMaxResults())) + } + if req != nil && req.OrderBy != nil { + params.Add("orderBy", fmt.Sprintf("%v", req.GetOrderBy())) + } + if req != nil && req.PageToken != nil { + params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) + } + if req != nil && req.ReturnPartialSuccess != nil { + params.Add("returnPartialSuccess", fmt.Sprintf("%v", req.GetReturnPartialSuccess())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.RegionInstanceGroupManagersListErrorsResponse{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// ListManagedInstances lists the instances in the managed instance group and instances that are scheduled to be created. The list includes any current actions that the group has scheduled for its instances. The orderBy query parameter is not supported. +func (c *regionInstanceGroupManagersRESTClient) ListManagedInstances(ctx context.Context, req *computepb.ListManagedInstancesRegionInstanceGroupManagersRequest, opts ...gax.CallOption) (*computepb.RegionInstanceGroupManagersListInstancesResponse, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/regions/%v/instanceGroupManagers/%v/listManagedInstances", req.GetProject(), req.GetRegion(), req.GetInstanceGroupManager()) + + params := url.Values{} + if req != nil && req.Filter != nil { + params.Add("filter", fmt.Sprintf("%v", req.GetFilter())) + } + if req != nil && req.MaxResults != nil { + params.Add("maxResults", fmt.Sprintf("%v", req.GetMaxResults())) + } + if req != nil && req.OrderBy != nil { + params.Add("orderBy", fmt.Sprintf("%v", req.GetOrderBy())) + } + if req != nil && req.PageToken != nil { + params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) + } + if req != nil && req.ReturnPartialSuccess != nil { + params.Add("returnPartialSuccess", fmt.Sprintf("%v", req.GetReturnPartialSuccess())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.RegionInstanceGroupManagersListInstancesResponse{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// ListPerInstanceConfigs lists all of the per-instance configs defined for the managed instance group. The orderBy query parameter is not supported. +func (c *regionInstanceGroupManagersRESTClient) ListPerInstanceConfigs(ctx context.Context, req *computepb.ListPerInstanceConfigsRegionInstanceGroupManagersRequest, opts ...gax.CallOption) (*computepb.RegionInstanceGroupManagersListInstanceConfigsResp, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/regions/%v/instanceGroupManagers/%v/listPerInstanceConfigs", req.GetProject(), req.GetRegion(), req.GetInstanceGroupManager()) + + params := url.Values{} + if req != nil && req.Filter != nil { + params.Add("filter", fmt.Sprintf("%v", req.GetFilter())) + } + if req != nil && req.MaxResults != nil { + params.Add("maxResults", fmt.Sprintf("%v", req.GetMaxResults())) + } + if req != nil && req.OrderBy != nil { + params.Add("orderBy", fmt.Sprintf("%v", req.GetOrderBy())) + } + if req != nil && req.PageToken != nil { + params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) + } + if req != nil && req.ReturnPartialSuccess != nil { + params.Add("returnPartialSuccess", fmt.Sprintf("%v", req.GetReturnPartialSuccess())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.RegionInstanceGroupManagersListInstanceConfigsResp{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Patch updates a managed instance group using the information that you specify in the request. This operation is marked as DONE when the group is patched even if the instances in the group are still in the process of being patched. You must separately verify the status of the individual instances with the listmanagedinstances method. This method supports PATCH semantics and uses the JSON merge patch format and processing rules. +func (c *regionInstanceGroupManagersRESTClient) Patch(ctx context.Context, req *computepb.PatchRegionInstanceGroupManagerRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetInstanceGroupManagerResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/regions/%v/instanceGroupManagers/%v", req.GetProject(), req.GetRegion(), req.GetInstanceGroupManager()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("PATCH", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// PatchPerInstanceConfigs inserts or patches per-instance configs for the managed instance group. perInstanceConfig.name (at http://perInstanceConfig.name) serves as a key used to distinguish whether to perform insert or patch. +func (c *regionInstanceGroupManagersRESTClient) PatchPerInstanceConfigs(ctx context.Context, req *computepb.PatchPerInstanceConfigsRegionInstanceGroupManagerRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetRegionInstanceGroupManagerPatchInstanceConfigReqResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/regions/%v/instanceGroupManagers/%v/patchPerInstanceConfigs", req.GetProject(), req.GetRegion(), req.GetInstanceGroupManager()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// RecreateInstances flags the specified VM instances in the managed instance group to be immediately recreated. Each instance is recreated using the group’s current configuration. This operation is marked as DONE when the flag is set even if the instances have not yet been recreated. You must separately verify the status of each instance by checking its currentAction field; for more information, see Checking the status of managed instances. +// +// If the group is part of a backend service that has enabled connection draining, it can take up to 60 seconds after the connection draining duration has elapsed before the VM instance is removed or deleted. +// +// You can specify a maximum of 1000 instances with this method per request. +func (c *regionInstanceGroupManagersRESTClient) RecreateInstances(ctx context.Context, req *computepb.RecreateInstancesRegionInstanceGroupManagerRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetRegionInstanceGroupManagersRecreateRequestResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/regions/%v/instanceGroupManagers/%v/recreateInstances", req.GetProject(), req.GetRegion(), req.GetInstanceGroupManager()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Resize changes the intended size of the managed instance group. If you increase the size, the group creates new instances using the current instance template. If you decrease the size, the group deletes one or more instances. +// +// The resize operation is marked DONE if the resize request is successful. The underlying actions take additional time. You must separately verify the status of the creating or deleting actions with the listmanagedinstances method. +// +// If the group is part of a backend service that has enabled connection draining, it can take up to 60 seconds after the connection draining duration has elapsed before the VM instance is removed or deleted. +func (c *regionInstanceGroupManagersRESTClient) Resize(ctx context.Context, req *computepb.ResizeRegionInstanceGroupManagerRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/regions/%v/instanceGroupManagers/%v/resize", req.GetProject(), req.GetRegion(), req.GetInstanceGroupManager()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + if req.GetSize() != 0 { + params.Add("size", fmt.Sprintf("%v", req.GetSize())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// SetInstanceTemplate sets the instance template to use when creating new instances or recreating instances in this group. Existing instances are not affected. +func (c *regionInstanceGroupManagersRESTClient) SetInstanceTemplate(ctx context.Context, req *computepb.SetInstanceTemplateRegionInstanceGroupManagerRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetRegionInstanceGroupManagersSetTemplateRequestResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/regions/%v/instanceGroupManagers/%v/setInstanceTemplate", req.GetProject(), req.GetRegion(), req.GetInstanceGroupManager()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// SetTargetPools modifies the target pools to which all new instances in this group are assigned. Existing instances in the group are not affected. +func (c *regionInstanceGroupManagersRESTClient) SetTargetPools(ctx context.Context, req *computepb.SetTargetPoolsRegionInstanceGroupManagerRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetRegionInstanceGroupManagersSetTargetPoolsRequestResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/regions/%v/instanceGroupManagers/%v/setTargetPools", req.GetProject(), req.GetRegion(), req.GetInstanceGroupManager()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// UpdatePerInstanceConfigs inserts or updates per-instance configs for the managed instance group. perInstanceConfig.name (at http://perInstanceConfig.name) serves as a key used to distinguish whether to perform insert or patch. +func (c *regionInstanceGroupManagersRESTClient) UpdatePerInstanceConfigs(ctx context.Context, req *computepb.UpdatePerInstanceConfigsRegionInstanceGroupManagerRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetRegionInstanceGroupManagerUpdateInstanceConfigReqResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/regions/%v/instanceGroupManagers/%v/updatePerInstanceConfigs", req.GetProject(), req.GetRegion(), req.GetInstanceGroupManager()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} diff --git a/compute/apiv1/region_instance_group_managers_client_example_test.go b/compute/apiv1/region_instance_group_managers_client_example_test.go new file mode 100644 index 00000000000..cf0c18b6003 --- /dev/null +++ b/compute/apiv1/region_instance_group_managers_client_example_test.go @@ -0,0 +1,397 @@ +// 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 compute_test + +import ( + "context" + + compute "cloud.google.com/go/compute/apiv1" + computepb "google.golang.org/genproto/googleapis/cloud/compute/v1" +) + +func ExampleNewRegionInstanceGroupManagersRESTClient() { + ctx := context.Background() + c, err := compute.NewRegionInstanceGroupManagersRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + // TODO: Use client. + _ = c +} + +func ExampleRegionInstanceGroupManagersClient_AbandonInstances() { + ctx := context.Background() + c, err := compute.NewRegionInstanceGroupManagersRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.AbandonInstancesRegionInstanceGroupManagerRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.AbandonInstances(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleRegionInstanceGroupManagersClient_ApplyUpdatesToInstances() { + ctx := context.Background() + c, err := compute.NewRegionInstanceGroupManagersRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.ApplyUpdatesToInstancesRegionInstanceGroupManagerRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.ApplyUpdatesToInstances(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleRegionInstanceGroupManagersClient_CreateInstances() { + ctx := context.Background() + c, err := compute.NewRegionInstanceGroupManagersRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.CreateInstancesRegionInstanceGroupManagerRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.CreateInstances(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleRegionInstanceGroupManagersClient_Delete() { + ctx := context.Background() + c, err := compute.NewRegionInstanceGroupManagersRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.DeleteRegionInstanceGroupManagerRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Delete(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleRegionInstanceGroupManagersClient_DeleteInstances() { + ctx := context.Background() + c, err := compute.NewRegionInstanceGroupManagersRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.DeleteInstancesRegionInstanceGroupManagerRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.DeleteInstances(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleRegionInstanceGroupManagersClient_DeletePerInstanceConfigs() { + ctx := context.Background() + c, err := compute.NewRegionInstanceGroupManagersRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.DeletePerInstanceConfigsRegionInstanceGroupManagerRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.DeletePerInstanceConfigs(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleRegionInstanceGroupManagersClient_Get() { + ctx := context.Background() + c, err := compute.NewRegionInstanceGroupManagersRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.GetRegionInstanceGroupManagerRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Get(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleRegionInstanceGroupManagersClient_Insert() { + ctx := context.Background() + c, err := compute.NewRegionInstanceGroupManagersRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.InsertRegionInstanceGroupManagerRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Insert(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleRegionInstanceGroupManagersClient_List() { + ctx := context.Background() + c, err := compute.NewRegionInstanceGroupManagersRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.ListRegionInstanceGroupManagersRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.List(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleRegionInstanceGroupManagersClient_ListErrors() { + ctx := context.Background() + c, err := compute.NewRegionInstanceGroupManagersRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.ListErrorsRegionInstanceGroupManagersRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.ListErrors(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleRegionInstanceGroupManagersClient_ListManagedInstances() { + ctx := context.Background() + c, err := compute.NewRegionInstanceGroupManagersRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.ListManagedInstancesRegionInstanceGroupManagersRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.ListManagedInstances(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleRegionInstanceGroupManagersClient_ListPerInstanceConfigs() { + ctx := context.Background() + c, err := compute.NewRegionInstanceGroupManagersRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.ListPerInstanceConfigsRegionInstanceGroupManagersRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.ListPerInstanceConfigs(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleRegionInstanceGroupManagersClient_Patch() { + ctx := context.Background() + c, err := compute.NewRegionInstanceGroupManagersRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.PatchRegionInstanceGroupManagerRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Patch(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleRegionInstanceGroupManagersClient_PatchPerInstanceConfigs() { + ctx := context.Background() + c, err := compute.NewRegionInstanceGroupManagersRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.PatchPerInstanceConfigsRegionInstanceGroupManagerRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.PatchPerInstanceConfigs(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleRegionInstanceGroupManagersClient_RecreateInstances() { + ctx := context.Background() + c, err := compute.NewRegionInstanceGroupManagersRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.RecreateInstancesRegionInstanceGroupManagerRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.RecreateInstances(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleRegionInstanceGroupManagersClient_Resize() { + ctx := context.Background() + c, err := compute.NewRegionInstanceGroupManagersRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.ResizeRegionInstanceGroupManagerRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Resize(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleRegionInstanceGroupManagersClient_SetInstanceTemplate() { + ctx := context.Background() + c, err := compute.NewRegionInstanceGroupManagersRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.SetInstanceTemplateRegionInstanceGroupManagerRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.SetInstanceTemplate(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleRegionInstanceGroupManagersClient_SetTargetPools() { + ctx := context.Background() + c, err := compute.NewRegionInstanceGroupManagersRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.SetTargetPoolsRegionInstanceGroupManagerRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.SetTargetPools(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleRegionInstanceGroupManagersClient_UpdatePerInstanceConfigs() { + ctx := context.Background() + c, err := compute.NewRegionInstanceGroupManagersRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.UpdatePerInstanceConfigsRegionInstanceGroupManagerRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.UpdatePerInstanceConfigs(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} diff --git a/compute/apiv1/region_instance_groups_client.go b/compute/apiv1/region_instance_groups_client.go new file mode 100644 index 00000000000..d2698ffb112 --- /dev/null +++ b/compute/apiv1/region_instance_groups_client.go @@ -0,0 +1,393 @@ +// 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 compute + +import ( + "bytes" + "context" + "fmt" + "io/ioutil" + "net/http" + "net/url" + + gax "github.com/googleapis/gax-go/v2" + "google.golang.org/api/option" + "google.golang.org/api/option/internaloption" + httptransport "google.golang.org/api/transport/http" + computepb "google.golang.org/genproto/googleapis/cloud/compute/v1" + "google.golang.org/grpc" + "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/encoding/protojson" +) + +var newRegionInstanceGroupsClientHook clientHook + +// RegionInstanceGroupsCallOptions contains the retry settings for each method of RegionInstanceGroupsClient. +type RegionInstanceGroupsCallOptions struct { + Get []gax.CallOption + List []gax.CallOption + ListInstances []gax.CallOption + SetNamedPorts []gax.CallOption +} + +// internalRegionInstanceGroupsClient is an interface that defines the methods availaible from Google Compute Engine API. +type internalRegionInstanceGroupsClient interface { + Close() error + setGoogleClientInfo(...string) + Connection() *grpc.ClientConn + Get(context.Context, *computepb.GetRegionInstanceGroupRequest, ...gax.CallOption) (*computepb.InstanceGroup, error) + List(context.Context, *computepb.ListRegionInstanceGroupsRequest, ...gax.CallOption) (*computepb.RegionInstanceGroupList, error) + ListInstances(context.Context, *computepb.ListInstancesRegionInstanceGroupsRequest, ...gax.CallOption) (*computepb.RegionInstanceGroupsListInstances, error) + SetNamedPorts(context.Context, *computepb.SetNamedPortsRegionInstanceGroupRequest, ...gax.CallOption) (*computepb.Operation, error) +} + +// RegionInstanceGroupsClient is a client for interacting with Google Compute Engine API. +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +// +// The RegionInstanceGroups API. +type RegionInstanceGroupsClient struct { + // The internal transport-dependent client. + internalClient internalRegionInstanceGroupsClient + + // The call options for this service. + CallOptions *RegionInstanceGroupsCallOptions +} + +// 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 *RegionInstanceGroupsClient) 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 *RegionInstanceGroupsClient) setGoogleClientInfo(keyval ...string) { + c.internalClient.setGoogleClientInfo(keyval...) +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *RegionInstanceGroupsClient) Connection() *grpc.ClientConn { + return c.internalClient.Connection() +} + +// Get returns the specified instance group resource. +func (c *RegionInstanceGroupsClient) Get(ctx context.Context, req *computepb.GetRegionInstanceGroupRequest, opts ...gax.CallOption) (*computepb.InstanceGroup, error) { + return c.internalClient.Get(ctx, req, opts...) +} + +// List retrieves the list of instance group resources contained within the specified region. +func (c *RegionInstanceGroupsClient) List(ctx context.Context, req *computepb.ListRegionInstanceGroupsRequest, opts ...gax.CallOption) (*computepb.RegionInstanceGroupList, error) { + return c.internalClient.List(ctx, req, opts...) +} + +// ListInstances lists the instances in the specified instance group and displays information about the named ports. Depending on the specified options, this method can list all instances or only the instances that are running. The orderBy query parameter is not supported. +func (c *RegionInstanceGroupsClient) ListInstances(ctx context.Context, req *computepb.ListInstancesRegionInstanceGroupsRequest, opts ...gax.CallOption) (*computepb.RegionInstanceGroupsListInstances, error) { + return c.internalClient.ListInstances(ctx, req, opts...) +} + +// SetNamedPorts sets the named ports for the specified regional instance group. +func (c *RegionInstanceGroupsClient) SetNamedPorts(ctx context.Context, req *computepb.SetNamedPortsRegionInstanceGroupRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.SetNamedPorts(ctx, req, opts...) +} + +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +type regionInstanceGroupsRESTClient struct { + // The http endpoint to connect to. + endpoint string + + // The http client. + httpClient *http.Client + + // The x-goog-* metadata to be sent with each request. + xGoogMetadata metadata.MD +} + +// NewRegionInstanceGroupsRESTClient creates a new region instance groups rest client. +// +// The RegionInstanceGroups API. +func NewRegionInstanceGroupsRESTClient(ctx context.Context, opts ...option.ClientOption) (*RegionInstanceGroupsClient, error) { + clientOpts := append(defaultRegionInstanceGroupsRESTClientOptions(), opts...) + httpClient, endpoint, err := httptransport.NewClient(ctx, clientOpts...) + if err != nil { + return nil, err + } + + c := ®ionInstanceGroupsRESTClient{ + endpoint: endpoint, + httpClient: httpClient, + } + c.setGoogleClientInfo() + + return &RegionInstanceGroupsClient{internalClient: c, CallOptions: &RegionInstanceGroupsCallOptions{}}, nil +} + +func defaultRegionInstanceGroupsRESTClientOptions() []option.ClientOption { + return []option.ClientOption{ + internaloption.WithDefaultEndpoint("compute.googleapis.com"), + internaloption.WithDefaultMTLSEndpoint("compute.mtls.googleapis.com"), + internaloption.WithDefaultAudience("https://compute.googleapis.com/"), + internaloption.WithDefaultScopes(DefaultAuthScopes()...), + } +} + +// 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 *regionInstanceGroupsRESTClient) setGoogleClientInfo(keyval ...string) { + kv := append([]string{"gl-go", versionGo()}, keyval...) + kv = append(kv, "gapic", versionClient, "gax", gax.Version, "rest", "UNKNOWN") + 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 *regionInstanceGroupsRESTClient) Close() error { + // Replace httpClient with nil to force cleanup. + c.httpClient = nil + return nil +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *regionInstanceGroupsRESTClient) Connection() *grpc.ClientConn { + return nil +} + +// Get returns the specified instance group resource. +func (c *regionInstanceGroupsRESTClient) Get(ctx context.Context, req *computepb.GetRegionInstanceGroupRequest, opts ...gax.CallOption) (*computepb.InstanceGroup, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/regions/%v/instanceGroups/%v", req.GetProject(), req.GetRegion(), req.GetInstanceGroup()) + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.InstanceGroup{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// List retrieves the list of instance group resources contained within the specified region. +func (c *regionInstanceGroupsRESTClient) List(ctx context.Context, req *computepb.ListRegionInstanceGroupsRequest, opts ...gax.CallOption) (*computepb.RegionInstanceGroupList, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/regions/%v/instanceGroups", req.GetProject(), req.GetRegion()) + + params := url.Values{} + if req != nil && req.Filter != nil { + params.Add("filter", fmt.Sprintf("%v", req.GetFilter())) + } + if req != nil && req.MaxResults != nil { + params.Add("maxResults", fmt.Sprintf("%v", req.GetMaxResults())) + } + if req != nil && req.OrderBy != nil { + params.Add("orderBy", fmt.Sprintf("%v", req.GetOrderBy())) + } + if req != nil && req.PageToken != nil { + params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) + } + if req != nil && req.ReturnPartialSuccess != nil { + params.Add("returnPartialSuccess", fmt.Sprintf("%v", req.GetReturnPartialSuccess())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.RegionInstanceGroupList{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// ListInstances lists the instances in the specified instance group and displays information about the named ports. Depending on the specified options, this method can list all instances or only the instances that are running. The orderBy query parameter is not supported. +func (c *regionInstanceGroupsRESTClient) ListInstances(ctx context.Context, req *computepb.ListInstancesRegionInstanceGroupsRequest, opts ...gax.CallOption) (*computepb.RegionInstanceGroupsListInstances, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetRegionInstanceGroupsListInstancesRequestResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/regions/%v/instanceGroups/%v/listInstances", req.GetProject(), req.GetRegion(), req.GetInstanceGroup()) + + params := url.Values{} + if req != nil && req.Filter != nil { + params.Add("filter", fmt.Sprintf("%v", req.GetFilter())) + } + if req != nil && req.MaxResults != nil { + params.Add("maxResults", fmt.Sprintf("%v", req.GetMaxResults())) + } + if req != nil && req.OrderBy != nil { + params.Add("orderBy", fmt.Sprintf("%v", req.GetOrderBy())) + } + if req != nil && req.PageToken != nil { + params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) + } + if req != nil && req.ReturnPartialSuccess != nil { + params.Add("returnPartialSuccess", fmt.Sprintf("%v", req.GetReturnPartialSuccess())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.RegionInstanceGroupsListInstances{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// SetNamedPorts sets the named ports for the specified regional instance group. +func (c *regionInstanceGroupsRESTClient) SetNamedPorts(ctx context.Context, req *computepb.SetNamedPortsRegionInstanceGroupRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetRegionInstanceGroupsSetNamedPortsRequestResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/regions/%v/instanceGroups/%v/setNamedPorts", req.GetProject(), req.GetRegion(), req.GetInstanceGroup()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} diff --git a/compute/apiv1/region_instance_groups_client_example_test.go b/compute/apiv1/region_instance_groups_client_example_test.go new file mode 100644 index 00000000000..646c6f1843d --- /dev/null +++ b/compute/apiv1/region_instance_groups_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 compute_test + +import ( + "context" + + compute "cloud.google.com/go/compute/apiv1" + computepb "google.golang.org/genproto/googleapis/cloud/compute/v1" +) + +func ExampleNewRegionInstanceGroupsRESTClient() { + ctx := context.Background() + c, err := compute.NewRegionInstanceGroupsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + // TODO: Use client. + _ = c +} + +func ExampleRegionInstanceGroupsClient_Get() { + ctx := context.Background() + c, err := compute.NewRegionInstanceGroupsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.GetRegionInstanceGroupRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Get(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleRegionInstanceGroupsClient_List() { + ctx := context.Background() + c, err := compute.NewRegionInstanceGroupsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.ListRegionInstanceGroupsRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.List(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleRegionInstanceGroupsClient_ListInstances() { + ctx := context.Background() + c, err := compute.NewRegionInstanceGroupsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.ListInstancesRegionInstanceGroupsRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.ListInstances(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleRegionInstanceGroupsClient_SetNamedPorts() { + ctx := context.Background() + c, err := compute.NewRegionInstanceGroupsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.SetNamedPortsRegionInstanceGroupRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.SetNamedPorts(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} diff --git a/compute/apiv1/region_instances_client.go b/compute/apiv1/region_instances_client.go new file mode 100644 index 00000000000..e9a7f88fdf8 --- /dev/null +++ b/compute/apiv1/region_instances_client.go @@ -0,0 +1,204 @@ +// 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 compute + +import ( + "bytes" + "context" + "fmt" + "io/ioutil" + "net/http" + "net/url" + + gax "github.com/googleapis/gax-go/v2" + "google.golang.org/api/option" + "google.golang.org/api/option/internaloption" + httptransport "google.golang.org/api/transport/http" + computepb "google.golang.org/genproto/googleapis/cloud/compute/v1" + "google.golang.org/grpc" + "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/encoding/protojson" +) + +var newRegionInstancesClientHook clientHook + +// RegionInstancesCallOptions contains the retry settings for each method of RegionInstancesClient. +type RegionInstancesCallOptions struct { + BulkInsert []gax.CallOption +} + +// internalRegionInstancesClient is an interface that defines the methods availaible from Google Compute Engine API. +type internalRegionInstancesClient interface { + Close() error + setGoogleClientInfo(...string) + Connection() *grpc.ClientConn + BulkInsert(context.Context, *computepb.BulkInsertRegionInstanceRequest, ...gax.CallOption) (*computepb.Operation, error) +} + +// RegionInstancesClient is a client for interacting with Google Compute Engine API. +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +// +// The RegionInstances API. +type RegionInstancesClient struct { + // The internal transport-dependent client. + internalClient internalRegionInstancesClient + + // The call options for this service. + CallOptions *RegionInstancesCallOptions +} + +// 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 *RegionInstancesClient) 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 *RegionInstancesClient) setGoogleClientInfo(keyval ...string) { + c.internalClient.setGoogleClientInfo(keyval...) +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *RegionInstancesClient) Connection() *grpc.ClientConn { + return c.internalClient.Connection() +} + +// BulkInsert creates multiple instances in a given region. Count specifies the number of instances to create. +func (c *RegionInstancesClient) BulkInsert(ctx context.Context, req *computepb.BulkInsertRegionInstanceRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.BulkInsert(ctx, req, opts...) +} + +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +type regionInstancesRESTClient struct { + // The http endpoint to connect to. + endpoint string + + // The http client. + httpClient *http.Client + + // The x-goog-* metadata to be sent with each request. + xGoogMetadata metadata.MD +} + +// NewRegionInstancesRESTClient creates a new region instances rest client. +// +// The RegionInstances API. +func NewRegionInstancesRESTClient(ctx context.Context, opts ...option.ClientOption) (*RegionInstancesClient, error) { + clientOpts := append(defaultRegionInstancesRESTClientOptions(), opts...) + httpClient, endpoint, err := httptransport.NewClient(ctx, clientOpts...) + if err != nil { + return nil, err + } + + c := ®ionInstancesRESTClient{ + endpoint: endpoint, + httpClient: httpClient, + } + c.setGoogleClientInfo() + + return &RegionInstancesClient{internalClient: c, CallOptions: &RegionInstancesCallOptions{}}, nil +} + +func defaultRegionInstancesRESTClientOptions() []option.ClientOption { + return []option.ClientOption{ + internaloption.WithDefaultEndpoint("compute.googleapis.com"), + internaloption.WithDefaultMTLSEndpoint("compute.mtls.googleapis.com"), + internaloption.WithDefaultAudience("https://compute.googleapis.com/"), + internaloption.WithDefaultScopes(DefaultAuthScopes()...), + } +} + +// 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 *regionInstancesRESTClient) setGoogleClientInfo(keyval ...string) { + kv := append([]string{"gl-go", versionGo()}, keyval...) + kv = append(kv, "gapic", versionClient, "gax", gax.Version, "rest", "UNKNOWN") + 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 *regionInstancesRESTClient) Close() error { + // Replace httpClient with nil to force cleanup. + c.httpClient = nil + return nil +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *regionInstancesRESTClient) Connection() *grpc.ClientConn { + return nil +} + +// BulkInsert creates multiple instances in a given region. Count specifies the number of instances to create. +func (c *regionInstancesRESTClient) BulkInsert(ctx context.Context, req *computepb.BulkInsertRegionInstanceRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetBulkInsertInstanceResourceResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/regions/%v/instances/bulkInsert", req.GetProject(), req.GetRegion()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} diff --git a/compute/apiv1/region_instances_client_example_test.go b/compute/apiv1/region_instances_client_example_test.go new file mode 100644 index 00000000000..9856d6f60c7 --- /dev/null +++ b/compute/apiv1/region_instances_client_example_test.go @@ -0,0 +1,55 @@ +// 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 compute_test + +import ( + "context" + + compute "cloud.google.com/go/compute/apiv1" + computepb "google.golang.org/genproto/googleapis/cloud/compute/v1" +) + +func ExampleNewRegionInstancesRESTClient() { + ctx := context.Background() + c, err := compute.NewRegionInstancesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + // TODO: Use client. + _ = c +} + +func ExampleRegionInstancesClient_BulkInsert() { + ctx := context.Background() + c, err := compute.NewRegionInstancesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.BulkInsertRegionInstanceRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.BulkInsert(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} diff --git a/compute/apiv1/region_network_endpoint_groups_client.go b/compute/apiv1/region_network_endpoint_groups_client.go new file mode 100644 index 00000000000..ace6be51de1 --- /dev/null +++ b/compute/apiv1/region_network_endpoint_groups_client.go @@ -0,0 +1,380 @@ +// 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 compute + +import ( + "bytes" + "context" + "fmt" + "io/ioutil" + "net/http" + "net/url" + + gax "github.com/googleapis/gax-go/v2" + "google.golang.org/api/option" + "google.golang.org/api/option/internaloption" + httptransport "google.golang.org/api/transport/http" + computepb "google.golang.org/genproto/googleapis/cloud/compute/v1" + "google.golang.org/grpc" + "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/encoding/protojson" +) + +var newRegionNetworkEndpointGroupsClientHook clientHook + +// RegionNetworkEndpointGroupsCallOptions contains the retry settings for each method of RegionNetworkEndpointGroupsClient. +type RegionNetworkEndpointGroupsCallOptions struct { + Delete []gax.CallOption + Get []gax.CallOption + Insert []gax.CallOption + List []gax.CallOption +} + +// internalRegionNetworkEndpointGroupsClient is an interface that defines the methods availaible from Google Compute Engine API. +type internalRegionNetworkEndpointGroupsClient interface { + Close() error + setGoogleClientInfo(...string) + Connection() *grpc.ClientConn + Delete(context.Context, *computepb.DeleteRegionNetworkEndpointGroupRequest, ...gax.CallOption) (*computepb.Operation, error) + Get(context.Context, *computepb.GetRegionNetworkEndpointGroupRequest, ...gax.CallOption) (*computepb.NetworkEndpointGroup, error) + Insert(context.Context, *computepb.InsertRegionNetworkEndpointGroupRequest, ...gax.CallOption) (*computepb.Operation, error) + List(context.Context, *computepb.ListRegionNetworkEndpointGroupsRequest, ...gax.CallOption) (*computepb.NetworkEndpointGroupList, error) +} + +// RegionNetworkEndpointGroupsClient is a client for interacting with Google Compute Engine API. +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +// +// The RegionNetworkEndpointGroups API. +type RegionNetworkEndpointGroupsClient struct { + // The internal transport-dependent client. + internalClient internalRegionNetworkEndpointGroupsClient + + // The call options for this service. + CallOptions *RegionNetworkEndpointGroupsCallOptions +} + +// 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 *RegionNetworkEndpointGroupsClient) 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 *RegionNetworkEndpointGroupsClient) setGoogleClientInfo(keyval ...string) { + c.internalClient.setGoogleClientInfo(keyval...) +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *RegionNetworkEndpointGroupsClient) Connection() *grpc.ClientConn { + return c.internalClient.Connection() +} + +// Delete deletes the specified network endpoint group. Note that the NEG cannot be deleted if it is configured as a backend of a backend service. +func (c *RegionNetworkEndpointGroupsClient) Delete(ctx context.Context, req *computepb.DeleteRegionNetworkEndpointGroupRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.Delete(ctx, req, opts...) +} + +// Get returns the specified network endpoint group. Gets a list of available network endpoint groups by making a list() request. +func (c *RegionNetworkEndpointGroupsClient) Get(ctx context.Context, req *computepb.GetRegionNetworkEndpointGroupRequest, opts ...gax.CallOption) (*computepb.NetworkEndpointGroup, error) { + return c.internalClient.Get(ctx, req, opts...) +} + +// Insert creates a network endpoint group in the specified project using the parameters that are included in the request. +func (c *RegionNetworkEndpointGroupsClient) Insert(ctx context.Context, req *computepb.InsertRegionNetworkEndpointGroupRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.Insert(ctx, req, opts...) +} + +// List retrieves the list of regional network endpoint groups available to the specified project in the given region. +func (c *RegionNetworkEndpointGroupsClient) List(ctx context.Context, req *computepb.ListRegionNetworkEndpointGroupsRequest, opts ...gax.CallOption) (*computepb.NetworkEndpointGroupList, error) { + return c.internalClient.List(ctx, req, opts...) +} + +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +type regionNetworkEndpointGroupsRESTClient struct { + // The http endpoint to connect to. + endpoint string + + // The http client. + httpClient *http.Client + + // The x-goog-* metadata to be sent with each request. + xGoogMetadata metadata.MD +} + +// NewRegionNetworkEndpointGroupsRESTClient creates a new region network endpoint groups rest client. +// +// The RegionNetworkEndpointGroups API. +func NewRegionNetworkEndpointGroupsRESTClient(ctx context.Context, opts ...option.ClientOption) (*RegionNetworkEndpointGroupsClient, error) { + clientOpts := append(defaultRegionNetworkEndpointGroupsRESTClientOptions(), opts...) + httpClient, endpoint, err := httptransport.NewClient(ctx, clientOpts...) + if err != nil { + return nil, err + } + + c := ®ionNetworkEndpointGroupsRESTClient{ + endpoint: endpoint, + httpClient: httpClient, + } + c.setGoogleClientInfo() + + return &RegionNetworkEndpointGroupsClient{internalClient: c, CallOptions: &RegionNetworkEndpointGroupsCallOptions{}}, nil +} + +func defaultRegionNetworkEndpointGroupsRESTClientOptions() []option.ClientOption { + return []option.ClientOption{ + internaloption.WithDefaultEndpoint("compute.googleapis.com"), + internaloption.WithDefaultMTLSEndpoint("compute.mtls.googleapis.com"), + internaloption.WithDefaultAudience("https://compute.googleapis.com/"), + internaloption.WithDefaultScopes(DefaultAuthScopes()...), + } +} + +// 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 *regionNetworkEndpointGroupsRESTClient) setGoogleClientInfo(keyval ...string) { + kv := append([]string{"gl-go", versionGo()}, keyval...) + kv = append(kv, "gapic", versionClient, "gax", gax.Version, "rest", "UNKNOWN") + 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 *regionNetworkEndpointGroupsRESTClient) Close() error { + // Replace httpClient with nil to force cleanup. + c.httpClient = nil + return nil +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *regionNetworkEndpointGroupsRESTClient) Connection() *grpc.ClientConn { + return nil +} + +// Delete deletes the specified network endpoint group. Note that the NEG cannot be deleted if it is configured as a backend of a backend service. +func (c *regionNetworkEndpointGroupsRESTClient) Delete(ctx context.Context, req *computepb.DeleteRegionNetworkEndpointGroupRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/regions/%v/networkEndpointGroups/%v", req.GetProject(), req.GetRegion(), req.GetNetworkEndpointGroup()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("DELETE", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Get returns the specified network endpoint group. Gets a list of available network endpoint groups by making a list() request. +func (c *regionNetworkEndpointGroupsRESTClient) Get(ctx context.Context, req *computepb.GetRegionNetworkEndpointGroupRequest, opts ...gax.CallOption) (*computepb.NetworkEndpointGroup, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/regions/%v/networkEndpointGroups/%v", req.GetProject(), req.GetRegion(), req.GetNetworkEndpointGroup()) + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.NetworkEndpointGroup{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Insert creates a network endpoint group in the specified project using the parameters that are included in the request. +func (c *regionNetworkEndpointGroupsRESTClient) Insert(ctx context.Context, req *computepb.InsertRegionNetworkEndpointGroupRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetNetworkEndpointGroupResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/regions/%v/networkEndpointGroups", req.GetProject(), req.GetRegion()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// List retrieves the list of regional network endpoint groups available to the specified project in the given region. +func (c *regionNetworkEndpointGroupsRESTClient) List(ctx context.Context, req *computepb.ListRegionNetworkEndpointGroupsRequest, opts ...gax.CallOption) (*computepb.NetworkEndpointGroupList, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/regions/%v/networkEndpointGroups", req.GetProject(), req.GetRegion()) + + params := url.Values{} + if req != nil && req.Filter != nil { + params.Add("filter", fmt.Sprintf("%v", req.GetFilter())) + } + if req != nil && req.MaxResults != nil { + params.Add("maxResults", fmt.Sprintf("%v", req.GetMaxResults())) + } + if req != nil && req.OrderBy != nil { + params.Add("orderBy", fmt.Sprintf("%v", req.GetOrderBy())) + } + if req != nil && req.PageToken != nil { + params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) + } + if req != nil && req.ReturnPartialSuccess != nil { + params.Add("returnPartialSuccess", fmt.Sprintf("%v", req.GetReturnPartialSuccess())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.NetworkEndpointGroupList{} + + return rsp, unm.Unmarshal(buf, rsp) +} diff --git a/compute/apiv1/region_network_endpoint_groups_client_example_test.go b/compute/apiv1/region_network_endpoint_groups_client_example_test.go new file mode 100644 index 00000000000..507dceea933 --- /dev/null +++ b/compute/apiv1/region_network_endpoint_groups_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 compute_test + +import ( + "context" + + compute "cloud.google.com/go/compute/apiv1" + computepb "google.golang.org/genproto/googleapis/cloud/compute/v1" +) + +func ExampleNewRegionNetworkEndpointGroupsRESTClient() { + ctx := context.Background() + c, err := compute.NewRegionNetworkEndpointGroupsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + // TODO: Use client. + _ = c +} + +func ExampleRegionNetworkEndpointGroupsClient_Delete() { + ctx := context.Background() + c, err := compute.NewRegionNetworkEndpointGroupsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.DeleteRegionNetworkEndpointGroupRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Delete(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleRegionNetworkEndpointGroupsClient_Get() { + ctx := context.Background() + c, err := compute.NewRegionNetworkEndpointGroupsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.GetRegionNetworkEndpointGroupRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Get(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleRegionNetworkEndpointGroupsClient_Insert() { + ctx := context.Background() + c, err := compute.NewRegionNetworkEndpointGroupsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.InsertRegionNetworkEndpointGroupRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Insert(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleRegionNetworkEndpointGroupsClient_List() { + ctx := context.Background() + c, err := compute.NewRegionNetworkEndpointGroupsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.ListRegionNetworkEndpointGroupsRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.List(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} diff --git a/compute/apiv1/region_notification_endpoints_client.go b/compute/apiv1/region_notification_endpoints_client.go new file mode 100644 index 00000000000..1ab16484260 --- /dev/null +++ b/compute/apiv1/region_notification_endpoints_client.go @@ -0,0 +1,380 @@ +// 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 compute + +import ( + "bytes" + "context" + "fmt" + "io/ioutil" + "net/http" + "net/url" + + gax "github.com/googleapis/gax-go/v2" + "google.golang.org/api/option" + "google.golang.org/api/option/internaloption" + httptransport "google.golang.org/api/transport/http" + computepb "google.golang.org/genproto/googleapis/cloud/compute/v1" + "google.golang.org/grpc" + "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/encoding/protojson" +) + +var newRegionNotificationEndpointsClientHook clientHook + +// RegionNotificationEndpointsCallOptions contains the retry settings for each method of RegionNotificationEndpointsClient. +type RegionNotificationEndpointsCallOptions struct { + Delete []gax.CallOption + Get []gax.CallOption + Insert []gax.CallOption + List []gax.CallOption +} + +// internalRegionNotificationEndpointsClient is an interface that defines the methods availaible from Google Compute Engine API. +type internalRegionNotificationEndpointsClient interface { + Close() error + setGoogleClientInfo(...string) + Connection() *grpc.ClientConn + Delete(context.Context, *computepb.DeleteRegionNotificationEndpointRequest, ...gax.CallOption) (*computepb.Operation, error) + Get(context.Context, *computepb.GetRegionNotificationEndpointRequest, ...gax.CallOption) (*computepb.NotificationEndpoint, error) + Insert(context.Context, *computepb.InsertRegionNotificationEndpointRequest, ...gax.CallOption) (*computepb.Operation, error) + List(context.Context, *computepb.ListRegionNotificationEndpointsRequest, ...gax.CallOption) (*computepb.NotificationEndpointList, error) +} + +// RegionNotificationEndpointsClient is a client for interacting with Google Compute Engine API. +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +// +// The RegionNotificationEndpoints API. +type RegionNotificationEndpointsClient struct { + // The internal transport-dependent client. + internalClient internalRegionNotificationEndpointsClient + + // The call options for this service. + CallOptions *RegionNotificationEndpointsCallOptions +} + +// 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 *RegionNotificationEndpointsClient) 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 *RegionNotificationEndpointsClient) setGoogleClientInfo(keyval ...string) { + c.internalClient.setGoogleClientInfo(keyval...) +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *RegionNotificationEndpointsClient) Connection() *grpc.ClientConn { + return c.internalClient.Connection() +} + +// Delete deletes the specified NotificationEndpoint in the given region +func (c *RegionNotificationEndpointsClient) Delete(ctx context.Context, req *computepb.DeleteRegionNotificationEndpointRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.Delete(ctx, req, opts...) +} + +// Get returns the specified NotificationEndpoint resource in the given region. +func (c *RegionNotificationEndpointsClient) Get(ctx context.Context, req *computepb.GetRegionNotificationEndpointRequest, opts ...gax.CallOption) (*computepb.NotificationEndpoint, error) { + return c.internalClient.Get(ctx, req, opts...) +} + +// Insert create a NotificationEndpoint in the specified project in the given region using the parameters that are included in the request. +func (c *RegionNotificationEndpointsClient) Insert(ctx context.Context, req *computepb.InsertRegionNotificationEndpointRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.Insert(ctx, req, opts...) +} + +// List lists the NotificationEndpoints for a project in the given region. +func (c *RegionNotificationEndpointsClient) List(ctx context.Context, req *computepb.ListRegionNotificationEndpointsRequest, opts ...gax.CallOption) (*computepb.NotificationEndpointList, error) { + return c.internalClient.List(ctx, req, opts...) +} + +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +type regionNotificationEndpointsRESTClient struct { + // The http endpoint to connect to. + endpoint string + + // The http client. + httpClient *http.Client + + // The x-goog-* metadata to be sent with each request. + xGoogMetadata metadata.MD +} + +// NewRegionNotificationEndpointsRESTClient creates a new region notification endpoints rest client. +// +// The RegionNotificationEndpoints API. +func NewRegionNotificationEndpointsRESTClient(ctx context.Context, opts ...option.ClientOption) (*RegionNotificationEndpointsClient, error) { + clientOpts := append(defaultRegionNotificationEndpointsRESTClientOptions(), opts...) + httpClient, endpoint, err := httptransport.NewClient(ctx, clientOpts...) + if err != nil { + return nil, err + } + + c := ®ionNotificationEndpointsRESTClient{ + endpoint: endpoint, + httpClient: httpClient, + } + c.setGoogleClientInfo() + + return &RegionNotificationEndpointsClient{internalClient: c, CallOptions: &RegionNotificationEndpointsCallOptions{}}, nil +} + +func defaultRegionNotificationEndpointsRESTClientOptions() []option.ClientOption { + return []option.ClientOption{ + internaloption.WithDefaultEndpoint("compute.googleapis.com"), + internaloption.WithDefaultMTLSEndpoint("compute.mtls.googleapis.com"), + internaloption.WithDefaultAudience("https://compute.googleapis.com/"), + internaloption.WithDefaultScopes(DefaultAuthScopes()...), + } +} + +// 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 *regionNotificationEndpointsRESTClient) setGoogleClientInfo(keyval ...string) { + kv := append([]string{"gl-go", versionGo()}, keyval...) + kv = append(kv, "gapic", versionClient, "gax", gax.Version, "rest", "UNKNOWN") + 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 *regionNotificationEndpointsRESTClient) Close() error { + // Replace httpClient with nil to force cleanup. + c.httpClient = nil + return nil +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *regionNotificationEndpointsRESTClient) Connection() *grpc.ClientConn { + return nil +} + +// Delete deletes the specified NotificationEndpoint in the given region +func (c *regionNotificationEndpointsRESTClient) Delete(ctx context.Context, req *computepb.DeleteRegionNotificationEndpointRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/regions/%v/notificationEndpoints/%v", req.GetProject(), req.GetRegion(), req.GetNotificationEndpoint()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("DELETE", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Get returns the specified NotificationEndpoint resource in the given region. +func (c *regionNotificationEndpointsRESTClient) Get(ctx context.Context, req *computepb.GetRegionNotificationEndpointRequest, opts ...gax.CallOption) (*computepb.NotificationEndpoint, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/regions/%v/notificationEndpoints/%v", req.GetProject(), req.GetRegion(), req.GetNotificationEndpoint()) + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.NotificationEndpoint{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Insert create a NotificationEndpoint in the specified project in the given region using the parameters that are included in the request. +func (c *regionNotificationEndpointsRESTClient) Insert(ctx context.Context, req *computepb.InsertRegionNotificationEndpointRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetNotificationEndpointResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/regions/%v/notificationEndpoints", req.GetProject(), req.GetRegion()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// List lists the NotificationEndpoints for a project in the given region. +func (c *regionNotificationEndpointsRESTClient) List(ctx context.Context, req *computepb.ListRegionNotificationEndpointsRequest, opts ...gax.CallOption) (*computepb.NotificationEndpointList, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/regions/%v/notificationEndpoints", req.GetProject(), req.GetRegion()) + + params := url.Values{} + if req != nil && req.Filter != nil { + params.Add("filter", fmt.Sprintf("%v", req.GetFilter())) + } + if req != nil && req.MaxResults != nil { + params.Add("maxResults", fmt.Sprintf("%v", req.GetMaxResults())) + } + if req != nil && req.OrderBy != nil { + params.Add("orderBy", fmt.Sprintf("%v", req.GetOrderBy())) + } + if req != nil && req.PageToken != nil { + params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) + } + if req != nil && req.ReturnPartialSuccess != nil { + params.Add("returnPartialSuccess", fmt.Sprintf("%v", req.GetReturnPartialSuccess())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.NotificationEndpointList{} + + return rsp, unm.Unmarshal(buf, rsp) +} diff --git a/compute/apiv1/region_notification_endpoints_client_example_test.go b/compute/apiv1/region_notification_endpoints_client_example_test.go new file mode 100644 index 00000000000..708851924c5 --- /dev/null +++ b/compute/apiv1/region_notification_endpoints_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 compute_test + +import ( + "context" + + compute "cloud.google.com/go/compute/apiv1" + computepb "google.golang.org/genproto/googleapis/cloud/compute/v1" +) + +func ExampleNewRegionNotificationEndpointsRESTClient() { + ctx := context.Background() + c, err := compute.NewRegionNotificationEndpointsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + // TODO: Use client. + _ = c +} + +func ExampleRegionNotificationEndpointsClient_Delete() { + ctx := context.Background() + c, err := compute.NewRegionNotificationEndpointsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.DeleteRegionNotificationEndpointRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Delete(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleRegionNotificationEndpointsClient_Get() { + ctx := context.Background() + c, err := compute.NewRegionNotificationEndpointsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.GetRegionNotificationEndpointRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Get(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleRegionNotificationEndpointsClient_Insert() { + ctx := context.Background() + c, err := compute.NewRegionNotificationEndpointsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.InsertRegionNotificationEndpointRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Insert(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleRegionNotificationEndpointsClient_List() { + ctx := context.Background() + c, err := compute.NewRegionNotificationEndpointsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.ListRegionNotificationEndpointsRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.List(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} diff --git a/compute/apiv1/region_operations_client.go b/compute/apiv1/region_operations_client.go new file mode 100644 index 00000000000..cccff7a0508 --- /dev/null +++ b/compute/apiv1/region_operations_client.go @@ -0,0 +1,377 @@ +// 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 compute + +import ( + "bytes" + "context" + "fmt" + "io/ioutil" + "net/http" + "net/url" + + gax "github.com/googleapis/gax-go/v2" + "google.golang.org/api/option" + "google.golang.org/api/option/internaloption" + httptransport "google.golang.org/api/transport/http" + computepb "google.golang.org/genproto/googleapis/cloud/compute/v1" + "google.golang.org/grpc" + "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/encoding/protojson" +) + +var newRegionOperationsClientHook clientHook + +// RegionOperationsCallOptions contains the retry settings for each method of RegionOperationsClient. +type RegionOperationsCallOptions struct { + Delete []gax.CallOption + Get []gax.CallOption + List []gax.CallOption + Wait []gax.CallOption +} + +// internalRegionOperationsClient is an interface that defines the methods availaible from Google Compute Engine API. +type internalRegionOperationsClient interface { + Close() error + setGoogleClientInfo(...string) + Connection() *grpc.ClientConn + Delete(context.Context, *computepb.DeleteRegionOperationRequest, ...gax.CallOption) (*computepb.DeleteRegionOperationResponse, error) + Get(context.Context, *computepb.GetRegionOperationRequest, ...gax.CallOption) (*computepb.Operation, error) + List(context.Context, *computepb.ListRegionOperationsRequest, ...gax.CallOption) (*computepb.OperationList, error) + Wait(context.Context, *computepb.WaitRegionOperationRequest, ...gax.CallOption) (*computepb.Operation, error) +} + +// RegionOperationsClient is a client for interacting with Google Compute Engine API. +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +// +// The RegionOperations API. +type RegionOperationsClient struct { + // The internal transport-dependent client. + internalClient internalRegionOperationsClient + + // The call options for this service. + CallOptions *RegionOperationsCallOptions +} + +// 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 *RegionOperationsClient) 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 *RegionOperationsClient) setGoogleClientInfo(keyval ...string) { + c.internalClient.setGoogleClientInfo(keyval...) +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *RegionOperationsClient) Connection() *grpc.ClientConn { + return c.internalClient.Connection() +} + +// Delete deletes the specified region-specific Operations resource. +func (c *RegionOperationsClient) Delete(ctx context.Context, req *computepb.DeleteRegionOperationRequest, opts ...gax.CallOption) (*computepb.DeleteRegionOperationResponse, error) { + return c.internalClient.Delete(ctx, req, opts...) +} + +// Get retrieves the specified region-specific Operations resource. +func (c *RegionOperationsClient) Get(ctx context.Context, req *computepb.GetRegionOperationRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.Get(ctx, req, opts...) +} + +// List retrieves a list of Operation resources contained within the specified region. +func (c *RegionOperationsClient) List(ctx context.Context, req *computepb.ListRegionOperationsRequest, opts ...gax.CallOption) (*computepb.OperationList, error) { + return c.internalClient.List(ctx, req, opts...) +} + +// Wait waits for the specified Operation resource to return as DONE or for the request to approach the 2 minute deadline, and retrieves the specified Operation resource. This method differs from the GET method in that it waits for no more than the default deadline (2 minutes) and then returns the current state of the operation, which might be DONE or still in progress. +// +// This method is called on a best-effort basis. Specifically: +// +// In uncommon cases, when the server is overloaded, the request might return before the default deadline is reached, or might return after zero seconds. +// +// If the default deadline is reached, there is no guarantee that the operation is actually done when the method returns. Be prepared to retry if the operation is not DONE. +func (c *RegionOperationsClient) Wait(ctx context.Context, req *computepb.WaitRegionOperationRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.Wait(ctx, req, opts...) +} + +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +type regionOperationsRESTClient struct { + // The http endpoint to connect to. + endpoint string + + // The http client. + httpClient *http.Client + + // The x-goog-* metadata to be sent with each request. + xGoogMetadata metadata.MD +} + +// NewRegionOperationsRESTClient creates a new region operations rest client. +// +// The RegionOperations API. +func NewRegionOperationsRESTClient(ctx context.Context, opts ...option.ClientOption) (*RegionOperationsClient, error) { + clientOpts := append(defaultRegionOperationsRESTClientOptions(), opts...) + httpClient, endpoint, err := httptransport.NewClient(ctx, clientOpts...) + if err != nil { + return nil, err + } + + c := ®ionOperationsRESTClient{ + endpoint: endpoint, + httpClient: httpClient, + } + c.setGoogleClientInfo() + + return &RegionOperationsClient{internalClient: c, CallOptions: &RegionOperationsCallOptions{}}, nil +} + +func defaultRegionOperationsRESTClientOptions() []option.ClientOption { + return []option.ClientOption{ + internaloption.WithDefaultEndpoint("compute.googleapis.com"), + internaloption.WithDefaultMTLSEndpoint("compute.mtls.googleapis.com"), + internaloption.WithDefaultAudience("https://compute.googleapis.com/"), + internaloption.WithDefaultScopes(DefaultAuthScopes()...), + } +} + +// 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 *regionOperationsRESTClient) setGoogleClientInfo(keyval ...string) { + kv := append([]string{"gl-go", versionGo()}, keyval...) + kv = append(kv, "gapic", versionClient, "gax", gax.Version, "rest", "UNKNOWN") + 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 *regionOperationsRESTClient) Close() error { + // Replace httpClient with nil to force cleanup. + c.httpClient = nil + return nil +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *regionOperationsRESTClient) Connection() *grpc.ClientConn { + return nil +} + +// Delete deletes the specified region-specific Operations resource. +func (c *regionOperationsRESTClient) Delete(ctx context.Context, req *computepb.DeleteRegionOperationRequest, opts ...gax.CallOption) (*computepb.DeleteRegionOperationResponse, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/regions/%v/operations/%v", req.GetProject(), req.GetRegion(), req.GetOperation()) + + httpReq, err := http.NewRequest("DELETE", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.DeleteRegionOperationResponse{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Get retrieves the specified region-specific Operations resource. +func (c *regionOperationsRESTClient) Get(ctx context.Context, req *computepb.GetRegionOperationRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/regions/%v/operations/%v", req.GetProject(), req.GetRegion(), req.GetOperation()) + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// List retrieves a list of Operation resources contained within the specified region. +func (c *regionOperationsRESTClient) List(ctx context.Context, req *computepb.ListRegionOperationsRequest, opts ...gax.CallOption) (*computepb.OperationList, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/regions/%v/operations", req.GetProject(), req.GetRegion()) + + params := url.Values{} + if req != nil && req.Filter != nil { + params.Add("filter", fmt.Sprintf("%v", req.GetFilter())) + } + if req != nil && req.MaxResults != nil { + params.Add("maxResults", fmt.Sprintf("%v", req.GetMaxResults())) + } + if req != nil && req.OrderBy != nil { + params.Add("orderBy", fmt.Sprintf("%v", req.GetOrderBy())) + } + if req != nil && req.PageToken != nil { + params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) + } + if req != nil && req.ReturnPartialSuccess != nil { + params.Add("returnPartialSuccess", fmt.Sprintf("%v", req.GetReturnPartialSuccess())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.OperationList{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Wait waits for the specified Operation resource to return as DONE or for the request to approach the 2 minute deadline, and retrieves the specified Operation resource. This method differs from the GET method in that it waits for no more than the default deadline (2 minutes) and then returns the current state of the operation, which might be DONE or still in progress. +// +// This method is called on a best-effort basis. Specifically: +// +// In uncommon cases, when the server is overloaded, the request might return before the default deadline is reached, or might return after zero seconds. +// +// If the default deadline is reached, there is no guarantee that the operation is actually done when the method returns. Be prepared to retry if the operation is not DONE. +func (c *regionOperationsRESTClient) Wait(ctx context.Context, req *computepb.WaitRegionOperationRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/regions/%v/operations/%v/wait", req.GetProject(), req.GetRegion(), req.GetOperation()) + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} diff --git a/compute/apiv1/region_operations_client_example_test.go b/compute/apiv1/region_operations_client_example_test.go new file mode 100644 index 00000000000..75736e6becc --- /dev/null +++ b/compute/apiv1/region_operations_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 compute_test + +import ( + "context" + + compute "cloud.google.com/go/compute/apiv1" + computepb "google.golang.org/genproto/googleapis/cloud/compute/v1" +) + +func ExampleNewRegionOperationsRESTClient() { + ctx := context.Background() + c, err := compute.NewRegionOperationsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + // TODO: Use client. + _ = c +} + +func ExampleRegionOperationsClient_Delete() { + ctx := context.Background() + c, err := compute.NewRegionOperationsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.DeleteRegionOperationRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Delete(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleRegionOperationsClient_Get() { + ctx := context.Background() + c, err := compute.NewRegionOperationsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.GetRegionOperationRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Get(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleRegionOperationsClient_List() { + ctx := context.Background() + c, err := compute.NewRegionOperationsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.ListRegionOperationsRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.List(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleRegionOperationsClient_Wait() { + ctx := context.Background() + c, err := compute.NewRegionOperationsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.WaitRegionOperationRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Wait(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} diff --git a/compute/apiv1/region_ssl_certificates_client.go b/compute/apiv1/region_ssl_certificates_client.go new file mode 100644 index 00000000000..bcf069420d6 --- /dev/null +++ b/compute/apiv1/region_ssl_certificates_client.go @@ -0,0 +1,380 @@ +// 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 compute + +import ( + "bytes" + "context" + "fmt" + "io/ioutil" + "net/http" + "net/url" + + gax "github.com/googleapis/gax-go/v2" + "google.golang.org/api/option" + "google.golang.org/api/option/internaloption" + httptransport "google.golang.org/api/transport/http" + computepb "google.golang.org/genproto/googleapis/cloud/compute/v1" + "google.golang.org/grpc" + "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/encoding/protojson" +) + +var newRegionSslCertificatesClientHook clientHook + +// RegionSslCertificatesCallOptions contains the retry settings for each method of RegionSslCertificatesClient. +type RegionSslCertificatesCallOptions struct { + Delete []gax.CallOption + Get []gax.CallOption + Insert []gax.CallOption + List []gax.CallOption +} + +// internalRegionSslCertificatesClient is an interface that defines the methods availaible from Google Compute Engine API. +type internalRegionSslCertificatesClient interface { + Close() error + setGoogleClientInfo(...string) + Connection() *grpc.ClientConn + Delete(context.Context, *computepb.DeleteRegionSslCertificateRequest, ...gax.CallOption) (*computepb.Operation, error) + Get(context.Context, *computepb.GetRegionSslCertificateRequest, ...gax.CallOption) (*computepb.SslCertificate, error) + Insert(context.Context, *computepb.InsertRegionSslCertificateRequest, ...gax.CallOption) (*computepb.Operation, error) + List(context.Context, *computepb.ListRegionSslCertificatesRequest, ...gax.CallOption) (*computepb.SslCertificateList, error) +} + +// RegionSslCertificatesClient is a client for interacting with Google Compute Engine API. +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +// +// The RegionSslCertificates API. +type RegionSslCertificatesClient struct { + // The internal transport-dependent client. + internalClient internalRegionSslCertificatesClient + + // The call options for this service. + CallOptions *RegionSslCertificatesCallOptions +} + +// 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 *RegionSslCertificatesClient) 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 *RegionSslCertificatesClient) setGoogleClientInfo(keyval ...string) { + c.internalClient.setGoogleClientInfo(keyval...) +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *RegionSslCertificatesClient) Connection() *grpc.ClientConn { + return c.internalClient.Connection() +} + +// Delete deletes the specified SslCertificate resource in the region. +func (c *RegionSslCertificatesClient) Delete(ctx context.Context, req *computepb.DeleteRegionSslCertificateRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.Delete(ctx, req, opts...) +} + +// Get returns the specified SslCertificate resource in the specified region. Get a list of available SSL certificates by making a list() request. +func (c *RegionSslCertificatesClient) Get(ctx context.Context, req *computepb.GetRegionSslCertificateRequest, opts ...gax.CallOption) (*computepb.SslCertificate, error) { + return c.internalClient.Get(ctx, req, opts...) +} + +// Insert creates a SslCertificate resource in the specified project and region using the data included in the request +func (c *RegionSslCertificatesClient) Insert(ctx context.Context, req *computepb.InsertRegionSslCertificateRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.Insert(ctx, req, opts...) +} + +// List retrieves the list of SslCertificate resources available to the specified project in the specified region. +func (c *RegionSslCertificatesClient) List(ctx context.Context, req *computepb.ListRegionSslCertificatesRequest, opts ...gax.CallOption) (*computepb.SslCertificateList, error) { + return c.internalClient.List(ctx, req, opts...) +} + +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +type regionSslCertificatesRESTClient struct { + // The http endpoint to connect to. + endpoint string + + // The http client. + httpClient *http.Client + + // The x-goog-* metadata to be sent with each request. + xGoogMetadata metadata.MD +} + +// NewRegionSslCertificatesRESTClient creates a new region ssl certificates rest client. +// +// The RegionSslCertificates API. +func NewRegionSslCertificatesRESTClient(ctx context.Context, opts ...option.ClientOption) (*RegionSslCertificatesClient, error) { + clientOpts := append(defaultRegionSslCertificatesRESTClientOptions(), opts...) + httpClient, endpoint, err := httptransport.NewClient(ctx, clientOpts...) + if err != nil { + return nil, err + } + + c := ®ionSslCertificatesRESTClient{ + endpoint: endpoint, + httpClient: httpClient, + } + c.setGoogleClientInfo() + + return &RegionSslCertificatesClient{internalClient: c, CallOptions: &RegionSslCertificatesCallOptions{}}, nil +} + +func defaultRegionSslCertificatesRESTClientOptions() []option.ClientOption { + return []option.ClientOption{ + internaloption.WithDefaultEndpoint("compute.googleapis.com"), + internaloption.WithDefaultMTLSEndpoint("compute.mtls.googleapis.com"), + internaloption.WithDefaultAudience("https://compute.googleapis.com/"), + internaloption.WithDefaultScopes(DefaultAuthScopes()...), + } +} + +// 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 *regionSslCertificatesRESTClient) setGoogleClientInfo(keyval ...string) { + kv := append([]string{"gl-go", versionGo()}, keyval...) + kv = append(kv, "gapic", versionClient, "gax", gax.Version, "rest", "UNKNOWN") + 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 *regionSslCertificatesRESTClient) Close() error { + // Replace httpClient with nil to force cleanup. + c.httpClient = nil + return nil +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *regionSslCertificatesRESTClient) Connection() *grpc.ClientConn { + return nil +} + +// Delete deletes the specified SslCertificate resource in the region. +func (c *regionSslCertificatesRESTClient) Delete(ctx context.Context, req *computepb.DeleteRegionSslCertificateRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/regions/%v/sslCertificates/%v", req.GetProject(), req.GetRegion(), req.GetSslCertificate()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("DELETE", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Get returns the specified SslCertificate resource in the specified region. Get a list of available SSL certificates by making a list() request. +func (c *regionSslCertificatesRESTClient) Get(ctx context.Context, req *computepb.GetRegionSslCertificateRequest, opts ...gax.CallOption) (*computepb.SslCertificate, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/regions/%v/sslCertificates/%v", req.GetProject(), req.GetRegion(), req.GetSslCertificate()) + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.SslCertificate{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Insert creates a SslCertificate resource in the specified project and region using the data included in the request +func (c *regionSslCertificatesRESTClient) Insert(ctx context.Context, req *computepb.InsertRegionSslCertificateRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetSslCertificateResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/regions/%v/sslCertificates", req.GetProject(), req.GetRegion()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// List retrieves the list of SslCertificate resources available to the specified project in the specified region. +func (c *regionSslCertificatesRESTClient) List(ctx context.Context, req *computepb.ListRegionSslCertificatesRequest, opts ...gax.CallOption) (*computepb.SslCertificateList, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/regions/%v/sslCertificates", req.GetProject(), req.GetRegion()) + + params := url.Values{} + if req != nil && req.Filter != nil { + params.Add("filter", fmt.Sprintf("%v", req.GetFilter())) + } + if req != nil && req.MaxResults != nil { + params.Add("maxResults", fmt.Sprintf("%v", req.GetMaxResults())) + } + if req != nil && req.OrderBy != nil { + params.Add("orderBy", fmt.Sprintf("%v", req.GetOrderBy())) + } + if req != nil && req.PageToken != nil { + params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) + } + if req != nil && req.ReturnPartialSuccess != nil { + params.Add("returnPartialSuccess", fmt.Sprintf("%v", req.GetReturnPartialSuccess())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.SslCertificateList{} + + return rsp, unm.Unmarshal(buf, rsp) +} diff --git a/compute/apiv1/region_ssl_certificates_client_example_test.go b/compute/apiv1/region_ssl_certificates_client_example_test.go new file mode 100644 index 00000000000..016dcb96a14 --- /dev/null +++ b/compute/apiv1/region_ssl_certificates_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 compute_test + +import ( + "context" + + compute "cloud.google.com/go/compute/apiv1" + computepb "google.golang.org/genproto/googleapis/cloud/compute/v1" +) + +func ExampleNewRegionSslCertificatesRESTClient() { + ctx := context.Background() + c, err := compute.NewRegionSslCertificatesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + // TODO: Use client. + _ = c +} + +func ExampleRegionSslCertificatesClient_Delete() { + ctx := context.Background() + c, err := compute.NewRegionSslCertificatesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.DeleteRegionSslCertificateRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Delete(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleRegionSslCertificatesClient_Get() { + ctx := context.Background() + c, err := compute.NewRegionSslCertificatesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.GetRegionSslCertificateRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Get(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleRegionSslCertificatesClient_Insert() { + ctx := context.Background() + c, err := compute.NewRegionSslCertificatesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.InsertRegionSslCertificateRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Insert(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleRegionSslCertificatesClient_List() { + ctx := context.Background() + c, err := compute.NewRegionSslCertificatesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.ListRegionSslCertificatesRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.List(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} diff --git a/compute/apiv1/region_target_http_proxies_client.go b/compute/apiv1/region_target_http_proxies_client.go new file mode 100644 index 00000000000..f2a338841e2 --- /dev/null +++ b/compute/apiv1/region_target_http_proxies_client.go @@ -0,0 +1,438 @@ +// 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 compute + +import ( + "bytes" + "context" + "fmt" + "io/ioutil" + "net/http" + "net/url" + + gax "github.com/googleapis/gax-go/v2" + "google.golang.org/api/option" + "google.golang.org/api/option/internaloption" + httptransport "google.golang.org/api/transport/http" + computepb "google.golang.org/genproto/googleapis/cloud/compute/v1" + "google.golang.org/grpc" + "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/encoding/protojson" +) + +var newRegionTargetHttpProxiesClientHook clientHook + +// RegionTargetHttpProxiesCallOptions contains the retry settings for each method of RegionTargetHttpProxiesClient. +type RegionTargetHttpProxiesCallOptions struct { + Delete []gax.CallOption + Get []gax.CallOption + Insert []gax.CallOption + List []gax.CallOption + SetUrlMap []gax.CallOption +} + +// internalRegionTargetHttpProxiesClient is an interface that defines the methods availaible from Google Compute Engine API. +type internalRegionTargetHttpProxiesClient interface { + Close() error + setGoogleClientInfo(...string) + Connection() *grpc.ClientConn + Delete(context.Context, *computepb.DeleteRegionTargetHttpProxyRequest, ...gax.CallOption) (*computepb.Operation, error) + Get(context.Context, *computepb.GetRegionTargetHttpProxyRequest, ...gax.CallOption) (*computepb.TargetHttpProxy, error) + Insert(context.Context, *computepb.InsertRegionTargetHttpProxyRequest, ...gax.CallOption) (*computepb.Operation, error) + List(context.Context, *computepb.ListRegionTargetHttpProxiesRequest, ...gax.CallOption) (*computepb.TargetHttpProxyList, error) + SetUrlMap(context.Context, *computepb.SetUrlMapRegionTargetHttpProxyRequest, ...gax.CallOption) (*computepb.Operation, error) +} + +// RegionTargetHttpProxiesClient is a client for interacting with Google Compute Engine API. +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +// +// The RegionTargetHttpProxies API. +type RegionTargetHttpProxiesClient struct { + // The internal transport-dependent client. + internalClient internalRegionTargetHttpProxiesClient + + // The call options for this service. + CallOptions *RegionTargetHttpProxiesCallOptions +} + +// 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 *RegionTargetHttpProxiesClient) 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 *RegionTargetHttpProxiesClient) setGoogleClientInfo(keyval ...string) { + c.internalClient.setGoogleClientInfo(keyval...) +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *RegionTargetHttpProxiesClient) Connection() *grpc.ClientConn { + return c.internalClient.Connection() +} + +// Delete deletes the specified TargetHttpProxy resource. +func (c *RegionTargetHttpProxiesClient) Delete(ctx context.Context, req *computepb.DeleteRegionTargetHttpProxyRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.Delete(ctx, req, opts...) +} + +// Get returns the specified TargetHttpProxy resource in the specified region. Gets a list of available target HTTP proxies by making a list() request. +func (c *RegionTargetHttpProxiesClient) Get(ctx context.Context, req *computepb.GetRegionTargetHttpProxyRequest, opts ...gax.CallOption) (*computepb.TargetHttpProxy, error) { + return c.internalClient.Get(ctx, req, opts...) +} + +// Insert creates a TargetHttpProxy resource in the specified project and region using the data included in the request. +func (c *RegionTargetHttpProxiesClient) Insert(ctx context.Context, req *computepb.InsertRegionTargetHttpProxyRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.Insert(ctx, req, opts...) +} + +// List retrieves the list of TargetHttpProxy resources available to the specified project in the specified region. +func (c *RegionTargetHttpProxiesClient) List(ctx context.Context, req *computepb.ListRegionTargetHttpProxiesRequest, opts ...gax.CallOption) (*computepb.TargetHttpProxyList, error) { + return c.internalClient.List(ctx, req, opts...) +} + +// SetUrlMap changes the URL map for TargetHttpProxy. +func (c *RegionTargetHttpProxiesClient) SetUrlMap(ctx context.Context, req *computepb.SetUrlMapRegionTargetHttpProxyRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.SetUrlMap(ctx, req, opts...) +} + +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +type regionTargetHttpProxiesRESTClient struct { + // The http endpoint to connect to. + endpoint string + + // The http client. + httpClient *http.Client + + // The x-goog-* metadata to be sent with each request. + xGoogMetadata metadata.MD +} + +// NewRegionTargetHttpProxiesRESTClient creates a new region target http proxies rest client. +// +// The RegionTargetHttpProxies API. +func NewRegionTargetHttpProxiesRESTClient(ctx context.Context, opts ...option.ClientOption) (*RegionTargetHttpProxiesClient, error) { + clientOpts := append(defaultRegionTargetHttpProxiesRESTClientOptions(), opts...) + httpClient, endpoint, err := httptransport.NewClient(ctx, clientOpts...) + if err != nil { + return nil, err + } + + c := ®ionTargetHttpProxiesRESTClient{ + endpoint: endpoint, + httpClient: httpClient, + } + c.setGoogleClientInfo() + + return &RegionTargetHttpProxiesClient{internalClient: c, CallOptions: &RegionTargetHttpProxiesCallOptions{}}, nil +} + +func defaultRegionTargetHttpProxiesRESTClientOptions() []option.ClientOption { + return []option.ClientOption{ + internaloption.WithDefaultEndpoint("compute.googleapis.com"), + internaloption.WithDefaultMTLSEndpoint("compute.mtls.googleapis.com"), + internaloption.WithDefaultAudience("https://compute.googleapis.com/"), + internaloption.WithDefaultScopes(DefaultAuthScopes()...), + } +} + +// 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 *regionTargetHttpProxiesRESTClient) setGoogleClientInfo(keyval ...string) { + kv := append([]string{"gl-go", versionGo()}, keyval...) + kv = append(kv, "gapic", versionClient, "gax", gax.Version, "rest", "UNKNOWN") + 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 *regionTargetHttpProxiesRESTClient) Close() error { + // Replace httpClient with nil to force cleanup. + c.httpClient = nil + return nil +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *regionTargetHttpProxiesRESTClient) Connection() *grpc.ClientConn { + return nil +} + +// Delete deletes the specified TargetHttpProxy resource. +func (c *regionTargetHttpProxiesRESTClient) Delete(ctx context.Context, req *computepb.DeleteRegionTargetHttpProxyRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/regions/%v/targetHttpProxies/%v", req.GetProject(), req.GetRegion(), req.GetTargetHttpProxy()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("DELETE", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Get returns the specified TargetHttpProxy resource in the specified region. Gets a list of available target HTTP proxies by making a list() request. +func (c *regionTargetHttpProxiesRESTClient) Get(ctx context.Context, req *computepb.GetRegionTargetHttpProxyRequest, opts ...gax.CallOption) (*computepb.TargetHttpProxy, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/regions/%v/targetHttpProxies/%v", req.GetProject(), req.GetRegion(), req.GetTargetHttpProxy()) + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.TargetHttpProxy{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Insert creates a TargetHttpProxy resource in the specified project and region using the data included in the request. +func (c *regionTargetHttpProxiesRESTClient) Insert(ctx context.Context, req *computepb.InsertRegionTargetHttpProxyRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetTargetHttpProxyResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/regions/%v/targetHttpProxies", req.GetProject(), req.GetRegion()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// List retrieves the list of TargetHttpProxy resources available to the specified project in the specified region. +func (c *regionTargetHttpProxiesRESTClient) List(ctx context.Context, req *computepb.ListRegionTargetHttpProxiesRequest, opts ...gax.CallOption) (*computepb.TargetHttpProxyList, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/regions/%v/targetHttpProxies", req.GetProject(), req.GetRegion()) + + params := url.Values{} + if req != nil && req.Filter != nil { + params.Add("filter", fmt.Sprintf("%v", req.GetFilter())) + } + if req != nil && req.MaxResults != nil { + params.Add("maxResults", fmt.Sprintf("%v", req.GetMaxResults())) + } + if req != nil && req.OrderBy != nil { + params.Add("orderBy", fmt.Sprintf("%v", req.GetOrderBy())) + } + if req != nil && req.PageToken != nil { + params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) + } + if req != nil && req.ReturnPartialSuccess != nil { + params.Add("returnPartialSuccess", fmt.Sprintf("%v", req.GetReturnPartialSuccess())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.TargetHttpProxyList{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// SetUrlMap changes the URL map for TargetHttpProxy. +func (c *regionTargetHttpProxiesRESTClient) SetUrlMap(ctx context.Context, req *computepb.SetUrlMapRegionTargetHttpProxyRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetUrlMapReferenceResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/regions/%v/targetHttpProxies/%v/setUrlMap", req.GetProject(), req.GetRegion(), req.GetTargetHttpProxy()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} diff --git a/compute/apiv1/region_target_http_proxies_client_example_test.go b/compute/apiv1/region_target_http_proxies_client_example_test.go new file mode 100644 index 00000000000..0ccd58f88ce --- /dev/null +++ b/compute/apiv1/region_target_http_proxies_client_example_test.go @@ -0,0 +1,131 @@ +// 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 compute_test + +import ( + "context" + + compute "cloud.google.com/go/compute/apiv1" + computepb "google.golang.org/genproto/googleapis/cloud/compute/v1" +) + +func ExampleNewRegionTargetHttpProxiesRESTClient() { + ctx := context.Background() + c, err := compute.NewRegionTargetHttpProxiesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + // TODO: Use client. + _ = c +} + +func ExampleRegionTargetHttpProxiesClient_Delete() { + ctx := context.Background() + c, err := compute.NewRegionTargetHttpProxiesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.DeleteRegionTargetHttpProxyRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Delete(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleRegionTargetHttpProxiesClient_Get() { + ctx := context.Background() + c, err := compute.NewRegionTargetHttpProxiesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.GetRegionTargetHttpProxyRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Get(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleRegionTargetHttpProxiesClient_Insert() { + ctx := context.Background() + c, err := compute.NewRegionTargetHttpProxiesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.InsertRegionTargetHttpProxyRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Insert(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleRegionTargetHttpProxiesClient_List() { + ctx := context.Background() + c, err := compute.NewRegionTargetHttpProxiesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.ListRegionTargetHttpProxiesRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.List(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleRegionTargetHttpProxiesClient_SetUrlMap() { + ctx := context.Background() + c, err := compute.NewRegionTargetHttpProxiesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.SetUrlMapRegionTargetHttpProxyRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.SetUrlMap(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} diff --git a/compute/apiv1/region_target_https_proxies_client.go b/compute/apiv1/region_target_https_proxies_client.go new file mode 100644 index 00000000000..af6c5481aa6 --- /dev/null +++ b/compute/apiv1/region_target_https_proxies_client.go @@ -0,0 +1,496 @@ +// 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 compute + +import ( + "bytes" + "context" + "fmt" + "io/ioutil" + "net/http" + "net/url" + + gax "github.com/googleapis/gax-go/v2" + "google.golang.org/api/option" + "google.golang.org/api/option/internaloption" + httptransport "google.golang.org/api/transport/http" + computepb "google.golang.org/genproto/googleapis/cloud/compute/v1" + "google.golang.org/grpc" + "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/encoding/protojson" +) + +var newRegionTargetHttpsProxiesClientHook clientHook + +// RegionTargetHttpsProxiesCallOptions contains the retry settings for each method of RegionTargetHttpsProxiesClient. +type RegionTargetHttpsProxiesCallOptions struct { + Delete []gax.CallOption + Get []gax.CallOption + Insert []gax.CallOption + List []gax.CallOption + SetSslCertificates []gax.CallOption + SetUrlMap []gax.CallOption +} + +// internalRegionTargetHttpsProxiesClient is an interface that defines the methods availaible from Google Compute Engine API. +type internalRegionTargetHttpsProxiesClient interface { + Close() error + setGoogleClientInfo(...string) + Connection() *grpc.ClientConn + Delete(context.Context, *computepb.DeleteRegionTargetHttpsProxyRequest, ...gax.CallOption) (*computepb.Operation, error) + Get(context.Context, *computepb.GetRegionTargetHttpsProxyRequest, ...gax.CallOption) (*computepb.TargetHttpsProxy, error) + Insert(context.Context, *computepb.InsertRegionTargetHttpsProxyRequest, ...gax.CallOption) (*computepb.Operation, error) + List(context.Context, *computepb.ListRegionTargetHttpsProxiesRequest, ...gax.CallOption) (*computepb.TargetHttpsProxyList, error) + SetSslCertificates(context.Context, *computepb.SetSslCertificatesRegionTargetHttpsProxyRequest, ...gax.CallOption) (*computepb.Operation, error) + SetUrlMap(context.Context, *computepb.SetUrlMapRegionTargetHttpsProxyRequest, ...gax.CallOption) (*computepb.Operation, error) +} + +// RegionTargetHttpsProxiesClient is a client for interacting with Google Compute Engine API. +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +// +// The RegionTargetHttpsProxies API. +type RegionTargetHttpsProxiesClient struct { + // The internal transport-dependent client. + internalClient internalRegionTargetHttpsProxiesClient + + // The call options for this service. + CallOptions *RegionTargetHttpsProxiesCallOptions +} + +// 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 *RegionTargetHttpsProxiesClient) 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 *RegionTargetHttpsProxiesClient) setGoogleClientInfo(keyval ...string) { + c.internalClient.setGoogleClientInfo(keyval...) +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *RegionTargetHttpsProxiesClient) Connection() *grpc.ClientConn { + return c.internalClient.Connection() +} + +// Delete deletes the specified TargetHttpsProxy resource. +func (c *RegionTargetHttpsProxiesClient) Delete(ctx context.Context, req *computepb.DeleteRegionTargetHttpsProxyRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.Delete(ctx, req, opts...) +} + +// Get returns the specified TargetHttpsProxy resource in the specified region. Gets a list of available target HTTP proxies by making a list() request. +func (c *RegionTargetHttpsProxiesClient) Get(ctx context.Context, req *computepb.GetRegionTargetHttpsProxyRequest, opts ...gax.CallOption) (*computepb.TargetHttpsProxy, error) { + return c.internalClient.Get(ctx, req, opts...) +} + +// Insert creates a TargetHttpsProxy resource in the specified project and region using the data included in the request. +func (c *RegionTargetHttpsProxiesClient) Insert(ctx context.Context, req *computepb.InsertRegionTargetHttpsProxyRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.Insert(ctx, req, opts...) +} + +// List retrieves the list of TargetHttpsProxy resources available to the specified project in the specified region. +func (c *RegionTargetHttpsProxiesClient) List(ctx context.Context, req *computepb.ListRegionTargetHttpsProxiesRequest, opts ...gax.CallOption) (*computepb.TargetHttpsProxyList, error) { + return c.internalClient.List(ctx, req, opts...) +} + +// SetSslCertificates replaces SslCertificates for TargetHttpsProxy. +func (c *RegionTargetHttpsProxiesClient) SetSslCertificates(ctx context.Context, req *computepb.SetSslCertificatesRegionTargetHttpsProxyRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.SetSslCertificates(ctx, req, opts...) +} + +// SetUrlMap changes the URL map for TargetHttpsProxy. +func (c *RegionTargetHttpsProxiesClient) SetUrlMap(ctx context.Context, req *computepb.SetUrlMapRegionTargetHttpsProxyRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.SetUrlMap(ctx, req, opts...) +} + +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +type regionTargetHttpsProxiesRESTClient struct { + // The http endpoint to connect to. + endpoint string + + // The http client. + httpClient *http.Client + + // The x-goog-* metadata to be sent with each request. + xGoogMetadata metadata.MD +} + +// NewRegionTargetHttpsProxiesRESTClient creates a new region target https proxies rest client. +// +// The RegionTargetHttpsProxies API. +func NewRegionTargetHttpsProxiesRESTClient(ctx context.Context, opts ...option.ClientOption) (*RegionTargetHttpsProxiesClient, error) { + clientOpts := append(defaultRegionTargetHttpsProxiesRESTClientOptions(), opts...) + httpClient, endpoint, err := httptransport.NewClient(ctx, clientOpts...) + if err != nil { + return nil, err + } + + c := ®ionTargetHttpsProxiesRESTClient{ + endpoint: endpoint, + httpClient: httpClient, + } + c.setGoogleClientInfo() + + return &RegionTargetHttpsProxiesClient{internalClient: c, CallOptions: &RegionTargetHttpsProxiesCallOptions{}}, nil +} + +func defaultRegionTargetHttpsProxiesRESTClientOptions() []option.ClientOption { + return []option.ClientOption{ + internaloption.WithDefaultEndpoint("compute.googleapis.com"), + internaloption.WithDefaultMTLSEndpoint("compute.mtls.googleapis.com"), + internaloption.WithDefaultAudience("https://compute.googleapis.com/"), + internaloption.WithDefaultScopes(DefaultAuthScopes()...), + } +} + +// 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 *regionTargetHttpsProxiesRESTClient) setGoogleClientInfo(keyval ...string) { + kv := append([]string{"gl-go", versionGo()}, keyval...) + kv = append(kv, "gapic", versionClient, "gax", gax.Version, "rest", "UNKNOWN") + 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 *regionTargetHttpsProxiesRESTClient) Close() error { + // Replace httpClient with nil to force cleanup. + c.httpClient = nil + return nil +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *regionTargetHttpsProxiesRESTClient) Connection() *grpc.ClientConn { + return nil +} + +// Delete deletes the specified TargetHttpsProxy resource. +func (c *regionTargetHttpsProxiesRESTClient) Delete(ctx context.Context, req *computepb.DeleteRegionTargetHttpsProxyRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/regions/%v/targetHttpsProxies/%v", req.GetProject(), req.GetRegion(), req.GetTargetHttpsProxy()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("DELETE", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Get returns the specified TargetHttpsProxy resource in the specified region. Gets a list of available target HTTP proxies by making a list() request. +func (c *regionTargetHttpsProxiesRESTClient) Get(ctx context.Context, req *computepb.GetRegionTargetHttpsProxyRequest, opts ...gax.CallOption) (*computepb.TargetHttpsProxy, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/regions/%v/targetHttpsProxies/%v", req.GetProject(), req.GetRegion(), req.GetTargetHttpsProxy()) + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.TargetHttpsProxy{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Insert creates a TargetHttpsProxy resource in the specified project and region using the data included in the request. +func (c *regionTargetHttpsProxiesRESTClient) Insert(ctx context.Context, req *computepb.InsertRegionTargetHttpsProxyRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetTargetHttpsProxyResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/regions/%v/targetHttpsProxies", req.GetProject(), req.GetRegion()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// List retrieves the list of TargetHttpsProxy resources available to the specified project in the specified region. +func (c *regionTargetHttpsProxiesRESTClient) List(ctx context.Context, req *computepb.ListRegionTargetHttpsProxiesRequest, opts ...gax.CallOption) (*computepb.TargetHttpsProxyList, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/regions/%v/targetHttpsProxies", req.GetProject(), req.GetRegion()) + + params := url.Values{} + if req != nil && req.Filter != nil { + params.Add("filter", fmt.Sprintf("%v", req.GetFilter())) + } + if req != nil && req.MaxResults != nil { + params.Add("maxResults", fmt.Sprintf("%v", req.GetMaxResults())) + } + if req != nil && req.OrderBy != nil { + params.Add("orderBy", fmt.Sprintf("%v", req.GetOrderBy())) + } + if req != nil && req.PageToken != nil { + params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) + } + if req != nil && req.ReturnPartialSuccess != nil { + params.Add("returnPartialSuccess", fmt.Sprintf("%v", req.GetReturnPartialSuccess())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.TargetHttpsProxyList{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// SetSslCertificates replaces SslCertificates for TargetHttpsProxy. +func (c *regionTargetHttpsProxiesRESTClient) SetSslCertificates(ctx context.Context, req *computepb.SetSslCertificatesRegionTargetHttpsProxyRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetRegionTargetHttpsProxiesSetSslCertificatesRequestResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/regions/%v/targetHttpsProxies/%v/setSslCertificates", req.GetProject(), req.GetRegion(), req.GetTargetHttpsProxy()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// SetUrlMap changes the URL map for TargetHttpsProxy. +func (c *regionTargetHttpsProxiesRESTClient) SetUrlMap(ctx context.Context, req *computepb.SetUrlMapRegionTargetHttpsProxyRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetUrlMapReferenceResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/regions/%v/targetHttpsProxies/%v/setUrlMap", req.GetProject(), req.GetRegion(), req.GetTargetHttpsProxy()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} diff --git a/compute/apiv1/region_target_https_proxies_client_example_test.go b/compute/apiv1/region_target_https_proxies_client_example_test.go new file mode 100644 index 00000000000..2e5ecb82af5 --- /dev/null +++ b/compute/apiv1/region_target_https_proxies_client_example_test.go @@ -0,0 +1,150 @@ +// 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 compute_test + +import ( + "context" + + compute "cloud.google.com/go/compute/apiv1" + computepb "google.golang.org/genproto/googleapis/cloud/compute/v1" +) + +func ExampleNewRegionTargetHttpsProxiesRESTClient() { + ctx := context.Background() + c, err := compute.NewRegionTargetHttpsProxiesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + // TODO: Use client. + _ = c +} + +func ExampleRegionTargetHttpsProxiesClient_Delete() { + ctx := context.Background() + c, err := compute.NewRegionTargetHttpsProxiesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.DeleteRegionTargetHttpsProxyRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Delete(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleRegionTargetHttpsProxiesClient_Get() { + ctx := context.Background() + c, err := compute.NewRegionTargetHttpsProxiesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.GetRegionTargetHttpsProxyRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Get(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleRegionTargetHttpsProxiesClient_Insert() { + ctx := context.Background() + c, err := compute.NewRegionTargetHttpsProxiesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.InsertRegionTargetHttpsProxyRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Insert(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleRegionTargetHttpsProxiesClient_List() { + ctx := context.Background() + c, err := compute.NewRegionTargetHttpsProxiesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.ListRegionTargetHttpsProxiesRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.List(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleRegionTargetHttpsProxiesClient_SetSslCertificates() { + ctx := context.Background() + c, err := compute.NewRegionTargetHttpsProxiesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.SetSslCertificatesRegionTargetHttpsProxyRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.SetSslCertificates(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleRegionTargetHttpsProxiesClient_SetUrlMap() { + ctx := context.Background() + c, err := compute.NewRegionTargetHttpsProxiesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.SetUrlMapRegionTargetHttpsProxyRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.SetUrlMap(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} diff --git a/compute/apiv1/region_url_maps_client.go b/compute/apiv1/region_url_maps_client.go new file mode 100644 index 00000000000..732c9c082d2 --- /dev/null +++ b/compute/apiv1/region_url_maps_client.go @@ -0,0 +1,556 @@ +// 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 compute + +import ( + "bytes" + "context" + "fmt" + "io/ioutil" + "net/http" + "net/url" + + gax "github.com/googleapis/gax-go/v2" + "google.golang.org/api/option" + "google.golang.org/api/option/internaloption" + httptransport "google.golang.org/api/transport/http" + computepb "google.golang.org/genproto/googleapis/cloud/compute/v1" + "google.golang.org/grpc" + "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/encoding/protojson" +) + +var newRegionUrlMapsClientHook clientHook + +// RegionUrlMapsCallOptions contains the retry settings for each method of RegionUrlMapsClient. +type RegionUrlMapsCallOptions struct { + Delete []gax.CallOption + Get []gax.CallOption + Insert []gax.CallOption + List []gax.CallOption + Patch []gax.CallOption + Update []gax.CallOption + Validate []gax.CallOption +} + +// internalRegionUrlMapsClient is an interface that defines the methods availaible from Google Compute Engine API. +type internalRegionUrlMapsClient interface { + Close() error + setGoogleClientInfo(...string) + Connection() *grpc.ClientConn + Delete(context.Context, *computepb.DeleteRegionUrlMapRequest, ...gax.CallOption) (*computepb.Operation, error) + Get(context.Context, *computepb.GetRegionUrlMapRequest, ...gax.CallOption) (*computepb.UrlMap, error) + Insert(context.Context, *computepb.InsertRegionUrlMapRequest, ...gax.CallOption) (*computepb.Operation, error) + List(context.Context, *computepb.ListRegionUrlMapsRequest, ...gax.CallOption) (*computepb.UrlMapList, error) + Patch(context.Context, *computepb.PatchRegionUrlMapRequest, ...gax.CallOption) (*computepb.Operation, error) + Update(context.Context, *computepb.UpdateRegionUrlMapRequest, ...gax.CallOption) (*computepb.Operation, error) + Validate(context.Context, *computepb.ValidateRegionUrlMapRequest, ...gax.CallOption) (*computepb.UrlMapsValidateResponse, error) +} + +// RegionUrlMapsClient is a client for interacting with Google Compute Engine API. +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +// +// The RegionUrlMaps API. +type RegionUrlMapsClient struct { + // The internal transport-dependent client. + internalClient internalRegionUrlMapsClient + + // The call options for this service. + CallOptions *RegionUrlMapsCallOptions +} + +// 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 *RegionUrlMapsClient) 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 *RegionUrlMapsClient) setGoogleClientInfo(keyval ...string) { + c.internalClient.setGoogleClientInfo(keyval...) +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *RegionUrlMapsClient) Connection() *grpc.ClientConn { + return c.internalClient.Connection() +} + +// Delete deletes the specified UrlMap resource. +func (c *RegionUrlMapsClient) Delete(ctx context.Context, req *computepb.DeleteRegionUrlMapRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.Delete(ctx, req, opts...) +} + +// Get returns the specified UrlMap resource. Gets a list of available URL maps by making a list() request. +func (c *RegionUrlMapsClient) Get(ctx context.Context, req *computepb.GetRegionUrlMapRequest, opts ...gax.CallOption) (*computepb.UrlMap, error) { + return c.internalClient.Get(ctx, req, opts...) +} + +// Insert creates a UrlMap resource in the specified project using the data included in the request. +func (c *RegionUrlMapsClient) Insert(ctx context.Context, req *computepb.InsertRegionUrlMapRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.Insert(ctx, req, opts...) +} + +// List retrieves the list of UrlMap resources available to the specified project in the specified region. +func (c *RegionUrlMapsClient) List(ctx context.Context, req *computepb.ListRegionUrlMapsRequest, opts ...gax.CallOption) (*computepb.UrlMapList, error) { + return c.internalClient.List(ctx, req, opts...) +} + +// Patch patches the specified UrlMap resource with the data included in the request. This method supports PATCH semantics and uses JSON merge patch format and processing rules. +func (c *RegionUrlMapsClient) Patch(ctx context.Context, req *computepb.PatchRegionUrlMapRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.Patch(ctx, req, opts...) +} + +// Update updates the specified UrlMap resource with the data included in the request. +func (c *RegionUrlMapsClient) Update(ctx context.Context, req *computepb.UpdateRegionUrlMapRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.Update(ctx, req, opts...) +} + +// Validate runs static validation for the UrlMap. In particular, the tests of the provided UrlMap will be run. Calling this method does NOT create the UrlMap. +func (c *RegionUrlMapsClient) Validate(ctx context.Context, req *computepb.ValidateRegionUrlMapRequest, opts ...gax.CallOption) (*computepb.UrlMapsValidateResponse, error) { + return c.internalClient.Validate(ctx, req, opts...) +} + +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +type regionUrlMapsRESTClient struct { + // The http endpoint to connect to. + endpoint string + + // The http client. + httpClient *http.Client + + // The x-goog-* metadata to be sent with each request. + xGoogMetadata metadata.MD +} + +// NewRegionUrlMapsRESTClient creates a new region url maps rest client. +// +// The RegionUrlMaps API. +func NewRegionUrlMapsRESTClient(ctx context.Context, opts ...option.ClientOption) (*RegionUrlMapsClient, error) { + clientOpts := append(defaultRegionUrlMapsRESTClientOptions(), opts...) + httpClient, endpoint, err := httptransport.NewClient(ctx, clientOpts...) + if err != nil { + return nil, err + } + + c := ®ionUrlMapsRESTClient{ + endpoint: endpoint, + httpClient: httpClient, + } + c.setGoogleClientInfo() + + return &RegionUrlMapsClient{internalClient: c, CallOptions: &RegionUrlMapsCallOptions{}}, nil +} + +func defaultRegionUrlMapsRESTClientOptions() []option.ClientOption { + return []option.ClientOption{ + internaloption.WithDefaultEndpoint("compute.googleapis.com"), + internaloption.WithDefaultMTLSEndpoint("compute.mtls.googleapis.com"), + internaloption.WithDefaultAudience("https://compute.googleapis.com/"), + internaloption.WithDefaultScopes(DefaultAuthScopes()...), + } +} + +// 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 *regionUrlMapsRESTClient) setGoogleClientInfo(keyval ...string) { + kv := append([]string{"gl-go", versionGo()}, keyval...) + kv = append(kv, "gapic", versionClient, "gax", gax.Version, "rest", "UNKNOWN") + 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 *regionUrlMapsRESTClient) Close() error { + // Replace httpClient with nil to force cleanup. + c.httpClient = nil + return nil +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *regionUrlMapsRESTClient) Connection() *grpc.ClientConn { + return nil +} + +// Delete deletes the specified UrlMap resource. +func (c *regionUrlMapsRESTClient) Delete(ctx context.Context, req *computepb.DeleteRegionUrlMapRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/regions/%v/urlMaps/%v", req.GetProject(), req.GetRegion(), req.GetUrlMap()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("DELETE", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Get returns the specified UrlMap resource. Gets a list of available URL maps by making a list() request. +func (c *regionUrlMapsRESTClient) Get(ctx context.Context, req *computepb.GetRegionUrlMapRequest, opts ...gax.CallOption) (*computepb.UrlMap, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/regions/%v/urlMaps/%v", req.GetProject(), req.GetRegion(), req.GetUrlMap()) + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.UrlMap{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Insert creates a UrlMap resource in the specified project using the data included in the request. +func (c *regionUrlMapsRESTClient) Insert(ctx context.Context, req *computepb.InsertRegionUrlMapRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetUrlMapResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/regions/%v/urlMaps", req.GetProject(), req.GetRegion()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// List retrieves the list of UrlMap resources available to the specified project in the specified region. +func (c *regionUrlMapsRESTClient) List(ctx context.Context, req *computepb.ListRegionUrlMapsRequest, opts ...gax.CallOption) (*computepb.UrlMapList, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/regions/%v/urlMaps", req.GetProject(), req.GetRegion()) + + params := url.Values{} + if req != nil && req.Filter != nil { + params.Add("filter", fmt.Sprintf("%v", req.GetFilter())) + } + if req != nil && req.MaxResults != nil { + params.Add("maxResults", fmt.Sprintf("%v", req.GetMaxResults())) + } + if req != nil && req.OrderBy != nil { + params.Add("orderBy", fmt.Sprintf("%v", req.GetOrderBy())) + } + if req != nil && req.PageToken != nil { + params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) + } + if req != nil && req.ReturnPartialSuccess != nil { + params.Add("returnPartialSuccess", fmt.Sprintf("%v", req.GetReturnPartialSuccess())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.UrlMapList{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Patch patches the specified UrlMap resource with the data included in the request. This method supports PATCH semantics and uses JSON merge patch format and processing rules. +func (c *regionUrlMapsRESTClient) Patch(ctx context.Context, req *computepb.PatchRegionUrlMapRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetUrlMapResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/regions/%v/urlMaps/%v", req.GetProject(), req.GetRegion(), req.GetUrlMap()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("PATCH", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Update updates the specified UrlMap resource with the data included in the request. +func (c *regionUrlMapsRESTClient) Update(ctx context.Context, req *computepb.UpdateRegionUrlMapRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetUrlMapResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("") + + params := url.Values{} + if req.GetProject() != "" { + params.Add("project", fmt.Sprintf("%v", req.GetProject())) + } + if req.GetRegion() != "" { + params.Add("region", fmt.Sprintf("%v", req.GetRegion())) + } + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + if req.GetUrlMap() != "" { + params.Add("urlMap", fmt.Sprintf("%v", req.GetUrlMap())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("PUT", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Validate runs static validation for the UrlMap. In particular, the tests of the provided UrlMap will be run. Calling this method does NOT create the UrlMap. +func (c *regionUrlMapsRESTClient) Validate(ctx context.Context, req *computepb.ValidateRegionUrlMapRequest, opts ...gax.CallOption) (*computepb.UrlMapsValidateResponse, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetRegionUrlMapsValidateRequestResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/regions/%v/urlMaps/%v/validate", req.GetProject(), req.GetRegion(), req.GetUrlMap()) + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.UrlMapsValidateResponse{} + + return rsp, unm.Unmarshal(buf, rsp) +} diff --git a/compute/apiv1/region_url_maps_client_example_test.go b/compute/apiv1/region_url_maps_client_example_test.go new file mode 100644 index 00000000000..8a20f726251 --- /dev/null +++ b/compute/apiv1/region_url_maps_client_example_test.go @@ -0,0 +1,169 @@ +// 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 compute_test + +import ( + "context" + + compute "cloud.google.com/go/compute/apiv1" + computepb "google.golang.org/genproto/googleapis/cloud/compute/v1" +) + +func ExampleNewRegionUrlMapsRESTClient() { + ctx := context.Background() + c, err := compute.NewRegionUrlMapsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + // TODO: Use client. + _ = c +} + +func ExampleRegionUrlMapsClient_Delete() { + ctx := context.Background() + c, err := compute.NewRegionUrlMapsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.DeleteRegionUrlMapRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Delete(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleRegionUrlMapsClient_Get() { + ctx := context.Background() + c, err := compute.NewRegionUrlMapsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.GetRegionUrlMapRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Get(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleRegionUrlMapsClient_Insert() { + ctx := context.Background() + c, err := compute.NewRegionUrlMapsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.InsertRegionUrlMapRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Insert(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleRegionUrlMapsClient_List() { + ctx := context.Background() + c, err := compute.NewRegionUrlMapsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.ListRegionUrlMapsRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.List(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleRegionUrlMapsClient_Patch() { + ctx := context.Background() + c, err := compute.NewRegionUrlMapsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.PatchRegionUrlMapRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Patch(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleRegionUrlMapsClient_Update() { + ctx := context.Background() + c, err := compute.NewRegionUrlMapsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.UpdateRegionUrlMapRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Update(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleRegionUrlMapsClient_Validate() { + ctx := context.Background() + c, err := compute.NewRegionUrlMapsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.ValidateRegionUrlMapRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Validate(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} diff --git a/compute/apiv1/regions_client.go b/compute/apiv1/regions_client.go new file mode 100644 index 00000000000..9d26c40564b --- /dev/null +++ b/compute/apiv1/regions_client.go @@ -0,0 +1,265 @@ +// 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 compute + +import ( + "bytes" + "context" + "fmt" + "io/ioutil" + "net/http" + "net/url" + + gax "github.com/googleapis/gax-go/v2" + "google.golang.org/api/option" + "google.golang.org/api/option/internaloption" + httptransport "google.golang.org/api/transport/http" + computepb "google.golang.org/genproto/googleapis/cloud/compute/v1" + "google.golang.org/grpc" + "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/encoding/protojson" +) + +var newRegionsClientHook clientHook + +// RegionsCallOptions contains the retry settings for each method of RegionsClient. +type RegionsCallOptions struct { + Get []gax.CallOption + List []gax.CallOption +} + +// internalRegionsClient is an interface that defines the methods availaible from Google Compute Engine API. +type internalRegionsClient interface { + Close() error + setGoogleClientInfo(...string) + Connection() *grpc.ClientConn + Get(context.Context, *computepb.GetRegionRequest, ...gax.CallOption) (*computepb.Region, error) + List(context.Context, *computepb.ListRegionsRequest, ...gax.CallOption) (*computepb.RegionList, error) +} + +// RegionsClient is a client for interacting with Google Compute Engine API. +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +// +// The Regions API. +type RegionsClient struct { + // The internal transport-dependent client. + internalClient internalRegionsClient + + // The call options for this service. + CallOptions *RegionsCallOptions +} + +// 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 *RegionsClient) 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 *RegionsClient) setGoogleClientInfo(keyval ...string) { + c.internalClient.setGoogleClientInfo(keyval...) +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *RegionsClient) Connection() *grpc.ClientConn { + return c.internalClient.Connection() +} + +// Get returns the specified Region resource. Gets a list of available regions by making a list() request. +func (c *RegionsClient) Get(ctx context.Context, req *computepb.GetRegionRequest, opts ...gax.CallOption) (*computepb.Region, error) { + return c.internalClient.Get(ctx, req, opts...) +} + +// List retrieves the list of region resources available to the specified project. +func (c *RegionsClient) List(ctx context.Context, req *computepb.ListRegionsRequest, opts ...gax.CallOption) (*computepb.RegionList, error) { + return c.internalClient.List(ctx, req, opts...) +} + +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +type regionsRESTClient struct { + // The http endpoint to connect to. + endpoint string + + // The http client. + httpClient *http.Client + + // The x-goog-* metadata to be sent with each request. + xGoogMetadata metadata.MD +} + +// NewRegionsRESTClient creates a new regions rest client. +// +// The Regions API. +func NewRegionsRESTClient(ctx context.Context, opts ...option.ClientOption) (*RegionsClient, error) { + clientOpts := append(defaultRegionsRESTClientOptions(), opts...) + httpClient, endpoint, err := httptransport.NewClient(ctx, clientOpts...) + if err != nil { + return nil, err + } + + c := ®ionsRESTClient{ + endpoint: endpoint, + httpClient: httpClient, + } + c.setGoogleClientInfo() + + return &RegionsClient{internalClient: c, CallOptions: &RegionsCallOptions{}}, nil +} + +func defaultRegionsRESTClientOptions() []option.ClientOption { + return []option.ClientOption{ + internaloption.WithDefaultEndpoint("compute.googleapis.com"), + internaloption.WithDefaultMTLSEndpoint("compute.mtls.googleapis.com"), + internaloption.WithDefaultAudience("https://compute.googleapis.com/"), + internaloption.WithDefaultScopes(DefaultAuthScopes()...), + } +} + +// 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 *regionsRESTClient) setGoogleClientInfo(keyval ...string) { + kv := append([]string{"gl-go", versionGo()}, keyval...) + kv = append(kv, "gapic", versionClient, "gax", gax.Version, "rest", "UNKNOWN") + 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 *regionsRESTClient) Close() error { + // Replace httpClient with nil to force cleanup. + c.httpClient = nil + return nil +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *regionsRESTClient) Connection() *grpc.ClientConn { + return nil +} + +// Get returns the specified Region resource. Gets a list of available regions by making a list() request. +func (c *regionsRESTClient) Get(ctx context.Context, req *computepb.GetRegionRequest, opts ...gax.CallOption) (*computepb.Region, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/regions/%v", req.GetProject(), req.GetRegion()) + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Region{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// List retrieves the list of region resources available to the specified project. +func (c *regionsRESTClient) List(ctx context.Context, req *computepb.ListRegionsRequest, opts ...gax.CallOption) (*computepb.RegionList, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/regions", req.GetProject()) + + params := url.Values{} + if req != nil && req.Filter != nil { + params.Add("filter", fmt.Sprintf("%v", req.GetFilter())) + } + if req != nil && req.MaxResults != nil { + params.Add("maxResults", fmt.Sprintf("%v", req.GetMaxResults())) + } + if req != nil && req.OrderBy != nil { + params.Add("orderBy", fmt.Sprintf("%v", req.GetOrderBy())) + } + if req != nil && req.PageToken != nil { + params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) + } + if req != nil && req.ReturnPartialSuccess != nil { + params.Add("returnPartialSuccess", fmt.Sprintf("%v", req.GetReturnPartialSuccess())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.RegionList{} + + return rsp, unm.Unmarshal(buf, rsp) +} diff --git a/compute/apiv1/regions_client_example_test.go b/compute/apiv1/regions_client_example_test.go new file mode 100644 index 00000000000..80af1fd0722 --- /dev/null +++ b/compute/apiv1/regions_client_example_test.go @@ -0,0 +1,74 @@ +// 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 compute_test + +import ( + "context" + + compute "cloud.google.com/go/compute/apiv1" + computepb "google.golang.org/genproto/googleapis/cloud/compute/v1" +) + +func ExampleNewRegionsRESTClient() { + ctx := context.Background() + c, err := compute.NewRegionsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + // TODO: Use client. + _ = c +} + +func ExampleRegionsClient_Get() { + ctx := context.Background() + c, err := compute.NewRegionsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.GetRegionRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Get(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleRegionsClient_List() { + ctx := context.Background() + c, err := compute.NewRegionsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.ListRegionsRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.List(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} diff --git a/compute/apiv1/reservations_client.go b/compute/apiv1/reservations_client.go new file mode 100644 index 00000000000..9c3cd718cce --- /dev/null +++ b/compute/apiv1/reservations_client.go @@ -0,0 +1,669 @@ +// 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 compute + +import ( + "bytes" + "context" + "fmt" + "io/ioutil" + "net/http" + "net/url" + + gax "github.com/googleapis/gax-go/v2" + "google.golang.org/api/option" + "google.golang.org/api/option/internaloption" + httptransport "google.golang.org/api/transport/http" + computepb "google.golang.org/genproto/googleapis/cloud/compute/v1" + "google.golang.org/grpc" + "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/encoding/protojson" +) + +var newReservationsClientHook clientHook + +// ReservationsCallOptions contains the retry settings for each method of ReservationsClient. +type ReservationsCallOptions struct { + AggregatedList []gax.CallOption + Delete []gax.CallOption + Get []gax.CallOption + GetIamPolicy []gax.CallOption + Insert []gax.CallOption + List []gax.CallOption + Resize []gax.CallOption + SetIamPolicy []gax.CallOption + TestIamPermissions []gax.CallOption +} + +// internalReservationsClient is an interface that defines the methods availaible from Google Compute Engine API. +type internalReservationsClient interface { + Close() error + setGoogleClientInfo(...string) + Connection() *grpc.ClientConn + AggregatedList(context.Context, *computepb.AggregatedListReservationsRequest, ...gax.CallOption) (*computepb.ReservationAggregatedList, error) + Delete(context.Context, *computepb.DeleteReservationRequest, ...gax.CallOption) (*computepb.Operation, error) + Get(context.Context, *computepb.GetReservationRequest, ...gax.CallOption) (*computepb.Reservation, error) + GetIamPolicy(context.Context, *computepb.GetIamPolicyReservationRequest, ...gax.CallOption) (*computepb.Policy, error) + Insert(context.Context, *computepb.InsertReservationRequest, ...gax.CallOption) (*computepb.Operation, error) + List(context.Context, *computepb.ListReservationsRequest, ...gax.CallOption) (*computepb.ReservationList, error) + Resize(context.Context, *computepb.ResizeReservationRequest, ...gax.CallOption) (*computepb.Operation, error) + SetIamPolicy(context.Context, *computepb.SetIamPolicyReservationRequest, ...gax.CallOption) (*computepb.Policy, error) + TestIamPermissions(context.Context, *computepb.TestIamPermissionsReservationRequest, ...gax.CallOption) (*computepb.TestPermissionsResponse, error) +} + +// ReservationsClient is a client for interacting with Google Compute Engine API. +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +// +// The Reservations API. +type ReservationsClient struct { + // The internal transport-dependent client. + internalClient internalReservationsClient + + // The call options for this service. + CallOptions *ReservationsCallOptions +} + +// 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 *ReservationsClient) 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 *ReservationsClient) setGoogleClientInfo(keyval ...string) { + c.internalClient.setGoogleClientInfo(keyval...) +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *ReservationsClient) Connection() *grpc.ClientConn { + return c.internalClient.Connection() +} + +// AggregatedList retrieves an aggregated list of reservations. +func (c *ReservationsClient) AggregatedList(ctx context.Context, req *computepb.AggregatedListReservationsRequest, opts ...gax.CallOption) (*computepb.ReservationAggregatedList, error) { + return c.internalClient.AggregatedList(ctx, req, opts...) +} + +// Delete deletes the specified reservation. +func (c *ReservationsClient) Delete(ctx context.Context, req *computepb.DeleteReservationRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.Delete(ctx, req, opts...) +} + +// Get retrieves information about the specified reservation. +func (c *ReservationsClient) Get(ctx context.Context, req *computepb.GetReservationRequest, opts ...gax.CallOption) (*computepb.Reservation, error) { + return c.internalClient.Get(ctx, req, opts...) +} + +// GetIamPolicy gets the access control policy for a resource. May be empty if no such policy or resource exists. +func (c *ReservationsClient) GetIamPolicy(ctx context.Context, req *computepb.GetIamPolicyReservationRequest, opts ...gax.CallOption) (*computepb.Policy, error) { + return c.internalClient.GetIamPolicy(ctx, req, opts...) +} + +// Insert creates a new reservation. For more information, read Reserving zonal resources. +func (c *ReservationsClient) Insert(ctx context.Context, req *computepb.InsertReservationRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.Insert(ctx, req, opts...) +} + +// List a list of all the reservations that have been configured for the specified project in specified zone. +func (c *ReservationsClient) List(ctx context.Context, req *computepb.ListReservationsRequest, opts ...gax.CallOption) (*computepb.ReservationList, error) { + return c.internalClient.List(ctx, req, opts...) +} + +// Resize resizes the reservation (applicable to standalone reservations only). For more information, read Modifying reservations. +func (c *ReservationsClient) Resize(ctx context.Context, req *computepb.ResizeReservationRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.Resize(ctx, req, opts...) +} + +// SetIamPolicy sets the access control policy on the specified resource. Replaces any existing policy. +func (c *ReservationsClient) SetIamPolicy(ctx context.Context, req *computepb.SetIamPolicyReservationRequest, opts ...gax.CallOption) (*computepb.Policy, error) { + return c.internalClient.SetIamPolicy(ctx, req, opts...) +} + +// TestIamPermissions returns permissions that a caller has on the specified resource. +func (c *ReservationsClient) TestIamPermissions(ctx context.Context, req *computepb.TestIamPermissionsReservationRequest, opts ...gax.CallOption) (*computepb.TestPermissionsResponse, error) { + return c.internalClient.TestIamPermissions(ctx, req, opts...) +} + +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +type reservationsRESTClient struct { + // The http endpoint to connect to. + endpoint string + + // The http client. + httpClient *http.Client + + // The x-goog-* metadata to be sent with each request. + xGoogMetadata metadata.MD +} + +// NewReservationsRESTClient creates a new reservations rest client. +// +// The Reservations API. +func NewReservationsRESTClient(ctx context.Context, opts ...option.ClientOption) (*ReservationsClient, error) { + clientOpts := append(defaultReservationsRESTClientOptions(), opts...) + httpClient, endpoint, err := httptransport.NewClient(ctx, clientOpts...) + if err != nil { + return nil, err + } + + c := &reservationsRESTClient{ + endpoint: endpoint, + httpClient: httpClient, + } + c.setGoogleClientInfo() + + return &ReservationsClient{internalClient: c, CallOptions: &ReservationsCallOptions{}}, nil +} + +func defaultReservationsRESTClientOptions() []option.ClientOption { + return []option.ClientOption{ + internaloption.WithDefaultEndpoint("compute.googleapis.com"), + internaloption.WithDefaultMTLSEndpoint("compute.mtls.googleapis.com"), + internaloption.WithDefaultAudience("https://compute.googleapis.com/"), + internaloption.WithDefaultScopes(DefaultAuthScopes()...), + } +} + +// 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 *reservationsRESTClient) setGoogleClientInfo(keyval ...string) { + kv := append([]string{"gl-go", versionGo()}, keyval...) + kv = append(kv, "gapic", versionClient, "gax", gax.Version, "rest", "UNKNOWN") + 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 *reservationsRESTClient) Close() error { + // Replace httpClient with nil to force cleanup. + c.httpClient = nil + return nil +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *reservationsRESTClient) Connection() *grpc.ClientConn { + return nil +} + +// AggregatedList retrieves an aggregated list of reservations. +func (c *reservationsRESTClient) AggregatedList(ctx context.Context, req *computepb.AggregatedListReservationsRequest, opts ...gax.CallOption) (*computepb.ReservationAggregatedList, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/aggregated/reservations", req.GetProject()) + + params := url.Values{} + if req != nil && req.Filter != nil { + params.Add("filter", fmt.Sprintf("%v", req.GetFilter())) + } + if req != nil && req.IncludeAllScopes != nil { + params.Add("includeAllScopes", fmt.Sprintf("%v", req.GetIncludeAllScopes())) + } + if req != nil && req.MaxResults != nil { + params.Add("maxResults", fmt.Sprintf("%v", req.GetMaxResults())) + } + if req != nil && req.OrderBy != nil { + params.Add("orderBy", fmt.Sprintf("%v", req.GetOrderBy())) + } + if req != nil && req.PageToken != nil { + params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) + } + if req != nil && req.ReturnPartialSuccess != nil { + params.Add("returnPartialSuccess", fmt.Sprintf("%v", req.GetReturnPartialSuccess())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.ReservationAggregatedList{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Delete deletes the specified reservation. +func (c *reservationsRESTClient) Delete(ctx context.Context, req *computepb.DeleteReservationRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/zones/%v/reservations/%v", req.GetProject(), req.GetZone(), req.GetReservation()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("DELETE", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Get retrieves information about the specified reservation. +func (c *reservationsRESTClient) Get(ctx context.Context, req *computepb.GetReservationRequest, opts ...gax.CallOption) (*computepb.Reservation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/zones/%v/reservations/%v", req.GetProject(), req.GetZone(), req.GetReservation()) + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Reservation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// GetIamPolicy gets the access control policy for a resource. May be empty if no such policy or resource exists. +func (c *reservationsRESTClient) GetIamPolicy(ctx context.Context, req *computepb.GetIamPolicyReservationRequest, opts ...gax.CallOption) (*computepb.Policy, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/zones/%v/reservations/%v/getIamPolicy", req.GetProject(), req.GetZone(), req.GetResource()) + + params := url.Values{} + if req != nil && req.OptionsRequestedPolicyVersion != nil { + params.Add("optionsRequestedPolicyVersion", fmt.Sprintf("%v", req.GetOptionsRequestedPolicyVersion())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Policy{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Insert creates a new reservation. For more information, read Reserving zonal resources. +func (c *reservationsRESTClient) Insert(ctx context.Context, req *computepb.InsertReservationRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetReservationResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/zones/%v/reservations", req.GetProject(), req.GetZone()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// List a list of all the reservations that have been configured for the specified project in specified zone. +func (c *reservationsRESTClient) List(ctx context.Context, req *computepb.ListReservationsRequest, opts ...gax.CallOption) (*computepb.ReservationList, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/zones/%v/reservations", req.GetProject(), req.GetZone()) + + params := url.Values{} + if req != nil && req.Filter != nil { + params.Add("filter", fmt.Sprintf("%v", req.GetFilter())) + } + if req != nil && req.MaxResults != nil { + params.Add("maxResults", fmt.Sprintf("%v", req.GetMaxResults())) + } + if req != nil && req.OrderBy != nil { + params.Add("orderBy", fmt.Sprintf("%v", req.GetOrderBy())) + } + if req != nil && req.PageToken != nil { + params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) + } + if req != nil && req.ReturnPartialSuccess != nil { + params.Add("returnPartialSuccess", fmt.Sprintf("%v", req.GetReturnPartialSuccess())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.ReservationList{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Resize resizes the reservation (applicable to standalone reservations only). For more information, read Modifying reservations. +func (c *reservationsRESTClient) Resize(ctx context.Context, req *computepb.ResizeReservationRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetReservationsResizeRequestResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/zones/%v/reservations/%v/resize", req.GetProject(), req.GetZone(), req.GetReservation()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// SetIamPolicy sets the access control policy on the specified resource. Replaces any existing policy. +func (c *reservationsRESTClient) SetIamPolicy(ctx context.Context, req *computepb.SetIamPolicyReservationRequest, opts ...gax.CallOption) (*computepb.Policy, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetZoneSetPolicyRequestResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/zones/%v/reservations/%v/setIamPolicy", req.GetProject(), req.GetZone(), req.GetResource()) + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Policy{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// TestIamPermissions returns permissions that a caller has on the specified resource. +func (c *reservationsRESTClient) TestIamPermissions(ctx context.Context, req *computepb.TestIamPermissionsReservationRequest, opts ...gax.CallOption) (*computepb.TestPermissionsResponse, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetTestPermissionsRequestResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/zones/%v/reservations/%v/testIamPermissions", req.GetProject(), req.GetZone(), req.GetResource()) + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.TestPermissionsResponse{} + + return rsp, unm.Unmarshal(buf, rsp) +} diff --git a/compute/apiv1/reservations_client_example_test.go b/compute/apiv1/reservations_client_example_test.go new file mode 100644 index 00000000000..dda54366096 --- /dev/null +++ b/compute/apiv1/reservations_client_example_test.go @@ -0,0 +1,207 @@ +// 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 compute_test + +import ( + "context" + + compute "cloud.google.com/go/compute/apiv1" + computepb "google.golang.org/genproto/googleapis/cloud/compute/v1" +) + +func ExampleNewReservationsRESTClient() { + ctx := context.Background() + c, err := compute.NewReservationsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + // TODO: Use client. + _ = c +} + +func ExampleReservationsClient_AggregatedList() { + ctx := context.Background() + c, err := compute.NewReservationsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.AggregatedListReservationsRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.AggregatedList(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleReservationsClient_Delete() { + ctx := context.Background() + c, err := compute.NewReservationsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.DeleteReservationRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Delete(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleReservationsClient_Get() { + ctx := context.Background() + c, err := compute.NewReservationsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.GetReservationRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Get(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleReservationsClient_GetIamPolicy() { + ctx := context.Background() + c, err := compute.NewReservationsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.GetIamPolicyReservationRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.GetIamPolicy(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleReservationsClient_Insert() { + ctx := context.Background() + c, err := compute.NewReservationsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.InsertReservationRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Insert(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleReservationsClient_List() { + ctx := context.Background() + c, err := compute.NewReservationsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.ListReservationsRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.List(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleReservationsClient_Resize() { + ctx := context.Background() + c, err := compute.NewReservationsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.ResizeReservationRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Resize(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleReservationsClient_SetIamPolicy() { + ctx := context.Background() + c, err := compute.NewReservationsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.SetIamPolicyReservationRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.SetIamPolicy(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleReservationsClient_TestIamPermissions() { + ctx := context.Background() + c, err := compute.NewReservationsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.TestIamPermissionsReservationRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.TestIamPermissions(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} diff --git a/compute/apiv1/resource_policies_client.go b/compute/apiv1/resource_policies_client.go new file mode 100644 index 00000000000..4e2b4d86273 --- /dev/null +++ b/compute/apiv1/resource_policies_client.go @@ -0,0 +1,611 @@ +// 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 compute + +import ( + "bytes" + "context" + "fmt" + "io/ioutil" + "net/http" + "net/url" + + gax "github.com/googleapis/gax-go/v2" + "google.golang.org/api/option" + "google.golang.org/api/option/internaloption" + httptransport "google.golang.org/api/transport/http" + computepb "google.golang.org/genproto/googleapis/cloud/compute/v1" + "google.golang.org/grpc" + "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/encoding/protojson" +) + +var newResourcePoliciesClientHook clientHook + +// ResourcePoliciesCallOptions contains the retry settings for each method of ResourcePoliciesClient. +type ResourcePoliciesCallOptions struct { + AggregatedList []gax.CallOption + Delete []gax.CallOption + Get []gax.CallOption + GetIamPolicy []gax.CallOption + Insert []gax.CallOption + List []gax.CallOption + SetIamPolicy []gax.CallOption + TestIamPermissions []gax.CallOption +} + +// internalResourcePoliciesClient is an interface that defines the methods availaible from Google Compute Engine API. +type internalResourcePoliciesClient interface { + Close() error + setGoogleClientInfo(...string) + Connection() *grpc.ClientConn + AggregatedList(context.Context, *computepb.AggregatedListResourcePoliciesRequest, ...gax.CallOption) (*computepb.ResourcePolicyAggregatedList, error) + Delete(context.Context, *computepb.DeleteResourcePolicyRequest, ...gax.CallOption) (*computepb.Operation, error) + Get(context.Context, *computepb.GetResourcePolicyRequest, ...gax.CallOption) (*computepb.ResourcePolicy, error) + GetIamPolicy(context.Context, *computepb.GetIamPolicyResourcePolicyRequest, ...gax.CallOption) (*computepb.Policy, error) + Insert(context.Context, *computepb.InsertResourcePolicyRequest, ...gax.CallOption) (*computepb.Operation, error) + List(context.Context, *computepb.ListResourcePoliciesRequest, ...gax.CallOption) (*computepb.ResourcePolicyList, error) + SetIamPolicy(context.Context, *computepb.SetIamPolicyResourcePolicyRequest, ...gax.CallOption) (*computepb.Policy, error) + TestIamPermissions(context.Context, *computepb.TestIamPermissionsResourcePolicyRequest, ...gax.CallOption) (*computepb.TestPermissionsResponse, error) +} + +// ResourcePoliciesClient is a client for interacting with Google Compute Engine API. +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +// +// The ResourcePolicies API. +type ResourcePoliciesClient struct { + // The internal transport-dependent client. + internalClient internalResourcePoliciesClient + + // The call options for this service. + CallOptions *ResourcePoliciesCallOptions +} + +// 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 *ResourcePoliciesClient) 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 *ResourcePoliciesClient) setGoogleClientInfo(keyval ...string) { + c.internalClient.setGoogleClientInfo(keyval...) +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *ResourcePoliciesClient) Connection() *grpc.ClientConn { + return c.internalClient.Connection() +} + +// AggregatedList retrieves an aggregated list of resource policies. +func (c *ResourcePoliciesClient) AggregatedList(ctx context.Context, req *computepb.AggregatedListResourcePoliciesRequest, opts ...gax.CallOption) (*computepb.ResourcePolicyAggregatedList, error) { + return c.internalClient.AggregatedList(ctx, req, opts...) +} + +// Delete deletes the specified resource policy. +func (c *ResourcePoliciesClient) Delete(ctx context.Context, req *computepb.DeleteResourcePolicyRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.Delete(ctx, req, opts...) +} + +// Get retrieves all information of the specified resource policy. +func (c *ResourcePoliciesClient) Get(ctx context.Context, req *computepb.GetResourcePolicyRequest, opts ...gax.CallOption) (*computepb.ResourcePolicy, error) { + return c.internalClient.Get(ctx, req, opts...) +} + +// GetIamPolicy gets the access control policy for a resource. May be empty if no such policy or resource exists. +func (c *ResourcePoliciesClient) GetIamPolicy(ctx context.Context, req *computepb.GetIamPolicyResourcePolicyRequest, opts ...gax.CallOption) (*computepb.Policy, error) { + return c.internalClient.GetIamPolicy(ctx, req, opts...) +} + +// Insert creates a new resource policy. +func (c *ResourcePoliciesClient) Insert(ctx context.Context, req *computepb.InsertResourcePolicyRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.Insert(ctx, req, opts...) +} + +// List a list all the resource policies that have been configured for the specified project in specified region. +func (c *ResourcePoliciesClient) List(ctx context.Context, req *computepb.ListResourcePoliciesRequest, opts ...gax.CallOption) (*computepb.ResourcePolicyList, error) { + return c.internalClient.List(ctx, req, opts...) +} + +// SetIamPolicy sets the access control policy on the specified resource. Replaces any existing policy. +func (c *ResourcePoliciesClient) SetIamPolicy(ctx context.Context, req *computepb.SetIamPolicyResourcePolicyRequest, opts ...gax.CallOption) (*computepb.Policy, error) { + return c.internalClient.SetIamPolicy(ctx, req, opts...) +} + +// TestIamPermissions returns permissions that a caller has on the specified resource. +func (c *ResourcePoliciesClient) TestIamPermissions(ctx context.Context, req *computepb.TestIamPermissionsResourcePolicyRequest, opts ...gax.CallOption) (*computepb.TestPermissionsResponse, error) { + return c.internalClient.TestIamPermissions(ctx, req, opts...) +} + +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +type resourcePoliciesRESTClient struct { + // The http endpoint to connect to. + endpoint string + + // The http client. + httpClient *http.Client + + // The x-goog-* metadata to be sent with each request. + xGoogMetadata metadata.MD +} + +// NewResourcePoliciesRESTClient creates a new resource policies rest client. +// +// The ResourcePolicies API. +func NewResourcePoliciesRESTClient(ctx context.Context, opts ...option.ClientOption) (*ResourcePoliciesClient, error) { + clientOpts := append(defaultResourcePoliciesRESTClientOptions(), opts...) + httpClient, endpoint, err := httptransport.NewClient(ctx, clientOpts...) + if err != nil { + return nil, err + } + + c := &resourcePoliciesRESTClient{ + endpoint: endpoint, + httpClient: httpClient, + } + c.setGoogleClientInfo() + + return &ResourcePoliciesClient{internalClient: c, CallOptions: &ResourcePoliciesCallOptions{}}, nil +} + +func defaultResourcePoliciesRESTClientOptions() []option.ClientOption { + return []option.ClientOption{ + internaloption.WithDefaultEndpoint("compute.googleapis.com"), + internaloption.WithDefaultMTLSEndpoint("compute.mtls.googleapis.com"), + internaloption.WithDefaultAudience("https://compute.googleapis.com/"), + internaloption.WithDefaultScopes(DefaultAuthScopes()...), + } +} + +// 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 *resourcePoliciesRESTClient) setGoogleClientInfo(keyval ...string) { + kv := append([]string{"gl-go", versionGo()}, keyval...) + kv = append(kv, "gapic", versionClient, "gax", gax.Version, "rest", "UNKNOWN") + 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 *resourcePoliciesRESTClient) Close() error { + // Replace httpClient with nil to force cleanup. + c.httpClient = nil + return nil +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *resourcePoliciesRESTClient) Connection() *grpc.ClientConn { + return nil +} + +// AggregatedList retrieves an aggregated list of resource policies. +func (c *resourcePoliciesRESTClient) AggregatedList(ctx context.Context, req *computepb.AggregatedListResourcePoliciesRequest, opts ...gax.CallOption) (*computepb.ResourcePolicyAggregatedList, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/aggregated/resourcePolicies", req.GetProject()) + + params := url.Values{} + if req != nil && req.Filter != nil { + params.Add("filter", fmt.Sprintf("%v", req.GetFilter())) + } + if req != nil && req.IncludeAllScopes != nil { + params.Add("includeAllScopes", fmt.Sprintf("%v", req.GetIncludeAllScopes())) + } + if req != nil && req.MaxResults != nil { + params.Add("maxResults", fmt.Sprintf("%v", req.GetMaxResults())) + } + if req != nil && req.OrderBy != nil { + params.Add("orderBy", fmt.Sprintf("%v", req.GetOrderBy())) + } + if req != nil && req.PageToken != nil { + params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) + } + if req != nil && req.ReturnPartialSuccess != nil { + params.Add("returnPartialSuccess", fmt.Sprintf("%v", req.GetReturnPartialSuccess())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.ResourcePolicyAggregatedList{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Delete deletes the specified resource policy. +func (c *resourcePoliciesRESTClient) Delete(ctx context.Context, req *computepb.DeleteResourcePolicyRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/regions/%v/resourcePolicies/%v", req.GetProject(), req.GetRegion(), req.GetResourcePolicy()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("DELETE", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Get retrieves all information of the specified resource policy. +func (c *resourcePoliciesRESTClient) Get(ctx context.Context, req *computepb.GetResourcePolicyRequest, opts ...gax.CallOption) (*computepb.ResourcePolicy, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/regions/%v/resourcePolicies/%v", req.GetProject(), req.GetRegion(), req.GetResourcePolicy()) + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.ResourcePolicy{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// GetIamPolicy gets the access control policy for a resource. May be empty if no such policy or resource exists. +func (c *resourcePoliciesRESTClient) GetIamPolicy(ctx context.Context, req *computepb.GetIamPolicyResourcePolicyRequest, opts ...gax.CallOption) (*computepb.Policy, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/regions/%v/resourcePolicies/%v/getIamPolicy", req.GetProject(), req.GetRegion(), req.GetResource()) + + params := url.Values{} + if req != nil && req.OptionsRequestedPolicyVersion != nil { + params.Add("optionsRequestedPolicyVersion", fmt.Sprintf("%v", req.GetOptionsRequestedPolicyVersion())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Policy{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Insert creates a new resource policy. +func (c *resourcePoliciesRESTClient) Insert(ctx context.Context, req *computepb.InsertResourcePolicyRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetResourcePolicyResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/regions/%v/resourcePolicies", req.GetProject(), req.GetRegion()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// List a list all the resource policies that have been configured for the specified project in specified region. +func (c *resourcePoliciesRESTClient) List(ctx context.Context, req *computepb.ListResourcePoliciesRequest, opts ...gax.CallOption) (*computepb.ResourcePolicyList, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/regions/%v/resourcePolicies", req.GetProject(), req.GetRegion()) + + params := url.Values{} + if req != nil && req.Filter != nil { + params.Add("filter", fmt.Sprintf("%v", req.GetFilter())) + } + if req != nil && req.MaxResults != nil { + params.Add("maxResults", fmt.Sprintf("%v", req.GetMaxResults())) + } + if req != nil && req.OrderBy != nil { + params.Add("orderBy", fmt.Sprintf("%v", req.GetOrderBy())) + } + if req != nil && req.PageToken != nil { + params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) + } + if req != nil && req.ReturnPartialSuccess != nil { + params.Add("returnPartialSuccess", fmt.Sprintf("%v", req.GetReturnPartialSuccess())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.ResourcePolicyList{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// SetIamPolicy sets the access control policy on the specified resource. Replaces any existing policy. +func (c *resourcePoliciesRESTClient) SetIamPolicy(ctx context.Context, req *computepb.SetIamPolicyResourcePolicyRequest, opts ...gax.CallOption) (*computepb.Policy, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetRegionSetPolicyRequestResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/regions/%v/resourcePolicies/%v/setIamPolicy", req.GetProject(), req.GetRegion(), req.GetResource()) + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Policy{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// TestIamPermissions returns permissions that a caller has on the specified resource. +func (c *resourcePoliciesRESTClient) TestIamPermissions(ctx context.Context, req *computepb.TestIamPermissionsResourcePolicyRequest, opts ...gax.CallOption) (*computepb.TestPermissionsResponse, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetTestPermissionsRequestResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/regions/%v/resourcePolicies/%v/testIamPermissions", req.GetProject(), req.GetRegion(), req.GetResource()) + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.TestPermissionsResponse{} + + return rsp, unm.Unmarshal(buf, rsp) +} diff --git a/compute/apiv1/resource_policies_client_example_test.go b/compute/apiv1/resource_policies_client_example_test.go new file mode 100644 index 00000000000..361e180ee6e --- /dev/null +++ b/compute/apiv1/resource_policies_client_example_test.go @@ -0,0 +1,188 @@ +// 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 compute_test + +import ( + "context" + + compute "cloud.google.com/go/compute/apiv1" + computepb "google.golang.org/genproto/googleapis/cloud/compute/v1" +) + +func ExampleNewResourcePoliciesRESTClient() { + ctx := context.Background() + c, err := compute.NewResourcePoliciesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + // TODO: Use client. + _ = c +} + +func ExampleResourcePoliciesClient_AggregatedList() { + ctx := context.Background() + c, err := compute.NewResourcePoliciesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.AggregatedListResourcePoliciesRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.AggregatedList(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleResourcePoliciesClient_Delete() { + ctx := context.Background() + c, err := compute.NewResourcePoliciesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.DeleteResourcePolicyRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Delete(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleResourcePoliciesClient_Get() { + ctx := context.Background() + c, err := compute.NewResourcePoliciesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.GetResourcePolicyRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Get(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleResourcePoliciesClient_GetIamPolicy() { + ctx := context.Background() + c, err := compute.NewResourcePoliciesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.GetIamPolicyResourcePolicyRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.GetIamPolicy(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleResourcePoliciesClient_Insert() { + ctx := context.Background() + c, err := compute.NewResourcePoliciesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.InsertResourcePolicyRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Insert(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleResourcePoliciesClient_List() { + ctx := context.Background() + c, err := compute.NewResourcePoliciesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.ListResourcePoliciesRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.List(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleResourcePoliciesClient_SetIamPolicy() { + ctx := context.Background() + c, err := compute.NewResourcePoliciesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.SetIamPolicyResourcePolicyRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.SetIamPolicy(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleResourcePoliciesClient_TestIamPermissions() { + ctx := context.Background() + c, err := compute.NewResourcePoliciesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.TestIamPermissionsResourcePolicyRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.TestIamPermissions(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} diff --git a/compute/apiv1/routers_client.go b/compute/apiv1/routers_client.go new file mode 100644 index 00000000000..b454d1707d6 --- /dev/null +++ b/compute/apiv1/routers_client.go @@ -0,0 +1,747 @@ +// 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 compute + +import ( + "bytes" + "context" + "fmt" + "io/ioutil" + "net/http" + "net/url" + + gax "github.com/googleapis/gax-go/v2" + "google.golang.org/api/option" + "google.golang.org/api/option/internaloption" + httptransport "google.golang.org/api/transport/http" + computepb "google.golang.org/genproto/googleapis/cloud/compute/v1" + "google.golang.org/grpc" + "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/encoding/protojson" +) + +var newRoutersClientHook clientHook + +// RoutersCallOptions contains the retry settings for each method of RoutersClient. +type RoutersCallOptions struct { + AggregatedList []gax.CallOption + Delete []gax.CallOption + Get []gax.CallOption + GetNatMappingInfo []gax.CallOption + GetRouterStatus []gax.CallOption + Insert []gax.CallOption + List []gax.CallOption + Patch []gax.CallOption + Preview []gax.CallOption + Update []gax.CallOption +} + +// internalRoutersClient is an interface that defines the methods availaible from Google Compute Engine API. +type internalRoutersClient interface { + Close() error + setGoogleClientInfo(...string) + Connection() *grpc.ClientConn + AggregatedList(context.Context, *computepb.AggregatedListRoutersRequest, ...gax.CallOption) (*computepb.RouterAggregatedList, error) + Delete(context.Context, *computepb.DeleteRouterRequest, ...gax.CallOption) (*computepb.Operation, error) + Get(context.Context, *computepb.GetRouterRequest, ...gax.CallOption) (*computepb.Router, error) + GetNatMappingInfo(context.Context, *computepb.GetNatMappingInfoRoutersRequest, ...gax.CallOption) (*computepb.VmEndpointNatMappingsList, error) + GetRouterStatus(context.Context, *computepb.GetRouterStatusRouterRequest, ...gax.CallOption) (*computepb.RouterStatusResponse, error) + Insert(context.Context, *computepb.InsertRouterRequest, ...gax.CallOption) (*computepb.Operation, error) + List(context.Context, *computepb.ListRoutersRequest, ...gax.CallOption) (*computepb.RouterList, error) + Patch(context.Context, *computepb.PatchRouterRequest, ...gax.CallOption) (*computepb.Operation, error) + Preview(context.Context, *computepb.PreviewRouterRequest, ...gax.CallOption) (*computepb.RoutersPreviewResponse, error) + Update(context.Context, *computepb.UpdateRouterRequest, ...gax.CallOption) (*computepb.Operation, error) +} + +// RoutersClient is a client for interacting with Google Compute Engine API. +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +// +// The Routers API. +type RoutersClient struct { + // The internal transport-dependent client. + internalClient internalRoutersClient + + // The call options for this service. + CallOptions *RoutersCallOptions +} + +// 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 *RoutersClient) 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 *RoutersClient) setGoogleClientInfo(keyval ...string) { + c.internalClient.setGoogleClientInfo(keyval...) +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *RoutersClient) Connection() *grpc.ClientConn { + return c.internalClient.Connection() +} + +// AggregatedList retrieves an aggregated list of routers. +func (c *RoutersClient) AggregatedList(ctx context.Context, req *computepb.AggregatedListRoutersRequest, opts ...gax.CallOption) (*computepb.RouterAggregatedList, error) { + return c.internalClient.AggregatedList(ctx, req, opts...) +} + +// Delete deletes the specified Router resource. +func (c *RoutersClient) Delete(ctx context.Context, req *computepb.DeleteRouterRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.Delete(ctx, req, opts...) +} + +// Get returns the specified Router resource. Gets a list of available routers by making a list() request. +func (c *RoutersClient) Get(ctx context.Context, req *computepb.GetRouterRequest, opts ...gax.CallOption) (*computepb.Router, error) { + return c.internalClient.Get(ctx, req, opts...) +} + +// GetNatMappingInfo retrieves runtime Nat mapping information of VM endpoints. +func (c *RoutersClient) GetNatMappingInfo(ctx context.Context, req *computepb.GetNatMappingInfoRoutersRequest, opts ...gax.CallOption) (*computepb.VmEndpointNatMappingsList, error) { + return c.internalClient.GetNatMappingInfo(ctx, req, opts...) +} + +// GetRouterStatus retrieves runtime information of the specified router. +func (c *RoutersClient) GetRouterStatus(ctx context.Context, req *computepb.GetRouterStatusRouterRequest, opts ...gax.CallOption) (*computepb.RouterStatusResponse, error) { + return c.internalClient.GetRouterStatus(ctx, req, opts...) +} + +// Insert creates a Router resource in the specified project and region using the data included in the request. +func (c *RoutersClient) Insert(ctx context.Context, req *computepb.InsertRouterRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.Insert(ctx, req, opts...) +} + +// List retrieves a list of Router resources available to the specified project. +func (c *RoutersClient) List(ctx context.Context, req *computepb.ListRoutersRequest, opts ...gax.CallOption) (*computepb.RouterList, error) { + return c.internalClient.List(ctx, req, opts...) +} + +// Patch patches the specified Router resource with the data included in the request. This method supports PATCH semantics and uses JSON merge patch format and processing rules. +func (c *RoutersClient) Patch(ctx context.Context, req *computepb.PatchRouterRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.Patch(ctx, req, opts...) +} + +// Preview preview fields auto-generated during router create and update operations. Calling this method does NOT create or update the router. +func (c *RoutersClient) Preview(ctx context.Context, req *computepb.PreviewRouterRequest, opts ...gax.CallOption) (*computepb.RoutersPreviewResponse, error) { + return c.internalClient.Preview(ctx, req, opts...) +} + +// Update updates the specified Router resource with the data included in the request. This method conforms to PUT semantics, which requests that the state of the target resource be created or replaced with the state defined by the representation enclosed in the request message payload. +func (c *RoutersClient) Update(ctx context.Context, req *computepb.UpdateRouterRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.Update(ctx, req, opts...) +} + +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +type routersRESTClient struct { + // The http endpoint to connect to. + endpoint string + + // The http client. + httpClient *http.Client + + // The x-goog-* metadata to be sent with each request. + xGoogMetadata metadata.MD +} + +// NewRoutersRESTClient creates a new routers rest client. +// +// The Routers API. +func NewRoutersRESTClient(ctx context.Context, opts ...option.ClientOption) (*RoutersClient, error) { + clientOpts := append(defaultRoutersRESTClientOptions(), opts...) + httpClient, endpoint, err := httptransport.NewClient(ctx, clientOpts...) + if err != nil { + return nil, err + } + + c := &routersRESTClient{ + endpoint: endpoint, + httpClient: httpClient, + } + c.setGoogleClientInfo() + + return &RoutersClient{internalClient: c, CallOptions: &RoutersCallOptions{}}, nil +} + +func defaultRoutersRESTClientOptions() []option.ClientOption { + return []option.ClientOption{ + internaloption.WithDefaultEndpoint("compute.googleapis.com"), + internaloption.WithDefaultMTLSEndpoint("compute.mtls.googleapis.com"), + internaloption.WithDefaultAudience("https://compute.googleapis.com/"), + internaloption.WithDefaultScopes(DefaultAuthScopes()...), + } +} + +// 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 *routersRESTClient) setGoogleClientInfo(keyval ...string) { + kv := append([]string{"gl-go", versionGo()}, keyval...) + kv = append(kv, "gapic", versionClient, "gax", gax.Version, "rest", "UNKNOWN") + 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 *routersRESTClient) Close() error { + // Replace httpClient with nil to force cleanup. + c.httpClient = nil + return nil +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *routersRESTClient) Connection() *grpc.ClientConn { + return nil +} + +// AggregatedList retrieves an aggregated list of routers. +func (c *routersRESTClient) AggregatedList(ctx context.Context, req *computepb.AggregatedListRoutersRequest, opts ...gax.CallOption) (*computepb.RouterAggregatedList, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/aggregated/routers", req.GetProject()) + + params := url.Values{} + if req != nil && req.Filter != nil { + params.Add("filter", fmt.Sprintf("%v", req.GetFilter())) + } + if req != nil && req.IncludeAllScopes != nil { + params.Add("includeAllScopes", fmt.Sprintf("%v", req.GetIncludeAllScopes())) + } + if req != nil && req.MaxResults != nil { + params.Add("maxResults", fmt.Sprintf("%v", req.GetMaxResults())) + } + if req != nil && req.OrderBy != nil { + params.Add("orderBy", fmt.Sprintf("%v", req.GetOrderBy())) + } + if req != nil && req.PageToken != nil { + params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) + } + if req != nil && req.ReturnPartialSuccess != nil { + params.Add("returnPartialSuccess", fmt.Sprintf("%v", req.GetReturnPartialSuccess())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.RouterAggregatedList{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Delete deletes the specified Router resource. +func (c *routersRESTClient) Delete(ctx context.Context, req *computepb.DeleteRouterRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/regions/%v/routers/%v", req.GetProject(), req.GetRegion(), req.GetRouter()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("DELETE", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Get returns the specified Router resource. Gets a list of available routers by making a list() request. +func (c *routersRESTClient) Get(ctx context.Context, req *computepb.GetRouterRequest, opts ...gax.CallOption) (*computepb.Router, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/regions/%v/routers/%v", req.GetProject(), req.GetRegion(), req.GetRouter()) + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Router{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// GetNatMappingInfo retrieves runtime Nat mapping information of VM endpoints. +func (c *routersRESTClient) GetNatMappingInfo(ctx context.Context, req *computepb.GetNatMappingInfoRoutersRequest, opts ...gax.CallOption) (*computepb.VmEndpointNatMappingsList, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/regions/%v/routers/%v/getNatMappingInfo", req.GetProject(), req.GetRegion(), req.GetRouter()) + + params := url.Values{} + if req != nil && req.Filter != nil { + params.Add("filter", fmt.Sprintf("%v", req.GetFilter())) + } + if req != nil && req.MaxResults != nil { + params.Add("maxResults", fmt.Sprintf("%v", req.GetMaxResults())) + } + if req != nil && req.OrderBy != nil { + params.Add("orderBy", fmt.Sprintf("%v", req.GetOrderBy())) + } + if req != nil && req.PageToken != nil { + params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) + } + if req != nil && req.ReturnPartialSuccess != nil { + params.Add("returnPartialSuccess", fmt.Sprintf("%v", req.GetReturnPartialSuccess())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.VmEndpointNatMappingsList{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// GetRouterStatus retrieves runtime information of the specified router. +func (c *routersRESTClient) GetRouterStatus(ctx context.Context, req *computepb.GetRouterStatusRouterRequest, opts ...gax.CallOption) (*computepb.RouterStatusResponse, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/regions/%v/routers/%v/getRouterStatus", req.GetProject(), req.GetRegion(), req.GetRouter()) + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.RouterStatusResponse{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Insert creates a Router resource in the specified project and region using the data included in the request. +func (c *routersRESTClient) Insert(ctx context.Context, req *computepb.InsertRouterRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetRouterResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/regions/%v/routers", req.GetProject(), req.GetRegion()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// List retrieves a list of Router resources available to the specified project. +func (c *routersRESTClient) List(ctx context.Context, req *computepb.ListRoutersRequest, opts ...gax.CallOption) (*computepb.RouterList, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/regions/%v/routers", req.GetProject(), req.GetRegion()) + + params := url.Values{} + if req != nil && req.Filter != nil { + params.Add("filter", fmt.Sprintf("%v", req.GetFilter())) + } + if req != nil && req.MaxResults != nil { + params.Add("maxResults", fmt.Sprintf("%v", req.GetMaxResults())) + } + if req != nil && req.OrderBy != nil { + params.Add("orderBy", fmt.Sprintf("%v", req.GetOrderBy())) + } + if req != nil && req.PageToken != nil { + params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) + } + if req != nil && req.ReturnPartialSuccess != nil { + params.Add("returnPartialSuccess", fmt.Sprintf("%v", req.GetReturnPartialSuccess())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.RouterList{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Patch patches the specified Router resource with the data included in the request. This method supports PATCH semantics and uses JSON merge patch format and processing rules. +func (c *routersRESTClient) Patch(ctx context.Context, req *computepb.PatchRouterRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetRouterResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/regions/%v/routers/%v", req.GetProject(), req.GetRegion(), req.GetRouter()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("PATCH", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Preview preview fields auto-generated during router create and update operations. Calling this method does NOT create or update the router. +func (c *routersRESTClient) Preview(ctx context.Context, req *computepb.PreviewRouterRequest, opts ...gax.CallOption) (*computepb.RoutersPreviewResponse, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetRouterResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/regions/%v/routers/%v/preview", req.GetProject(), req.GetRegion(), req.GetRouter()) + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.RoutersPreviewResponse{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Update updates the specified Router resource with the data included in the request. This method conforms to PUT semantics, which requests that the state of the target resource be created or replaced with the state defined by the representation enclosed in the request message payload. +func (c *routersRESTClient) Update(ctx context.Context, req *computepb.UpdateRouterRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetRouterResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("") + + params := url.Values{} + if req.GetProject() != "" { + params.Add("project", fmt.Sprintf("%v", req.GetProject())) + } + if req.GetRegion() != "" { + params.Add("region", fmt.Sprintf("%v", req.GetRegion())) + } + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + if req.GetRouter() != "" { + params.Add("router", fmt.Sprintf("%v", req.GetRouter())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("PUT", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} diff --git a/compute/apiv1/routers_client_example_test.go b/compute/apiv1/routers_client_example_test.go new file mode 100644 index 00000000000..96553d9bd1d --- /dev/null +++ b/compute/apiv1/routers_client_example_test.go @@ -0,0 +1,226 @@ +// 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 compute_test + +import ( + "context" + + compute "cloud.google.com/go/compute/apiv1" + computepb "google.golang.org/genproto/googleapis/cloud/compute/v1" +) + +func ExampleNewRoutersRESTClient() { + ctx := context.Background() + c, err := compute.NewRoutersRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + // TODO: Use client. + _ = c +} + +func ExampleRoutersClient_AggregatedList() { + ctx := context.Background() + c, err := compute.NewRoutersRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.AggregatedListRoutersRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.AggregatedList(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleRoutersClient_Delete() { + ctx := context.Background() + c, err := compute.NewRoutersRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.DeleteRouterRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Delete(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleRoutersClient_Get() { + ctx := context.Background() + c, err := compute.NewRoutersRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.GetRouterRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Get(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleRoutersClient_GetNatMappingInfo() { + ctx := context.Background() + c, err := compute.NewRoutersRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.GetNatMappingInfoRoutersRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.GetNatMappingInfo(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleRoutersClient_GetRouterStatus() { + ctx := context.Background() + c, err := compute.NewRoutersRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.GetRouterStatusRouterRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.GetRouterStatus(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleRoutersClient_Insert() { + ctx := context.Background() + c, err := compute.NewRoutersRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.InsertRouterRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Insert(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleRoutersClient_List() { + ctx := context.Background() + c, err := compute.NewRoutersRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.ListRoutersRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.List(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleRoutersClient_Patch() { + ctx := context.Background() + c, err := compute.NewRoutersRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.PatchRouterRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Patch(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleRoutersClient_Preview() { + ctx := context.Background() + c, err := compute.NewRoutersRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.PreviewRouterRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Preview(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleRoutersClient_Update() { + ctx := context.Background() + c, err := compute.NewRoutersRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.UpdateRouterRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Update(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} diff --git a/compute/apiv1/routes_client.go b/compute/apiv1/routes_client.go new file mode 100644 index 00000000000..cd8f909f21b --- /dev/null +++ b/compute/apiv1/routes_client.go @@ -0,0 +1,380 @@ +// 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 compute + +import ( + "bytes" + "context" + "fmt" + "io/ioutil" + "net/http" + "net/url" + + gax "github.com/googleapis/gax-go/v2" + "google.golang.org/api/option" + "google.golang.org/api/option/internaloption" + httptransport "google.golang.org/api/transport/http" + computepb "google.golang.org/genproto/googleapis/cloud/compute/v1" + "google.golang.org/grpc" + "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/encoding/protojson" +) + +var newRoutesClientHook clientHook + +// RoutesCallOptions contains the retry settings for each method of RoutesClient. +type RoutesCallOptions struct { + Delete []gax.CallOption + Get []gax.CallOption + Insert []gax.CallOption + List []gax.CallOption +} + +// internalRoutesClient is an interface that defines the methods availaible from Google Compute Engine API. +type internalRoutesClient interface { + Close() error + setGoogleClientInfo(...string) + Connection() *grpc.ClientConn + Delete(context.Context, *computepb.DeleteRouteRequest, ...gax.CallOption) (*computepb.Operation, error) + Get(context.Context, *computepb.GetRouteRequest, ...gax.CallOption) (*computepb.Route, error) + Insert(context.Context, *computepb.InsertRouteRequest, ...gax.CallOption) (*computepb.Operation, error) + List(context.Context, *computepb.ListRoutesRequest, ...gax.CallOption) (*computepb.RouteList, error) +} + +// RoutesClient is a client for interacting with Google Compute Engine API. +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +// +// The Routes API. +type RoutesClient struct { + // The internal transport-dependent client. + internalClient internalRoutesClient + + // The call options for this service. + CallOptions *RoutesCallOptions +} + +// 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 *RoutesClient) 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 *RoutesClient) setGoogleClientInfo(keyval ...string) { + c.internalClient.setGoogleClientInfo(keyval...) +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *RoutesClient) Connection() *grpc.ClientConn { + return c.internalClient.Connection() +} + +// Delete deletes the specified Route resource. +func (c *RoutesClient) Delete(ctx context.Context, req *computepb.DeleteRouteRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.Delete(ctx, req, opts...) +} + +// Get returns the specified Route resource. Gets a list of available routes by making a list() request. +func (c *RoutesClient) Get(ctx context.Context, req *computepb.GetRouteRequest, opts ...gax.CallOption) (*computepb.Route, error) { + return c.internalClient.Get(ctx, req, opts...) +} + +// Insert creates a Route resource in the specified project using the data included in the request. +func (c *RoutesClient) Insert(ctx context.Context, req *computepb.InsertRouteRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.Insert(ctx, req, opts...) +} + +// List retrieves the list of Route resources available to the specified project. +func (c *RoutesClient) List(ctx context.Context, req *computepb.ListRoutesRequest, opts ...gax.CallOption) (*computepb.RouteList, error) { + return c.internalClient.List(ctx, req, opts...) +} + +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +type routesRESTClient struct { + // The http endpoint to connect to. + endpoint string + + // The http client. + httpClient *http.Client + + // The x-goog-* metadata to be sent with each request. + xGoogMetadata metadata.MD +} + +// NewRoutesRESTClient creates a new routes rest client. +// +// The Routes API. +func NewRoutesRESTClient(ctx context.Context, opts ...option.ClientOption) (*RoutesClient, error) { + clientOpts := append(defaultRoutesRESTClientOptions(), opts...) + httpClient, endpoint, err := httptransport.NewClient(ctx, clientOpts...) + if err != nil { + return nil, err + } + + c := &routesRESTClient{ + endpoint: endpoint, + httpClient: httpClient, + } + c.setGoogleClientInfo() + + return &RoutesClient{internalClient: c, CallOptions: &RoutesCallOptions{}}, nil +} + +func defaultRoutesRESTClientOptions() []option.ClientOption { + return []option.ClientOption{ + internaloption.WithDefaultEndpoint("compute.googleapis.com"), + internaloption.WithDefaultMTLSEndpoint("compute.mtls.googleapis.com"), + internaloption.WithDefaultAudience("https://compute.googleapis.com/"), + internaloption.WithDefaultScopes(DefaultAuthScopes()...), + } +} + +// 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 *routesRESTClient) setGoogleClientInfo(keyval ...string) { + kv := append([]string{"gl-go", versionGo()}, keyval...) + kv = append(kv, "gapic", versionClient, "gax", gax.Version, "rest", "UNKNOWN") + 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 *routesRESTClient) Close() error { + // Replace httpClient with nil to force cleanup. + c.httpClient = nil + return nil +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *routesRESTClient) Connection() *grpc.ClientConn { + return nil +} + +// Delete deletes the specified Route resource. +func (c *routesRESTClient) Delete(ctx context.Context, req *computepb.DeleteRouteRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/routes/%v", req.GetProject(), req.GetRoute()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("DELETE", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Get returns the specified Route resource. Gets a list of available routes by making a list() request. +func (c *routesRESTClient) Get(ctx context.Context, req *computepb.GetRouteRequest, opts ...gax.CallOption) (*computepb.Route, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/routes/%v", req.GetProject(), req.GetRoute()) + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Route{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Insert creates a Route resource in the specified project using the data included in the request. +func (c *routesRESTClient) Insert(ctx context.Context, req *computepb.InsertRouteRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetRouteResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/routes", req.GetProject()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// List retrieves the list of Route resources available to the specified project. +func (c *routesRESTClient) List(ctx context.Context, req *computepb.ListRoutesRequest, opts ...gax.CallOption) (*computepb.RouteList, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/routes", req.GetProject()) + + params := url.Values{} + if req != nil && req.Filter != nil { + params.Add("filter", fmt.Sprintf("%v", req.GetFilter())) + } + if req != nil && req.MaxResults != nil { + params.Add("maxResults", fmt.Sprintf("%v", req.GetMaxResults())) + } + if req != nil && req.OrderBy != nil { + params.Add("orderBy", fmt.Sprintf("%v", req.GetOrderBy())) + } + if req != nil && req.PageToken != nil { + params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) + } + if req != nil && req.ReturnPartialSuccess != nil { + params.Add("returnPartialSuccess", fmt.Sprintf("%v", req.GetReturnPartialSuccess())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.RouteList{} + + return rsp, unm.Unmarshal(buf, rsp) +} diff --git a/compute/apiv1/routes_client_example_test.go b/compute/apiv1/routes_client_example_test.go new file mode 100644 index 00000000000..730354784ea --- /dev/null +++ b/compute/apiv1/routes_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 compute_test + +import ( + "context" + + compute "cloud.google.com/go/compute/apiv1" + computepb "google.golang.org/genproto/googleapis/cloud/compute/v1" +) + +func ExampleNewRoutesRESTClient() { + ctx := context.Background() + c, err := compute.NewRoutesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + // TODO: Use client. + _ = c +} + +func ExampleRoutesClient_Delete() { + ctx := context.Background() + c, err := compute.NewRoutesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.DeleteRouteRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Delete(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleRoutesClient_Get() { + ctx := context.Background() + c, err := compute.NewRoutesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.GetRouteRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Get(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleRoutesClient_Insert() { + ctx := context.Background() + c, err := compute.NewRoutesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.InsertRouteRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Insert(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleRoutesClient_List() { + ctx := context.Background() + c, err := compute.NewRoutesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.ListRoutesRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.List(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} diff --git a/compute/apiv1/security_policies_client.go b/compute/apiv1/security_policies_client.go new file mode 100644 index 00000000000..fceb1652547 --- /dev/null +++ b/compute/apiv1/security_policies_client.go @@ -0,0 +1,730 @@ +// 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 compute + +import ( + "bytes" + "context" + "fmt" + "io/ioutil" + "net/http" + "net/url" + + gax "github.com/googleapis/gax-go/v2" + "google.golang.org/api/option" + "google.golang.org/api/option/internaloption" + httptransport "google.golang.org/api/transport/http" + computepb "google.golang.org/genproto/googleapis/cloud/compute/v1" + "google.golang.org/grpc" + "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/encoding/protojson" +) + +var newSecurityPoliciesClientHook clientHook + +// SecurityPoliciesCallOptions contains the retry settings for each method of SecurityPoliciesClient. +type SecurityPoliciesCallOptions struct { + AddRule []gax.CallOption + Delete []gax.CallOption + Get []gax.CallOption + GetRule []gax.CallOption + Insert []gax.CallOption + List []gax.CallOption + ListPreconfiguredExpressionSets []gax.CallOption + Patch []gax.CallOption + PatchRule []gax.CallOption + RemoveRule []gax.CallOption +} + +// internalSecurityPoliciesClient is an interface that defines the methods availaible from Google Compute Engine API. +type internalSecurityPoliciesClient interface { + Close() error + setGoogleClientInfo(...string) + Connection() *grpc.ClientConn + AddRule(context.Context, *computepb.AddRuleSecurityPolicyRequest, ...gax.CallOption) (*computepb.Operation, error) + Delete(context.Context, *computepb.DeleteSecurityPolicyRequest, ...gax.CallOption) (*computepb.Operation, error) + Get(context.Context, *computepb.GetSecurityPolicyRequest, ...gax.CallOption) (*computepb.SecurityPolicy, error) + GetRule(context.Context, *computepb.GetRuleSecurityPolicyRequest, ...gax.CallOption) (*computepb.SecurityPolicyRule, error) + Insert(context.Context, *computepb.InsertSecurityPolicyRequest, ...gax.CallOption) (*computepb.Operation, error) + List(context.Context, *computepb.ListSecurityPoliciesRequest, ...gax.CallOption) (*computepb.SecurityPolicyList, error) + ListPreconfiguredExpressionSets(context.Context, *computepb.ListPreconfiguredExpressionSetsSecurityPoliciesRequest, ...gax.CallOption) (*computepb.SecurityPoliciesListPreconfiguredExpressionSetsResponse, error) + Patch(context.Context, *computepb.PatchSecurityPolicyRequest, ...gax.CallOption) (*computepb.Operation, error) + PatchRule(context.Context, *computepb.PatchRuleSecurityPolicyRequest, ...gax.CallOption) (*computepb.Operation, error) + RemoveRule(context.Context, *computepb.RemoveRuleSecurityPolicyRequest, ...gax.CallOption) (*computepb.Operation, error) +} + +// SecurityPoliciesClient is a client for interacting with Google Compute Engine API. +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +// +// The SecurityPolicies API. +type SecurityPoliciesClient struct { + // The internal transport-dependent client. + internalClient internalSecurityPoliciesClient + + // The call options for this service. + CallOptions *SecurityPoliciesCallOptions +} + +// 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 *SecurityPoliciesClient) 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 *SecurityPoliciesClient) setGoogleClientInfo(keyval ...string) { + c.internalClient.setGoogleClientInfo(keyval...) +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *SecurityPoliciesClient) Connection() *grpc.ClientConn { + return c.internalClient.Connection() +} + +// AddRule inserts a rule into a security policy. +func (c *SecurityPoliciesClient) AddRule(ctx context.Context, req *computepb.AddRuleSecurityPolicyRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.AddRule(ctx, req, opts...) +} + +// Delete deletes the specified policy. +func (c *SecurityPoliciesClient) Delete(ctx context.Context, req *computepb.DeleteSecurityPolicyRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.Delete(ctx, req, opts...) +} + +// Get list all of the ordered rules present in a single specified policy. +func (c *SecurityPoliciesClient) Get(ctx context.Context, req *computepb.GetSecurityPolicyRequest, opts ...gax.CallOption) (*computepb.SecurityPolicy, error) { + return c.internalClient.Get(ctx, req, opts...) +} + +// GetRule gets a rule at the specified priority. +func (c *SecurityPoliciesClient) GetRule(ctx context.Context, req *computepb.GetRuleSecurityPolicyRequest, opts ...gax.CallOption) (*computepb.SecurityPolicyRule, error) { + return c.internalClient.GetRule(ctx, req, opts...) +} + +// Insert creates a new policy in the specified project using the data included in the request. +func (c *SecurityPoliciesClient) Insert(ctx context.Context, req *computepb.InsertSecurityPolicyRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.Insert(ctx, req, opts...) +} + +// List list all the policies that have been configured for the specified project. +func (c *SecurityPoliciesClient) List(ctx context.Context, req *computepb.ListSecurityPoliciesRequest, opts ...gax.CallOption) (*computepb.SecurityPolicyList, error) { + return c.internalClient.List(ctx, req, opts...) +} + +// ListPreconfiguredExpressionSets gets the current list of preconfigured Web Application Firewall (WAF) expressions. +func (c *SecurityPoliciesClient) ListPreconfiguredExpressionSets(ctx context.Context, req *computepb.ListPreconfiguredExpressionSetsSecurityPoliciesRequest, opts ...gax.CallOption) (*computepb.SecurityPoliciesListPreconfiguredExpressionSetsResponse, error) { + return c.internalClient.ListPreconfiguredExpressionSets(ctx, req, opts...) +} + +// Patch patches the specified policy with the data included in the request. This cannot be used to be update the rules in the policy. Please use the per rule methods like addRule, patchRule, and removeRule instead. +func (c *SecurityPoliciesClient) Patch(ctx context.Context, req *computepb.PatchSecurityPolicyRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.Patch(ctx, req, opts...) +} + +// PatchRule patches a rule at the specified priority. +func (c *SecurityPoliciesClient) PatchRule(ctx context.Context, req *computepb.PatchRuleSecurityPolicyRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.PatchRule(ctx, req, opts...) +} + +// RemoveRule deletes a rule at the specified priority. +func (c *SecurityPoliciesClient) RemoveRule(ctx context.Context, req *computepb.RemoveRuleSecurityPolicyRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.RemoveRule(ctx, req, opts...) +} + +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +type securityPoliciesRESTClient struct { + // The http endpoint to connect to. + endpoint string + + // The http client. + httpClient *http.Client + + // The x-goog-* metadata to be sent with each request. + xGoogMetadata metadata.MD +} + +// NewSecurityPoliciesRESTClient creates a new security policies rest client. +// +// The SecurityPolicies API. +func NewSecurityPoliciesRESTClient(ctx context.Context, opts ...option.ClientOption) (*SecurityPoliciesClient, error) { + clientOpts := append(defaultSecurityPoliciesRESTClientOptions(), opts...) + httpClient, endpoint, err := httptransport.NewClient(ctx, clientOpts...) + if err != nil { + return nil, err + } + + c := &securityPoliciesRESTClient{ + endpoint: endpoint, + httpClient: httpClient, + } + c.setGoogleClientInfo() + + return &SecurityPoliciesClient{internalClient: c, CallOptions: &SecurityPoliciesCallOptions{}}, nil +} + +func defaultSecurityPoliciesRESTClientOptions() []option.ClientOption { + return []option.ClientOption{ + internaloption.WithDefaultEndpoint("compute.googleapis.com"), + internaloption.WithDefaultMTLSEndpoint("compute.mtls.googleapis.com"), + internaloption.WithDefaultAudience("https://compute.googleapis.com/"), + internaloption.WithDefaultScopes(DefaultAuthScopes()...), + } +} + +// 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 *securityPoliciesRESTClient) setGoogleClientInfo(keyval ...string) { + kv := append([]string{"gl-go", versionGo()}, keyval...) + kv = append(kv, "gapic", versionClient, "gax", gax.Version, "rest", "UNKNOWN") + 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 *securityPoliciesRESTClient) Close() error { + // Replace httpClient with nil to force cleanup. + c.httpClient = nil + return nil +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *securityPoliciesRESTClient) Connection() *grpc.ClientConn { + return nil +} + +// AddRule inserts a rule into a security policy. +func (c *securityPoliciesRESTClient) AddRule(ctx context.Context, req *computepb.AddRuleSecurityPolicyRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetSecurityPolicyRuleResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/securityPolicies/%v/addRule", req.GetProject(), req.GetSecurityPolicy()) + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Delete deletes the specified policy. +func (c *securityPoliciesRESTClient) Delete(ctx context.Context, req *computepb.DeleteSecurityPolicyRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/securityPolicies/%v", req.GetProject(), req.GetSecurityPolicy()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("DELETE", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Get list all of the ordered rules present in a single specified policy. +func (c *securityPoliciesRESTClient) Get(ctx context.Context, req *computepb.GetSecurityPolicyRequest, opts ...gax.CallOption) (*computepb.SecurityPolicy, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/securityPolicies/%v", req.GetProject(), req.GetSecurityPolicy()) + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.SecurityPolicy{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// GetRule gets a rule at the specified priority. +func (c *securityPoliciesRESTClient) GetRule(ctx context.Context, req *computepb.GetRuleSecurityPolicyRequest, opts ...gax.CallOption) (*computepb.SecurityPolicyRule, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/securityPolicies/%v/getRule", req.GetProject(), req.GetSecurityPolicy()) + + params := url.Values{} + if req != nil && req.Priority != nil { + params.Add("priority", fmt.Sprintf("%v", req.GetPriority())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.SecurityPolicyRule{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Insert creates a new policy in the specified project using the data included in the request. +func (c *securityPoliciesRESTClient) Insert(ctx context.Context, req *computepb.InsertSecurityPolicyRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetSecurityPolicyResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/securityPolicies", req.GetProject()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// List list all the policies that have been configured for the specified project. +func (c *securityPoliciesRESTClient) List(ctx context.Context, req *computepb.ListSecurityPoliciesRequest, opts ...gax.CallOption) (*computepb.SecurityPolicyList, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/securityPolicies", req.GetProject()) + + params := url.Values{} + if req != nil && req.Filter != nil { + params.Add("filter", fmt.Sprintf("%v", req.GetFilter())) + } + if req != nil && req.MaxResults != nil { + params.Add("maxResults", fmt.Sprintf("%v", req.GetMaxResults())) + } + if req != nil && req.OrderBy != nil { + params.Add("orderBy", fmt.Sprintf("%v", req.GetOrderBy())) + } + if req != nil && req.PageToken != nil { + params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) + } + if req != nil && req.ReturnPartialSuccess != nil { + params.Add("returnPartialSuccess", fmt.Sprintf("%v", req.GetReturnPartialSuccess())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.SecurityPolicyList{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// ListPreconfiguredExpressionSets gets the current list of preconfigured Web Application Firewall (WAF) expressions. +func (c *securityPoliciesRESTClient) ListPreconfiguredExpressionSets(ctx context.Context, req *computepb.ListPreconfiguredExpressionSetsSecurityPoliciesRequest, opts ...gax.CallOption) (*computepb.SecurityPoliciesListPreconfiguredExpressionSetsResponse, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/securityPolicies/listPreconfiguredExpressionSets", req.GetProject()) + + params := url.Values{} + if req != nil && req.Filter != nil { + params.Add("filter", fmt.Sprintf("%v", req.GetFilter())) + } + if req != nil && req.MaxResults != nil { + params.Add("maxResults", fmt.Sprintf("%v", req.GetMaxResults())) + } + if req != nil && req.OrderBy != nil { + params.Add("orderBy", fmt.Sprintf("%v", req.GetOrderBy())) + } + if req != nil && req.PageToken != nil { + params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) + } + if req != nil && req.ReturnPartialSuccess != nil { + params.Add("returnPartialSuccess", fmt.Sprintf("%v", req.GetReturnPartialSuccess())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.SecurityPoliciesListPreconfiguredExpressionSetsResponse{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Patch patches the specified policy with the data included in the request. This cannot be used to be update the rules in the policy. Please use the per rule methods like addRule, patchRule, and removeRule instead. +func (c *securityPoliciesRESTClient) Patch(ctx context.Context, req *computepb.PatchSecurityPolicyRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetSecurityPolicyResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/securityPolicies/%v", req.GetProject(), req.GetSecurityPolicy()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("PATCH", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// PatchRule patches a rule at the specified priority. +func (c *securityPoliciesRESTClient) PatchRule(ctx context.Context, req *computepb.PatchRuleSecurityPolicyRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetSecurityPolicyRuleResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/securityPolicies/%v/patchRule", req.GetProject(), req.GetSecurityPolicy()) + + params := url.Values{} + if req != nil && req.Priority != nil { + params.Add("priority", fmt.Sprintf("%v", req.GetPriority())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// RemoveRule deletes a rule at the specified priority. +func (c *securityPoliciesRESTClient) RemoveRule(ctx context.Context, req *computepb.RemoveRuleSecurityPolicyRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/securityPolicies/%v/removeRule", req.GetProject(), req.GetSecurityPolicy()) + + params := url.Values{} + if req != nil && req.Priority != nil { + params.Add("priority", fmt.Sprintf("%v", req.GetPriority())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} diff --git a/compute/apiv1/security_policies_client_example_test.go b/compute/apiv1/security_policies_client_example_test.go new file mode 100644 index 00000000000..65dbeb4fc52 --- /dev/null +++ b/compute/apiv1/security_policies_client_example_test.go @@ -0,0 +1,226 @@ +// 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 compute_test + +import ( + "context" + + compute "cloud.google.com/go/compute/apiv1" + computepb "google.golang.org/genproto/googleapis/cloud/compute/v1" +) + +func ExampleNewSecurityPoliciesRESTClient() { + ctx := context.Background() + c, err := compute.NewSecurityPoliciesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + // TODO: Use client. + _ = c +} + +func ExampleSecurityPoliciesClient_AddRule() { + ctx := context.Background() + c, err := compute.NewSecurityPoliciesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.AddRuleSecurityPolicyRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.AddRule(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleSecurityPoliciesClient_Delete() { + ctx := context.Background() + c, err := compute.NewSecurityPoliciesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.DeleteSecurityPolicyRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Delete(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleSecurityPoliciesClient_Get() { + ctx := context.Background() + c, err := compute.NewSecurityPoliciesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.GetSecurityPolicyRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Get(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleSecurityPoliciesClient_GetRule() { + ctx := context.Background() + c, err := compute.NewSecurityPoliciesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.GetRuleSecurityPolicyRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.GetRule(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleSecurityPoliciesClient_Insert() { + ctx := context.Background() + c, err := compute.NewSecurityPoliciesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.InsertSecurityPolicyRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Insert(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleSecurityPoliciesClient_List() { + ctx := context.Background() + c, err := compute.NewSecurityPoliciesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.ListSecurityPoliciesRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.List(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleSecurityPoliciesClient_ListPreconfiguredExpressionSets() { + ctx := context.Background() + c, err := compute.NewSecurityPoliciesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.ListPreconfiguredExpressionSetsSecurityPoliciesRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.ListPreconfiguredExpressionSets(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleSecurityPoliciesClient_Patch() { + ctx := context.Background() + c, err := compute.NewSecurityPoliciesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.PatchSecurityPolicyRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Patch(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleSecurityPoliciesClient_PatchRule() { + ctx := context.Background() + c, err := compute.NewSecurityPoliciesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.PatchRuleSecurityPolicyRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.PatchRule(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleSecurityPoliciesClient_RemoveRule() { + ctx := context.Background() + c, err := compute.NewSecurityPoliciesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.RemoveRuleSecurityPolicyRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.RemoveRule(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} diff --git a/compute/apiv1/snapshots_client.go b/compute/apiv1/snapshots_client.go new file mode 100644 index 00000000000..d95bf38a6f8 --- /dev/null +++ b/compute/apiv1/snapshots_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 compute + +import ( + "bytes" + "context" + "fmt" + "io/ioutil" + "net/http" + "net/url" + + gax "github.com/googleapis/gax-go/v2" + "google.golang.org/api/option" + "google.golang.org/api/option/internaloption" + httptransport "google.golang.org/api/transport/http" + computepb "google.golang.org/genproto/googleapis/cloud/compute/v1" + "google.golang.org/grpc" + "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/encoding/protojson" +) + +var newSnapshotsClientHook clientHook + +// SnapshotsCallOptions contains the retry settings for each method of SnapshotsClient. +type SnapshotsCallOptions struct { + Delete []gax.CallOption + Get []gax.CallOption + GetIamPolicy []gax.CallOption + List []gax.CallOption + SetIamPolicy []gax.CallOption + SetLabels []gax.CallOption + TestIamPermissions []gax.CallOption +} + +// internalSnapshotsClient is an interface that defines the methods availaible from Google Compute Engine API. +type internalSnapshotsClient interface { + Close() error + setGoogleClientInfo(...string) + Connection() *grpc.ClientConn + Delete(context.Context, *computepb.DeleteSnapshotRequest, ...gax.CallOption) (*computepb.Operation, error) + Get(context.Context, *computepb.GetSnapshotRequest, ...gax.CallOption) (*computepb.Snapshot, error) + GetIamPolicy(context.Context, *computepb.GetIamPolicySnapshotRequest, ...gax.CallOption) (*computepb.Policy, error) + List(context.Context, *computepb.ListSnapshotsRequest, ...gax.CallOption) (*computepb.SnapshotList, error) + SetIamPolicy(context.Context, *computepb.SetIamPolicySnapshotRequest, ...gax.CallOption) (*computepb.Policy, error) + SetLabels(context.Context, *computepb.SetLabelsSnapshotRequest, ...gax.CallOption) (*computepb.Operation, error) + TestIamPermissions(context.Context, *computepb.TestIamPermissionsSnapshotRequest, ...gax.CallOption) (*computepb.TestPermissionsResponse, error) +} + +// SnapshotsClient is a client for interacting with Google Compute Engine API. +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +// +// The Snapshots API. +type SnapshotsClient struct { + // The internal transport-dependent client. + internalClient internalSnapshotsClient + + // The call options for this service. + CallOptions *SnapshotsCallOptions +} + +// 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 *SnapshotsClient) 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 *SnapshotsClient) setGoogleClientInfo(keyval ...string) { + c.internalClient.setGoogleClientInfo(keyval...) +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *SnapshotsClient) Connection() *grpc.ClientConn { + return c.internalClient.Connection() +} + +// Delete deletes the specified Snapshot resource. Keep in mind that deleting a single snapshot might not necessarily delete all the data on that snapshot. If any data on the snapshot that is marked for deletion is needed for subsequent snapshots, the data will be moved to the next corresponding snapshot. +// +// For more information, see Deleting snapshots. +func (c *SnapshotsClient) Delete(ctx context.Context, req *computepb.DeleteSnapshotRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.Delete(ctx, req, opts...) +} + +// Get returns the specified Snapshot resource. Gets a list of available snapshots by making a list() request. +func (c *SnapshotsClient) Get(ctx context.Context, req *computepb.GetSnapshotRequest, opts ...gax.CallOption) (*computepb.Snapshot, error) { + return c.internalClient.Get(ctx, req, opts...) +} + +// GetIamPolicy gets the access control policy for a resource. May be empty if no such policy or resource exists. +func (c *SnapshotsClient) GetIamPolicy(ctx context.Context, req *computepb.GetIamPolicySnapshotRequest, opts ...gax.CallOption) (*computepb.Policy, error) { + return c.internalClient.GetIamPolicy(ctx, req, opts...) +} + +// List retrieves the list of Snapshot resources contained within the specified project. +func (c *SnapshotsClient) List(ctx context.Context, req *computepb.ListSnapshotsRequest, opts ...gax.CallOption) (*computepb.SnapshotList, error) { + return c.internalClient.List(ctx, req, opts...) +} + +// SetIamPolicy sets the access control policy on the specified resource. Replaces any existing policy. +func (c *SnapshotsClient) SetIamPolicy(ctx context.Context, req *computepb.SetIamPolicySnapshotRequest, opts ...gax.CallOption) (*computepb.Policy, error) { + return c.internalClient.SetIamPolicy(ctx, req, opts...) +} + +// SetLabels sets the labels on a snapshot. To learn more about labels, read the Labeling Resources documentation. +func (c *SnapshotsClient) SetLabels(ctx context.Context, req *computepb.SetLabelsSnapshotRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.SetLabels(ctx, req, opts...) +} + +// TestIamPermissions returns permissions that a caller has on the specified resource. +func (c *SnapshotsClient) TestIamPermissions(ctx context.Context, req *computepb.TestIamPermissionsSnapshotRequest, opts ...gax.CallOption) (*computepb.TestPermissionsResponse, error) { + return c.internalClient.TestIamPermissions(ctx, req, opts...) +} + +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +type snapshotsRESTClient struct { + // The http endpoint to connect to. + endpoint string + + // The http client. + httpClient *http.Client + + // The x-goog-* metadata to be sent with each request. + xGoogMetadata metadata.MD +} + +// NewSnapshotsRESTClient creates a new snapshots rest client. +// +// The Snapshots API. +func NewSnapshotsRESTClient(ctx context.Context, opts ...option.ClientOption) (*SnapshotsClient, error) { + clientOpts := append(defaultSnapshotsRESTClientOptions(), opts...) + httpClient, endpoint, err := httptransport.NewClient(ctx, clientOpts...) + if err != nil { + return nil, err + } + + c := &snapshotsRESTClient{ + endpoint: endpoint, + httpClient: httpClient, + } + c.setGoogleClientInfo() + + return &SnapshotsClient{internalClient: c, CallOptions: &SnapshotsCallOptions{}}, nil +} + +func defaultSnapshotsRESTClientOptions() []option.ClientOption { + return []option.ClientOption{ + internaloption.WithDefaultEndpoint("compute.googleapis.com"), + internaloption.WithDefaultMTLSEndpoint("compute.mtls.googleapis.com"), + internaloption.WithDefaultAudience("https://compute.googleapis.com/"), + internaloption.WithDefaultScopes(DefaultAuthScopes()...), + } +} + +// 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 *snapshotsRESTClient) setGoogleClientInfo(keyval ...string) { + kv := append([]string{"gl-go", versionGo()}, keyval...) + kv = append(kv, "gapic", versionClient, "gax", gax.Version, "rest", "UNKNOWN") + 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 *snapshotsRESTClient) Close() error { + // Replace httpClient with nil to force cleanup. + c.httpClient = nil + return nil +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *snapshotsRESTClient) Connection() *grpc.ClientConn { + return nil +} + +// Delete deletes the specified Snapshot resource. Keep in mind that deleting a single snapshot might not necessarily delete all the data on that snapshot. If any data on the snapshot that is marked for deletion is needed for subsequent snapshots, the data will be moved to the next corresponding snapshot. +// +// For more information, see Deleting snapshots. +func (c *snapshotsRESTClient) Delete(ctx context.Context, req *computepb.DeleteSnapshotRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/snapshots/%v", req.GetProject(), req.GetSnapshot()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("DELETE", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Get returns the specified Snapshot resource. Gets a list of available snapshots by making a list() request. +func (c *snapshotsRESTClient) Get(ctx context.Context, req *computepb.GetSnapshotRequest, opts ...gax.CallOption) (*computepb.Snapshot, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/snapshots/%v", req.GetProject(), req.GetSnapshot()) + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Snapshot{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// GetIamPolicy gets the access control policy for a resource. May be empty if no such policy or resource exists. +func (c *snapshotsRESTClient) GetIamPolicy(ctx context.Context, req *computepb.GetIamPolicySnapshotRequest, opts ...gax.CallOption) (*computepb.Policy, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/snapshots/%v/getIamPolicy", req.GetProject(), req.GetResource()) + + params := url.Values{} + if req != nil && req.OptionsRequestedPolicyVersion != nil { + params.Add("optionsRequestedPolicyVersion", fmt.Sprintf("%v", req.GetOptionsRequestedPolicyVersion())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Policy{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// List retrieves the list of Snapshot resources contained within the specified project. +func (c *snapshotsRESTClient) List(ctx context.Context, req *computepb.ListSnapshotsRequest, opts ...gax.CallOption) (*computepb.SnapshotList, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/snapshots", req.GetProject()) + + params := url.Values{} + if req != nil && req.Filter != nil { + params.Add("filter", fmt.Sprintf("%v", req.GetFilter())) + } + if req != nil && req.MaxResults != nil { + params.Add("maxResults", fmt.Sprintf("%v", req.GetMaxResults())) + } + if req != nil && req.OrderBy != nil { + params.Add("orderBy", fmt.Sprintf("%v", req.GetOrderBy())) + } + if req != nil && req.PageToken != nil { + params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) + } + if req != nil && req.ReturnPartialSuccess != nil { + params.Add("returnPartialSuccess", fmt.Sprintf("%v", req.GetReturnPartialSuccess())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.SnapshotList{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// SetIamPolicy sets the access control policy on the specified resource. Replaces any existing policy. +func (c *snapshotsRESTClient) SetIamPolicy(ctx context.Context, req *computepb.SetIamPolicySnapshotRequest, opts ...gax.CallOption) (*computepb.Policy, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetGlobalSetPolicyRequestResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/snapshots/%v/setIamPolicy", req.GetProject(), req.GetResource()) + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Policy{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// SetLabels sets the labels on a snapshot. To learn more about labels, read the Labeling Resources documentation. +func (c *snapshotsRESTClient) SetLabels(ctx context.Context, req *computepb.SetLabelsSnapshotRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetGlobalSetLabelsRequestResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/snapshots/%v/setLabels", req.GetProject(), req.GetResource()) + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// TestIamPermissions returns permissions that a caller has on the specified resource. +func (c *snapshotsRESTClient) TestIamPermissions(ctx context.Context, req *computepb.TestIamPermissionsSnapshotRequest, opts ...gax.CallOption) (*computepb.TestPermissionsResponse, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetTestPermissionsRequestResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/snapshots/%v/testIamPermissions", req.GetProject(), req.GetResource()) + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.TestPermissionsResponse{} + + return rsp, unm.Unmarshal(buf, rsp) +} diff --git a/compute/apiv1/snapshots_client_example_test.go b/compute/apiv1/snapshots_client_example_test.go new file mode 100644 index 00000000000..ebdb2d2c377 --- /dev/null +++ b/compute/apiv1/snapshots_client_example_test.go @@ -0,0 +1,169 @@ +// 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 compute_test + +import ( + "context" + + compute "cloud.google.com/go/compute/apiv1" + computepb "google.golang.org/genproto/googleapis/cloud/compute/v1" +) + +func ExampleNewSnapshotsRESTClient() { + ctx := context.Background() + c, err := compute.NewSnapshotsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + // TODO: Use client. + _ = c +} + +func ExampleSnapshotsClient_Delete() { + ctx := context.Background() + c, err := compute.NewSnapshotsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.DeleteSnapshotRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Delete(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleSnapshotsClient_Get() { + ctx := context.Background() + c, err := compute.NewSnapshotsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.GetSnapshotRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Get(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleSnapshotsClient_GetIamPolicy() { + ctx := context.Background() + c, err := compute.NewSnapshotsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.GetIamPolicySnapshotRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.GetIamPolicy(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleSnapshotsClient_List() { + ctx := context.Background() + c, err := compute.NewSnapshotsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.ListSnapshotsRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.List(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleSnapshotsClient_SetIamPolicy() { + ctx := context.Background() + c, err := compute.NewSnapshotsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.SetIamPolicySnapshotRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.SetIamPolicy(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleSnapshotsClient_SetLabels() { + ctx := context.Background() + c, err := compute.NewSnapshotsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.SetLabelsSnapshotRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.SetLabels(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleSnapshotsClient_TestIamPermissions() { + ctx := context.Background() + c, err := compute.NewSnapshotsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.TestIamPermissionsSnapshotRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.TestIamPermissions(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} diff --git a/compute/apiv1/ssl_certificates_client.go b/compute/apiv1/ssl_certificates_client.go new file mode 100644 index 00000000000..509741ea1e8 --- /dev/null +++ b/compute/apiv1/ssl_certificates_client.go @@ -0,0 +1,452 @@ +// 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 compute + +import ( + "bytes" + "context" + "fmt" + "io/ioutil" + "net/http" + "net/url" + + gax "github.com/googleapis/gax-go/v2" + "google.golang.org/api/option" + "google.golang.org/api/option/internaloption" + httptransport "google.golang.org/api/transport/http" + computepb "google.golang.org/genproto/googleapis/cloud/compute/v1" + "google.golang.org/grpc" + "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/encoding/protojson" +) + +var newSslCertificatesClientHook clientHook + +// SslCertificatesCallOptions contains the retry settings for each method of SslCertificatesClient. +type SslCertificatesCallOptions struct { + AggregatedList []gax.CallOption + Delete []gax.CallOption + Get []gax.CallOption + Insert []gax.CallOption + List []gax.CallOption +} + +// internalSslCertificatesClient is an interface that defines the methods availaible from Google Compute Engine API. +type internalSslCertificatesClient interface { + Close() error + setGoogleClientInfo(...string) + Connection() *grpc.ClientConn + AggregatedList(context.Context, *computepb.AggregatedListSslCertificatesRequest, ...gax.CallOption) (*computepb.SslCertificateAggregatedList, error) + Delete(context.Context, *computepb.DeleteSslCertificateRequest, ...gax.CallOption) (*computepb.Operation, error) + Get(context.Context, *computepb.GetSslCertificateRequest, ...gax.CallOption) (*computepb.SslCertificate, error) + Insert(context.Context, *computepb.InsertSslCertificateRequest, ...gax.CallOption) (*computepb.Operation, error) + List(context.Context, *computepb.ListSslCertificatesRequest, ...gax.CallOption) (*computepb.SslCertificateList, error) +} + +// SslCertificatesClient is a client for interacting with Google Compute Engine API. +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +// +// The SslCertificates API. +type SslCertificatesClient struct { + // The internal transport-dependent client. + internalClient internalSslCertificatesClient + + // The call options for this service. + CallOptions *SslCertificatesCallOptions +} + +// 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 *SslCertificatesClient) 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 *SslCertificatesClient) setGoogleClientInfo(keyval ...string) { + c.internalClient.setGoogleClientInfo(keyval...) +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *SslCertificatesClient) Connection() *grpc.ClientConn { + return c.internalClient.Connection() +} + +// AggregatedList retrieves the list of all SslCertificate resources, regional and global, available to the specified project. +func (c *SslCertificatesClient) AggregatedList(ctx context.Context, req *computepb.AggregatedListSslCertificatesRequest, opts ...gax.CallOption) (*computepb.SslCertificateAggregatedList, error) { + return c.internalClient.AggregatedList(ctx, req, opts...) +} + +// Delete deletes the specified SslCertificate resource. +func (c *SslCertificatesClient) Delete(ctx context.Context, req *computepb.DeleteSslCertificateRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.Delete(ctx, req, opts...) +} + +// Get returns the specified SslCertificate resource. Gets a list of available SSL certificates by making a list() request. +func (c *SslCertificatesClient) Get(ctx context.Context, req *computepb.GetSslCertificateRequest, opts ...gax.CallOption) (*computepb.SslCertificate, error) { + return c.internalClient.Get(ctx, req, opts...) +} + +// Insert creates a SslCertificate resource in the specified project using the data included in the request. +func (c *SslCertificatesClient) Insert(ctx context.Context, req *computepb.InsertSslCertificateRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.Insert(ctx, req, opts...) +} + +// List retrieves the list of SslCertificate resources available to the specified project. +func (c *SslCertificatesClient) List(ctx context.Context, req *computepb.ListSslCertificatesRequest, opts ...gax.CallOption) (*computepb.SslCertificateList, error) { + return c.internalClient.List(ctx, req, opts...) +} + +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +type sslCertificatesRESTClient struct { + // The http endpoint to connect to. + endpoint string + + // The http client. + httpClient *http.Client + + // The x-goog-* metadata to be sent with each request. + xGoogMetadata metadata.MD +} + +// NewSslCertificatesRESTClient creates a new ssl certificates rest client. +// +// The SslCertificates API. +func NewSslCertificatesRESTClient(ctx context.Context, opts ...option.ClientOption) (*SslCertificatesClient, error) { + clientOpts := append(defaultSslCertificatesRESTClientOptions(), opts...) + httpClient, endpoint, err := httptransport.NewClient(ctx, clientOpts...) + if err != nil { + return nil, err + } + + c := &sslCertificatesRESTClient{ + endpoint: endpoint, + httpClient: httpClient, + } + c.setGoogleClientInfo() + + return &SslCertificatesClient{internalClient: c, CallOptions: &SslCertificatesCallOptions{}}, nil +} + +func defaultSslCertificatesRESTClientOptions() []option.ClientOption { + return []option.ClientOption{ + internaloption.WithDefaultEndpoint("compute.googleapis.com"), + internaloption.WithDefaultMTLSEndpoint("compute.mtls.googleapis.com"), + internaloption.WithDefaultAudience("https://compute.googleapis.com/"), + internaloption.WithDefaultScopes(DefaultAuthScopes()...), + } +} + +// 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 *sslCertificatesRESTClient) setGoogleClientInfo(keyval ...string) { + kv := append([]string{"gl-go", versionGo()}, keyval...) + kv = append(kv, "gapic", versionClient, "gax", gax.Version, "rest", "UNKNOWN") + 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 *sslCertificatesRESTClient) Close() error { + // Replace httpClient with nil to force cleanup. + c.httpClient = nil + return nil +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *sslCertificatesRESTClient) Connection() *grpc.ClientConn { + return nil +} + +// AggregatedList retrieves the list of all SslCertificate resources, regional and global, available to the specified project. +func (c *sslCertificatesRESTClient) AggregatedList(ctx context.Context, req *computepb.AggregatedListSslCertificatesRequest, opts ...gax.CallOption) (*computepb.SslCertificateAggregatedList, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/aggregated/sslCertificates", req.GetProject()) + + params := url.Values{} + if req != nil && req.Filter != nil { + params.Add("filter", fmt.Sprintf("%v", req.GetFilter())) + } + if req != nil && req.IncludeAllScopes != nil { + params.Add("includeAllScopes", fmt.Sprintf("%v", req.GetIncludeAllScopes())) + } + if req != nil && req.MaxResults != nil { + params.Add("maxResults", fmt.Sprintf("%v", req.GetMaxResults())) + } + if req != nil && req.OrderBy != nil { + params.Add("orderBy", fmt.Sprintf("%v", req.GetOrderBy())) + } + if req != nil && req.PageToken != nil { + params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) + } + if req != nil && req.ReturnPartialSuccess != nil { + params.Add("returnPartialSuccess", fmt.Sprintf("%v", req.GetReturnPartialSuccess())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.SslCertificateAggregatedList{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Delete deletes the specified SslCertificate resource. +func (c *sslCertificatesRESTClient) Delete(ctx context.Context, req *computepb.DeleteSslCertificateRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/sslCertificates/%v", req.GetProject(), req.GetSslCertificate()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("DELETE", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Get returns the specified SslCertificate resource. Gets a list of available SSL certificates by making a list() request. +func (c *sslCertificatesRESTClient) Get(ctx context.Context, req *computepb.GetSslCertificateRequest, opts ...gax.CallOption) (*computepb.SslCertificate, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/sslCertificates/%v", req.GetProject(), req.GetSslCertificate()) + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.SslCertificate{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Insert creates a SslCertificate resource in the specified project using the data included in the request. +func (c *sslCertificatesRESTClient) Insert(ctx context.Context, req *computepb.InsertSslCertificateRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetSslCertificateResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/sslCertificates", req.GetProject()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// List retrieves the list of SslCertificate resources available to the specified project. +func (c *sslCertificatesRESTClient) List(ctx context.Context, req *computepb.ListSslCertificatesRequest, opts ...gax.CallOption) (*computepb.SslCertificateList, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/sslCertificates", req.GetProject()) + + params := url.Values{} + if req != nil && req.Filter != nil { + params.Add("filter", fmt.Sprintf("%v", req.GetFilter())) + } + if req != nil && req.MaxResults != nil { + params.Add("maxResults", fmt.Sprintf("%v", req.GetMaxResults())) + } + if req != nil && req.OrderBy != nil { + params.Add("orderBy", fmt.Sprintf("%v", req.GetOrderBy())) + } + if req != nil && req.PageToken != nil { + params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) + } + if req != nil && req.ReturnPartialSuccess != nil { + params.Add("returnPartialSuccess", fmt.Sprintf("%v", req.GetReturnPartialSuccess())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.SslCertificateList{} + + return rsp, unm.Unmarshal(buf, rsp) +} diff --git a/compute/apiv1/ssl_certificates_client_example_test.go b/compute/apiv1/ssl_certificates_client_example_test.go new file mode 100644 index 00000000000..2859305e6cf --- /dev/null +++ b/compute/apiv1/ssl_certificates_client_example_test.go @@ -0,0 +1,131 @@ +// 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 compute_test + +import ( + "context" + + compute "cloud.google.com/go/compute/apiv1" + computepb "google.golang.org/genproto/googleapis/cloud/compute/v1" +) + +func ExampleNewSslCertificatesRESTClient() { + ctx := context.Background() + c, err := compute.NewSslCertificatesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + // TODO: Use client. + _ = c +} + +func ExampleSslCertificatesClient_AggregatedList() { + ctx := context.Background() + c, err := compute.NewSslCertificatesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.AggregatedListSslCertificatesRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.AggregatedList(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleSslCertificatesClient_Delete() { + ctx := context.Background() + c, err := compute.NewSslCertificatesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.DeleteSslCertificateRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Delete(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleSslCertificatesClient_Get() { + ctx := context.Background() + c, err := compute.NewSslCertificatesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.GetSslCertificateRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Get(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleSslCertificatesClient_Insert() { + ctx := context.Background() + c, err := compute.NewSslCertificatesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.InsertSslCertificateRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Insert(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleSslCertificatesClient_List() { + ctx := context.Background() + c, err := compute.NewSslCertificatesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.ListSslCertificatesRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.List(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} diff --git a/compute/apiv1/ssl_policies_client.go b/compute/apiv1/ssl_policies_client.go new file mode 100644 index 00000000000..b3ead7c8b80 --- /dev/null +++ b/compute/apiv1/ssl_policies_client.go @@ -0,0 +1,507 @@ +// 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 compute + +import ( + "bytes" + "context" + "fmt" + "io/ioutil" + "net/http" + "net/url" + + gax "github.com/googleapis/gax-go/v2" + "google.golang.org/api/option" + "google.golang.org/api/option/internaloption" + httptransport "google.golang.org/api/transport/http" + computepb "google.golang.org/genproto/googleapis/cloud/compute/v1" + "google.golang.org/grpc" + "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/encoding/protojson" +) + +var newSslPoliciesClientHook clientHook + +// SslPoliciesCallOptions contains the retry settings for each method of SslPoliciesClient. +type SslPoliciesCallOptions struct { + Delete []gax.CallOption + Get []gax.CallOption + Insert []gax.CallOption + List []gax.CallOption + ListAvailableFeatures []gax.CallOption + Patch []gax.CallOption +} + +// internalSslPoliciesClient is an interface that defines the methods availaible from Google Compute Engine API. +type internalSslPoliciesClient interface { + Close() error + setGoogleClientInfo(...string) + Connection() *grpc.ClientConn + Delete(context.Context, *computepb.DeleteSslPolicyRequest, ...gax.CallOption) (*computepb.Operation, error) + Get(context.Context, *computepb.GetSslPolicyRequest, ...gax.CallOption) (*computepb.SslPolicy, error) + Insert(context.Context, *computepb.InsertSslPolicyRequest, ...gax.CallOption) (*computepb.Operation, error) + List(context.Context, *computepb.ListSslPoliciesRequest, ...gax.CallOption) (*computepb.SslPoliciesList, error) + ListAvailableFeatures(context.Context, *computepb.ListAvailableFeaturesSslPoliciesRequest, ...gax.CallOption) (*computepb.SslPoliciesListAvailableFeaturesResponse, error) + Patch(context.Context, *computepb.PatchSslPolicyRequest, ...gax.CallOption) (*computepb.Operation, error) +} + +// SslPoliciesClient is a client for interacting with Google Compute Engine API. +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +// +// The SslPolicies API. +type SslPoliciesClient struct { + // The internal transport-dependent client. + internalClient internalSslPoliciesClient + + // The call options for this service. + CallOptions *SslPoliciesCallOptions +} + +// 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 *SslPoliciesClient) 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 *SslPoliciesClient) setGoogleClientInfo(keyval ...string) { + c.internalClient.setGoogleClientInfo(keyval...) +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *SslPoliciesClient) Connection() *grpc.ClientConn { + return c.internalClient.Connection() +} + +// Delete deletes the specified SSL policy. The SSL policy resource can be deleted only if it is not in use by any TargetHttpsProxy or TargetSslProxy resources. +func (c *SslPoliciesClient) Delete(ctx context.Context, req *computepb.DeleteSslPolicyRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.Delete(ctx, req, opts...) +} + +// Get lists all of the ordered rules present in a single specified policy. +func (c *SslPoliciesClient) Get(ctx context.Context, req *computepb.GetSslPolicyRequest, opts ...gax.CallOption) (*computepb.SslPolicy, error) { + return c.internalClient.Get(ctx, req, opts...) +} + +// Insert returns the specified SSL policy resource. Gets a list of available SSL policies by making a list() request. +func (c *SslPoliciesClient) Insert(ctx context.Context, req *computepb.InsertSslPolicyRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.Insert(ctx, req, opts...) +} + +// List lists all the SSL policies that have been configured for the specified project. +func (c *SslPoliciesClient) List(ctx context.Context, req *computepb.ListSslPoliciesRequest, opts ...gax.CallOption) (*computepb.SslPoliciesList, error) { + return c.internalClient.List(ctx, req, opts...) +} + +// ListAvailableFeatures lists all features that can be specified in the SSL policy when using custom profile. +func (c *SslPoliciesClient) ListAvailableFeatures(ctx context.Context, req *computepb.ListAvailableFeaturesSslPoliciesRequest, opts ...gax.CallOption) (*computepb.SslPoliciesListAvailableFeaturesResponse, error) { + return c.internalClient.ListAvailableFeatures(ctx, req, opts...) +} + +// Patch patches the specified SSL policy with the data included in the request. +func (c *SslPoliciesClient) Patch(ctx context.Context, req *computepb.PatchSslPolicyRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.Patch(ctx, req, opts...) +} + +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +type sslPoliciesRESTClient struct { + // The http endpoint to connect to. + endpoint string + + // The http client. + httpClient *http.Client + + // The x-goog-* metadata to be sent with each request. + xGoogMetadata metadata.MD +} + +// NewSslPoliciesRESTClient creates a new ssl policies rest client. +// +// The SslPolicies API. +func NewSslPoliciesRESTClient(ctx context.Context, opts ...option.ClientOption) (*SslPoliciesClient, error) { + clientOpts := append(defaultSslPoliciesRESTClientOptions(), opts...) + httpClient, endpoint, err := httptransport.NewClient(ctx, clientOpts...) + if err != nil { + return nil, err + } + + c := &sslPoliciesRESTClient{ + endpoint: endpoint, + httpClient: httpClient, + } + c.setGoogleClientInfo() + + return &SslPoliciesClient{internalClient: c, CallOptions: &SslPoliciesCallOptions{}}, nil +} + +func defaultSslPoliciesRESTClientOptions() []option.ClientOption { + return []option.ClientOption{ + internaloption.WithDefaultEndpoint("compute.googleapis.com"), + internaloption.WithDefaultMTLSEndpoint("compute.mtls.googleapis.com"), + internaloption.WithDefaultAudience("https://compute.googleapis.com/"), + internaloption.WithDefaultScopes(DefaultAuthScopes()...), + } +} + +// 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 *sslPoliciesRESTClient) setGoogleClientInfo(keyval ...string) { + kv := append([]string{"gl-go", versionGo()}, keyval...) + kv = append(kv, "gapic", versionClient, "gax", gax.Version, "rest", "UNKNOWN") + 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 *sslPoliciesRESTClient) Close() error { + // Replace httpClient with nil to force cleanup. + c.httpClient = nil + return nil +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *sslPoliciesRESTClient) Connection() *grpc.ClientConn { + return nil +} + +// Delete deletes the specified SSL policy. The SSL policy resource can be deleted only if it is not in use by any TargetHttpsProxy or TargetSslProxy resources. +func (c *sslPoliciesRESTClient) Delete(ctx context.Context, req *computepb.DeleteSslPolicyRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/sslPolicies/%v", req.GetProject(), req.GetSslPolicy()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("DELETE", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Get lists all of the ordered rules present in a single specified policy. +func (c *sslPoliciesRESTClient) Get(ctx context.Context, req *computepb.GetSslPolicyRequest, opts ...gax.CallOption) (*computepb.SslPolicy, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/sslPolicies/%v", req.GetProject(), req.GetSslPolicy()) + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.SslPolicy{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Insert returns the specified SSL policy resource. Gets a list of available SSL policies by making a list() request. +func (c *sslPoliciesRESTClient) Insert(ctx context.Context, req *computepb.InsertSslPolicyRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetSslPolicyResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/sslPolicies", req.GetProject()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// List lists all the SSL policies that have been configured for the specified project. +func (c *sslPoliciesRESTClient) List(ctx context.Context, req *computepb.ListSslPoliciesRequest, opts ...gax.CallOption) (*computepb.SslPoliciesList, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/sslPolicies", req.GetProject()) + + params := url.Values{} + if req != nil && req.Filter != nil { + params.Add("filter", fmt.Sprintf("%v", req.GetFilter())) + } + if req != nil && req.MaxResults != nil { + params.Add("maxResults", fmt.Sprintf("%v", req.GetMaxResults())) + } + if req != nil && req.OrderBy != nil { + params.Add("orderBy", fmt.Sprintf("%v", req.GetOrderBy())) + } + if req != nil && req.PageToken != nil { + params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) + } + if req != nil && req.ReturnPartialSuccess != nil { + params.Add("returnPartialSuccess", fmt.Sprintf("%v", req.GetReturnPartialSuccess())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.SslPoliciesList{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// ListAvailableFeatures lists all features that can be specified in the SSL policy when using custom profile. +func (c *sslPoliciesRESTClient) ListAvailableFeatures(ctx context.Context, req *computepb.ListAvailableFeaturesSslPoliciesRequest, opts ...gax.CallOption) (*computepb.SslPoliciesListAvailableFeaturesResponse, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/sslPolicies/listAvailableFeatures", req.GetProject()) + + params := url.Values{} + if req != nil && req.Filter != nil { + params.Add("filter", fmt.Sprintf("%v", req.GetFilter())) + } + if req != nil && req.MaxResults != nil { + params.Add("maxResults", fmt.Sprintf("%v", req.GetMaxResults())) + } + if req != nil && req.OrderBy != nil { + params.Add("orderBy", fmt.Sprintf("%v", req.GetOrderBy())) + } + if req != nil && req.PageToken != nil { + params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) + } + if req != nil && req.ReturnPartialSuccess != nil { + params.Add("returnPartialSuccess", fmt.Sprintf("%v", req.GetReturnPartialSuccess())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.SslPoliciesListAvailableFeaturesResponse{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Patch patches the specified SSL policy with the data included in the request. +func (c *sslPoliciesRESTClient) Patch(ctx context.Context, req *computepb.PatchSslPolicyRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetSslPolicyResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/sslPolicies/%v", req.GetProject(), req.GetSslPolicy()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("PATCH", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} diff --git a/compute/apiv1/ssl_policies_client_example_test.go b/compute/apiv1/ssl_policies_client_example_test.go new file mode 100644 index 00000000000..a74e2832e04 --- /dev/null +++ b/compute/apiv1/ssl_policies_client_example_test.go @@ -0,0 +1,150 @@ +// 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 compute_test + +import ( + "context" + + compute "cloud.google.com/go/compute/apiv1" + computepb "google.golang.org/genproto/googleapis/cloud/compute/v1" +) + +func ExampleNewSslPoliciesRESTClient() { + ctx := context.Background() + c, err := compute.NewSslPoliciesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + // TODO: Use client. + _ = c +} + +func ExampleSslPoliciesClient_Delete() { + ctx := context.Background() + c, err := compute.NewSslPoliciesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.DeleteSslPolicyRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Delete(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleSslPoliciesClient_Get() { + ctx := context.Background() + c, err := compute.NewSslPoliciesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.GetSslPolicyRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Get(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleSslPoliciesClient_Insert() { + ctx := context.Background() + c, err := compute.NewSslPoliciesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.InsertSslPolicyRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Insert(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleSslPoliciesClient_List() { + ctx := context.Background() + c, err := compute.NewSslPoliciesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.ListSslPoliciesRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.List(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleSslPoliciesClient_ListAvailableFeatures() { + ctx := context.Background() + c, err := compute.NewSslPoliciesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.ListAvailableFeaturesSslPoliciesRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.ListAvailableFeatures(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleSslPoliciesClient_Patch() { + ctx := context.Background() + c, err := compute.NewSslPoliciesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.PatchSslPolicyRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Patch(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} diff --git a/compute/apiv1/subnetworks_client.go b/compute/apiv1/subnetworks_client.go new file mode 100644 index 00000000000..d0bcf696135 --- /dev/null +++ b/compute/apiv1/subnetworks_client.go @@ -0,0 +1,857 @@ +// 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 compute + +import ( + "bytes" + "context" + "fmt" + "io/ioutil" + "net/http" + "net/url" + + gax "github.com/googleapis/gax-go/v2" + "google.golang.org/api/option" + "google.golang.org/api/option/internaloption" + httptransport "google.golang.org/api/transport/http" + computepb "google.golang.org/genproto/googleapis/cloud/compute/v1" + "google.golang.org/grpc" + "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/encoding/protojson" +) + +var newSubnetworksClientHook clientHook + +// SubnetworksCallOptions contains the retry settings for each method of SubnetworksClient. +type SubnetworksCallOptions struct { + AggregatedList []gax.CallOption + Delete []gax.CallOption + ExpandIpCidrRange []gax.CallOption + Get []gax.CallOption + GetIamPolicy []gax.CallOption + Insert []gax.CallOption + List []gax.CallOption + ListUsable []gax.CallOption + Patch []gax.CallOption + SetIamPolicy []gax.CallOption + SetPrivateIpGoogleAccess []gax.CallOption + TestIamPermissions []gax.CallOption +} + +// internalSubnetworksClient is an interface that defines the methods availaible from Google Compute Engine API. +type internalSubnetworksClient interface { + Close() error + setGoogleClientInfo(...string) + Connection() *grpc.ClientConn + AggregatedList(context.Context, *computepb.AggregatedListSubnetworksRequest, ...gax.CallOption) (*computepb.SubnetworkAggregatedList, error) + Delete(context.Context, *computepb.DeleteSubnetworkRequest, ...gax.CallOption) (*computepb.Operation, error) + ExpandIpCidrRange(context.Context, *computepb.ExpandIpCidrRangeSubnetworkRequest, ...gax.CallOption) (*computepb.Operation, error) + Get(context.Context, *computepb.GetSubnetworkRequest, ...gax.CallOption) (*computepb.Subnetwork, error) + GetIamPolicy(context.Context, *computepb.GetIamPolicySubnetworkRequest, ...gax.CallOption) (*computepb.Policy, error) + Insert(context.Context, *computepb.InsertSubnetworkRequest, ...gax.CallOption) (*computepb.Operation, error) + List(context.Context, *computepb.ListSubnetworksRequest, ...gax.CallOption) (*computepb.SubnetworkList, error) + ListUsable(context.Context, *computepb.ListUsableSubnetworksRequest, ...gax.CallOption) (*computepb.UsableSubnetworksAggregatedList, error) + Patch(context.Context, *computepb.PatchSubnetworkRequest, ...gax.CallOption) (*computepb.Operation, error) + SetIamPolicy(context.Context, *computepb.SetIamPolicySubnetworkRequest, ...gax.CallOption) (*computepb.Policy, error) + SetPrivateIpGoogleAccess(context.Context, *computepb.SetPrivateIpGoogleAccessSubnetworkRequest, ...gax.CallOption) (*computepb.Operation, error) + TestIamPermissions(context.Context, *computepb.TestIamPermissionsSubnetworkRequest, ...gax.CallOption) (*computepb.TestPermissionsResponse, error) +} + +// SubnetworksClient is a client for interacting with Google Compute Engine API. +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +// +// The Subnetworks API. +type SubnetworksClient struct { + // The internal transport-dependent client. + internalClient internalSubnetworksClient + + // The call options for this service. + CallOptions *SubnetworksCallOptions +} + +// 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 *SubnetworksClient) 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 *SubnetworksClient) setGoogleClientInfo(keyval ...string) { + c.internalClient.setGoogleClientInfo(keyval...) +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *SubnetworksClient) Connection() *grpc.ClientConn { + return c.internalClient.Connection() +} + +// AggregatedList retrieves an aggregated list of subnetworks. +func (c *SubnetworksClient) AggregatedList(ctx context.Context, req *computepb.AggregatedListSubnetworksRequest, opts ...gax.CallOption) (*computepb.SubnetworkAggregatedList, error) { + return c.internalClient.AggregatedList(ctx, req, opts...) +} + +// Delete deletes the specified subnetwork. +func (c *SubnetworksClient) Delete(ctx context.Context, req *computepb.DeleteSubnetworkRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.Delete(ctx, req, opts...) +} + +// ExpandIpCidrRange expands the IP CIDR range of the subnetwork to a specified value. +func (c *SubnetworksClient) ExpandIpCidrRange(ctx context.Context, req *computepb.ExpandIpCidrRangeSubnetworkRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.ExpandIpCidrRange(ctx, req, opts...) +} + +// Get returns the specified subnetwork. Gets a list of available subnetworks list() request. +func (c *SubnetworksClient) Get(ctx context.Context, req *computepb.GetSubnetworkRequest, opts ...gax.CallOption) (*computepb.Subnetwork, error) { + return c.internalClient.Get(ctx, req, opts...) +} + +// GetIamPolicy gets the access control policy for a resource. May be empty if no such policy or resource exists. +func (c *SubnetworksClient) GetIamPolicy(ctx context.Context, req *computepb.GetIamPolicySubnetworkRequest, opts ...gax.CallOption) (*computepb.Policy, error) { + return c.internalClient.GetIamPolicy(ctx, req, opts...) +} + +// Insert creates a subnetwork in the specified project using the data included in the request. +func (c *SubnetworksClient) Insert(ctx context.Context, req *computepb.InsertSubnetworkRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.Insert(ctx, req, opts...) +} + +// List retrieves a list of subnetworks available to the specified project. +func (c *SubnetworksClient) List(ctx context.Context, req *computepb.ListSubnetworksRequest, opts ...gax.CallOption) (*computepb.SubnetworkList, error) { + return c.internalClient.List(ctx, req, opts...) +} + +// ListUsable retrieves an aggregated list of all usable subnetworks in the project. +func (c *SubnetworksClient) ListUsable(ctx context.Context, req *computepb.ListUsableSubnetworksRequest, opts ...gax.CallOption) (*computepb.UsableSubnetworksAggregatedList, error) { + return c.internalClient.ListUsable(ctx, req, opts...) +} + +// Patch patches the specified subnetwork with the data included in the request. Only certain fields can be updated with a patch request as indicated in the field descriptions. You must specify the current fingerprint of the subnetwork resource being patched. +func (c *SubnetworksClient) Patch(ctx context.Context, req *computepb.PatchSubnetworkRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.Patch(ctx, req, opts...) +} + +// SetIamPolicy sets the access control policy on the specified resource. Replaces any existing policy. +func (c *SubnetworksClient) SetIamPolicy(ctx context.Context, req *computepb.SetIamPolicySubnetworkRequest, opts ...gax.CallOption) (*computepb.Policy, error) { + return c.internalClient.SetIamPolicy(ctx, req, opts...) +} + +// SetPrivateIpGoogleAccess set whether VMs in this subnet can access Google services without assigning external IP addresses through Private Google Access. +func (c *SubnetworksClient) SetPrivateIpGoogleAccess(ctx context.Context, req *computepb.SetPrivateIpGoogleAccessSubnetworkRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.SetPrivateIpGoogleAccess(ctx, req, opts...) +} + +// TestIamPermissions returns permissions that a caller has on the specified resource. +func (c *SubnetworksClient) TestIamPermissions(ctx context.Context, req *computepb.TestIamPermissionsSubnetworkRequest, opts ...gax.CallOption) (*computepb.TestPermissionsResponse, error) { + return c.internalClient.TestIamPermissions(ctx, req, opts...) +} + +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +type subnetworksRESTClient struct { + // The http endpoint to connect to. + endpoint string + + // The http client. + httpClient *http.Client + + // The x-goog-* metadata to be sent with each request. + xGoogMetadata metadata.MD +} + +// NewSubnetworksRESTClient creates a new subnetworks rest client. +// +// The Subnetworks API. +func NewSubnetworksRESTClient(ctx context.Context, opts ...option.ClientOption) (*SubnetworksClient, error) { + clientOpts := append(defaultSubnetworksRESTClientOptions(), opts...) + httpClient, endpoint, err := httptransport.NewClient(ctx, clientOpts...) + if err != nil { + return nil, err + } + + c := &subnetworksRESTClient{ + endpoint: endpoint, + httpClient: httpClient, + } + c.setGoogleClientInfo() + + return &SubnetworksClient{internalClient: c, CallOptions: &SubnetworksCallOptions{}}, nil +} + +func defaultSubnetworksRESTClientOptions() []option.ClientOption { + return []option.ClientOption{ + internaloption.WithDefaultEndpoint("compute.googleapis.com"), + internaloption.WithDefaultMTLSEndpoint("compute.mtls.googleapis.com"), + internaloption.WithDefaultAudience("https://compute.googleapis.com/"), + internaloption.WithDefaultScopes(DefaultAuthScopes()...), + } +} + +// 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 *subnetworksRESTClient) setGoogleClientInfo(keyval ...string) { + kv := append([]string{"gl-go", versionGo()}, keyval...) + kv = append(kv, "gapic", versionClient, "gax", gax.Version, "rest", "UNKNOWN") + 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 *subnetworksRESTClient) Close() error { + // Replace httpClient with nil to force cleanup. + c.httpClient = nil + return nil +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *subnetworksRESTClient) Connection() *grpc.ClientConn { + return nil +} + +// AggregatedList retrieves an aggregated list of subnetworks. +func (c *subnetworksRESTClient) AggregatedList(ctx context.Context, req *computepb.AggregatedListSubnetworksRequest, opts ...gax.CallOption) (*computepb.SubnetworkAggregatedList, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/aggregated/subnetworks", req.GetProject()) + + params := url.Values{} + if req != nil && req.Filter != nil { + params.Add("filter", fmt.Sprintf("%v", req.GetFilter())) + } + if req != nil && req.IncludeAllScopes != nil { + params.Add("includeAllScopes", fmt.Sprintf("%v", req.GetIncludeAllScopes())) + } + if req != nil && req.MaxResults != nil { + params.Add("maxResults", fmt.Sprintf("%v", req.GetMaxResults())) + } + if req != nil && req.OrderBy != nil { + params.Add("orderBy", fmt.Sprintf("%v", req.GetOrderBy())) + } + if req != nil && req.PageToken != nil { + params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) + } + if req != nil && req.ReturnPartialSuccess != nil { + params.Add("returnPartialSuccess", fmt.Sprintf("%v", req.GetReturnPartialSuccess())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.SubnetworkAggregatedList{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Delete deletes the specified subnetwork. +func (c *subnetworksRESTClient) Delete(ctx context.Context, req *computepb.DeleteSubnetworkRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/regions/%v/subnetworks/%v", req.GetProject(), req.GetRegion(), req.GetSubnetwork()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("DELETE", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// ExpandIpCidrRange expands the IP CIDR range of the subnetwork to a specified value. +func (c *subnetworksRESTClient) ExpandIpCidrRange(ctx context.Context, req *computepb.ExpandIpCidrRangeSubnetworkRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetSubnetworksExpandIpCidrRangeRequestResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/regions/%v/subnetworks/%v/expandIpCidrRange", req.GetProject(), req.GetRegion(), req.GetSubnetwork()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Get returns the specified subnetwork. Gets a list of available subnetworks list() request. +func (c *subnetworksRESTClient) Get(ctx context.Context, req *computepb.GetSubnetworkRequest, opts ...gax.CallOption) (*computepb.Subnetwork, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/regions/%v/subnetworks/%v", req.GetProject(), req.GetRegion(), req.GetSubnetwork()) + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Subnetwork{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// GetIamPolicy gets the access control policy for a resource. May be empty if no such policy or resource exists. +func (c *subnetworksRESTClient) GetIamPolicy(ctx context.Context, req *computepb.GetIamPolicySubnetworkRequest, opts ...gax.CallOption) (*computepb.Policy, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/regions/%v/subnetworks/%v/getIamPolicy", req.GetProject(), req.GetRegion(), req.GetResource()) + + params := url.Values{} + if req != nil && req.OptionsRequestedPolicyVersion != nil { + params.Add("optionsRequestedPolicyVersion", fmt.Sprintf("%v", req.GetOptionsRequestedPolicyVersion())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Policy{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Insert creates a subnetwork in the specified project using the data included in the request. +func (c *subnetworksRESTClient) Insert(ctx context.Context, req *computepb.InsertSubnetworkRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetSubnetworkResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/regions/%v/subnetworks", req.GetProject(), req.GetRegion()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// List retrieves a list of subnetworks available to the specified project. +func (c *subnetworksRESTClient) List(ctx context.Context, req *computepb.ListSubnetworksRequest, opts ...gax.CallOption) (*computepb.SubnetworkList, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/regions/%v/subnetworks", req.GetProject(), req.GetRegion()) + + params := url.Values{} + if req != nil && req.Filter != nil { + params.Add("filter", fmt.Sprintf("%v", req.GetFilter())) + } + if req != nil && req.MaxResults != nil { + params.Add("maxResults", fmt.Sprintf("%v", req.GetMaxResults())) + } + if req != nil && req.OrderBy != nil { + params.Add("orderBy", fmt.Sprintf("%v", req.GetOrderBy())) + } + if req != nil && req.PageToken != nil { + params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) + } + if req != nil && req.ReturnPartialSuccess != nil { + params.Add("returnPartialSuccess", fmt.Sprintf("%v", req.GetReturnPartialSuccess())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.SubnetworkList{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// ListUsable retrieves an aggregated list of all usable subnetworks in the project. +func (c *subnetworksRESTClient) ListUsable(ctx context.Context, req *computepb.ListUsableSubnetworksRequest, opts ...gax.CallOption) (*computepb.UsableSubnetworksAggregatedList, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/aggregated/subnetworks/listUsable", req.GetProject()) + + params := url.Values{} + if req != nil && req.Filter != nil { + params.Add("filter", fmt.Sprintf("%v", req.GetFilter())) + } + if req != nil && req.MaxResults != nil { + params.Add("maxResults", fmt.Sprintf("%v", req.GetMaxResults())) + } + if req != nil && req.OrderBy != nil { + params.Add("orderBy", fmt.Sprintf("%v", req.GetOrderBy())) + } + if req != nil && req.PageToken != nil { + params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) + } + if req != nil && req.ReturnPartialSuccess != nil { + params.Add("returnPartialSuccess", fmt.Sprintf("%v", req.GetReturnPartialSuccess())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.UsableSubnetworksAggregatedList{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Patch patches the specified subnetwork with the data included in the request. Only certain fields can be updated with a patch request as indicated in the field descriptions. You must specify the current fingerprint of the subnetwork resource being patched. +func (c *subnetworksRESTClient) Patch(ctx context.Context, req *computepb.PatchSubnetworkRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetSubnetworkResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/regions/%v/subnetworks/%v", req.GetProject(), req.GetRegion(), req.GetSubnetwork()) + + params := url.Values{} + if req != nil && req.DrainTimeoutSeconds != nil { + params.Add("drainTimeoutSeconds", fmt.Sprintf("%v", req.GetDrainTimeoutSeconds())) + } + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("PATCH", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// SetIamPolicy sets the access control policy on the specified resource. Replaces any existing policy. +func (c *subnetworksRESTClient) SetIamPolicy(ctx context.Context, req *computepb.SetIamPolicySubnetworkRequest, opts ...gax.CallOption) (*computepb.Policy, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetRegionSetPolicyRequestResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/regions/%v/subnetworks/%v/setIamPolicy", req.GetProject(), req.GetRegion(), req.GetResource()) + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Policy{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// SetPrivateIpGoogleAccess set whether VMs in this subnet can access Google services without assigning external IP addresses through Private Google Access. +func (c *subnetworksRESTClient) SetPrivateIpGoogleAccess(ctx context.Context, req *computepb.SetPrivateIpGoogleAccessSubnetworkRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetSubnetworksSetPrivateIpGoogleAccessRequestResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/regions/%v/subnetworks/%v/setPrivateIpGoogleAccess", req.GetProject(), req.GetRegion(), req.GetSubnetwork()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// TestIamPermissions returns permissions that a caller has on the specified resource. +func (c *subnetworksRESTClient) TestIamPermissions(ctx context.Context, req *computepb.TestIamPermissionsSubnetworkRequest, opts ...gax.CallOption) (*computepb.TestPermissionsResponse, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetTestPermissionsRequestResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/regions/%v/subnetworks/%v/testIamPermissions", req.GetProject(), req.GetRegion(), req.GetResource()) + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.TestPermissionsResponse{} + + return rsp, unm.Unmarshal(buf, rsp) +} diff --git a/compute/apiv1/subnetworks_client_example_test.go b/compute/apiv1/subnetworks_client_example_test.go new file mode 100644 index 00000000000..c561c8311df --- /dev/null +++ b/compute/apiv1/subnetworks_client_example_test.go @@ -0,0 +1,264 @@ +// 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 compute_test + +import ( + "context" + + compute "cloud.google.com/go/compute/apiv1" + computepb "google.golang.org/genproto/googleapis/cloud/compute/v1" +) + +func ExampleNewSubnetworksRESTClient() { + ctx := context.Background() + c, err := compute.NewSubnetworksRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + // TODO: Use client. + _ = c +} + +func ExampleSubnetworksClient_AggregatedList() { + ctx := context.Background() + c, err := compute.NewSubnetworksRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.AggregatedListSubnetworksRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.AggregatedList(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleSubnetworksClient_Delete() { + ctx := context.Background() + c, err := compute.NewSubnetworksRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.DeleteSubnetworkRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Delete(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleSubnetworksClient_ExpandIpCidrRange() { + ctx := context.Background() + c, err := compute.NewSubnetworksRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.ExpandIpCidrRangeSubnetworkRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.ExpandIpCidrRange(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleSubnetworksClient_Get() { + ctx := context.Background() + c, err := compute.NewSubnetworksRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.GetSubnetworkRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Get(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleSubnetworksClient_GetIamPolicy() { + ctx := context.Background() + c, err := compute.NewSubnetworksRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.GetIamPolicySubnetworkRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.GetIamPolicy(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleSubnetworksClient_Insert() { + ctx := context.Background() + c, err := compute.NewSubnetworksRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.InsertSubnetworkRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Insert(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleSubnetworksClient_List() { + ctx := context.Background() + c, err := compute.NewSubnetworksRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.ListSubnetworksRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.List(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleSubnetworksClient_ListUsable() { + ctx := context.Background() + c, err := compute.NewSubnetworksRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.ListUsableSubnetworksRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.ListUsable(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleSubnetworksClient_Patch() { + ctx := context.Background() + c, err := compute.NewSubnetworksRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.PatchSubnetworkRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Patch(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleSubnetworksClient_SetIamPolicy() { + ctx := context.Background() + c, err := compute.NewSubnetworksRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.SetIamPolicySubnetworkRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.SetIamPolicy(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleSubnetworksClient_SetPrivateIpGoogleAccess() { + ctx := context.Background() + c, err := compute.NewSubnetworksRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.SetPrivateIpGoogleAccessSubnetworkRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.SetPrivateIpGoogleAccess(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleSubnetworksClient_TestIamPermissions() { + ctx := context.Background() + c, err := compute.NewSubnetworksRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.TestIamPermissionsSubnetworkRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.TestIamPermissions(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} diff --git a/compute/apiv1/target_grpc_proxies_client.go b/compute/apiv1/target_grpc_proxies_client.go new file mode 100644 index 00000000000..da17c2d17f9 --- /dev/null +++ b/compute/apiv1/target_grpc_proxies_client.go @@ -0,0 +1,438 @@ +// 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 compute + +import ( + "bytes" + "context" + "fmt" + "io/ioutil" + "net/http" + "net/url" + + gax "github.com/googleapis/gax-go/v2" + "google.golang.org/api/option" + "google.golang.org/api/option/internaloption" + httptransport "google.golang.org/api/transport/http" + computepb "google.golang.org/genproto/googleapis/cloud/compute/v1" + "google.golang.org/grpc" + "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/encoding/protojson" +) + +var newTargetGrpcProxiesClientHook clientHook + +// TargetGrpcProxiesCallOptions contains the retry settings for each method of TargetGrpcProxiesClient. +type TargetGrpcProxiesCallOptions struct { + Delete []gax.CallOption + Get []gax.CallOption + Insert []gax.CallOption + List []gax.CallOption + Patch []gax.CallOption +} + +// internalTargetGrpcProxiesClient is an interface that defines the methods availaible from Google Compute Engine API. +type internalTargetGrpcProxiesClient interface { + Close() error + setGoogleClientInfo(...string) + Connection() *grpc.ClientConn + Delete(context.Context, *computepb.DeleteTargetGrpcProxyRequest, ...gax.CallOption) (*computepb.Operation, error) + Get(context.Context, *computepb.GetTargetGrpcProxyRequest, ...gax.CallOption) (*computepb.TargetGrpcProxy, error) + Insert(context.Context, *computepb.InsertTargetGrpcProxyRequest, ...gax.CallOption) (*computepb.Operation, error) + List(context.Context, *computepb.ListTargetGrpcProxiesRequest, ...gax.CallOption) (*computepb.TargetGrpcProxyList, error) + Patch(context.Context, *computepb.PatchTargetGrpcProxyRequest, ...gax.CallOption) (*computepb.Operation, error) +} + +// TargetGrpcProxiesClient is a client for interacting with Google Compute Engine API. +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +// +// The TargetGrpcProxies API. +type TargetGrpcProxiesClient struct { + // The internal transport-dependent client. + internalClient internalTargetGrpcProxiesClient + + // The call options for this service. + CallOptions *TargetGrpcProxiesCallOptions +} + +// 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 *TargetGrpcProxiesClient) 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 *TargetGrpcProxiesClient) setGoogleClientInfo(keyval ...string) { + c.internalClient.setGoogleClientInfo(keyval...) +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *TargetGrpcProxiesClient) Connection() *grpc.ClientConn { + return c.internalClient.Connection() +} + +// Delete deletes the specified TargetGrpcProxy in the given scope +func (c *TargetGrpcProxiesClient) Delete(ctx context.Context, req *computepb.DeleteTargetGrpcProxyRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.Delete(ctx, req, opts...) +} + +// Get returns the specified TargetGrpcProxy resource in the given scope. +func (c *TargetGrpcProxiesClient) Get(ctx context.Context, req *computepb.GetTargetGrpcProxyRequest, opts ...gax.CallOption) (*computepb.TargetGrpcProxy, error) { + return c.internalClient.Get(ctx, req, opts...) +} + +// Insert creates a TargetGrpcProxy in the specified project in the given scope using the parameters that are included in the request. +func (c *TargetGrpcProxiesClient) Insert(ctx context.Context, req *computepb.InsertTargetGrpcProxyRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.Insert(ctx, req, opts...) +} + +// List lists the TargetGrpcProxies for a project in the given scope. +func (c *TargetGrpcProxiesClient) List(ctx context.Context, req *computepb.ListTargetGrpcProxiesRequest, opts ...gax.CallOption) (*computepb.TargetGrpcProxyList, error) { + return c.internalClient.List(ctx, req, opts...) +} + +// Patch patches the specified TargetGrpcProxy resource with the data included in the request. This method supports PATCH semantics and uses JSON merge patch format and processing rules. +func (c *TargetGrpcProxiesClient) Patch(ctx context.Context, req *computepb.PatchTargetGrpcProxyRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.Patch(ctx, req, opts...) +} + +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +type targetGrpcProxiesRESTClient struct { + // The http endpoint to connect to. + endpoint string + + // The http client. + httpClient *http.Client + + // The x-goog-* metadata to be sent with each request. + xGoogMetadata metadata.MD +} + +// NewTargetGrpcProxiesRESTClient creates a new target grpc proxies rest client. +// +// The TargetGrpcProxies API. +func NewTargetGrpcProxiesRESTClient(ctx context.Context, opts ...option.ClientOption) (*TargetGrpcProxiesClient, error) { + clientOpts := append(defaultTargetGrpcProxiesRESTClientOptions(), opts...) + httpClient, endpoint, err := httptransport.NewClient(ctx, clientOpts...) + if err != nil { + return nil, err + } + + c := &targetGrpcProxiesRESTClient{ + endpoint: endpoint, + httpClient: httpClient, + } + c.setGoogleClientInfo() + + return &TargetGrpcProxiesClient{internalClient: c, CallOptions: &TargetGrpcProxiesCallOptions{}}, nil +} + +func defaultTargetGrpcProxiesRESTClientOptions() []option.ClientOption { + return []option.ClientOption{ + internaloption.WithDefaultEndpoint("compute.googleapis.com"), + internaloption.WithDefaultMTLSEndpoint("compute.mtls.googleapis.com"), + internaloption.WithDefaultAudience("https://compute.googleapis.com/"), + internaloption.WithDefaultScopes(DefaultAuthScopes()...), + } +} + +// 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 *targetGrpcProxiesRESTClient) setGoogleClientInfo(keyval ...string) { + kv := append([]string{"gl-go", versionGo()}, keyval...) + kv = append(kv, "gapic", versionClient, "gax", gax.Version, "rest", "UNKNOWN") + 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 *targetGrpcProxiesRESTClient) Close() error { + // Replace httpClient with nil to force cleanup. + c.httpClient = nil + return nil +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *targetGrpcProxiesRESTClient) Connection() *grpc.ClientConn { + return nil +} + +// Delete deletes the specified TargetGrpcProxy in the given scope +func (c *targetGrpcProxiesRESTClient) Delete(ctx context.Context, req *computepb.DeleteTargetGrpcProxyRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/targetGrpcProxies/%v", req.GetProject(), req.GetTargetGrpcProxy()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("DELETE", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Get returns the specified TargetGrpcProxy resource in the given scope. +func (c *targetGrpcProxiesRESTClient) Get(ctx context.Context, req *computepb.GetTargetGrpcProxyRequest, opts ...gax.CallOption) (*computepb.TargetGrpcProxy, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/targetGrpcProxies/%v", req.GetProject(), req.GetTargetGrpcProxy()) + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.TargetGrpcProxy{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Insert creates a TargetGrpcProxy in the specified project in the given scope using the parameters that are included in the request. +func (c *targetGrpcProxiesRESTClient) Insert(ctx context.Context, req *computepb.InsertTargetGrpcProxyRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetTargetGrpcProxyResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/targetGrpcProxies", req.GetProject()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// List lists the TargetGrpcProxies for a project in the given scope. +func (c *targetGrpcProxiesRESTClient) List(ctx context.Context, req *computepb.ListTargetGrpcProxiesRequest, opts ...gax.CallOption) (*computepb.TargetGrpcProxyList, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/targetGrpcProxies", req.GetProject()) + + params := url.Values{} + if req != nil && req.Filter != nil { + params.Add("filter", fmt.Sprintf("%v", req.GetFilter())) + } + if req != nil && req.MaxResults != nil { + params.Add("maxResults", fmt.Sprintf("%v", req.GetMaxResults())) + } + if req != nil && req.OrderBy != nil { + params.Add("orderBy", fmt.Sprintf("%v", req.GetOrderBy())) + } + if req != nil && req.PageToken != nil { + params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) + } + if req != nil && req.ReturnPartialSuccess != nil { + params.Add("returnPartialSuccess", fmt.Sprintf("%v", req.GetReturnPartialSuccess())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.TargetGrpcProxyList{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Patch patches the specified TargetGrpcProxy resource with the data included in the request. This method supports PATCH semantics and uses JSON merge patch format and processing rules. +func (c *targetGrpcProxiesRESTClient) Patch(ctx context.Context, req *computepb.PatchTargetGrpcProxyRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetTargetGrpcProxyResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/targetGrpcProxies/%v", req.GetProject(), req.GetTargetGrpcProxy()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("PATCH", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} diff --git a/compute/apiv1/target_grpc_proxies_client_example_test.go b/compute/apiv1/target_grpc_proxies_client_example_test.go new file mode 100644 index 00000000000..b1fdef19971 --- /dev/null +++ b/compute/apiv1/target_grpc_proxies_client_example_test.go @@ -0,0 +1,131 @@ +// 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 compute_test + +import ( + "context" + + compute "cloud.google.com/go/compute/apiv1" + computepb "google.golang.org/genproto/googleapis/cloud/compute/v1" +) + +func ExampleNewTargetGrpcProxiesRESTClient() { + ctx := context.Background() + c, err := compute.NewTargetGrpcProxiesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + // TODO: Use client. + _ = c +} + +func ExampleTargetGrpcProxiesClient_Delete() { + ctx := context.Background() + c, err := compute.NewTargetGrpcProxiesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.DeleteTargetGrpcProxyRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Delete(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleTargetGrpcProxiesClient_Get() { + ctx := context.Background() + c, err := compute.NewTargetGrpcProxiesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.GetTargetGrpcProxyRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Get(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleTargetGrpcProxiesClient_Insert() { + ctx := context.Background() + c, err := compute.NewTargetGrpcProxiesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.InsertTargetGrpcProxyRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Insert(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleTargetGrpcProxiesClient_List() { + ctx := context.Background() + c, err := compute.NewTargetGrpcProxiesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.ListTargetGrpcProxiesRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.List(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleTargetGrpcProxiesClient_Patch() { + ctx := context.Background() + c, err := compute.NewTargetGrpcProxiesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.PatchTargetGrpcProxyRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Patch(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} diff --git a/compute/apiv1/target_http_proxies_client.go b/compute/apiv1/target_http_proxies_client.go new file mode 100644 index 00000000000..a7dea19c74e --- /dev/null +++ b/compute/apiv1/target_http_proxies_client.go @@ -0,0 +1,568 @@ +// 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 compute + +import ( + "bytes" + "context" + "fmt" + "io/ioutil" + "net/http" + "net/url" + + gax "github.com/googleapis/gax-go/v2" + "google.golang.org/api/option" + "google.golang.org/api/option/internaloption" + httptransport "google.golang.org/api/transport/http" + computepb "google.golang.org/genproto/googleapis/cloud/compute/v1" + "google.golang.org/grpc" + "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/encoding/protojson" +) + +var newTargetHttpProxiesClientHook clientHook + +// TargetHttpProxiesCallOptions contains the retry settings for each method of TargetHttpProxiesClient. +type TargetHttpProxiesCallOptions struct { + AggregatedList []gax.CallOption + Delete []gax.CallOption + Get []gax.CallOption + Insert []gax.CallOption + List []gax.CallOption + Patch []gax.CallOption + SetUrlMap []gax.CallOption +} + +// internalTargetHttpProxiesClient is an interface that defines the methods availaible from Google Compute Engine API. +type internalTargetHttpProxiesClient interface { + Close() error + setGoogleClientInfo(...string) + Connection() *grpc.ClientConn + AggregatedList(context.Context, *computepb.AggregatedListTargetHttpProxiesRequest, ...gax.CallOption) (*computepb.TargetHttpProxyAggregatedList, error) + Delete(context.Context, *computepb.DeleteTargetHttpProxyRequest, ...gax.CallOption) (*computepb.Operation, error) + Get(context.Context, *computepb.GetTargetHttpProxyRequest, ...gax.CallOption) (*computepb.TargetHttpProxy, error) + Insert(context.Context, *computepb.InsertTargetHttpProxyRequest, ...gax.CallOption) (*computepb.Operation, error) + List(context.Context, *computepb.ListTargetHttpProxiesRequest, ...gax.CallOption) (*computepb.TargetHttpProxyList, error) + Patch(context.Context, *computepb.PatchTargetHttpProxyRequest, ...gax.CallOption) (*computepb.Operation, error) + SetUrlMap(context.Context, *computepb.SetUrlMapTargetHttpProxyRequest, ...gax.CallOption) (*computepb.Operation, error) +} + +// TargetHttpProxiesClient is a client for interacting with Google Compute Engine API. +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +// +// The TargetHttpProxies API. +type TargetHttpProxiesClient struct { + // The internal transport-dependent client. + internalClient internalTargetHttpProxiesClient + + // The call options for this service. + CallOptions *TargetHttpProxiesCallOptions +} + +// 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 *TargetHttpProxiesClient) 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 *TargetHttpProxiesClient) setGoogleClientInfo(keyval ...string) { + c.internalClient.setGoogleClientInfo(keyval...) +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *TargetHttpProxiesClient) Connection() *grpc.ClientConn { + return c.internalClient.Connection() +} + +// AggregatedList retrieves the list of all TargetHttpProxy resources, regional and global, available to the specified project. +func (c *TargetHttpProxiesClient) AggregatedList(ctx context.Context, req *computepb.AggregatedListTargetHttpProxiesRequest, opts ...gax.CallOption) (*computepb.TargetHttpProxyAggregatedList, error) { + return c.internalClient.AggregatedList(ctx, req, opts...) +} + +// Delete deletes the specified TargetHttpProxy resource. +func (c *TargetHttpProxiesClient) Delete(ctx context.Context, req *computepb.DeleteTargetHttpProxyRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.Delete(ctx, req, opts...) +} + +// Get returns the specified TargetHttpProxy resource. Gets a list of available target HTTP proxies by making a list() request. +func (c *TargetHttpProxiesClient) Get(ctx context.Context, req *computepb.GetTargetHttpProxyRequest, opts ...gax.CallOption) (*computepb.TargetHttpProxy, error) { + return c.internalClient.Get(ctx, req, opts...) +} + +// Insert creates a TargetHttpProxy resource in the specified project using the data included in the request. +func (c *TargetHttpProxiesClient) Insert(ctx context.Context, req *computepb.InsertTargetHttpProxyRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.Insert(ctx, req, opts...) +} + +// List retrieves the list of TargetHttpProxy resources available to the specified project. +func (c *TargetHttpProxiesClient) List(ctx context.Context, req *computepb.ListTargetHttpProxiesRequest, opts ...gax.CallOption) (*computepb.TargetHttpProxyList, error) { + return c.internalClient.List(ctx, req, opts...) +} + +// Patch patches the specified TargetHttpProxy resource with the data included in the request. This method supports PATCH semantics and uses JSON merge patch format and processing rules. (== suppress_warning http-rest-shadowed ==) +func (c *TargetHttpProxiesClient) Patch(ctx context.Context, req *computepb.PatchTargetHttpProxyRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.Patch(ctx, req, opts...) +} + +// SetUrlMap changes the URL map for TargetHttpProxy. +func (c *TargetHttpProxiesClient) SetUrlMap(ctx context.Context, req *computepb.SetUrlMapTargetHttpProxyRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.SetUrlMap(ctx, req, opts...) +} + +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +type targetHttpProxiesRESTClient struct { + // The http endpoint to connect to. + endpoint string + + // The http client. + httpClient *http.Client + + // The x-goog-* metadata to be sent with each request. + xGoogMetadata metadata.MD +} + +// NewTargetHttpProxiesRESTClient creates a new target http proxies rest client. +// +// The TargetHttpProxies API. +func NewTargetHttpProxiesRESTClient(ctx context.Context, opts ...option.ClientOption) (*TargetHttpProxiesClient, error) { + clientOpts := append(defaultTargetHttpProxiesRESTClientOptions(), opts...) + httpClient, endpoint, err := httptransport.NewClient(ctx, clientOpts...) + if err != nil { + return nil, err + } + + c := &targetHttpProxiesRESTClient{ + endpoint: endpoint, + httpClient: httpClient, + } + c.setGoogleClientInfo() + + return &TargetHttpProxiesClient{internalClient: c, CallOptions: &TargetHttpProxiesCallOptions{}}, nil +} + +func defaultTargetHttpProxiesRESTClientOptions() []option.ClientOption { + return []option.ClientOption{ + internaloption.WithDefaultEndpoint("compute.googleapis.com"), + internaloption.WithDefaultMTLSEndpoint("compute.mtls.googleapis.com"), + internaloption.WithDefaultAudience("https://compute.googleapis.com/"), + internaloption.WithDefaultScopes(DefaultAuthScopes()...), + } +} + +// 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 *targetHttpProxiesRESTClient) setGoogleClientInfo(keyval ...string) { + kv := append([]string{"gl-go", versionGo()}, keyval...) + kv = append(kv, "gapic", versionClient, "gax", gax.Version, "rest", "UNKNOWN") + 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 *targetHttpProxiesRESTClient) Close() error { + // Replace httpClient with nil to force cleanup. + c.httpClient = nil + return nil +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *targetHttpProxiesRESTClient) Connection() *grpc.ClientConn { + return nil +} + +// AggregatedList retrieves the list of all TargetHttpProxy resources, regional and global, available to the specified project. +func (c *targetHttpProxiesRESTClient) AggregatedList(ctx context.Context, req *computepb.AggregatedListTargetHttpProxiesRequest, opts ...gax.CallOption) (*computepb.TargetHttpProxyAggregatedList, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/aggregated/targetHttpProxies", req.GetProject()) + + params := url.Values{} + if req != nil && req.Filter != nil { + params.Add("filter", fmt.Sprintf("%v", req.GetFilter())) + } + if req != nil && req.IncludeAllScopes != nil { + params.Add("includeAllScopes", fmt.Sprintf("%v", req.GetIncludeAllScopes())) + } + if req != nil && req.MaxResults != nil { + params.Add("maxResults", fmt.Sprintf("%v", req.GetMaxResults())) + } + if req != nil && req.OrderBy != nil { + params.Add("orderBy", fmt.Sprintf("%v", req.GetOrderBy())) + } + if req != nil && req.PageToken != nil { + params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) + } + if req != nil && req.ReturnPartialSuccess != nil { + params.Add("returnPartialSuccess", fmt.Sprintf("%v", req.GetReturnPartialSuccess())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.TargetHttpProxyAggregatedList{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Delete deletes the specified TargetHttpProxy resource. +func (c *targetHttpProxiesRESTClient) Delete(ctx context.Context, req *computepb.DeleteTargetHttpProxyRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/targetHttpProxies/%v", req.GetProject(), req.GetTargetHttpProxy()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("DELETE", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Get returns the specified TargetHttpProxy resource. Gets a list of available target HTTP proxies by making a list() request. +func (c *targetHttpProxiesRESTClient) Get(ctx context.Context, req *computepb.GetTargetHttpProxyRequest, opts ...gax.CallOption) (*computepb.TargetHttpProxy, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/targetHttpProxies/%v", req.GetProject(), req.GetTargetHttpProxy()) + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.TargetHttpProxy{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Insert creates a TargetHttpProxy resource in the specified project using the data included in the request. +func (c *targetHttpProxiesRESTClient) Insert(ctx context.Context, req *computepb.InsertTargetHttpProxyRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetTargetHttpProxyResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/targetHttpProxies", req.GetProject()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// List retrieves the list of TargetHttpProxy resources available to the specified project. +func (c *targetHttpProxiesRESTClient) List(ctx context.Context, req *computepb.ListTargetHttpProxiesRequest, opts ...gax.CallOption) (*computepb.TargetHttpProxyList, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/targetHttpProxies", req.GetProject()) + + params := url.Values{} + if req != nil && req.Filter != nil { + params.Add("filter", fmt.Sprintf("%v", req.GetFilter())) + } + if req != nil && req.MaxResults != nil { + params.Add("maxResults", fmt.Sprintf("%v", req.GetMaxResults())) + } + if req != nil && req.OrderBy != nil { + params.Add("orderBy", fmt.Sprintf("%v", req.GetOrderBy())) + } + if req != nil && req.PageToken != nil { + params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) + } + if req != nil && req.ReturnPartialSuccess != nil { + params.Add("returnPartialSuccess", fmt.Sprintf("%v", req.GetReturnPartialSuccess())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.TargetHttpProxyList{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Patch patches the specified TargetHttpProxy resource with the data included in the request. This method supports PATCH semantics and uses JSON merge patch format and processing rules. (== suppress_warning http-rest-shadowed ==) +func (c *targetHttpProxiesRESTClient) Patch(ctx context.Context, req *computepb.PatchTargetHttpProxyRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetTargetHttpProxyResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/targetHttpProxies/%v", req.GetProject(), req.GetTargetHttpProxy()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("PATCH", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// SetUrlMap changes the URL map for TargetHttpProxy. +func (c *targetHttpProxiesRESTClient) SetUrlMap(ctx context.Context, req *computepb.SetUrlMapTargetHttpProxyRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetUrlMapReferenceResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/targetHttpProxies/%v/setUrlMap", req.GetProject(), req.GetTargetHttpProxy()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} diff --git a/compute/apiv1/target_http_proxies_client_example_test.go b/compute/apiv1/target_http_proxies_client_example_test.go new file mode 100644 index 00000000000..07d31ff9562 --- /dev/null +++ b/compute/apiv1/target_http_proxies_client_example_test.go @@ -0,0 +1,169 @@ +// 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 compute_test + +import ( + "context" + + compute "cloud.google.com/go/compute/apiv1" + computepb "google.golang.org/genproto/googleapis/cloud/compute/v1" +) + +func ExampleNewTargetHttpProxiesRESTClient() { + ctx := context.Background() + c, err := compute.NewTargetHttpProxiesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + // TODO: Use client. + _ = c +} + +func ExampleTargetHttpProxiesClient_AggregatedList() { + ctx := context.Background() + c, err := compute.NewTargetHttpProxiesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.AggregatedListTargetHttpProxiesRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.AggregatedList(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleTargetHttpProxiesClient_Delete() { + ctx := context.Background() + c, err := compute.NewTargetHttpProxiesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.DeleteTargetHttpProxyRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Delete(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleTargetHttpProxiesClient_Get() { + ctx := context.Background() + c, err := compute.NewTargetHttpProxiesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.GetTargetHttpProxyRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Get(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleTargetHttpProxiesClient_Insert() { + ctx := context.Background() + c, err := compute.NewTargetHttpProxiesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.InsertTargetHttpProxyRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Insert(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleTargetHttpProxiesClient_List() { + ctx := context.Background() + c, err := compute.NewTargetHttpProxiesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.ListTargetHttpProxiesRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.List(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleTargetHttpProxiesClient_Patch() { + ctx := context.Background() + c, err := compute.NewTargetHttpProxiesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.PatchTargetHttpProxyRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Patch(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleTargetHttpProxiesClient_SetUrlMap() { + ctx := context.Background() + c, err := compute.NewTargetHttpProxiesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.SetUrlMapTargetHttpProxyRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.SetUrlMap(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} diff --git a/compute/apiv1/target_https_proxies_client.go b/compute/apiv1/target_https_proxies_client.go new file mode 100644 index 00000000000..c2af2689ab4 --- /dev/null +++ b/compute/apiv1/target_https_proxies_client.go @@ -0,0 +1,742 @@ +// 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 compute + +import ( + "bytes" + "context" + "fmt" + "io/ioutil" + "net/http" + "net/url" + + gax "github.com/googleapis/gax-go/v2" + "google.golang.org/api/option" + "google.golang.org/api/option/internaloption" + httptransport "google.golang.org/api/transport/http" + computepb "google.golang.org/genproto/googleapis/cloud/compute/v1" + "google.golang.org/grpc" + "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/encoding/protojson" +) + +var newTargetHttpsProxiesClientHook clientHook + +// TargetHttpsProxiesCallOptions contains the retry settings for each method of TargetHttpsProxiesClient. +type TargetHttpsProxiesCallOptions struct { + AggregatedList []gax.CallOption + Delete []gax.CallOption + Get []gax.CallOption + Insert []gax.CallOption + List []gax.CallOption + Patch []gax.CallOption + SetQuicOverride []gax.CallOption + SetSslCertificates []gax.CallOption + SetSslPolicy []gax.CallOption + SetUrlMap []gax.CallOption +} + +// internalTargetHttpsProxiesClient is an interface that defines the methods availaible from Google Compute Engine API. +type internalTargetHttpsProxiesClient interface { + Close() error + setGoogleClientInfo(...string) + Connection() *grpc.ClientConn + AggregatedList(context.Context, *computepb.AggregatedListTargetHttpsProxiesRequest, ...gax.CallOption) (*computepb.TargetHttpsProxyAggregatedList, error) + Delete(context.Context, *computepb.DeleteTargetHttpsProxyRequest, ...gax.CallOption) (*computepb.Operation, error) + Get(context.Context, *computepb.GetTargetHttpsProxyRequest, ...gax.CallOption) (*computepb.TargetHttpsProxy, error) + Insert(context.Context, *computepb.InsertTargetHttpsProxyRequest, ...gax.CallOption) (*computepb.Operation, error) + List(context.Context, *computepb.ListTargetHttpsProxiesRequest, ...gax.CallOption) (*computepb.TargetHttpsProxyList, error) + Patch(context.Context, *computepb.PatchTargetHttpsProxyRequest, ...gax.CallOption) (*computepb.Operation, error) + SetQuicOverride(context.Context, *computepb.SetQuicOverrideTargetHttpsProxyRequest, ...gax.CallOption) (*computepb.Operation, error) + SetSslCertificates(context.Context, *computepb.SetSslCertificatesTargetHttpsProxyRequest, ...gax.CallOption) (*computepb.Operation, error) + SetSslPolicy(context.Context, *computepb.SetSslPolicyTargetHttpsProxyRequest, ...gax.CallOption) (*computepb.Operation, error) + SetUrlMap(context.Context, *computepb.SetUrlMapTargetHttpsProxyRequest, ...gax.CallOption) (*computepb.Operation, error) +} + +// TargetHttpsProxiesClient is a client for interacting with Google Compute Engine API. +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +// +// The TargetHttpsProxies API. +type TargetHttpsProxiesClient struct { + // The internal transport-dependent client. + internalClient internalTargetHttpsProxiesClient + + // The call options for this service. + CallOptions *TargetHttpsProxiesCallOptions +} + +// 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 *TargetHttpsProxiesClient) 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 *TargetHttpsProxiesClient) setGoogleClientInfo(keyval ...string) { + c.internalClient.setGoogleClientInfo(keyval...) +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *TargetHttpsProxiesClient) Connection() *grpc.ClientConn { + return c.internalClient.Connection() +} + +// AggregatedList retrieves the list of all TargetHttpsProxy resources, regional and global, available to the specified project. +func (c *TargetHttpsProxiesClient) AggregatedList(ctx context.Context, req *computepb.AggregatedListTargetHttpsProxiesRequest, opts ...gax.CallOption) (*computepb.TargetHttpsProxyAggregatedList, error) { + return c.internalClient.AggregatedList(ctx, req, opts...) +} + +// Delete deletes the specified TargetHttpsProxy resource. +func (c *TargetHttpsProxiesClient) Delete(ctx context.Context, req *computepb.DeleteTargetHttpsProxyRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.Delete(ctx, req, opts...) +} + +// Get returns the specified TargetHttpsProxy resource. Gets a list of available target HTTPS proxies by making a list() request. +func (c *TargetHttpsProxiesClient) Get(ctx context.Context, req *computepb.GetTargetHttpsProxyRequest, opts ...gax.CallOption) (*computepb.TargetHttpsProxy, error) { + return c.internalClient.Get(ctx, req, opts...) +} + +// Insert creates a TargetHttpsProxy resource in the specified project using the data included in the request. +func (c *TargetHttpsProxiesClient) Insert(ctx context.Context, req *computepb.InsertTargetHttpsProxyRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.Insert(ctx, req, opts...) +} + +// List retrieves the list of TargetHttpsProxy resources available to the specified project. +func (c *TargetHttpsProxiesClient) List(ctx context.Context, req *computepb.ListTargetHttpsProxiesRequest, opts ...gax.CallOption) (*computepb.TargetHttpsProxyList, error) { + return c.internalClient.List(ctx, req, opts...) +} + +// Patch patches the specified TargetHttpsProxy resource with the data included in the request. This method supports PATCH semantics and uses JSON merge patch format and processing rules. (== suppress_warning http-rest-shadowed ==) +func (c *TargetHttpsProxiesClient) Patch(ctx context.Context, req *computepb.PatchTargetHttpsProxyRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.Patch(ctx, req, opts...) +} + +// SetQuicOverride sets the QUIC override policy for TargetHttpsProxy. +func (c *TargetHttpsProxiesClient) SetQuicOverride(ctx context.Context, req *computepb.SetQuicOverrideTargetHttpsProxyRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.SetQuicOverride(ctx, req, opts...) +} + +// SetSslCertificates replaces SslCertificates for TargetHttpsProxy. +func (c *TargetHttpsProxiesClient) SetSslCertificates(ctx context.Context, req *computepb.SetSslCertificatesTargetHttpsProxyRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.SetSslCertificates(ctx, req, opts...) +} + +// SetSslPolicy sets the SSL policy for TargetHttpsProxy. The SSL policy specifies the server-side support for SSL features. This affects connections between clients and the HTTPS proxy load balancer. They do not affect the connection between the load balancer and the backends. +func (c *TargetHttpsProxiesClient) SetSslPolicy(ctx context.Context, req *computepb.SetSslPolicyTargetHttpsProxyRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.SetSslPolicy(ctx, req, opts...) +} + +// SetUrlMap changes the URL map for TargetHttpsProxy. +func (c *TargetHttpsProxiesClient) SetUrlMap(ctx context.Context, req *computepb.SetUrlMapTargetHttpsProxyRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.SetUrlMap(ctx, req, opts...) +} + +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +type targetHttpsProxiesRESTClient struct { + // The http endpoint to connect to. + endpoint string + + // The http client. + httpClient *http.Client + + // The x-goog-* metadata to be sent with each request. + xGoogMetadata metadata.MD +} + +// NewTargetHttpsProxiesRESTClient creates a new target https proxies rest client. +// +// The TargetHttpsProxies API. +func NewTargetHttpsProxiesRESTClient(ctx context.Context, opts ...option.ClientOption) (*TargetHttpsProxiesClient, error) { + clientOpts := append(defaultTargetHttpsProxiesRESTClientOptions(), opts...) + httpClient, endpoint, err := httptransport.NewClient(ctx, clientOpts...) + if err != nil { + return nil, err + } + + c := &targetHttpsProxiesRESTClient{ + endpoint: endpoint, + httpClient: httpClient, + } + c.setGoogleClientInfo() + + return &TargetHttpsProxiesClient{internalClient: c, CallOptions: &TargetHttpsProxiesCallOptions{}}, nil +} + +func defaultTargetHttpsProxiesRESTClientOptions() []option.ClientOption { + return []option.ClientOption{ + internaloption.WithDefaultEndpoint("compute.googleapis.com"), + internaloption.WithDefaultMTLSEndpoint("compute.mtls.googleapis.com"), + internaloption.WithDefaultAudience("https://compute.googleapis.com/"), + internaloption.WithDefaultScopes(DefaultAuthScopes()...), + } +} + +// 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 *targetHttpsProxiesRESTClient) setGoogleClientInfo(keyval ...string) { + kv := append([]string{"gl-go", versionGo()}, keyval...) + kv = append(kv, "gapic", versionClient, "gax", gax.Version, "rest", "UNKNOWN") + 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 *targetHttpsProxiesRESTClient) Close() error { + // Replace httpClient with nil to force cleanup. + c.httpClient = nil + return nil +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *targetHttpsProxiesRESTClient) Connection() *grpc.ClientConn { + return nil +} + +// AggregatedList retrieves the list of all TargetHttpsProxy resources, regional and global, available to the specified project. +func (c *targetHttpsProxiesRESTClient) AggregatedList(ctx context.Context, req *computepb.AggregatedListTargetHttpsProxiesRequest, opts ...gax.CallOption) (*computepb.TargetHttpsProxyAggregatedList, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/aggregated/targetHttpsProxies", req.GetProject()) + + params := url.Values{} + if req != nil && req.Filter != nil { + params.Add("filter", fmt.Sprintf("%v", req.GetFilter())) + } + if req != nil && req.IncludeAllScopes != nil { + params.Add("includeAllScopes", fmt.Sprintf("%v", req.GetIncludeAllScopes())) + } + if req != nil && req.MaxResults != nil { + params.Add("maxResults", fmt.Sprintf("%v", req.GetMaxResults())) + } + if req != nil && req.OrderBy != nil { + params.Add("orderBy", fmt.Sprintf("%v", req.GetOrderBy())) + } + if req != nil && req.PageToken != nil { + params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) + } + if req != nil && req.ReturnPartialSuccess != nil { + params.Add("returnPartialSuccess", fmt.Sprintf("%v", req.GetReturnPartialSuccess())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.TargetHttpsProxyAggregatedList{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Delete deletes the specified TargetHttpsProxy resource. +func (c *targetHttpsProxiesRESTClient) Delete(ctx context.Context, req *computepb.DeleteTargetHttpsProxyRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/targetHttpsProxies/%v", req.GetProject(), req.GetTargetHttpsProxy()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("DELETE", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Get returns the specified TargetHttpsProxy resource. Gets a list of available target HTTPS proxies by making a list() request. +func (c *targetHttpsProxiesRESTClient) Get(ctx context.Context, req *computepb.GetTargetHttpsProxyRequest, opts ...gax.CallOption) (*computepb.TargetHttpsProxy, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/targetHttpsProxies/%v", req.GetProject(), req.GetTargetHttpsProxy()) + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.TargetHttpsProxy{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Insert creates a TargetHttpsProxy resource in the specified project using the data included in the request. +func (c *targetHttpsProxiesRESTClient) Insert(ctx context.Context, req *computepb.InsertTargetHttpsProxyRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetTargetHttpsProxyResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/targetHttpsProxies", req.GetProject()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// List retrieves the list of TargetHttpsProxy resources available to the specified project. +func (c *targetHttpsProxiesRESTClient) List(ctx context.Context, req *computepb.ListTargetHttpsProxiesRequest, opts ...gax.CallOption) (*computepb.TargetHttpsProxyList, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/targetHttpsProxies", req.GetProject()) + + params := url.Values{} + if req != nil && req.Filter != nil { + params.Add("filter", fmt.Sprintf("%v", req.GetFilter())) + } + if req != nil && req.MaxResults != nil { + params.Add("maxResults", fmt.Sprintf("%v", req.GetMaxResults())) + } + if req != nil && req.OrderBy != nil { + params.Add("orderBy", fmt.Sprintf("%v", req.GetOrderBy())) + } + if req != nil && req.PageToken != nil { + params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) + } + if req != nil && req.ReturnPartialSuccess != nil { + params.Add("returnPartialSuccess", fmt.Sprintf("%v", req.GetReturnPartialSuccess())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.TargetHttpsProxyList{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Patch patches the specified TargetHttpsProxy resource with the data included in the request. This method supports PATCH semantics and uses JSON merge patch format and processing rules. (== suppress_warning http-rest-shadowed ==) +func (c *targetHttpsProxiesRESTClient) Patch(ctx context.Context, req *computepb.PatchTargetHttpsProxyRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetTargetHttpsProxyResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/targetHttpsProxies/%v", req.GetProject(), req.GetTargetHttpsProxy()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("PATCH", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// SetQuicOverride sets the QUIC override policy for TargetHttpsProxy. +func (c *targetHttpsProxiesRESTClient) SetQuicOverride(ctx context.Context, req *computepb.SetQuicOverrideTargetHttpsProxyRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetTargetHttpsProxiesSetQuicOverrideRequestResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/targetHttpsProxies/%v/setQuicOverride", req.GetProject(), req.GetTargetHttpsProxy()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// SetSslCertificates replaces SslCertificates for TargetHttpsProxy. +func (c *targetHttpsProxiesRESTClient) SetSslCertificates(ctx context.Context, req *computepb.SetSslCertificatesTargetHttpsProxyRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetTargetHttpsProxiesSetSslCertificatesRequestResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/targetHttpsProxies/%v/setSslCertificates", req.GetProject(), req.GetTargetHttpsProxy()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// SetSslPolicy sets the SSL policy for TargetHttpsProxy. The SSL policy specifies the server-side support for SSL features. This affects connections between clients and the HTTPS proxy load balancer. They do not affect the connection between the load balancer and the backends. +func (c *targetHttpsProxiesRESTClient) SetSslPolicy(ctx context.Context, req *computepb.SetSslPolicyTargetHttpsProxyRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetSslPolicyReferenceResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/targetHttpsProxies/%v/setSslPolicy", req.GetProject(), req.GetTargetHttpsProxy()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// SetUrlMap changes the URL map for TargetHttpsProxy. +func (c *targetHttpsProxiesRESTClient) SetUrlMap(ctx context.Context, req *computepb.SetUrlMapTargetHttpsProxyRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetUrlMapReferenceResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/targetHttpsProxies/%v/setUrlMap", req.GetProject(), req.GetTargetHttpsProxy()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} diff --git a/compute/apiv1/target_https_proxies_client_example_test.go b/compute/apiv1/target_https_proxies_client_example_test.go new file mode 100644 index 00000000000..3430ce2206f --- /dev/null +++ b/compute/apiv1/target_https_proxies_client_example_test.go @@ -0,0 +1,226 @@ +// 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 compute_test + +import ( + "context" + + compute "cloud.google.com/go/compute/apiv1" + computepb "google.golang.org/genproto/googleapis/cloud/compute/v1" +) + +func ExampleNewTargetHttpsProxiesRESTClient() { + ctx := context.Background() + c, err := compute.NewTargetHttpsProxiesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + // TODO: Use client. + _ = c +} + +func ExampleTargetHttpsProxiesClient_AggregatedList() { + ctx := context.Background() + c, err := compute.NewTargetHttpsProxiesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.AggregatedListTargetHttpsProxiesRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.AggregatedList(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleTargetHttpsProxiesClient_Delete() { + ctx := context.Background() + c, err := compute.NewTargetHttpsProxiesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.DeleteTargetHttpsProxyRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Delete(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleTargetHttpsProxiesClient_Get() { + ctx := context.Background() + c, err := compute.NewTargetHttpsProxiesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.GetTargetHttpsProxyRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Get(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleTargetHttpsProxiesClient_Insert() { + ctx := context.Background() + c, err := compute.NewTargetHttpsProxiesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.InsertTargetHttpsProxyRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Insert(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleTargetHttpsProxiesClient_List() { + ctx := context.Background() + c, err := compute.NewTargetHttpsProxiesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.ListTargetHttpsProxiesRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.List(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleTargetHttpsProxiesClient_Patch() { + ctx := context.Background() + c, err := compute.NewTargetHttpsProxiesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.PatchTargetHttpsProxyRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Patch(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleTargetHttpsProxiesClient_SetQuicOverride() { + ctx := context.Background() + c, err := compute.NewTargetHttpsProxiesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.SetQuicOverrideTargetHttpsProxyRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.SetQuicOverride(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleTargetHttpsProxiesClient_SetSslCertificates() { + ctx := context.Background() + c, err := compute.NewTargetHttpsProxiesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.SetSslCertificatesTargetHttpsProxyRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.SetSslCertificates(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleTargetHttpsProxiesClient_SetSslPolicy() { + ctx := context.Background() + c, err := compute.NewTargetHttpsProxiesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.SetSslPolicyTargetHttpsProxyRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.SetSslPolicy(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleTargetHttpsProxiesClient_SetUrlMap() { + ctx := context.Background() + c, err := compute.NewTargetHttpsProxiesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.SetUrlMapTargetHttpsProxyRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.SetUrlMap(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} diff --git a/compute/apiv1/target_instances_client.go b/compute/apiv1/target_instances_client.go new file mode 100644 index 00000000000..25b0514dc64 --- /dev/null +++ b/compute/apiv1/target_instances_client.go @@ -0,0 +1,452 @@ +// 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 compute + +import ( + "bytes" + "context" + "fmt" + "io/ioutil" + "net/http" + "net/url" + + gax "github.com/googleapis/gax-go/v2" + "google.golang.org/api/option" + "google.golang.org/api/option/internaloption" + httptransport "google.golang.org/api/transport/http" + computepb "google.golang.org/genproto/googleapis/cloud/compute/v1" + "google.golang.org/grpc" + "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/encoding/protojson" +) + +var newTargetInstancesClientHook clientHook + +// TargetInstancesCallOptions contains the retry settings for each method of TargetInstancesClient. +type TargetInstancesCallOptions struct { + AggregatedList []gax.CallOption + Delete []gax.CallOption + Get []gax.CallOption + Insert []gax.CallOption + List []gax.CallOption +} + +// internalTargetInstancesClient is an interface that defines the methods availaible from Google Compute Engine API. +type internalTargetInstancesClient interface { + Close() error + setGoogleClientInfo(...string) + Connection() *grpc.ClientConn + AggregatedList(context.Context, *computepb.AggregatedListTargetInstancesRequest, ...gax.CallOption) (*computepb.TargetInstanceAggregatedList, error) + Delete(context.Context, *computepb.DeleteTargetInstanceRequest, ...gax.CallOption) (*computepb.Operation, error) + Get(context.Context, *computepb.GetTargetInstanceRequest, ...gax.CallOption) (*computepb.TargetInstance, error) + Insert(context.Context, *computepb.InsertTargetInstanceRequest, ...gax.CallOption) (*computepb.Operation, error) + List(context.Context, *computepb.ListTargetInstancesRequest, ...gax.CallOption) (*computepb.TargetInstanceList, error) +} + +// TargetInstancesClient is a client for interacting with Google Compute Engine API. +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +// +// The TargetInstances API. +type TargetInstancesClient struct { + // The internal transport-dependent client. + internalClient internalTargetInstancesClient + + // The call options for this service. + CallOptions *TargetInstancesCallOptions +} + +// 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 *TargetInstancesClient) 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 *TargetInstancesClient) setGoogleClientInfo(keyval ...string) { + c.internalClient.setGoogleClientInfo(keyval...) +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *TargetInstancesClient) Connection() *grpc.ClientConn { + return c.internalClient.Connection() +} + +// AggregatedList retrieves an aggregated list of target instances. +func (c *TargetInstancesClient) AggregatedList(ctx context.Context, req *computepb.AggregatedListTargetInstancesRequest, opts ...gax.CallOption) (*computepb.TargetInstanceAggregatedList, error) { + return c.internalClient.AggregatedList(ctx, req, opts...) +} + +// Delete deletes the specified TargetInstance resource. +func (c *TargetInstancesClient) Delete(ctx context.Context, req *computepb.DeleteTargetInstanceRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.Delete(ctx, req, opts...) +} + +// Get returns the specified TargetInstance resource. Gets a list of available target instances by making a list() request. +func (c *TargetInstancesClient) Get(ctx context.Context, req *computepb.GetTargetInstanceRequest, opts ...gax.CallOption) (*computepb.TargetInstance, error) { + return c.internalClient.Get(ctx, req, opts...) +} + +// Insert creates a TargetInstance resource in the specified project and zone using the data included in the request. +func (c *TargetInstancesClient) Insert(ctx context.Context, req *computepb.InsertTargetInstanceRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.Insert(ctx, req, opts...) +} + +// List retrieves a list of TargetInstance resources available to the specified project and zone. +func (c *TargetInstancesClient) List(ctx context.Context, req *computepb.ListTargetInstancesRequest, opts ...gax.CallOption) (*computepb.TargetInstanceList, error) { + return c.internalClient.List(ctx, req, opts...) +} + +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +type targetInstancesRESTClient struct { + // The http endpoint to connect to. + endpoint string + + // The http client. + httpClient *http.Client + + // The x-goog-* metadata to be sent with each request. + xGoogMetadata metadata.MD +} + +// NewTargetInstancesRESTClient creates a new target instances rest client. +// +// The TargetInstances API. +func NewTargetInstancesRESTClient(ctx context.Context, opts ...option.ClientOption) (*TargetInstancesClient, error) { + clientOpts := append(defaultTargetInstancesRESTClientOptions(), opts...) + httpClient, endpoint, err := httptransport.NewClient(ctx, clientOpts...) + if err != nil { + return nil, err + } + + c := &targetInstancesRESTClient{ + endpoint: endpoint, + httpClient: httpClient, + } + c.setGoogleClientInfo() + + return &TargetInstancesClient{internalClient: c, CallOptions: &TargetInstancesCallOptions{}}, nil +} + +func defaultTargetInstancesRESTClientOptions() []option.ClientOption { + return []option.ClientOption{ + internaloption.WithDefaultEndpoint("compute.googleapis.com"), + internaloption.WithDefaultMTLSEndpoint("compute.mtls.googleapis.com"), + internaloption.WithDefaultAudience("https://compute.googleapis.com/"), + internaloption.WithDefaultScopes(DefaultAuthScopes()...), + } +} + +// 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 *targetInstancesRESTClient) setGoogleClientInfo(keyval ...string) { + kv := append([]string{"gl-go", versionGo()}, keyval...) + kv = append(kv, "gapic", versionClient, "gax", gax.Version, "rest", "UNKNOWN") + 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 *targetInstancesRESTClient) Close() error { + // Replace httpClient with nil to force cleanup. + c.httpClient = nil + return nil +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *targetInstancesRESTClient) Connection() *grpc.ClientConn { + return nil +} + +// AggregatedList retrieves an aggregated list of target instances. +func (c *targetInstancesRESTClient) AggregatedList(ctx context.Context, req *computepb.AggregatedListTargetInstancesRequest, opts ...gax.CallOption) (*computepb.TargetInstanceAggregatedList, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/aggregated/targetInstances", req.GetProject()) + + params := url.Values{} + if req != nil && req.Filter != nil { + params.Add("filter", fmt.Sprintf("%v", req.GetFilter())) + } + if req != nil && req.IncludeAllScopes != nil { + params.Add("includeAllScopes", fmt.Sprintf("%v", req.GetIncludeAllScopes())) + } + if req != nil && req.MaxResults != nil { + params.Add("maxResults", fmt.Sprintf("%v", req.GetMaxResults())) + } + if req != nil && req.OrderBy != nil { + params.Add("orderBy", fmt.Sprintf("%v", req.GetOrderBy())) + } + if req != nil && req.PageToken != nil { + params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) + } + if req != nil && req.ReturnPartialSuccess != nil { + params.Add("returnPartialSuccess", fmt.Sprintf("%v", req.GetReturnPartialSuccess())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.TargetInstanceAggregatedList{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Delete deletes the specified TargetInstance resource. +func (c *targetInstancesRESTClient) Delete(ctx context.Context, req *computepb.DeleteTargetInstanceRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/zones/%v/targetInstances/%v", req.GetProject(), req.GetZone(), req.GetTargetInstance()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("DELETE", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Get returns the specified TargetInstance resource. Gets a list of available target instances by making a list() request. +func (c *targetInstancesRESTClient) Get(ctx context.Context, req *computepb.GetTargetInstanceRequest, opts ...gax.CallOption) (*computepb.TargetInstance, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/zones/%v/targetInstances/%v", req.GetProject(), req.GetZone(), req.GetTargetInstance()) + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.TargetInstance{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Insert creates a TargetInstance resource in the specified project and zone using the data included in the request. +func (c *targetInstancesRESTClient) Insert(ctx context.Context, req *computepb.InsertTargetInstanceRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetTargetInstanceResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/zones/%v/targetInstances", req.GetProject(), req.GetZone()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// List retrieves a list of TargetInstance resources available to the specified project and zone. +func (c *targetInstancesRESTClient) List(ctx context.Context, req *computepb.ListTargetInstancesRequest, opts ...gax.CallOption) (*computepb.TargetInstanceList, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/zones/%v/targetInstances", req.GetProject(), req.GetZone()) + + params := url.Values{} + if req != nil && req.Filter != nil { + params.Add("filter", fmt.Sprintf("%v", req.GetFilter())) + } + if req != nil && req.MaxResults != nil { + params.Add("maxResults", fmt.Sprintf("%v", req.GetMaxResults())) + } + if req != nil && req.OrderBy != nil { + params.Add("orderBy", fmt.Sprintf("%v", req.GetOrderBy())) + } + if req != nil && req.PageToken != nil { + params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) + } + if req != nil && req.ReturnPartialSuccess != nil { + params.Add("returnPartialSuccess", fmt.Sprintf("%v", req.GetReturnPartialSuccess())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.TargetInstanceList{} + + return rsp, unm.Unmarshal(buf, rsp) +} diff --git a/compute/apiv1/target_instances_client_example_test.go b/compute/apiv1/target_instances_client_example_test.go new file mode 100644 index 00000000000..de3679b3076 --- /dev/null +++ b/compute/apiv1/target_instances_client_example_test.go @@ -0,0 +1,131 @@ +// 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 compute_test + +import ( + "context" + + compute "cloud.google.com/go/compute/apiv1" + computepb "google.golang.org/genproto/googleapis/cloud/compute/v1" +) + +func ExampleNewTargetInstancesRESTClient() { + ctx := context.Background() + c, err := compute.NewTargetInstancesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + // TODO: Use client. + _ = c +} + +func ExampleTargetInstancesClient_AggregatedList() { + ctx := context.Background() + c, err := compute.NewTargetInstancesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.AggregatedListTargetInstancesRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.AggregatedList(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleTargetInstancesClient_Delete() { + ctx := context.Background() + c, err := compute.NewTargetInstancesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.DeleteTargetInstanceRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Delete(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleTargetInstancesClient_Get() { + ctx := context.Background() + c, err := compute.NewTargetInstancesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.GetTargetInstanceRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Get(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleTargetInstancesClient_Insert() { + ctx := context.Background() + c, err := compute.NewTargetInstancesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.InsertTargetInstanceRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Insert(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleTargetInstancesClient_List() { + ctx := context.Background() + c, err := compute.NewTargetInstancesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.ListTargetInstancesRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.List(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} diff --git a/compute/apiv1/target_pools_client.go b/compute/apiv1/target_pools_client.go new file mode 100644 index 00000000000..f05abeca64d --- /dev/null +++ b/compute/apiv1/target_pools_client.go @@ -0,0 +1,796 @@ +// 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 compute + +import ( + "bytes" + "context" + "fmt" + "io/ioutil" + "net/http" + "net/url" + + gax "github.com/googleapis/gax-go/v2" + "google.golang.org/api/option" + "google.golang.org/api/option/internaloption" + httptransport "google.golang.org/api/transport/http" + computepb "google.golang.org/genproto/googleapis/cloud/compute/v1" + "google.golang.org/grpc" + "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/encoding/protojson" +) + +var newTargetPoolsClientHook clientHook + +// TargetPoolsCallOptions contains the retry settings for each method of TargetPoolsClient. +type TargetPoolsCallOptions struct { + AddHealthCheck []gax.CallOption + AddInstance []gax.CallOption + AggregatedList []gax.CallOption + Delete []gax.CallOption + Get []gax.CallOption + GetHealth []gax.CallOption + Insert []gax.CallOption + List []gax.CallOption + RemoveHealthCheck []gax.CallOption + RemoveInstance []gax.CallOption + SetBackup []gax.CallOption +} + +// internalTargetPoolsClient is an interface that defines the methods availaible from Google Compute Engine API. +type internalTargetPoolsClient interface { + Close() error + setGoogleClientInfo(...string) + Connection() *grpc.ClientConn + AddHealthCheck(context.Context, *computepb.AddHealthCheckTargetPoolRequest, ...gax.CallOption) (*computepb.Operation, error) + AddInstance(context.Context, *computepb.AddInstanceTargetPoolRequest, ...gax.CallOption) (*computepb.Operation, error) + AggregatedList(context.Context, *computepb.AggregatedListTargetPoolsRequest, ...gax.CallOption) (*computepb.TargetPoolAggregatedList, error) + Delete(context.Context, *computepb.DeleteTargetPoolRequest, ...gax.CallOption) (*computepb.Operation, error) + Get(context.Context, *computepb.GetTargetPoolRequest, ...gax.CallOption) (*computepb.TargetPool, error) + GetHealth(context.Context, *computepb.GetHealthTargetPoolRequest, ...gax.CallOption) (*computepb.TargetPoolInstanceHealth, error) + Insert(context.Context, *computepb.InsertTargetPoolRequest, ...gax.CallOption) (*computepb.Operation, error) + List(context.Context, *computepb.ListTargetPoolsRequest, ...gax.CallOption) (*computepb.TargetPoolList, error) + RemoveHealthCheck(context.Context, *computepb.RemoveHealthCheckTargetPoolRequest, ...gax.CallOption) (*computepb.Operation, error) + RemoveInstance(context.Context, *computepb.RemoveInstanceTargetPoolRequest, ...gax.CallOption) (*computepb.Operation, error) + SetBackup(context.Context, *computepb.SetBackupTargetPoolRequest, ...gax.CallOption) (*computepb.Operation, error) +} + +// TargetPoolsClient is a client for interacting with Google Compute Engine API. +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +// +// The TargetPools API. +type TargetPoolsClient struct { + // The internal transport-dependent client. + internalClient internalTargetPoolsClient + + // The call options for this service. + CallOptions *TargetPoolsCallOptions +} + +// 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 *TargetPoolsClient) 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 *TargetPoolsClient) setGoogleClientInfo(keyval ...string) { + c.internalClient.setGoogleClientInfo(keyval...) +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *TargetPoolsClient) Connection() *grpc.ClientConn { + return c.internalClient.Connection() +} + +// AddHealthCheck adds health check URLs to a target pool. +func (c *TargetPoolsClient) AddHealthCheck(ctx context.Context, req *computepb.AddHealthCheckTargetPoolRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.AddHealthCheck(ctx, req, opts...) +} + +// AddInstance adds an instance to a target pool. +func (c *TargetPoolsClient) AddInstance(ctx context.Context, req *computepb.AddInstanceTargetPoolRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.AddInstance(ctx, req, opts...) +} + +// AggregatedList retrieves an aggregated list of target pools. +func (c *TargetPoolsClient) AggregatedList(ctx context.Context, req *computepb.AggregatedListTargetPoolsRequest, opts ...gax.CallOption) (*computepb.TargetPoolAggregatedList, error) { + return c.internalClient.AggregatedList(ctx, req, opts...) +} + +// Delete deletes the specified target pool. +func (c *TargetPoolsClient) Delete(ctx context.Context, req *computepb.DeleteTargetPoolRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.Delete(ctx, req, opts...) +} + +// Get returns the specified target pool. Gets a list of available target pools by making a list() request. +func (c *TargetPoolsClient) Get(ctx context.Context, req *computepb.GetTargetPoolRequest, opts ...gax.CallOption) (*computepb.TargetPool, error) { + return c.internalClient.Get(ctx, req, opts...) +} + +// GetHealth gets the most recent health check results for each IP for the instance that is referenced by the given target pool. +func (c *TargetPoolsClient) GetHealth(ctx context.Context, req *computepb.GetHealthTargetPoolRequest, opts ...gax.CallOption) (*computepb.TargetPoolInstanceHealth, error) { + return c.internalClient.GetHealth(ctx, req, opts...) +} + +// Insert creates a target pool in the specified project and region using the data included in the request. +func (c *TargetPoolsClient) Insert(ctx context.Context, req *computepb.InsertTargetPoolRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.Insert(ctx, req, opts...) +} + +// List retrieves a list of target pools available to the specified project and region. +func (c *TargetPoolsClient) List(ctx context.Context, req *computepb.ListTargetPoolsRequest, opts ...gax.CallOption) (*computepb.TargetPoolList, error) { + return c.internalClient.List(ctx, req, opts...) +} + +// RemoveHealthCheck removes health check URL from a target pool. +func (c *TargetPoolsClient) RemoveHealthCheck(ctx context.Context, req *computepb.RemoveHealthCheckTargetPoolRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.RemoveHealthCheck(ctx, req, opts...) +} + +// RemoveInstance removes instance URL from a target pool. +func (c *TargetPoolsClient) RemoveInstance(ctx context.Context, req *computepb.RemoveInstanceTargetPoolRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.RemoveInstance(ctx, req, opts...) +} + +// SetBackup changes a backup target pool’s configurations. +func (c *TargetPoolsClient) SetBackup(ctx context.Context, req *computepb.SetBackupTargetPoolRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.SetBackup(ctx, req, opts...) +} + +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +type targetPoolsRESTClient struct { + // The http endpoint to connect to. + endpoint string + + // The http client. + httpClient *http.Client + + // The x-goog-* metadata to be sent with each request. + xGoogMetadata metadata.MD +} + +// NewTargetPoolsRESTClient creates a new target pools rest client. +// +// The TargetPools API. +func NewTargetPoolsRESTClient(ctx context.Context, opts ...option.ClientOption) (*TargetPoolsClient, error) { + clientOpts := append(defaultTargetPoolsRESTClientOptions(), opts...) + httpClient, endpoint, err := httptransport.NewClient(ctx, clientOpts...) + if err != nil { + return nil, err + } + + c := &targetPoolsRESTClient{ + endpoint: endpoint, + httpClient: httpClient, + } + c.setGoogleClientInfo() + + return &TargetPoolsClient{internalClient: c, CallOptions: &TargetPoolsCallOptions{}}, nil +} + +func defaultTargetPoolsRESTClientOptions() []option.ClientOption { + return []option.ClientOption{ + internaloption.WithDefaultEndpoint("compute.googleapis.com"), + internaloption.WithDefaultMTLSEndpoint("compute.mtls.googleapis.com"), + internaloption.WithDefaultAudience("https://compute.googleapis.com/"), + internaloption.WithDefaultScopes(DefaultAuthScopes()...), + } +} + +// 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 *targetPoolsRESTClient) setGoogleClientInfo(keyval ...string) { + kv := append([]string{"gl-go", versionGo()}, keyval...) + kv = append(kv, "gapic", versionClient, "gax", gax.Version, "rest", "UNKNOWN") + 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 *targetPoolsRESTClient) Close() error { + // Replace httpClient with nil to force cleanup. + c.httpClient = nil + return nil +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *targetPoolsRESTClient) Connection() *grpc.ClientConn { + return nil +} + +// AddHealthCheck adds health check URLs to a target pool. +func (c *targetPoolsRESTClient) AddHealthCheck(ctx context.Context, req *computepb.AddHealthCheckTargetPoolRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetTargetPoolsAddHealthCheckRequestResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/regions/%v/targetPools/%v/addHealthCheck", req.GetProject(), req.GetRegion(), req.GetTargetPool()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// AddInstance adds an instance to a target pool. +func (c *targetPoolsRESTClient) AddInstance(ctx context.Context, req *computepb.AddInstanceTargetPoolRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetTargetPoolsAddInstanceRequestResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/regions/%v/targetPools/%v/addInstance", req.GetProject(), req.GetRegion(), req.GetTargetPool()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// AggregatedList retrieves an aggregated list of target pools. +func (c *targetPoolsRESTClient) AggregatedList(ctx context.Context, req *computepb.AggregatedListTargetPoolsRequest, opts ...gax.CallOption) (*computepb.TargetPoolAggregatedList, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/aggregated/targetPools", req.GetProject()) + + params := url.Values{} + if req != nil && req.Filter != nil { + params.Add("filter", fmt.Sprintf("%v", req.GetFilter())) + } + if req != nil && req.IncludeAllScopes != nil { + params.Add("includeAllScopes", fmt.Sprintf("%v", req.GetIncludeAllScopes())) + } + if req != nil && req.MaxResults != nil { + params.Add("maxResults", fmt.Sprintf("%v", req.GetMaxResults())) + } + if req != nil && req.OrderBy != nil { + params.Add("orderBy", fmt.Sprintf("%v", req.GetOrderBy())) + } + if req != nil && req.PageToken != nil { + params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) + } + if req != nil && req.ReturnPartialSuccess != nil { + params.Add("returnPartialSuccess", fmt.Sprintf("%v", req.GetReturnPartialSuccess())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.TargetPoolAggregatedList{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Delete deletes the specified target pool. +func (c *targetPoolsRESTClient) Delete(ctx context.Context, req *computepb.DeleteTargetPoolRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/regions/%v/targetPools/%v", req.GetProject(), req.GetRegion(), req.GetTargetPool()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("DELETE", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Get returns the specified target pool. Gets a list of available target pools by making a list() request. +func (c *targetPoolsRESTClient) Get(ctx context.Context, req *computepb.GetTargetPoolRequest, opts ...gax.CallOption) (*computepb.TargetPool, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/regions/%v/targetPools/%v", req.GetProject(), req.GetRegion(), req.GetTargetPool()) + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.TargetPool{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// GetHealth gets the most recent health check results for each IP for the instance that is referenced by the given target pool. +func (c *targetPoolsRESTClient) GetHealth(ctx context.Context, req *computepb.GetHealthTargetPoolRequest, opts ...gax.CallOption) (*computepb.TargetPoolInstanceHealth, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetInstanceReferenceResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/regions/%v/targetPools/%v/getHealth", req.GetProject(), req.GetRegion(), req.GetTargetPool()) + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.TargetPoolInstanceHealth{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Insert creates a target pool in the specified project and region using the data included in the request. +func (c *targetPoolsRESTClient) Insert(ctx context.Context, req *computepb.InsertTargetPoolRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetTargetPoolResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/regions/%v/targetPools", req.GetProject(), req.GetRegion()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// List retrieves a list of target pools available to the specified project and region. +func (c *targetPoolsRESTClient) List(ctx context.Context, req *computepb.ListTargetPoolsRequest, opts ...gax.CallOption) (*computepb.TargetPoolList, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/regions/%v/targetPools", req.GetProject(), req.GetRegion()) + + params := url.Values{} + if req != nil && req.Filter != nil { + params.Add("filter", fmt.Sprintf("%v", req.GetFilter())) + } + if req != nil && req.MaxResults != nil { + params.Add("maxResults", fmt.Sprintf("%v", req.GetMaxResults())) + } + if req != nil && req.OrderBy != nil { + params.Add("orderBy", fmt.Sprintf("%v", req.GetOrderBy())) + } + if req != nil && req.PageToken != nil { + params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) + } + if req != nil && req.ReturnPartialSuccess != nil { + params.Add("returnPartialSuccess", fmt.Sprintf("%v", req.GetReturnPartialSuccess())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.TargetPoolList{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// RemoveHealthCheck removes health check URL from a target pool. +func (c *targetPoolsRESTClient) RemoveHealthCheck(ctx context.Context, req *computepb.RemoveHealthCheckTargetPoolRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetTargetPoolsRemoveHealthCheckRequestResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/regions/%v/targetPools/%v/removeHealthCheck", req.GetProject(), req.GetRegion(), req.GetTargetPool()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// RemoveInstance removes instance URL from a target pool. +func (c *targetPoolsRESTClient) RemoveInstance(ctx context.Context, req *computepb.RemoveInstanceTargetPoolRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetTargetPoolsRemoveInstanceRequestResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/regions/%v/targetPools/%v/removeInstance", req.GetProject(), req.GetRegion(), req.GetTargetPool()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// SetBackup changes a backup target pool’s configurations. +func (c *targetPoolsRESTClient) SetBackup(ctx context.Context, req *computepb.SetBackupTargetPoolRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetTargetReferenceResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/regions/%v/targetPools/%v/setBackup", req.GetProject(), req.GetRegion(), req.GetTargetPool()) + + params := url.Values{} + if req != nil && req.FailoverRatio != nil { + params.Add("failoverRatio", fmt.Sprintf("%v", req.GetFailoverRatio())) + } + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} diff --git a/compute/apiv1/target_pools_client_example_test.go b/compute/apiv1/target_pools_client_example_test.go new file mode 100644 index 00000000000..480016f09eb --- /dev/null +++ b/compute/apiv1/target_pools_client_example_test.go @@ -0,0 +1,245 @@ +// 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 compute_test + +import ( + "context" + + compute "cloud.google.com/go/compute/apiv1" + computepb "google.golang.org/genproto/googleapis/cloud/compute/v1" +) + +func ExampleNewTargetPoolsRESTClient() { + ctx := context.Background() + c, err := compute.NewTargetPoolsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + // TODO: Use client. + _ = c +} + +func ExampleTargetPoolsClient_AddHealthCheck() { + ctx := context.Background() + c, err := compute.NewTargetPoolsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.AddHealthCheckTargetPoolRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.AddHealthCheck(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleTargetPoolsClient_AddInstance() { + ctx := context.Background() + c, err := compute.NewTargetPoolsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.AddInstanceTargetPoolRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.AddInstance(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleTargetPoolsClient_AggregatedList() { + ctx := context.Background() + c, err := compute.NewTargetPoolsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.AggregatedListTargetPoolsRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.AggregatedList(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleTargetPoolsClient_Delete() { + ctx := context.Background() + c, err := compute.NewTargetPoolsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.DeleteTargetPoolRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Delete(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleTargetPoolsClient_Get() { + ctx := context.Background() + c, err := compute.NewTargetPoolsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.GetTargetPoolRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Get(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleTargetPoolsClient_GetHealth() { + ctx := context.Background() + c, err := compute.NewTargetPoolsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.GetHealthTargetPoolRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.GetHealth(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleTargetPoolsClient_Insert() { + ctx := context.Background() + c, err := compute.NewTargetPoolsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.InsertTargetPoolRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Insert(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleTargetPoolsClient_List() { + ctx := context.Background() + c, err := compute.NewTargetPoolsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.ListTargetPoolsRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.List(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleTargetPoolsClient_RemoveHealthCheck() { + ctx := context.Background() + c, err := compute.NewTargetPoolsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.RemoveHealthCheckTargetPoolRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.RemoveHealthCheck(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleTargetPoolsClient_RemoveInstance() { + ctx := context.Background() + c, err := compute.NewTargetPoolsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.RemoveInstanceTargetPoolRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.RemoveInstance(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleTargetPoolsClient_SetBackup() { + ctx := context.Background() + c, err := compute.NewTargetPoolsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.SetBackupTargetPoolRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.SetBackup(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} diff --git a/compute/apiv1/target_ssl_proxies_client.go b/compute/apiv1/target_ssl_proxies_client.go new file mode 100644 index 00000000000..bbbd9dc7364 --- /dev/null +++ b/compute/apiv1/target_ssl_proxies_client.go @@ -0,0 +1,612 @@ +// 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 compute + +import ( + "bytes" + "context" + "fmt" + "io/ioutil" + "net/http" + "net/url" + + gax "github.com/googleapis/gax-go/v2" + "google.golang.org/api/option" + "google.golang.org/api/option/internaloption" + httptransport "google.golang.org/api/transport/http" + computepb "google.golang.org/genproto/googleapis/cloud/compute/v1" + "google.golang.org/grpc" + "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/encoding/protojson" +) + +var newTargetSslProxiesClientHook clientHook + +// TargetSslProxiesCallOptions contains the retry settings for each method of TargetSslProxiesClient. +type TargetSslProxiesCallOptions struct { + Delete []gax.CallOption + Get []gax.CallOption + Insert []gax.CallOption + List []gax.CallOption + SetBackendService []gax.CallOption + SetProxyHeader []gax.CallOption + SetSslCertificates []gax.CallOption + SetSslPolicy []gax.CallOption +} + +// internalTargetSslProxiesClient is an interface that defines the methods availaible from Google Compute Engine API. +type internalTargetSslProxiesClient interface { + Close() error + setGoogleClientInfo(...string) + Connection() *grpc.ClientConn + Delete(context.Context, *computepb.DeleteTargetSslProxyRequest, ...gax.CallOption) (*computepb.Operation, error) + Get(context.Context, *computepb.GetTargetSslProxyRequest, ...gax.CallOption) (*computepb.TargetSslProxy, error) + Insert(context.Context, *computepb.InsertTargetSslProxyRequest, ...gax.CallOption) (*computepb.Operation, error) + List(context.Context, *computepb.ListTargetSslProxiesRequest, ...gax.CallOption) (*computepb.TargetSslProxyList, error) + SetBackendService(context.Context, *computepb.SetBackendServiceTargetSslProxyRequest, ...gax.CallOption) (*computepb.Operation, error) + SetProxyHeader(context.Context, *computepb.SetProxyHeaderTargetSslProxyRequest, ...gax.CallOption) (*computepb.Operation, error) + SetSslCertificates(context.Context, *computepb.SetSslCertificatesTargetSslProxyRequest, ...gax.CallOption) (*computepb.Operation, error) + SetSslPolicy(context.Context, *computepb.SetSslPolicyTargetSslProxyRequest, ...gax.CallOption) (*computepb.Operation, error) +} + +// TargetSslProxiesClient is a client for interacting with Google Compute Engine API. +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +// +// The TargetSslProxies API. +type TargetSslProxiesClient struct { + // The internal transport-dependent client. + internalClient internalTargetSslProxiesClient + + // The call options for this service. + CallOptions *TargetSslProxiesCallOptions +} + +// 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 *TargetSslProxiesClient) 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 *TargetSslProxiesClient) setGoogleClientInfo(keyval ...string) { + c.internalClient.setGoogleClientInfo(keyval...) +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *TargetSslProxiesClient) Connection() *grpc.ClientConn { + return c.internalClient.Connection() +} + +// Delete deletes the specified TargetSslProxy resource. +func (c *TargetSslProxiesClient) Delete(ctx context.Context, req *computepb.DeleteTargetSslProxyRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.Delete(ctx, req, opts...) +} + +// Get returns the specified TargetSslProxy resource. Gets a list of available target SSL proxies by making a list() request. +func (c *TargetSslProxiesClient) Get(ctx context.Context, req *computepb.GetTargetSslProxyRequest, opts ...gax.CallOption) (*computepb.TargetSslProxy, error) { + return c.internalClient.Get(ctx, req, opts...) +} + +// Insert creates a TargetSslProxy resource in the specified project using the data included in the request. +func (c *TargetSslProxiesClient) Insert(ctx context.Context, req *computepb.InsertTargetSslProxyRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.Insert(ctx, req, opts...) +} + +// List retrieves the list of TargetSslProxy resources available to the specified project. +func (c *TargetSslProxiesClient) List(ctx context.Context, req *computepb.ListTargetSslProxiesRequest, opts ...gax.CallOption) (*computepb.TargetSslProxyList, error) { + return c.internalClient.List(ctx, req, opts...) +} + +// SetBackendService changes the BackendService for TargetSslProxy. +func (c *TargetSslProxiesClient) SetBackendService(ctx context.Context, req *computepb.SetBackendServiceTargetSslProxyRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.SetBackendService(ctx, req, opts...) +} + +// SetProxyHeader changes the ProxyHeaderType for TargetSslProxy. +func (c *TargetSslProxiesClient) SetProxyHeader(ctx context.Context, req *computepb.SetProxyHeaderTargetSslProxyRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.SetProxyHeader(ctx, req, opts...) +} + +// SetSslCertificates changes SslCertificates for TargetSslProxy. +func (c *TargetSslProxiesClient) SetSslCertificates(ctx context.Context, req *computepb.SetSslCertificatesTargetSslProxyRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.SetSslCertificates(ctx, req, opts...) +} + +// SetSslPolicy sets the SSL policy for TargetSslProxy. The SSL policy specifies the server-side support for SSL features. This affects connections between clients and the SSL proxy load balancer. They do not affect the connection between the load balancer and the backends. +func (c *TargetSslProxiesClient) SetSslPolicy(ctx context.Context, req *computepb.SetSslPolicyTargetSslProxyRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.SetSslPolicy(ctx, req, opts...) +} + +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +type targetSslProxiesRESTClient struct { + // The http endpoint to connect to. + endpoint string + + // The http client. + httpClient *http.Client + + // The x-goog-* metadata to be sent with each request. + xGoogMetadata metadata.MD +} + +// NewTargetSslProxiesRESTClient creates a new target ssl proxies rest client. +// +// The TargetSslProxies API. +func NewTargetSslProxiesRESTClient(ctx context.Context, opts ...option.ClientOption) (*TargetSslProxiesClient, error) { + clientOpts := append(defaultTargetSslProxiesRESTClientOptions(), opts...) + httpClient, endpoint, err := httptransport.NewClient(ctx, clientOpts...) + if err != nil { + return nil, err + } + + c := &targetSslProxiesRESTClient{ + endpoint: endpoint, + httpClient: httpClient, + } + c.setGoogleClientInfo() + + return &TargetSslProxiesClient{internalClient: c, CallOptions: &TargetSslProxiesCallOptions{}}, nil +} + +func defaultTargetSslProxiesRESTClientOptions() []option.ClientOption { + return []option.ClientOption{ + internaloption.WithDefaultEndpoint("compute.googleapis.com"), + internaloption.WithDefaultMTLSEndpoint("compute.mtls.googleapis.com"), + internaloption.WithDefaultAudience("https://compute.googleapis.com/"), + internaloption.WithDefaultScopes(DefaultAuthScopes()...), + } +} + +// 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 *targetSslProxiesRESTClient) setGoogleClientInfo(keyval ...string) { + kv := append([]string{"gl-go", versionGo()}, keyval...) + kv = append(kv, "gapic", versionClient, "gax", gax.Version, "rest", "UNKNOWN") + 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 *targetSslProxiesRESTClient) Close() error { + // Replace httpClient with nil to force cleanup. + c.httpClient = nil + return nil +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *targetSslProxiesRESTClient) Connection() *grpc.ClientConn { + return nil +} + +// Delete deletes the specified TargetSslProxy resource. +func (c *targetSslProxiesRESTClient) Delete(ctx context.Context, req *computepb.DeleteTargetSslProxyRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/targetSslProxies/%v", req.GetProject(), req.GetTargetSslProxy()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("DELETE", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Get returns the specified TargetSslProxy resource. Gets a list of available target SSL proxies by making a list() request. +func (c *targetSslProxiesRESTClient) Get(ctx context.Context, req *computepb.GetTargetSslProxyRequest, opts ...gax.CallOption) (*computepb.TargetSslProxy, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/targetSslProxies/%v", req.GetProject(), req.GetTargetSslProxy()) + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.TargetSslProxy{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Insert creates a TargetSslProxy resource in the specified project using the data included in the request. +func (c *targetSslProxiesRESTClient) Insert(ctx context.Context, req *computepb.InsertTargetSslProxyRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetTargetSslProxyResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/targetSslProxies", req.GetProject()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// List retrieves the list of TargetSslProxy resources available to the specified project. +func (c *targetSslProxiesRESTClient) List(ctx context.Context, req *computepb.ListTargetSslProxiesRequest, opts ...gax.CallOption) (*computepb.TargetSslProxyList, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/targetSslProxies", req.GetProject()) + + params := url.Values{} + if req != nil && req.Filter != nil { + params.Add("filter", fmt.Sprintf("%v", req.GetFilter())) + } + if req != nil && req.MaxResults != nil { + params.Add("maxResults", fmt.Sprintf("%v", req.GetMaxResults())) + } + if req != nil && req.OrderBy != nil { + params.Add("orderBy", fmt.Sprintf("%v", req.GetOrderBy())) + } + if req != nil && req.PageToken != nil { + params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) + } + if req != nil && req.ReturnPartialSuccess != nil { + params.Add("returnPartialSuccess", fmt.Sprintf("%v", req.GetReturnPartialSuccess())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.TargetSslProxyList{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// SetBackendService changes the BackendService for TargetSslProxy. +func (c *targetSslProxiesRESTClient) SetBackendService(ctx context.Context, req *computepb.SetBackendServiceTargetSslProxyRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetTargetSslProxiesSetBackendServiceRequestResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/targetSslProxies/%v/setBackendService", req.GetProject(), req.GetTargetSslProxy()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// SetProxyHeader changes the ProxyHeaderType for TargetSslProxy. +func (c *targetSslProxiesRESTClient) SetProxyHeader(ctx context.Context, req *computepb.SetProxyHeaderTargetSslProxyRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetTargetSslProxiesSetProxyHeaderRequestResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/targetSslProxies/%v/setProxyHeader", req.GetProject(), req.GetTargetSslProxy()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// SetSslCertificates changes SslCertificates for TargetSslProxy. +func (c *targetSslProxiesRESTClient) SetSslCertificates(ctx context.Context, req *computepb.SetSslCertificatesTargetSslProxyRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetTargetSslProxiesSetSslCertificatesRequestResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/targetSslProxies/%v/setSslCertificates", req.GetProject(), req.GetTargetSslProxy()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// SetSslPolicy sets the SSL policy for TargetSslProxy. The SSL policy specifies the server-side support for SSL features. This affects connections between clients and the SSL proxy load balancer. They do not affect the connection between the load balancer and the backends. +func (c *targetSslProxiesRESTClient) SetSslPolicy(ctx context.Context, req *computepb.SetSslPolicyTargetSslProxyRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetSslPolicyReferenceResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/targetSslProxies/%v/setSslPolicy", req.GetProject(), req.GetTargetSslProxy()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} diff --git a/compute/apiv1/target_ssl_proxies_client_example_test.go b/compute/apiv1/target_ssl_proxies_client_example_test.go new file mode 100644 index 00000000000..09db740716c --- /dev/null +++ b/compute/apiv1/target_ssl_proxies_client_example_test.go @@ -0,0 +1,188 @@ +// 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 compute_test + +import ( + "context" + + compute "cloud.google.com/go/compute/apiv1" + computepb "google.golang.org/genproto/googleapis/cloud/compute/v1" +) + +func ExampleNewTargetSslProxiesRESTClient() { + ctx := context.Background() + c, err := compute.NewTargetSslProxiesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + // TODO: Use client. + _ = c +} + +func ExampleTargetSslProxiesClient_Delete() { + ctx := context.Background() + c, err := compute.NewTargetSslProxiesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.DeleteTargetSslProxyRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Delete(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleTargetSslProxiesClient_Get() { + ctx := context.Background() + c, err := compute.NewTargetSslProxiesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.GetTargetSslProxyRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Get(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleTargetSslProxiesClient_Insert() { + ctx := context.Background() + c, err := compute.NewTargetSslProxiesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.InsertTargetSslProxyRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Insert(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleTargetSslProxiesClient_List() { + ctx := context.Background() + c, err := compute.NewTargetSslProxiesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.ListTargetSslProxiesRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.List(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleTargetSslProxiesClient_SetBackendService() { + ctx := context.Background() + c, err := compute.NewTargetSslProxiesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.SetBackendServiceTargetSslProxyRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.SetBackendService(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleTargetSslProxiesClient_SetProxyHeader() { + ctx := context.Background() + c, err := compute.NewTargetSslProxiesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.SetProxyHeaderTargetSslProxyRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.SetProxyHeader(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleTargetSslProxiesClient_SetSslCertificates() { + ctx := context.Background() + c, err := compute.NewTargetSslProxiesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.SetSslCertificatesTargetSslProxyRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.SetSslCertificates(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleTargetSslProxiesClient_SetSslPolicy() { + ctx := context.Background() + c, err := compute.NewTargetSslProxiesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.SetSslPolicyTargetSslProxyRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.SetSslPolicy(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} diff --git a/compute/apiv1/target_tcp_proxies_client.go b/compute/apiv1/target_tcp_proxies_client.go new file mode 100644 index 00000000000..f2631211628 --- /dev/null +++ b/compute/apiv1/target_tcp_proxies_client.go @@ -0,0 +1,496 @@ +// 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 compute + +import ( + "bytes" + "context" + "fmt" + "io/ioutil" + "net/http" + "net/url" + + gax "github.com/googleapis/gax-go/v2" + "google.golang.org/api/option" + "google.golang.org/api/option/internaloption" + httptransport "google.golang.org/api/transport/http" + computepb "google.golang.org/genproto/googleapis/cloud/compute/v1" + "google.golang.org/grpc" + "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/encoding/protojson" +) + +var newTargetTcpProxiesClientHook clientHook + +// TargetTcpProxiesCallOptions contains the retry settings for each method of TargetTcpProxiesClient. +type TargetTcpProxiesCallOptions struct { + Delete []gax.CallOption + Get []gax.CallOption + Insert []gax.CallOption + List []gax.CallOption + SetBackendService []gax.CallOption + SetProxyHeader []gax.CallOption +} + +// internalTargetTcpProxiesClient is an interface that defines the methods availaible from Google Compute Engine API. +type internalTargetTcpProxiesClient interface { + Close() error + setGoogleClientInfo(...string) + Connection() *grpc.ClientConn + Delete(context.Context, *computepb.DeleteTargetTcpProxyRequest, ...gax.CallOption) (*computepb.Operation, error) + Get(context.Context, *computepb.GetTargetTcpProxyRequest, ...gax.CallOption) (*computepb.TargetTcpProxy, error) + Insert(context.Context, *computepb.InsertTargetTcpProxyRequest, ...gax.CallOption) (*computepb.Operation, error) + List(context.Context, *computepb.ListTargetTcpProxiesRequest, ...gax.CallOption) (*computepb.TargetTcpProxyList, error) + SetBackendService(context.Context, *computepb.SetBackendServiceTargetTcpProxyRequest, ...gax.CallOption) (*computepb.Operation, error) + SetProxyHeader(context.Context, *computepb.SetProxyHeaderTargetTcpProxyRequest, ...gax.CallOption) (*computepb.Operation, error) +} + +// TargetTcpProxiesClient is a client for interacting with Google Compute Engine API. +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +// +// The TargetTcpProxies API. +type TargetTcpProxiesClient struct { + // The internal transport-dependent client. + internalClient internalTargetTcpProxiesClient + + // The call options for this service. + CallOptions *TargetTcpProxiesCallOptions +} + +// 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 *TargetTcpProxiesClient) 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 *TargetTcpProxiesClient) setGoogleClientInfo(keyval ...string) { + c.internalClient.setGoogleClientInfo(keyval...) +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *TargetTcpProxiesClient) Connection() *grpc.ClientConn { + return c.internalClient.Connection() +} + +// Delete deletes the specified TargetTcpProxy resource. +func (c *TargetTcpProxiesClient) Delete(ctx context.Context, req *computepb.DeleteTargetTcpProxyRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.Delete(ctx, req, opts...) +} + +// Get returns the specified TargetTcpProxy resource. Gets a list of available target TCP proxies by making a list() request. +func (c *TargetTcpProxiesClient) Get(ctx context.Context, req *computepb.GetTargetTcpProxyRequest, opts ...gax.CallOption) (*computepb.TargetTcpProxy, error) { + return c.internalClient.Get(ctx, req, opts...) +} + +// Insert creates a TargetTcpProxy resource in the specified project using the data included in the request. +func (c *TargetTcpProxiesClient) Insert(ctx context.Context, req *computepb.InsertTargetTcpProxyRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.Insert(ctx, req, opts...) +} + +// List retrieves the list of TargetTcpProxy resources available to the specified project. +func (c *TargetTcpProxiesClient) List(ctx context.Context, req *computepb.ListTargetTcpProxiesRequest, opts ...gax.CallOption) (*computepb.TargetTcpProxyList, error) { + return c.internalClient.List(ctx, req, opts...) +} + +// SetBackendService changes the BackendService for TargetTcpProxy. +func (c *TargetTcpProxiesClient) SetBackendService(ctx context.Context, req *computepb.SetBackendServiceTargetTcpProxyRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.SetBackendService(ctx, req, opts...) +} + +// SetProxyHeader changes the ProxyHeaderType for TargetTcpProxy. +func (c *TargetTcpProxiesClient) SetProxyHeader(ctx context.Context, req *computepb.SetProxyHeaderTargetTcpProxyRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.SetProxyHeader(ctx, req, opts...) +} + +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +type targetTcpProxiesRESTClient struct { + // The http endpoint to connect to. + endpoint string + + // The http client. + httpClient *http.Client + + // The x-goog-* metadata to be sent with each request. + xGoogMetadata metadata.MD +} + +// NewTargetTcpProxiesRESTClient creates a new target tcp proxies rest client. +// +// The TargetTcpProxies API. +func NewTargetTcpProxiesRESTClient(ctx context.Context, opts ...option.ClientOption) (*TargetTcpProxiesClient, error) { + clientOpts := append(defaultTargetTcpProxiesRESTClientOptions(), opts...) + httpClient, endpoint, err := httptransport.NewClient(ctx, clientOpts...) + if err != nil { + return nil, err + } + + c := &targetTcpProxiesRESTClient{ + endpoint: endpoint, + httpClient: httpClient, + } + c.setGoogleClientInfo() + + return &TargetTcpProxiesClient{internalClient: c, CallOptions: &TargetTcpProxiesCallOptions{}}, nil +} + +func defaultTargetTcpProxiesRESTClientOptions() []option.ClientOption { + return []option.ClientOption{ + internaloption.WithDefaultEndpoint("compute.googleapis.com"), + internaloption.WithDefaultMTLSEndpoint("compute.mtls.googleapis.com"), + internaloption.WithDefaultAudience("https://compute.googleapis.com/"), + internaloption.WithDefaultScopes(DefaultAuthScopes()...), + } +} + +// 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 *targetTcpProxiesRESTClient) setGoogleClientInfo(keyval ...string) { + kv := append([]string{"gl-go", versionGo()}, keyval...) + kv = append(kv, "gapic", versionClient, "gax", gax.Version, "rest", "UNKNOWN") + 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 *targetTcpProxiesRESTClient) Close() error { + // Replace httpClient with nil to force cleanup. + c.httpClient = nil + return nil +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *targetTcpProxiesRESTClient) Connection() *grpc.ClientConn { + return nil +} + +// Delete deletes the specified TargetTcpProxy resource. +func (c *targetTcpProxiesRESTClient) Delete(ctx context.Context, req *computepb.DeleteTargetTcpProxyRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/targetTcpProxies/%v", req.GetProject(), req.GetTargetTcpProxy()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("DELETE", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Get returns the specified TargetTcpProxy resource. Gets a list of available target TCP proxies by making a list() request. +func (c *targetTcpProxiesRESTClient) Get(ctx context.Context, req *computepb.GetTargetTcpProxyRequest, opts ...gax.CallOption) (*computepb.TargetTcpProxy, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/targetTcpProxies/%v", req.GetProject(), req.GetTargetTcpProxy()) + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.TargetTcpProxy{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Insert creates a TargetTcpProxy resource in the specified project using the data included in the request. +func (c *targetTcpProxiesRESTClient) Insert(ctx context.Context, req *computepb.InsertTargetTcpProxyRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetTargetTcpProxyResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/targetTcpProxies", req.GetProject()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// List retrieves the list of TargetTcpProxy resources available to the specified project. +func (c *targetTcpProxiesRESTClient) List(ctx context.Context, req *computepb.ListTargetTcpProxiesRequest, opts ...gax.CallOption) (*computepb.TargetTcpProxyList, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/targetTcpProxies", req.GetProject()) + + params := url.Values{} + if req != nil && req.Filter != nil { + params.Add("filter", fmt.Sprintf("%v", req.GetFilter())) + } + if req != nil && req.MaxResults != nil { + params.Add("maxResults", fmt.Sprintf("%v", req.GetMaxResults())) + } + if req != nil && req.OrderBy != nil { + params.Add("orderBy", fmt.Sprintf("%v", req.GetOrderBy())) + } + if req != nil && req.PageToken != nil { + params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) + } + if req != nil && req.ReturnPartialSuccess != nil { + params.Add("returnPartialSuccess", fmt.Sprintf("%v", req.GetReturnPartialSuccess())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.TargetTcpProxyList{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// SetBackendService changes the BackendService for TargetTcpProxy. +func (c *targetTcpProxiesRESTClient) SetBackendService(ctx context.Context, req *computepb.SetBackendServiceTargetTcpProxyRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetTargetTcpProxiesSetBackendServiceRequestResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/targetTcpProxies/%v/setBackendService", req.GetProject(), req.GetTargetTcpProxy()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// SetProxyHeader changes the ProxyHeaderType for TargetTcpProxy. +func (c *targetTcpProxiesRESTClient) SetProxyHeader(ctx context.Context, req *computepb.SetProxyHeaderTargetTcpProxyRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetTargetTcpProxiesSetProxyHeaderRequestResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/targetTcpProxies/%v/setProxyHeader", req.GetProject(), req.GetTargetTcpProxy()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} diff --git a/compute/apiv1/target_tcp_proxies_client_example_test.go b/compute/apiv1/target_tcp_proxies_client_example_test.go new file mode 100644 index 00000000000..0e95e1f74eb --- /dev/null +++ b/compute/apiv1/target_tcp_proxies_client_example_test.go @@ -0,0 +1,150 @@ +// 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 compute_test + +import ( + "context" + + compute "cloud.google.com/go/compute/apiv1" + computepb "google.golang.org/genproto/googleapis/cloud/compute/v1" +) + +func ExampleNewTargetTcpProxiesRESTClient() { + ctx := context.Background() + c, err := compute.NewTargetTcpProxiesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + // TODO: Use client. + _ = c +} + +func ExampleTargetTcpProxiesClient_Delete() { + ctx := context.Background() + c, err := compute.NewTargetTcpProxiesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.DeleteTargetTcpProxyRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Delete(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleTargetTcpProxiesClient_Get() { + ctx := context.Background() + c, err := compute.NewTargetTcpProxiesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.GetTargetTcpProxyRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Get(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleTargetTcpProxiesClient_Insert() { + ctx := context.Background() + c, err := compute.NewTargetTcpProxiesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.InsertTargetTcpProxyRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Insert(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleTargetTcpProxiesClient_List() { + ctx := context.Background() + c, err := compute.NewTargetTcpProxiesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.ListTargetTcpProxiesRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.List(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleTargetTcpProxiesClient_SetBackendService() { + ctx := context.Background() + c, err := compute.NewTargetTcpProxiesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.SetBackendServiceTargetTcpProxyRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.SetBackendService(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleTargetTcpProxiesClient_SetProxyHeader() { + ctx := context.Background() + c, err := compute.NewTargetTcpProxiesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.SetProxyHeaderTargetTcpProxyRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.SetProxyHeader(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} diff --git a/compute/apiv1/target_vpn_gateways_client.go b/compute/apiv1/target_vpn_gateways_client.go new file mode 100644 index 00000000000..996e785297f --- /dev/null +++ b/compute/apiv1/target_vpn_gateways_client.go @@ -0,0 +1,452 @@ +// 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 compute + +import ( + "bytes" + "context" + "fmt" + "io/ioutil" + "net/http" + "net/url" + + gax "github.com/googleapis/gax-go/v2" + "google.golang.org/api/option" + "google.golang.org/api/option/internaloption" + httptransport "google.golang.org/api/transport/http" + computepb "google.golang.org/genproto/googleapis/cloud/compute/v1" + "google.golang.org/grpc" + "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/encoding/protojson" +) + +var newTargetVpnGatewaysClientHook clientHook + +// TargetVpnGatewaysCallOptions contains the retry settings for each method of TargetVpnGatewaysClient. +type TargetVpnGatewaysCallOptions struct { + AggregatedList []gax.CallOption + Delete []gax.CallOption + Get []gax.CallOption + Insert []gax.CallOption + List []gax.CallOption +} + +// internalTargetVpnGatewaysClient is an interface that defines the methods availaible from Google Compute Engine API. +type internalTargetVpnGatewaysClient interface { + Close() error + setGoogleClientInfo(...string) + Connection() *grpc.ClientConn + AggregatedList(context.Context, *computepb.AggregatedListTargetVpnGatewaysRequest, ...gax.CallOption) (*computepb.TargetVpnGatewayAggregatedList, error) + Delete(context.Context, *computepb.DeleteTargetVpnGatewayRequest, ...gax.CallOption) (*computepb.Operation, error) + Get(context.Context, *computepb.GetTargetVpnGatewayRequest, ...gax.CallOption) (*computepb.TargetVpnGateway, error) + Insert(context.Context, *computepb.InsertTargetVpnGatewayRequest, ...gax.CallOption) (*computepb.Operation, error) + List(context.Context, *computepb.ListTargetVpnGatewaysRequest, ...gax.CallOption) (*computepb.TargetVpnGatewayList, error) +} + +// TargetVpnGatewaysClient is a client for interacting with Google Compute Engine API. +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +// +// The TargetVpnGateways API. +type TargetVpnGatewaysClient struct { + // The internal transport-dependent client. + internalClient internalTargetVpnGatewaysClient + + // The call options for this service. + CallOptions *TargetVpnGatewaysCallOptions +} + +// 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 *TargetVpnGatewaysClient) 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 *TargetVpnGatewaysClient) setGoogleClientInfo(keyval ...string) { + c.internalClient.setGoogleClientInfo(keyval...) +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *TargetVpnGatewaysClient) Connection() *grpc.ClientConn { + return c.internalClient.Connection() +} + +// AggregatedList retrieves an aggregated list of target VPN gateways. +func (c *TargetVpnGatewaysClient) AggregatedList(ctx context.Context, req *computepb.AggregatedListTargetVpnGatewaysRequest, opts ...gax.CallOption) (*computepb.TargetVpnGatewayAggregatedList, error) { + return c.internalClient.AggregatedList(ctx, req, opts...) +} + +// Delete deletes the specified target VPN gateway. +func (c *TargetVpnGatewaysClient) Delete(ctx context.Context, req *computepb.DeleteTargetVpnGatewayRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.Delete(ctx, req, opts...) +} + +// Get returns the specified target VPN gateway. Gets a list of available target VPN gateways by making a list() request. +func (c *TargetVpnGatewaysClient) Get(ctx context.Context, req *computepb.GetTargetVpnGatewayRequest, opts ...gax.CallOption) (*computepb.TargetVpnGateway, error) { + return c.internalClient.Get(ctx, req, opts...) +} + +// Insert creates a target VPN gateway in the specified project and region using the data included in the request. +func (c *TargetVpnGatewaysClient) Insert(ctx context.Context, req *computepb.InsertTargetVpnGatewayRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.Insert(ctx, req, opts...) +} + +// List retrieves a list of target VPN gateways available to the specified project and region. +func (c *TargetVpnGatewaysClient) List(ctx context.Context, req *computepb.ListTargetVpnGatewaysRequest, opts ...gax.CallOption) (*computepb.TargetVpnGatewayList, error) { + return c.internalClient.List(ctx, req, opts...) +} + +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +type targetVpnGatewaysRESTClient struct { + // The http endpoint to connect to. + endpoint string + + // The http client. + httpClient *http.Client + + // The x-goog-* metadata to be sent with each request. + xGoogMetadata metadata.MD +} + +// NewTargetVpnGatewaysRESTClient creates a new target vpn gateways rest client. +// +// The TargetVpnGateways API. +func NewTargetVpnGatewaysRESTClient(ctx context.Context, opts ...option.ClientOption) (*TargetVpnGatewaysClient, error) { + clientOpts := append(defaultTargetVpnGatewaysRESTClientOptions(), opts...) + httpClient, endpoint, err := httptransport.NewClient(ctx, clientOpts...) + if err != nil { + return nil, err + } + + c := &targetVpnGatewaysRESTClient{ + endpoint: endpoint, + httpClient: httpClient, + } + c.setGoogleClientInfo() + + return &TargetVpnGatewaysClient{internalClient: c, CallOptions: &TargetVpnGatewaysCallOptions{}}, nil +} + +func defaultTargetVpnGatewaysRESTClientOptions() []option.ClientOption { + return []option.ClientOption{ + internaloption.WithDefaultEndpoint("compute.googleapis.com"), + internaloption.WithDefaultMTLSEndpoint("compute.mtls.googleapis.com"), + internaloption.WithDefaultAudience("https://compute.googleapis.com/"), + internaloption.WithDefaultScopes(DefaultAuthScopes()...), + } +} + +// 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 *targetVpnGatewaysRESTClient) setGoogleClientInfo(keyval ...string) { + kv := append([]string{"gl-go", versionGo()}, keyval...) + kv = append(kv, "gapic", versionClient, "gax", gax.Version, "rest", "UNKNOWN") + 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 *targetVpnGatewaysRESTClient) Close() error { + // Replace httpClient with nil to force cleanup. + c.httpClient = nil + return nil +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *targetVpnGatewaysRESTClient) Connection() *grpc.ClientConn { + return nil +} + +// AggregatedList retrieves an aggregated list of target VPN gateways. +func (c *targetVpnGatewaysRESTClient) AggregatedList(ctx context.Context, req *computepb.AggregatedListTargetVpnGatewaysRequest, opts ...gax.CallOption) (*computepb.TargetVpnGatewayAggregatedList, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/aggregated/targetVpnGateways", req.GetProject()) + + params := url.Values{} + if req != nil && req.Filter != nil { + params.Add("filter", fmt.Sprintf("%v", req.GetFilter())) + } + if req != nil && req.IncludeAllScopes != nil { + params.Add("includeAllScopes", fmt.Sprintf("%v", req.GetIncludeAllScopes())) + } + if req != nil && req.MaxResults != nil { + params.Add("maxResults", fmt.Sprintf("%v", req.GetMaxResults())) + } + if req != nil && req.OrderBy != nil { + params.Add("orderBy", fmt.Sprintf("%v", req.GetOrderBy())) + } + if req != nil && req.PageToken != nil { + params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) + } + if req != nil && req.ReturnPartialSuccess != nil { + params.Add("returnPartialSuccess", fmt.Sprintf("%v", req.GetReturnPartialSuccess())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.TargetVpnGatewayAggregatedList{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Delete deletes the specified target VPN gateway. +func (c *targetVpnGatewaysRESTClient) Delete(ctx context.Context, req *computepb.DeleteTargetVpnGatewayRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/regions/%v/targetVpnGateways/%v", req.GetProject(), req.GetRegion(), req.GetTargetVpnGateway()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("DELETE", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Get returns the specified target VPN gateway. Gets a list of available target VPN gateways by making a list() request. +func (c *targetVpnGatewaysRESTClient) Get(ctx context.Context, req *computepb.GetTargetVpnGatewayRequest, opts ...gax.CallOption) (*computepb.TargetVpnGateway, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/regions/%v/targetVpnGateways/%v", req.GetProject(), req.GetRegion(), req.GetTargetVpnGateway()) + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.TargetVpnGateway{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Insert creates a target VPN gateway in the specified project and region using the data included in the request. +func (c *targetVpnGatewaysRESTClient) Insert(ctx context.Context, req *computepb.InsertTargetVpnGatewayRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetTargetVpnGatewayResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/regions/%v/targetVpnGateways", req.GetProject(), req.GetRegion()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// List retrieves a list of target VPN gateways available to the specified project and region. +func (c *targetVpnGatewaysRESTClient) List(ctx context.Context, req *computepb.ListTargetVpnGatewaysRequest, opts ...gax.CallOption) (*computepb.TargetVpnGatewayList, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/regions/%v/targetVpnGateways", req.GetProject(), req.GetRegion()) + + params := url.Values{} + if req != nil && req.Filter != nil { + params.Add("filter", fmt.Sprintf("%v", req.GetFilter())) + } + if req != nil && req.MaxResults != nil { + params.Add("maxResults", fmt.Sprintf("%v", req.GetMaxResults())) + } + if req != nil && req.OrderBy != nil { + params.Add("orderBy", fmt.Sprintf("%v", req.GetOrderBy())) + } + if req != nil && req.PageToken != nil { + params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) + } + if req != nil && req.ReturnPartialSuccess != nil { + params.Add("returnPartialSuccess", fmt.Sprintf("%v", req.GetReturnPartialSuccess())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.TargetVpnGatewayList{} + + return rsp, unm.Unmarshal(buf, rsp) +} diff --git a/compute/apiv1/target_vpn_gateways_client_example_test.go b/compute/apiv1/target_vpn_gateways_client_example_test.go new file mode 100644 index 00000000000..1c8e35cd606 --- /dev/null +++ b/compute/apiv1/target_vpn_gateways_client_example_test.go @@ -0,0 +1,131 @@ +// 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 compute_test + +import ( + "context" + + compute "cloud.google.com/go/compute/apiv1" + computepb "google.golang.org/genproto/googleapis/cloud/compute/v1" +) + +func ExampleNewTargetVpnGatewaysRESTClient() { + ctx := context.Background() + c, err := compute.NewTargetVpnGatewaysRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + // TODO: Use client. + _ = c +} + +func ExampleTargetVpnGatewaysClient_AggregatedList() { + ctx := context.Background() + c, err := compute.NewTargetVpnGatewaysRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.AggregatedListTargetVpnGatewaysRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.AggregatedList(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleTargetVpnGatewaysClient_Delete() { + ctx := context.Background() + c, err := compute.NewTargetVpnGatewaysRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.DeleteTargetVpnGatewayRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Delete(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleTargetVpnGatewaysClient_Get() { + ctx := context.Background() + c, err := compute.NewTargetVpnGatewaysRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.GetTargetVpnGatewayRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Get(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleTargetVpnGatewaysClient_Insert() { + ctx := context.Background() + c, err := compute.NewTargetVpnGatewaysRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.InsertTargetVpnGatewayRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Insert(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleTargetVpnGatewaysClient_List() { + ctx := context.Background() + c, err := compute.NewTargetVpnGatewaysRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.ListTargetVpnGatewaysRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.List(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} diff --git a/compute/apiv1/url_maps_client.go b/compute/apiv1/url_maps_client.go new file mode 100644 index 00000000000..798e93645d9 --- /dev/null +++ b/compute/apiv1/url_maps_client.go @@ -0,0 +1,687 @@ +// 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 compute + +import ( + "bytes" + "context" + "fmt" + "io/ioutil" + "net/http" + "net/url" + + gax "github.com/googleapis/gax-go/v2" + "google.golang.org/api/option" + "google.golang.org/api/option/internaloption" + httptransport "google.golang.org/api/transport/http" + computepb "google.golang.org/genproto/googleapis/cloud/compute/v1" + "google.golang.org/grpc" + "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/encoding/protojson" +) + +var newUrlMapsClientHook clientHook + +// UrlMapsCallOptions contains the retry settings for each method of UrlMapsClient. +type UrlMapsCallOptions struct { + AggregatedList []gax.CallOption + Delete []gax.CallOption + Get []gax.CallOption + Insert []gax.CallOption + InvalidateCache []gax.CallOption + List []gax.CallOption + Patch []gax.CallOption + Update []gax.CallOption + Validate []gax.CallOption +} + +// internalUrlMapsClient is an interface that defines the methods availaible from Google Compute Engine API. +type internalUrlMapsClient interface { + Close() error + setGoogleClientInfo(...string) + Connection() *grpc.ClientConn + AggregatedList(context.Context, *computepb.AggregatedListUrlMapsRequest, ...gax.CallOption) (*computepb.UrlMapsAggregatedList, error) + Delete(context.Context, *computepb.DeleteUrlMapRequest, ...gax.CallOption) (*computepb.Operation, error) + Get(context.Context, *computepb.GetUrlMapRequest, ...gax.CallOption) (*computepb.UrlMap, error) + Insert(context.Context, *computepb.InsertUrlMapRequest, ...gax.CallOption) (*computepb.Operation, error) + InvalidateCache(context.Context, *computepb.InvalidateCacheUrlMapRequest, ...gax.CallOption) (*computepb.Operation, error) + List(context.Context, *computepb.ListUrlMapsRequest, ...gax.CallOption) (*computepb.UrlMapList, error) + Patch(context.Context, *computepb.PatchUrlMapRequest, ...gax.CallOption) (*computepb.Operation, error) + Update(context.Context, *computepb.UpdateUrlMapRequest, ...gax.CallOption) (*computepb.Operation, error) + Validate(context.Context, *computepb.ValidateUrlMapRequest, ...gax.CallOption) (*computepb.UrlMapsValidateResponse, error) +} + +// UrlMapsClient is a client for interacting with Google Compute Engine API. +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +// +// The UrlMaps API. +type UrlMapsClient struct { + // The internal transport-dependent client. + internalClient internalUrlMapsClient + + // The call options for this service. + CallOptions *UrlMapsCallOptions +} + +// 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 *UrlMapsClient) 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 *UrlMapsClient) setGoogleClientInfo(keyval ...string) { + c.internalClient.setGoogleClientInfo(keyval...) +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *UrlMapsClient) Connection() *grpc.ClientConn { + return c.internalClient.Connection() +} + +// AggregatedList retrieves the list of all UrlMap resources, regional and global, available to the specified project. +func (c *UrlMapsClient) AggregatedList(ctx context.Context, req *computepb.AggregatedListUrlMapsRequest, opts ...gax.CallOption) (*computepb.UrlMapsAggregatedList, error) { + return c.internalClient.AggregatedList(ctx, req, opts...) +} + +// Delete deletes the specified UrlMap resource. +func (c *UrlMapsClient) Delete(ctx context.Context, req *computepb.DeleteUrlMapRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.Delete(ctx, req, opts...) +} + +// Get returns the specified UrlMap resource. Gets a list of available URL maps by making a list() request. +func (c *UrlMapsClient) Get(ctx context.Context, req *computepb.GetUrlMapRequest, opts ...gax.CallOption) (*computepb.UrlMap, error) { + return c.internalClient.Get(ctx, req, opts...) +} + +// Insert creates a UrlMap resource in the specified project using the data included in the request. +func (c *UrlMapsClient) Insert(ctx context.Context, req *computepb.InsertUrlMapRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.Insert(ctx, req, opts...) +} + +// InvalidateCache initiates a cache invalidation operation, invalidating the specified path, scoped to the specified UrlMap. +// +// For more information, see Invalidating cached content (at /cdn/docs/invalidating-cached-content). +func (c *UrlMapsClient) InvalidateCache(ctx context.Context, req *computepb.InvalidateCacheUrlMapRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.InvalidateCache(ctx, req, opts...) +} + +// List retrieves the list of UrlMap resources available to the specified project. +func (c *UrlMapsClient) List(ctx context.Context, req *computepb.ListUrlMapsRequest, opts ...gax.CallOption) (*computepb.UrlMapList, error) { + return c.internalClient.List(ctx, req, opts...) +} + +// Patch patches the specified UrlMap resource with the data included in the request. This method supports PATCH semantics and uses the JSON merge patch format and processing rules. +func (c *UrlMapsClient) Patch(ctx context.Context, req *computepb.PatchUrlMapRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.Patch(ctx, req, opts...) +} + +// Update updates the specified UrlMap resource with the data included in the request. +func (c *UrlMapsClient) Update(ctx context.Context, req *computepb.UpdateUrlMapRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.Update(ctx, req, opts...) +} + +// Validate runs static validation for the UrlMap. In particular, the tests of the provided UrlMap will be run. Calling this method does NOT create the UrlMap. +func (c *UrlMapsClient) Validate(ctx context.Context, req *computepb.ValidateUrlMapRequest, opts ...gax.CallOption) (*computepb.UrlMapsValidateResponse, error) { + return c.internalClient.Validate(ctx, req, opts...) +} + +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +type urlMapsRESTClient struct { + // The http endpoint to connect to. + endpoint string + + // The http client. + httpClient *http.Client + + // The x-goog-* metadata to be sent with each request. + xGoogMetadata metadata.MD +} + +// NewUrlMapsRESTClient creates a new url maps rest client. +// +// The UrlMaps API. +func NewUrlMapsRESTClient(ctx context.Context, opts ...option.ClientOption) (*UrlMapsClient, error) { + clientOpts := append(defaultUrlMapsRESTClientOptions(), opts...) + httpClient, endpoint, err := httptransport.NewClient(ctx, clientOpts...) + if err != nil { + return nil, err + } + + c := &urlMapsRESTClient{ + endpoint: endpoint, + httpClient: httpClient, + } + c.setGoogleClientInfo() + + return &UrlMapsClient{internalClient: c, CallOptions: &UrlMapsCallOptions{}}, nil +} + +func defaultUrlMapsRESTClientOptions() []option.ClientOption { + return []option.ClientOption{ + internaloption.WithDefaultEndpoint("compute.googleapis.com"), + internaloption.WithDefaultMTLSEndpoint("compute.mtls.googleapis.com"), + internaloption.WithDefaultAudience("https://compute.googleapis.com/"), + internaloption.WithDefaultScopes(DefaultAuthScopes()...), + } +} + +// 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 *urlMapsRESTClient) setGoogleClientInfo(keyval ...string) { + kv := append([]string{"gl-go", versionGo()}, keyval...) + kv = append(kv, "gapic", versionClient, "gax", gax.Version, "rest", "UNKNOWN") + 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 *urlMapsRESTClient) Close() error { + // Replace httpClient with nil to force cleanup. + c.httpClient = nil + return nil +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *urlMapsRESTClient) Connection() *grpc.ClientConn { + return nil +} + +// AggregatedList retrieves the list of all UrlMap resources, regional and global, available to the specified project. +func (c *urlMapsRESTClient) AggregatedList(ctx context.Context, req *computepb.AggregatedListUrlMapsRequest, opts ...gax.CallOption) (*computepb.UrlMapsAggregatedList, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/aggregated/urlMaps", req.GetProject()) + + params := url.Values{} + if req != nil && req.Filter != nil { + params.Add("filter", fmt.Sprintf("%v", req.GetFilter())) + } + if req != nil && req.IncludeAllScopes != nil { + params.Add("includeAllScopes", fmt.Sprintf("%v", req.GetIncludeAllScopes())) + } + if req != nil && req.MaxResults != nil { + params.Add("maxResults", fmt.Sprintf("%v", req.GetMaxResults())) + } + if req != nil && req.OrderBy != nil { + params.Add("orderBy", fmt.Sprintf("%v", req.GetOrderBy())) + } + if req != nil && req.PageToken != nil { + params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) + } + if req != nil && req.ReturnPartialSuccess != nil { + params.Add("returnPartialSuccess", fmt.Sprintf("%v", req.GetReturnPartialSuccess())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.UrlMapsAggregatedList{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Delete deletes the specified UrlMap resource. +func (c *urlMapsRESTClient) Delete(ctx context.Context, req *computepb.DeleteUrlMapRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/urlMaps/%v", req.GetProject(), req.GetUrlMap()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("DELETE", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Get returns the specified UrlMap resource. Gets a list of available URL maps by making a list() request. +func (c *urlMapsRESTClient) Get(ctx context.Context, req *computepb.GetUrlMapRequest, opts ...gax.CallOption) (*computepb.UrlMap, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/urlMaps/%v", req.GetProject(), req.GetUrlMap()) + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.UrlMap{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Insert creates a UrlMap resource in the specified project using the data included in the request. +func (c *urlMapsRESTClient) Insert(ctx context.Context, req *computepb.InsertUrlMapRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetUrlMapResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/urlMaps", req.GetProject()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// InvalidateCache initiates a cache invalidation operation, invalidating the specified path, scoped to the specified UrlMap. +// +// For more information, see Invalidating cached content (at /cdn/docs/invalidating-cached-content). +func (c *urlMapsRESTClient) InvalidateCache(ctx context.Context, req *computepb.InvalidateCacheUrlMapRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetCacheInvalidationRuleResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/urlMaps/%v/invalidateCache", req.GetProject(), req.GetUrlMap()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// List retrieves the list of UrlMap resources available to the specified project. +func (c *urlMapsRESTClient) List(ctx context.Context, req *computepb.ListUrlMapsRequest, opts ...gax.CallOption) (*computepb.UrlMapList, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/urlMaps", req.GetProject()) + + params := url.Values{} + if req != nil && req.Filter != nil { + params.Add("filter", fmt.Sprintf("%v", req.GetFilter())) + } + if req != nil && req.MaxResults != nil { + params.Add("maxResults", fmt.Sprintf("%v", req.GetMaxResults())) + } + if req != nil && req.OrderBy != nil { + params.Add("orderBy", fmt.Sprintf("%v", req.GetOrderBy())) + } + if req != nil && req.PageToken != nil { + params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) + } + if req != nil && req.ReturnPartialSuccess != nil { + params.Add("returnPartialSuccess", fmt.Sprintf("%v", req.GetReturnPartialSuccess())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.UrlMapList{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Patch patches the specified UrlMap resource with the data included in the request. This method supports PATCH semantics and uses the JSON merge patch format and processing rules. +func (c *urlMapsRESTClient) Patch(ctx context.Context, req *computepb.PatchUrlMapRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetUrlMapResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/urlMaps/%v", req.GetProject(), req.GetUrlMap()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("PATCH", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Update updates the specified UrlMap resource with the data included in the request. +func (c *urlMapsRESTClient) Update(ctx context.Context, req *computepb.UpdateUrlMapRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetUrlMapResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("") + + params := url.Values{} + if req.GetProject() != "" { + params.Add("project", fmt.Sprintf("%v", req.GetProject())) + } + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + if req.GetUrlMap() != "" { + params.Add("urlMap", fmt.Sprintf("%v", req.GetUrlMap())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("PUT", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Validate runs static validation for the UrlMap. In particular, the tests of the provided UrlMap will be run. Calling this method does NOT create the UrlMap. +func (c *urlMapsRESTClient) Validate(ctx context.Context, req *computepb.ValidateUrlMapRequest, opts ...gax.CallOption) (*computepb.UrlMapsValidateResponse, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetUrlMapsValidateRequestResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/global/urlMaps/%v/validate", req.GetProject(), req.GetUrlMap()) + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.UrlMapsValidateResponse{} + + return rsp, unm.Unmarshal(buf, rsp) +} diff --git a/compute/apiv1/url_maps_client_example_test.go b/compute/apiv1/url_maps_client_example_test.go new file mode 100644 index 00000000000..d6f8304d1e7 --- /dev/null +++ b/compute/apiv1/url_maps_client_example_test.go @@ -0,0 +1,207 @@ +// 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 compute_test + +import ( + "context" + + compute "cloud.google.com/go/compute/apiv1" + computepb "google.golang.org/genproto/googleapis/cloud/compute/v1" +) + +func ExampleNewUrlMapsRESTClient() { + ctx := context.Background() + c, err := compute.NewUrlMapsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + // TODO: Use client. + _ = c +} + +func ExampleUrlMapsClient_AggregatedList() { + ctx := context.Background() + c, err := compute.NewUrlMapsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.AggregatedListUrlMapsRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.AggregatedList(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleUrlMapsClient_Delete() { + ctx := context.Background() + c, err := compute.NewUrlMapsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.DeleteUrlMapRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Delete(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleUrlMapsClient_Get() { + ctx := context.Background() + c, err := compute.NewUrlMapsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.GetUrlMapRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Get(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleUrlMapsClient_Insert() { + ctx := context.Background() + c, err := compute.NewUrlMapsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.InsertUrlMapRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Insert(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleUrlMapsClient_InvalidateCache() { + ctx := context.Background() + c, err := compute.NewUrlMapsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.InvalidateCacheUrlMapRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.InvalidateCache(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleUrlMapsClient_List() { + ctx := context.Background() + c, err := compute.NewUrlMapsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.ListUrlMapsRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.List(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleUrlMapsClient_Patch() { + ctx := context.Background() + c, err := compute.NewUrlMapsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.PatchUrlMapRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Patch(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleUrlMapsClient_Update() { + ctx := context.Background() + c, err := compute.NewUrlMapsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.UpdateUrlMapRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Update(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleUrlMapsClient_Validate() { + ctx := context.Background() + c, err := compute.NewUrlMapsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.ValidateUrlMapRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Validate(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} diff --git a/compute/apiv1/vpn_gateways_client.go b/compute/apiv1/vpn_gateways_client.go new file mode 100644 index 00000000000..80eb318a484 --- /dev/null +++ b/compute/apiv1/vpn_gateways_client.go @@ -0,0 +1,611 @@ +// 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 compute + +import ( + "bytes" + "context" + "fmt" + "io/ioutil" + "net/http" + "net/url" + + gax "github.com/googleapis/gax-go/v2" + "google.golang.org/api/option" + "google.golang.org/api/option/internaloption" + httptransport "google.golang.org/api/transport/http" + computepb "google.golang.org/genproto/googleapis/cloud/compute/v1" + "google.golang.org/grpc" + "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/encoding/protojson" +) + +var newVpnGatewaysClientHook clientHook + +// VpnGatewaysCallOptions contains the retry settings for each method of VpnGatewaysClient. +type VpnGatewaysCallOptions struct { + AggregatedList []gax.CallOption + Delete []gax.CallOption + Get []gax.CallOption + GetStatus []gax.CallOption + Insert []gax.CallOption + List []gax.CallOption + SetLabels []gax.CallOption + TestIamPermissions []gax.CallOption +} + +// internalVpnGatewaysClient is an interface that defines the methods availaible from Google Compute Engine API. +type internalVpnGatewaysClient interface { + Close() error + setGoogleClientInfo(...string) + Connection() *grpc.ClientConn + AggregatedList(context.Context, *computepb.AggregatedListVpnGatewaysRequest, ...gax.CallOption) (*computepb.VpnGatewayAggregatedList, error) + Delete(context.Context, *computepb.DeleteVpnGatewayRequest, ...gax.CallOption) (*computepb.Operation, error) + Get(context.Context, *computepb.GetVpnGatewayRequest, ...gax.CallOption) (*computepb.VpnGateway, error) + GetStatus(context.Context, *computepb.GetStatusVpnGatewayRequest, ...gax.CallOption) (*computepb.VpnGatewaysGetStatusResponse, error) + Insert(context.Context, *computepb.InsertVpnGatewayRequest, ...gax.CallOption) (*computepb.Operation, error) + List(context.Context, *computepb.ListVpnGatewaysRequest, ...gax.CallOption) (*computepb.VpnGatewayList, error) + SetLabels(context.Context, *computepb.SetLabelsVpnGatewayRequest, ...gax.CallOption) (*computepb.Operation, error) + TestIamPermissions(context.Context, *computepb.TestIamPermissionsVpnGatewayRequest, ...gax.CallOption) (*computepb.TestPermissionsResponse, error) +} + +// VpnGatewaysClient is a client for interacting with Google Compute Engine API. +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +// +// The VpnGateways API. +type VpnGatewaysClient struct { + // The internal transport-dependent client. + internalClient internalVpnGatewaysClient + + // The call options for this service. + CallOptions *VpnGatewaysCallOptions +} + +// 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 *VpnGatewaysClient) 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 *VpnGatewaysClient) setGoogleClientInfo(keyval ...string) { + c.internalClient.setGoogleClientInfo(keyval...) +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *VpnGatewaysClient) Connection() *grpc.ClientConn { + return c.internalClient.Connection() +} + +// AggregatedList retrieves an aggregated list of VPN gateways. +func (c *VpnGatewaysClient) AggregatedList(ctx context.Context, req *computepb.AggregatedListVpnGatewaysRequest, opts ...gax.CallOption) (*computepb.VpnGatewayAggregatedList, error) { + return c.internalClient.AggregatedList(ctx, req, opts...) +} + +// Delete deletes the specified VPN gateway. +func (c *VpnGatewaysClient) Delete(ctx context.Context, req *computepb.DeleteVpnGatewayRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.Delete(ctx, req, opts...) +} + +// Get returns the specified VPN gateway. Gets a list of available VPN gateways by making a list() request. +func (c *VpnGatewaysClient) Get(ctx context.Context, req *computepb.GetVpnGatewayRequest, opts ...gax.CallOption) (*computepb.VpnGateway, error) { + return c.internalClient.Get(ctx, req, opts...) +} + +// GetStatus returns the status for the specified VPN gateway. +func (c *VpnGatewaysClient) GetStatus(ctx context.Context, req *computepb.GetStatusVpnGatewayRequest, opts ...gax.CallOption) (*computepb.VpnGatewaysGetStatusResponse, error) { + return c.internalClient.GetStatus(ctx, req, opts...) +} + +// Insert creates a VPN gateway in the specified project and region using the data included in the request. +func (c *VpnGatewaysClient) Insert(ctx context.Context, req *computepb.InsertVpnGatewayRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.Insert(ctx, req, opts...) +} + +// List retrieves a list of VPN gateways available to the specified project and region. +func (c *VpnGatewaysClient) List(ctx context.Context, req *computepb.ListVpnGatewaysRequest, opts ...gax.CallOption) (*computepb.VpnGatewayList, error) { + return c.internalClient.List(ctx, req, opts...) +} + +// SetLabels sets the labels on a VpnGateway. To learn more about labels, read the Labeling Resources documentation. +func (c *VpnGatewaysClient) SetLabels(ctx context.Context, req *computepb.SetLabelsVpnGatewayRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.SetLabels(ctx, req, opts...) +} + +// TestIamPermissions returns permissions that a caller has on the specified resource. +func (c *VpnGatewaysClient) TestIamPermissions(ctx context.Context, req *computepb.TestIamPermissionsVpnGatewayRequest, opts ...gax.CallOption) (*computepb.TestPermissionsResponse, error) { + return c.internalClient.TestIamPermissions(ctx, req, opts...) +} + +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +type vpnGatewaysRESTClient struct { + // The http endpoint to connect to. + endpoint string + + // The http client. + httpClient *http.Client + + // The x-goog-* metadata to be sent with each request. + xGoogMetadata metadata.MD +} + +// NewVpnGatewaysRESTClient creates a new vpn gateways rest client. +// +// The VpnGateways API. +func NewVpnGatewaysRESTClient(ctx context.Context, opts ...option.ClientOption) (*VpnGatewaysClient, error) { + clientOpts := append(defaultVpnGatewaysRESTClientOptions(), opts...) + httpClient, endpoint, err := httptransport.NewClient(ctx, clientOpts...) + if err != nil { + return nil, err + } + + c := &vpnGatewaysRESTClient{ + endpoint: endpoint, + httpClient: httpClient, + } + c.setGoogleClientInfo() + + return &VpnGatewaysClient{internalClient: c, CallOptions: &VpnGatewaysCallOptions{}}, nil +} + +func defaultVpnGatewaysRESTClientOptions() []option.ClientOption { + return []option.ClientOption{ + internaloption.WithDefaultEndpoint("compute.googleapis.com"), + internaloption.WithDefaultMTLSEndpoint("compute.mtls.googleapis.com"), + internaloption.WithDefaultAudience("https://compute.googleapis.com/"), + internaloption.WithDefaultScopes(DefaultAuthScopes()...), + } +} + +// 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 *vpnGatewaysRESTClient) setGoogleClientInfo(keyval ...string) { + kv := append([]string{"gl-go", versionGo()}, keyval...) + kv = append(kv, "gapic", versionClient, "gax", gax.Version, "rest", "UNKNOWN") + 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 *vpnGatewaysRESTClient) Close() error { + // Replace httpClient with nil to force cleanup. + c.httpClient = nil + return nil +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *vpnGatewaysRESTClient) Connection() *grpc.ClientConn { + return nil +} + +// AggregatedList retrieves an aggregated list of VPN gateways. +func (c *vpnGatewaysRESTClient) AggregatedList(ctx context.Context, req *computepb.AggregatedListVpnGatewaysRequest, opts ...gax.CallOption) (*computepb.VpnGatewayAggregatedList, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/aggregated/vpnGateways", req.GetProject()) + + params := url.Values{} + if req != nil && req.Filter != nil { + params.Add("filter", fmt.Sprintf("%v", req.GetFilter())) + } + if req != nil && req.IncludeAllScopes != nil { + params.Add("includeAllScopes", fmt.Sprintf("%v", req.GetIncludeAllScopes())) + } + if req != nil && req.MaxResults != nil { + params.Add("maxResults", fmt.Sprintf("%v", req.GetMaxResults())) + } + if req != nil && req.OrderBy != nil { + params.Add("orderBy", fmt.Sprintf("%v", req.GetOrderBy())) + } + if req != nil && req.PageToken != nil { + params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) + } + if req != nil && req.ReturnPartialSuccess != nil { + params.Add("returnPartialSuccess", fmt.Sprintf("%v", req.GetReturnPartialSuccess())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.VpnGatewayAggregatedList{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Delete deletes the specified VPN gateway. +func (c *vpnGatewaysRESTClient) Delete(ctx context.Context, req *computepb.DeleteVpnGatewayRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/regions/%v/vpnGateways/%v", req.GetProject(), req.GetRegion(), req.GetVpnGateway()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("DELETE", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Get returns the specified VPN gateway. Gets a list of available VPN gateways by making a list() request. +func (c *vpnGatewaysRESTClient) Get(ctx context.Context, req *computepb.GetVpnGatewayRequest, opts ...gax.CallOption) (*computepb.VpnGateway, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/regions/%v/vpnGateways/%v", req.GetProject(), req.GetRegion(), req.GetVpnGateway()) + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.VpnGateway{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// GetStatus returns the status for the specified VPN gateway. +func (c *vpnGatewaysRESTClient) GetStatus(ctx context.Context, req *computepb.GetStatusVpnGatewayRequest, opts ...gax.CallOption) (*computepb.VpnGatewaysGetStatusResponse, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/regions/%v/vpnGateways/%v/getStatus", req.GetProject(), req.GetRegion(), req.GetVpnGateway()) + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.VpnGatewaysGetStatusResponse{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Insert creates a VPN gateway in the specified project and region using the data included in the request. +func (c *vpnGatewaysRESTClient) Insert(ctx context.Context, req *computepb.InsertVpnGatewayRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetVpnGatewayResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/regions/%v/vpnGateways", req.GetProject(), req.GetRegion()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// List retrieves a list of VPN gateways available to the specified project and region. +func (c *vpnGatewaysRESTClient) List(ctx context.Context, req *computepb.ListVpnGatewaysRequest, opts ...gax.CallOption) (*computepb.VpnGatewayList, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/regions/%v/vpnGateways", req.GetProject(), req.GetRegion()) + + params := url.Values{} + if req != nil && req.Filter != nil { + params.Add("filter", fmt.Sprintf("%v", req.GetFilter())) + } + if req != nil && req.MaxResults != nil { + params.Add("maxResults", fmt.Sprintf("%v", req.GetMaxResults())) + } + if req != nil && req.OrderBy != nil { + params.Add("orderBy", fmt.Sprintf("%v", req.GetOrderBy())) + } + if req != nil && req.PageToken != nil { + params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) + } + if req != nil && req.ReturnPartialSuccess != nil { + params.Add("returnPartialSuccess", fmt.Sprintf("%v", req.GetReturnPartialSuccess())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.VpnGatewayList{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// SetLabels sets the labels on a VpnGateway. To learn more about labels, read the Labeling Resources documentation. +func (c *vpnGatewaysRESTClient) SetLabels(ctx context.Context, req *computepb.SetLabelsVpnGatewayRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetRegionSetLabelsRequestResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/regions/%v/vpnGateways/%v/setLabels", req.GetProject(), req.GetRegion(), req.GetResource()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// TestIamPermissions returns permissions that a caller has on the specified resource. +func (c *vpnGatewaysRESTClient) TestIamPermissions(ctx context.Context, req *computepb.TestIamPermissionsVpnGatewayRequest, opts ...gax.CallOption) (*computepb.TestPermissionsResponse, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetTestPermissionsRequestResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/regions/%v/vpnGateways/%v/testIamPermissions", req.GetProject(), req.GetRegion(), req.GetResource()) + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.TestPermissionsResponse{} + + return rsp, unm.Unmarshal(buf, rsp) +} diff --git a/compute/apiv1/vpn_gateways_client_example_test.go b/compute/apiv1/vpn_gateways_client_example_test.go new file mode 100644 index 00000000000..74b8ecf2f1a --- /dev/null +++ b/compute/apiv1/vpn_gateways_client_example_test.go @@ -0,0 +1,188 @@ +// 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 compute_test + +import ( + "context" + + compute "cloud.google.com/go/compute/apiv1" + computepb "google.golang.org/genproto/googleapis/cloud/compute/v1" +) + +func ExampleNewVpnGatewaysRESTClient() { + ctx := context.Background() + c, err := compute.NewVpnGatewaysRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + // TODO: Use client. + _ = c +} + +func ExampleVpnGatewaysClient_AggregatedList() { + ctx := context.Background() + c, err := compute.NewVpnGatewaysRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.AggregatedListVpnGatewaysRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.AggregatedList(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleVpnGatewaysClient_Delete() { + ctx := context.Background() + c, err := compute.NewVpnGatewaysRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.DeleteVpnGatewayRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Delete(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleVpnGatewaysClient_Get() { + ctx := context.Background() + c, err := compute.NewVpnGatewaysRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.GetVpnGatewayRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Get(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleVpnGatewaysClient_GetStatus() { + ctx := context.Background() + c, err := compute.NewVpnGatewaysRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.GetStatusVpnGatewayRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.GetStatus(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleVpnGatewaysClient_Insert() { + ctx := context.Background() + c, err := compute.NewVpnGatewaysRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.InsertVpnGatewayRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Insert(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleVpnGatewaysClient_List() { + ctx := context.Background() + c, err := compute.NewVpnGatewaysRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.ListVpnGatewaysRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.List(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleVpnGatewaysClient_SetLabels() { + ctx := context.Background() + c, err := compute.NewVpnGatewaysRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.SetLabelsVpnGatewayRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.SetLabels(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleVpnGatewaysClient_TestIamPermissions() { + ctx := context.Background() + c, err := compute.NewVpnGatewaysRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.TestIamPermissionsVpnGatewayRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.TestIamPermissions(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} diff --git a/compute/apiv1/vpn_tunnels_client.go b/compute/apiv1/vpn_tunnels_client.go new file mode 100644 index 00000000000..718d75406b2 --- /dev/null +++ b/compute/apiv1/vpn_tunnels_client.go @@ -0,0 +1,452 @@ +// 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 compute + +import ( + "bytes" + "context" + "fmt" + "io/ioutil" + "net/http" + "net/url" + + gax "github.com/googleapis/gax-go/v2" + "google.golang.org/api/option" + "google.golang.org/api/option/internaloption" + httptransport "google.golang.org/api/transport/http" + computepb "google.golang.org/genproto/googleapis/cloud/compute/v1" + "google.golang.org/grpc" + "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/encoding/protojson" +) + +var newVpnTunnelsClientHook clientHook + +// VpnTunnelsCallOptions contains the retry settings for each method of VpnTunnelsClient. +type VpnTunnelsCallOptions struct { + AggregatedList []gax.CallOption + Delete []gax.CallOption + Get []gax.CallOption + Insert []gax.CallOption + List []gax.CallOption +} + +// internalVpnTunnelsClient is an interface that defines the methods availaible from Google Compute Engine API. +type internalVpnTunnelsClient interface { + Close() error + setGoogleClientInfo(...string) + Connection() *grpc.ClientConn + AggregatedList(context.Context, *computepb.AggregatedListVpnTunnelsRequest, ...gax.CallOption) (*computepb.VpnTunnelAggregatedList, error) + Delete(context.Context, *computepb.DeleteVpnTunnelRequest, ...gax.CallOption) (*computepb.Operation, error) + Get(context.Context, *computepb.GetVpnTunnelRequest, ...gax.CallOption) (*computepb.VpnTunnel, error) + Insert(context.Context, *computepb.InsertVpnTunnelRequest, ...gax.CallOption) (*computepb.Operation, error) + List(context.Context, *computepb.ListVpnTunnelsRequest, ...gax.CallOption) (*computepb.VpnTunnelList, error) +} + +// VpnTunnelsClient is a client for interacting with Google Compute Engine API. +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +// +// The VpnTunnels API. +type VpnTunnelsClient struct { + // The internal transport-dependent client. + internalClient internalVpnTunnelsClient + + // The call options for this service. + CallOptions *VpnTunnelsCallOptions +} + +// 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 *VpnTunnelsClient) 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 *VpnTunnelsClient) setGoogleClientInfo(keyval ...string) { + c.internalClient.setGoogleClientInfo(keyval...) +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *VpnTunnelsClient) Connection() *grpc.ClientConn { + return c.internalClient.Connection() +} + +// AggregatedList retrieves an aggregated list of VPN tunnels. +func (c *VpnTunnelsClient) AggregatedList(ctx context.Context, req *computepb.AggregatedListVpnTunnelsRequest, opts ...gax.CallOption) (*computepb.VpnTunnelAggregatedList, error) { + return c.internalClient.AggregatedList(ctx, req, opts...) +} + +// Delete deletes the specified VpnTunnel resource. +func (c *VpnTunnelsClient) Delete(ctx context.Context, req *computepb.DeleteVpnTunnelRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.Delete(ctx, req, opts...) +} + +// Get returns the specified VpnTunnel resource. Gets a list of available VPN tunnels by making a list() request. +func (c *VpnTunnelsClient) Get(ctx context.Context, req *computepb.GetVpnTunnelRequest, opts ...gax.CallOption) (*computepb.VpnTunnel, error) { + return c.internalClient.Get(ctx, req, opts...) +} + +// Insert creates a VpnTunnel resource in the specified project and region using the data included in the request. +func (c *VpnTunnelsClient) Insert(ctx context.Context, req *computepb.InsertVpnTunnelRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.Insert(ctx, req, opts...) +} + +// List retrieves a list of VpnTunnel resources contained in the specified project and region. +func (c *VpnTunnelsClient) List(ctx context.Context, req *computepb.ListVpnTunnelsRequest, opts ...gax.CallOption) (*computepb.VpnTunnelList, error) { + return c.internalClient.List(ctx, req, opts...) +} + +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +type vpnTunnelsRESTClient struct { + // The http endpoint to connect to. + endpoint string + + // The http client. + httpClient *http.Client + + // The x-goog-* metadata to be sent with each request. + xGoogMetadata metadata.MD +} + +// NewVpnTunnelsRESTClient creates a new vpn tunnels rest client. +// +// The VpnTunnels API. +func NewVpnTunnelsRESTClient(ctx context.Context, opts ...option.ClientOption) (*VpnTunnelsClient, error) { + clientOpts := append(defaultVpnTunnelsRESTClientOptions(), opts...) + httpClient, endpoint, err := httptransport.NewClient(ctx, clientOpts...) + if err != nil { + return nil, err + } + + c := &vpnTunnelsRESTClient{ + endpoint: endpoint, + httpClient: httpClient, + } + c.setGoogleClientInfo() + + return &VpnTunnelsClient{internalClient: c, CallOptions: &VpnTunnelsCallOptions{}}, nil +} + +func defaultVpnTunnelsRESTClientOptions() []option.ClientOption { + return []option.ClientOption{ + internaloption.WithDefaultEndpoint("compute.googleapis.com"), + internaloption.WithDefaultMTLSEndpoint("compute.mtls.googleapis.com"), + internaloption.WithDefaultAudience("https://compute.googleapis.com/"), + internaloption.WithDefaultScopes(DefaultAuthScopes()...), + } +} + +// 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 *vpnTunnelsRESTClient) setGoogleClientInfo(keyval ...string) { + kv := append([]string{"gl-go", versionGo()}, keyval...) + kv = append(kv, "gapic", versionClient, "gax", gax.Version, "rest", "UNKNOWN") + 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 *vpnTunnelsRESTClient) Close() error { + // Replace httpClient with nil to force cleanup. + c.httpClient = nil + return nil +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *vpnTunnelsRESTClient) Connection() *grpc.ClientConn { + return nil +} + +// AggregatedList retrieves an aggregated list of VPN tunnels. +func (c *vpnTunnelsRESTClient) AggregatedList(ctx context.Context, req *computepb.AggregatedListVpnTunnelsRequest, opts ...gax.CallOption) (*computepb.VpnTunnelAggregatedList, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/aggregated/vpnTunnels", req.GetProject()) + + params := url.Values{} + if req != nil && req.Filter != nil { + params.Add("filter", fmt.Sprintf("%v", req.GetFilter())) + } + if req != nil && req.IncludeAllScopes != nil { + params.Add("includeAllScopes", fmt.Sprintf("%v", req.GetIncludeAllScopes())) + } + if req != nil && req.MaxResults != nil { + params.Add("maxResults", fmt.Sprintf("%v", req.GetMaxResults())) + } + if req != nil && req.OrderBy != nil { + params.Add("orderBy", fmt.Sprintf("%v", req.GetOrderBy())) + } + if req != nil && req.PageToken != nil { + params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) + } + if req != nil && req.ReturnPartialSuccess != nil { + params.Add("returnPartialSuccess", fmt.Sprintf("%v", req.GetReturnPartialSuccess())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.VpnTunnelAggregatedList{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Delete deletes the specified VpnTunnel resource. +func (c *vpnTunnelsRESTClient) Delete(ctx context.Context, req *computepb.DeleteVpnTunnelRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/regions/%v/vpnTunnels/%v", req.GetProject(), req.GetRegion(), req.GetVpnTunnel()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("DELETE", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Get returns the specified VpnTunnel resource. Gets a list of available VPN tunnels by making a list() request. +func (c *vpnTunnelsRESTClient) Get(ctx context.Context, req *computepb.GetVpnTunnelRequest, opts ...gax.CallOption) (*computepb.VpnTunnel, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/regions/%v/vpnTunnels/%v", req.GetProject(), req.GetRegion(), req.GetVpnTunnel()) + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.VpnTunnel{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Insert creates a VpnTunnel resource in the specified project and region using the data included in the request. +func (c *vpnTunnelsRESTClient) Insert(ctx context.Context, req *computepb.InsertVpnTunnelRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + body := req.GetVpnTunnelResource() + jsonReq, err := m.Marshal(body) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/regions/%v/vpnTunnels", req.GetProject(), req.GetRegion()) + + params := url.Values{} + if req != nil && req.RequestId != nil { + params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// List retrieves a list of VpnTunnel resources contained in the specified project and region. +func (c *vpnTunnelsRESTClient) List(ctx context.Context, req *computepb.ListVpnTunnelsRequest, opts ...gax.CallOption) (*computepb.VpnTunnelList, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/regions/%v/vpnTunnels", req.GetProject(), req.GetRegion()) + + params := url.Values{} + if req != nil && req.Filter != nil { + params.Add("filter", fmt.Sprintf("%v", req.GetFilter())) + } + if req != nil && req.MaxResults != nil { + params.Add("maxResults", fmt.Sprintf("%v", req.GetMaxResults())) + } + if req != nil && req.OrderBy != nil { + params.Add("orderBy", fmt.Sprintf("%v", req.GetOrderBy())) + } + if req != nil && req.PageToken != nil { + params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) + } + if req != nil && req.ReturnPartialSuccess != nil { + params.Add("returnPartialSuccess", fmt.Sprintf("%v", req.GetReturnPartialSuccess())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.VpnTunnelList{} + + return rsp, unm.Unmarshal(buf, rsp) +} diff --git a/compute/apiv1/vpn_tunnels_client_example_test.go b/compute/apiv1/vpn_tunnels_client_example_test.go new file mode 100644 index 00000000000..d5354e683ee --- /dev/null +++ b/compute/apiv1/vpn_tunnels_client_example_test.go @@ -0,0 +1,131 @@ +// 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 compute_test + +import ( + "context" + + compute "cloud.google.com/go/compute/apiv1" + computepb "google.golang.org/genproto/googleapis/cloud/compute/v1" +) + +func ExampleNewVpnTunnelsRESTClient() { + ctx := context.Background() + c, err := compute.NewVpnTunnelsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + // TODO: Use client. + _ = c +} + +func ExampleVpnTunnelsClient_AggregatedList() { + ctx := context.Background() + c, err := compute.NewVpnTunnelsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.AggregatedListVpnTunnelsRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.AggregatedList(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleVpnTunnelsClient_Delete() { + ctx := context.Background() + c, err := compute.NewVpnTunnelsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.DeleteVpnTunnelRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Delete(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleVpnTunnelsClient_Get() { + ctx := context.Background() + c, err := compute.NewVpnTunnelsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.GetVpnTunnelRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Get(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleVpnTunnelsClient_Insert() { + ctx := context.Background() + c, err := compute.NewVpnTunnelsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.InsertVpnTunnelRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Insert(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleVpnTunnelsClient_List() { + ctx := context.Background() + c, err := compute.NewVpnTunnelsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.ListVpnTunnelsRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.List(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} diff --git a/compute/apiv1/zone_operations_client.go b/compute/apiv1/zone_operations_client.go new file mode 100644 index 00000000000..e77c5b33300 --- /dev/null +++ b/compute/apiv1/zone_operations_client.go @@ -0,0 +1,377 @@ +// 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 compute + +import ( + "bytes" + "context" + "fmt" + "io/ioutil" + "net/http" + "net/url" + + gax "github.com/googleapis/gax-go/v2" + "google.golang.org/api/option" + "google.golang.org/api/option/internaloption" + httptransport "google.golang.org/api/transport/http" + computepb "google.golang.org/genproto/googleapis/cloud/compute/v1" + "google.golang.org/grpc" + "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/encoding/protojson" +) + +var newZoneOperationsClientHook clientHook + +// ZoneOperationsCallOptions contains the retry settings for each method of ZoneOperationsClient. +type ZoneOperationsCallOptions struct { + Delete []gax.CallOption + Get []gax.CallOption + List []gax.CallOption + Wait []gax.CallOption +} + +// internalZoneOperationsClient is an interface that defines the methods availaible from Google Compute Engine API. +type internalZoneOperationsClient interface { + Close() error + setGoogleClientInfo(...string) + Connection() *grpc.ClientConn + Delete(context.Context, *computepb.DeleteZoneOperationRequest, ...gax.CallOption) (*computepb.DeleteZoneOperationResponse, error) + Get(context.Context, *computepb.GetZoneOperationRequest, ...gax.CallOption) (*computepb.Operation, error) + List(context.Context, *computepb.ListZoneOperationsRequest, ...gax.CallOption) (*computepb.OperationList, error) + Wait(context.Context, *computepb.WaitZoneOperationRequest, ...gax.CallOption) (*computepb.Operation, error) +} + +// ZoneOperationsClient is a client for interacting with Google Compute Engine API. +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +// +// The ZoneOperations API. +type ZoneOperationsClient struct { + // The internal transport-dependent client. + internalClient internalZoneOperationsClient + + // The call options for this service. + CallOptions *ZoneOperationsCallOptions +} + +// 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 *ZoneOperationsClient) 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 *ZoneOperationsClient) setGoogleClientInfo(keyval ...string) { + c.internalClient.setGoogleClientInfo(keyval...) +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *ZoneOperationsClient) Connection() *grpc.ClientConn { + return c.internalClient.Connection() +} + +// Delete deletes the specified zone-specific Operations resource. +func (c *ZoneOperationsClient) Delete(ctx context.Context, req *computepb.DeleteZoneOperationRequest, opts ...gax.CallOption) (*computepb.DeleteZoneOperationResponse, error) { + return c.internalClient.Delete(ctx, req, opts...) +} + +// Get retrieves the specified zone-specific Operations resource. +func (c *ZoneOperationsClient) Get(ctx context.Context, req *computepb.GetZoneOperationRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.Get(ctx, req, opts...) +} + +// List retrieves a list of Operation resources contained within the specified zone. +func (c *ZoneOperationsClient) List(ctx context.Context, req *computepb.ListZoneOperationsRequest, opts ...gax.CallOption) (*computepb.OperationList, error) { + return c.internalClient.List(ctx, req, opts...) +} + +// Wait waits for the specified Operation resource to return as DONE or for the request to approach the 2 minute deadline, and retrieves the specified Operation resource. This method differs from the GET method in that it waits for no more than the default deadline (2 minutes) and then returns the current state of the operation, which might be DONE or still in progress. +// +// This method is called on a best-effort basis. Specifically: +// +// In uncommon cases, when the server is overloaded, the request might return before the default deadline is reached, or might return after zero seconds. +// +// If the default deadline is reached, there is no guarantee that the operation is actually done when the method returns. Be prepared to retry if the operation is not DONE. +func (c *ZoneOperationsClient) Wait(ctx context.Context, req *computepb.WaitZoneOperationRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + return c.internalClient.Wait(ctx, req, opts...) +} + +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +type zoneOperationsRESTClient struct { + // The http endpoint to connect to. + endpoint string + + // The http client. + httpClient *http.Client + + // The x-goog-* metadata to be sent with each request. + xGoogMetadata metadata.MD +} + +// NewZoneOperationsRESTClient creates a new zone operations rest client. +// +// The ZoneOperations API. +func NewZoneOperationsRESTClient(ctx context.Context, opts ...option.ClientOption) (*ZoneOperationsClient, error) { + clientOpts := append(defaultZoneOperationsRESTClientOptions(), opts...) + httpClient, endpoint, err := httptransport.NewClient(ctx, clientOpts...) + if err != nil { + return nil, err + } + + c := &zoneOperationsRESTClient{ + endpoint: endpoint, + httpClient: httpClient, + } + c.setGoogleClientInfo() + + return &ZoneOperationsClient{internalClient: c, CallOptions: &ZoneOperationsCallOptions{}}, nil +} + +func defaultZoneOperationsRESTClientOptions() []option.ClientOption { + return []option.ClientOption{ + internaloption.WithDefaultEndpoint("compute.googleapis.com"), + internaloption.WithDefaultMTLSEndpoint("compute.mtls.googleapis.com"), + internaloption.WithDefaultAudience("https://compute.googleapis.com/"), + internaloption.WithDefaultScopes(DefaultAuthScopes()...), + } +} + +// 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 *zoneOperationsRESTClient) setGoogleClientInfo(keyval ...string) { + kv := append([]string{"gl-go", versionGo()}, keyval...) + kv = append(kv, "gapic", versionClient, "gax", gax.Version, "rest", "UNKNOWN") + 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 *zoneOperationsRESTClient) Close() error { + // Replace httpClient with nil to force cleanup. + c.httpClient = nil + return nil +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *zoneOperationsRESTClient) Connection() *grpc.ClientConn { + return nil +} + +// Delete deletes the specified zone-specific Operations resource. +func (c *zoneOperationsRESTClient) Delete(ctx context.Context, req *computepb.DeleteZoneOperationRequest, opts ...gax.CallOption) (*computepb.DeleteZoneOperationResponse, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/zones/%v/operations/%v", req.GetProject(), req.GetZone(), req.GetOperation()) + + httpReq, err := http.NewRequest("DELETE", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.DeleteZoneOperationResponse{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Get retrieves the specified zone-specific Operations resource. +func (c *zoneOperationsRESTClient) Get(ctx context.Context, req *computepb.GetZoneOperationRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/zones/%v/operations/%v", req.GetProject(), req.GetZone(), req.GetOperation()) + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// List retrieves a list of Operation resources contained within the specified zone. +func (c *zoneOperationsRESTClient) List(ctx context.Context, req *computepb.ListZoneOperationsRequest, opts ...gax.CallOption) (*computepb.OperationList, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/zones/%v/operations", req.GetProject(), req.GetZone()) + + params := url.Values{} + if req != nil && req.Filter != nil { + params.Add("filter", fmt.Sprintf("%v", req.GetFilter())) + } + if req != nil && req.MaxResults != nil { + params.Add("maxResults", fmt.Sprintf("%v", req.GetMaxResults())) + } + if req != nil && req.OrderBy != nil { + params.Add("orderBy", fmt.Sprintf("%v", req.GetOrderBy())) + } + if req != nil && req.PageToken != nil { + params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) + } + if req != nil && req.ReturnPartialSuccess != nil { + params.Add("returnPartialSuccess", fmt.Sprintf("%v", req.GetReturnPartialSuccess())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.OperationList{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// Wait waits for the specified Operation resource to return as DONE or for the request to approach the 2 minute deadline, and retrieves the specified Operation resource. This method differs from the GET method in that it waits for no more than the default deadline (2 minutes) and then returns the current state of the operation, which might be DONE or still in progress. +// +// This method is called on a best-effort basis. Specifically: +// +// In uncommon cases, when the server is overloaded, the request might return before the default deadline is reached, or might return after zero seconds. +// +// If the default deadline is reached, there is no guarantee that the operation is actually done when the method returns. Be prepared to retry if the operation is not DONE. +func (c *zoneOperationsRESTClient) Wait(ctx context.Context, req *computepb.WaitZoneOperationRequest, opts ...gax.CallOption) (*computepb.Operation, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/zones/%v/operations/%v/wait", req.GetProject(), req.GetZone(), req.GetOperation()) + + httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Operation{} + + return rsp, unm.Unmarshal(buf, rsp) +} diff --git a/compute/apiv1/zone_operations_client_example_test.go b/compute/apiv1/zone_operations_client_example_test.go new file mode 100644 index 00000000000..f7f1c346c63 --- /dev/null +++ b/compute/apiv1/zone_operations_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 compute_test + +import ( + "context" + + compute "cloud.google.com/go/compute/apiv1" + computepb "google.golang.org/genproto/googleapis/cloud/compute/v1" +) + +func ExampleNewZoneOperationsRESTClient() { + ctx := context.Background() + c, err := compute.NewZoneOperationsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + // TODO: Use client. + _ = c +} + +func ExampleZoneOperationsClient_Delete() { + ctx := context.Background() + c, err := compute.NewZoneOperationsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.DeleteZoneOperationRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Delete(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleZoneOperationsClient_Get() { + ctx := context.Background() + c, err := compute.NewZoneOperationsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.GetZoneOperationRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Get(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleZoneOperationsClient_List() { + ctx := context.Background() + c, err := compute.NewZoneOperationsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.ListZoneOperationsRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.List(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleZoneOperationsClient_Wait() { + ctx := context.Background() + c, err := compute.NewZoneOperationsRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.WaitZoneOperationRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Wait(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} diff --git a/compute/apiv1/zones_client.go b/compute/apiv1/zones_client.go new file mode 100644 index 00000000000..bc02f75e4b6 --- /dev/null +++ b/compute/apiv1/zones_client.go @@ -0,0 +1,265 @@ +// 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 compute + +import ( + "bytes" + "context" + "fmt" + "io/ioutil" + "net/http" + "net/url" + + gax "github.com/googleapis/gax-go/v2" + "google.golang.org/api/option" + "google.golang.org/api/option/internaloption" + httptransport "google.golang.org/api/transport/http" + computepb "google.golang.org/genproto/googleapis/cloud/compute/v1" + "google.golang.org/grpc" + "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/encoding/protojson" +) + +var newZonesClientHook clientHook + +// ZonesCallOptions contains the retry settings for each method of ZonesClient. +type ZonesCallOptions struct { + Get []gax.CallOption + List []gax.CallOption +} + +// internalZonesClient is an interface that defines the methods availaible from Google Compute Engine API. +type internalZonesClient interface { + Close() error + setGoogleClientInfo(...string) + Connection() *grpc.ClientConn + Get(context.Context, *computepb.GetZoneRequest, ...gax.CallOption) (*computepb.Zone, error) + List(context.Context, *computepb.ListZonesRequest, ...gax.CallOption) (*computepb.ZoneList, error) +} + +// ZonesClient is a client for interacting with Google Compute Engine API. +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +// +// The Zones API. +type ZonesClient struct { + // The internal transport-dependent client. + internalClient internalZonesClient + + // The call options for this service. + CallOptions *ZonesCallOptions +} + +// 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 *ZonesClient) 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 *ZonesClient) setGoogleClientInfo(keyval ...string) { + c.internalClient.setGoogleClientInfo(keyval...) +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *ZonesClient) Connection() *grpc.ClientConn { + return c.internalClient.Connection() +} + +// Get returns the specified Zone resource. Gets a list of available zones by making a list() request. +func (c *ZonesClient) Get(ctx context.Context, req *computepb.GetZoneRequest, opts ...gax.CallOption) (*computepb.Zone, error) { + return c.internalClient.Get(ctx, req, opts...) +} + +// List retrieves the list of Zone resources available to the specified project. +func (c *ZonesClient) List(ctx context.Context, req *computepb.ListZonesRequest, opts ...gax.CallOption) (*computepb.ZoneList, error) { + return c.internalClient.List(ctx, req, opts...) +} + +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +type zonesRESTClient struct { + // The http endpoint to connect to. + endpoint string + + // The http client. + httpClient *http.Client + + // The x-goog-* metadata to be sent with each request. + xGoogMetadata metadata.MD +} + +// NewZonesRESTClient creates a new zones rest client. +// +// The Zones API. +func NewZonesRESTClient(ctx context.Context, opts ...option.ClientOption) (*ZonesClient, error) { + clientOpts := append(defaultZonesRESTClientOptions(), opts...) + httpClient, endpoint, err := httptransport.NewClient(ctx, clientOpts...) + if err != nil { + return nil, err + } + + c := &zonesRESTClient{ + endpoint: endpoint, + httpClient: httpClient, + } + c.setGoogleClientInfo() + + return &ZonesClient{internalClient: c, CallOptions: &ZonesCallOptions{}}, nil +} + +func defaultZonesRESTClientOptions() []option.ClientOption { + return []option.ClientOption{ + internaloption.WithDefaultEndpoint("compute.googleapis.com"), + internaloption.WithDefaultMTLSEndpoint("compute.mtls.googleapis.com"), + internaloption.WithDefaultAudience("https://compute.googleapis.com/"), + internaloption.WithDefaultScopes(DefaultAuthScopes()...), + } +} + +// 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 *zonesRESTClient) setGoogleClientInfo(keyval ...string) { + kv := append([]string{"gl-go", versionGo()}, keyval...) + kv = append(kv, "gapic", versionClient, "gax", gax.Version, "rest", "UNKNOWN") + 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 *zonesRESTClient) Close() error { + // Replace httpClient with nil to force cleanup. + c.httpClient = nil + return nil +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *zonesRESTClient) Connection() *grpc.ClientConn { + return nil +} + +// Get returns the specified Zone resource. Gets a list of available zones by making a list() request. +func (c *zonesRESTClient) Get(ctx context.Context, req *computepb.GetZoneRequest, opts ...gax.CallOption) (*computepb.Zone, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/zones/%v", req.GetProject(), req.GetZone()) + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.Zone{} + + return rsp, unm.Unmarshal(buf, rsp) +} + +// List retrieves the list of Zone resources available to the specified project. +func (c *zonesRESTClient) List(ctx context.Context, req *computepb.ListZonesRequest, opts ...gax.CallOption) (*computepb.ZoneList, error) { + m := protojson.MarshalOptions{AllowPartial: true, EmitUnpopulated: true} + jsonReq, err := m.Marshal(req) + if err != nil { + return nil, err + } + + baseUrl, _ := url.Parse(c.endpoint) + baseUrl.Path += fmt.Sprintf("/compute/v1/projects/%v/zones", req.GetProject()) + + params := url.Values{} + if req != nil && req.Filter != nil { + params.Add("filter", fmt.Sprintf("%v", req.GetFilter())) + } + if req != nil && req.MaxResults != nil { + params.Add("maxResults", fmt.Sprintf("%v", req.GetMaxResults())) + } + if req != nil && req.OrderBy != nil { + params.Add("orderBy", fmt.Sprintf("%v", req.GetOrderBy())) + } + if req != nil && req.PageToken != nil { + params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) + } + if req != nil && req.ReturnPartialSuccess != nil { + params.Add("returnPartialSuccess", fmt.Sprintf("%v", req.GetReturnPartialSuccess())) + } + + baseUrl.RawQuery = params.Encode() + + httpReq, err := http.NewRequest("GET", baseUrl.String(), bytes.NewReader(jsonReq)) + if err != nil { + return nil, err + } + httpReq = httpReq.WithContext(ctx) + // Set the headers + for k, v := range c.xGoogMetadata { + httpReq.Header[k] = v + } + httpReq.Header["Content-Type"] = []string{"application/json"} + + httpRsp, err := c.httpClient.Do(httpReq) + if err != nil { + return nil, err + } + defer httpRsp.Body.Close() + + if httpRsp.StatusCode != http.StatusOK { + return nil, fmt.Errorf(httpRsp.Status) + } + + buf, err := ioutil.ReadAll(httpRsp.Body) + if err != nil { + return nil, err + } + + unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} + rsp := &computepb.ZoneList{} + + return rsp, unm.Unmarshal(buf, rsp) +} diff --git a/compute/apiv1/zones_client_example_test.go b/compute/apiv1/zones_client_example_test.go new file mode 100644 index 00000000000..109f4704bb8 --- /dev/null +++ b/compute/apiv1/zones_client_example_test.go @@ -0,0 +1,74 @@ +// 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 compute_test + +import ( + "context" + + compute "cloud.google.com/go/compute/apiv1" + computepb "google.golang.org/genproto/googleapis/cloud/compute/v1" +) + +func ExampleNewZonesRESTClient() { + ctx := context.Background() + c, err := compute.NewZonesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + // TODO: Use client. + _ = c +} + +func ExampleZonesClient_Get() { + ctx := context.Background() + c, err := compute.NewZonesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.GetZoneRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.Get(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleZonesClient_List() { + ctx := context.Background() + c, err := compute.NewZonesRESTClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &computepb.ListZonesRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.List(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} diff --git a/container/apiv1/cluster_manager_client.go b/container/apiv1/cluster_manager_client.go index 13661a6e97a..c922b2eb4d5 100644 --- a/container/apiv1/cluster_manager_client.go +++ b/container/apiv1/cluster_manager_client.go @@ -23,7 +23,6 @@ import ( "net/url" "time" - "github.com/golang/protobuf/proto" gax "github.com/googleapis/gax-go/v2" "google.golang.org/api/iterator" "google.golang.org/api/option" @@ -33,6 +32,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newClusterManagerClientHook clientHook @@ -79,6 +79,7 @@ func defaultClusterManagerGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("container.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://container.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/container/apiv1/doc.go b/container/apiv1/doc.go index 8cdaa2dd2e2..787945ededa 100644 --- a/container/apiv1/doc.go +++ b/container/apiv1/doc.go @@ -49,7 +49,7 @@ import ( type clientHookParams struct{} type clientHook func(context.Context, clientHookParams) ([]option.ClientOption, error) -const versionClient = "20210612" +const versionClient = "20210701" func insertMetadata(ctx context.Context, mds ...metadata.MD) context.Context { out, _ := metadata.FromOutgoingContext(ctx) diff --git a/containeranalysis/apiv1/doc.go b/containeranalysis/apiv1/doc.go index fdda05dcc3c..f1900dc7333 100644 --- a/containeranalysis/apiv1/doc.go +++ b/containeranalysis/apiv1/doc.go @@ -98,4 +98,4 @@ func versionGo() string { return "UNKNOWN" } -const versionClient = "20210612" +const versionClient = "20210624" diff --git a/containeranalysis/apiv1beta1/container_analysis_v1_beta1_client.go b/containeranalysis/apiv1beta1/container_analysis_v1_beta1_client.go index 8ebdfceb788..341abafb6c1 100644 --- a/containeranalysis/apiv1beta1/container_analysis_v1_beta1_client.go +++ b/containeranalysis/apiv1beta1/container_analysis_v1_beta1_client.go @@ -23,7 +23,6 @@ import ( "net/url" "time" - "github.com/golang/protobuf/proto" gax "github.com/googleapis/gax-go/v2" "google.golang.org/api/iterator" "google.golang.org/api/option" @@ -34,6 +33,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newContainerAnalysisV1Beta1ClientHook clientHook @@ -54,6 +54,7 @@ func defaultContainerAnalysisV1Beta1GRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("containeranalysis.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://containeranalysis.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/containeranalysis/apiv1beta1/doc.go b/containeranalysis/apiv1beta1/doc.go index 8bc91766f4b..0f7c7c8a773 100644 --- a/containeranalysis/apiv1beta1/doc.go +++ b/containeranalysis/apiv1beta1/doc.go @@ -51,7 +51,7 @@ import ( type clientHookParams struct{} type clientHook func(context.Context, clientHookParams) ([]option.ClientOption, error) -const versionClient = "20210612" +const versionClient = "20210701" func insertMetadata(ctx context.Context, mds ...metadata.MD) context.Context { out, _ := metadata.FromOutgoingContext(ctx) diff --git a/containeranalysis/apiv1beta1/grafeas_v1_beta1_client.go b/containeranalysis/apiv1beta1/grafeas_v1_beta1_client.go index 7f5faa57379..6ba9a5b0a68 100644 --- a/containeranalysis/apiv1beta1/grafeas_v1_beta1_client.go +++ b/containeranalysis/apiv1beta1/grafeas_v1_beta1_client.go @@ -23,7 +23,6 @@ import ( "net/url" "time" - "github.com/golang/protobuf/proto" gax "github.com/googleapis/gax-go/v2" "google.golang.org/api/iterator" "google.golang.org/api/option" @@ -33,6 +32,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newGrafeasV1Beta1ClientHook clientHook @@ -62,6 +62,7 @@ func defaultGrafeasV1Beta1GRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("containeranalysis.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://containeranalysis.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/datacatalog/apiv1/data_catalog_client.go b/datacatalog/apiv1/data_catalog_client.go index e6e92aabd06..567e84f10fa 100644 --- a/datacatalog/apiv1/data_catalog_client.go +++ b/datacatalog/apiv1/data_catalog_client.go @@ -23,7 +23,6 @@ import ( "net/url" "time" - "github.com/golang/protobuf/proto" gax "github.com/googleapis/gax-go/v2" "google.golang.org/api/iterator" "google.golang.org/api/option" @@ -34,6 +33,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newClientHook clientHook @@ -76,6 +76,7 @@ func defaultGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("datacatalog.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://datacatalog.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/datacatalog/apiv1/doc.go b/datacatalog/apiv1/doc.go index 2aed75eca0e..2168e44843d 100644 --- a/datacatalog/apiv1/doc.go +++ b/datacatalog/apiv1/doc.go @@ -49,7 +49,7 @@ import ( type clientHookParams struct{} type clientHook func(context.Context, clientHookParams) ([]option.ClientOption, error) -const versionClient = "20210612" +const versionClient = "20210701" func insertMetadata(ctx context.Context, mds ...metadata.MD) context.Context { out, _ := metadata.FromOutgoingContext(ctx) diff --git a/datacatalog/apiv1/policy_tag_manager_client.go b/datacatalog/apiv1/policy_tag_manager_client.go index c53e44920d2..09e41c757c5 100644 --- a/datacatalog/apiv1/policy_tag_manager_client.go +++ b/datacatalog/apiv1/policy_tag_manager_client.go @@ -23,7 +23,6 @@ import ( "net/url" "time" - "github.com/golang/protobuf/proto" gax "github.com/googleapis/gax-go/v2" "google.golang.org/api/iterator" "google.golang.org/api/option" @@ -33,6 +32,7 @@ import ( iampb "google.golang.org/genproto/googleapis/iam/v1" "google.golang.org/grpc" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newPolicyTagManagerClientHook clientHook @@ -60,6 +60,7 @@ func defaultPolicyTagManagerGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("datacatalog.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://datacatalog.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/datacatalog/apiv1/policy_tag_manager_serialization_client.go b/datacatalog/apiv1/policy_tag_manager_serialization_client.go index b863c393c17..cea7c6579c5 100644 --- a/datacatalog/apiv1/policy_tag_manager_serialization_client.go +++ b/datacatalog/apiv1/policy_tag_manager_serialization_client.go @@ -46,6 +46,7 @@ func defaultPolicyTagManagerSerializationGRPCClientOptions() []option.ClientOpti internaloption.WithDefaultMTLSEndpoint("datacatalog.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://datacatalog.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/datacatalog/apiv1beta1/data_catalog_client.go b/datacatalog/apiv1beta1/data_catalog_client.go index f828f15b303..e3d6a16f448 100644 --- a/datacatalog/apiv1beta1/data_catalog_client.go +++ b/datacatalog/apiv1beta1/data_catalog_client.go @@ -23,7 +23,6 @@ import ( "net/url" "time" - "github.com/golang/protobuf/proto" gax "github.com/googleapis/gax-go/v2" "google.golang.org/api/iterator" "google.golang.org/api/option" @@ -34,6 +33,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newClientHook clientHook @@ -75,6 +75,7 @@ func defaultGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("datacatalog.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://datacatalog.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/datacatalog/apiv1beta1/doc.go b/datacatalog/apiv1beta1/doc.go index ec1ae1ce66f..fd5ad470493 100644 --- a/datacatalog/apiv1beta1/doc.go +++ b/datacatalog/apiv1beta1/doc.go @@ -51,7 +51,7 @@ import ( type clientHookParams struct{} type clientHook func(context.Context, clientHookParams) ([]option.ClientOption, error) -const versionClient = "20210612" +const versionClient = "20210701" func insertMetadata(ctx context.Context, mds ...metadata.MD) context.Context { out, _ := metadata.FromOutgoingContext(ctx) diff --git a/datacatalog/apiv1beta1/policy_tag_manager_client.go b/datacatalog/apiv1beta1/policy_tag_manager_client.go index 66b406a2850..9028e6e7776 100644 --- a/datacatalog/apiv1beta1/policy_tag_manager_client.go +++ b/datacatalog/apiv1beta1/policy_tag_manager_client.go @@ -22,7 +22,6 @@ import ( "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" @@ -32,6 +31,7 @@ import ( iampb "google.golang.org/genproto/googleapis/iam/v1" "google.golang.org/grpc" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newPolicyTagManagerClientHook clientHook @@ -59,6 +59,7 @@ func defaultPolicyTagManagerGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("datacatalog.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://datacatalog.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/datacatalog/apiv1beta1/policy_tag_manager_serialization_client.go b/datacatalog/apiv1beta1/policy_tag_manager_serialization_client.go index aea423fce33..46723d2ba02 100644 --- a/datacatalog/apiv1beta1/policy_tag_manager_serialization_client.go +++ b/datacatalog/apiv1beta1/policy_tag_manager_serialization_client.go @@ -45,6 +45,7 @@ func defaultPolicyTagManagerSerializationGRPCClientOptions() []option.ClientOpti internaloption.WithDefaultMTLSEndpoint("datacatalog.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://datacatalog.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/dataflow/apiv1beta3/doc.go b/dataflow/apiv1beta3/doc.go new file mode 100644 index 00000000000..4b8ebff9155 --- /dev/null +++ b/dataflow/apiv1beta3/doc.go @@ -0,0 +1,121 @@ +// 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 dataflow is an auto-generated package for the +// Dataflow API. +// +// Manages Google Cloud Dataflow projects on Google Cloud Platform. +// +// 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 dataflow // import "cloud.google.com/go/dataflow/apiv1beta3" + +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 = "20210701" + +func insertMetadata(ctx context.Context, mds ...metadata.MD) context.Context { + out, _ := metadata.FromOutgoingContext(ctx) + out = out.Copy() + for _, md := range mds { + for k, v := range md { + out[k] = append(out[k], v...) + } + } + return metadata.NewOutgoingContext(ctx, out) +} + +func checkDisableDeadlines() (bool, error) { + raw, ok := os.LookupEnv("GOOGLE_API_GO_EXPERIMENTAL_DISABLE_DEFAULT_DEADLINE") + if !ok { + return false, nil + } + + b, err := strconv.ParseBool(raw) + return b, err +} + +// DefaultAuthScopes reports the default set of authentication scopes to use with this package. +func DefaultAuthScopes() []string { + return []string{ + "https://www.googleapis.com/auth/cloud-platform", + "https://www.googleapis.com/auth/compute", + "https://www.googleapis.com/auth/compute.readonly", + "https://www.googleapis.com/auth/userinfo.email", + } +} + +// 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/dataflow/apiv1beta3/flex_templates_client.go b/dataflow/apiv1beta3/flex_templates_client.go new file mode 100644 index 00000000000..9e7917b2aae --- /dev/null +++ b/dataflow/apiv1beta3/flex_templates_client.go @@ -0,0 +1,198 @@ +// 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 dataflow + +import ( + "context" + "math" + + 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" + dataflowpb "google.golang.org/genproto/googleapis/dataflow/v1beta3" + "google.golang.org/grpc" + "google.golang.org/grpc/metadata" +) + +var newFlexTemplatesClientHook clientHook + +// FlexTemplatesCallOptions contains the retry settings for each method of FlexTemplatesClient. +type FlexTemplatesCallOptions struct { + LaunchFlexTemplate []gax.CallOption +} + +func defaultFlexTemplatesGRPCClientOptions() []option.ClientOption { + return []option.ClientOption{ + internaloption.WithDefaultEndpoint("dataflow.googleapis.com:443"), + internaloption.WithDefaultMTLSEndpoint("dataflow.mtls.googleapis.com:443"), + internaloption.WithDefaultAudience("https://dataflow.googleapis.com/"), + internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), + option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), + option.WithGRPCDialOption(grpc.WithDefaultCallOptions( + grpc.MaxCallRecvMsgSize(math.MaxInt32))), + } +} + +func defaultFlexTemplatesCallOptions() *FlexTemplatesCallOptions { + return &FlexTemplatesCallOptions{ + LaunchFlexTemplate: []gax.CallOption{}, + } +} + +// internalFlexTemplatesClient is an interface that defines the methods availaible from Dataflow API. +type internalFlexTemplatesClient interface { + Close() error + setGoogleClientInfo(...string) + Connection() *grpc.ClientConn + LaunchFlexTemplate(context.Context, *dataflowpb.LaunchFlexTemplateRequest, ...gax.CallOption) (*dataflowpb.LaunchFlexTemplateResponse, error) +} + +// FlexTemplatesClient is a client for interacting with Dataflow API. +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +// +// Provides a service for Flex templates. This feature is not ready yet. +type FlexTemplatesClient struct { + // The internal transport-dependent client. + internalClient internalFlexTemplatesClient + + // The call options for this service. + CallOptions *FlexTemplatesCallOptions +} + +// 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 *FlexTemplatesClient) 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 *FlexTemplatesClient) setGoogleClientInfo(keyval ...string) { + c.internalClient.setGoogleClientInfo(keyval...) +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *FlexTemplatesClient) Connection() *grpc.ClientConn { + return c.internalClient.Connection() +} + +// LaunchFlexTemplate launch a job with a FlexTemplate. +func (c *FlexTemplatesClient) LaunchFlexTemplate(ctx context.Context, req *dataflowpb.LaunchFlexTemplateRequest, opts ...gax.CallOption) (*dataflowpb.LaunchFlexTemplateResponse, error) { + return c.internalClient.LaunchFlexTemplate(ctx, req, opts...) +} + +// flexTemplatesGRPCClient is a client for interacting with Dataflow API over gRPC transport. +// +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +type flexTemplatesGRPCClient 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 FlexTemplatesClient + CallOptions **FlexTemplatesCallOptions + + // The gRPC API client. + flexTemplatesClient dataflowpb.FlexTemplatesServiceClient + + // The x-goog-* metadata to be sent with each request. + xGoogMetadata metadata.MD +} + +// NewFlexTemplatesClient creates a new flex templates service client based on gRPC. +// The returned client must be Closed when it is done being used to clean up its underlying connections. +// +// Provides a service for Flex templates. This feature is not ready yet. +func NewFlexTemplatesClient(ctx context.Context, opts ...option.ClientOption) (*FlexTemplatesClient, error) { + clientOpts := defaultFlexTemplatesGRPCClientOptions() + if newFlexTemplatesClientHook != nil { + hookOpts, err := newFlexTemplatesClientHook(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 := FlexTemplatesClient{CallOptions: defaultFlexTemplatesCallOptions()} + + c := &flexTemplatesGRPCClient{ + connPool: connPool, + disableDeadlines: disableDeadlines, + flexTemplatesClient: dataflowpb.NewFlexTemplatesServiceClient(connPool), + CallOptions: &client.CallOptions, + } + c.setGoogleClientInfo() + + client.internalClient = c + + return &client, nil +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *flexTemplatesGRPCClient) 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 *flexTemplatesGRPCClient) 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 *flexTemplatesGRPCClient) Close() error { + return c.connPool.Close() +} + +func (c *flexTemplatesGRPCClient) LaunchFlexTemplate(ctx context.Context, req *dataflowpb.LaunchFlexTemplateRequest, opts ...gax.CallOption) (*dataflowpb.LaunchFlexTemplateResponse, error) { + ctx = insertMetadata(ctx, c.xGoogMetadata) + opts = append((*c.CallOptions).LaunchFlexTemplate[0:len((*c.CallOptions).LaunchFlexTemplate):len((*c.CallOptions).LaunchFlexTemplate)], opts...) + var resp *dataflowpb.LaunchFlexTemplateResponse + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.flexTemplatesClient.LaunchFlexTemplate(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} diff --git a/dataflow/apiv1beta3/flex_templates_client_example_test.go b/dataflow/apiv1beta3/flex_templates_client_example_test.go new file mode 100644 index 00000000000..04876acb107 --- /dev/null +++ b/dataflow/apiv1beta3/flex_templates_client_example_test.go @@ -0,0 +1,55 @@ +// 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 dataflow_test + +import ( + "context" + + dataflow "cloud.google.com/go/dataflow/apiv1beta3" + dataflowpb "google.golang.org/genproto/googleapis/dataflow/v1beta3" +) + +func ExampleNewFlexTemplatesClient() { + ctx := context.Background() + c, err := dataflow.NewFlexTemplatesClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + // TODO: Use client. + _ = c +} + +func ExampleFlexTemplatesClient_LaunchFlexTemplate() { + ctx := context.Background() + c, err := dataflow.NewFlexTemplatesClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &dataflowpb.LaunchFlexTemplateRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.LaunchFlexTemplate(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} diff --git a/dataflow/apiv1beta3/gapic_metadata.json b/dataflow/apiv1beta3/gapic_metadata.json new file mode 100644 index 00000000000..9dcbc9db670 --- /dev/null +++ b/dataflow/apiv1beta3/gapic_metadata.json @@ -0,0 +1,153 @@ +{ + "schema": "1.0", + "comment": "This file maps proto services/RPCs to the corresponding library clients/methods.", + "language": "go", + "protoPackage": "google.dataflow.v1beta3", + "libraryPackage": "cloud.google.com/go/dataflow/apiv1beta3", + "services": { + "FlexTemplatesService": { + "clients": { + "grpc": { + "libraryClient": "FlexTemplatesClient", + "rpcs": { + "LaunchFlexTemplate": { + "methods": [ + "LaunchFlexTemplate" + ] + } + } + } + } + }, + "JobsV1Beta3": { + "clients": { + "grpc": { + "libraryClient": "JobsV1Beta3Client", + "rpcs": { + "AggregatedListJobs": { + "methods": [ + "AggregatedListJobs" + ] + }, + "CheckActiveJobs": { + "methods": [ + "CheckActiveJobs" + ] + }, + "CreateJob": { + "methods": [ + "CreateJob" + ] + }, + "GetJob": { + "methods": [ + "GetJob" + ] + }, + "ListJobs": { + "methods": [ + "ListJobs" + ] + }, + "SnapshotJob": { + "methods": [ + "SnapshotJob" + ] + }, + "UpdateJob": { + "methods": [ + "UpdateJob" + ] + } + } + } + } + }, + "MessagesV1Beta3": { + "clients": { + "grpc": { + "libraryClient": "MessagesV1Beta3Client", + "rpcs": { + "ListJobMessages": { + "methods": [ + "ListJobMessages" + ] + } + } + } + } + }, + "MetricsV1Beta3": { + "clients": { + "grpc": { + "libraryClient": "MetricsV1Beta3Client", + "rpcs": { + "GetJobExecutionDetails": { + "methods": [ + "GetJobExecutionDetails" + ] + }, + "GetJobMetrics": { + "methods": [ + "GetJobMetrics" + ] + }, + "GetStageExecutionDetails": { + "methods": [ + "GetStageExecutionDetails" + ] + } + } + } + } + }, + "SnapshotsV1Beta3": { + "clients": { + "grpc": { + "libraryClient": "SnapshotsV1Beta3Client", + "rpcs": { + "DeleteSnapshot": { + "methods": [ + "DeleteSnapshot" + ] + }, + "GetSnapshot": { + "methods": [ + "GetSnapshot" + ] + }, + "ListSnapshots": { + "methods": [ + "ListSnapshots" + ] + } + } + } + } + }, + "TemplatesService": { + "clients": { + "grpc": { + "libraryClient": "TemplatesClient", + "rpcs": { + "CreateJobFromTemplate": { + "methods": [ + "CreateJobFromTemplate" + ] + }, + "GetTemplate": { + "methods": [ + "GetTemplate" + ] + }, + "LaunchTemplate": { + "methods": [ + "LaunchTemplate" + ] + } + } + } + } + } + } +} diff --git a/dataflow/apiv1beta3/jobs_v1_beta3_client.go b/dataflow/apiv1beta3/jobs_v1_beta3_client.go new file mode 100644 index 00000000000..e477258d858 --- /dev/null +++ b/dataflow/apiv1beta3/jobs_v1_beta3_client.go @@ -0,0 +1,486 @@ +// 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 dataflow + +import ( + "context" + "math" + "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" + dataflowpb "google.golang.org/genproto/googleapis/dataflow/v1beta3" + "google.golang.org/grpc" + "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" +) + +var newJobsV1Beta3ClientHook clientHook + +// JobsV1Beta3CallOptions contains the retry settings for each method of JobsV1Beta3Client. +type JobsV1Beta3CallOptions struct { + CreateJob []gax.CallOption + GetJob []gax.CallOption + UpdateJob []gax.CallOption + ListJobs []gax.CallOption + AggregatedListJobs []gax.CallOption + CheckActiveJobs []gax.CallOption + SnapshotJob []gax.CallOption +} + +func defaultJobsV1Beta3GRPCClientOptions() []option.ClientOption { + return []option.ClientOption{ + internaloption.WithDefaultEndpoint("dataflow.googleapis.com:443"), + internaloption.WithDefaultMTLSEndpoint("dataflow.mtls.googleapis.com:443"), + internaloption.WithDefaultAudience("https://dataflow.googleapis.com/"), + internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), + option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), + option.WithGRPCDialOption(grpc.WithDefaultCallOptions( + grpc.MaxCallRecvMsgSize(math.MaxInt32))), + } +} + +func defaultJobsV1Beta3CallOptions() *JobsV1Beta3CallOptions { + return &JobsV1Beta3CallOptions{ + CreateJob: []gax.CallOption{}, + GetJob: []gax.CallOption{}, + UpdateJob: []gax.CallOption{}, + ListJobs: []gax.CallOption{}, + AggregatedListJobs: []gax.CallOption{}, + CheckActiveJobs: []gax.CallOption{}, + SnapshotJob: []gax.CallOption{}, + } +} + +// internalJobsV1Beta3Client is an interface that defines the methods availaible from Dataflow API. +type internalJobsV1Beta3Client interface { + Close() error + setGoogleClientInfo(...string) + Connection() *grpc.ClientConn + CreateJob(context.Context, *dataflowpb.CreateJobRequest, ...gax.CallOption) (*dataflowpb.Job, error) + GetJob(context.Context, *dataflowpb.GetJobRequest, ...gax.CallOption) (*dataflowpb.Job, error) + UpdateJob(context.Context, *dataflowpb.UpdateJobRequest, ...gax.CallOption) (*dataflowpb.Job, error) + ListJobs(context.Context, *dataflowpb.ListJobsRequest, ...gax.CallOption) *JobIterator + AggregatedListJobs(context.Context, *dataflowpb.ListJobsRequest, ...gax.CallOption) *JobIterator + CheckActiveJobs(context.Context, *dataflowpb.CheckActiveJobsRequest, ...gax.CallOption) (*dataflowpb.CheckActiveJobsResponse, error) + SnapshotJob(context.Context, *dataflowpb.SnapshotJobRequest, ...gax.CallOption) (*dataflowpb.Snapshot, error) +} + +// JobsV1Beta3Client is a client for interacting with Dataflow API. +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +// +// Provides a method to create and modify Google Cloud Dataflow jobs. +// A Job is a multi-stage computation graph run by the Cloud Dataflow service. +type JobsV1Beta3Client struct { + // The internal transport-dependent client. + internalClient internalJobsV1Beta3Client + + // The call options for this service. + CallOptions *JobsV1Beta3CallOptions +} + +// 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 *JobsV1Beta3Client) 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 *JobsV1Beta3Client) setGoogleClientInfo(keyval ...string) { + c.internalClient.setGoogleClientInfo(keyval...) +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *JobsV1Beta3Client) Connection() *grpc.ClientConn { + return c.internalClient.Connection() +} + +// CreateJob creates a Cloud Dataflow job. +// +// To create a job, we recommend using projects.locations.jobs.create with a +// [regional endpoint] +// (https://cloud.google.com/dataflow/docs/concepts/regional-endpoints (at https://cloud.google.com/dataflow/docs/concepts/regional-endpoints)). Using +// projects.jobs.create is not recommended, as your job will always start +// in us-central1. +func (c *JobsV1Beta3Client) CreateJob(ctx context.Context, req *dataflowpb.CreateJobRequest, opts ...gax.CallOption) (*dataflowpb.Job, error) { + return c.internalClient.CreateJob(ctx, req, opts...) +} + +// GetJob gets the state of the specified Cloud Dataflow job. +// +// To get the state of a job, we recommend using projects.locations.jobs.get +// with a [regional endpoint] +// (https://cloud.google.com/dataflow/docs/concepts/regional-endpoints (at https://cloud.google.com/dataflow/docs/concepts/regional-endpoints)). Using +// projects.jobs.get is not recommended, as you can only get the state of +// jobs that are running in us-central1. +func (c *JobsV1Beta3Client) GetJob(ctx context.Context, req *dataflowpb.GetJobRequest, opts ...gax.CallOption) (*dataflowpb.Job, error) { + return c.internalClient.GetJob(ctx, req, opts...) +} + +// UpdateJob updates the state of an existing Cloud Dataflow job. +// +// To update the state of an existing job, we recommend using +// projects.locations.jobs.update with a [regional endpoint] +// (https://cloud.google.com/dataflow/docs/concepts/regional-endpoints (at https://cloud.google.com/dataflow/docs/concepts/regional-endpoints)). Using +// projects.jobs.update is not recommended, as you can only update the state +// of jobs that are running in us-central1. +func (c *JobsV1Beta3Client) UpdateJob(ctx context.Context, req *dataflowpb.UpdateJobRequest, opts ...gax.CallOption) (*dataflowpb.Job, error) { + return c.internalClient.UpdateJob(ctx, req, opts...) +} + +// ListJobs list the jobs of a project. +// +// To list the jobs of a project in a region, we recommend using +// projects.locations.jobs.list with a [regional endpoint] +// (https://cloud.google.com/dataflow/docs/concepts/regional-endpoints (at https://cloud.google.com/dataflow/docs/concepts/regional-endpoints)). To +// list the all jobs across all regions, use projects.jobs.aggregated. Using +// projects.jobs.list is not recommended, as you can only get the list of +// jobs that are running in us-central1. +func (c *JobsV1Beta3Client) ListJobs(ctx context.Context, req *dataflowpb.ListJobsRequest, opts ...gax.CallOption) *JobIterator { + return c.internalClient.ListJobs(ctx, req, opts...) +} + +// AggregatedListJobs list the jobs of a project across all regions. +func (c *JobsV1Beta3Client) AggregatedListJobs(ctx context.Context, req *dataflowpb.ListJobsRequest, opts ...gax.CallOption) *JobIterator { + return c.internalClient.AggregatedListJobs(ctx, req, opts...) +} + +// CheckActiveJobs check for existence of active jobs in the given project across all regions. +func (c *JobsV1Beta3Client) CheckActiveJobs(ctx context.Context, req *dataflowpb.CheckActiveJobsRequest, opts ...gax.CallOption) (*dataflowpb.CheckActiveJobsResponse, error) { + return c.internalClient.CheckActiveJobs(ctx, req, opts...) +} + +// SnapshotJob snapshot the state of a streaming job. +func (c *JobsV1Beta3Client) SnapshotJob(ctx context.Context, req *dataflowpb.SnapshotJobRequest, opts ...gax.CallOption) (*dataflowpb.Snapshot, error) { + return c.internalClient.SnapshotJob(ctx, req, opts...) +} + +// jobsV1Beta3GRPCClient is a client for interacting with Dataflow API over gRPC transport. +// +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +type jobsV1Beta3GRPCClient 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 JobsV1Beta3Client + CallOptions **JobsV1Beta3CallOptions + + // The gRPC API client. + jobsV1Beta3Client dataflowpb.JobsV1Beta3Client + + // The x-goog-* metadata to be sent with each request. + xGoogMetadata metadata.MD +} + +// NewJobsV1Beta3Client creates a new jobs v1 beta3 client based on gRPC. +// The returned client must be Closed when it is done being used to clean up its underlying connections. +// +// Provides a method to create and modify Google Cloud Dataflow jobs. +// A Job is a multi-stage computation graph run by the Cloud Dataflow service. +func NewJobsV1Beta3Client(ctx context.Context, opts ...option.ClientOption) (*JobsV1Beta3Client, error) { + clientOpts := defaultJobsV1Beta3GRPCClientOptions() + if newJobsV1Beta3ClientHook != nil { + hookOpts, err := newJobsV1Beta3ClientHook(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 := JobsV1Beta3Client{CallOptions: defaultJobsV1Beta3CallOptions()} + + c := &jobsV1Beta3GRPCClient{ + connPool: connPool, + disableDeadlines: disableDeadlines, + jobsV1Beta3Client: dataflowpb.NewJobsV1Beta3Client(connPool), + CallOptions: &client.CallOptions, + } + c.setGoogleClientInfo() + + client.internalClient = c + + return &client, nil +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *jobsV1Beta3GRPCClient) 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 *jobsV1Beta3GRPCClient) 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 *jobsV1Beta3GRPCClient) Close() error { + return c.connPool.Close() +} + +func (c *jobsV1Beta3GRPCClient) CreateJob(ctx context.Context, req *dataflowpb.CreateJobRequest, opts ...gax.CallOption) (*dataflowpb.Job, error) { + if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { + cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond) + defer cancel() + ctx = cctx + } + ctx = insertMetadata(ctx, c.xGoogMetadata) + opts = append((*c.CallOptions).CreateJob[0:len((*c.CallOptions).CreateJob):len((*c.CallOptions).CreateJob)], opts...) + var resp *dataflowpb.Job + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.jobsV1Beta3Client.CreateJob(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} + +func (c *jobsV1Beta3GRPCClient) GetJob(ctx context.Context, req *dataflowpb.GetJobRequest, opts ...gax.CallOption) (*dataflowpb.Job, error) { + if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { + cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond) + defer cancel() + ctx = cctx + } + ctx = insertMetadata(ctx, c.xGoogMetadata) + opts = append((*c.CallOptions).GetJob[0:len((*c.CallOptions).GetJob):len((*c.CallOptions).GetJob)], opts...) + var resp *dataflowpb.Job + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.jobsV1Beta3Client.GetJob(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} + +func (c *jobsV1Beta3GRPCClient) UpdateJob(ctx context.Context, req *dataflowpb.UpdateJobRequest, opts ...gax.CallOption) (*dataflowpb.Job, error) { + if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { + cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond) + defer cancel() + ctx = cctx + } + ctx = insertMetadata(ctx, c.xGoogMetadata) + opts = append((*c.CallOptions).UpdateJob[0:len((*c.CallOptions).UpdateJob):len((*c.CallOptions).UpdateJob)], opts...) + var resp *dataflowpb.Job + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.jobsV1Beta3Client.UpdateJob(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} + +func (c *jobsV1Beta3GRPCClient) ListJobs(ctx context.Context, req *dataflowpb.ListJobsRequest, opts ...gax.CallOption) *JobIterator { + ctx = insertMetadata(ctx, c.xGoogMetadata) + opts = append((*c.CallOptions).ListJobs[0:len((*c.CallOptions).ListJobs):len((*c.CallOptions).ListJobs)], opts...) + it := &JobIterator{} + req = proto.Clone(req).(*dataflowpb.ListJobsRequest) + it.InternalFetch = func(pageSize int, pageToken string) ([]*dataflowpb.Job, string, error) { + var resp *dataflowpb.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.jobsV1Beta3Client.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 *jobsV1Beta3GRPCClient) AggregatedListJobs(ctx context.Context, req *dataflowpb.ListJobsRequest, opts ...gax.CallOption) *JobIterator { + ctx = insertMetadata(ctx, c.xGoogMetadata) + opts = append((*c.CallOptions).AggregatedListJobs[0:len((*c.CallOptions).AggregatedListJobs):len((*c.CallOptions).AggregatedListJobs)], opts...) + it := &JobIterator{} + req = proto.Clone(req).(*dataflowpb.ListJobsRequest) + it.InternalFetch = func(pageSize int, pageToken string) ([]*dataflowpb.Job, string, error) { + var resp *dataflowpb.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.jobsV1Beta3Client.AggregatedListJobs(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 *jobsV1Beta3GRPCClient) CheckActiveJobs(ctx context.Context, req *dataflowpb.CheckActiveJobsRequest, opts ...gax.CallOption) (*dataflowpb.CheckActiveJobsResponse, error) { + if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { + cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond) + defer cancel() + ctx = cctx + } + ctx = insertMetadata(ctx, c.xGoogMetadata) + opts = append((*c.CallOptions).CheckActiveJobs[0:len((*c.CallOptions).CheckActiveJobs):len((*c.CallOptions).CheckActiveJobs)], opts...) + var resp *dataflowpb.CheckActiveJobsResponse + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.jobsV1Beta3Client.CheckActiveJobs(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} + +func (c *jobsV1Beta3GRPCClient) SnapshotJob(ctx context.Context, req *dataflowpb.SnapshotJobRequest, opts ...gax.CallOption) (*dataflowpb.Snapshot, error) { + if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { + cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond) + defer cancel() + ctx = cctx + } + ctx = insertMetadata(ctx, c.xGoogMetadata) + opts = append((*c.CallOptions).SnapshotJob[0:len((*c.CallOptions).SnapshotJob):len((*c.CallOptions).SnapshotJob)], opts...) + var resp *dataflowpb.Snapshot + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.jobsV1Beta3Client.SnapshotJob(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} + +// JobIterator manages a stream of *dataflowpb.Job. +type JobIterator struct { + items []*dataflowpb.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 []*dataflowpb.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() (*dataflowpb.Job, error) { + var item *dataflowpb.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 +} diff --git a/dataflow/apiv1beta3/jobs_v1_beta3_client_example_test.go b/dataflow/apiv1beta3/jobs_v1_beta3_client_example_test.go new file mode 100644 index 00000000000..101dc40be89 --- /dev/null +++ b/dataflow/apiv1beta3/jobs_v1_beta3_client_example_test.go @@ -0,0 +1,182 @@ +// 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 dataflow_test + +import ( + "context" + + dataflow "cloud.google.com/go/dataflow/apiv1beta3" + "google.golang.org/api/iterator" + dataflowpb "google.golang.org/genproto/googleapis/dataflow/v1beta3" +) + +func ExampleNewJobsV1Beta3Client() { + ctx := context.Background() + c, err := dataflow.NewJobsV1Beta3Client(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + // TODO: Use client. + _ = c +} + +func ExampleJobsV1Beta3Client_CreateJob() { + ctx := context.Background() + c, err := dataflow.NewJobsV1Beta3Client(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &dataflowpb.CreateJobRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.CreateJob(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleJobsV1Beta3Client_GetJob() { + ctx := context.Background() + c, err := dataflow.NewJobsV1Beta3Client(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &dataflowpb.GetJobRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.GetJob(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleJobsV1Beta3Client_UpdateJob() { + ctx := context.Background() + c, err := dataflow.NewJobsV1Beta3Client(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &dataflowpb.UpdateJobRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.UpdateJob(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleJobsV1Beta3Client_ListJobs() { + ctx := context.Background() + c, err := dataflow.NewJobsV1Beta3Client(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &dataflowpb.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 ExampleJobsV1Beta3Client_AggregatedListJobs() { + ctx := context.Background() + c, err := dataflow.NewJobsV1Beta3Client(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &dataflowpb.ListJobsRequest{ + // TODO: Fill request struct fields. + } + it := c.AggregatedListJobs(ctx, req) + for { + resp, err := it.Next() + if err == iterator.Done { + break + } + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp + } +} + +func ExampleJobsV1Beta3Client_CheckActiveJobs() { + ctx := context.Background() + c, err := dataflow.NewJobsV1Beta3Client(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &dataflowpb.CheckActiveJobsRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.CheckActiveJobs(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleJobsV1Beta3Client_SnapshotJob() { + ctx := context.Background() + c, err := dataflow.NewJobsV1Beta3Client(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &dataflowpb.SnapshotJobRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.SnapshotJob(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} diff --git a/dataflow/apiv1beta3/messages_v1_beta3_client.go b/dataflow/apiv1beta3/messages_v1_beta3_client.go new file mode 100644 index 00000000000..cc2ccb08df0 --- /dev/null +++ b/dataflow/apiv1beta3/messages_v1_beta3_client.go @@ -0,0 +1,279 @@ +// 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 dataflow + +import ( + "context" + "math" + + 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" + dataflowpb "google.golang.org/genproto/googleapis/dataflow/v1beta3" + "google.golang.org/grpc" + "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" +) + +var newMessagesV1Beta3ClientHook clientHook + +// MessagesV1Beta3CallOptions contains the retry settings for each method of MessagesV1Beta3Client. +type MessagesV1Beta3CallOptions struct { + ListJobMessages []gax.CallOption +} + +func defaultMessagesV1Beta3GRPCClientOptions() []option.ClientOption { + return []option.ClientOption{ + internaloption.WithDefaultEndpoint("dataflow.googleapis.com:443"), + internaloption.WithDefaultMTLSEndpoint("dataflow.mtls.googleapis.com:443"), + internaloption.WithDefaultAudience("https://dataflow.googleapis.com/"), + internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), + option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), + option.WithGRPCDialOption(grpc.WithDefaultCallOptions( + grpc.MaxCallRecvMsgSize(math.MaxInt32))), + } +} + +func defaultMessagesV1Beta3CallOptions() *MessagesV1Beta3CallOptions { + return &MessagesV1Beta3CallOptions{ + ListJobMessages: []gax.CallOption{}, + } +} + +// internalMessagesV1Beta3Client is an interface that defines the methods availaible from Dataflow API. +type internalMessagesV1Beta3Client interface { + Close() error + setGoogleClientInfo(...string) + Connection() *grpc.ClientConn + ListJobMessages(context.Context, *dataflowpb.ListJobMessagesRequest, ...gax.CallOption) *JobMessageIterator +} + +// MessagesV1Beta3Client is a client for interacting with Dataflow API. +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +// +// The Dataflow Messages API is used for monitoring the progress of +// Dataflow jobs. +type MessagesV1Beta3Client struct { + // The internal transport-dependent client. + internalClient internalMessagesV1Beta3Client + + // The call options for this service. + CallOptions *MessagesV1Beta3CallOptions +} + +// 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 *MessagesV1Beta3Client) 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 *MessagesV1Beta3Client) setGoogleClientInfo(keyval ...string) { + c.internalClient.setGoogleClientInfo(keyval...) +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *MessagesV1Beta3Client) Connection() *grpc.ClientConn { + return c.internalClient.Connection() +} + +// ListJobMessages request the job status. +// +// To request the status of a job, we recommend using +// projects.locations.jobs.messages.list with a [regional endpoint] +// (https://cloud.google.com/dataflow/docs/concepts/regional-endpoints (at https://cloud.google.com/dataflow/docs/concepts/regional-endpoints)). Using +// projects.jobs.messages.list is not recommended, as you can only request +// the status of jobs that are running in us-central1. +func (c *MessagesV1Beta3Client) ListJobMessages(ctx context.Context, req *dataflowpb.ListJobMessagesRequest, opts ...gax.CallOption) *JobMessageIterator { + return c.internalClient.ListJobMessages(ctx, req, opts...) +} + +// messagesV1Beta3GRPCClient is a client for interacting with Dataflow API over gRPC transport. +// +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +type messagesV1Beta3GRPCClient 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 MessagesV1Beta3Client + CallOptions **MessagesV1Beta3CallOptions + + // The gRPC API client. + messagesV1Beta3Client dataflowpb.MessagesV1Beta3Client + + // The x-goog-* metadata to be sent with each request. + xGoogMetadata metadata.MD +} + +// NewMessagesV1Beta3Client creates a new messages v1 beta3 client based on gRPC. +// The returned client must be Closed when it is done being used to clean up its underlying connections. +// +// The Dataflow Messages API is used for monitoring the progress of +// Dataflow jobs. +func NewMessagesV1Beta3Client(ctx context.Context, opts ...option.ClientOption) (*MessagesV1Beta3Client, error) { + clientOpts := defaultMessagesV1Beta3GRPCClientOptions() + if newMessagesV1Beta3ClientHook != nil { + hookOpts, err := newMessagesV1Beta3ClientHook(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 := MessagesV1Beta3Client{CallOptions: defaultMessagesV1Beta3CallOptions()} + + c := &messagesV1Beta3GRPCClient{ + connPool: connPool, + disableDeadlines: disableDeadlines, + messagesV1Beta3Client: dataflowpb.NewMessagesV1Beta3Client(connPool), + CallOptions: &client.CallOptions, + } + c.setGoogleClientInfo() + + client.internalClient = c + + return &client, nil +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *messagesV1Beta3GRPCClient) 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 *messagesV1Beta3GRPCClient) 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 *messagesV1Beta3GRPCClient) Close() error { + return c.connPool.Close() +} + +func (c *messagesV1Beta3GRPCClient) ListJobMessages(ctx context.Context, req *dataflowpb.ListJobMessagesRequest, opts ...gax.CallOption) *JobMessageIterator { + ctx = insertMetadata(ctx, c.xGoogMetadata) + opts = append((*c.CallOptions).ListJobMessages[0:len((*c.CallOptions).ListJobMessages):len((*c.CallOptions).ListJobMessages)], opts...) + it := &JobMessageIterator{} + req = proto.Clone(req).(*dataflowpb.ListJobMessagesRequest) + it.InternalFetch = func(pageSize int, pageToken string) ([]*dataflowpb.JobMessage, string, error) { + var resp *dataflowpb.ListJobMessagesResponse + 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.messagesV1Beta3Client.ListJobMessages(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, "", err + } + + it.Response = resp + return resp.GetJobMessages(), 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 +} + +// JobMessageIterator manages a stream of *dataflowpb.JobMessage. +type JobMessageIterator struct { + items []*dataflowpb.JobMessage + 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 []*dataflowpb.JobMessage, nextPageToken string, err error) +} + +// PageInfo supports pagination. See the google.golang.org/api/iterator package for details. +func (it *JobMessageIterator) 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 *JobMessageIterator) Next() (*dataflowpb.JobMessage, error) { + var item *dataflowpb.JobMessage + if err := it.nextFunc(); err != nil { + return item, err + } + item = it.items[0] + it.items = it.items[1:] + return item, nil +} + +func (it *JobMessageIterator) bufLen() int { + return len(it.items) +} + +func (it *JobMessageIterator) takeBuf() interface{} { + b := it.items + it.items = nil + return b +} diff --git a/dataflow/apiv1beta3/messages_v1_beta3_client_example_test.go b/dataflow/apiv1beta3/messages_v1_beta3_client_example_test.go new file mode 100644 index 00000000000..d07cbb34975 --- /dev/null +++ b/dataflow/apiv1beta3/messages_v1_beta3_client_example_test.go @@ -0,0 +1,62 @@ +// 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 dataflow_test + +import ( + "context" + + dataflow "cloud.google.com/go/dataflow/apiv1beta3" + "google.golang.org/api/iterator" + dataflowpb "google.golang.org/genproto/googleapis/dataflow/v1beta3" +) + +func ExampleNewMessagesV1Beta3Client() { + ctx := context.Background() + c, err := dataflow.NewMessagesV1Beta3Client(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + // TODO: Use client. + _ = c +} + +func ExampleMessagesV1Beta3Client_ListJobMessages() { + ctx := context.Background() + c, err := dataflow.NewMessagesV1Beta3Client(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &dataflowpb.ListJobMessagesRequest{ + // TODO: Fill request struct fields. + } + it := c.ListJobMessages(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/dataflow/apiv1beta3/metrics_v1_beta3_client.go b/dataflow/apiv1beta3/metrics_v1_beta3_client.go new file mode 100644 index 00000000000..76bf3af545b --- /dev/null +++ b/dataflow/apiv1beta3/metrics_v1_beta3_client.go @@ -0,0 +1,407 @@ +// 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 dataflow + +import ( + "context" + "math" + "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" + dataflowpb "google.golang.org/genproto/googleapis/dataflow/v1beta3" + "google.golang.org/grpc" + "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" +) + +var newMetricsV1Beta3ClientHook clientHook + +// MetricsV1Beta3CallOptions contains the retry settings for each method of MetricsV1Beta3Client. +type MetricsV1Beta3CallOptions struct { + GetJobMetrics []gax.CallOption + GetJobExecutionDetails []gax.CallOption + GetStageExecutionDetails []gax.CallOption +} + +func defaultMetricsV1Beta3GRPCClientOptions() []option.ClientOption { + return []option.ClientOption{ + internaloption.WithDefaultEndpoint("dataflow.googleapis.com:443"), + internaloption.WithDefaultMTLSEndpoint("dataflow.mtls.googleapis.com:443"), + internaloption.WithDefaultAudience("https://dataflow.googleapis.com/"), + internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), + option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), + option.WithGRPCDialOption(grpc.WithDefaultCallOptions( + grpc.MaxCallRecvMsgSize(math.MaxInt32))), + } +} + +func defaultMetricsV1Beta3CallOptions() *MetricsV1Beta3CallOptions { + return &MetricsV1Beta3CallOptions{ + GetJobMetrics: []gax.CallOption{}, + GetJobExecutionDetails: []gax.CallOption{}, + GetStageExecutionDetails: []gax.CallOption{}, + } +} + +// internalMetricsV1Beta3Client is an interface that defines the methods availaible from Dataflow API. +type internalMetricsV1Beta3Client interface { + Close() error + setGoogleClientInfo(...string) + Connection() *grpc.ClientConn + GetJobMetrics(context.Context, *dataflowpb.GetJobMetricsRequest, ...gax.CallOption) (*dataflowpb.JobMetrics, error) + GetJobExecutionDetails(context.Context, *dataflowpb.GetJobExecutionDetailsRequest, ...gax.CallOption) *StageSummaryIterator + GetStageExecutionDetails(context.Context, *dataflowpb.GetStageExecutionDetailsRequest, ...gax.CallOption) *WorkerDetailsIterator +} + +// MetricsV1Beta3Client is a client for interacting with Dataflow API. +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +// +// The Dataflow Metrics API lets you monitor the progress of Dataflow +// jobs. +type MetricsV1Beta3Client struct { + // The internal transport-dependent client. + internalClient internalMetricsV1Beta3Client + + // The call options for this service. + CallOptions *MetricsV1Beta3CallOptions +} + +// 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 *MetricsV1Beta3Client) 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 *MetricsV1Beta3Client) setGoogleClientInfo(keyval ...string) { + c.internalClient.setGoogleClientInfo(keyval...) +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *MetricsV1Beta3Client) Connection() *grpc.ClientConn { + return c.internalClient.Connection() +} + +// GetJobMetrics request the job status. +// +// To request the status of a job, we recommend using +// projects.locations.jobs.getMetrics with a [regional endpoint] +// (https://cloud.google.com/dataflow/docs/concepts/regional-endpoints (at https://cloud.google.com/dataflow/docs/concepts/regional-endpoints)). Using +// projects.jobs.getMetrics is not recommended, as you can only request the +// status of jobs that are running in us-central1. +func (c *MetricsV1Beta3Client) GetJobMetrics(ctx context.Context, req *dataflowpb.GetJobMetricsRequest, opts ...gax.CallOption) (*dataflowpb.JobMetrics, error) { + return c.internalClient.GetJobMetrics(ctx, req, opts...) +} + +// GetJobExecutionDetails request detailed information about the execution status of the job. +// +// EXPERIMENTAL. This API is subject to change or removal without notice. +func (c *MetricsV1Beta3Client) GetJobExecutionDetails(ctx context.Context, req *dataflowpb.GetJobExecutionDetailsRequest, opts ...gax.CallOption) *StageSummaryIterator { + return c.internalClient.GetJobExecutionDetails(ctx, req, opts...) +} + +// GetStageExecutionDetails request detailed information about the execution status of a stage of the +// job. +// +// EXPERIMENTAL. This API is subject to change or removal without notice. +func (c *MetricsV1Beta3Client) GetStageExecutionDetails(ctx context.Context, req *dataflowpb.GetStageExecutionDetailsRequest, opts ...gax.CallOption) *WorkerDetailsIterator { + return c.internalClient.GetStageExecutionDetails(ctx, req, opts...) +} + +// metricsV1Beta3GRPCClient is a client for interacting with Dataflow API over gRPC transport. +// +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +type metricsV1Beta3GRPCClient 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 MetricsV1Beta3Client + CallOptions **MetricsV1Beta3CallOptions + + // The gRPC API client. + metricsV1Beta3Client dataflowpb.MetricsV1Beta3Client + + // The x-goog-* metadata to be sent with each request. + xGoogMetadata metadata.MD +} + +// NewMetricsV1Beta3Client creates a new metrics v1 beta3 client based on gRPC. +// The returned client must be Closed when it is done being used to clean up its underlying connections. +// +// The Dataflow Metrics API lets you monitor the progress of Dataflow +// jobs. +func NewMetricsV1Beta3Client(ctx context.Context, opts ...option.ClientOption) (*MetricsV1Beta3Client, error) { + clientOpts := defaultMetricsV1Beta3GRPCClientOptions() + if newMetricsV1Beta3ClientHook != nil { + hookOpts, err := newMetricsV1Beta3ClientHook(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 := MetricsV1Beta3Client{CallOptions: defaultMetricsV1Beta3CallOptions()} + + c := &metricsV1Beta3GRPCClient{ + connPool: connPool, + disableDeadlines: disableDeadlines, + metricsV1Beta3Client: dataflowpb.NewMetricsV1Beta3Client(connPool), + CallOptions: &client.CallOptions, + } + c.setGoogleClientInfo() + + client.internalClient = c + + return &client, nil +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *metricsV1Beta3GRPCClient) 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 *metricsV1Beta3GRPCClient) 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 *metricsV1Beta3GRPCClient) Close() error { + return c.connPool.Close() +} + +func (c *metricsV1Beta3GRPCClient) GetJobMetrics(ctx context.Context, req *dataflowpb.GetJobMetricsRequest, opts ...gax.CallOption) (*dataflowpb.JobMetrics, error) { + if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { + cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond) + defer cancel() + ctx = cctx + } + ctx = insertMetadata(ctx, c.xGoogMetadata) + opts = append((*c.CallOptions).GetJobMetrics[0:len((*c.CallOptions).GetJobMetrics):len((*c.CallOptions).GetJobMetrics)], opts...) + var resp *dataflowpb.JobMetrics + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.metricsV1Beta3Client.GetJobMetrics(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} + +func (c *metricsV1Beta3GRPCClient) GetJobExecutionDetails(ctx context.Context, req *dataflowpb.GetJobExecutionDetailsRequest, opts ...gax.CallOption) *StageSummaryIterator { + ctx = insertMetadata(ctx, c.xGoogMetadata) + opts = append((*c.CallOptions).GetJobExecutionDetails[0:len((*c.CallOptions).GetJobExecutionDetails):len((*c.CallOptions).GetJobExecutionDetails)], opts...) + it := &StageSummaryIterator{} + req = proto.Clone(req).(*dataflowpb.GetJobExecutionDetailsRequest) + it.InternalFetch = func(pageSize int, pageToken string) ([]*dataflowpb.StageSummary, string, error) { + var resp *dataflowpb.JobExecutionDetails + 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.metricsV1Beta3Client.GetJobExecutionDetails(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, "", err + } + + it.Response = resp + return resp.GetStages(), 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 *metricsV1Beta3GRPCClient) GetStageExecutionDetails(ctx context.Context, req *dataflowpb.GetStageExecutionDetailsRequest, opts ...gax.CallOption) *WorkerDetailsIterator { + ctx = insertMetadata(ctx, c.xGoogMetadata) + opts = append((*c.CallOptions).GetStageExecutionDetails[0:len((*c.CallOptions).GetStageExecutionDetails):len((*c.CallOptions).GetStageExecutionDetails)], opts...) + it := &WorkerDetailsIterator{} + req = proto.Clone(req).(*dataflowpb.GetStageExecutionDetailsRequest) + it.InternalFetch = func(pageSize int, pageToken string) ([]*dataflowpb.WorkerDetails, string, error) { + var resp *dataflowpb.StageExecutionDetails + 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.metricsV1Beta3Client.GetStageExecutionDetails(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, "", err + } + + it.Response = resp + return resp.GetWorkers(), 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 +} + +// StageSummaryIterator manages a stream of *dataflowpb.StageSummary. +type StageSummaryIterator struct { + items []*dataflowpb.StageSummary + 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 []*dataflowpb.StageSummary, nextPageToken string, err error) +} + +// PageInfo supports pagination. See the google.golang.org/api/iterator package for details. +func (it *StageSummaryIterator) 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 *StageSummaryIterator) Next() (*dataflowpb.StageSummary, error) { + var item *dataflowpb.StageSummary + if err := it.nextFunc(); err != nil { + return item, err + } + item = it.items[0] + it.items = it.items[1:] + return item, nil +} + +func (it *StageSummaryIterator) bufLen() int { + return len(it.items) +} + +func (it *StageSummaryIterator) takeBuf() interface{} { + b := it.items + it.items = nil + return b +} + +// WorkerDetailsIterator manages a stream of *dataflowpb.WorkerDetails. +type WorkerDetailsIterator struct { + items []*dataflowpb.WorkerDetails + 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 []*dataflowpb.WorkerDetails, nextPageToken string, err error) +} + +// PageInfo supports pagination. See the google.golang.org/api/iterator package for details. +func (it *WorkerDetailsIterator) 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 *WorkerDetailsIterator) Next() (*dataflowpb.WorkerDetails, error) { + var item *dataflowpb.WorkerDetails + if err := it.nextFunc(); err != nil { + return item, err + } + item = it.items[0] + it.items = it.items[1:] + return item, nil +} + +func (it *WorkerDetailsIterator) bufLen() int { + return len(it.items) +} + +func (it *WorkerDetailsIterator) takeBuf() interface{} { + b := it.items + it.items = nil + return b +} diff --git a/dataflow/apiv1beta3/metrics_v1_beta3_client_example_test.go b/dataflow/apiv1beta3/metrics_v1_beta3_client_example_test.go new file mode 100644 index 00000000000..7677189c786 --- /dev/null +++ b/dataflow/apiv1beta3/metrics_v1_beta3_client_example_test.go @@ -0,0 +1,106 @@ +// 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 dataflow_test + +import ( + "context" + + dataflow "cloud.google.com/go/dataflow/apiv1beta3" + "google.golang.org/api/iterator" + dataflowpb "google.golang.org/genproto/googleapis/dataflow/v1beta3" +) + +func ExampleNewMetricsV1Beta3Client() { + ctx := context.Background() + c, err := dataflow.NewMetricsV1Beta3Client(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + // TODO: Use client. + _ = c +} + +func ExampleMetricsV1Beta3Client_GetJobMetrics() { + ctx := context.Background() + c, err := dataflow.NewMetricsV1Beta3Client(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &dataflowpb.GetJobMetricsRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.GetJobMetrics(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleMetricsV1Beta3Client_GetJobExecutionDetails() { + ctx := context.Background() + c, err := dataflow.NewMetricsV1Beta3Client(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &dataflowpb.GetJobExecutionDetailsRequest{ + // TODO: Fill request struct fields. + } + it := c.GetJobExecutionDetails(ctx, req) + for { + resp, err := it.Next() + if err == iterator.Done { + break + } + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp + } +} + +func ExampleMetricsV1Beta3Client_GetStageExecutionDetails() { + ctx := context.Background() + c, err := dataflow.NewMetricsV1Beta3Client(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &dataflowpb.GetStageExecutionDetailsRequest{ + // TODO: Fill request struct fields. + } + it := c.GetStageExecutionDetails(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/dataflow/apiv1beta3/snapshots_v1_beta3_client.go b/dataflow/apiv1beta3/snapshots_v1_beta3_client.go new file mode 100644 index 00000000000..212281bc7d4 --- /dev/null +++ b/dataflow/apiv1beta3/snapshots_v1_beta3_client.go @@ -0,0 +1,260 @@ +// 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 dataflow + +import ( + "context" + "math" + "time" + + 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" + dataflowpb "google.golang.org/genproto/googleapis/dataflow/v1beta3" + "google.golang.org/grpc" + "google.golang.org/grpc/metadata" +) + +var newSnapshotsV1Beta3ClientHook clientHook + +// SnapshotsV1Beta3CallOptions contains the retry settings for each method of SnapshotsV1Beta3Client. +type SnapshotsV1Beta3CallOptions struct { + GetSnapshot []gax.CallOption + DeleteSnapshot []gax.CallOption + ListSnapshots []gax.CallOption +} + +func defaultSnapshotsV1Beta3GRPCClientOptions() []option.ClientOption { + return []option.ClientOption{ + internaloption.WithDefaultEndpoint("dataflow.googleapis.com:443"), + internaloption.WithDefaultMTLSEndpoint("dataflow.mtls.googleapis.com:443"), + internaloption.WithDefaultAudience("https://dataflow.googleapis.com/"), + internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), + option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), + option.WithGRPCDialOption(grpc.WithDefaultCallOptions( + grpc.MaxCallRecvMsgSize(math.MaxInt32))), + } +} + +func defaultSnapshotsV1Beta3CallOptions() *SnapshotsV1Beta3CallOptions { + return &SnapshotsV1Beta3CallOptions{ + GetSnapshot: []gax.CallOption{}, + DeleteSnapshot: []gax.CallOption{}, + ListSnapshots: []gax.CallOption{}, + } +} + +// internalSnapshotsV1Beta3Client is an interface that defines the methods availaible from Dataflow API. +type internalSnapshotsV1Beta3Client interface { + Close() error + setGoogleClientInfo(...string) + Connection() *grpc.ClientConn + GetSnapshot(context.Context, *dataflowpb.GetSnapshotRequest, ...gax.CallOption) (*dataflowpb.Snapshot, error) + DeleteSnapshot(context.Context, *dataflowpb.DeleteSnapshotRequest, ...gax.CallOption) (*dataflowpb.DeleteSnapshotResponse, error) + ListSnapshots(context.Context, *dataflowpb.ListSnapshotsRequest, ...gax.CallOption) (*dataflowpb.ListSnapshotsResponse, error) +} + +// SnapshotsV1Beta3Client is a client for interacting with Dataflow API. +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +// +// Provides methods to manage snapshots of Google Cloud Dataflow jobs. +type SnapshotsV1Beta3Client struct { + // The internal transport-dependent client. + internalClient internalSnapshotsV1Beta3Client + + // The call options for this service. + CallOptions *SnapshotsV1Beta3CallOptions +} + +// 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 *SnapshotsV1Beta3Client) 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 *SnapshotsV1Beta3Client) setGoogleClientInfo(keyval ...string) { + c.internalClient.setGoogleClientInfo(keyval...) +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *SnapshotsV1Beta3Client) Connection() *grpc.ClientConn { + return c.internalClient.Connection() +} + +// GetSnapshot gets information about a snapshot. +func (c *SnapshotsV1Beta3Client) GetSnapshot(ctx context.Context, req *dataflowpb.GetSnapshotRequest, opts ...gax.CallOption) (*dataflowpb.Snapshot, error) { + return c.internalClient.GetSnapshot(ctx, req, opts...) +} + +// DeleteSnapshot deletes a snapshot. +func (c *SnapshotsV1Beta3Client) DeleteSnapshot(ctx context.Context, req *dataflowpb.DeleteSnapshotRequest, opts ...gax.CallOption) (*dataflowpb.DeleteSnapshotResponse, error) { + return c.internalClient.DeleteSnapshot(ctx, req, opts...) +} + +// ListSnapshots lists snapshots. +func (c *SnapshotsV1Beta3Client) ListSnapshots(ctx context.Context, req *dataflowpb.ListSnapshotsRequest, opts ...gax.CallOption) (*dataflowpb.ListSnapshotsResponse, error) { + return c.internalClient.ListSnapshots(ctx, req, opts...) +} + +// snapshotsV1Beta3GRPCClient is a client for interacting with Dataflow API over gRPC transport. +// +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +type snapshotsV1Beta3GRPCClient 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 SnapshotsV1Beta3Client + CallOptions **SnapshotsV1Beta3CallOptions + + // The gRPC API client. + snapshotsV1Beta3Client dataflowpb.SnapshotsV1Beta3Client + + // The x-goog-* metadata to be sent with each request. + xGoogMetadata metadata.MD +} + +// NewSnapshotsV1Beta3Client creates a new snapshots v1 beta3 client based on gRPC. +// The returned client must be Closed when it is done being used to clean up its underlying connections. +// +// Provides methods to manage snapshots of Google Cloud Dataflow jobs. +func NewSnapshotsV1Beta3Client(ctx context.Context, opts ...option.ClientOption) (*SnapshotsV1Beta3Client, error) { + clientOpts := defaultSnapshotsV1Beta3GRPCClientOptions() + if newSnapshotsV1Beta3ClientHook != nil { + hookOpts, err := newSnapshotsV1Beta3ClientHook(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 := SnapshotsV1Beta3Client{CallOptions: defaultSnapshotsV1Beta3CallOptions()} + + c := &snapshotsV1Beta3GRPCClient{ + connPool: connPool, + disableDeadlines: disableDeadlines, + snapshotsV1Beta3Client: dataflowpb.NewSnapshotsV1Beta3Client(connPool), + CallOptions: &client.CallOptions, + } + c.setGoogleClientInfo() + + client.internalClient = c + + return &client, nil +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *snapshotsV1Beta3GRPCClient) 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 *snapshotsV1Beta3GRPCClient) 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 *snapshotsV1Beta3GRPCClient) Close() error { + return c.connPool.Close() +} + +func (c *snapshotsV1Beta3GRPCClient) GetSnapshot(ctx context.Context, req *dataflowpb.GetSnapshotRequest, opts ...gax.CallOption) (*dataflowpb.Snapshot, error) { + if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { + cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond) + defer cancel() + ctx = cctx + } + ctx = insertMetadata(ctx, c.xGoogMetadata) + opts = append((*c.CallOptions).GetSnapshot[0:len((*c.CallOptions).GetSnapshot):len((*c.CallOptions).GetSnapshot)], opts...) + var resp *dataflowpb.Snapshot + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.snapshotsV1Beta3Client.GetSnapshot(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} + +func (c *snapshotsV1Beta3GRPCClient) DeleteSnapshot(ctx context.Context, req *dataflowpb.DeleteSnapshotRequest, opts ...gax.CallOption) (*dataflowpb.DeleteSnapshotResponse, error) { + if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { + cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond) + defer cancel() + ctx = cctx + } + ctx = insertMetadata(ctx, c.xGoogMetadata) + opts = append((*c.CallOptions).DeleteSnapshot[0:len((*c.CallOptions).DeleteSnapshot):len((*c.CallOptions).DeleteSnapshot)], opts...) + var resp *dataflowpb.DeleteSnapshotResponse + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.snapshotsV1Beta3Client.DeleteSnapshot(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} + +func (c *snapshotsV1Beta3GRPCClient) ListSnapshots(ctx context.Context, req *dataflowpb.ListSnapshotsRequest, opts ...gax.CallOption) (*dataflowpb.ListSnapshotsResponse, error) { + if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { + cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond) + defer cancel() + ctx = cctx + } + ctx = insertMetadata(ctx, c.xGoogMetadata) + opts = append((*c.CallOptions).ListSnapshots[0:len((*c.CallOptions).ListSnapshots):len((*c.CallOptions).ListSnapshots)], opts...) + var resp *dataflowpb.ListSnapshotsResponse + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.snapshotsV1Beta3Client.ListSnapshots(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} diff --git a/dataflow/apiv1beta3/snapshots_v1_beta3_client_example_test.go b/dataflow/apiv1beta3/snapshots_v1_beta3_client_example_test.go new file mode 100644 index 00000000000..3c41e38f62b --- /dev/null +++ b/dataflow/apiv1beta3/snapshots_v1_beta3_client_example_test.go @@ -0,0 +1,93 @@ +// 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 dataflow_test + +import ( + "context" + + dataflow "cloud.google.com/go/dataflow/apiv1beta3" + dataflowpb "google.golang.org/genproto/googleapis/dataflow/v1beta3" +) + +func ExampleNewSnapshotsV1Beta3Client() { + ctx := context.Background() + c, err := dataflow.NewSnapshotsV1Beta3Client(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + // TODO: Use client. + _ = c +} + +func ExampleSnapshotsV1Beta3Client_GetSnapshot() { + ctx := context.Background() + c, err := dataflow.NewSnapshotsV1Beta3Client(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &dataflowpb.GetSnapshotRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.GetSnapshot(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleSnapshotsV1Beta3Client_DeleteSnapshot() { + ctx := context.Background() + c, err := dataflow.NewSnapshotsV1Beta3Client(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &dataflowpb.DeleteSnapshotRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.DeleteSnapshot(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleSnapshotsV1Beta3Client_ListSnapshots() { + ctx := context.Background() + c, err := dataflow.NewSnapshotsV1Beta3Client(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &dataflowpb.ListSnapshotsRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.ListSnapshots(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} diff --git a/dataflow/apiv1beta3/templates_client.go b/dataflow/apiv1beta3/templates_client.go new file mode 100644 index 00000000000..856ad73d5e4 --- /dev/null +++ b/dataflow/apiv1beta3/templates_client.go @@ -0,0 +1,260 @@ +// 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 dataflow + +import ( + "context" + "math" + "time" + + 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" + dataflowpb "google.golang.org/genproto/googleapis/dataflow/v1beta3" + "google.golang.org/grpc" + "google.golang.org/grpc/metadata" +) + +var newTemplatesClientHook clientHook + +// TemplatesCallOptions contains the retry settings for each method of TemplatesClient. +type TemplatesCallOptions struct { + CreateJobFromTemplate []gax.CallOption + LaunchTemplate []gax.CallOption + GetTemplate []gax.CallOption +} + +func defaultTemplatesGRPCClientOptions() []option.ClientOption { + return []option.ClientOption{ + internaloption.WithDefaultEndpoint("dataflow.googleapis.com:443"), + internaloption.WithDefaultMTLSEndpoint("dataflow.mtls.googleapis.com:443"), + internaloption.WithDefaultAudience("https://dataflow.googleapis.com/"), + internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), + option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), + option.WithGRPCDialOption(grpc.WithDefaultCallOptions( + grpc.MaxCallRecvMsgSize(math.MaxInt32))), + } +} + +func defaultTemplatesCallOptions() *TemplatesCallOptions { + return &TemplatesCallOptions{ + CreateJobFromTemplate: []gax.CallOption{}, + LaunchTemplate: []gax.CallOption{}, + GetTemplate: []gax.CallOption{}, + } +} + +// internalTemplatesClient is an interface that defines the methods availaible from Dataflow API. +type internalTemplatesClient interface { + Close() error + setGoogleClientInfo(...string) + Connection() *grpc.ClientConn + CreateJobFromTemplate(context.Context, *dataflowpb.CreateJobFromTemplateRequest, ...gax.CallOption) (*dataflowpb.Job, error) + LaunchTemplate(context.Context, *dataflowpb.LaunchTemplateRequest, ...gax.CallOption) (*dataflowpb.LaunchTemplateResponse, error) + GetTemplate(context.Context, *dataflowpb.GetTemplateRequest, ...gax.CallOption) (*dataflowpb.GetTemplateResponse, error) +} + +// TemplatesClient is a client for interacting with Dataflow API. +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +// +// Provides a method to create Cloud Dataflow jobs from templates. +type TemplatesClient struct { + // The internal transport-dependent client. + internalClient internalTemplatesClient + + // The call options for this service. + CallOptions *TemplatesCallOptions +} + +// 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 *TemplatesClient) 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 *TemplatesClient) setGoogleClientInfo(keyval ...string) { + c.internalClient.setGoogleClientInfo(keyval...) +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *TemplatesClient) Connection() *grpc.ClientConn { + return c.internalClient.Connection() +} + +// CreateJobFromTemplate creates a Cloud Dataflow job from a template. +func (c *TemplatesClient) CreateJobFromTemplate(ctx context.Context, req *dataflowpb.CreateJobFromTemplateRequest, opts ...gax.CallOption) (*dataflowpb.Job, error) { + return c.internalClient.CreateJobFromTemplate(ctx, req, opts...) +} + +// LaunchTemplate launch a template. +func (c *TemplatesClient) LaunchTemplate(ctx context.Context, req *dataflowpb.LaunchTemplateRequest, opts ...gax.CallOption) (*dataflowpb.LaunchTemplateResponse, error) { + return c.internalClient.LaunchTemplate(ctx, req, opts...) +} + +// GetTemplate get the template associated with a template. +func (c *TemplatesClient) GetTemplate(ctx context.Context, req *dataflowpb.GetTemplateRequest, opts ...gax.CallOption) (*dataflowpb.GetTemplateResponse, error) { + return c.internalClient.GetTemplate(ctx, req, opts...) +} + +// templatesGRPCClient is a client for interacting with Dataflow API over gRPC transport. +// +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +type templatesGRPCClient 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 TemplatesClient + CallOptions **TemplatesCallOptions + + // The gRPC API client. + templatesClient dataflowpb.TemplatesServiceClient + + // The x-goog-* metadata to be sent with each request. + xGoogMetadata metadata.MD +} + +// NewTemplatesClient creates a new templates service client based on gRPC. +// The returned client must be Closed when it is done being used to clean up its underlying connections. +// +// Provides a method to create Cloud Dataflow jobs from templates. +func NewTemplatesClient(ctx context.Context, opts ...option.ClientOption) (*TemplatesClient, error) { + clientOpts := defaultTemplatesGRPCClientOptions() + if newTemplatesClientHook != nil { + hookOpts, err := newTemplatesClientHook(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 := TemplatesClient{CallOptions: defaultTemplatesCallOptions()} + + c := &templatesGRPCClient{ + connPool: connPool, + disableDeadlines: disableDeadlines, + templatesClient: dataflowpb.NewTemplatesServiceClient(connPool), + CallOptions: &client.CallOptions, + } + c.setGoogleClientInfo() + + client.internalClient = c + + return &client, nil +} + +// Connection returns a connection to the API service. +// +// Deprecated. +func (c *templatesGRPCClient) 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 *templatesGRPCClient) 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 *templatesGRPCClient) Close() error { + return c.connPool.Close() +} + +func (c *templatesGRPCClient) CreateJobFromTemplate(ctx context.Context, req *dataflowpb.CreateJobFromTemplateRequest, opts ...gax.CallOption) (*dataflowpb.Job, error) { + if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { + cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond) + defer cancel() + ctx = cctx + } + ctx = insertMetadata(ctx, c.xGoogMetadata) + opts = append((*c.CallOptions).CreateJobFromTemplate[0:len((*c.CallOptions).CreateJobFromTemplate):len((*c.CallOptions).CreateJobFromTemplate)], opts...) + var resp *dataflowpb.Job + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.templatesClient.CreateJobFromTemplate(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} + +func (c *templatesGRPCClient) LaunchTemplate(ctx context.Context, req *dataflowpb.LaunchTemplateRequest, opts ...gax.CallOption) (*dataflowpb.LaunchTemplateResponse, error) { + if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { + cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond) + defer cancel() + ctx = cctx + } + ctx = insertMetadata(ctx, c.xGoogMetadata) + opts = append((*c.CallOptions).LaunchTemplate[0:len((*c.CallOptions).LaunchTemplate):len((*c.CallOptions).LaunchTemplate)], opts...) + var resp *dataflowpb.LaunchTemplateResponse + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.templatesClient.LaunchTemplate(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} + +func (c *templatesGRPCClient) GetTemplate(ctx context.Context, req *dataflowpb.GetTemplateRequest, opts ...gax.CallOption) (*dataflowpb.GetTemplateResponse, error) { + if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { + cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond) + defer cancel() + ctx = cctx + } + ctx = insertMetadata(ctx, c.xGoogMetadata) + opts = append((*c.CallOptions).GetTemplate[0:len((*c.CallOptions).GetTemplate):len((*c.CallOptions).GetTemplate)], opts...) + var resp *dataflowpb.GetTemplateResponse + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.templatesClient.GetTemplate(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} diff --git a/dataflow/apiv1beta3/templates_client_example_test.go b/dataflow/apiv1beta3/templates_client_example_test.go new file mode 100644 index 00000000000..16bc0ab021b --- /dev/null +++ b/dataflow/apiv1beta3/templates_client_example_test.go @@ -0,0 +1,93 @@ +// 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 dataflow_test + +import ( + "context" + + dataflow "cloud.google.com/go/dataflow/apiv1beta3" + dataflowpb "google.golang.org/genproto/googleapis/dataflow/v1beta3" +) + +func ExampleNewTemplatesClient() { + ctx := context.Background() + c, err := dataflow.NewTemplatesClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + // TODO: Use client. + _ = c +} + +func ExampleTemplatesClient_CreateJobFromTemplate() { + ctx := context.Background() + c, err := dataflow.NewTemplatesClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &dataflowpb.CreateJobFromTemplateRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.CreateJobFromTemplate(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleTemplatesClient_LaunchTemplate() { + ctx := context.Background() + c, err := dataflow.NewTemplatesClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &dataflowpb.LaunchTemplateRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.LaunchTemplate(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleTemplatesClient_GetTemplate() { + ctx := context.Background() + c, err := dataflow.NewTemplatesClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &dataflowpb.GetTemplateRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.GetTemplate(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} diff --git a/datalabeling/apiv1beta1/data_labeling_client.go b/datalabeling/apiv1beta1/data_labeling_client.go index cce4cdb7f18..61a191faaaf 100644 --- a/datalabeling/apiv1beta1/data_labeling_client.go +++ b/datalabeling/apiv1beta1/data_labeling_client.go @@ -25,7 +25,6 @@ import ( "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" @@ -36,6 +35,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newClientHook clientHook @@ -84,6 +84,7 @@ func defaultGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("datalabeling.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://datalabeling.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/datalabeling/apiv1beta1/doc.go b/datalabeling/apiv1beta1/doc.go index b2202fa0968..8058caf4596 100644 --- a/datalabeling/apiv1beta1/doc.go +++ b/datalabeling/apiv1beta1/doc.go @@ -50,7 +50,7 @@ import ( type clientHookParams struct{} type clientHook func(context.Context, clientHookParams) ([]option.ClientOption, error) -const versionClient = "20210612" +const versionClient = "20210701" func insertMetadata(ctx context.Context, mds ...metadata.MD) context.Context { out, _ := metadata.FromOutgoingContext(ctx) diff --git a/dataproc/apiv1/autoscaling_policy_client.go b/dataproc/apiv1/autoscaling_policy_client.go index 9b03812064d..a94c109486a 100644 --- a/dataproc/apiv1/autoscaling_policy_client.go +++ b/dataproc/apiv1/autoscaling_policy_client.go @@ -23,7 +23,6 @@ import ( "net/url" "time" - "github.com/golang/protobuf/proto" gax "github.com/googleapis/gax-go/v2" "google.golang.org/api/iterator" "google.golang.org/api/option" @@ -33,6 +32,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newAutoscalingPolicyClientHook clientHook @@ -52,6 +52,7 @@ func defaultAutoscalingPolicyGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("dataproc.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://dataproc.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/dataproc/apiv1/cluster_controller_client.go b/dataproc/apiv1/cluster_controller_client.go index 57f6257732e..d56b657af72 100644 --- a/dataproc/apiv1/cluster_controller_client.go +++ b/dataproc/apiv1/cluster_controller_client.go @@ -25,7 +25,6 @@ import ( "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" @@ -36,6 +35,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newClusterControllerClientHook clientHook @@ -58,6 +58,7 @@ func defaultClusterControllerGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("dataproc.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://dataproc.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/dataproc/apiv1/doc.go b/dataproc/apiv1/doc.go index c0046ebd0f6..69c90b1e10b 100644 --- a/dataproc/apiv1/doc.go +++ b/dataproc/apiv1/doc.go @@ -48,7 +48,7 @@ import ( type clientHookParams struct{} type clientHook func(context.Context, clientHookParams) ([]option.ClientOption, error) -const versionClient = "20210612" +const versionClient = "20210701" func insertMetadata(ctx context.Context, mds ...metadata.MD) context.Context { out, _ := metadata.FromOutgoingContext(ctx) diff --git a/dataproc/apiv1/job_controller_client.go b/dataproc/apiv1/job_controller_client.go index 7f4bd45f05a..55f7e6f68e5 100644 --- a/dataproc/apiv1/job_controller_client.go +++ b/dataproc/apiv1/job_controller_client.go @@ -25,7 +25,6 @@ import ( "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" @@ -36,6 +35,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newJobControllerClientHook clientHook @@ -57,6 +57,7 @@ func defaultJobControllerGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("dataproc.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://dataproc.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/dataproc/apiv1/workflow_template_client.go b/dataproc/apiv1/workflow_template_client.go index 463daa99bb4..20b85241a68 100644 --- a/dataproc/apiv1/workflow_template_client.go +++ b/dataproc/apiv1/workflow_template_client.go @@ -25,7 +25,6 @@ import ( "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" @@ -36,6 +35,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newWorkflowTemplateClientHook clientHook @@ -57,6 +57,7 @@ func defaultWorkflowTemplateGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("dataproc.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://dataproc.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/dataproc/apiv1beta2/autoscaling_policy_client.go b/dataproc/apiv1beta2/autoscaling_policy_client.go index a6ae2eb7458..13232d64c49 100644 --- a/dataproc/apiv1beta2/autoscaling_policy_client.go +++ b/dataproc/apiv1beta2/autoscaling_policy_client.go @@ -23,7 +23,6 @@ import ( "net/url" "time" - "github.com/golang/protobuf/proto" gax "github.com/googleapis/gax-go/v2" "google.golang.org/api/iterator" "google.golang.org/api/option" @@ -33,6 +32,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newAutoscalingPolicyClientHook clientHook @@ -52,6 +52,7 @@ func defaultAutoscalingPolicyGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("dataproc.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://dataproc.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/dataproc/apiv1beta2/cluster_controller_client.go b/dataproc/apiv1beta2/cluster_controller_client.go index fa8cc6d6325..f7847cbff80 100644 --- a/dataproc/apiv1beta2/cluster_controller_client.go +++ b/dataproc/apiv1beta2/cluster_controller_client.go @@ -25,7 +25,6 @@ import ( "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" @@ -36,6 +35,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newClusterControllerClientHook clientHook @@ -56,6 +56,7 @@ func defaultClusterControllerGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("dataproc.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://dataproc.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/dataproc/apiv1beta2/doc.go b/dataproc/apiv1beta2/doc.go index a070ab717b5..667e018c5f0 100644 --- a/dataproc/apiv1beta2/doc.go +++ b/dataproc/apiv1beta2/doc.go @@ -50,7 +50,7 @@ import ( type clientHookParams struct{} type clientHook func(context.Context, clientHookParams) ([]option.ClientOption, error) -const versionClient = "20210612" +const versionClient = "20210701" func insertMetadata(ctx context.Context, mds ...metadata.MD) context.Context { out, _ := metadata.FromOutgoingContext(ctx) diff --git a/dataproc/apiv1beta2/job_controller_client.go b/dataproc/apiv1beta2/job_controller_client.go index c315ea3833c..4910000d2b1 100644 --- a/dataproc/apiv1beta2/job_controller_client.go +++ b/dataproc/apiv1beta2/job_controller_client.go @@ -25,7 +25,6 @@ import ( "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" @@ -36,6 +35,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newJobControllerClientHook clientHook @@ -57,6 +57,7 @@ func defaultJobControllerGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("dataproc.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://dataproc.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/dataproc/apiv1beta2/workflow_template_client.go b/dataproc/apiv1beta2/workflow_template_client.go index 905001ff8da..620f9441a5d 100644 --- a/dataproc/apiv1beta2/workflow_template_client.go +++ b/dataproc/apiv1beta2/workflow_template_client.go @@ -25,7 +25,6 @@ import ( "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" @@ -36,6 +35,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newWorkflowTemplateClientHook clientHook @@ -57,6 +57,7 @@ func defaultWorkflowTemplateGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("dataproc.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://dataproc.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/dataqna/apiv1alpha/auto_suggestion_client.go b/dataqna/apiv1alpha/auto_suggestion_client.go index 0ca05d234dc..783980ac9fd 100644 --- a/dataqna/apiv1alpha/auto_suggestion_client.go +++ b/dataqna/apiv1alpha/auto_suggestion_client.go @@ -45,6 +45,7 @@ func defaultAutoSuggestionGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("dataqna.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://dataqna.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/dataqna/apiv1alpha/doc.go b/dataqna/apiv1alpha/doc.go index 72ef5100e29..5d3e59576c6 100644 --- a/dataqna/apiv1alpha/doc.go +++ b/dataqna/apiv1alpha/doc.go @@ -51,7 +51,7 @@ import ( type clientHookParams struct{} type clientHook func(context.Context, clientHookParams) ([]option.ClientOption, error) -const versionClient = "20210612" +const versionClient = "20210701" func insertMetadata(ctx context.Context, mds ...metadata.MD) context.Context { out, _ := metadata.FromOutgoingContext(ctx) diff --git a/dataqna/apiv1alpha/question_client.go b/dataqna/apiv1alpha/question_client.go index 198a6334fd4..7958afba6fe 100644 --- a/dataqna/apiv1alpha/question_client.go +++ b/dataqna/apiv1alpha/question_client.go @@ -50,6 +50,7 @@ func defaultQuestionGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("dataqna.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://dataqna.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/datastore/admin/apiv1/datastore_admin_client.go b/datastore/admin/apiv1/datastore_admin_client.go index 2308019b759..a2225bf5a6d 100644 --- a/datastore/admin/apiv1/datastore_admin_client.go +++ b/datastore/admin/apiv1/datastore_admin_client.go @@ -25,7 +25,6 @@ import ( "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" @@ -36,6 +35,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newDatastoreAdminClientHook clientHook @@ -56,6 +56,7 @@ func defaultDatastoreAdminGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("datastore.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://datastore.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/datastore/admin/apiv1/doc.go b/datastore/admin/apiv1/doc.go index e5a866fd7ea..fad25e838c2 100644 --- a/datastore/admin/apiv1/doc.go +++ b/datastore/admin/apiv1/doc.go @@ -51,7 +51,7 @@ import ( type clientHookParams struct{} type clientHook func(context.Context, clientHookParams) ([]option.ClientOption, error) -const versionClient = "20210612" +const versionClient = "20210701" func insertMetadata(ctx context.Context, mds ...metadata.MD) context.Context { out, _ := metadata.FromOutgoingContext(ctx) diff --git a/datastore/go.mod b/datastore/go.mod index 99070a850a7..d9b084df589 100644 --- a/datastore/go.mod +++ b/datastore/go.mod @@ -7,8 +7,8 @@ require ( github.com/golang/protobuf v1.5.2 github.com/google/go-cmp v0.5.6 github.com/googleapis/gax-go/v2 v2.0.5 - google.golang.org/api v0.48.0 - google.golang.org/genproto v0.0.0-20210614143202-012ab6975634 + google.golang.org/api v0.50.0 + google.golang.org/genproto v0.0.0-20210701133433-6b8dcf568a95 google.golang.org/grpc v1.38.0 - google.golang.org/protobuf v1.26.0 + google.golang.org/protobuf v1.27.1 ) diff --git a/datastore/go.sum b/datastore/go.sum index 51829ee2af9..aa8fd5de0a2 100644 --- a/datastore/go.sum +++ b/datastore/go.sum @@ -248,8 +248,9 @@ golang.org/x/oauth2 v0.0.0-20201208152858-08078c50e5b5/go.mod h1:KelEdhl1UZF7XfJ golang.org/x/oauth2 v0.0.0-20210218202405-ba52d332ba99/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= golang.org/x/oauth2 v0.0.0-20210220000619-9bb904979d93/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= golang.org/x/oauth2 v0.0.0-20210313182246-cd4f82c27b84/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= -golang.org/x/oauth2 v0.0.0-20210514164344-f6687ab2804c h1:pkQiBZBvdos9qq4wBAHqlzuZHEXo07pqV06ef90u1WI= golang.org/x/oauth2 v0.0.0-20210514164344-f6687ab2804c/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= +golang.org/x/oauth2 v0.0.0-20210628180205-a41e5a781914 h1:3B43BWw0xEBsLZ/NO1VALz6fppU3481pik+2Ksv45z8= +golang.org/x/oauth2 v0.0.0-20210628180205-a41e5a781914/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= @@ -300,8 +301,9 @@ golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210514084401-e8d321eab015/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20210603125802-9665404d3644 h1:CA1DEQ4NdKphKeL70tvsWNdT5oFh1lOjihRcEDROi0I= golang.org/x/sys v0.0.0-20210603125802-9665404d3644/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20210616094352-59db8d763f22 h1:RqytpXGR1iVNX7psjB3ff8y7sNFinVFvkx1c8SjBkio= +golang.org/x/sys v0.0.0-20210616094352-59db8d763f22/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= @@ -363,8 +365,9 @@ golang.org/x/tools v0.0.0-20210105154028-b0ab187a4818/go.mod h1:emZCQorbCU4vsT4f golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0= golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.2/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= -golang.org/x/tools v0.1.3 h1:L69ShwSZEyCsLKoAxDKeMvLDZkumEe8gXUZAjab0tX8= golang.org/x/tools v0.1.3/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= +golang.org/x/tools v0.1.4 h1:cVngSRcfgyZCzys3KYOpCFa+4dqX/Oub9tAq00ttGVs= +golang.org/x/tools v0.1.4/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= @@ -392,8 +395,9 @@ google.golang.org/api v0.40.0/go.mod h1:fYKFpnQN0DsDSKRVRcQSDQNtqWPfM9i+zNPxepjR google.golang.org/api v0.41.0/go.mod h1:RkxM5lITDfTzmyKFPt+wGrCJbVfniCr2ool8kTBzRTU= google.golang.org/api v0.43.0/go.mod h1:nQsDGjRXMo4lvh5hP0TKqF244gqhGcr/YSIykhUk/94= google.golang.org/api v0.47.0/go.mod h1:Wbvgpq1HddcWVtzsVLyfLp8lDg6AA241LmgIL59tHXo= -google.golang.org/api v0.48.0 h1:RDAPWfNFY06dffEXfn7hZF5Fr1ZbnChzfQZAPyBd1+I= google.golang.org/api v0.48.0/go.mod h1:71Pr1vy+TAZRPkPs/xlCf5SsU8WjuAWv1Pfjbtukyy4= +google.golang.org/api v0.50.0 h1:LX7NFCFYOHzr7WHaYiRUpeipZe9o5L8T+2F4Z798VDw= +google.golang.org/api v0.50.0/go.mod h1:4bNT5pAuq5ji4SRZm+5QIkjny9JAyVD/3gaSihNefaw= google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= google.golang.org/appengine v1.5.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= @@ -445,8 +449,9 @@ google.golang.org/genproto v0.0.0-20210513213006-bf773b8c8384/go.mod h1:P3QM42oQ google.golang.org/genproto v0.0.0-20210602131652-f16073e35f0c/go.mod h1:UODoCrxHCcBojKKwX1terBiRUaqAsFqJiF615XL43r0= google.golang.org/genproto v0.0.0-20210604141403-392c879c8b08/go.mod h1:UODoCrxHCcBojKKwX1terBiRUaqAsFqJiF615XL43r0= google.golang.org/genproto v0.0.0-20210608205507-b6d2f5bf0d7d/go.mod h1:UODoCrxHCcBojKKwX1terBiRUaqAsFqJiF615XL43r0= -google.golang.org/genproto v0.0.0-20210614143202-012ab6975634 h1:LnkHrvncK4mYysgs+R1wPeMAILrmunf0Tzl0Li71pxo= -google.golang.org/genproto v0.0.0-20210614143202-012ab6975634/go.mod h1:SzzZ/N+nwJDaO1kznhnlzqS8ocJICar6hYhVyhi++24= +google.golang.org/genproto v0.0.0-20210624195500-8bfb893ecb84/go.mod h1:SzzZ/N+nwJDaO1kznhnlzqS8ocJICar6hYhVyhi++24= +google.golang.org/genproto v0.0.0-20210701133433-6b8dcf568a95 h1:xyRjacsGcaSoZ2fTcaLCSzh2JEceLLOT4X8k32Q0xAQ= +google.golang.org/genproto v0.0.0-20210701133433-6b8dcf568a95/go.mod h1:yiaVoXHpRzHGyxV3o4DktVWY4mSUErTKaeEOq6C3t3U= google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38= google.golang.org/grpc v1.21.1/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM= @@ -481,8 +486,9 @@ google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpAD google.golang.org/protobuf v1.24.0/go.mod h1:r/3tXBNzIEhYS9I1OUVjXDlt8tc493IdKGjtUeSXeh4= google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c= google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= -google.golang.org/protobuf v1.26.0 h1:bxAC2xTBsZGibn2RTntX0oH50xLsqy1OxA9tTL3p/lk= google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= +google.golang.org/protobuf v1.27.1 h1:SnqbnDw1V7RiZcXPx5MEeqPv2s79L9i7BJUlG/+RurQ= +google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= diff --git a/datastream/apiv1alpha1/datastream_client.go b/datastream/apiv1alpha1/datastream_client.go new file mode 100644 index 00000000000..ad4aa195e4f --- /dev/null +++ b/datastream/apiv1alpha1/datastream_client.go @@ -0,0 +1,2077 @@ +// 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 datastream + +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" + datastreampb "google.golang.org/genproto/googleapis/cloud/datastream/v1alpha1" + longrunningpb "google.golang.org/genproto/googleapis/longrunning" + "google.golang.org/grpc" + "google.golang.org/grpc/codes" + "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 { + ListConnectionProfiles []gax.CallOption + GetConnectionProfile []gax.CallOption + CreateConnectionProfile []gax.CallOption + UpdateConnectionProfile []gax.CallOption + DeleteConnectionProfile []gax.CallOption + DiscoverConnectionProfile []gax.CallOption + ListStreams []gax.CallOption + GetStream []gax.CallOption + CreateStream []gax.CallOption + UpdateStream []gax.CallOption + DeleteStream []gax.CallOption + FetchErrors []gax.CallOption + FetchStaticIps []gax.CallOption + CreatePrivateConnection []gax.CallOption + GetPrivateConnection []gax.CallOption + ListPrivateConnections []gax.CallOption + DeletePrivateConnection []gax.CallOption + CreateRoute []gax.CallOption + GetRoute []gax.CallOption + ListRoutes []gax.CallOption + DeleteRoute []gax.CallOption +} + +func defaultGRPCClientOptions() []option.ClientOption { + return []option.ClientOption{ + internaloption.WithDefaultEndpoint("datastream.googleapis.com:443"), + internaloption.WithDefaultMTLSEndpoint("datastream.mtls.googleapis.com:443"), + internaloption.WithDefaultAudience("https://datastream.googleapis.com/"), + internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), + option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), + option.WithGRPCDialOption(grpc.WithDefaultCallOptions( + grpc.MaxCallRecvMsgSize(math.MaxInt32))), + } +} + +func defaultCallOptions() *CallOptions { + return &CallOptions{ + ListConnectionProfiles: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.Unavailable, + }, gax.Backoff{ + Initial: 1000 * time.Millisecond, + Max: 10000 * time.Millisecond, + Multiplier: 1.30, + }) + }), + }, + GetConnectionProfile: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.Unavailable, + }, gax.Backoff{ + Initial: 1000 * time.Millisecond, + Max: 10000 * time.Millisecond, + Multiplier: 1.30, + }) + }), + }, + CreateConnectionProfile: []gax.CallOption{}, + UpdateConnectionProfile: []gax.CallOption{}, + DeleteConnectionProfile: []gax.CallOption{}, + DiscoverConnectionProfile: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.Unavailable, + }, gax.Backoff{ + Initial: 1000 * time.Millisecond, + Max: 10000 * time.Millisecond, + Multiplier: 1.30, + }) + }), + }, + ListStreams: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.Unavailable, + }, gax.Backoff{ + Initial: 1000 * time.Millisecond, + Max: 10000 * time.Millisecond, + Multiplier: 1.30, + }) + }), + }, + GetStream: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.Unavailable, + }, gax.Backoff{ + Initial: 1000 * time.Millisecond, + Max: 10000 * time.Millisecond, + Multiplier: 1.30, + }) + }), + }, + CreateStream: []gax.CallOption{}, + UpdateStream: []gax.CallOption{}, + DeleteStream: []gax.CallOption{}, + FetchErrors: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.Unavailable, + }, gax.Backoff{ + Initial: 1000 * time.Millisecond, + Max: 10000 * time.Millisecond, + Multiplier: 1.30, + }) + }), + }, + FetchStaticIps: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.Unavailable, + }, gax.Backoff{ + Initial: 1000 * time.Millisecond, + Max: 10000 * time.Millisecond, + Multiplier: 1.30, + }) + }), + }, + CreatePrivateConnection: []gax.CallOption{}, + GetPrivateConnection: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.Unavailable, + }, gax.Backoff{ + Initial: 1000 * time.Millisecond, + Max: 10000 * time.Millisecond, + Multiplier: 1.30, + }) + }), + }, + ListPrivateConnections: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.Unavailable, + }, gax.Backoff{ + Initial: 1000 * time.Millisecond, + Max: 10000 * time.Millisecond, + Multiplier: 1.30, + }) + }), + }, + DeletePrivateConnection: []gax.CallOption{}, + CreateRoute: []gax.CallOption{}, + GetRoute: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.Unavailable, + }, gax.Backoff{ + Initial: 1000 * time.Millisecond, + Max: 10000 * time.Millisecond, + Multiplier: 1.30, + }) + }), + }, + ListRoutes: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.Unavailable, + }, gax.Backoff{ + Initial: 1000 * time.Millisecond, + Max: 10000 * time.Millisecond, + Multiplier: 1.30, + }) + }), + }, + DeleteRoute: []gax.CallOption{}, + } +} + +// internalClient is an interface that defines the methods availaible from Datastream API. +type internalClient interface { + Close() error + setGoogleClientInfo(...string) + Connection() *grpc.ClientConn + ListConnectionProfiles(context.Context, *datastreampb.ListConnectionProfilesRequest, ...gax.CallOption) *ConnectionProfileIterator + GetConnectionProfile(context.Context, *datastreampb.GetConnectionProfileRequest, ...gax.CallOption) (*datastreampb.ConnectionProfile, error) + CreateConnectionProfile(context.Context, *datastreampb.CreateConnectionProfileRequest, ...gax.CallOption) (*CreateConnectionProfileOperation, error) + CreateConnectionProfileOperation(name string) *CreateConnectionProfileOperation + UpdateConnectionProfile(context.Context, *datastreampb.UpdateConnectionProfileRequest, ...gax.CallOption) (*UpdateConnectionProfileOperation, error) + UpdateConnectionProfileOperation(name string) *UpdateConnectionProfileOperation + DeleteConnectionProfile(context.Context, *datastreampb.DeleteConnectionProfileRequest, ...gax.CallOption) (*DeleteConnectionProfileOperation, error) + DeleteConnectionProfileOperation(name string) *DeleteConnectionProfileOperation + DiscoverConnectionProfile(context.Context, *datastreampb.DiscoverConnectionProfileRequest, ...gax.CallOption) (*datastreampb.DiscoverConnectionProfileResponse, error) + ListStreams(context.Context, *datastreampb.ListStreamsRequest, ...gax.CallOption) *StreamIterator + GetStream(context.Context, *datastreampb.GetStreamRequest, ...gax.CallOption) (*datastreampb.Stream, error) + CreateStream(context.Context, *datastreampb.CreateStreamRequest, ...gax.CallOption) (*CreateStreamOperation, error) + CreateStreamOperation(name string) *CreateStreamOperation + UpdateStream(context.Context, *datastreampb.UpdateStreamRequest, ...gax.CallOption) (*UpdateStreamOperation, error) + UpdateStreamOperation(name string) *UpdateStreamOperation + DeleteStream(context.Context, *datastreampb.DeleteStreamRequest, ...gax.CallOption) (*DeleteStreamOperation, error) + DeleteStreamOperation(name string) *DeleteStreamOperation + FetchErrors(context.Context, *datastreampb.FetchErrorsRequest, ...gax.CallOption) (*FetchErrorsOperation, error) + FetchErrorsOperation(name string) *FetchErrorsOperation + FetchStaticIps(context.Context, *datastreampb.FetchStaticIpsRequest, ...gax.CallOption) *StringIterator + CreatePrivateConnection(context.Context, *datastreampb.CreatePrivateConnectionRequest, ...gax.CallOption) (*CreatePrivateConnectionOperation, error) + CreatePrivateConnectionOperation(name string) *CreatePrivateConnectionOperation + GetPrivateConnection(context.Context, *datastreampb.GetPrivateConnectionRequest, ...gax.CallOption) (*datastreampb.PrivateConnection, error) + ListPrivateConnections(context.Context, *datastreampb.ListPrivateConnectionsRequest, ...gax.CallOption) *PrivateConnectionIterator + DeletePrivateConnection(context.Context, *datastreampb.DeletePrivateConnectionRequest, ...gax.CallOption) (*DeletePrivateConnectionOperation, error) + DeletePrivateConnectionOperation(name string) *DeletePrivateConnectionOperation + CreateRoute(context.Context, *datastreampb.CreateRouteRequest, ...gax.CallOption) (*CreateRouteOperation, error) + CreateRouteOperation(name string) *CreateRouteOperation + GetRoute(context.Context, *datastreampb.GetRouteRequest, ...gax.CallOption) (*datastreampb.Route, error) + ListRoutes(context.Context, *datastreampb.ListRoutesRequest, ...gax.CallOption) *RouteIterator + DeleteRoute(context.Context, *datastreampb.DeleteRouteRequest, ...gax.CallOption) (*DeleteRouteOperation, error) + DeleteRouteOperation(name string) *DeleteRouteOperation +} + +// Client is a client for interacting with Datastream API. +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +// +// Datastream service +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() +} + +// ListConnectionProfiles use this method to list connection profiles created in a project and +// location. +func (c *Client) ListConnectionProfiles(ctx context.Context, req *datastreampb.ListConnectionProfilesRequest, opts ...gax.CallOption) *ConnectionProfileIterator { + return c.internalClient.ListConnectionProfiles(ctx, req, opts...) +} + +// GetConnectionProfile use this method to get details about a connection profile. +func (c *Client) GetConnectionProfile(ctx context.Context, req *datastreampb.GetConnectionProfileRequest, opts ...gax.CallOption) (*datastreampb.ConnectionProfile, error) { + return c.internalClient.GetConnectionProfile(ctx, req, opts...) +} + +// CreateConnectionProfile use this method to create a connection profile in a project and location. +func (c *Client) CreateConnectionProfile(ctx context.Context, req *datastreampb.CreateConnectionProfileRequest, opts ...gax.CallOption) (*CreateConnectionProfileOperation, error) { + return c.internalClient.CreateConnectionProfile(ctx, req, opts...) +} + +// CreateConnectionProfileOperation returns a new CreateConnectionProfileOperation from a given name. +// The name must be that of a previously created CreateConnectionProfileOperation, possibly from a different process. +func (c *Client) CreateConnectionProfileOperation(name string) *CreateConnectionProfileOperation { + return c.internalClient.CreateConnectionProfileOperation(name) +} + +// UpdateConnectionProfile use this method to update the parameters of a connection profile. +func (c *Client) UpdateConnectionProfile(ctx context.Context, req *datastreampb.UpdateConnectionProfileRequest, opts ...gax.CallOption) (*UpdateConnectionProfileOperation, error) { + return c.internalClient.UpdateConnectionProfile(ctx, req, opts...) +} + +// UpdateConnectionProfileOperation returns a new UpdateConnectionProfileOperation from a given name. +// The name must be that of a previously created UpdateConnectionProfileOperation, possibly from a different process. +func (c *Client) UpdateConnectionProfileOperation(name string) *UpdateConnectionProfileOperation { + return c.internalClient.UpdateConnectionProfileOperation(name) +} + +// DeleteConnectionProfile use this method to delete a connection profile… +func (c *Client) DeleteConnectionProfile(ctx context.Context, req *datastreampb.DeleteConnectionProfileRequest, opts ...gax.CallOption) (*DeleteConnectionProfileOperation, error) { + return c.internalClient.DeleteConnectionProfile(ctx, req, opts...) +} + +// DeleteConnectionProfileOperation returns a new DeleteConnectionProfileOperation from a given name. +// The name must be that of a previously created DeleteConnectionProfileOperation, possibly from a different process. +func (c *Client) DeleteConnectionProfileOperation(name string) *DeleteConnectionProfileOperation { + return c.internalClient.DeleteConnectionProfileOperation(name) +} + +// DiscoverConnectionProfile use this method to discover a connection profile. +// The discover API call exposes the data objects and metadata belonging to +// the profile. Typically, a request returns children data objects under a +// parent data object that’s optionally supplied in the request. +func (c *Client) DiscoverConnectionProfile(ctx context.Context, req *datastreampb.DiscoverConnectionProfileRequest, opts ...gax.CallOption) (*datastreampb.DiscoverConnectionProfileResponse, error) { + return c.internalClient.DiscoverConnectionProfile(ctx, req, opts...) +} + +// ListStreams use this method to list streams in a project and location. +func (c *Client) ListStreams(ctx context.Context, req *datastreampb.ListStreamsRequest, opts ...gax.CallOption) *StreamIterator { + return c.internalClient.ListStreams(ctx, req, opts...) +} + +// GetStream use this method to get details about a stream. +func (c *Client) GetStream(ctx context.Context, req *datastreampb.GetStreamRequest, opts ...gax.CallOption) (*datastreampb.Stream, error) { + return c.internalClient.GetStream(ctx, req, opts...) +} + +// CreateStream use this method to create a stream. +func (c *Client) CreateStream(ctx context.Context, req *datastreampb.CreateStreamRequest, opts ...gax.CallOption) (*CreateStreamOperation, error) { + return c.internalClient.CreateStream(ctx, req, opts...) +} + +// CreateStreamOperation returns a new CreateStreamOperation from a given name. +// The name must be that of a previously created CreateStreamOperation, possibly from a different process. +func (c *Client) CreateStreamOperation(name string) *CreateStreamOperation { + return c.internalClient.CreateStreamOperation(name) +} + +// UpdateStream use this method to update the configuration of a stream. +func (c *Client) UpdateStream(ctx context.Context, req *datastreampb.UpdateStreamRequest, opts ...gax.CallOption) (*UpdateStreamOperation, error) { + return c.internalClient.UpdateStream(ctx, req, opts...) +} + +// UpdateStreamOperation returns a new UpdateStreamOperation from a given name. +// The name must be that of a previously created UpdateStreamOperation, possibly from a different process. +func (c *Client) UpdateStreamOperation(name string) *UpdateStreamOperation { + return c.internalClient.UpdateStreamOperation(name) +} + +// DeleteStream use this method to delete a stream. +func (c *Client) DeleteStream(ctx context.Context, req *datastreampb.DeleteStreamRequest, opts ...gax.CallOption) (*DeleteStreamOperation, error) { + return c.internalClient.DeleteStream(ctx, req, opts...) +} + +// DeleteStreamOperation returns a new DeleteStreamOperation from a given name. +// The name must be that of a previously created DeleteStreamOperation, possibly from a different process. +func (c *Client) DeleteStreamOperation(name string) *DeleteStreamOperation { + return c.internalClient.DeleteStreamOperation(name) +} + +// FetchErrors use this method to fetch any errors associated with a stream. +func (c *Client) FetchErrors(ctx context.Context, req *datastreampb.FetchErrorsRequest, opts ...gax.CallOption) (*FetchErrorsOperation, error) { + return c.internalClient.FetchErrors(ctx, req, opts...) +} + +// FetchErrorsOperation returns a new FetchErrorsOperation from a given name. +// The name must be that of a previously created FetchErrorsOperation, possibly from a different process. +func (c *Client) FetchErrorsOperation(name string) *FetchErrorsOperation { + return c.internalClient.FetchErrorsOperation(name) +} + +// FetchStaticIps the FetchStaticIps API call exposes the static ips used by Datastream. +// Typically, a request returns children data objects under +// a parent data object that’s optionally supplied in the request. +func (c *Client) FetchStaticIps(ctx context.Context, req *datastreampb.FetchStaticIpsRequest, opts ...gax.CallOption) *StringIterator { + return c.internalClient.FetchStaticIps(ctx, req, opts...) +} + +// CreatePrivateConnection use this method to create a private connectivity configuration. +func (c *Client) CreatePrivateConnection(ctx context.Context, req *datastreampb.CreatePrivateConnectionRequest, opts ...gax.CallOption) (*CreatePrivateConnectionOperation, error) { + return c.internalClient.CreatePrivateConnection(ctx, req, opts...) +} + +// CreatePrivateConnectionOperation returns a new CreatePrivateConnectionOperation from a given name. +// The name must be that of a previously created CreatePrivateConnectionOperation, possibly from a different process. +func (c *Client) CreatePrivateConnectionOperation(name string) *CreatePrivateConnectionOperation { + return c.internalClient.CreatePrivateConnectionOperation(name) +} + +// GetPrivateConnection use this method to get details about a private connectivity configuration. +func (c *Client) GetPrivateConnection(ctx context.Context, req *datastreampb.GetPrivateConnectionRequest, opts ...gax.CallOption) (*datastreampb.PrivateConnection, error) { + return c.internalClient.GetPrivateConnection(ctx, req, opts...) +} + +// ListPrivateConnections use this method to list private connectivity configurations in a project +// and location. +func (c *Client) ListPrivateConnections(ctx context.Context, req *datastreampb.ListPrivateConnectionsRequest, opts ...gax.CallOption) *PrivateConnectionIterator { + return c.internalClient.ListPrivateConnections(ctx, req, opts...) +} + +// DeletePrivateConnection use this method to delete a private connectivity configuration. +func (c *Client) DeletePrivateConnection(ctx context.Context, req *datastreampb.DeletePrivateConnectionRequest, opts ...gax.CallOption) (*DeletePrivateConnectionOperation, error) { + return c.internalClient.DeletePrivateConnection(ctx, req, opts...) +} + +// DeletePrivateConnectionOperation returns a new DeletePrivateConnectionOperation from a given name. +// The name must be that of a previously created DeletePrivateConnectionOperation, possibly from a different process. +func (c *Client) DeletePrivateConnectionOperation(name string) *DeletePrivateConnectionOperation { + return c.internalClient.DeletePrivateConnectionOperation(name) +} + +// CreateRoute use this method to create a route for a private connectivity in a project +// and location. +func (c *Client) CreateRoute(ctx context.Context, req *datastreampb.CreateRouteRequest, opts ...gax.CallOption) (*CreateRouteOperation, error) { + return c.internalClient.CreateRoute(ctx, req, opts...) +} + +// CreateRouteOperation returns a new CreateRouteOperation from a given name. +// The name must be that of a previously created CreateRouteOperation, possibly from a different process. +func (c *Client) CreateRouteOperation(name string) *CreateRouteOperation { + return c.internalClient.CreateRouteOperation(name) +} + +// GetRoute use this method to get details about a route. +func (c *Client) GetRoute(ctx context.Context, req *datastreampb.GetRouteRequest, opts ...gax.CallOption) (*datastreampb.Route, error) { + return c.internalClient.GetRoute(ctx, req, opts...) +} + +// ListRoutes use this method to list routes created for a private connectivity in a +// project and location. +func (c *Client) ListRoutes(ctx context.Context, req *datastreampb.ListRoutesRequest, opts ...gax.CallOption) *RouteIterator { + return c.internalClient.ListRoutes(ctx, req, opts...) +} + +// DeleteRoute use this method to delete a route. +func (c *Client) DeleteRoute(ctx context.Context, req *datastreampb.DeleteRouteRequest, opts ...gax.CallOption) (*DeleteRouteOperation, error) { + return c.internalClient.DeleteRoute(ctx, req, opts...) +} + +// DeleteRouteOperation returns a new DeleteRouteOperation from a given name. +// The name must be that of a previously created DeleteRouteOperation, possibly from a different process. +func (c *Client) DeleteRouteOperation(name string) *DeleteRouteOperation { + return c.internalClient.DeleteRouteOperation(name) +} + +// gRPCClient is a client for interacting with Datastream 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 datastreampb.DatastreamClient + + // 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 datastream client based on gRPC. +// The returned client must be Closed when it is done being used to clean up its underlying connections. +// +// Datastream service +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: datastreampb.NewDatastreamClient(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) ListConnectionProfiles(ctx context.Context, req *datastreampb.ListConnectionProfilesRequest, opts ...gax.CallOption) *ConnectionProfileIterator { + 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).ListConnectionProfiles[0:len((*c.CallOptions).ListConnectionProfiles):len((*c.CallOptions).ListConnectionProfiles)], opts...) + it := &ConnectionProfileIterator{} + req = proto.Clone(req).(*datastreampb.ListConnectionProfilesRequest) + it.InternalFetch = func(pageSize int, pageToken string) ([]*datastreampb.ConnectionProfile, string, error) { + var resp *datastreampb.ListConnectionProfilesResponse + 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.ListConnectionProfiles(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, "", err + } + + it.Response = resp + return resp.GetConnectionProfiles(), 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) GetConnectionProfile(ctx context.Context, req *datastreampb.GetConnectionProfileRequest, opts ...gax.CallOption) (*datastreampb.ConnectionProfile, 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).GetConnectionProfile[0:len((*c.CallOptions).GetConnectionProfile):len((*c.CallOptions).GetConnectionProfile)], opts...) + var resp *datastreampb.ConnectionProfile + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.client.GetConnectionProfile(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} + +func (c *gRPCClient) CreateConnectionProfile(ctx context.Context, req *datastreampb.CreateConnectionProfileRequest, opts ...gax.CallOption) (*CreateConnectionProfileOperation, 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).CreateConnectionProfile[0:len((*c.CallOptions).CreateConnectionProfile):len((*c.CallOptions).CreateConnectionProfile)], opts...) + var resp *longrunningpb.Operation + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.client.CreateConnectionProfile(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return &CreateConnectionProfileOperation{ + lro: longrunning.InternalNewOperation(*c.LROClient, resp), + }, nil +} + +func (c *gRPCClient) UpdateConnectionProfile(ctx context.Context, req *datastreampb.UpdateConnectionProfileRequest, opts ...gax.CallOption) (*UpdateConnectionProfileOperation, 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", "connection_profile.name", url.QueryEscape(req.GetConnectionProfile().GetName()))) + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append((*c.CallOptions).UpdateConnectionProfile[0:len((*c.CallOptions).UpdateConnectionProfile):len((*c.CallOptions).UpdateConnectionProfile)], opts...) + var resp *longrunningpb.Operation + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.client.UpdateConnectionProfile(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return &UpdateConnectionProfileOperation{ + lro: longrunning.InternalNewOperation(*c.LROClient, resp), + }, nil +} + +func (c *gRPCClient) DeleteConnectionProfile(ctx context.Context, req *datastreampb.DeleteConnectionProfileRequest, opts ...gax.CallOption) (*DeleteConnectionProfileOperation, 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).DeleteConnectionProfile[0:len((*c.CallOptions).DeleteConnectionProfile):len((*c.CallOptions).DeleteConnectionProfile)], opts...) + var resp *longrunningpb.Operation + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.client.DeleteConnectionProfile(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return &DeleteConnectionProfileOperation{ + lro: longrunning.InternalNewOperation(*c.LROClient, resp), + }, nil +} + +func (c *gRPCClient) DiscoverConnectionProfile(ctx context.Context, req *datastreampb.DiscoverConnectionProfileRequest, opts ...gax.CallOption) (*datastreampb.DiscoverConnectionProfileResponse, 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).DiscoverConnectionProfile[0:len((*c.CallOptions).DiscoverConnectionProfile):len((*c.CallOptions).DiscoverConnectionProfile)], opts...) + var resp *datastreampb.DiscoverConnectionProfileResponse + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.client.DiscoverConnectionProfile(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} + +func (c *gRPCClient) ListStreams(ctx context.Context, req *datastreampb.ListStreamsRequest, opts ...gax.CallOption) *StreamIterator { + 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).ListStreams[0:len((*c.CallOptions).ListStreams):len((*c.CallOptions).ListStreams)], opts...) + it := &StreamIterator{} + req = proto.Clone(req).(*datastreampb.ListStreamsRequest) + it.InternalFetch = func(pageSize int, pageToken string) ([]*datastreampb.Stream, string, error) { + var resp *datastreampb.ListStreamsResponse + 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.ListStreams(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, "", err + } + + it.Response = resp + return resp.GetStreams(), 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) GetStream(ctx context.Context, req *datastreampb.GetStreamRequest, opts ...gax.CallOption) (*datastreampb.Stream, 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).GetStream[0:len((*c.CallOptions).GetStream):len((*c.CallOptions).GetStream)], opts...) + var resp *datastreampb.Stream + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.client.GetStream(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} + +func (c *gRPCClient) CreateStream(ctx context.Context, req *datastreampb.CreateStreamRequest, opts ...gax.CallOption) (*CreateStreamOperation, 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).CreateStream[0:len((*c.CallOptions).CreateStream):len((*c.CallOptions).CreateStream)], opts...) + var resp *longrunningpb.Operation + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.client.CreateStream(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return &CreateStreamOperation{ + lro: longrunning.InternalNewOperation(*c.LROClient, resp), + }, nil +} + +func (c *gRPCClient) UpdateStream(ctx context.Context, req *datastreampb.UpdateStreamRequest, opts ...gax.CallOption) (*UpdateStreamOperation, 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", "stream.name", url.QueryEscape(req.GetStream().GetName()))) + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append((*c.CallOptions).UpdateStream[0:len((*c.CallOptions).UpdateStream):len((*c.CallOptions).UpdateStream)], opts...) + var resp *longrunningpb.Operation + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.client.UpdateStream(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return &UpdateStreamOperation{ + lro: longrunning.InternalNewOperation(*c.LROClient, resp), + }, nil +} + +func (c *gRPCClient) DeleteStream(ctx context.Context, req *datastreampb.DeleteStreamRequest, opts ...gax.CallOption) (*DeleteStreamOperation, 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).DeleteStream[0:len((*c.CallOptions).DeleteStream):len((*c.CallOptions).DeleteStream)], opts...) + var resp *longrunningpb.Operation + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.client.DeleteStream(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return &DeleteStreamOperation{ + lro: longrunning.InternalNewOperation(*c.LROClient, resp), + }, nil +} + +func (c *gRPCClient) FetchErrors(ctx context.Context, req *datastreampb.FetchErrorsRequest, opts ...gax.CallOption) (*FetchErrorsOperation, 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", "stream", url.QueryEscape(req.GetStream()))) + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append((*c.CallOptions).FetchErrors[0:len((*c.CallOptions).FetchErrors):len((*c.CallOptions).FetchErrors)], opts...) + var resp *longrunningpb.Operation + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.client.FetchErrors(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return &FetchErrorsOperation{ + lro: longrunning.InternalNewOperation(*c.LROClient, resp), + }, nil +} + +func (c *gRPCClient) FetchStaticIps(ctx context.Context, req *datastreampb.FetchStaticIpsRequest, opts ...gax.CallOption) *StringIterator { + 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).FetchStaticIps[0:len((*c.CallOptions).FetchStaticIps):len((*c.CallOptions).FetchStaticIps)], opts...) + it := &StringIterator{} + req = proto.Clone(req).(*datastreampb.FetchStaticIpsRequest) + it.InternalFetch = func(pageSize int, pageToken string) ([]string, string, error) { + var resp *datastreampb.FetchStaticIpsResponse + 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.FetchStaticIps(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, "", err + } + + it.Response = resp + return resp.GetStaticIps(), 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) CreatePrivateConnection(ctx context.Context, req *datastreampb.CreatePrivateConnectionRequest, opts ...gax.CallOption) (*CreatePrivateConnectionOperation, 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).CreatePrivateConnection[0:len((*c.CallOptions).CreatePrivateConnection):len((*c.CallOptions).CreatePrivateConnection)], opts...) + var resp *longrunningpb.Operation + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.client.CreatePrivateConnection(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return &CreatePrivateConnectionOperation{ + lro: longrunning.InternalNewOperation(*c.LROClient, resp), + }, nil +} + +func (c *gRPCClient) GetPrivateConnection(ctx context.Context, req *datastreampb.GetPrivateConnectionRequest, opts ...gax.CallOption) (*datastreampb.PrivateConnection, 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).GetPrivateConnection[0:len((*c.CallOptions).GetPrivateConnection):len((*c.CallOptions).GetPrivateConnection)], opts...) + var resp *datastreampb.PrivateConnection + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.client.GetPrivateConnection(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} + +func (c *gRPCClient) ListPrivateConnections(ctx context.Context, req *datastreampb.ListPrivateConnectionsRequest, opts ...gax.CallOption) *PrivateConnectionIterator { + 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).ListPrivateConnections[0:len((*c.CallOptions).ListPrivateConnections):len((*c.CallOptions).ListPrivateConnections)], opts...) + it := &PrivateConnectionIterator{} + req = proto.Clone(req).(*datastreampb.ListPrivateConnectionsRequest) + it.InternalFetch = func(pageSize int, pageToken string) ([]*datastreampb.PrivateConnection, string, error) { + var resp *datastreampb.ListPrivateConnectionsResponse + 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.ListPrivateConnections(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, "", err + } + + it.Response = resp + return resp.GetPrivateConnections(), 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) DeletePrivateConnection(ctx context.Context, req *datastreampb.DeletePrivateConnectionRequest, opts ...gax.CallOption) (*DeletePrivateConnectionOperation, 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).DeletePrivateConnection[0:len((*c.CallOptions).DeletePrivateConnection):len((*c.CallOptions).DeletePrivateConnection)], opts...) + var resp *longrunningpb.Operation + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.client.DeletePrivateConnection(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return &DeletePrivateConnectionOperation{ + lro: longrunning.InternalNewOperation(*c.LROClient, resp), + }, nil +} + +func (c *gRPCClient) CreateRoute(ctx context.Context, req *datastreampb.CreateRouteRequest, opts ...gax.CallOption) (*CreateRouteOperation, 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).CreateRoute[0:len((*c.CallOptions).CreateRoute):len((*c.CallOptions).CreateRoute)], opts...) + var resp *longrunningpb.Operation + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.client.CreateRoute(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return &CreateRouteOperation{ + lro: longrunning.InternalNewOperation(*c.LROClient, resp), + }, nil +} + +func (c *gRPCClient) GetRoute(ctx context.Context, req *datastreampb.GetRouteRequest, opts ...gax.CallOption) (*datastreampb.Route, 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).GetRoute[0:len((*c.CallOptions).GetRoute):len((*c.CallOptions).GetRoute)], opts...) + var resp *datastreampb.Route + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.client.GetRoute(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} + +func (c *gRPCClient) ListRoutes(ctx context.Context, req *datastreampb.ListRoutesRequest, opts ...gax.CallOption) *RouteIterator { + 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).ListRoutes[0:len((*c.CallOptions).ListRoutes):len((*c.CallOptions).ListRoutes)], opts...) + it := &RouteIterator{} + req = proto.Clone(req).(*datastreampb.ListRoutesRequest) + it.InternalFetch = func(pageSize int, pageToken string) ([]*datastreampb.Route, string, error) { + var resp *datastreampb.ListRoutesResponse + 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.ListRoutes(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, "", err + } + + it.Response = resp + return resp.GetRoutes(), 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) DeleteRoute(ctx context.Context, req *datastreampb.DeleteRouteRequest, opts ...gax.CallOption) (*DeleteRouteOperation, 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).DeleteRoute[0:len((*c.CallOptions).DeleteRoute):len((*c.CallOptions).DeleteRoute)], opts...) + var resp *longrunningpb.Operation + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.client.DeleteRoute(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return &DeleteRouteOperation{ + lro: longrunning.InternalNewOperation(*c.LROClient, resp), + }, nil +} + +// CreateConnectionProfileOperation manages a long-running operation from CreateConnectionProfile. +type CreateConnectionProfileOperation struct { + lro *longrunning.Operation +} + +// CreateConnectionProfileOperation returns a new CreateConnectionProfileOperation from a given name. +// The name must be that of a previously created CreateConnectionProfileOperation, possibly from a different process. +func (c *gRPCClient) CreateConnectionProfileOperation(name string) *CreateConnectionProfileOperation { + return &CreateConnectionProfileOperation{ + 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 *CreateConnectionProfileOperation) Wait(ctx context.Context, opts ...gax.CallOption) (*datastreampb.ConnectionProfile, error) { + var resp datastreampb.ConnectionProfile + 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 *CreateConnectionProfileOperation) Poll(ctx context.Context, opts ...gax.CallOption) (*datastreampb.ConnectionProfile, error) { + var resp datastreampb.ConnectionProfile + 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 *CreateConnectionProfileOperation) Metadata() (*datastreampb.OperationMetadata, error) { + var meta datastreampb.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 *CreateConnectionProfileOperation) 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 *CreateConnectionProfileOperation) Name() string { + return op.lro.Name() +} + +// CreatePrivateConnectionOperation manages a long-running operation from CreatePrivateConnection. +type CreatePrivateConnectionOperation struct { + lro *longrunning.Operation +} + +// CreatePrivateConnectionOperation returns a new CreatePrivateConnectionOperation from a given name. +// The name must be that of a previously created CreatePrivateConnectionOperation, possibly from a different process. +func (c *gRPCClient) CreatePrivateConnectionOperation(name string) *CreatePrivateConnectionOperation { + return &CreatePrivateConnectionOperation{ + 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 *CreatePrivateConnectionOperation) Wait(ctx context.Context, opts ...gax.CallOption) (*datastreampb.PrivateConnection, error) { + var resp datastreampb.PrivateConnection + 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 *CreatePrivateConnectionOperation) Poll(ctx context.Context, opts ...gax.CallOption) (*datastreampb.PrivateConnection, error) { + var resp datastreampb.PrivateConnection + 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 *CreatePrivateConnectionOperation) Metadata() (*datastreampb.OperationMetadata, error) { + var meta datastreampb.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 *CreatePrivateConnectionOperation) 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 *CreatePrivateConnectionOperation) Name() string { + return op.lro.Name() +} + +// CreateRouteOperation manages a long-running operation from CreateRoute. +type CreateRouteOperation struct { + lro *longrunning.Operation +} + +// CreateRouteOperation returns a new CreateRouteOperation from a given name. +// The name must be that of a previously created CreateRouteOperation, possibly from a different process. +func (c *gRPCClient) CreateRouteOperation(name string) *CreateRouteOperation { + return &CreateRouteOperation{ + 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 *CreateRouteOperation) Wait(ctx context.Context, opts ...gax.CallOption) (*datastreampb.Route, error) { + var resp datastreampb.Route + 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 *CreateRouteOperation) Poll(ctx context.Context, opts ...gax.CallOption) (*datastreampb.Route, error) { + var resp datastreampb.Route + 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 *CreateRouteOperation) Metadata() (*datastreampb.OperationMetadata, error) { + var meta datastreampb.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 *CreateRouteOperation) 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 *CreateRouteOperation) Name() string { + return op.lro.Name() +} + +// CreateStreamOperation manages a long-running operation from CreateStream. +type CreateStreamOperation struct { + lro *longrunning.Operation +} + +// CreateStreamOperation returns a new CreateStreamOperation from a given name. +// The name must be that of a previously created CreateStreamOperation, possibly from a different process. +func (c *gRPCClient) CreateStreamOperation(name string) *CreateStreamOperation { + return &CreateStreamOperation{ + 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 *CreateStreamOperation) Wait(ctx context.Context, opts ...gax.CallOption) (*datastreampb.Stream, error) { + var resp datastreampb.Stream + 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 *CreateStreamOperation) Poll(ctx context.Context, opts ...gax.CallOption) (*datastreampb.Stream, error) { + var resp datastreampb.Stream + 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 *CreateStreamOperation) Metadata() (*datastreampb.OperationMetadata, error) { + var meta datastreampb.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 *CreateStreamOperation) 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 *CreateStreamOperation) Name() string { + return op.lro.Name() +} + +// DeleteConnectionProfileOperation manages a long-running operation from DeleteConnectionProfile. +type DeleteConnectionProfileOperation struct { + lro *longrunning.Operation +} + +// DeleteConnectionProfileOperation returns a new DeleteConnectionProfileOperation from a given name. +// The name must be that of a previously created DeleteConnectionProfileOperation, possibly from a different process. +func (c *gRPCClient) DeleteConnectionProfileOperation(name string) *DeleteConnectionProfileOperation { + return &DeleteConnectionProfileOperation{ + 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 *DeleteConnectionProfileOperation) 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 *DeleteConnectionProfileOperation) 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 *DeleteConnectionProfileOperation) Metadata() (*datastreampb.OperationMetadata, error) { + var meta datastreampb.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 *DeleteConnectionProfileOperation) 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 *DeleteConnectionProfileOperation) Name() string { + return op.lro.Name() +} + +// DeletePrivateConnectionOperation manages a long-running operation from DeletePrivateConnection. +type DeletePrivateConnectionOperation struct { + lro *longrunning.Operation +} + +// DeletePrivateConnectionOperation returns a new DeletePrivateConnectionOperation from a given name. +// The name must be that of a previously created DeletePrivateConnectionOperation, possibly from a different process. +func (c *gRPCClient) DeletePrivateConnectionOperation(name string) *DeletePrivateConnectionOperation { + return &DeletePrivateConnectionOperation{ + 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 *DeletePrivateConnectionOperation) 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 *DeletePrivateConnectionOperation) 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 *DeletePrivateConnectionOperation) Metadata() (*datastreampb.OperationMetadata, error) { + var meta datastreampb.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 *DeletePrivateConnectionOperation) 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 *DeletePrivateConnectionOperation) Name() string { + return op.lro.Name() +} + +// DeleteRouteOperation manages a long-running operation from DeleteRoute. +type DeleteRouteOperation struct { + lro *longrunning.Operation +} + +// DeleteRouteOperation returns a new DeleteRouteOperation from a given name. +// The name must be that of a previously created DeleteRouteOperation, possibly from a different process. +func (c *gRPCClient) DeleteRouteOperation(name string) *DeleteRouteOperation { + return &DeleteRouteOperation{ + 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 *DeleteRouteOperation) 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 *DeleteRouteOperation) 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 *DeleteRouteOperation) Metadata() (*datastreampb.OperationMetadata, error) { + var meta datastreampb.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 *DeleteRouteOperation) 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 *DeleteRouteOperation) Name() string { + return op.lro.Name() +} + +// DeleteStreamOperation manages a long-running operation from DeleteStream. +type DeleteStreamOperation struct { + lro *longrunning.Operation +} + +// DeleteStreamOperation returns a new DeleteStreamOperation from a given name. +// The name must be that of a previously created DeleteStreamOperation, possibly from a different process. +func (c *gRPCClient) DeleteStreamOperation(name string) *DeleteStreamOperation { + return &DeleteStreamOperation{ + 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 *DeleteStreamOperation) 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 *DeleteStreamOperation) 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 *DeleteStreamOperation) Metadata() (*datastreampb.OperationMetadata, error) { + var meta datastreampb.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 *DeleteStreamOperation) 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 *DeleteStreamOperation) Name() string { + return op.lro.Name() +} + +// FetchErrorsOperation manages a long-running operation from FetchErrors. +type FetchErrorsOperation struct { + lro *longrunning.Operation +} + +// FetchErrorsOperation returns a new FetchErrorsOperation from a given name. +// The name must be that of a previously created FetchErrorsOperation, possibly from a different process. +func (c *gRPCClient) FetchErrorsOperation(name string) *FetchErrorsOperation { + return &FetchErrorsOperation{ + 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 *FetchErrorsOperation) Wait(ctx context.Context, opts ...gax.CallOption) (*datastreampb.FetchErrorsResponse, error) { + var resp datastreampb.FetchErrorsResponse + 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 *FetchErrorsOperation) Poll(ctx context.Context, opts ...gax.CallOption) (*datastreampb.FetchErrorsResponse, error) { + var resp datastreampb.FetchErrorsResponse + 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 *FetchErrorsOperation) Metadata() (*datastreampb.OperationMetadata, error) { + var meta datastreampb.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 *FetchErrorsOperation) 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 *FetchErrorsOperation) Name() string { + return op.lro.Name() +} + +// UpdateConnectionProfileOperation manages a long-running operation from UpdateConnectionProfile. +type UpdateConnectionProfileOperation struct { + lro *longrunning.Operation +} + +// UpdateConnectionProfileOperation returns a new UpdateConnectionProfileOperation from a given name. +// The name must be that of a previously created UpdateConnectionProfileOperation, possibly from a different process. +func (c *gRPCClient) UpdateConnectionProfileOperation(name string) *UpdateConnectionProfileOperation { + return &UpdateConnectionProfileOperation{ + 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 *UpdateConnectionProfileOperation) Wait(ctx context.Context, opts ...gax.CallOption) (*datastreampb.ConnectionProfile, error) { + var resp datastreampb.ConnectionProfile + 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 *UpdateConnectionProfileOperation) Poll(ctx context.Context, opts ...gax.CallOption) (*datastreampb.ConnectionProfile, error) { + var resp datastreampb.ConnectionProfile + 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 *UpdateConnectionProfileOperation) Metadata() (*datastreampb.OperationMetadata, error) { + var meta datastreampb.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 *UpdateConnectionProfileOperation) 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 *UpdateConnectionProfileOperation) Name() string { + return op.lro.Name() +} + +// UpdateStreamOperation manages a long-running operation from UpdateStream. +type UpdateStreamOperation struct { + lro *longrunning.Operation +} + +// UpdateStreamOperation returns a new UpdateStreamOperation from a given name. +// The name must be that of a previously created UpdateStreamOperation, possibly from a different process. +func (c *gRPCClient) UpdateStreamOperation(name string) *UpdateStreamOperation { + return &UpdateStreamOperation{ + 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 *UpdateStreamOperation) Wait(ctx context.Context, opts ...gax.CallOption) (*datastreampb.Stream, error) { + var resp datastreampb.Stream + 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 *UpdateStreamOperation) Poll(ctx context.Context, opts ...gax.CallOption) (*datastreampb.Stream, error) { + var resp datastreampb.Stream + 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 *UpdateStreamOperation) Metadata() (*datastreampb.OperationMetadata, error) { + var meta datastreampb.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 *UpdateStreamOperation) 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 *UpdateStreamOperation) Name() string { + return op.lro.Name() +} + +// ConnectionProfileIterator manages a stream of *datastreampb.ConnectionProfile. +type ConnectionProfileIterator struct { + items []*datastreampb.ConnectionProfile + 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 []*datastreampb.ConnectionProfile, nextPageToken string, err error) +} + +// PageInfo supports pagination. See the google.golang.org/api/iterator package for details. +func (it *ConnectionProfileIterator) 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 *ConnectionProfileIterator) Next() (*datastreampb.ConnectionProfile, error) { + var item *datastreampb.ConnectionProfile + if err := it.nextFunc(); err != nil { + return item, err + } + item = it.items[0] + it.items = it.items[1:] + return item, nil +} + +func (it *ConnectionProfileIterator) bufLen() int { + return len(it.items) +} + +func (it *ConnectionProfileIterator) takeBuf() interface{} { + b := it.items + it.items = nil + return b +} + +// PrivateConnectionIterator manages a stream of *datastreampb.PrivateConnection. +type PrivateConnectionIterator struct { + items []*datastreampb.PrivateConnection + 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 []*datastreampb.PrivateConnection, nextPageToken string, err error) +} + +// PageInfo supports pagination. See the google.golang.org/api/iterator package for details. +func (it *PrivateConnectionIterator) 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 *PrivateConnectionIterator) Next() (*datastreampb.PrivateConnection, error) { + var item *datastreampb.PrivateConnection + if err := it.nextFunc(); err != nil { + return item, err + } + item = it.items[0] + it.items = it.items[1:] + return item, nil +} + +func (it *PrivateConnectionIterator) bufLen() int { + return len(it.items) +} + +func (it *PrivateConnectionIterator) takeBuf() interface{} { + b := it.items + it.items = nil + return b +} + +// RouteIterator manages a stream of *datastreampb.Route. +type RouteIterator struct { + items []*datastreampb.Route + 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 []*datastreampb.Route, nextPageToken string, err error) +} + +// PageInfo supports pagination. See the google.golang.org/api/iterator package for details. +func (it *RouteIterator) 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 *RouteIterator) Next() (*datastreampb.Route, error) { + var item *datastreampb.Route + if err := it.nextFunc(); err != nil { + return item, err + } + item = it.items[0] + it.items = it.items[1:] + return item, nil +} + +func (it *RouteIterator) bufLen() int { + return len(it.items) +} + +func (it *RouteIterator) takeBuf() interface{} { + b := it.items + it.items = nil + return b +} + +// StreamIterator manages a stream of *datastreampb.Stream. +type StreamIterator struct { + items []*datastreampb.Stream + 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 []*datastreampb.Stream, nextPageToken string, err error) +} + +// PageInfo supports pagination. See the google.golang.org/api/iterator package for details. +func (it *StreamIterator) 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 *StreamIterator) Next() (*datastreampb.Stream, error) { + var item *datastreampb.Stream + if err := it.nextFunc(); err != nil { + return item, err + } + item = it.items[0] + it.items = it.items[1:] + return item, nil +} + +func (it *StreamIterator) bufLen() int { + return len(it.items) +} + +func (it *StreamIterator) takeBuf() interface{} { + b := it.items + it.items = nil + return b +} + +// StringIterator manages a stream of string. +type StringIterator struct { + items []string + 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 []string, nextPageToken string, err error) +} + +// PageInfo supports pagination. See the google.golang.org/api/iterator package for details. +func (it *StringIterator) 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 *StringIterator) Next() (string, error) { + var item string + if err := it.nextFunc(); err != nil { + return item, err + } + item = it.items[0] + it.items = it.items[1:] + return item, nil +} + +func (it *StringIterator) bufLen() int { + return len(it.items) +} + +func (it *StringIterator) takeBuf() interface{} { + b := it.items + it.items = nil + return b +} diff --git a/datastream/apiv1alpha1/datastream_client_example_test.go b/datastream/apiv1alpha1/datastream_client_example_test.go new file mode 100644 index 00000000000..c2fdcb2e2ad --- /dev/null +++ b/datastream/apiv1alpha1/datastream_client_example_test.go @@ -0,0 +1,513 @@ +// 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 datastream_test + +import ( + "context" + + datastream "cloud.google.com/go/datastream/apiv1alpha1" + "google.golang.org/api/iterator" + datastreampb "google.golang.org/genproto/googleapis/cloud/datastream/v1alpha1" +) + +func ExampleNewClient() { + ctx := context.Background() + c, err := datastream.NewClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + // TODO: Use client. + _ = c +} + +func ExampleClient_ListConnectionProfiles() { + ctx := context.Background() + c, err := datastream.NewClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &datastreampb.ListConnectionProfilesRequest{ + // TODO: Fill request struct fields. + } + it := c.ListConnectionProfiles(ctx, req) + for { + resp, err := it.Next() + if err == iterator.Done { + break + } + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp + } +} + +func ExampleClient_GetConnectionProfile() { + ctx := context.Background() + c, err := datastream.NewClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &datastreampb.GetConnectionProfileRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.GetConnectionProfile(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleClient_CreateConnectionProfile() { + ctx := context.Background() + c, err := datastream.NewClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &datastreampb.CreateConnectionProfileRequest{ + // TODO: Fill request struct fields. + } + op, err := c.CreateConnectionProfile(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_UpdateConnectionProfile() { + ctx := context.Background() + c, err := datastream.NewClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &datastreampb.UpdateConnectionProfileRequest{ + // TODO: Fill request struct fields. + } + op, err := c.UpdateConnectionProfile(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_DeleteConnectionProfile() { + ctx := context.Background() + c, err := datastream.NewClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &datastreampb.DeleteConnectionProfileRequest{ + // TODO: Fill request struct fields. + } + op, err := c.DeleteConnectionProfile(ctx, req) + if err != nil { + // TODO: Handle error. + } + + err = op.Wait(ctx) + if err != nil { + // TODO: Handle error. + } +} + +func ExampleClient_DiscoverConnectionProfile() { + ctx := context.Background() + c, err := datastream.NewClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &datastreampb.DiscoverConnectionProfileRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.DiscoverConnectionProfile(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleClient_ListStreams() { + ctx := context.Background() + c, err := datastream.NewClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &datastreampb.ListStreamsRequest{ + // TODO: Fill request struct fields. + } + it := c.ListStreams(ctx, req) + for { + resp, err := it.Next() + if err == iterator.Done { + break + } + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp + } +} + +func ExampleClient_GetStream() { + ctx := context.Background() + c, err := datastream.NewClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &datastreampb.GetStreamRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.GetStream(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleClient_CreateStream() { + ctx := context.Background() + c, err := datastream.NewClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &datastreampb.CreateStreamRequest{ + // TODO: Fill request struct fields. + } + op, err := c.CreateStream(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_UpdateStream() { + ctx := context.Background() + c, err := datastream.NewClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &datastreampb.UpdateStreamRequest{ + // TODO: Fill request struct fields. + } + op, err := c.UpdateStream(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_DeleteStream() { + ctx := context.Background() + c, err := datastream.NewClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &datastreampb.DeleteStreamRequest{ + // TODO: Fill request struct fields. + } + op, err := c.DeleteStream(ctx, req) + if err != nil { + // TODO: Handle error. + } + + err = op.Wait(ctx) + if err != nil { + // TODO: Handle error. + } +} + +func ExampleClient_FetchErrors() { + ctx := context.Background() + c, err := datastream.NewClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &datastreampb.FetchErrorsRequest{ + // TODO: Fill request struct fields. + } + op, err := c.FetchErrors(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_FetchStaticIps() { + ctx := context.Background() + c, err := datastream.NewClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &datastreampb.FetchStaticIpsRequest{ + // TODO: Fill request struct fields. + } + it := c.FetchStaticIps(ctx, req) + for { + resp, err := it.Next() + if err == iterator.Done { + break + } + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp + } +} + +func ExampleClient_CreatePrivateConnection() { + ctx := context.Background() + c, err := datastream.NewClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &datastreampb.CreatePrivateConnectionRequest{ + // TODO: Fill request struct fields. + } + op, err := c.CreatePrivateConnection(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_GetPrivateConnection() { + ctx := context.Background() + c, err := datastream.NewClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &datastreampb.GetPrivateConnectionRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.GetPrivateConnection(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleClient_ListPrivateConnections() { + ctx := context.Background() + c, err := datastream.NewClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &datastreampb.ListPrivateConnectionsRequest{ + // TODO: Fill request struct fields. + } + it := c.ListPrivateConnections(ctx, req) + for { + resp, err := it.Next() + if err == iterator.Done { + break + } + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp + } +} + +func ExampleClient_DeletePrivateConnection() { + ctx := context.Background() + c, err := datastream.NewClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &datastreampb.DeletePrivateConnectionRequest{ + // TODO: Fill request struct fields. + } + op, err := c.DeletePrivateConnection(ctx, req) + if err != nil { + // TODO: Handle error. + } + + err = op.Wait(ctx) + if err != nil { + // TODO: Handle error. + } +} + +func ExampleClient_CreateRoute() { + ctx := context.Background() + c, err := datastream.NewClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &datastreampb.CreateRouteRequest{ + // TODO: Fill request struct fields. + } + op, err := c.CreateRoute(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_GetRoute() { + ctx := context.Background() + c, err := datastream.NewClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &datastreampb.GetRouteRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.GetRoute(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleClient_ListRoutes() { + ctx := context.Background() + c, err := datastream.NewClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &datastreampb.ListRoutesRequest{ + // TODO: Fill request struct fields. + } + it := c.ListRoutes(ctx, req) + for { + resp, err := it.Next() + if err == iterator.Done { + break + } + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp + } +} + +func ExampleClient_DeleteRoute() { + ctx := context.Background() + c, err := datastream.NewClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &datastreampb.DeleteRouteRequest{ + // TODO: Fill request struct fields. + } + op, err := c.DeleteRoute(ctx, req) + if err != nil { + // TODO: Handle error. + } + + err = op.Wait(ctx) + if err != nil { + // TODO: Handle error. + } +} diff --git a/datastream/apiv1alpha1/doc.go b/datastream/apiv1alpha1/doc.go new file mode 100644 index 00000000000..b110d9efea7 --- /dev/null +++ b/datastream/apiv1alpha1/doc.go @@ -0,0 +1,116 @@ +// 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 datastream is an auto-generated package for the +// Datastream API. +// +// NOTE: This package is in alpha. It is not stable, and is likely to change. +// +// 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 datastream // import "cloud.google.com/go/datastream/apiv1alpha1" + +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 = "20210701" + +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/datastream/apiv1alpha1/gapic_metadata.json b/datastream/apiv1alpha1/gapic_metadata.json new file mode 100644 index 00000000000..417ecf9c439 --- /dev/null +++ b/datastream/apiv1alpha1/gapic_metadata.json @@ -0,0 +1,123 @@ +{ + "schema": "1.0", + "comment": "This file maps proto services/RPCs to the corresponding library clients/methods.", + "language": "go", + "protoPackage": "google.cloud.datastream.v1alpha1", + "libraryPackage": "cloud.google.com/go/datastream/apiv1alpha1", + "services": { + "Datastream": { + "clients": { + "grpc": { + "libraryClient": "Client", + "rpcs": { + "CreateConnectionProfile": { + "methods": [ + "CreateConnectionProfile" + ] + }, + "CreatePrivateConnection": { + "methods": [ + "CreatePrivateConnection" + ] + }, + "CreateRoute": { + "methods": [ + "CreateRoute" + ] + }, + "CreateStream": { + "methods": [ + "CreateStream" + ] + }, + "DeleteConnectionProfile": { + "methods": [ + "DeleteConnectionProfile" + ] + }, + "DeletePrivateConnection": { + "methods": [ + "DeletePrivateConnection" + ] + }, + "DeleteRoute": { + "methods": [ + "DeleteRoute" + ] + }, + "DeleteStream": { + "methods": [ + "DeleteStream" + ] + }, + "DiscoverConnectionProfile": { + "methods": [ + "DiscoverConnectionProfile" + ] + }, + "FetchErrors": { + "methods": [ + "FetchErrors" + ] + }, + "FetchStaticIps": { + "methods": [ + "FetchStaticIps" + ] + }, + "GetConnectionProfile": { + "methods": [ + "GetConnectionProfile" + ] + }, + "GetPrivateConnection": { + "methods": [ + "GetPrivateConnection" + ] + }, + "GetRoute": { + "methods": [ + "GetRoute" + ] + }, + "GetStream": { + "methods": [ + "GetStream" + ] + }, + "ListConnectionProfiles": { + "methods": [ + "ListConnectionProfiles" + ] + }, + "ListPrivateConnections": { + "methods": [ + "ListPrivateConnections" + ] + }, + "ListRoutes": { + "methods": [ + "ListRoutes" + ] + }, + "ListStreams": { + "methods": [ + "ListStreams" + ] + }, + "UpdateConnectionProfile": { + "methods": [ + "UpdateConnectionProfile" + ] + }, + "UpdateStream": { + "methods": [ + "UpdateStream" + ] + } + } + } + } + } + } +} diff --git a/debugger/apiv2/controller2_client.go b/debugger/apiv2/controller2_client.go index d8e887be439..5e06b37bcf7 100644 --- a/debugger/apiv2/controller2_client.go +++ b/debugger/apiv2/controller2_client.go @@ -48,6 +48,7 @@ func defaultController2GRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("clouddebugger.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://clouddebugger.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/debugger/apiv2/debugger2_client.go b/debugger/apiv2/debugger2_client.go index 868b90dee0d..ed6af24d20b 100644 --- a/debugger/apiv2/debugger2_client.go +++ b/debugger/apiv2/debugger2_client.go @@ -50,6 +50,7 @@ func defaultDebugger2GRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("clouddebugger.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://clouddebugger.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/debugger/apiv2/doc.go b/debugger/apiv2/doc.go index b265d40e195..43dbfffd1ad 100644 --- a/debugger/apiv2/doc.go +++ b/debugger/apiv2/doc.go @@ -49,7 +49,7 @@ import ( type clientHookParams struct{} type clientHook func(context.Context, clientHookParams) ([]option.ClientOption, error) -const versionClient = "20210612" +const versionClient = "20210701" func insertMetadata(ctx context.Context, mds ...metadata.MD) context.Context { out, _ := metadata.FromOutgoingContext(ctx) diff --git a/dialogflow/apiv2/agents_client.go b/dialogflow/apiv2/agents_client.go index 8e4bddc6c15..c7af082de25 100644 --- a/dialogflow/apiv2/agents_client.go +++ b/dialogflow/apiv2/agents_client.go @@ -25,7 +25,6 @@ import ( "cloud.google.com/go/longrunning" lroauto "cloud.google.com/go/longrunning/autogen" - "github.com/golang/protobuf/proto" structpb "github.com/golang/protobuf/ptypes/struct" gax "github.com/googleapis/gax-go/v2" "google.golang.org/api/iterator" @@ -37,6 +36,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newAgentsClientHook clientHook @@ -60,6 +60,7 @@ func defaultAgentsGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("dialogflow.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://dialogflow.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), @@ -235,6 +236,10 @@ func (c *AgentsClient) GetAgent(ctx context.Context, req *dialogflowpb.GetAgentR } // SetAgent creates/updates the specified agent. +// +// Note: You should always train an agent prior to sending it queries. See the +// training +// documentation (at https://cloud.google.com/dialogflow/es/docs/training). func (c *AgentsClient) SetAgent(ctx context.Context, req *dialogflowpb.SetAgentRequest, opts ...gax.CallOption) (*dialogflowpb.Agent, error) { return c.internalClient.SetAgent(ctx, req, opts...) } @@ -257,7 +262,9 @@ func (c *AgentsClient) SearchAgents(ctx context.Context, req *dialogflowpb.Searc // TrainAgent trains the specified agent. // -// Operation +// Note: You should always train an agent prior to sending it queries. See the +// training +// documentation (at https://cloud.google.com/dialogflow/es/docs/training). func (c *AgentsClient) TrainAgent(ctx context.Context, req *dialogflowpb.TrainAgentRequest, opts ...gax.CallOption) (*TrainAgentOperation, error) { return c.internalClient.TrainAgent(ctx, req, opts...) } @@ -269,8 +276,6 @@ func (c *AgentsClient) TrainAgentOperation(name string) *TrainAgentOperation { } // ExportAgent exports the specified agent to a ZIP file. -// -// Operation func (c *AgentsClient) ExportAgent(ctx context.Context, req *dialogflowpb.ExportAgentRequest, opts ...gax.CallOption) (*ExportAgentOperation, error) { return c.internalClient.ExportAgent(ctx, req, opts...) } @@ -291,9 +296,12 @@ func (c *AgentsClient) ExportAgentOperation(name string) *ExportAgentOperation { // call TrainAgent and wait for the operation it returns in order to train // explicitly. // -// Operation // An operation which tracks when importing is complete. It only tracks // when the draft agent is updated not when it is done training. +// +// Note: You should always train an agent prior to sending it queries. See the +// training +// documentation (at https://cloud.google.com/dialogflow/es/docs/training). func (c *AgentsClient) ImportAgent(ctx context.Context, req *dialogflowpb.ImportAgentRequest, opts ...gax.CallOption) (*ImportAgentOperation, error) { return c.internalClient.ImportAgent(ctx, req, opts...) } @@ -313,9 +321,12 @@ func (c *AgentsClient) ImportAgentOperation(name string) *ImportAgentOperation { // completed yet. Please call TrainAgent and wait for the operation it // returns in order to train explicitly. // -// Operation // An operation which tracks when restoring is complete. It only tracks // when the draft agent is updated not when it is done training. +// +// Note: You should always train an agent prior to sending it queries. See the +// training +// documentation (at https://cloud.google.com/dialogflow/es/docs/training). func (c *AgentsClient) RestoreAgent(ctx context.Context, req *dialogflowpb.RestoreAgentRequest, opts ...gax.CallOption) (*RestoreAgentOperation, error) { return c.internalClient.RestoreAgent(ctx, req, opts...) } diff --git a/dialogflow/apiv2/answer_records_client.go b/dialogflow/apiv2/answer_records_client.go index 953fad16259..d5b41536174 100644 --- a/dialogflow/apiv2/answer_records_client.go +++ b/dialogflow/apiv2/answer_records_client.go @@ -23,7 +23,6 @@ import ( "net/url" "time" - "github.com/golang/protobuf/proto" gax "github.com/googleapis/gax-go/v2" "google.golang.org/api/iterator" "google.golang.org/api/option" @@ -33,6 +32,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newAnswerRecordsClientHook clientHook @@ -49,6 +49,7 @@ func defaultAnswerRecordsGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("dialogflow.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://dialogflow.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/dialogflow/apiv2/contexts_client.go b/dialogflow/apiv2/contexts_client.go index ef338270481..88148448c87 100644 --- a/dialogflow/apiv2/contexts_client.go +++ b/dialogflow/apiv2/contexts_client.go @@ -23,7 +23,6 @@ import ( "net/url" "time" - "github.com/golang/protobuf/proto" gax "github.com/googleapis/gax-go/v2" "google.golang.org/api/iterator" "google.golang.org/api/option" @@ -33,6 +32,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newContextsClientHook clientHook @@ -53,6 +53,7 @@ func defaultContextsGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("dialogflow.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://dialogflow.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/dialogflow/apiv2/conversation_profiles_client.go b/dialogflow/apiv2/conversation_profiles_client.go index 8580a83ccf2..71adba384d6 100644 --- a/dialogflow/apiv2/conversation_profiles_client.go +++ b/dialogflow/apiv2/conversation_profiles_client.go @@ -23,7 +23,6 @@ import ( "net/url" "time" - "github.com/golang/protobuf/proto" gax "github.com/googleapis/gax-go/v2" "google.golang.org/api/iterator" "google.golang.org/api/option" @@ -33,6 +32,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newConversationProfilesClientHook clientHook @@ -52,6 +52,7 @@ func defaultConversationProfilesGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("dialogflow.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://dialogflow.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/dialogflow/apiv2/conversations_client.go b/dialogflow/apiv2/conversations_client.go index 6b299522ee5..66450e377a4 100644 --- a/dialogflow/apiv2/conversations_client.go +++ b/dialogflow/apiv2/conversations_client.go @@ -23,7 +23,6 @@ import ( "net/url" "time" - "github.com/golang/protobuf/proto" gax "github.com/googleapis/gax-go/v2" "google.golang.org/api/iterator" "google.golang.org/api/option" @@ -33,6 +32,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newConversationsClientHook clientHook @@ -52,6 +52,7 @@ func defaultConversationsGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("dialogflow.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://dialogflow.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/dialogflow/apiv2/doc.go b/dialogflow/apiv2/doc.go index c758007337b..32d95a11eb1 100644 --- a/dialogflow/apiv2/doc.go +++ b/dialogflow/apiv2/doc.go @@ -49,7 +49,7 @@ import ( type clientHookParams struct{} type clientHook func(context.Context, clientHookParams) ([]option.ClientOption, error) -const versionClient = "20210617" +const versionClient = "20210701" func insertMetadata(ctx context.Context, mds ...metadata.MD) context.Context { out, _ := metadata.FromOutgoingContext(ctx) diff --git a/dialogflow/apiv2/documents_client.go b/dialogflow/apiv2/documents_client.go index ea6302b1f5c..9ccc6e10b61 100644 --- a/dialogflow/apiv2/documents_client.go +++ b/dialogflow/apiv2/documents_client.go @@ -25,7 +25,6 @@ import ( "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" @@ -36,6 +35,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newDocumentsClientHook clientHook @@ -56,6 +56,7 @@ func defaultDocumentsGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("dialogflow.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://dialogflow.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/dialogflow/apiv2/entity_types_client.go b/dialogflow/apiv2/entity_types_client.go index e65e03d4adc..81431a15203 100644 --- a/dialogflow/apiv2/entity_types_client.go +++ b/dialogflow/apiv2/entity_types_client.go @@ -25,7 +25,6 @@ import ( "cloud.google.com/go/longrunning" lroauto "cloud.google.com/go/longrunning/autogen" - "github.com/golang/protobuf/proto" structpb "github.com/golang/protobuf/ptypes/struct" gax "github.com/googleapis/gax-go/v2" "google.golang.org/api/iterator" @@ -37,6 +36,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newEntityTypesClientHook clientHook @@ -61,6 +61,7 @@ func defaultEntityTypesGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("dialogflow.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://dialogflow.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), @@ -254,23 +255,37 @@ func (c *EntityTypesClient) GetEntityType(ctx context.Context, req *dialogflowpb } // CreateEntityType creates an entity type in the specified agent. +// +// Note: You should always train an agent prior to sending it queries. See the +// training +// documentation (at https://cloud.google.com/dialogflow/es/docs/training). func (c *EntityTypesClient) CreateEntityType(ctx context.Context, req *dialogflowpb.CreateEntityTypeRequest, opts ...gax.CallOption) (*dialogflowpb.EntityType, error) { return c.internalClient.CreateEntityType(ctx, req, opts...) } // UpdateEntityType updates the specified entity type. +// +// Note: You should always train an agent prior to sending it queries. See the +// training +// documentation (at https://cloud.google.com/dialogflow/es/docs/training). func (c *EntityTypesClient) UpdateEntityType(ctx context.Context, req *dialogflowpb.UpdateEntityTypeRequest, opts ...gax.CallOption) (*dialogflowpb.EntityType, error) { return c.internalClient.UpdateEntityType(ctx, req, opts...) } // DeleteEntityType deletes the specified entity type. +// +// Note: You should always train an agent prior to sending it queries. See the +// training +// documentation (at https://cloud.google.com/dialogflow/es/docs/training). func (c *EntityTypesClient) DeleteEntityType(ctx context.Context, req *dialogflowpb.DeleteEntityTypeRequest, opts ...gax.CallOption) error { return c.internalClient.DeleteEntityType(ctx, req, opts...) } // BatchUpdateEntityTypes updates/Creates multiple entity types in the specified agent. // -// Operation +// Note: You should always train an agent prior to sending it queries. See the +// training +// documentation (at https://cloud.google.com/dialogflow/es/docs/training). func (c *EntityTypesClient) BatchUpdateEntityTypes(ctx context.Context, req *dialogflowpb.BatchUpdateEntityTypesRequest, opts ...gax.CallOption) (*BatchUpdateEntityTypesOperation, error) { return c.internalClient.BatchUpdateEntityTypes(ctx, req, opts...) } @@ -283,7 +298,9 @@ func (c *EntityTypesClient) BatchUpdateEntityTypesOperation(name string) *BatchU // BatchDeleteEntityTypes deletes entity types in the specified agent. // -// Operation +// Note: You should always train an agent prior to sending it queries. See the +// training +// documentation (at https://cloud.google.com/dialogflow/es/docs/training). func (c *EntityTypesClient) BatchDeleteEntityTypes(ctx context.Context, req *dialogflowpb.BatchDeleteEntityTypesRequest, opts ...gax.CallOption) (*BatchDeleteEntityTypesOperation, error) { return c.internalClient.BatchDeleteEntityTypes(ctx, req, opts...) } @@ -296,7 +313,9 @@ func (c *EntityTypesClient) BatchDeleteEntityTypesOperation(name string) *BatchD // BatchCreateEntities creates multiple new entities in the specified entity type. // -// Operation +// Note: You should always train an agent prior to sending it queries. See the +// training +// documentation (at https://cloud.google.com/dialogflow/es/docs/training). func (c *EntityTypesClient) BatchCreateEntities(ctx context.Context, req *dialogflowpb.BatchCreateEntitiesRequest, opts ...gax.CallOption) (*BatchCreateEntitiesOperation, error) { return c.internalClient.BatchCreateEntities(ctx, req, opts...) } @@ -311,7 +330,9 @@ func (c *EntityTypesClient) BatchCreateEntitiesOperation(name string) *BatchCrea // method does not affect entities in the entity type that aren’t explicitly // specified in the request. // -// Operation +// Note: You should always train an agent prior to sending it queries. See the +// training +// documentation (at https://cloud.google.com/dialogflow/es/docs/training). func (c *EntityTypesClient) BatchUpdateEntities(ctx context.Context, req *dialogflowpb.BatchUpdateEntitiesRequest, opts ...gax.CallOption) (*BatchUpdateEntitiesOperation, error) { return c.internalClient.BatchUpdateEntities(ctx, req, opts...) } @@ -324,7 +345,9 @@ func (c *EntityTypesClient) BatchUpdateEntitiesOperation(name string) *BatchUpda // BatchDeleteEntities deletes entities in the specified entity type. // -// Operation +// Note: You should always train an agent prior to sending it queries. See the +// training +// documentation (at https://cloud.google.com/dialogflow/es/docs/training). func (c *EntityTypesClient) BatchDeleteEntities(ctx context.Context, req *dialogflowpb.BatchDeleteEntitiesRequest, opts ...gax.CallOption) (*BatchDeleteEntitiesOperation, error) { return c.internalClient.BatchDeleteEntities(ctx, req, opts...) } diff --git a/dialogflow/apiv2/environments_client.go b/dialogflow/apiv2/environments_client.go index 310e2936460..4710977241f 100644 --- a/dialogflow/apiv2/environments_client.go +++ b/dialogflow/apiv2/environments_client.go @@ -23,7 +23,6 @@ import ( "net/url" "time" - "github.com/golang/protobuf/proto" gax "github.com/googleapis/gax-go/v2" "google.golang.org/api/iterator" "google.golang.org/api/option" @@ -33,6 +32,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newEnvironmentsClientHook clientHook @@ -53,6 +53,7 @@ func defaultEnvironmentsGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("dialogflow.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://dialogflow.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/dialogflow/apiv2/fulfillments_client.go b/dialogflow/apiv2/fulfillments_client.go index 0853a8bcee2..06fcd7116fc 100644 --- a/dialogflow/apiv2/fulfillments_client.go +++ b/dialogflow/apiv2/fulfillments_client.go @@ -47,6 +47,7 @@ func defaultFulfillmentsGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("dialogflow.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://dialogflow.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/dialogflow/apiv2/intents_client.go b/dialogflow/apiv2/intents_client.go index 6b033b88c56..943fcad720b 100644 --- a/dialogflow/apiv2/intents_client.go +++ b/dialogflow/apiv2/intents_client.go @@ -25,7 +25,6 @@ import ( "cloud.google.com/go/longrunning" lroauto "cloud.google.com/go/longrunning/autogen" - "github.com/golang/protobuf/proto" structpb "github.com/golang/protobuf/ptypes/struct" gax "github.com/googleapis/gax-go/v2" "google.golang.org/api/iterator" @@ -37,6 +36,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newIntentsClientHook clientHook @@ -58,6 +58,7 @@ func defaultIntentsGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("dialogflow.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://dialogflow.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), @@ -212,23 +213,37 @@ func (c *IntentsClient) GetIntent(ctx context.Context, req *dialogflowpb.GetInte } // CreateIntent creates an intent in the specified agent. +// +// Note: You should always train an agent prior to sending it queries. See the +// training +// documentation (at https://cloud.google.com/dialogflow/es/docs/training). func (c *IntentsClient) CreateIntent(ctx context.Context, req *dialogflowpb.CreateIntentRequest, opts ...gax.CallOption) (*dialogflowpb.Intent, error) { return c.internalClient.CreateIntent(ctx, req, opts...) } // UpdateIntent updates the specified intent. +// +// Note: You should always train an agent prior to sending it queries. See the +// training +// documentation (at https://cloud.google.com/dialogflow/es/docs/training). func (c *IntentsClient) UpdateIntent(ctx context.Context, req *dialogflowpb.UpdateIntentRequest, opts ...gax.CallOption) (*dialogflowpb.Intent, error) { return c.internalClient.UpdateIntent(ctx, req, opts...) } // DeleteIntent deletes the specified intent and its direct or indirect followup intents. +// +// Note: You should always train an agent prior to sending it queries. See the +// training +// documentation (at https://cloud.google.com/dialogflow/es/docs/training). func (c *IntentsClient) DeleteIntent(ctx context.Context, req *dialogflowpb.DeleteIntentRequest, opts ...gax.CallOption) error { return c.internalClient.DeleteIntent(ctx, req, opts...) } // BatchUpdateIntents updates/Creates multiple intents in the specified agent. // -// Operation +// Note: You should always train an agent prior to sending it queries. See the +// training +// documentation (at https://cloud.google.com/dialogflow/es/docs/training). func (c *IntentsClient) BatchUpdateIntents(ctx context.Context, req *dialogflowpb.BatchUpdateIntentsRequest, opts ...gax.CallOption) (*BatchUpdateIntentsOperation, error) { return c.internalClient.BatchUpdateIntents(ctx, req, opts...) } @@ -241,7 +256,9 @@ func (c *IntentsClient) BatchUpdateIntentsOperation(name string) *BatchUpdateInt // BatchDeleteIntents deletes intents in the specified agent. // -// Operation +// Note: You should always train an agent prior to sending it queries. See the +// training +// documentation (at https://cloud.google.com/dialogflow/es/docs/training). func (c *IntentsClient) BatchDeleteIntents(ctx context.Context, req *dialogflowpb.BatchDeleteIntentsRequest, opts ...gax.CallOption) (*BatchDeleteIntentsOperation, error) { return c.internalClient.BatchDeleteIntents(ctx, req, opts...) } diff --git a/dialogflow/apiv2/knowledge_bases_client.go b/dialogflow/apiv2/knowledge_bases_client.go index cb339c67410..7772de6bf35 100644 --- a/dialogflow/apiv2/knowledge_bases_client.go +++ b/dialogflow/apiv2/knowledge_bases_client.go @@ -23,7 +23,6 @@ import ( "net/url" "time" - "github.com/golang/protobuf/proto" gax "github.com/googleapis/gax-go/v2" "google.golang.org/api/iterator" "google.golang.org/api/option" @@ -33,6 +32,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newKnowledgeBasesClientHook clientHook @@ -52,6 +52,7 @@ func defaultKnowledgeBasesGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("dialogflow.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://dialogflow.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/dialogflow/apiv2/participants_client.go b/dialogflow/apiv2/participants_client.go index edc7c36512f..3e10e0ce495 100644 --- a/dialogflow/apiv2/participants_client.go +++ b/dialogflow/apiv2/participants_client.go @@ -23,7 +23,6 @@ import ( "net/url" "time" - "github.com/golang/protobuf/proto" gax "github.com/googleapis/gax-go/v2" "google.golang.org/api/iterator" "google.golang.org/api/option" @@ -33,6 +32,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newParticipantsClientHook clientHook @@ -54,6 +54,7 @@ func defaultParticipantsGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("dialogflow.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://dialogflow.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/dialogflow/apiv2/session_entity_types_client.go b/dialogflow/apiv2/session_entity_types_client.go index dceedf6fcd1..077bf4ab083 100644 --- a/dialogflow/apiv2/session_entity_types_client.go +++ b/dialogflow/apiv2/session_entity_types_client.go @@ -23,7 +23,6 @@ import ( "net/url" "time" - "github.com/golang/protobuf/proto" gax "github.com/googleapis/gax-go/v2" "google.golang.org/api/iterator" "google.golang.org/api/option" @@ -33,6 +32,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newSessionEntityTypesClientHook clientHook @@ -52,6 +52,7 @@ func defaultSessionEntityTypesGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("dialogflow.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://dialogflow.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/dialogflow/apiv2/sessions_client.go b/dialogflow/apiv2/sessions_client.go index 05dd73c3229..878f22f45d6 100644 --- a/dialogflow/apiv2/sessions_client.go +++ b/dialogflow/apiv2/sessions_client.go @@ -47,6 +47,7 @@ func defaultSessionsGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("dialogflow.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://dialogflow.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/dialogflow/apiv2/versions_client.go b/dialogflow/apiv2/versions_client.go index cc0db296f6d..b813a24bce6 100644 --- a/dialogflow/apiv2/versions_client.go +++ b/dialogflow/apiv2/versions_client.go @@ -23,7 +23,6 @@ import ( "net/url" "time" - "github.com/golang/protobuf/proto" gax "github.com/googleapis/gax-go/v2" "google.golang.org/api/iterator" "google.golang.org/api/option" @@ -33,6 +32,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newVersionsClientHook clientHook @@ -52,6 +52,7 @@ func defaultVersionsGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("dialogflow.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://dialogflow.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/dialogflow/cx/apiv3/agents_client.go b/dialogflow/cx/apiv3/agents_client.go index 4a9bdc216ae..21623d410fb 100644 --- a/dialogflow/cx/apiv3/agents_client.go +++ b/dialogflow/cx/apiv3/agents_client.go @@ -25,7 +25,6 @@ import ( "cloud.google.com/go/longrunning" lroauto "cloud.google.com/go/longrunning/autogen" - "github.com/golang/protobuf/proto" structpb "github.com/golang/protobuf/ptypes/struct" gax "github.com/googleapis/gax-go/v2" "google.golang.org/api/iterator" @@ -37,6 +36,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newAgentsClientHook clientHook @@ -60,6 +60,7 @@ func defaultAgentsGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("dialogflow.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://dialogflow.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), @@ -238,11 +239,19 @@ func (c *AgentsClient) GetAgent(ctx context.Context, req *cxpb.GetAgentRequest, } // CreateAgent creates an agent in the specified location. +// +// Note: You should always train flows prior to sending them queries. See the +// training +// documentation (at https://cloud.google.com/dialogflow/cx/docs/concept/training). func (c *AgentsClient) CreateAgent(ctx context.Context, req *cxpb.CreateAgentRequest, opts ...gax.CallOption) (*cxpb.Agent, error) { return c.internalClient.CreateAgent(ctx, req, opts...) } // UpdateAgent updates the specified agent. +// +// Note: You should always train flows prior to sending them queries. See the +// training +// documentation (at https://cloud.google.com/dialogflow/cx/docs/concept/training). func (c *AgentsClient) UpdateAgent(ctx context.Context, req *cxpb.UpdateAgentRequest, opts ...gax.CallOption) (*cxpb.Agent, error) { return c.internalClient.UpdateAgent(ctx, req, opts...) } @@ -267,6 +276,10 @@ func (c *AgentsClient) ExportAgentOperation(name string) *ExportAgentOperation { // // Replaces the current agent with a new one. Note that all existing resources // in agent (e.g. intents, entity types, flows) will be removed. +// +// Note: You should always train flows prior to sending them queries. See the +// training +// documentation (at https://cloud.google.com/dialogflow/cx/docs/concept/training). func (c *AgentsClient) RestoreAgent(ctx context.Context, req *cxpb.RestoreAgentRequest, opts ...gax.CallOption) (*RestoreAgentOperation, error) { return c.internalClient.RestoreAgent(ctx, req, opts...) } diff --git a/dialogflow/cx/apiv3/doc.go b/dialogflow/cx/apiv3/doc.go index a1bebf150e0..9b11084fd7f 100644 --- a/dialogflow/cx/apiv3/doc.go +++ b/dialogflow/cx/apiv3/doc.go @@ -20,8 +20,6 @@ // Builds conversational interfaces (for example, chatbots, and voice-powered // apps and devices). // -// 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 @@ -51,7 +49,7 @@ import ( type clientHookParams struct{} type clientHook func(context.Context, clientHookParams) ([]option.ClientOption, error) -const versionClient = "20210612" +const versionClient = "20210701" func insertMetadata(ctx context.Context, mds ...metadata.MD) context.Context { out, _ := metadata.FromOutgoingContext(ctx) diff --git a/dialogflow/cx/apiv3/entity_types_client.go b/dialogflow/cx/apiv3/entity_types_client.go index 8f861a110b9..b83a0712ee2 100644 --- a/dialogflow/cx/apiv3/entity_types_client.go +++ b/dialogflow/cx/apiv3/entity_types_client.go @@ -23,7 +23,6 @@ import ( "net/url" "time" - "github.com/golang/protobuf/proto" gax "github.com/googleapis/gax-go/v2" "google.golang.org/api/iterator" "google.golang.org/api/option" @@ -33,6 +32,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newEntityTypesClientHook clientHook @@ -52,6 +52,7 @@ func defaultEntityTypesGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("dialogflow.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://dialogflow.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), @@ -175,16 +176,28 @@ func (c *EntityTypesClient) GetEntityType(ctx context.Context, req *cxpb.GetEnti } // CreateEntityType creates an entity type in the specified agent. +// +// Note: You should always train a flow prior to sending it queries. See the +// training +// documentation (at https://cloud.google.com/dialogflow/cx/docs/concept/training). func (c *EntityTypesClient) CreateEntityType(ctx context.Context, req *cxpb.CreateEntityTypeRequest, opts ...gax.CallOption) (*cxpb.EntityType, error) { return c.internalClient.CreateEntityType(ctx, req, opts...) } // UpdateEntityType updates the specified entity type. +// +// Note: You should always train a flow prior to sending it queries. See the +// training +// documentation (at https://cloud.google.com/dialogflow/cx/docs/concept/training). func (c *EntityTypesClient) UpdateEntityType(ctx context.Context, req *cxpb.UpdateEntityTypeRequest, opts ...gax.CallOption) (*cxpb.EntityType, error) { return c.internalClient.UpdateEntityType(ctx, req, opts...) } // DeleteEntityType deletes the specified entity type. +// +// Note: You should always train a flow prior to sending it queries. See the +// training +// documentation (at https://cloud.google.com/dialogflow/cx/docs/concept/training). func (c *EntityTypesClient) DeleteEntityType(ctx context.Context, req *cxpb.DeleteEntityTypeRequest, opts ...gax.CallOption) error { return c.internalClient.DeleteEntityType(ctx, req, opts...) } diff --git a/dialogflow/cx/apiv3/environments_client.go b/dialogflow/cx/apiv3/environments_client.go index 54b78cded35..fe106fbf731 100644 --- a/dialogflow/cx/apiv3/environments_client.go +++ b/dialogflow/cx/apiv3/environments_client.go @@ -25,7 +25,6 @@ import ( "cloud.google.com/go/longrunning" lroauto "cloud.google.com/go/longrunning/autogen" - "github.com/golang/protobuf/proto" structpb "github.com/golang/protobuf/ptypes/struct" gax "github.com/googleapis/gax-go/v2" "google.golang.org/api/iterator" @@ -37,6 +36,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newEnvironmentsClientHook clientHook @@ -59,6 +59,7 @@ func defaultEnvironmentsGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("dialogflow.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://dialogflow.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/dialogflow/cx/apiv3/experiments_client.go b/dialogflow/cx/apiv3/experiments_client.go index 35d71ae941a..e3effcf44be 100644 --- a/dialogflow/cx/apiv3/experiments_client.go +++ b/dialogflow/cx/apiv3/experiments_client.go @@ -23,7 +23,6 @@ import ( "net/url" "time" - "github.com/golang/protobuf/proto" gax "github.com/googleapis/gax-go/v2" "google.golang.org/api/iterator" "google.golang.org/api/option" @@ -33,6 +32,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newExperimentsClientHook clientHook @@ -54,6 +54,7 @@ func defaultExperimentsGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("dialogflow.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://dialogflow.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/dialogflow/cx/apiv3/flows_client.go b/dialogflow/cx/apiv3/flows_client.go index 6bc73b4ba11..925c3737c07 100644 --- a/dialogflow/cx/apiv3/flows_client.go +++ b/dialogflow/cx/apiv3/flows_client.go @@ -25,7 +25,6 @@ import ( "cloud.google.com/go/longrunning" lroauto "cloud.google.com/go/longrunning/autogen" - "github.com/golang/protobuf/proto" structpb "github.com/golang/protobuf/ptypes/struct" gax "github.com/googleapis/gax-go/v2" "google.golang.org/api/iterator" @@ -37,6 +36,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newFlowsClientHook clientHook @@ -61,6 +61,7 @@ func defaultFlowsGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("dialogflow.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://dialogflow.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), @@ -242,6 +243,10 @@ func (c *FlowsClient) Connection() *grpc.ClientConn { } // CreateFlow creates a flow in the specified agent. +// +// Note: You should always train a flow prior to sending it queries. See the +// training +// documentation (at https://cloud.google.com/dialogflow/cx/docs/concept/training). func (c *FlowsClient) CreateFlow(ctx context.Context, req *cxpb.CreateFlowRequest, opts ...gax.CallOption) (*cxpb.Flow, error) { return c.internalClient.CreateFlow(ctx, req, opts...) } @@ -262,12 +267,20 @@ func (c *FlowsClient) GetFlow(ctx context.Context, req *cxpb.GetFlowRequest, opt } // UpdateFlow updates the specified flow. +// +// Note: You should always train a flow prior to sending it queries. See the +// training +// documentation (at https://cloud.google.com/dialogflow/cx/docs/concept/training). func (c *FlowsClient) UpdateFlow(ctx context.Context, req *cxpb.UpdateFlowRequest, opts ...gax.CallOption) (*cxpb.Flow, error) { return c.internalClient.UpdateFlow(ctx, req, opts...) } // TrainFlow trains the specified flow. Note that only the flow in ‘draft’ environment // is trained. +// +// Note: You should always train a flow prior to sending it queries. See the +// training +// documentation (at https://cloud.google.com/dialogflow/cx/docs/concept/training). func (c *FlowsClient) TrainFlow(ctx context.Context, req *cxpb.TrainFlowRequest, opts ...gax.CallOption) (*TrainFlowOperation, error) { return c.internalClient.TrainFlow(ctx, req, opts...) } @@ -292,6 +305,10 @@ func (c *FlowsClient) GetFlowValidationResult(ctx context.Context, req *cxpb.Get } // ImportFlow imports the specified flow to the specified agent from a binary file. +// +// Note: You should always train a flow prior to sending it queries. See the +// training +// documentation (at https://cloud.google.com/dialogflow/cx/docs/concept/training). func (c *FlowsClient) ImportFlow(ctx context.Context, req *cxpb.ImportFlowRequest, opts ...gax.CallOption) (*ImportFlowOperation, error) { return c.internalClient.ImportFlow(ctx, req, opts...) } diff --git a/dialogflow/cx/apiv3/intents_client.go b/dialogflow/cx/apiv3/intents_client.go index b5c6963b708..bcd010bb58d 100644 --- a/dialogflow/cx/apiv3/intents_client.go +++ b/dialogflow/cx/apiv3/intents_client.go @@ -23,7 +23,6 @@ import ( "net/url" "time" - "github.com/golang/protobuf/proto" gax "github.com/googleapis/gax-go/v2" "google.golang.org/api/iterator" "google.golang.org/api/option" @@ -33,6 +32,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newIntentsClientHook clientHook @@ -52,6 +52,7 @@ func defaultIntentsGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("dialogflow.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://dialogflow.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), @@ -175,16 +176,28 @@ func (c *IntentsClient) GetIntent(ctx context.Context, req *cxpb.GetIntentReques } // CreateIntent creates an intent in the specified agent. +// +// Note: You should always train a flow prior to sending it queries. See the +// training +// documentation (at https://cloud.google.com/dialogflow/cx/docs/concept/training). func (c *IntentsClient) CreateIntent(ctx context.Context, req *cxpb.CreateIntentRequest, opts ...gax.CallOption) (*cxpb.Intent, error) { return c.internalClient.CreateIntent(ctx, req, opts...) } // UpdateIntent updates the specified intent. +// +// Note: You should always train a flow prior to sending it queries. See the +// training +// documentation (at https://cloud.google.com/dialogflow/cx/docs/concept/training). func (c *IntentsClient) UpdateIntent(ctx context.Context, req *cxpb.UpdateIntentRequest, opts ...gax.CallOption) (*cxpb.Intent, error) { return c.internalClient.UpdateIntent(ctx, req, opts...) } // DeleteIntent deletes the specified intent. +// +// Note: You should always train a flow prior to sending it queries. See the +// training +// documentation (at https://cloud.google.com/dialogflow/cx/docs/concept/training). func (c *IntentsClient) DeleteIntent(ctx context.Context, req *cxpb.DeleteIntentRequest, opts ...gax.CallOption) error { return c.internalClient.DeleteIntent(ctx, req, opts...) } diff --git a/dialogflow/cx/apiv3/pages_client.go b/dialogflow/cx/apiv3/pages_client.go index 4783a0eb75d..72666daa72b 100644 --- a/dialogflow/cx/apiv3/pages_client.go +++ b/dialogflow/cx/apiv3/pages_client.go @@ -23,7 +23,6 @@ import ( "net/url" "time" - "github.com/golang/protobuf/proto" gax "github.com/googleapis/gax-go/v2" "google.golang.org/api/iterator" "google.golang.org/api/option" @@ -33,6 +32,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newPagesClientHook clientHook @@ -52,6 +52,7 @@ func defaultPagesGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("dialogflow.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://dialogflow.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), @@ -175,16 +176,28 @@ func (c *PagesClient) GetPage(ctx context.Context, req *cxpb.GetPageRequest, opt } // CreatePage creates a page in the specified flow. +// +// Note: You should always train a flow prior to sending it queries. See the +// training +// documentation (at https://cloud.google.com/dialogflow/cx/docs/concept/training). func (c *PagesClient) CreatePage(ctx context.Context, req *cxpb.CreatePageRequest, opts ...gax.CallOption) (*cxpb.Page, error) { return c.internalClient.CreatePage(ctx, req, opts...) } // UpdatePage updates the specified page. +// +// Note: You should always train a flow prior to sending it queries. See the +// training +// documentation (at https://cloud.google.com/dialogflow/cx/docs/concept/training). func (c *PagesClient) UpdatePage(ctx context.Context, req *cxpb.UpdatePageRequest, opts ...gax.CallOption) (*cxpb.Page, error) { return c.internalClient.UpdatePage(ctx, req, opts...) } // DeletePage deletes the specified page. +// +// Note: You should always train a flow prior to sending it queries. See the +// training +// documentation (at https://cloud.google.com/dialogflow/cx/docs/concept/training). func (c *PagesClient) DeletePage(ctx context.Context, req *cxpb.DeletePageRequest, opts ...gax.CallOption) error { return c.internalClient.DeletePage(ctx, req, opts...) } diff --git a/dialogflow/cx/apiv3/security_settings_client.go b/dialogflow/cx/apiv3/security_settings_client.go index 6ed77d67bb3..9c6fe124670 100644 --- a/dialogflow/cx/apiv3/security_settings_client.go +++ b/dialogflow/cx/apiv3/security_settings_client.go @@ -23,7 +23,6 @@ import ( "net/url" "time" - "github.com/golang/protobuf/proto" gax "github.com/googleapis/gax-go/v2" "google.golang.org/api/iterator" "google.golang.org/api/option" @@ -33,6 +32,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newSecuritySettingsClientHook clientHook @@ -52,6 +52,7 @@ func defaultSecuritySettingsGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("dialogflow.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://dialogflow.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/dialogflow/cx/apiv3/session_entity_types_client.go b/dialogflow/cx/apiv3/session_entity_types_client.go index 2140f40dd18..c9f0380baff 100644 --- a/dialogflow/cx/apiv3/session_entity_types_client.go +++ b/dialogflow/cx/apiv3/session_entity_types_client.go @@ -23,7 +23,6 @@ import ( "net/url" "time" - "github.com/golang/protobuf/proto" gax "github.com/googleapis/gax-go/v2" "google.golang.org/api/iterator" "google.golang.org/api/option" @@ -33,6 +32,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newSessionEntityTypesClientHook clientHook @@ -52,6 +52,7 @@ func defaultSessionEntityTypesGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("dialogflow.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://dialogflow.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/dialogflow/cx/apiv3/sessions_client.go b/dialogflow/cx/apiv3/sessions_client.go index d83dd24d87b..54de3d9551e 100644 --- a/dialogflow/cx/apiv3/sessions_client.go +++ b/dialogflow/cx/apiv3/sessions_client.go @@ -49,6 +49,7 @@ func defaultSessionsGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("dialogflow.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://dialogflow.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/dialogflow/cx/apiv3/test_cases_client.go b/dialogflow/cx/apiv3/test_cases_client.go index 34c54b698c5..c780c3c5c95 100644 --- a/dialogflow/cx/apiv3/test_cases_client.go +++ b/dialogflow/cx/apiv3/test_cases_client.go @@ -25,7 +25,6 @@ import ( "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" @@ -36,6 +35,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newTestCasesClientHook clientHook @@ -62,6 +62,7 @@ func defaultTestCasesGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("dialogflow.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://dialogflow.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/dialogflow/cx/apiv3/transition_route_groups_client.go b/dialogflow/cx/apiv3/transition_route_groups_client.go index dfa7a11800a..9963cdc2073 100644 --- a/dialogflow/cx/apiv3/transition_route_groups_client.go +++ b/dialogflow/cx/apiv3/transition_route_groups_client.go @@ -23,7 +23,6 @@ import ( "net/url" "time" - "github.com/golang/protobuf/proto" gax "github.com/googleapis/gax-go/v2" "google.golang.org/api/iterator" "google.golang.org/api/option" @@ -33,6 +32,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newTransitionRouteGroupsClientHook clientHook @@ -52,6 +52,7 @@ func defaultTransitionRouteGroupsGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("dialogflow.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://dialogflow.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), @@ -175,16 +176,28 @@ func (c *TransitionRouteGroupsClient) GetTransitionRouteGroup(ctx context.Contex } // CreateTransitionRouteGroup creates an TransitionRouteGroup in the specified flow. +// +// Note: You should always train a flow prior to sending it queries. See the +// training +// documentation (at https://cloud.google.com/dialogflow/cx/docs/concept/training). func (c *TransitionRouteGroupsClient) CreateTransitionRouteGroup(ctx context.Context, req *cxpb.CreateTransitionRouteGroupRequest, opts ...gax.CallOption) (*cxpb.TransitionRouteGroup, error) { return c.internalClient.CreateTransitionRouteGroup(ctx, req, opts...) } // UpdateTransitionRouteGroup updates the specified TransitionRouteGroup. +// +// Note: You should always train a flow prior to sending it queries. See the +// training +// documentation (at https://cloud.google.com/dialogflow/cx/docs/concept/training). func (c *TransitionRouteGroupsClient) UpdateTransitionRouteGroup(ctx context.Context, req *cxpb.UpdateTransitionRouteGroupRequest, opts ...gax.CallOption) (*cxpb.TransitionRouteGroup, error) { return c.internalClient.UpdateTransitionRouteGroup(ctx, req, opts...) } // DeleteTransitionRouteGroup deletes the specified TransitionRouteGroup. +// +// Note: You should always train a flow prior to sending it queries. See the +// training +// documentation (at https://cloud.google.com/dialogflow/cx/docs/concept/training). func (c *TransitionRouteGroupsClient) DeleteTransitionRouteGroup(ctx context.Context, req *cxpb.DeleteTransitionRouteGroupRequest, opts ...gax.CallOption) error { return c.internalClient.DeleteTransitionRouteGroup(ctx, req, opts...) } diff --git a/dialogflow/cx/apiv3/versions_client.go b/dialogflow/cx/apiv3/versions_client.go index 11febef026e..b400500eaf1 100644 --- a/dialogflow/cx/apiv3/versions_client.go +++ b/dialogflow/cx/apiv3/versions_client.go @@ -25,7 +25,6 @@ import ( "cloud.google.com/go/longrunning" lroauto "cloud.google.com/go/longrunning/autogen" - "github.com/golang/protobuf/proto" structpb "github.com/golang/protobuf/ptypes/struct" gax "github.com/googleapis/gax-go/v2" "google.golang.org/api/iterator" @@ -37,6 +36,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newVersionsClientHook clientHook @@ -57,6 +57,7 @@ func defaultVersionsGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("dialogflow.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://dialogflow.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/dialogflow/cx/apiv3/webhooks_client.go b/dialogflow/cx/apiv3/webhooks_client.go index b097a71bcc0..b589171ae2e 100644 --- a/dialogflow/cx/apiv3/webhooks_client.go +++ b/dialogflow/cx/apiv3/webhooks_client.go @@ -23,7 +23,6 @@ import ( "net/url" "time" - "github.com/golang/protobuf/proto" gax "github.com/googleapis/gax-go/v2" "google.golang.org/api/iterator" "google.golang.org/api/option" @@ -33,6 +32,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newWebhooksClientHook clientHook @@ -52,6 +52,7 @@ func defaultWebhooksGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("dialogflow.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://dialogflow.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/dialogflow/cx/apiv3beta1/agents_client.go b/dialogflow/cx/apiv3beta1/agents_client.go index 131c311e2fd..2aadca15813 100644 --- a/dialogflow/cx/apiv3beta1/agents_client.go +++ b/dialogflow/cx/apiv3beta1/agents_client.go @@ -25,7 +25,6 @@ import ( "cloud.google.com/go/longrunning" lroauto "cloud.google.com/go/longrunning/autogen" - "github.com/golang/protobuf/proto" structpb "github.com/golang/protobuf/ptypes/struct" gax "github.com/googleapis/gax-go/v2" "google.golang.org/api/iterator" @@ -37,6 +36,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newAgentsClientHook clientHook @@ -60,6 +60,7 @@ func defaultAgentsGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("dialogflow.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://dialogflow.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), @@ -238,11 +239,19 @@ func (c *AgentsClient) GetAgent(ctx context.Context, req *cxpb.GetAgentRequest, } // CreateAgent creates an agent in the specified location. +// +// Note: You should always train a flow prior to sending it queries. See the +// training +// documentation (at https://cloud.google.com/dialogflow/cx/docs/concept/training). func (c *AgentsClient) CreateAgent(ctx context.Context, req *cxpb.CreateAgentRequest, opts ...gax.CallOption) (*cxpb.Agent, error) { return c.internalClient.CreateAgent(ctx, req, opts...) } // UpdateAgent updates the specified agent. +// +// Note: You should always train a flow prior to sending it queries. See the +// training +// documentation (at https://cloud.google.com/dialogflow/cx/docs/concept/training). func (c *AgentsClient) UpdateAgent(ctx context.Context, req *cxpb.UpdateAgentRequest, opts ...gax.CallOption) (*cxpb.Agent, error) { return c.internalClient.UpdateAgent(ctx, req, opts...) } @@ -267,6 +276,10 @@ func (c *AgentsClient) ExportAgentOperation(name string) *ExportAgentOperation { // // Replaces the current agent with a new one. Note that all existing resources // in agent (e.g. intents, entity types, flows) will be removed. +// +// Note: You should always train a flow prior to sending it queries. See the +// training +// documentation (at https://cloud.google.com/dialogflow/cx/docs/concept/training). func (c *AgentsClient) RestoreAgent(ctx context.Context, req *cxpb.RestoreAgentRequest, opts ...gax.CallOption) (*RestoreAgentOperation, error) { return c.internalClient.RestoreAgent(ctx, req, opts...) } diff --git a/dialogflow/cx/apiv3beta1/doc.go b/dialogflow/cx/apiv3beta1/doc.go index 012b6036163..1c2c2e8e25f 100644 --- a/dialogflow/cx/apiv3beta1/doc.go +++ b/dialogflow/cx/apiv3beta1/doc.go @@ -51,7 +51,7 @@ import ( type clientHookParams struct{} type clientHook func(context.Context, clientHookParams) ([]option.ClientOption, error) -const versionClient = "20210612" +const versionClient = "20210701" func insertMetadata(ctx context.Context, mds ...metadata.MD) context.Context { out, _ := metadata.FromOutgoingContext(ctx) diff --git a/dialogflow/cx/apiv3beta1/entity_types_client.go b/dialogflow/cx/apiv3beta1/entity_types_client.go index 5190cd5fc42..1356e6a40b8 100644 --- a/dialogflow/cx/apiv3beta1/entity_types_client.go +++ b/dialogflow/cx/apiv3beta1/entity_types_client.go @@ -23,7 +23,6 @@ import ( "net/url" "time" - "github.com/golang/protobuf/proto" gax "github.com/googleapis/gax-go/v2" "google.golang.org/api/iterator" "google.golang.org/api/option" @@ -33,6 +32,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newEntityTypesClientHook clientHook @@ -52,6 +52,7 @@ func defaultEntityTypesGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("dialogflow.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://dialogflow.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), @@ -180,11 +181,19 @@ func (c *EntityTypesClient) CreateEntityType(ctx context.Context, req *cxpb.Crea } // UpdateEntityType updates the specified entity type. +// +// Note: You should always train a flow prior to sending it queries. See the +// training +// documentation (at https://cloud.google.com/dialogflow/cx/docs/concept/training). func (c *EntityTypesClient) UpdateEntityType(ctx context.Context, req *cxpb.UpdateEntityTypeRequest, opts ...gax.CallOption) (*cxpb.EntityType, error) { return c.internalClient.UpdateEntityType(ctx, req, opts...) } // DeleteEntityType deletes the specified entity type. +// +// Note: You should always train a flow prior to sending it queries. See the +// training +// documentation (at https://cloud.google.com/dialogflow/cx/docs/concept/training). func (c *EntityTypesClient) DeleteEntityType(ctx context.Context, req *cxpb.DeleteEntityTypeRequest, opts ...gax.CallOption) error { return c.internalClient.DeleteEntityType(ctx, req, opts...) } diff --git a/dialogflow/cx/apiv3beta1/environments_client.go b/dialogflow/cx/apiv3beta1/environments_client.go index 1a8e55670bb..d5262806e2e 100644 --- a/dialogflow/cx/apiv3beta1/environments_client.go +++ b/dialogflow/cx/apiv3beta1/environments_client.go @@ -25,7 +25,6 @@ import ( "cloud.google.com/go/longrunning" lroauto "cloud.google.com/go/longrunning/autogen" - "github.com/golang/protobuf/proto" structpb "github.com/golang/protobuf/ptypes/struct" gax "github.com/googleapis/gax-go/v2" "google.golang.org/api/iterator" @@ -37,6 +36,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newEnvironmentsClientHook clientHook @@ -59,6 +59,7 @@ func defaultEnvironmentsGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("dialogflow.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://dialogflow.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/dialogflow/cx/apiv3beta1/experiments_client.go b/dialogflow/cx/apiv3beta1/experiments_client.go index e39247aa6af..60a5d6e51f0 100644 --- a/dialogflow/cx/apiv3beta1/experiments_client.go +++ b/dialogflow/cx/apiv3beta1/experiments_client.go @@ -23,7 +23,6 @@ import ( "net/url" "time" - "github.com/golang/protobuf/proto" gax "github.com/googleapis/gax-go/v2" "google.golang.org/api/iterator" "google.golang.org/api/option" @@ -33,6 +32,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newExperimentsClientHook clientHook @@ -54,6 +54,7 @@ func defaultExperimentsGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("dialogflow.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://dialogflow.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/dialogflow/cx/apiv3beta1/flows_client.go b/dialogflow/cx/apiv3beta1/flows_client.go index 606175729ea..ba2b783d087 100644 --- a/dialogflow/cx/apiv3beta1/flows_client.go +++ b/dialogflow/cx/apiv3beta1/flows_client.go @@ -25,7 +25,6 @@ import ( "cloud.google.com/go/longrunning" lroauto "cloud.google.com/go/longrunning/autogen" - "github.com/golang/protobuf/proto" structpb "github.com/golang/protobuf/ptypes/struct" gax "github.com/googleapis/gax-go/v2" "google.golang.org/api/iterator" @@ -37,6 +36,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newFlowsClientHook clientHook @@ -61,6 +61,7 @@ func defaultFlowsGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("dialogflow.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://dialogflow.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), @@ -242,6 +243,10 @@ func (c *FlowsClient) Connection() *grpc.ClientConn { } // CreateFlow creates a flow in the specified agent. +// +// Note: You should always train a flow prior to sending it queries. See the +// training +// documentation (at https://cloud.google.com/dialogflow/cx/docs/concept/training). func (c *FlowsClient) CreateFlow(ctx context.Context, req *cxpb.CreateFlowRequest, opts ...gax.CallOption) (*cxpb.Flow, error) { return c.internalClient.CreateFlow(ctx, req, opts...) } @@ -262,12 +267,20 @@ func (c *FlowsClient) GetFlow(ctx context.Context, req *cxpb.GetFlowRequest, opt } // UpdateFlow updates the specified flow. +// +// Note: You should always train a flow prior to sending it queries. See the +// training +// documentation (at https://cloud.google.com/dialogflow/cx/docs/concept/training). func (c *FlowsClient) UpdateFlow(ctx context.Context, req *cxpb.UpdateFlowRequest, opts ...gax.CallOption) (*cxpb.Flow, error) { return c.internalClient.UpdateFlow(ctx, req, opts...) } // TrainFlow trains the specified flow. Note that only the flow in ‘draft’ environment // is trained. +// +// Note: You should always train a flow prior to sending it queries. See the +// training +// documentation (at https://cloud.google.com/dialogflow/cx/docs/concept/training). func (c *FlowsClient) TrainFlow(ctx context.Context, req *cxpb.TrainFlowRequest, opts ...gax.CallOption) (*TrainFlowOperation, error) { return c.internalClient.TrainFlow(ctx, req, opts...) } @@ -292,6 +305,10 @@ func (c *FlowsClient) GetFlowValidationResult(ctx context.Context, req *cxpb.Get } // ImportFlow imports the specified flow to the specified agent from a binary file. +// +// Note: You should always train a flow prior to sending it queries. See the +// training +// documentation (at https://cloud.google.com/dialogflow/cx/docs/concept/training). func (c *FlowsClient) ImportFlow(ctx context.Context, req *cxpb.ImportFlowRequest, opts ...gax.CallOption) (*ImportFlowOperation, error) { return c.internalClient.ImportFlow(ctx, req, opts...) } diff --git a/dialogflow/cx/apiv3beta1/intents_client.go b/dialogflow/cx/apiv3beta1/intents_client.go index ebb8125f371..e321664e981 100644 --- a/dialogflow/cx/apiv3beta1/intents_client.go +++ b/dialogflow/cx/apiv3beta1/intents_client.go @@ -23,7 +23,6 @@ import ( "net/url" "time" - "github.com/golang/protobuf/proto" gax "github.com/googleapis/gax-go/v2" "google.golang.org/api/iterator" "google.golang.org/api/option" @@ -33,6 +32,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newIntentsClientHook clientHook @@ -52,6 +52,7 @@ func defaultIntentsGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("dialogflow.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://dialogflow.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), @@ -175,16 +176,28 @@ func (c *IntentsClient) GetIntent(ctx context.Context, req *cxpb.GetIntentReques } // CreateIntent creates an intent in the specified agent. +// +// Note: You should always train a flow prior to sending it queries. See the +// training +// documentation (at https://cloud.google.com/dialogflow/cx/docs/concept/training). func (c *IntentsClient) CreateIntent(ctx context.Context, req *cxpb.CreateIntentRequest, opts ...gax.CallOption) (*cxpb.Intent, error) { return c.internalClient.CreateIntent(ctx, req, opts...) } // UpdateIntent updates the specified intent. +// +// Note: You should always train a flow prior to sending it queries. See the +// training +// documentation (at https://cloud.google.com/dialogflow/cx/docs/concept/training). func (c *IntentsClient) UpdateIntent(ctx context.Context, req *cxpb.UpdateIntentRequest, opts ...gax.CallOption) (*cxpb.Intent, error) { return c.internalClient.UpdateIntent(ctx, req, opts...) } // DeleteIntent deletes the specified intent. +// +// Note: You should always train a flow prior to sending it queries. See the +// training +// documentation (at https://cloud.google.com/dialogflow/cx/docs/concept/training). func (c *IntentsClient) DeleteIntent(ctx context.Context, req *cxpb.DeleteIntentRequest, opts ...gax.CallOption) error { return c.internalClient.DeleteIntent(ctx, req, opts...) } diff --git a/dialogflow/cx/apiv3beta1/pages_client.go b/dialogflow/cx/apiv3beta1/pages_client.go index 82ef5a19765..9e980d34e3f 100644 --- a/dialogflow/cx/apiv3beta1/pages_client.go +++ b/dialogflow/cx/apiv3beta1/pages_client.go @@ -23,7 +23,6 @@ import ( "net/url" "time" - "github.com/golang/protobuf/proto" gax "github.com/googleapis/gax-go/v2" "google.golang.org/api/iterator" "google.golang.org/api/option" @@ -33,6 +32,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newPagesClientHook clientHook @@ -52,6 +52,7 @@ func defaultPagesGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("dialogflow.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://dialogflow.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/dialogflow/cx/apiv3beta1/security_settings_client.go b/dialogflow/cx/apiv3beta1/security_settings_client.go index 53dd1439a45..36ab26c693e 100644 --- a/dialogflow/cx/apiv3beta1/security_settings_client.go +++ b/dialogflow/cx/apiv3beta1/security_settings_client.go @@ -23,7 +23,6 @@ import ( "net/url" "time" - "github.com/golang/protobuf/proto" gax "github.com/googleapis/gax-go/v2" "google.golang.org/api/iterator" "google.golang.org/api/option" @@ -33,6 +32,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newSecuritySettingsClientHook clientHook @@ -52,6 +52,7 @@ func defaultSecuritySettingsGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("dialogflow.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://dialogflow.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/dialogflow/cx/apiv3beta1/session_entity_types_client.go b/dialogflow/cx/apiv3beta1/session_entity_types_client.go index 35dff68574f..08799a17047 100644 --- a/dialogflow/cx/apiv3beta1/session_entity_types_client.go +++ b/dialogflow/cx/apiv3beta1/session_entity_types_client.go @@ -23,7 +23,6 @@ import ( "net/url" "time" - "github.com/golang/protobuf/proto" gax "github.com/googleapis/gax-go/v2" "google.golang.org/api/iterator" "google.golang.org/api/option" @@ -33,6 +32,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newSessionEntityTypesClientHook clientHook @@ -52,6 +52,7 @@ func defaultSessionEntityTypesGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("dialogflow.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://dialogflow.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/dialogflow/cx/apiv3beta1/sessions_client.go b/dialogflow/cx/apiv3beta1/sessions_client.go index 7206183b897..4fea31d5e43 100644 --- a/dialogflow/cx/apiv3beta1/sessions_client.go +++ b/dialogflow/cx/apiv3beta1/sessions_client.go @@ -49,6 +49,7 @@ func defaultSessionsGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("dialogflow.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://dialogflow.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/dialogflow/cx/apiv3beta1/test_cases_client.go b/dialogflow/cx/apiv3beta1/test_cases_client.go index 401ee2e80a3..5b8729fcd04 100644 --- a/dialogflow/cx/apiv3beta1/test_cases_client.go +++ b/dialogflow/cx/apiv3beta1/test_cases_client.go @@ -25,7 +25,6 @@ import ( "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" @@ -36,6 +35,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newTestCasesClientHook clientHook @@ -62,6 +62,7 @@ func defaultTestCasesGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("dialogflow.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://dialogflow.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/dialogflow/cx/apiv3beta1/transition_route_groups_client.go b/dialogflow/cx/apiv3beta1/transition_route_groups_client.go index ceaad6f3d00..46117280f8b 100644 --- a/dialogflow/cx/apiv3beta1/transition_route_groups_client.go +++ b/dialogflow/cx/apiv3beta1/transition_route_groups_client.go @@ -23,7 +23,6 @@ import ( "net/url" "time" - "github.com/golang/protobuf/proto" gax "github.com/googleapis/gax-go/v2" "google.golang.org/api/iterator" "google.golang.org/api/option" @@ -33,6 +32,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newTransitionRouteGroupsClientHook clientHook @@ -52,6 +52,7 @@ func defaultTransitionRouteGroupsGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("dialogflow.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://dialogflow.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), @@ -175,16 +176,28 @@ func (c *TransitionRouteGroupsClient) GetTransitionRouteGroup(ctx context.Contex } // CreateTransitionRouteGroup creates an TransitionRouteGroup in the specified flow. +// +// Note: You should always train a flow prior to sending it queries. See the +// training +// documentation (at https://cloud.google.com/dialogflow/cx/docs/concept/training). func (c *TransitionRouteGroupsClient) CreateTransitionRouteGroup(ctx context.Context, req *cxpb.CreateTransitionRouteGroupRequest, opts ...gax.CallOption) (*cxpb.TransitionRouteGroup, error) { return c.internalClient.CreateTransitionRouteGroup(ctx, req, opts...) } // UpdateTransitionRouteGroup updates the specified TransitionRouteGroup. +// +// Note: You should always train a flow prior to sending it queries. See the +// training +// documentation (at https://cloud.google.com/dialogflow/cx/docs/concept/training). func (c *TransitionRouteGroupsClient) UpdateTransitionRouteGroup(ctx context.Context, req *cxpb.UpdateTransitionRouteGroupRequest, opts ...gax.CallOption) (*cxpb.TransitionRouteGroup, error) { return c.internalClient.UpdateTransitionRouteGroup(ctx, req, opts...) } // DeleteTransitionRouteGroup deletes the specified TransitionRouteGroup. +// +// Note: You should always train a flow prior to sending it queries. See the +// training +// documentation (at https://cloud.google.com/dialogflow/cx/docs/concept/training). func (c *TransitionRouteGroupsClient) DeleteTransitionRouteGroup(ctx context.Context, req *cxpb.DeleteTransitionRouteGroupRequest, opts ...gax.CallOption) error { return c.internalClient.DeleteTransitionRouteGroup(ctx, req, opts...) } diff --git a/dialogflow/cx/apiv3beta1/versions_client.go b/dialogflow/cx/apiv3beta1/versions_client.go index a08e8faeada..0035da11c55 100644 --- a/dialogflow/cx/apiv3beta1/versions_client.go +++ b/dialogflow/cx/apiv3beta1/versions_client.go @@ -25,7 +25,6 @@ import ( "cloud.google.com/go/longrunning" lroauto "cloud.google.com/go/longrunning/autogen" - "github.com/golang/protobuf/proto" structpb "github.com/golang/protobuf/ptypes/struct" gax "github.com/googleapis/gax-go/v2" "google.golang.org/api/iterator" @@ -37,6 +36,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newVersionsClientHook clientHook @@ -57,6 +57,7 @@ func defaultVersionsGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("dialogflow.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://dialogflow.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/dialogflow/cx/apiv3beta1/webhooks_client.go b/dialogflow/cx/apiv3beta1/webhooks_client.go index c97635e74a5..56e62b18405 100644 --- a/dialogflow/cx/apiv3beta1/webhooks_client.go +++ b/dialogflow/cx/apiv3beta1/webhooks_client.go @@ -23,7 +23,6 @@ import ( "net/url" "time" - "github.com/golang/protobuf/proto" gax "github.com/googleapis/gax-go/v2" "google.golang.org/api/iterator" "google.golang.org/api/option" @@ -33,6 +32,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newWebhooksClientHook clientHook @@ -52,6 +52,7 @@ func defaultWebhooksGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("dialogflow.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://dialogflow.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/dlp/apiv2/dlp_client.go b/dlp/apiv2/dlp_client.go index 99546de6fe6..810a3565c0b 100644 --- a/dlp/apiv2/dlp_client.go +++ b/dlp/apiv2/dlp_client.go @@ -23,7 +23,6 @@ import ( "net/url" "time" - "github.com/golang/protobuf/proto" gax "github.com/googleapis/gax-go/v2" "google.golang.org/api/iterator" "google.golang.org/api/option" @@ -33,6 +32,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newClientHook clientHook @@ -81,6 +81,7 @@ func defaultGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("dlp.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://dlp.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/dlp/apiv2/doc.go b/dlp/apiv2/doc.go index d726b9713e8..78df191ef06 100644 --- a/dlp/apiv2/doc.go +++ b/dlp/apiv2/doc.go @@ -50,7 +50,7 @@ import ( type clientHookParams struct{} type clientHook func(context.Context, clientHookParams) ([]option.ClientOption, error) -const versionClient = "20210612" +const versionClient = "20210701" func insertMetadata(ctx context.Context, mds ...metadata.MD) context.Context { out, _ := metadata.FromOutgoingContext(ctx) diff --git a/documentai/apiv1/doc.go b/documentai/apiv1/doc.go index 177d3ae80c4..1eee9f2a7d3 100644 --- a/documentai/apiv1/doc.go +++ b/documentai/apiv1/doc.go @@ -21,8 +21,6 @@ // semi-structured documents using state-of-the-art Google AI such as natural // language, computer vision, translation, and AutoML. // -// 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 @@ -52,7 +50,7 @@ import ( type clientHookParams struct{} type clientHook func(context.Context, clientHookParams) ([]option.ClientOption, error) -const versionClient = "20210612" +const versionClient = "20210701" func insertMetadata(ctx context.Context, mds ...metadata.MD) context.Context { out, _ := metadata.FromOutgoingContext(ctx) diff --git a/documentai/apiv1/document_processor_client.go b/documentai/apiv1/document_processor_client.go index 775ce5195ca..8e87c607dac 100644 --- a/documentai/apiv1/document_processor_client.go +++ b/documentai/apiv1/document_processor_client.go @@ -51,6 +51,7 @@ func defaultDocumentProcessorGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("documentai.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://documentai.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/documentai/apiv1beta3/doc.go b/documentai/apiv1beta3/doc.go index dbe6588c055..6db4adc466c 100644 --- a/documentai/apiv1beta3/doc.go +++ b/documentai/apiv1beta3/doc.go @@ -52,7 +52,7 @@ import ( type clientHookParams struct{} type clientHook func(context.Context, clientHookParams) ([]option.ClientOption, error) -const versionClient = "20210617" +const versionClient = "20210701" func insertMetadata(ctx context.Context, mds ...metadata.MD) context.Context { out, _ := metadata.FromOutgoingContext(ctx) diff --git a/documentai/apiv1beta3/document_processor_client.go b/documentai/apiv1beta3/document_processor_client.go index 7448033b082..1a006861380 100644 --- a/documentai/apiv1beta3/document_processor_client.go +++ b/documentai/apiv1beta3/document_processor_client.go @@ -25,7 +25,6 @@ import ( "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" @@ -36,6 +35,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newDocumentProcessorClientHook clientHook @@ -59,6 +59,7 @@ func defaultDocumentProcessorGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("documentai.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://documentai.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/domains/apiv1beta1/doc.go b/domains/apiv1beta1/doc.go index f3bdc2a7d13..52c7b825a9e 100644 --- a/domains/apiv1beta1/doc.go +++ b/domains/apiv1beta1/doc.go @@ -50,7 +50,7 @@ import ( type clientHookParams struct{} type clientHook func(context.Context, clientHookParams) ([]option.ClientOption, error) -const versionClient = "20210612" +const versionClient = "20210701" func insertMetadata(ctx context.Context, mds ...metadata.MD) context.Context { out, _ := metadata.FromOutgoingContext(ctx) diff --git a/domains/apiv1beta1/domains_client.go b/domains/apiv1beta1/domains_client.go index 2de29930c59..a298686dc7f 100644 --- a/domains/apiv1beta1/domains_client.go +++ b/domains/apiv1beta1/domains_client.go @@ -25,7 +25,6 @@ import ( "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" @@ -35,6 +34,7 @@ import ( longrunningpb "google.golang.org/genproto/googleapis/longrunning" "google.golang.org/grpc" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newClientHook clientHook @@ -62,6 +62,7 @@ func defaultGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("domains.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://domains.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/errorreporting/apiv1beta1/doc.go b/errorreporting/apiv1beta1/doc.go index aac2058ccaf..732bdb35079 100644 --- a/errorreporting/apiv1beta1/doc.go +++ b/errorreporting/apiv1beta1/doc.go @@ -52,7 +52,7 @@ import ( type clientHookParams struct{} type clientHook func(context.Context, clientHookParams) ([]option.ClientOption, error) -const versionClient = "20210612" +const versionClient = "20210701" func insertMetadata(ctx context.Context, mds ...metadata.MD) context.Context { out, _ := metadata.FromOutgoingContext(ctx) diff --git a/errorreporting/apiv1beta1/error_group_client.go b/errorreporting/apiv1beta1/error_group_client.go index 12409a232b5..9440d1f0cc0 100644 --- a/errorreporting/apiv1beta1/error_group_client.go +++ b/errorreporting/apiv1beta1/error_group_client.go @@ -47,6 +47,7 @@ func defaultErrorGroupGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("clouderrorreporting.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://clouderrorreporting.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/errorreporting/apiv1beta1/error_stats_client.go b/errorreporting/apiv1beta1/error_stats_client.go index 8e15939ceb9..e12bc96f20c 100644 --- a/errorreporting/apiv1beta1/error_stats_client.go +++ b/errorreporting/apiv1beta1/error_stats_client.go @@ -23,7 +23,6 @@ import ( "net/url" "time" - "github.com/golang/protobuf/proto" gax "github.com/googleapis/gax-go/v2" "google.golang.org/api/iterator" "google.golang.org/api/option" @@ -33,6 +32,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newErrorStatsClientHook clientHook @@ -50,6 +50,7 @@ func defaultErrorStatsGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("clouderrorreporting.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://clouderrorreporting.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/errorreporting/apiv1beta1/report_errors_client.go b/errorreporting/apiv1beta1/report_errors_client.go index 3c91faa4296..796e5675d86 100644 --- a/errorreporting/apiv1beta1/report_errors_client.go +++ b/errorreporting/apiv1beta1/report_errors_client.go @@ -45,6 +45,7 @@ func defaultReportErrorsGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("clouderrorreporting.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://clouderrorreporting.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/essentialcontacts/apiv1/doc.go b/essentialcontacts/apiv1/doc.go index 1bdb1641e65..824133d10c3 100644 --- a/essentialcontacts/apiv1/doc.go +++ b/essentialcontacts/apiv1/doc.go @@ -17,8 +17,6 @@ // Package essentialcontacts is an auto-generated package for the // Essential Contacts API. // -// 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 @@ -48,7 +46,7 @@ import ( type clientHookParams struct{} type clientHook func(context.Context, clientHookParams) ([]option.ClientOption, error) -const versionClient = "20210612" +const versionClient = "20210701" func insertMetadata(ctx context.Context, mds ...metadata.MD) context.Context { out, _ := metadata.FromOutgoingContext(ctx) diff --git a/essentialcontacts/apiv1/essential_contacts_client.go b/essentialcontacts/apiv1/essential_contacts_client.go index 892e1502341..7485c6c69b2 100644 --- a/essentialcontacts/apiv1/essential_contacts_client.go +++ b/essentialcontacts/apiv1/essential_contacts_client.go @@ -23,7 +23,6 @@ import ( "net/url" "time" - "github.com/golang/protobuf/proto" gax "github.com/googleapis/gax-go/v2" "google.golang.org/api/iterator" "google.golang.org/api/option" @@ -33,6 +32,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newClientHook clientHook @@ -54,6 +54,7 @@ func defaultGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("essentialcontacts.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://essentialcontacts.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/eventarc/apiv1/doc.go b/eventarc/apiv1/doc.go new file mode 100644 index 00000000000..2100ac370f4 --- /dev/null +++ b/eventarc/apiv1/doc.go @@ -0,0 +1,116 @@ +// 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 eventarc is an auto-generated package for the +// Eventarc API. +// +// 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 eventarc // import "cloud.google.com/go/eventarc/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 = "20210701" + +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/eventarc/apiv1/eventarc_client.go b/eventarc/apiv1/eventarc_client.go new file mode 100644 index 00000000000..e5b3824500d --- /dev/null +++ b/eventarc/apiv1/eventarc_client.go @@ -0,0 +1,631 @@ +// 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 eventarc + +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" + eventarcpb "google.golang.org/genproto/googleapis/cloud/eventarc/v1" + longrunningpb "google.golang.org/genproto/googleapis/longrunning" + "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 { + GetTrigger []gax.CallOption + ListTriggers []gax.CallOption + CreateTrigger []gax.CallOption + UpdateTrigger []gax.CallOption + DeleteTrigger []gax.CallOption +} + +func defaultGRPCClientOptions() []option.ClientOption { + return []option.ClientOption{ + internaloption.WithDefaultEndpoint("eventarc.googleapis.com:443"), + internaloption.WithDefaultMTLSEndpoint("eventarc.mtls.googleapis.com:443"), + internaloption.WithDefaultAudience("https://eventarc.googleapis.com/"), + internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), + option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), + option.WithGRPCDialOption(grpc.WithDefaultCallOptions( + grpc.MaxCallRecvMsgSize(math.MaxInt32))), + } +} + +func defaultCallOptions() *CallOptions { + return &CallOptions{ + GetTrigger: []gax.CallOption{}, + ListTriggers: []gax.CallOption{}, + CreateTrigger: []gax.CallOption{}, + UpdateTrigger: []gax.CallOption{}, + DeleteTrigger: []gax.CallOption{}, + } +} + +// internalClient is an interface that defines the methods availaible from Eventarc API. +type internalClient interface { + Close() error + setGoogleClientInfo(...string) + Connection() *grpc.ClientConn + GetTrigger(context.Context, *eventarcpb.GetTriggerRequest, ...gax.CallOption) (*eventarcpb.Trigger, error) + ListTriggers(context.Context, *eventarcpb.ListTriggersRequest, ...gax.CallOption) *TriggerIterator + CreateTrigger(context.Context, *eventarcpb.CreateTriggerRequest, ...gax.CallOption) (*CreateTriggerOperation, error) + CreateTriggerOperation(name string) *CreateTriggerOperation + UpdateTrigger(context.Context, *eventarcpb.UpdateTriggerRequest, ...gax.CallOption) (*UpdateTriggerOperation, error) + UpdateTriggerOperation(name string) *UpdateTriggerOperation + DeleteTrigger(context.Context, *eventarcpb.DeleteTriggerRequest, ...gax.CallOption) (*DeleteTriggerOperation, error) + DeleteTriggerOperation(name string) *DeleteTriggerOperation +} + +// Client is a client for interacting with Eventarc API. +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +// +// Eventarc allows users to subscribe to various events that are provided by +// Google Cloud services and forward them to supported destinations. +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() +} + +// GetTrigger get a single trigger. +func (c *Client) GetTrigger(ctx context.Context, req *eventarcpb.GetTriggerRequest, opts ...gax.CallOption) (*eventarcpb.Trigger, error) { + return c.internalClient.GetTrigger(ctx, req, opts...) +} + +// ListTriggers list triggers. +func (c *Client) ListTriggers(ctx context.Context, req *eventarcpb.ListTriggersRequest, opts ...gax.CallOption) *TriggerIterator { + return c.internalClient.ListTriggers(ctx, req, opts...) +} + +// CreateTrigger create a new trigger in a particular project and location. +func (c *Client) CreateTrigger(ctx context.Context, req *eventarcpb.CreateTriggerRequest, opts ...gax.CallOption) (*CreateTriggerOperation, error) { + return c.internalClient.CreateTrigger(ctx, req, opts...) +} + +// CreateTriggerOperation returns a new CreateTriggerOperation from a given name. +// The name must be that of a previously created CreateTriggerOperation, possibly from a different process. +func (c *Client) CreateTriggerOperation(name string) *CreateTriggerOperation { + return c.internalClient.CreateTriggerOperation(name) +} + +// UpdateTrigger update a single trigger. +func (c *Client) UpdateTrigger(ctx context.Context, req *eventarcpb.UpdateTriggerRequest, opts ...gax.CallOption) (*UpdateTriggerOperation, error) { + return c.internalClient.UpdateTrigger(ctx, req, opts...) +} + +// UpdateTriggerOperation returns a new UpdateTriggerOperation from a given name. +// The name must be that of a previously created UpdateTriggerOperation, possibly from a different process. +func (c *Client) UpdateTriggerOperation(name string) *UpdateTriggerOperation { + return c.internalClient.UpdateTriggerOperation(name) +} + +// DeleteTrigger delete a single trigger. +func (c *Client) DeleteTrigger(ctx context.Context, req *eventarcpb.DeleteTriggerRequest, opts ...gax.CallOption) (*DeleteTriggerOperation, error) { + return c.internalClient.DeleteTrigger(ctx, req, opts...) +} + +// DeleteTriggerOperation returns a new DeleteTriggerOperation from a given name. +// The name must be that of a previously created DeleteTriggerOperation, possibly from a different process. +func (c *Client) DeleteTriggerOperation(name string) *DeleteTriggerOperation { + return c.internalClient.DeleteTriggerOperation(name) +} + +// gRPCClient is a client for interacting with Eventarc 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 eventarcpb.EventarcClient + + // 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 eventarc client based on gRPC. +// The returned client must be Closed when it is done being used to clean up its underlying connections. +// +// Eventarc allows users to subscribe to various events that are provided by +// Google Cloud services and forward them to supported destinations. +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: eventarcpb.NewEventarcClient(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) GetTrigger(ctx context.Context, req *eventarcpb.GetTriggerRequest, opts ...gax.CallOption) (*eventarcpb.Trigger, error) { + 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).GetTrigger[0:len((*c.CallOptions).GetTrigger):len((*c.CallOptions).GetTrigger)], opts...) + var resp *eventarcpb.Trigger + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.client.GetTrigger(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} + +func (c *gRPCClient) ListTriggers(ctx context.Context, req *eventarcpb.ListTriggersRequest, opts ...gax.CallOption) *TriggerIterator { + 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).ListTriggers[0:len((*c.CallOptions).ListTriggers):len((*c.CallOptions).ListTriggers)], opts...) + it := &TriggerIterator{} + req = proto.Clone(req).(*eventarcpb.ListTriggersRequest) + it.InternalFetch = func(pageSize int, pageToken string) ([]*eventarcpb.Trigger, string, error) { + var resp *eventarcpb.ListTriggersResponse + 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.ListTriggers(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, "", err + } + + it.Response = resp + return resp.GetTriggers(), 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) CreateTrigger(ctx context.Context, req *eventarcpb.CreateTriggerRequest, opts ...gax.CallOption) (*CreateTriggerOperation, error) { + 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).CreateTrigger[0:len((*c.CallOptions).CreateTrigger):len((*c.CallOptions).CreateTrigger)], opts...) + var resp *longrunningpb.Operation + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.client.CreateTrigger(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return &CreateTriggerOperation{ + lro: longrunning.InternalNewOperation(*c.LROClient, resp), + }, nil +} + +func (c *gRPCClient) UpdateTrigger(ctx context.Context, req *eventarcpb.UpdateTriggerRequest, opts ...gax.CallOption) (*UpdateTriggerOperation, error) { + md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "trigger.name", url.QueryEscape(req.GetTrigger().GetName()))) + ctx = insertMetadata(ctx, c.xGoogMetadata, md) + opts = append((*c.CallOptions).UpdateTrigger[0:len((*c.CallOptions).UpdateTrigger):len((*c.CallOptions).UpdateTrigger)], opts...) + var resp *longrunningpb.Operation + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.client.UpdateTrigger(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return &UpdateTriggerOperation{ + lro: longrunning.InternalNewOperation(*c.LROClient, resp), + }, nil +} + +func (c *gRPCClient) DeleteTrigger(ctx context.Context, req *eventarcpb.DeleteTriggerRequest, opts ...gax.CallOption) (*DeleteTriggerOperation, error) { + 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).DeleteTrigger[0:len((*c.CallOptions).DeleteTrigger):len((*c.CallOptions).DeleteTrigger)], opts...) + var resp *longrunningpb.Operation + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.client.DeleteTrigger(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return &DeleteTriggerOperation{ + lro: longrunning.InternalNewOperation(*c.LROClient, resp), + }, nil +} + +// CreateTriggerOperation manages a long-running operation from CreateTrigger. +type CreateTriggerOperation struct { + lro *longrunning.Operation +} + +// CreateTriggerOperation returns a new CreateTriggerOperation from a given name. +// The name must be that of a previously created CreateTriggerOperation, possibly from a different process. +func (c *gRPCClient) CreateTriggerOperation(name string) *CreateTriggerOperation { + return &CreateTriggerOperation{ + 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 *CreateTriggerOperation) Wait(ctx context.Context, opts ...gax.CallOption) (*eventarcpb.Trigger, error) { + var resp eventarcpb.Trigger + 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 *CreateTriggerOperation) Poll(ctx context.Context, opts ...gax.CallOption) (*eventarcpb.Trigger, error) { + var resp eventarcpb.Trigger + 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 *CreateTriggerOperation) Metadata() (*eventarcpb.OperationMetadata, error) { + var meta eventarcpb.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 *CreateTriggerOperation) 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 *CreateTriggerOperation) Name() string { + return op.lro.Name() +} + +// DeleteTriggerOperation manages a long-running operation from DeleteTrigger. +type DeleteTriggerOperation struct { + lro *longrunning.Operation +} + +// DeleteTriggerOperation returns a new DeleteTriggerOperation from a given name. +// The name must be that of a previously created DeleteTriggerOperation, possibly from a different process. +func (c *gRPCClient) DeleteTriggerOperation(name string) *DeleteTriggerOperation { + return &DeleteTriggerOperation{ + 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 *DeleteTriggerOperation) Wait(ctx context.Context, opts ...gax.CallOption) (*eventarcpb.Trigger, error) { + var resp eventarcpb.Trigger + 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 *DeleteTriggerOperation) Poll(ctx context.Context, opts ...gax.CallOption) (*eventarcpb.Trigger, error) { + var resp eventarcpb.Trigger + 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 *DeleteTriggerOperation) Metadata() (*eventarcpb.OperationMetadata, error) { + var meta eventarcpb.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 *DeleteTriggerOperation) 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 *DeleteTriggerOperation) Name() string { + return op.lro.Name() +} + +// UpdateTriggerOperation manages a long-running operation from UpdateTrigger. +type UpdateTriggerOperation struct { + lro *longrunning.Operation +} + +// UpdateTriggerOperation returns a new UpdateTriggerOperation from a given name. +// The name must be that of a previously created UpdateTriggerOperation, possibly from a different process. +func (c *gRPCClient) UpdateTriggerOperation(name string) *UpdateTriggerOperation { + return &UpdateTriggerOperation{ + 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 *UpdateTriggerOperation) Wait(ctx context.Context, opts ...gax.CallOption) (*eventarcpb.Trigger, error) { + var resp eventarcpb.Trigger + 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 *UpdateTriggerOperation) Poll(ctx context.Context, opts ...gax.CallOption) (*eventarcpb.Trigger, error) { + var resp eventarcpb.Trigger + 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 *UpdateTriggerOperation) Metadata() (*eventarcpb.OperationMetadata, error) { + var meta eventarcpb.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 *UpdateTriggerOperation) 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 *UpdateTriggerOperation) Name() string { + return op.lro.Name() +} + +// TriggerIterator manages a stream of *eventarcpb.Trigger. +type TriggerIterator struct { + items []*eventarcpb.Trigger + 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 []*eventarcpb.Trigger, nextPageToken string, err error) +} + +// PageInfo supports pagination. See the google.golang.org/api/iterator package for details. +func (it *TriggerIterator) 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 *TriggerIterator) Next() (*eventarcpb.Trigger, error) { + var item *eventarcpb.Trigger + if err := it.nextFunc(); err != nil { + return item, err + } + item = it.items[0] + it.items = it.items[1:] + return item, nil +} + +func (it *TriggerIterator) bufLen() int { + return len(it.items) +} + +func (it *TriggerIterator) takeBuf() interface{} { + b := it.items + it.items = nil + return b +} diff --git a/eventarc/apiv1/eventarc_client_example_test.go b/eventarc/apiv1/eventarc_client_example_test.go new file mode 100644 index 00000000000..3829788aee3 --- /dev/null +++ b/eventarc/apiv1/eventarc_client_example_test.go @@ -0,0 +1,153 @@ +// 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 eventarc_test + +import ( + "context" + + eventarc "cloud.google.com/go/eventarc/apiv1" + "google.golang.org/api/iterator" + eventarcpb "google.golang.org/genproto/googleapis/cloud/eventarc/v1" +) + +func ExampleNewClient() { + ctx := context.Background() + c, err := eventarc.NewClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + // TODO: Use client. + _ = c +} + +func ExampleClient_GetTrigger() { + ctx := context.Background() + c, err := eventarc.NewClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &eventarcpb.GetTriggerRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.GetTrigger(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleClient_ListTriggers() { + ctx := context.Background() + c, err := eventarc.NewClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &eventarcpb.ListTriggersRequest{ + // TODO: Fill request struct fields. + } + it := c.ListTriggers(ctx, req) + for { + resp, err := it.Next() + if err == iterator.Done { + break + } + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp + } +} + +func ExampleClient_CreateTrigger() { + ctx := context.Background() + c, err := eventarc.NewClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &eventarcpb.CreateTriggerRequest{ + // TODO: Fill request struct fields. + } + op, err := c.CreateTrigger(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_UpdateTrigger() { + ctx := context.Background() + c, err := eventarc.NewClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &eventarcpb.UpdateTriggerRequest{ + // TODO: Fill request struct fields. + } + op, err := c.UpdateTrigger(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_DeleteTrigger() { + ctx := context.Background() + c, err := eventarc.NewClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &eventarcpb.DeleteTriggerRequest{ + // TODO: Fill request struct fields. + } + op, err := c.DeleteTrigger(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/eventarc/apiv1/gapic_metadata.json b/eventarc/apiv1/gapic_metadata.json new file mode 100644 index 00000000000..a71dacd0a3c --- /dev/null +++ b/eventarc/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.eventarc.v1", + "libraryPackage": "cloud.google.com/go/eventarc/apiv1", + "services": { + "Eventarc": { + "clients": { + "grpc": { + "libraryClient": "Client", + "rpcs": { + "CreateTrigger": { + "methods": [ + "CreateTrigger" + ] + }, + "DeleteTrigger": { + "methods": [ + "DeleteTrigger" + ] + }, + "GetTrigger": { + "methods": [ + "GetTrigger" + ] + }, + "ListTriggers": { + "methods": [ + "ListTriggers" + ] + }, + "UpdateTrigger": { + "methods": [ + "UpdateTrigger" + ] + } + } + } + } + } + } +} diff --git a/firestore/apiv1/admin/doc.go b/firestore/apiv1/admin/doc.go index 96ac39dce44..78ecef1f7cc 100644 --- a/firestore/apiv1/admin/doc.go +++ b/firestore/apiv1/admin/doc.go @@ -49,7 +49,7 @@ import ( type clientHookParams struct{} type clientHook func(context.Context, clientHookParams) ([]option.ClientOption, error) -const versionClient = "20210612" +const versionClient = "20210701" func insertMetadata(ctx context.Context, mds ...metadata.MD) context.Context { out, _ := metadata.FromOutgoingContext(ctx) diff --git a/firestore/apiv1/admin/firestore_admin_client.go b/firestore/apiv1/admin/firestore_admin_client.go index 2c561682d62..5dcbbdd2152 100644 --- a/firestore/apiv1/admin/firestore_admin_client.go +++ b/firestore/apiv1/admin/firestore_admin_client.go @@ -25,7 +25,6 @@ import ( "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" @@ -36,6 +35,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newFirestoreAdminClientHook clientHook @@ -59,6 +59,7 @@ func defaultFirestoreAdminGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("firestore.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://firestore.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/firestore/apiv1/doc.go b/firestore/apiv1/doc.go index 347af8c6aac..c1e56d75b51 100644 --- a/firestore/apiv1/doc.go +++ b/firestore/apiv1/doc.go @@ -49,7 +49,7 @@ import ( type clientHookParams struct{} type clientHook func(context.Context, clientHookParams) ([]option.ClientOption, error) -const versionClient = "20210612" +const versionClient = "20210701" func insertMetadata(ctx context.Context, mds ...metadata.MD) context.Context { out, _ := metadata.FromOutgoingContext(ctx) diff --git a/firestore/apiv1/firestore_client.go b/firestore/apiv1/firestore_client.go index 6d30017d08e..deec0b20090 100644 --- a/firestore/apiv1/firestore_client.go +++ b/firestore/apiv1/firestore_client.go @@ -23,7 +23,6 @@ import ( "net/url" "time" - "github.com/golang/protobuf/proto" gax "github.com/googleapis/gax-go/v2" "google.golang.org/api/iterator" "google.golang.org/api/option" @@ -33,6 +32,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newClientHook clientHook @@ -62,6 +62,7 @@ func defaultGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("firestore.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://firestore.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/firestore/apiv1beta1/doc.go b/firestore/apiv1beta1/doc.go index d5d7a2c2c9c..75dcfa86000 100644 --- a/firestore/apiv1beta1/doc.go +++ b/firestore/apiv1beta1/doc.go @@ -46,7 +46,7 @@ import ( "google.golang.org/grpc/metadata" ) -const versionClient = "20210612" +const versionClient = "20210624" func insertMetadata(ctx context.Context, mds ...metadata.MD) context.Context { out, _ := metadata.FromOutgoingContext(ctx) diff --git a/firestore/client.go b/firestore/client.go index 8ee1071d283..1b4c4618672 100644 --- a/firestore/client.go +++ b/firestore/client.go @@ -60,6 +60,9 @@ type Client struct { // NewClient creates a new Firestore client that uses the given project. func NewClient(ctx context.Context, projectID string, opts ...option.ClientOption) (*Client, error) { + if projectID == "" { + return nil, errors.New("firestore: projectID was empty") + } var o []option.ClientOption // If this environment variable is defined, configure the client to talk to the emulator. if addr := os.Getenv("FIRESTORE_EMULATOR_HOST"); addr != "" { diff --git a/firestore/collgroupref.go b/firestore/collgroupref.go index e43a7e648c5..90986ad71f6 100644 --- a/firestore/collgroupref.go +++ b/firestore/collgroupref.go @@ -14,6 +14,16 @@ package firestore +import ( + "context" + "errors" + "fmt" + "sort" + + "google.golang.org/api/iterator" + firestorepb "google.golang.org/genproto/googleapis/firestore/v1" +) + // A CollectionGroupRef is a reference to a group of collections sharing the // same ID. type CollectionGroupRef struct { @@ -36,3 +46,141 @@ func newCollectionGroupRef(c *Client, dbPath, collectionID string) *CollectionGr }, } } + +// GetPartitionedQueries returns a slice of Query objects, each containing a +// partition of a collection group. partitionCount must be a positive value and +// the number of returned partitions may be less than the requested number if +// providing the desired number would result in partitions with very few documents. +// +// If a Collection Group Query would return a large number of documents, this +// can help to subdivide the query to smaller working units that can be distributed. +func (cgr CollectionGroupRef) GetPartitionedQueries(ctx context.Context, partitionCount int) ([]Query, error) { + qp, err := cgr.getPartitions(ctx, partitionCount) + if err != nil { + return nil, err + } + queries := make([]Query, len(qp)) + for i, part := range qp { + queries[i] = part.toQuery() + } + return queries, nil +} + +// getPartitions returns a slice of queryPartition objects, describing a start +// and end range to query a subsection of the collection group. partitionCount +// must be a positive value and the number of returned partitions may be less +// than the requested number if providing the desired number would result in +// partitions with very few documents. +func (cgr CollectionGroupRef) getPartitions(ctx context.Context, partitionCount int) ([]queryPartition, error) { + orderedQuery := cgr.query().OrderBy(DocumentID, Asc) + + if partitionCount <= 0 { + return nil, errors.New("a positive partitionCount must be provided") + } else if partitionCount == 1 { + return []queryPartition{{CollectionGroupQuery: orderedQuery}}, nil + } + + db := cgr.c.path() + ctx = withResourceHeader(ctx, db) + + // CollectionGroup Queries need to be ordered by __name__ ASC. + query, err := orderedQuery.toProto() + if err != nil { + return nil, err + } + structuredQuery := &firestorepb.PartitionQueryRequest_StructuredQuery{ + StructuredQuery: query, + } + + // Uses default PageSize + pbr := &firestorepb.PartitionQueryRequest{ + Parent: db + "/documents", + PartitionCount: int64(partitionCount), + QueryType: structuredQuery, + } + cursorReferences := make([]*firestorepb.Value, 0, partitionCount) + iter := cgr.c.c.PartitionQuery(ctx, pbr) + for { + cursor, err := iter.Next() + if err == iterator.Done { + break + } + if err != nil { + return nil, fmt.Errorf("GetPartitions: %v", err) + } + cursorReferences = append(cursorReferences, cursor.GetValues()...) + } + + // From Proto documentation: + // To obtain a complete result set ordered with respect to the results of the + // query supplied to PartitionQuery, the results sets should be merged: + // cursor A, cursor B, cursor M, cursor Q, cursor U, cursor W + // Once we have exhausted the pages, the cursor values need to be sorted in + // lexicographical order by segment (areas between '/'). + sort.Sort(byFirestoreValue(cursorReferences)) + + queryPartitions := make([]queryPartition, 0, len(cursorReferences)) + previousCursor := "" + + for _, cursor := range cursorReferences { + cursorRef := cursor.GetReferenceValue() + + // remove the root path from the reference, as queries take cursors + // relative to a collection + cursorRef = cursorRef[len(orderedQuery.path)+1:] + + qp := queryPartition{ + CollectionGroupQuery: orderedQuery, + StartAt: previousCursor, + EndBefore: cursorRef, + } + queryPartitions = append(queryPartitions, qp) + previousCursor = cursorRef + } + + // In the case there were no partitions, we still add a single partition to + // the result, that covers the complete range. + lastPart := queryPartition{CollectionGroupQuery: orderedQuery} + if len(cursorReferences) > 0 { + cursorRef := cursorReferences[len(cursorReferences)-1].GetReferenceValue() + lastPart.StartAt = cursorRef[len(orderedQuery.path)+1:] + } + queryPartitions = append(queryPartitions, lastPart) + + return queryPartitions, nil +} + +// queryPartition provides a Collection Group Reference and start and end split +// points allowing for a section of a collection group to be queried. This is +// used by GetPartitions which, given a CollectionGroupReference returns smaller +// sub-queries or partitions +type queryPartition struct { + // CollectionGroupQuery is an ordered query on a CollectionGroupReference. + // This query must be ordered Asc on __name__. + // Example: client.CollectionGroup("collectionID").query().OrderBy(DocumentID, Asc) + CollectionGroupQuery Query + + // StartAt is a document reference value, relative to the collection, not + // a complete parent path. + // Example: "documents/collectionName/documentName" + StartAt string + + // EndBefore is a document reference value, relative to the collection, not + // a complete parent path. + // Example: "documents/collectionName/documentName" + EndBefore string +} + +// toQuery converts a queryPartition object to a Query object +func (qp queryPartition) toQuery() Query { + q := *qp.CollectionGroupQuery.query() + + // Remove the leading path before calling StartAt, EndBefore + if qp.StartAt != "" { + q = q.StartAt(qp.StartAt) + } + if qp.EndBefore != "" { + q = q.EndBefore(qp.EndBefore) + } + return q +} diff --git a/firestore/collgroupref_test.go b/firestore/collgroupref_test.go new file mode 100644 index 00000000000..bbcbfe4ebb6 --- /dev/null +++ b/firestore/collgroupref_test.go @@ -0,0 +1,73 @@ +// 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 +// +// http://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. + +package firestore + +import ( + "context" + "testing" +) + +func TestCGR_TestQueryPartition_ToQuery(t *testing.T) { + cgr := newCollectionGroupRef(testClient, testClient.path(), "collectionID") + qp := queryPartition{ + CollectionGroupQuery: cgr.Query.OrderBy(DocumentID, Asc), + StartAt: "documents/start/at", + EndBefore: "documents/end/before", + } + + got := qp.toQuery() + + want := Query{ + c: testClient, + path: "projects/projectID/databases/(default)", + parentPath: "projects/projectID/databases/(default)/documents", + collectionID: "collectionID", + startVals: []interface{}{"documents/start/at"}, + endVals: []interface{}{"documents/end/before"}, + startBefore: true, + endBefore: true, + allDescendants: true, + orders: []order{{fieldPath: []string{"__name__"}, dir: 1}}, + } + + if !testEqual(got, want) { + t.Errorf("got %+v, want %+v", got, want) + } +} + +func TestCGR_TestGetPartitions(t *testing.T) { + cgr := newCollectionGroupRef(testClient, testClient.path(), "collectionID") + _, err := cgr.getPartitions(context.Background(), 0) + if err == nil { + t.Error("Expected an error when requested partition count is < 1") + } + + parts, err := cgr.getPartitions(context.Background(), 1) + if err != nil { + t.Error("Didn't expect an error when requested partition count is 1") + } + if len(parts) != 1 { + t.Fatal("Expected 1 queryPartition") + } + got := parts[0] + want := queryPartition{ + CollectionGroupQuery: cgr.Query.OrderBy(DocumentID, Asc), + StartAt: "", + EndBefore: "", + } + if !testEqual(got, want) { + t.Errorf("got %+v, want %+v", got, want) + } +} diff --git a/firestore/go.mod b/firestore/go.mod index 2d462040952..42888a32e23 100644 --- a/firestore/go.mod +++ b/firestore/go.mod @@ -7,7 +7,8 @@ require ( github.com/golang/protobuf v1.5.2 github.com/google/go-cmp v0.5.6 github.com/googleapis/gax-go/v2 v2.0.5 - google.golang.org/api v0.48.0 - google.golang.org/genproto v0.0.0-20210614143202-012ab6975634 + google.golang.org/api v0.50.0 + google.golang.org/genproto v0.0.0-20210701133433-6b8dcf568a95 google.golang.org/grpc v1.38.0 + google.golang.org/protobuf v1.27.1 ) diff --git a/firestore/go.sum b/firestore/go.sum index 51829ee2af9..aa8fd5de0a2 100644 --- a/firestore/go.sum +++ b/firestore/go.sum @@ -248,8 +248,9 @@ golang.org/x/oauth2 v0.0.0-20201208152858-08078c50e5b5/go.mod h1:KelEdhl1UZF7XfJ golang.org/x/oauth2 v0.0.0-20210218202405-ba52d332ba99/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= golang.org/x/oauth2 v0.0.0-20210220000619-9bb904979d93/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= golang.org/x/oauth2 v0.0.0-20210313182246-cd4f82c27b84/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= -golang.org/x/oauth2 v0.0.0-20210514164344-f6687ab2804c h1:pkQiBZBvdos9qq4wBAHqlzuZHEXo07pqV06ef90u1WI= golang.org/x/oauth2 v0.0.0-20210514164344-f6687ab2804c/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= +golang.org/x/oauth2 v0.0.0-20210628180205-a41e5a781914 h1:3B43BWw0xEBsLZ/NO1VALz6fppU3481pik+2Ksv45z8= +golang.org/x/oauth2 v0.0.0-20210628180205-a41e5a781914/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= @@ -300,8 +301,9 @@ golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210514084401-e8d321eab015/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20210603125802-9665404d3644 h1:CA1DEQ4NdKphKeL70tvsWNdT5oFh1lOjihRcEDROi0I= golang.org/x/sys v0.0.0-20210603125802-9665404d3644/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20210616094352-59db8d763f22 h1:RqytpXGR1iVNX7psjB3ff8y7sNFinVFvkx1c8SjBkio= +golang.org/x/sys v0.0.0-20210616094352-59db8d763f22/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= @@ -363,8 +365,9 @@ golang.org/x/tools v0.0.0-20210105154028-b0ab187a4818/go.mod h1:emZCQorbCU4vsT4f golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0= golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.2/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= -golang.org/x/tools v0.1.3 h1:L69ShwSZEyCsLKoAxDKeMvLDZkumEe8gXUZAjab0tX8= golang.org/x/tools v0.1.3/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= +golang.org/x/tools v0.1.4 h1:cVngSRcfgyZCzys3KYOpCFa+4dqX/Oub9tAq00ttGVs= +golang.org/x/tools v0.1.4/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= @@ -392,8 +395,9 @@ google.golang.org/api v0.40.0/go.mod h1:fYKFpnQN0DsDSKRVRcQSDQNtqWPfM9i+zNPxepjR google.golang.org/api v0.41.0/go.mod h1:RkxM5lITDfTzmyKFPt+wGrCJbVfniCr2ool8kTBzRTU= google.golang.org/api v0.43.0/go.mod h1:nQsDGjRXMo4lvh5hP0TKqF244gqhGcr/YSIykhUk/94= google.golang.org/api v0.47.0/go.mod h1:Wbvgpq1HddcWVtzsVLyfLp8lDg6AA241LmgIL59tHXo= -google.golang.org/api v0.48.0 h1:RDAPWfNFY06dffEXfn7hZF5Fr1ZbnChzfQZAPyBd1+I= google.golang.org/api v0.48.0/go.mod h1:71Pr1vy+TAZRPkPs/xlCf5SsU8WjuAWv1Pfjbtukyy4= +google.golang.org/api v0.50.0 h1:LX7NFCFYOHzr7WHaYiRUpeipZe9o5L8T+2F4Z798VDw= +google.golang.org/api v0.50.0/go.mod h1:4bNT5pAuq5ji4SRZm+5QIkjny9JAyVD/3gaSihNefaw= google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= google.golang.org/appengine v1.5.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= @@ -445,8 +449,9 @@ google.golang.org/genproto v0.0.0-20210513213006-bf773b8c8384/go.mod h1:P3QM42oQ google.golang.org/genproto v0.0.0-20210602131652-f16073e35f0c/go.mod h1:UODoCrxHCcBojKKwX1terBiRUaqAsFqJiF615XL43r0= google.golang.org/genproto v0.0.0-20210604141403-392c879c8b08/go.mod h1:UODoCrxHCcBojKKwX1terBiRUaqAsFqJiF615XL43r0= google.golang.org/genproto v0.0.0-20210608205507-b6d2f5bf0d7d/go.mod h1:UODoCrxHCcBojKKwX1terBiRUaqAsFqJiF615XL43r0= -google.golang.org/genproto v0.0.0-20210614143202-012ab6975634 h1:LnkHrvncK4mYysgs+R1wPeMAILrmunf0Tzl0Li71pxo= -google.golang.org/genproto v0.0.0-20210614143202-012ab6975634/go.mod h1:SzzZ/N+nwJDaO1kznhnlzqS8ocJICar6hYhVyhi++24= +google.golang.org/genproto v0.0.0-20210624195500-8bfb893ecb84/go.mod h1:SzzZ/N+nwJDaO1kznhnlzqS8ocJICar6hYhVyhi++24= +google.golang.org/genproto v0.0.0-20210701133433-6b8dcf568a95 h1:xyRjacsGcaSoZ2fTcaLCSzh2JEceLLOT4X8k32Q0xAQ= +google.golang.org/genproto v0.0.0-20210701133433-6b8dcf568a95/go.mod h1:yiaVoXHpRzHGyxV3o4DktVWY4mSUErTKaeEOq6C3t3U= google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38= google.golang.org/grpc v1.21.1/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM= @@ -481,8 +486,9 @@ google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpAD google.golang.org/protobuf v1.24.0/go.mod h1:r/3tXBNzIEhYS9I1OUVjXDlt8tc493IdKGjtUeSXeh4= google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c= google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= -google.golang.org/protobuf v1.26.0 h1:bxAC2xTBsZGibn2RTntX0oH50xLsqy1OxA9tTL3p/lk= google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= +google.golang.org/protobuf v1.27.1 h1:SnqbnDw1V7RiZcXPx5MEeqPv2s79L9i7BJUlG/+RurQ= +google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= diff --git a/firestore/integration_test.go b/firestore/integration_test.go index e398150f84f..ca841858f98 100644 --- a/firestore/integration_test.go +++ b/firestore/integration_test.go @@ -1601,3 +1601,88 @@ func TestDetectProjectID(t *testing.T) { t.Errorf("expected an error while using TokenSource that does not have a project ID") } } + +func TestIntegration_ColGroupRefPartitions(t *testing.T) { + h := testHelper{t} + coll := integrationColl(t) + ctx := context.Background() + + // Create a doc in the test collection so a collectionID is live for testing + doc := coll.NewDoc() + h.mustCreate(doc, integrationTestMap) + + for _, tc := range []struct { + collectionID string + expectedPartitionCount int + }{ + // Verify no failures if a collection doesn't exist + {collectionID: "does-not-exist", expectedPartitionCount: 1}, + // Verify a collectionID with a small number of results returns a partition + {collectionID: coll.collectionID, expectedPartitionCount: 1}, + } { + colGroup := iClient.CollectionGroup(tc.collectionID) + partitions, err := colGroup.getPartitions(ctx, 10) + if err != nil { + t.Fatalf("getPartitions: received unexpected error: %v", err) + } + if got, want := len(partitions), tc.expectedPartitionCount; got != want { + t.Errorf("Unexpected Partition Count: got %d, want %d", got, want) + } + } +} + +func TestIntegration_ColGroupRefPartitionsLarge(t *testing.T) { + // Create collection with enough documents to have multiple partitions. + coll := integrationColl(t) + collectionID := coll.collectionID + "largeCollection" + coll = iClient.Collection(collectionID) + + ctx := context.Background() + + documentCount := 2*128 + 127 // Minimum partition size is 128. + + // Create documents in a collection sufficient to trigger multiple partitions. + batch := iClient.Batch() + deleteBatch := iClient.Batch() + for i := 0; i < documentCount; i++ { + doc := coll.Doc(fmt.Sprintf("doc%d", i)) + batch.Create(doc, integrationTestMap) + deleteBatch.Delete(doc) + } + batch.Commit(ctx) + defer deleteBatch.Commit(ctx) + + // Verify that we retrieve 383 documents for the colGroup (128*2 + 127) + colGroup := iClient.CollectionGroup(collectionID) + docs, err := colGroup.Documents(ctx).GetAll() + if err != nil { + t.Fatalf("GetAll(): received unexpected error: %v", err) + } + if got, want := len(docs), documentCount; got != want { + t.Errorf("Unexpected number of documents in collection group: got %d, want %d", got, want) + } + + // Get partitions, allow up to 10 to come back, expect less will be returned. + partitions, err := colGroup.GetPartitionedQueries(ctx, 10) + if err != nil { + t.Fatalf("GetPartitionedQueries: received unexpected error: %v", err) + } + if len(partitions) < 2 { + t.Errorf("Unexpected Partition Count. Expected 2 or more: got %d, want 2+", len(partitions)) + } + + // Verify that we retrieve 383 documents across all partitions. (128*2 + 127) + totalCount := 0 + for _, query := range partitions { + + allDocs, err := query.Documents(ctx).GetAll() + if err != nil { + t.Fatalf("GetAll(): received unexpected error: %v", err) + } + totalCount += len(allDocs) + } + + if got, want := totalCount, documentCount; got != want { + t.Errorf("Unexpected number of documents across partitions: got %d, want %d", got, want) + } +} diff --git a/firestore/order.go b/firestore/order.go index e5ee1e09fb5..c495a141fd3 100644 --- a/firestore/order.go +++ b/firestore/order.go @@ -22,6 +22,7 @@ import ( "strings" tspb "github.com/golang/protobuf/ptypes/timestamp" + firestorepb "google.golang.org/genproto/googleapis/firestore/v1" pb "google.golang.org/genproto/googleapis/firestore/v1" ) @@ -214,3 +215,10 @@ func typeOrder(v *pb.Value) int { panic(fmt.Sprintf("bad value type: %v", v)) } } + +// byReferenceValue implements sort.Interface for []*firestorepb.Value +type byFirestoreValue []*firestorepb.Value + +func (a byFirestoreValue) Len() int { return len(a) } +func (a byFirestoreValue) Swap(i, j int) { a[i], a[j] = a[j], a[i] } +func (a byFirestoreValue) Less(i, j int) bool { return compareValues(a[i], a[j]) < 0 } diff --git a/functions/apiv1/cloud_functions_client.go b/functions/apiv1/cloud_functions_client.go index df2718fe933..4f342917b6b 100644 --- a/functions/apiv1/cloud_functions_client.go +++ b/functions/apiv1/cloud_functions_client.go @@ -25,7 +25,6 @@ import ( "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" @@ -37,6 +36,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newCloudFunctionsClientHook clientHook @@ -62,6 +62,7 @@ func defaultCloudFunctionsGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("cloudfunctions.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://cloudfunctions.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/functions/apiv1/doc.go b/functions/apiv1/doc.go index 4bde116d95f..a4585accc01 100644 --- a/functions/apiv1/doc.go +++ b/functions/apiv1/doc.go @@ -49,7 +49,7 @@ import ( type clientHookParams struct{} type clientHook func(context.Context, clientHookParams) ([]option.ClientOption, error) -const versionClient = "20210612" +const versionClient = "20210701" func insertMetadata(ctx context.Context, mds ...metadata.MD) context.Context { out, _ := metadata.FromOutgoingContext(ctx) diff --git a/gaming/apiv1/doc.go b/gaming/apiv1/doc.go index 42dbf2e7808..a76ed2f294d 100644 --- a/gaming/apiv1/doc.go +++ b/gaming/apiv1/doc.go @@ -49,7 +49,7 @@ import ( type clientHookParams struct{} type clientHook func(context.Context, clientHookParams) ([]option.ClientOption, error) -const versionClient = "20210612" +const versionClient = "20210701" func insertMetadata(ctx context.Context, mds ...metadata.MD) context.Context { out, _ := metadata.FromOutgoingContext(ctx) diff --git a/gaming/apiv1/game_server_clusters_client.go b/gaming/apiv1/game_server_clusters_client.go index b85d8fc04d2..85b83e1c8b8 100644 --- a/gaming/apiv1/game_server_clusters_client.go +++ b/gaming/apiv1/game_server_clusters_client.go @@ -25,7 +25,6 @@ import ( "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" @@ -36,6 +35,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newGameServerClustersClientHook clientHook @@ -58,6 +58,7 @@ func defaultGameServerClustersGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("gameservices.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://gameservices.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/gaming/apiv1/game_server_configs_client.go b/gaming/apiv1/game_server_configs_client.go index 306df815e77..63cbca4f35d 100644 --- a/gaming/apiv1/game_server_configs_client.go +++ b/gaming/apiv1/game_server_configs_client.go @@ -25,7 +25,6 @@ import ( "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" @@ -36,6 +35,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newGameServerConfigsClientHook clientHook @@ -54,6 +54,7 @@ func defaultGameServerConfigsGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("gameservices.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://gameservices.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/gaming/apiv1/game_server_deployments_client.go b/gaming/apiv1/game_server_deployments_client.go index d4c7c5bcfe3..c393a74567c 100644 --- a/gaming/apiv1/game_server_deployments_client.go +++ b/gaming/apiv1/game_server_deployments_client.go @@ -25,7 +25,6 @@ import ( "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" @@ -36,6 +35,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newGameServerDeploymentsClientHook clientHook @@ -59,6 +59,7 @@ func defaultGameServerDeploymentsGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("gameservices.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://gameservices.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/gaming/apiv1/realms_client.go b/gaming/apiv1/realms_client.go index 552d18a3e5b..75e54f399cf 100644 --- a/gaming/apiv1/realms_client.go +++ b/gaming/apiv1/realms_client.go @@ -25,7 +25,6 @@ import ( "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" @@ -36,6 +35,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newRealmsClientHook clientHook @@ -56,6 +56,7 @@ func defaultRealmsGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("gameservices.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://gameservices.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/gaming/apiv1beta/doc.go b/gaming/apiv1beta/doc.go index 28da66d096e..c98ad69fa04 100644 --- a/gaming/apiv1beta/doc.go +++ b/gaming/apiv1beta/doc.go @@ -51,7 +51,7 @@ import ( type clientHookParams struct{} type clientHook func(context.Context, clientHookParams) ([]option.ClientOption, error) -const versionClient = "20210612" +const versionClient = "20210701" func insertMetadata(ctx context.Context, mds ...metadata.MD) context.Context { out, _ := metadata.FromOutgoingContext(ctx) diff --git a/gaming/apiv1beta/game_server_clusters_client.go b/gaming/apiv1beta/game_server_clusters_client.go index 48817c1edc3..e780ddb8094 100644 --- a/gaming/apiv1beta/game_server_clusters_client.go +++ b/gaming/apiv1beta/game_server_clusters_client.go @@ -25,7 +25,6 @@ import ( "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" @@ -36,6 +35,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newGameServerClustersClientHook clientHook @@ -58,6 +58,7 @@ func defaultGameServerClustersGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("gameservices.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://gameservices.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/gaming/apiv1beta/game_server_configs_client.go b/gaming/apiv1beta/game_server_configs_client.go index f3b91fd85ec..0d60f4411fc 100644 --- a/gaming/apiv1beta/game_server_configs_client.go +++ b/gaming/apiv1beta/game_server_configs_client.go @@ -25,7 +25,6 @@ import ( "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" @@ -36,6 +35,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newGameServerConfigsClientHook clientHook @@ -54,6 +54,7 @@ func defaultGameServerConfigsGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("gameservices.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://gameservices.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/gaming/apiv1beta/game_server_deployments_client.go b/gaming/apiv1beta/game_server_deployments_client.go index 76a2bb8bdc8..04f2749fe6c 100644 --- a/gaming/apiv1beta/game_server_deployments_client.go +++ b/gaming/apiv1beta/game_server_deployments_client.go @@ -25,7 +25,6 @@ import ( "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" @@ -36,6 +35,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newGameServerDeploymentsClientHook clientHook @@ -59,6 +59,7 @@ func defaultGameServerDeploymentsGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("gameservices.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://gameservices.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/gaming/apiv1beta/realms_client.go b/gaming/apiv1beta/realms_client.go index 28b33654ba1..0c719ea776b 100644 --- a/gaming/apiv1beta/realms_client.go +++ b/gaming/apiv1beta/realms_client.go @@ -25,7 +25,6 @@ import ( "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" @@ -36,6 +35,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newRealmsClientHook clientHook @@ -56,6 +56,7 @@ func defaultRealmsGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("gameservices.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://gameservices.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/gkeconnect/gateway/apiv1beta1/doc.go b/gkeconnect/gateway/apiv1beta1/doc.go index e25dfe6f9d5..c2078ca33f0 100644 --- a/gkeconnect/gateway/apiv1beta1/doc.go +++ b/gkeconnect/gateway/apiv1beta1/doc.go @@ -51,7 +51,7 @@ import ( type clientHookParams struct{} type clientHook func(context.Context, clientHookParams) ([]option.ClientOption, error) -const versionClient = "20210612" +const versionClient = "20210701" func insertMetadata(ctx context.Context, mds ...metadata.MD) context.Context { out, _ := metadata.FromOutgoingContext(ctx) diff --git a/gkeconnect/gateway/apiv1beta1/gateway_client.go b/gkeconnect/gateway/apiv1beta1/gateway_client.go index fdfa650992b..756cbbf38fe 100644 --- a/gkeconnect/gateway/apiv1beta1/gateway_client.go +++ b/gkeconnect/gateway/apiv1beta1/gateway_client.go @@ -47,6 +47,7 @@ func defaultGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("connectgateway.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://connectgateway.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/gkehub/apiv1beta1/doc.go b/gkehub/apiv1beta1/doc.go index 6202711ef04..4e52a500a58 100644 --- a/gkehub/apiv1beta1/doc.go +++ b/gkehub/apiv1beta1/doc.go @@ -48,7 +48,7 @@ import ( type clientHookParams struct{} type clientHook func(context.Context, clientHookParams) ([]option.ClientOption, error) -const versionClient = "20210612" +const versionClient = "20210701" func insertMetadata(ctx context.Context, mds ...metadata.MD) context.Context { out, _ := metadata.FromOutgoingContext(ctx) diff --git a/gkehub/apiv1beta1/gke_hub_membership_client.go b/gkehub/apiv1beta1/gke_hub_membership_client.go index f45e246303c..7eb98cdd428 100644 --- a/gkehub/apiv1beta1/gke_hub_membership_client.go +++ b/gkehub/apiv1beta1/gke_hub_membership_client.go @@ -25,7 +25,6 @@ import ( "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" @@ -36,6 +35,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newGkeHubMembershipClientHook clientHook @@ -58,6 +58,7 @@ func defaultGkeHubMembershipGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("gkehub.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://gkehub.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/go.mod b/go.mod index a070bd00dde..ebfba10f281 100644 --- a/go.mod +++ b/go.mod @@ -13,11 +13,11 @@ require ( github.com/jstemmer/go-junit-report v0.9.1 go.opencensus.io v0.23.0 golang.org/x/lint v0.0.0-20210508222113-6edffad5e616 - golang.org/x/oauth2 v0.0.0-20210615190721-d04028783cf1 + golang.org/x/oauth2 v0.0.0-20210628180205-a41e5a781914 golang.org/x/text v0.3.6 - golang.org/x/tools v0.1.3 - google.golang.org/api v0.48.0 - google.golang.org/genproto v0.0.0-20210617175327-b9e0b3197ced + golang.org/x/tools v0.1.4 + google.golang.org/api v0.50.0 + google.golang.org/genproto v0.0.0-20210701133433-6b8dcf568a95 google.golang.org/grpc v1.38.0 - google.golang.org/protobuf v1.26.0 + google.golang.org/protobuf v1.27.1 ) diff --git a/go.sum b/go.sum index a65100f3d21..cdf29627f57 100644 --- a/go.sum +++ b/go.sum @@ -19,6 +19,7 @@ cloud.google.com/go v0.78.0/go.mod h1:QjdrLG0uq+YwhjoVOLsS1t7TW8fs36kLs4XO5R5ECH cloud.google.com/go v0.79.0/go.mod h1:3bzgcEeQlzbuEAYu4mrWhKqWjmpprinYgKJLgKHnbb8= cloud.google.com/go v0.81.0/go.mod h1:mk/AM35KwGk/Nm2YSeZbxXdrNK3KZOYHmLkOqC2V6E0= cloud.google.com/go v0.83.0/go.mod h1:Z7MJUsANfY0pYPdw0lbnivPx4/vhy/e2FEkSkF7vAVY= +cloud.google.com/go v0.84.0/go.mod h1:RazrYuxIK6Kb7YrzzhPoLmCVzl7Sup4NrbKPg8KHSUM= cloud.google.com/go/bigquery v1.0.1/go.mod h1:i/xbL2UlR5RvWAURpBYZTtm/cXjCha9lbfbpx4poX+o= cloud.google.com/go/bigquery v1.3.0/go.mod h1:PjpwJnslEMmckchkHFfq+HTD2DmtT67aNFKH1/VBDHE= cloud.google.com/go/bigquery v1.4.0/go.mod h1:S8dzgnTigyfTmLBfrtrhyYhwRxG72rYxvftPBK2Dvzc= @@ -255,8 +256,8 @@ golang.org/x/oauth2 v0.0.0-20210218202405-ba52d332ba99/go.mod h1:KelEdhl1UZF7XfJ golang.org/x/oauth2 v0.0.0-20210220000619-9bb904979d93/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= golang.org/x/oauth2 v0.0.0-20210313182246-cd4f82c27b84/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= golang.org/x/oauth2 v0.0.0-20210514164344-f6687ab2804c/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= -golang.org/x/oauth2 v0.0.0-20210615190721-d04028783cf1 h1:x622Z2o4hgCr/4CiKWc51jHVKaWdtVpBNmEI8wI9Qns= -golang.org/x/oauth2 v0.0.0-20210615190721-d04028783cf1/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= +golang.org/x/oauth2 v0.0.0-20210628180205-a41e5a781914 h1:3B43BWw0xEBsLZ/NO1VALz6fppU3481pik+2Ksv45z8= +golang.org/x/oauth2 v0.0.0-20210628180205-a41e5a781914/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= @@ -308,8 +309,9 @@ golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210514084401-e8d321eab015/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20210603125802-9665404d3644 h1:CA1DEQ4NdKphKeL70tvsWNdT5oFh1lOjihRcEDROi0I= golang.org/x/sys v0.0.0-20210603125802-9665404d3644/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20210616094352-59db8d763f22 h1:RqytpXGR1iVNX7psjB3ff8y7sNFinVFvkx1c8SjBkio= +golang.org/x/sys v0.0.0-20210616094352-59db8d763f22/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= @@ -371,8 +373,9 @@ golang.org/x/tools v0.0.0-20210105154028-b0ab187a4818/go.mod h1:emZCQorbCU4vsT4f golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0= golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.2/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= -golang.org/x/tools v0.1.3 h1:L69ShwSZEyCsLKoAxDKeMvLDZkumEe8gXUZAjab0tX8= golang.org/x/tools v0.1.3/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= +golang.org/x/tools v0.1.4 h1:cVngSRcfgyZCzys3KYOpCFa+4dqX/Oub9tAq00ttGVs= +golang.org/x/tools v0.1.4/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= @@ -400,8 +403,9 @@ google.golang.org/api v0.40.0/go.mod h1:fYKFpnQN0DsDSKRVRcQSDQNtqWPfM9i+zNPxepjR google.golang.org/api v0.41.0/go.mod h1:RkxM5lITDfTzmyKFPt+wGrCJbVfniCr2ool8kTBzRTU= google.golang.org/api v0.43.0/go.mod h1:nQsDGjRXMo4lvh5hP0TKqF244gqhGcr/YSIykhUk/94= google.golang.org/api v0.47.0/go.mod h1:Wbvgpq1HddcWVtzsVLyfLp8lDg6AA241LmgIL59tHXo= -google.golang.org/api v0.48.0 h1:RDAPWfNFY06dffEXfn7hZF5Fr1ZbnChzfQZAPyBd1+I= google.golang.org/api v0.48.0/go.mod h1:71Pr1vy+TAZRPkPs/xlCf5SsU8WjuAWv1Pfjbtukyy4= +google.golang.org/api v0.50.0 h1:LX7NFCFYOHzr7WHaYiRUpeipZe9o5L8T+2F4Z798VDw= +google.golang.org/api v0.50.0/go.mod h1:4bNT5pAuq5ji4SRZm+5QIkjny9JAyVD/3gaSihNefaw= google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= google.golang.org/appengine v1.5.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= @@ -452,8 +456,10 @@ google.golang.org/genproto v0.0.0-20210402141018-6c239bbf2bb1/go.mod h1:9lPAdzaE google.golang.org/genproto v0.0.0-20210513213006-bf773b8c8384/go.mod h1:P3QM42oQyzQSnHPnZ/vqoCdDmzH28fzWByN9asMeM8A= google.golang.org/genproto v0.0.0-20210602131652-f16073e35f0c/go.mod h1:UODoCrxHCcBojKKwX1terBiRUaqAsFqJiF615XL43r0= google.golang.org/genproto v0.0.0-20210604141403-392c879c8b08/go.mod h1:UODoCrxHCcBojKKwX1terBiRUaqAsFqJiF615XL43r0= -google.golang.org/genproto v0.0.0-20210617175327-b9e0b3197ced h1:c5geK1iMU3cDKtFrCVQIcjR3W+JOZMuhIyICMCTbtus= -google.golang.org/genproto v0.0.0-20210617175327-b9e0b3197ced/go.mod h1:SzzZ/N+nwJDaO1kznhnlzqS8ocJICar6hYhVyhi++24= +google.golang.org/genproto v0.0.0-20210608205507-b6d2f5bf0d7d/go.mod h1:UODoCrxHCcBojKKwX1terBiRUaqAsFqJiF615XL43r0= +google.golang.org/genproto v0.0.0-20210624195500-8bfb893ecb84/go.mod h1:SzzZ/N+nwJDaO1kznhnlzqS8ocJICar6hYhVyhi++24= +google.golang.org/genproto v0.0.0-20210701133433-6b8dcf568a95 h1:xyRjacsGcaSoZ2fTcaLCSzh2JEceLLOT4X8k32Q0xAQ= +google.golang.org/genproto v0.0.0-20210701133433-6b8dcf568a95/go.mod h1:yiaVoXHpRzHGyxV3o4DktVWY4mSUErTKaeEOq6C3t3U= google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38= google.golang.org/grpc v1.21.1/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM= @@ -488,8 +494,9 @@ google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpAD google.golang.org/protobuf v1.24.0/go.mod h1:r/3tXBNzIEhYS9I1OUVjXDlt8tc493IdKGjtUeSXeh4= google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c= google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= -google.golang.org/protobuf v1.26.0 h1:bxAC2xTBsZGibn2RTntX0oH50xLsqy1OxA9tTL3p/lk= google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= +google.golang.org/protobuf v1.27.1 h1:SnqbnDw1V7RiZcXPx5MEeqPv2s79L9i7BJUlG/+RurQ= +google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= diff --git a/grafeas/apiv1/doc.go b/grafeas/apiv1/doc.go index e6cd315b80f..b495225f0d3 100644 --- a/grafeas/apiv1/doc.go +++ b/grafeas/apiv1/doc.go @@ -92,4 +92,4 @@ func versionGo() string { return "UNKNOWN" } -const versionClient = "20210612" +const versionClient = "20210624" diff --git a/gsuiteaddons/apiv1/doc.go b/gsuiteaddons/apiv1/doc.go index 480185bb2aa..2487b0bc497 100644 --- a/gsuiteaddons/apiv1/doc.go +++ b/gsuiteaddons/apiv1/doc.go @@ -48,7 +48,7 @@ import ( type clientHookParams struct{} type clientHook func(context.Context, clientHookParams) ([]option.ClientOption, error) -const versionClient = "20210612" +const versionClient = "20210701" func insertMetadata(ctx context.Context, mds ...metadata.MD) context.Context { out, _ := metadata.FromOutgoingContext(ctx) diff --git a/gsuiteaddons/apiv1/g_suite_add_ons_client.go b/gsuiteaddons/apiv1/g_suite_add_ons_client.go index 621a3399a19..2ca35d0799f 100644 --- a/gsuiteaddons/apiv1/g_suite_add_ons_client.go +++ b/gsuiteaddons/apiv1/g_suite_add_ons_client.go @@ -23,7 +23,6 @@ import ( "net/url" "time" - "github.com/golang/protobuf/proto" gax "github.com/googleapis/gax-go/v2" "google.golang.org/api/iterator" "google.golang.org/api/option" @@ -33,6 +32,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newClientHook clientHook @@ -56,6 +56,7 @@ func defaultGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("gsuiteaddons.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://gsuiteaddons.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/iam/admin/apiv1/doc.go b/iam/admin/apiv1/doc.go index 49e8451cbe5..39d55c6b280 100644 --- a/iam/admin/apiv1/doc.go +++ b/iam/admin/apiv1/doc.go @@ -100,4 +100,4 @@ func versionGo() string { return "UNKNOWN" } -const versionClient = "20210612" +const versionClient = "20210624" diff --git a/iam/credentials/apiv1/doc.go b/iam/credentials/apiv1/doc.go index 2ae8af9b648..d2b85b8f7dc 100644 --- a/iam/credentials/apiv1/doc.go +++ b/iam/credentials/apiv1/doc.go @@ -49,7 +49,7 @@ import ( type clientHookParams struct{} type clientHook func(context.Context, clientHookParams) ([]option.ClientOption, error) -const versionClient = "20210612" +const versionClient = "20210701" func insertMetadata(ctx context.Context, mds ...metadata.MD) context.Context { out, _ := metadata.FromOutgoingContext(ctx) diff --git a/iam/credentials/apiv1/iam_credentials_client.go b/iam/credentials/apiv1/iam_credentials_client.go index 8569451ac30..e9924a15354 100644 --- a/iam/credentials/apiv1/iam_credentials_client.go +++ b/iam/credentials/apiv1/iam_credentials_client.go @@ -49,6 +49,7 @@ func defaultIamCredentialsGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("iamcredentials.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://iamcredentials.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/internal/.repo-metadata-full.json b/internal/.repo-metadata-full.json index 13bb34a67ca..4e9f7ec2c64 100644 --- a/internal/.repo-metadata-full.json +++ b/internal/.repo-metadata-full.json @@ -284,7 +284,7 @@ "language": "Go", "client_library_type": "generated", "docs_url": "https://cloud.google.com/go/docs/reference/cloud.google.com/go/latest/clouddms/apiv1", - "release_level": "beta", + "release_level": "ga", "library_type": "" }, "cloud.google.com/go/cloudtasks/apiv2": { @@ -314,6 +314,15 @@ "release_level": "beta", "library_type": "" }, + "cloud.google.com/go/compute/apiv1": { + "distribution_name": "cloud.google.com/go/compute/apiv1", + "description": "Google Compute Engine API", + "language": "Go", + "client_library_type": "generated", + "docs_url": "https://cloud.google.com/go/docs/reference/cloud.google.com/go/latest/compute/apiv1", + "release_level": "alpha", + "library_type": "" + }, "cloud.google.com/go/compute/metadata": { "distribution_name": "cloud.google.com/go/compute/metadata", "description": "Service Metadata API", @@ -359,6 +368,15 @@ "release_level": "beta", "library_type": "" }, + "cloud.google.com/go/dataflow/apiv1beta3": { + "distribution_name": "cloud.google.com/go/dataflow/apiv1beta3", + "description": "Dataflow API", + "language": "Go", + "client_library_type": "generated", + "docs_url": "https://cloud.google.com/go/docs/reference/cloud.google.com/go/latest/dataflow/apiv1beta3", + "release_level": "beta", + "library_type": "" + }, "cloud.google.com/go/datalabeling/apiv1beta1": { "distribution_name": "cloud.google.com/go/datalabeling/apiv1beta1", "description": "Data Labeling API", @@ -413,6 +431,15 @@ "release_level": "alpha", "library_type": "" }, + "cloud.google.com/go/datastream/apiv1alpha1": { + "distribution_name": "cloud.google.com/go/datastream/apiv1alpha1", + "description": "Datastream API", + "language": "Go", + "client_library_type": "generated", + "docs_url": "https://cloud.google.com/go/docs/reference/cloud.google.com/go/latest/datastream/apiv1alpha1", + "release_level": "alpha", + "library_type": "" + }, "cloud.google.com/go/debugger/apiv2": { "distribution_name": "cloud.google.com/go/debugger/apiv2", "description": "Stackdriver Debugger API", @@ -437,7 +464,7 @@ "language": "Go", "client_library_type": "generated", "docs_url": "https://cloud.google.com/go/docs/reference/cloud.google.com/go/latest/dialogflow/cx/apiv3", - "release_level": "beta", + "release_level": "ga", "library_type": "" }, "cloud.google.com/go/dialogflow/cx/apiv3beta1": { @@ -464,7 +491,7 @@ "language": "Go", "client_library_type": "generated", "docs_url": "https://cloud.google.com/go/docs/reference/cloud.google.com/go/latest/documentai/apiv1", - "release_level": "beta", + "release_level": "ga", "library_type": "" }, "cloud.google.com/go/documentai/apiv1beta3": { @@ -509,6 +536,15 @@ "language": "Go", "client_library_type": "generated", "docs_url": "https://cloud.google.com/go/docs/reference/cloud.google.com/go/latest/essentialcontacts/apiv1", + "release_level": "ga", + "library_type": "" + }, + "cloud.google.com/go/eventarc/apiv1": { + "distribution_name": "cloud.google.com/go/eventarc/apiv1", + "description": "Eventarc API", + "language": "Go", + "client_library_type": "generated", + "docs_url": "https://cloud.google.com/go/docs/reference/cloud.google.com/go/latest/eventarc/apiv1", "release_level": "beta", "library_type": "" }, @@ -734,7 +770,7 @@ "language": "Go", "client_library_type": "generated", "docs_url": "https://cloud.google.com/go/docs/reference/cloud.google.com/go/latest/metastore/apiv1", - "release_level": "beta", + "release_level": "ga", "library_type": "" }, "cloud.google.com/go/metastore/apiv1alpha": { @@ -1013,7 +1049,7 @@ "language": "Go", "client_library_type": "generated", "docs_url": "https://cloud.google.com/go/docs/reference/cloud.google.com/go/latest/resourcesettings/apiv1", - "release_level": "beta", + "release_level": "ga", "library_type": "" }, "cloud.google.com/go/retail/apiv2": { @@ -1076,7 +1112,7 @@ "language": "Go", "client_library_type": "generated", "docs_url": "https://cloud.google.com/go/docs/reference/cloud.google.com/go/latest/security/privateca/apiv1", - "release_level": "beta", + "release_level": "ga", "library_type": "" }, "cloud.google.com/go/security/privateca/apiv1beta1": { @@ -1166,7 +1202,7 @@ "language": "Go", "client_library_type": "generated", "docs_url": "https://cloud.google.com/go/docs/reference/cloud.google.com/go/latest/serviceusage/apiv1", - "release_level": "beta", + "release_level": "ga", "library_type": "" }, "cloud.google.com/go/shell/apiv1": { @@ -1241,6 +1277,15 @@ "release_level": "ga", "library_type": "GAPIC_MANUAL" }, + "cloud.google.com/go/storage/internal/apiv1": { + "distribution_name": "cloud.google.com/go/storage/internal/apiv1", + "description": "Cloud Storage API", + "language": "Go", + "client_library_type": "generated", + "docs_url": "https://cloud.google.com/go/docs/reference/cloud.google.com/go/latest/storage/internal/apiv1", + "release_level": "alpha", + "library_type": "" + }, "cloud.google.com/go/talent/apiv4": { "distribution_name": "cloud.google.com/go/talent/apiv4", "description": "Cloud Talent Solution API", @@ -1394,6 +1439,15 @@ "release_level": "beta", "library_type": "" }, + "cloud.google.com/go/workflows/executions/apiv1": { + "distribution_name": "cloud.google.com/go/workflows/executions/apiv1", + "description": "Workflow Executions API", + "language": "Go", + "client_library_type": "generated", + "docs_url": "https://cloud.google.com/go/docs/reference/cloud.google.com/go/latest/workflows/executions/apiv1", + "release_level": "beta", + "library_type": "" + }, "cloud.google.com/go/workflows/executions/apiv1beta": { "distribution_name": "cloud.google.com/go/workflows/executions/apiv1beta", "description": "Workflow Executions API", diff --git a/internal/examples/fake/go.mod b/internal/examples/fake/go.mod index a28b07053e3..c0c4fb663e2 100644 --- a/internal/examples/fake/go.mod +++ b/internal/examples/fake/go.mod @@ -3,8 +3,8 @@ module cloud.google.com/go/internal/examples/fake go 1.15 require ( - cloud.google.com/go v0.81.0 - google.golang.org/api v0.46.0 - google.golang.org/genproto v0.0.0-20210601144548-a796c710e9b6 - google.golang.org/grpc v1.37.1 + cloud.google.com/go v0.84.0 + google.golang.org/api v0.49.0 + google.golang.org/genproto v0.0.0-20210630183607-d20f26d13c79 + google.golang.org/grpc v1.38.0 ) diff --git a/internal/examples/fake/go.sum b/internal/examples/fake/go.sum index d9ac81ca88b..a536cf14e91 100644 --- a/internal/examples/fake/go.sum +++ b/internal/examples/fake/go.sum @@ -17,8 +17,10 @@ cloud.google.com/go v0.72.0/go.mod h1:M+5Vjvlc2wnp6tjzE102Dw08nGShTscUx2nZMufOKP cloud.google.com/go v0.74.0/go.mod h1:VV1xSbzvo+9QJOxLDaJfTjx5e+MePCpCWwvftOeQmWk= cloud.google.com/go v0.78.0/go.mod h1:QjdrLG0uq+YwhjoVOLsS1t7TW8fs36kLs4XO5R5ECHg= cloud.google.com/go v0.79.0/go.mod h1:3bzgcEeQlzbuEAYu4mrWhKqWjmpprinYgKJLgKHnbb8= -cloud.google.com/go v0.81.0 h1:at8Tk2zUz63cLPR0JPWm5vp77pEZmzxEQBEfRKn1VV8= cloud.google.com/go v0.81.0/go.mod h1:mk/AM35KwGk/Nm2YSeZbxXdrNK3KZOYHmLkOqC2V6E0= +cloud.google.com/go v0.83.0/go.mod h1:Z7MJUsANfY0pYPdw0lbnivPx4/vhy/e2FEkSkF7vAVY= +cloud.google.com/go v0.84.0 h1:hVhK90DwCdOAYGME/FJd9vNIZye9HBR6Yy3fu4js3N8= +cloud.google.com/go v0.84.0/go.mod h1:RazrYuxIK6Kb7YrzzhPoLmCVzl7Sup4NrbKPg8KHSUM= cloud.google.com/go/bigquery v1.0.1/go.mod h1:i/xbL2UlR5RvWAURpBYZTtm/cXjCha9lbfbpx4poX+o= cloud.google.com/go/bigquery v1.3.0/go.mod h1:PjpwJnslEMmckchkHFfq+HTD2DmtT67aNFKH1/VBDHE= cloud.google.com/go/bigquery v1.4.0/go.mod h1:S8dzgnTigyfTmLBfrtrhyYhwRxG72rYxvftPBK2Dvzc= @@ -89,6 +91,7 @@ github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaS github.com/golang/protobuf v1.5.1/go.mod h1:DopwsBzvsk0Fs44TXzsVbJyPhcCPeIwnvohx4u74HPM= github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw= github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= +github.com/golang/snappy v0.0.3/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= @@ -101,11 +104,13 @@ github.com/google/go-cmp v0.5.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/ github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.3/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU= github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.6 h1:BKbKCqvP6I+rmFHt06ZmyQtvB8xAkWdhFyr0ZUNZcxQ= +github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs= github.com/google/martian/v3 v3.0.0/go.mod h1:y5Zk1BBys9G+gd6Jrk0W3cC1+ELVxBWuIGO+w/tUAp0= github.com/google/martian/v3 v3.1.0/go.mod h1:y5Zk1BBys9G+gd6Jrk0W3cC1+ELVxBWuIGO+w/tUAp0= +github.com/google/martian/v3 v3.2.1/go.mod h1:oBOf6HBosgwRXnUGWUB05QECsc6uvmMiJ3+6W4l/CUk= github.com/google/pprof v0.0.0-20181206194817-3ea8567a2e57/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc= github.com/google/pprof v0.0.0-20190515194954-54271f7e092f/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc= github.com/google/pprof v0.0.0-20191218002539-d4f498aebedc/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM= @@ -117,6 +122,7 @@ github.com/google/pprof v0.0.0-20201023163331-3e6fc7fc9c4c/go.mod h1:kpwsk12EmLe github.com/google/pprof v0.0.0-20201203190320-1bf35d6f28c2/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= github.com/google/pprof v0.0.0-20210122040257-d980be63207e/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= github.com/google/pprof v0.0.0-20210226084205-cbba55b83ad5/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= +github.com/google/pprof v0.0.0-20210601050228-01bbb1931b22/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg= @@ -143,6 +149,7 @@ github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9de github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= +github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU= go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8= go.opencensus.io v0.22.2/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= @@ -179,6 +186,7 @@ golang.org/x/lint v0.0.0-20191125180803-fdd1cda4f05f/go.mod h1:5qLYkcX4OjUUV8bRu golang.org/x/lint v0.0.0-20200130185559-910be7a94367/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY= golang.org/x/lint v0.0.0-20200302205851-738671d3881b/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY= golang.org/x/lint v0.0.0-20201208152925-83fdc39ff7b5/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY= +golang.org/x/lint v0.0.0-20210508222113-6edffad5e616/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY= golang.org/x/mobile v0.0.0-20190312151609-d3739f865fa6/go.mod h1:z+o9i4GpDbdi3rU15maQ/Ox0txvL9dWGYEHz965HBQE= golang.org/x/mobile v0.0.0-20190719004257-d2bd2a29d028/go.mod h1:E/iHnbuqvinMTCcRqshq8CkpyQDoeVncDDYHnLhea+o= golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc= @@ -189,6 +197,7 @@ golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.4.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.4.1/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= +golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= @@ -222,6 +231,7 @@ golang.org/x/net v0.0.0-20201209123823-ac852fbbde11/go.mod h1:m0MpNAwzfU5UDzcl9v golang.org/x/net v0.0.0-20210119194325-5f4716e94777/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20210316092652-d523dce5a7f4/go.mod h1:RBQZq4jEuRlivfhVLdyRGr576XBO4/greRjx4P4O3yc= +golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM= golang.org/x/net v0.0.0-20210503060351-7fd8e65b6420 h1:a8jGStKg0XqKDlKqjLrXn0ioF5MH36pT7Z0BRTqLhbk= golang.org/x/net v0.0.0-20210503060351-7fd8e65b6420/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= @@ -235,8 +245,9 @@ golang.org/x/oauth2 v0.0.0-20201208152858-08078c50e5b5/go.mod h1:KelEdhl1UZF7XfJ golang.org/x/oauth2 v0.0.0-20210218202405-ba52d332ba99/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= golang.org/x/oauth2 v0.0.0-20210220000619-9bb904979d93/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= golang.org/x/oauth2 v0.0.0-20210313182246-cd4f82c27b84/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= -golang.org/x/oauth2 v0.0.0-20210427180440-81ed05c6b58c h1:SgVl/sCtkicsS7psKkje4H9YtjdEl3xsYh7N+5TDHqY= -golang.org/x/oauth2 v0.0.0-20210427180440-81ed05c6b58c/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= +golang.org/x/oauth2 v0.0.0-20210514164344-f6687ab2804c/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= +golang.org/x/oauth2 v0.0.0-20210615190721-d04028783cf1 h1:x622Z2o4hgCr/4CiKWc51jHVKaWdtVpBNmEI8wI9Qns= +golang.org/x/oauth2 v0.0.0-20210615190721-d04028783cf1/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= @@ -283,9 +294,13 @@ golang.org/x/sys v0.0.0-20210220050731-9a76102bfb43/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20210305230114-8fe3ee5dd75b/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210315160823-c6e025ad8005/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210320140829-1e4c9ba3b0c4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210503080704-8803ae5d1324 h1:pAwJxDByZctfPwzlNGrDN2BQLsdPb9NkhoTJtUkAO28= -golang.org/x/sys v0.0.0-20210503080704-8803ae5d1324/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20210514084401-e8d321eab015/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20210603125802-9665404d3644/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20210616094352-59db8d763f22 h1:RqytpXGR1iVNX7psjB3ff8y7sNFinVFvkx1c8SjBkio= +golang.org/x/sys v0.0.0-20210616094352-59db8d763f22/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= @@ -345,6 +360,10 @@ golang.org/x/tools v0.0.0-20201201161351-ac6f37ff4c2a/go.mod h1:emZCQorbCU4vsT4f golang.org/x/tools v0.0.0-20201208233053-a543418bbed2/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= golang.org/x/tools v0.0.0-20210105154028-b0ab187a4818/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0= +golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= +golang.org/x/tools v0.1.2/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= +golang.org/x/tools v0.1.3/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= +golang.org/x/tools v0.1.4/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= @@ -371,8 +390,10 @@ google.golang.org/api v0.36.0/go.mod h1:+z5ficQTmoYpPn8LCUNVpK5I7hwkpjbcgqA7I34q google.golang.org/api v0.40.0/go.mod h1:fYKFpnQN0DsDSKRVRcQSDQNtqWPfM9i+zNPxepjRCQ8= google.golang.org/api v0.41.0/go.mod h1:RkxM5lITDfTzmyKFPt+wGrCJbVfniCr2ool8kTBzRTU= google.golang.org/api v0.43.0/go.mod h1:nQsDGjRXMo4lvh5hP0TKqF244gqhGcr/YSIykhUk/94= -google.golang.org/api v0.46.0 h1:jkDWHOBIoNSD0OQpq4rtBVu+Rh325MPjXG1rakAp8JU= -google.golang.org/api v0.46.0/go.mod h1:ceL4oozhkAiTID8XMmJBsIxID/9wMXJVVFXPg4ylg3I= +google.golang.org/api v0.47.0/go.mod h1:Wbvgpq1HddcWVtzsVLyfLp8lDg6AA241LmgIL59tHXo= +google.golang.org/api v0.48.0/go.mod h1:71Pr1vy+TAZRPkPs/xlCf5SsU8WjuAWv1Pfjbtukyy4= +google.golang.org/api v0.49.0 h1:gjIBDxlTG7vnzMmEnYwTnvLTF8Rjzo+ETCgEX1YZ/fY= +google.golang.org/api v0.49.0/go.mod h1:BECiH72wsfwUvOVn3+btPD5WHi0LzavZReBndi42L18= google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= google.golang.org/appengine v1.5.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= @@ -420,9 +441,13 @@ google.golang.org/genproto v0.0.0-20210303154014-9728d6b83eeb/go.mod h1:FWY/as6D google.golang.org/genproto v0.0.0-20210310155132-4ce2db91004e/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= google.golang.org/genproto v0.0.0-20210319143718-93e7006c17a6/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= google.golang.org/genproto v0.0.0-20210402141018-6c239bbf2bb1/go.mod h1:9lPAdzaEmUacj36I+k7YKbEc5CXzPIeORRgDAUOu28A= -google.golang.org/genproto v0.0.0-20210429181445-86c259c2b4ab/go.mod h1:P3QM42oQyzQSnHPnZ/vqoCdDmzH28fzWByN9asMeM8A= -google.golang.org/genproto v0.0.0-20210601144548-a796c710e9b6 h1:zWmI+1Z2ZiKs1ceiAn4gjBd1v/d/AuWf/b+bLPe9aNw= -google.golang.org/genproto v0.0.0-20210601144548-a796c710e9b6/go.mod h1:P3QM42oQyzQSnHPnZ/vqoCdDmzH28fzWByN9asMeM8A= +google.golang.org/genproto v0.0.0-20210513213006-bf773b8c8384/go.mod h1:P3QM42oQyzQSnHPnZ/vqoCdDmzH28fzWByN9asMeM8A= +google.golang.org/genproto v0.0.0-20210602131652-f16073e35f0c/go.mod h1:UODoCrxHCcBojKKwX1terBiRUaqAsFqJiF615XL43r0= +google.golang.org/genproto v0.0.0-20210604141403-392c879c8b08/go.mod h1:UODoCrxHCcBojKKwX1terBiRUaqAsFqJiF615XL43r0= +google.golang.org/genproto v0.0.0-20210608205507-b6d2f5bf0d7d/go.mod h1:UODoCrxHCcBojKKwX1terBiRUaqAsFqJiF615XL43r0= +google.golang.org/genproto v0.0.0-20210617175327-b9e0b3197ced/go.mod h1:SzzZ/N+nwJDaO1kznhnlzqS8ocJICar6hYhVyhi++24= +google.golang.org/genproto v0.0.0-20210630183607-d20f26d13c79 h1:s1jFTXJryg4a1mew7xv03VZD8N9XjxFhk1o4Js4WvPQ= +google.golang.org/genproto v0.0.0-20210630183607-d20f26d13c79/go.mod h1:yiaVoXHpRzHGyxV3o4DktVWY4mSUErTKaeEOq6C3t3U= google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38= google.golang.org/grpc v1.21.1/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM= @@ -442,8 +467,10 @@ google.golang.org/grpc v1.35.0/go.mod h1:qjiiYl8FncCW8feJPdyg3v6XW24KsRHe+dy9BAG google.golang.org/grpc v1.36.0/go.mod h1:qjiiYl8FncCW8feJPdyg3v6XW24KsRHe+dy9BAGRRjU= google.golang.org/grpc v1.36.1/go.mod h1:qjiiYl8FncCW8feJPdyg3v6XW24KsRHe+dy9BAGRRjU= google.golang.org/grpc v1.37.0/go.mod h1:NREThFqKR1f3iQ6oBuvc5LadQuXVGo9rkm5ZGrQdJfM= -google.golang.org/grpc v1.37.1 h1:ARnQJNWxGyYJpdf/JXscNlQr/uv607ZPU9Z7ogHi+iI= google.golang.org/grpc v1.37.1/go.mod h1:NREThFqKR1f3iQ6oBuvc5LadQuXVGo9rkm5ZGrQdJfM= +google.golang.org/grpc v1.38.0 h1:/9BgsAsa5nWe26HqOlvlgJnqBuktYOLCgjCPqsa56W0= +google.golang.org/grpc v1.38.0/go.mod h1:NREThFqKR1f3iQ6oBuvc5LadQuXVGo9rkm5ZGrQdJfM= +google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.1.0/go.mod h1:6Kw0yEErY5E/yWrBtf03jp27GLLJujG4z/JK95pnjjw= google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= @@ -455,8 +482,9 @@ google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpAD google.golang.org/protobuf v1.24.0/go.mod h1:r/3tXBNzIEhYS9I1OUVjXDlt8tc493IdKGjtUeSXeh4= google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c= google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= -google.golang.org/protobuf v1.26.0 h1:bxAC2xTBsZGibn2RTntX0oH50xLsqy1OxA9tTL3p/lk= google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= +google.golang.org/protobuf v1.27.1 h1:SnqbnDw1V7RiZcXPx5MEeqPv2s79L9i7BJUlG/+RurQ= +google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= diff --git a/internal/examples/mock/go.mod b/internal/examples/mock/go.mod index 1502350dc08..acc420a8cb6 100644 --- a/internal/examples/mock/go.mod +++ b/internal/examples/mock/go.mod @@ -3,6 +3,9 @@ module cloud.google.com/go/internal/examples/mock go 1.15 require ( + github.com/google/go-cmp v0.5.6 // indirect github.com/googleapis/gax-go/v2 v2.0.5 - google.golang.org/genproto v0.0.0-20210601144548-a796c710e9b6 + golang.org/x/net v0.0.0-20210503060351-7fd8e65b6420 // indirect + golang.org/x/sys v0.0.0-20210616094352-59db8d763f22 // indirect + google.golang.org/genproto v0.0.0-20210630183607-d20f26d13c79 ) diff --git a/internal/examples/mock/go.sum b/internal/examples/mock/go.sum index 9f22d276f25..6869245539f 100644 --- a/internal/examples/mock/go.sum +++ b/internal/examples/mock/go.sum @@ -7,7 +7,7 @@ github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnht github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= -github.com/envoyproxy/go-control-plane v0.9.9-0.20201210154907-fd9021fe5dad/go.mod h1:cXg6YxExXjJnVBQHBLXeUAgxn2UodCpnH306RInaBQk= +github.com/envoyproxy/go-control-plane v0.9.9-0.20210217033140-668b12f5399d/go.mod h1:cXg6YxExXjJnVBQHBLXeUAgxn2UodCpnH306RInaBQk= github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= @@ -28,8 +28,9 @@ github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMyw github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU= github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.6 h1:BKbKCqvP6I+rmFHt06ZmyQtvB8xAkWdhFyr0ZUNZcxQ= +github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/googleapis/gax-go/v2 v2.0.5 h1:sjZBwGj9Jlw33ImPtvFviGYvseOtDM7hkSKB7+Tv3SM= github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk= @@ -37,45 +38,45 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= -github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= +github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= -golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= -golang.org/x/lint v0.0.0-20201208152925-83fdc39ff7b5/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY= +golang.org/x/lint v0.0.0-20210508222113-6edffad5e616/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY= golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg= -golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= +golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= -golang.org/x/net v0.0.0-20210316092652-d523dce5a7f4 h1:b0LrWgu8+q7z4J+0Y3Umo5q1dL7NXBkKBWkaVkAq17E= -golang.org/x/net v0.0.0-20210316092652-d523dce5a7f4/go.mod h1:RBQZq4jEuRlivfhVLdyRGr576XBO4/greRjx4P4O3yc= +golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM= +golang.org/x/net v0.0.0-20210503060351-7fd8e65b6420 h1:a8jGStKg0XqKDlKqjLrXn0ioF5MH36pT7Z0BRTqLhbk= +golang.org/x/net v0.0.0-20210503060351-7fd8e65b6420/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210315160823-c6e025ad8005/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210320140829-1e4c9ba3b0c4 h1:EZ2mChiOa8udjfp6rRmswTbtZN/QzUQp4ptM4rnjHvc= -golang.org/x/sys v0.0.0-20210320140829-1e4c9ba3b0c4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20210616094352-59db8d763f22 h1:RqytpXGR1iVNX7psjB3ff8y7sNFinVFvkx1c8SjBkio= +golang.org/x/sys v0.0.0-20210616094352-59db8d763f22/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/text v0.3.5 h1:i6eZZ+zk0SOf0xgBpEpPD18qWcJda6q1sxt3S0kzyUQ= golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.6 h1:aRYxNxv6iGQlyVaZmk6ZgYEDa+Jg18DxebPSrd6bg1M= +golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY= @@ -83,7 +84,7 @@ golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3 golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20200130002326-2f3ba24bd6e7/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= -golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0= +golang.org/x/tools v0.1.4/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= @@ -94,14 +95,14 @@ google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7 google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo= -google.golang.org/genproto v0.0.0-20210601144548-a796c710e9b6 h1:zWmI+1Z2ZiKs1ceiAn4gjBd1v/d/AuWf/b+bLPe9aNw= -google.golang.org/genproto v0.0.0-20210601144548-a796c710e9b6/go.mod h1:P3QM42oQyzQSnHPnZ/vqoCdDmzH28fzWByN9asMeM8A= +google.golang.org/genproto v0.0.0-20210630183607-d20f26d13c79 h1:s1jFTXJryg4a1mew7xv03VZD8N9XjxFhk1o4Js4WvPQ= +google.golang.org/genproto v0.0.0-20210630183607-d20f26d13c79/go.mod h1:yiaVoXHpRzHGyxV3o4DktVWY4mSUErTKaeEOq6C3t3U= google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY= google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= -google.golang.org/grpc v1.36.1 h1:cmUfbeGKnz9+2DD/UYsMQXeqbHZqZDs4eQwW0sFOpBY= -google.golang.org/grpc v1.36.1/go.mod h1:qjiiYl8FncCW8feJPdyg3v6XW24KsRHe+dy9BAGRRjU= +google.golang.org/grpc v1.38.0 h1:/9BgsAsa5nWe26HqOlvlgJnqBuktYOLCgjCPqsa56W0= +google.golang.org/grpc v1.38.0/go.mod h1:NREThFqKR1f3iQ6oBuvc5LadQuXVGo9rkm5ZGrQdJfM= google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= @@ -112,8 +113,9 @@ google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2 google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c= google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= -google.golang.org/protobuf v1.26.0 h1:bxAC2xTBsZGibn2RTntX0oH50xLsqy1OxA9tTL3p/lk= google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= +google.golang.org/protobuf v1.27.1 h1:SnqbnDw1V7RiZcXPx5MEeqPv2s79L9i7BJUlG/+RurQ= +google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= diff --git a/internal/gapicgen/cmd/genbot/Dockerfile b/internal/gapicgen/cmd/genbot/Dockerfile index b097205cae9..faeffdd1d4a 100644 --- a/internal/gapicgen/cmd/genbot/Dockerfile +++ b/internal/gapicgen/cmd/genbot/Dockerfile @@ -28,7 +28,7 @@ RUN GO111MODULE=on go get \ golang.org/x/lint/golint@latest \ golang.org/x/tools/cmd/goimports@latest \ honnef.co/go/tools/cmd/staticcheck@latest \ - github.com/googleapis/gapic-generator-go/cmd/protoc-gen-go_gapic@v0.20.4 + github.com/googleapis/gapic-generator-go/cmd/protoc-gen-go_gapic@v0.21.5 ENV PATH="${PATH}:/root/go/bin" # Source: http://debuggable.com/posts/disable-strict-host-checking-for-git-clone:49896ff3-0ac0-4263-9703-1eae4834cda3 diff --git a/internal/gapicgen/cmd/genbot/bot.go b/internal/gapicgen/cmd/genbot/bot.go index b75115b32b4..5ab3c3b3ff4 100644 --- a/internal/gapicgen/cmd/genbot/bot.go +++ b/internal/gapicgen/cmd/genbot/bot.go @@ -26,12 +26,20 @@ import ( "cloud.google.com/go/internal/gapicgen/git" ) -func genBot(ctx context.Context, githubAccessToken, githubUsername, githubName, githubEmail string) error { +type botConfig struct { + githubAccessToken string + githubUsername string + githubName string + githubEmail string + forceAll bool +} + +func genBot(ctx context.Context, c botConfig) error { for k, v := range map[string]string{ - "githubAccessToken": githubAccessToken, - "githubUsername": githubUsername, - "githubName": githubName, - "githubEmail": githubEmail, + "githubAccessToken": c.githubAccessToken, + "githubUsername": c.githubUsername, + "githubName": c.githubName, + "githubEmail": c.githubEmail, } { if v == "" { log.Printf("missing or empty value for required flag --%s\n", k) @@ -40,7 +48,7 @@ func genBot(ctx context.Context, githubAccessToken, githubUsername, githubName, } // Setup the client and git environment. - githubClient, err := git.NewGithubClient(ctx, githubUsername, githubName, githubEmail, githubAccessToken) + githubClient, err := git.NewGithubClient(ctx, c.githubUsername, c.githubName, c.githubEmail, c.githubAccessToken) if err != nil { return err } @@ -73,7 +81,7 @@ func genBot(ctx context.Context, githubAccessToken, githubUsername, githubName, return nil } - return generate(ctx, githubClient) + return generate(ctx, githubClient, c.forceAll) } // hasCreatedPRToday checks if the created time of a PR is from today. diff --git a/internal/gapicgen/cmd/genbot/generate.go b/internal/gapicgen/cmd/genbot/generate.go index 170090a34ba..b4ea82b336c 100644 --- a/internal/gapicgen/cmd/genbot/generate.go +++ b/internal/gapicgen/cmd/genbot/generate.go @@ -31,7 +31,7 @@ import ( // generate downloads sources and generates pull requests for go-genproto and // google-cloud-go if needed. -func generate(ctx context.Context, githubClient *git.GithubClient) error { +func generate(ctx context.Context, githubClient *git.GithubClient, forceAll bool) error { log.Println("creating temp dir") tmpDir, err := ioutil.TempDir("", "update-genproto") if err != nil { @@ -42,6 +42,7 @@ func generate(ctx context.Context, githubClient *git.GithubClient) error { log.Printf("working out %s\n", tmpDir) googleapisDir := filepath.Join(tmpDir, "googleapis") + googleapisDiscoDir := filepath.Join(tmpDir, "googleapis-discovery") gocloudDir := filepath.Join(tmpDir, "gocloud") genprotoDir := filepath.Join(tmpDir, "genproto") protoDir := filepath.Join(tmpDir, "proto") @@ -52,6 +53,9 @@ func generate(ctx context.Context, githubClient *git.GithubClient) error { grp.Go(func() error { return git.DeepClone("https://github.com/googleapis/googleapis", googleapisDir) }) + grp.Go(func() error { + return git.DeepClone("https://github.com/googleapis/googleapis-discovery", googleapisDiscoDir) + }) grp.Go(func() error { return git.DeepClone("https://github.com/googleapis/go-genproto", genprotoDir) }) @@ -67,10 +71,12 @@ func generate(ctx context.Context, githubClient *git.GithubClient) error { // Regen. conf := &generator.Config{ - GoogleapisDir: googleapisDir, - GenprotoDir: genprotoDir, - GapicDir: gocloudDir, - ProtoDir: protoDir, + GoogleapisDir: googleapisDir, + GoogleapisDiscoDir: googleapisDiscoDir, + GenprotoDir: genprotoDir, + GapicDir: gocloudDir, + ProtoDir: protoDir, + ForceAll: forceAll, } changes, err := generator.Generate(ctx, conf) if err != nil { diff --git a/internal/gapicgen/cmd/genbot/local.go b/internal/gapicgen/cmd/genbot/local.go index 0848ef3d5c5..c7cab8bfaa4 100644 --- a/internal/gapicgen/cmd/genbot/local.go +++ b/internal/gapicgen/cmd/genbot/local.go @@ -29,13 +29,14 @@ import ( ) type localConfig struct { - googleapisDir string - gocloudDir string - genprotoDir string - protoDir string - gapicToGenerate string - onlyGapics bool - regenOnly bool + googleapisDir string + googleapisDiscoDir string + gocloudDir string + genprotoDir string + protoDir string + gapicToGenerate string + onlyGapics bool + regenOnly bool } func genLocal(ctx context.Context, c localConfig) error { @@ -46,6 +47,7 @@ func genLocal(ctx context.Context, c localConfig) error { } log.Printf("temp dir created at %s\n", tmpDir) tmpGoogleapisDir := filepath.Join(tmpDir, "googleapis") + tmpGoogleapisDiscoDir := filepath.Join(tmpDir, "googleapis-discovery") tmpGenprotoDir := filepath.Join(tmpDir, "genproto") tmpGocloudDir := filepath.Join(tmpDir, "gocloud") tmpProtoDir := filepath.Join(tmpDir, "proto") @@ -53,6 +55,7 @@ func genLocal(ctx context.Context, c localConfig) error { // Clone repositories if needed. grp, _ := errgroup.WithContext(ctx) gitShallowClone(grp, "https://github.com/googleapis/googleapis.git", c.googleapisDir, tmpGoogleapisDir) + gitShallowClone(grp, "https://github.com/googleapis/googleapis-discovery.git", c.googleapisDiscoDir, tmpGoogleapisDiscoDir) gitShallowClone(grp, "https://github.com/googleapis/go-genproto", c.genprotoDir, tmpGenprotoDir) gitShallowClone(grp, "https://github.com/googleapis/google-cloud-go", c.gocloudDir, tmpGocloudDir) gitShallowClone(grp, "https://github.com/protocolbuffers/protobuf", c.protoDir, tmpProtoDir) @@ -62,14 +65,15 @@ func genLocal(ctx context.Context, c localConfig) error { // Regen. conf := &generator.Config{ - GoogleapisDir: deafultDir(tmpGoogleapisDir, c.googleapisDir), - GenprotoDir: deafultDir(tmpGenprotoDir, c.genprotoDir), - GapicDir: deafultDir(tmpGocloudDir, c.gocloudDir), - ProtoDir: deafultDir(tmpProtoDir, c.protoDir), - GapicToGenerate: c.gapicToGenerate, - OnlyGenerateGapic: c.onlyGapics, - LocalMode: true, - RegenOnly: c.regenOnly, + GoogleapisDir: deafultDir(tmpGoogleapisDir, c.googleapisDir), + GoogleapisDiscoDir: deafultDir(tmpGoogleapisDiscoDir, c.googleapisDiscoDir), + GenprotoDir: deafultDir(tmpGenprotoDir, c.genprotoDir), + GapicDir: deafultDir(tmpGocloudDir, c.gocloudDir), + ProtoDir: deafultDir(tmpProtoDir, c.protoDir), + GapicToGenerate: c.gapicToGenerate, + OnlyGenerateGapic: c.onlyGapics, + LocalMode: true, + RegenOnly: c.regenOnly, } if _, err := generator.Generate(ctx, conf); err != nil { log.Printf("Generator ran (and failed) in %s\n", tmpDir) diff --git a/internal/gapicgen/cmd/genbot/main.go b/internal/gapicgen/cmd/genbot/main.go index 7f90115eccf..89f941959f6 100644 --- a/internal/gapicgen/cmd/genbot/main.go +++ b/internal/gapicgen/cmd/genbot/main.go @@ -41,9 +41,11 @@ func main() { githubName := flag.String("githubName", os.Getenv("GITHUB_NAME"), "The name of the author for git commits.") githubEmail := flag.String("githubEmail", os.Getenv("GITHUB_EMAIL"), "The email address of the author.") localMode := flag.Bool("local", strToBool(os.Getenv("GENBOT_LOCAL_MODE")), "Enables generating sources locally. This mode will not open any pull requests.") + forceAll := flag.Bool("forceAll", strToBool(os.Getenv("GENBOT_FORCE_ALL")), "Enables regenerating everything regardless of changes in googleapis.") // flags for local mode googleapisDir := flag.String("googleapis-dir", os.Getenv("GOOGLEAPIS_DIR"), "Directory where sources of googleapis/googleapis resides. If unset the sources will be cloned to a temporary directory that is not cleaned up.") + googleapisDiscoDir := flag.String("googleapis-disco-dir", os.Getenv("GOOGLEAPIS_DISCO_DIR"), "Directory where sources of googleapis/googleapis-discovery resides. If unset the sources will be cloned to a temporary directory that is not cleaned up.") gocloudDir := flag.String("gocloud-dir", os.Getenv("GOCLOUD_DIR"), "Directory where sources of googleapis/google-cloud-go resides. If unset the sources will be cloned to a temporary directory that is not cleaned up.") genprotoDir := flag.String("genproto-dir", os.Getenv("GENPROTO_DIR"), "Directory where sources of googleapis/go-genproto resides. If unset the sources will be cloned to a temporary directory that is not cleaned up.") protoDir := flag.String("proto-dir", os.Getenv("PROTO_DIR"), "Directory where sources of google/protobuf resides. If unset the sources will be cloned to a temporary directory that is not cleaned up.") @@ -55,19 +57,26 @@ func main() { if *localMode { if err := genLocal(ctx, localConfig{ - googleapisDir: *googleapisDir, - gocloudDir: *gocloudDir, - genprotoDir: *genprotoDir, - protoDir: *protoDir, - gapicToGenerate: *gapicToGenerate, - onlyGapics: *onlyGapics, - regenOnly: *regenOnly, + googleapisDir: *googleapisDir, + googleapisDiscoDir: *googleapisDiscoDir, + gocloudDir: *gocloudDir, + genprotoDir: *genprotoDir, + protoDir: *protoDir, + gapicToGenerate: *gapicToGenerate, + onlyGapics: *onlyGapics, + regenOnly: *regenOnly, }); err != nil { log.Fatal(err) } return } - if err := genBot(ctx, *githubAccessToken, *githubUsername, *githubName, *githubEmail); err != nil { + if err := genBot(ctx, botConfig{ + githubAccessToken: *githubAccessToken, + githubUsername: *githubUsername, + githubName: *githubName, + githubEmail: *githubEmail, + forceAll: *forceAll, + }); err != nil { log.Fatal(err) } } diff --git a/internal/gapicgen/generator/config.go b/internal/gapicgen/generator/config.go index 17afd1b2ebf..935d478b254 100644 --- a/internal/gapicgen/generator/config.go +++ b/internal/gapicgen/generator/config.go @@ -46,10 +46,28 @@ type microgenConfig struct { // disableMetadata is used to toggle generation of the gapic_metadata.json // file for the client library. disableMetadata bool + + // transports is a list of transports to generate a client for. Acceptable + // values are 'grpc' and 'rest' + transports []string + + // googleapisDiscovery indicates if the protos reside in googleapis-discovery + // or not. Default is false, and will be looked up in googleapis. + googleapisDiscovery bool } var microgenGapicConfigs = []*microgenConfig{ // Cloud APIs + { + inputDirectoryPath: "google/cloud/compute/v1", + pkg: "compute", + importPath: "cloud.google.com/go/compute/apiv1", + apiServiceConfigPath: "google/cloud/compute/v1/compute_v1.yaml", + transports: []string{"rest"}, + // TODO(dovs): Change to "ga" when ready. + releaseLevel: "alpha", + googleapisDiscovery: true, + }, { inputDirectoryPath: "google/cloud/texttospeech/v1", pkg: "texttospeech", @@ -576,8 +594,7 @@ var microgenGapicConfigs = []*microgenConfig{ importPath: "cloud.google.com/go/dialogflow/cx/apiv3", gRPCServiceConfigPath: "google/cloud/dialogflow/cx/v3/dialogflow_grpc_service_config.json", apiServiceConfigPath: "google/cloud/dialogflow/cx/v3/dialogflow_v3.yaml", - // GA after 2021/04/23 - releaseLevel: "beta", + releaseLevel: "ga", }, { inputDirectoryPath: "google/cloud/dialogflow/v2", @@ -839,6 +856,15 @@ var microgenGapicConfigs = []*microgenConfig{ apiServiceConfigPath: "google/cloud/workflows/v1beta/workflows_v1beta.yaml", releaseLevel: "beta", }, + { + inputDirectoryPath: "google/cloud/workflows/executions/v1", + pkg: "executions", + importPath: "cloud.google.com/go/workflows/executions/apiv1", + gRPCServiceConfigPath: "google/cloud/workflows/executions/v1/executions_grpc_service_config.json", + apiServiceConfigPath: "google/cloud/workflows/executions/v1/workflowexecutions_v1.yaml", + // GA after 2021/07/30 + releaseLevel: "beta", + }, { inputDirectoryPath: "google/cloud/workflows/executions/v1beta", pkg: "executions", @@ -861,8 +887,7 @@ var microgenGapicConfigs = []*microgenConfig{ importPath: "cloud.google.com/go/security/privateca/apiv1", gRPCServiceConfigPath: "google/cloud/security/privateca/v1/privateca_grpc_service_config.json", apiServiceConfigPath: "google/cloud/security/privateca/v1/privateca_v1.yaml", - // GA after 2021/05/29 - releaseLevel: "beta", + releaseLevel: "ga", }, { inputDirectoryPath: "google/cloud/assuredworkloads/v1beta1", @@ -964,8 +989,7 @@ var microgenGapicConfigs = []*microgenConfig{ importPath: "cloud.google.com/go/documentai/apiv1", gRPCServiceConfigPath: "google/cloud/documentai/v1/documentai_v1_grpc_service_config.json", apiServiceConfigPath: "google/cloud/documentai/v1/documentai_v1.yaml", - // GA after 2021/04/23 - releaseLevel: "beta", + releaseLevel: "ga", }, { inputDirectoryPath: "google/cloud/documentai/v1beta3", @@ -1021,6 +1045,7 @@ var microgenGapicConfigs = []*microgenConfig{ gRPCServiceConfigPath: "google/cloud/recommendationengine/v1beta1/recommendationengine_grpc_service_config.json", apiServiceConfigPath: "google/cloud/recommendationengine/v1beta1/recommendationengine_v1beta1.yaml", releaseLevel: "beta", + stopGeneration: true, }, { inputDirectoryPath: "google/cloud/gkehub/v1beta1", @@ -1044,8 +1069,7 @@ var microgenGapicConfigs = []*microgenConfig{ importPath: "cloud.google.com/go/metastore/apiv1", gRPCServiceConfigPath: "google/cloud/metastore/v1/metastore_grpc_service_config.json", apiServiceConfigPath: "google/cloud/metastore/v1/metastore_v1.yaml", - // GA after 2021/06/10 - releaseLevel: "beta", + releaseLevel: "ga", }, { inputDirectoryPath: "google/cloud/metastore/v1alpha", @@ -1069,8 +1093,7 @@ var microgenGapicConfigs = []*microgenConfig{ importPath: "cloud.google.com/go/resourcesettings/apiv1", gRPCServiceConfigPath: "google/cloud/resourcesettings/v1/resourcesettings_grpc_service_config.json", apiServiceConfigPath: "google/cloud/resourcesettings/v1/resourcesettings_v1.yaml", - // GA after 2021/04/23 - releaseLevel: "beta", + releaseLevel: "ga", }, { inputDirectoryPath: "google/cloud/clouddms/v1", @@ -1078,8 +1101,7 @@ var microgenGapicConfigs = []*microgenConfig{ importPath: "cloud.google.com/go/clouddms/apiv1", gRPCServiceConfigPath: "google/cloud/clouddms/v1/library_grpc_service_config.json", apiServiceConfigPath: "google/cloud/clouddms/v1/datamigration_v1.yaml", - // GA after 2021/06/10 - releaseLevel: "beta", + releaseLevel: "ga", }, { inputDirectoryPath: "google/cloud/essentialcontacts/v1", @@ -1087,8 +1109,7 @@ var microgenGapicConfigs = []*microgenConfig{ importPath: "cloud.google.com/go/essentialcontacts/apiv1", gRPCServiceConfigPath: "google/cloud/essentialcontacts/v1/essentialcontacts_v1_grpc_service_config.json", apiServiceConfigPath: "google/cloud/essentialcontacts/v1/essentialcontacts_v1.yaml", - // GA after 2021/06/18 - releaseLevel: "beta", + releaseLevel: "ga", }, { inputDirectoryPath: "google/api/serviceusage/v1", @@ -1096,8 +1117,7 @@ var microgenGapicConfigs = []*microgenConfig{ importPath: "cloud.google.com/go/serviceusage/apiv1", gRPCServiceConfigPath: "google/api/serviceusage/v1/serviceusage_grpc_service_config.json", apiServiceConfigPath: "google/api/serviceusage/v1/serviceusage_v1.yaml", - // GA after 2021/06/18 - releaseLevel: "beta", + releaseLevel: "ga", }, { inputDirectoryPath: "google/cloud/shell/v1", @@ -1168,6 +1188,31 @@ var microgenGapicConfigs = []*microgenConfig{ apiServiceConfigPath: "google/cloud/gkeconnect/gateway/v1beta1/connectgateway_v1beta1.yaml", releaseLevel: "beta", }, + { + inputDirectoryPath: "google/cloud/datastream/v1alpha1", + pkg: "datastream", + importPath: "cloud.google.com/go/datastream/apiv1alpha1", + gRPCServiceConfigPath: "google/cloud/datastream/v1alpha1/datastream_grpc_service_config.json", + apiServiceConfigPath: "google/cloud/datastream/v1alpha1/datastream_v1alpha1.yaml", + releaseLevel: "alpha", + }, + { + inputDirectoryPath: "google/dataflow/v1beta3", + pkg: "dataflow", + importPath: "cloud.google.com/go/dataflow/apiv1beta3", + gRPCServiceConfigPath: "google/dataflow/v1beta3/dataflow_grpc_service_config.json", + apiServiceConfigPath: "google/dataflow/v1beta3/dataflow_v1beta3.yaml", + releaseLevel: "beta", + }, + { + inputDirectoryPath: "google/cloud/eventarc/v1", + pkg: "eventarc", + importPath: "cloud.google.com/go/eventarc/apiv1", + gRPCServiceConfigPath: "google/cloud/eventarc/v1/eventarc_grpc_service_config.json", + apiServiceConfigPath: "google/cloud/eventarc/v1/eventarc_v1.yaml", + // GA after 2021/07/30 + releaseLevel: "beta", + }, // Non-Cloud APIs { @@ -1203,4 +1248,12 @@ var microgenGapicConfigs = []*microgenConfig{ // GA after 2021/06/10 releaseLevel: "beta", }, + { + inputDirectoryPath: "google/storage/v1", + pkg: "storage", + importPath: "cloud.google.com/go/storage/internal/apiv1", + gRPCServiceConfigPath: "google/storage/v1/storage_grpc_service_config.json", + apiServiceConfigPath: "google/storage/v1/storage_v1.yaml", + releaseLevel: "alpha", + }, } diff --git a/internal/gapicgen/generator/config_test.go b/internal/gapicgen/generator/config_test.go index b5d61a77b51..9460acf0c85 100644 --- a/internal/gapicgen/generator/config_test.go +++ b/internal/gapicgen/generator/config_test.go @@ -33,8 +33,9 @@ var apivExceptions = map[string]bool{ } var packagePathExceptions = map[string]bool{ - "cloud.google.com/go/longrunning/autogen": true, - "cloud.google.com/go/firestore/apiv1/admin": true, + "cloud.google.com/go/longrunning/autogen": true, + "cloud.google.com/go/firestore/apiv1/admin": true, + "cloud.google.com/go/storage/internal/apiv1": true, } // TestMicrogenConfigs validates config entries. diff --git a/internal/gapicgen/generator/gapics.go b/internal/gapicgen/generator/gapics.go index 8362dffc32b..e57315a91df 100644 --- a/internal/gapicgen/generator/gapics.go +++ b/internal/gapicgen/generator/gapics.go @@ -32,27 +32,29 @@ import ( // GapicGenerator is used to regenerate gapic libraries. type GapicGenerator struct { - googleapisDir string - protoDir string - googleCloudDir string - genprotoDir string - gapicToGenerate string - regenOnly bool - onlyGenerateGapic bool - modifiedPkgs []string + googleapisDir string + googleapisDiscoDir string + protoDir string + googleCloudDir string + genprotoDir string + gapicToGenerate string + regenOnly bool + onlyGenerateGapic bool + modifiedPkgs []string } // NewGapicGenerator creates a GapicGenerator. func NewGapicGenerator(c *Config, modifiedPkgs []string) *GapicGenerator { return &GapicGenerator{ - googleapisDir: c.GoogleapisDir, - protoDir: c.ProtoDir, - googleCloudDir: c.GapicDir, - genprotoDir: c.GenprotoDir, - gapicToGenerate: c.GapicToGenerate, - regenOnly: c.RegenOnly, - onlyGenerateGapic: c.OnlyGenerateGapic, - modifiedPkgs: modifiedPkgs, + googleapisDir: c.GoogleapisDir, + googleapisDiscoDir: c.GoogleapisDiscoDir, + protoDir: c.ProtoDir, + googleCloudDir: c.GapicDir, + genprotoDir: c.GenprotoDir, + gapicToGenerate: c.GapicToGenerate, + regenOnly: c.RegenOnly, + onlyGenerateGapic: c.OnlyGenerateGapic, + modifiedPkgs: modifiedPkgs, } } @@ -267,13 +269,20 @@ find . -name '*.backup' -delete // microgen runs the microgenerator on a single microgen config. func (g *GapicGenerator) microgen(conf *microgenConfig) error { log.Println("microgen generating", conf.pkg) + dir := g.googleapisDir + if conf.googleapisDiscovery { + dir = g.googleapisDiscoDir + } var protoFiles []string - if err := filepath.Walk(g.googleapisDir+"/"+conf.inputDirectoryPath, func(path string, info os.FileInfo, err error) error { + if err := filepath.Walk(dir+"/"+conf.inputDirectoryPath, func(path string, info os.FileInfo, err error) error { if err != nil { return err } - if strings.Contains(info.Name(), ".proto") { + // Ignore compute_small.proto which is just for testing and would cause a collision if used in generation. + // + // TODO(noahdietz): Remove this when it is no longer needed. + if strings.Contains(info.Name(), ".proto") && !strings.Contains(info.Name(), "compute_small.proto") { protoFiles = append(protoFiles, path) } return nil @@ -282,6 +291,7 @@ func (g *GapicGenerator) microgen(conf *microgenConfig) error { } args := []string{"-I", g.googleapisDir, + "-I", g.googleapisDiscoDir, "--experimental_allow_proto3_optional", "-I", g.protoDir, "--go_gapic_out", g.googleCloudDir, @@ -297,9 +307,12 @@ func (g *GapicGenerator) microgen(conf *microgenConfig) error { if !conf.disableMetadata { args = append(args, "--go_gapic_opt", "metadata") } + if len(conf.transports) > 0 { + args = append(args, "--go_gapic_opt", fmt.Sprintf("transport=%s", strings.Join(conf.transports, "+"))) + } args = append(args, protoFiles...) c := execv.Command("protoc", args...) - c.Dir = g.googleapisDir + c.Dir = dir return c.Run() } @@ -478,7 +491,11 @@ func (g *GapicGenerator) manifest(confs []*microgenConfig) error { entries[manual.DistributionName] = manual } for _, conf := range confs { - yamlPath := filepath.Join(g.googleapisDir, conf.apiServiceConfigPath) + dir := g.googleapisDir + if conf.googleapisDiscovery { + dir = g.googleapisDiscoDir + } + yamlPath := filepath.Join(dir, conf.apiServiceConfigPath) yamlFile, err := os.Open(yamlPath) if err != nil { return err @@ -522,7 +539,11 @@ func (g *GapicGenerator) copyMicrogenFiles() error { func (g *GapicGenerator) parseAPIShortnames(confs []*microgenConfig, manualEntries []manifestEntry) (map[string]string, error) { shortnames := map[string]string{} for _, conf := range confs { - yamlPath := filepath.Join(g.googleapisDir, conf.apiServiceConfigPath) + dir := g.googleapisDir + if conf.googleapisDiscovery { + dir = g.googleapisDiscoDir + } + yamlPath := filepath.Join(dir, conf.apiServiceConfigPath) yamlFile, err := os.Open(yamlPath) if err != nil { return nil, err diff --git a/internal/gapicgen/generator/generator.go b/internal/gapicgen/generator/generator.go index 1c17e0e43d9..bea74721bc2 100644 --- a/internal/gapicgen/generator/generator.go +++ b/internal/gapicgen/generator/generator.go @@ -29,14 +29,16 @@ import ( // Config contains inputs needed to generate sources. type Config struct { - GoogleapisDir string - GenprotoDir string - GapicDir string - ProtoDir string - GapicToGenerate string - OnlyGenerateGapic bool - LocalMode bool - RegenOnly bool + GoogleapisDir string + GoogleapisDiscoDir string + GenprotoDir string + GapicDir string + ProtoDir string + GapicToGenerate string + OnlyGenerateGapic bool + LocalMode bool + RegenOnly bool + ForceAll bool } // Generate generates genproto and gapics. diff --git a/internal/gapicgen/generator/genproto.go b/internal/gapicgen/generator/genproto.go index 0314bdf5a0e..2d18bf0dd56 100644 --- a/internal/gapicgen/generator/genproto.go +++ b/internal/gapicgen/generator/genproto.go @@ -20,6 +20,7 @@ import ( "fmt" "io/ioutil" "log" + "os" "path/filepath" "regexp" "strconv" @@ -54,17 +55,21 @@ var denylist = map[string]bool{ // GenprotoGenerator is used to generate code for googleapis/go-genproto. type GenprotoGenerator struct { - genprotoDir string - googleapisDir string - protoSrcDir string + genprotoDir string + googleapisDir string + googleapisDiscoDir string + protoSrcDir string + forceAll bool } // NewGenprotoGenerator creates a new GenprotoGenerator. func NewGenprotoGenerator(c *Config) *GenprotoGenerator { return &GenprotoGenerator{ - genprotoDir: c.GenprotoDir, - googleapisDir: c.GoogleapisDir, - protoSrcDir: filepath.Join(c.ProtoDir, "/src"), + genprotoDir: c.GenprotoDir, + googleapisDir: c.GoogleapisDir, + googleapisDiscoDir: c.GoogleapisDiscoDir, + protoSrcDir: filepath.Join(c.ProtoDir, "/src"), + forceAll: c.ForceAll, } } @@ -99,7 +104,7 @@ func (g *GenprotoGenerator) Regen(ctx context.Context) error { log.Println("regenerating genproto") // Create space to put generated .pb.go's. - c := execv.Command("mkdir", "generated") + c := execv.Command("mkdir", "-p", "generated") c.Dir = g.genprotoDir if err := c.Run(); err != nil { return err @@ -111,6 +116,10 @@ func (g *GenprotoGenerator) Regen(ctx context.Context) error { return err } + // TODO(noahdietz): In local mode, since it clones a shallow copy with 1 commit, + // if the last regenerated hash is earlier than the top commit, the git diff-tree + // command fails. This is is a bit of a rough edge. Using my local clone of + // googleapis rectified the issue. pkgFiles, err := g.getUpdatedPackages(string(lastHash)) if err != nil { return err @@ -129,9 +138,15 @@ func (g *GenprotoGenerator) Regen(ctx context.Context) error { fn := fileNames grp.Go(func() error { log.Println("running protoc on", pk) - return g.protoc(fn) + return g.protoc(fn, true /* grpc */) }) } + // TODO(noahdietz): This needs to be generalized to support any proto in googleapis-discovery. + // It's hard because the regen.txt contains the committish from googleapis last used to regen. + grp.Go(func() error { + log.Println("running protoc on compute") + return g.protoc([]string{"google/cloud/compute/v1/compute.proto"}, false /* grpc */) + }) if err := grp.Wait(); err != nil { return err } @@ -175,8 +190,12 @@ func goPkg(fileName string) (string, error) { // protoc executes the "protoc" command on files named in fileNames, and outputs // to "/generated". -func (g *GenprotoGenerator) protoc(fileNames []string) error { - args := []string{"--experimental_allow_proto3_optional", fmt.Sprintf("--go_out=plugins=grpc:%s/generated", g.genprotoDir), "-I", g.googleapisDir, "-I", g.protoSrcDir} +func (g *GenprotoGenerator) protoc(fileNames []string, grpc bool) error { + stubs := fmt.Sprintf("--go_out=%s/generated", g.genprotoDir) + if grpc { + stubs = fmt.Sprintf("--go_out=plugins=grpc:%s/generated", g.genprotoDir) + } + args := []string{"--experimental_allow_proto3_optional", stubs, "-I", g.googleapisDiscoDir, "-I", g.googleapisDir, "-I", g.protoSrcDir} args = append(args, fileNames...) c := execv.Command("protoc", args...) c.Dir = g.genprotoDir @@ -186,6 +205,9 @@ func (g *GenprotoGenerator) protoc(fileNames []string) error { // getUpdatedPackages parses all of the new commits to find what packages need // to be regenerated. func (g *GenprotoGenerator) getUpdatedPackages(googleapisHash string) (map[string][]string, error) { + if g.forceAll { + return g.getAllPackages() + } files, err := git.UpdateFilesSinceHash(g.googleapisDir, googleapisHash) if err != nil { return nil, err @@ -205,6 +227,41 @@ func (g *GenprotoGenerator) getUpdatedPackages(googleapisHash string) (map[strin return pkgFiles, nil } +func (g *GenprotoGenerator) getAllPackages() (map[string][]string, error) { + seenFiles := make(map[string]bool) + pkgFiles := make(map[string][]string) + for _, root := range []string{g.googleapisDir} { + walkFn := func(path string, info os.FileInfo, err error) error { + if err != nil { + return err + } + if !info.Mode().IsRegular() || !strings.HasSuffix(path, ".proto") { + return nil + } + + switch rel, err := filepath.Rel(root, path); { + case err != nil: + return err + case seenFiles[rel]: + return nil + default: + seenFiles[rel] = true + } + + pkg, err := goPkg(path) + if err != nil { + return err + } + pkgFiles[pkg] = append(pkgFiles[pkg], path) + return nil + } + if err := filepath.Walk(root, walkFn); err != nil { + return nil, err + } + } + return pkgFiles, nil +} + // moveAndCleanupGeneratedSrc moves all generated src to their correct locations // in the repository, because protoc puts it in a folder called `generated/``. func (g *GenprotoGenerator) moveAndCleanupGeneratedSrc() error { diff --git a/internal/gapicgen/go.mod b/internal/gapicgen/go.mod index d4447f9c15f..05519980cae 100644 --- a/internal/gapicgen/go.mod +++ b/internal/gapicgen/go.mod @@ -4,15 +4,15 @@ go 1.16 require ( cloud.google.com/go v0.84.0 - cloud.google.com/go/internal/godocfx v0.0.0-20210621170140-22ffc18e522c + cloud.google.com/go/internal/godocfx v0.0.0-20210629140244-1672234f50c8 github.com/google/go-github/v35 v35.3.0 github.com/shurcooL/githubv4 v0.0.0-20201206200315-234843c633fa github.com/shurcooL/graphql v0.0.0-20200928012149-18c5c3165e3a // indirect - golang.org/x/oauth2 v0.0.0-20210615190721-d04028783cf1 + golang.org/x/oauth2 v0.0.0-20210628180205-a41e5a781914 golang.org/x/sync v0.0.0-20210220032951-036812b2e83c golang.org/x/sys v0.0.0-20210616094352-59db8d763f22 - google.golang.org/genproto v0.0.0-20210608205507-b6d2f5bf0d7d - google.golang.org/protobuf v1.26.0 + google.golang.org/genproto v0.0.0-20210630183607-d20f26d13c79 + google.golang.org/protobuf v1.27.1 gopkg.in/src-d/go-git.v4 v4.13.1 gopkg.in/yaml.v2 v2.4.0 ) diff --git a/internal/gapicgen/go.sum b/internal/gapicgen/go.sum index 746a4bde0a6..caf147b10f4 100644 --- a/internal/gapicgen/go.sum +++ b/internal/gapicgen/go.sum @@ -30,8 +30,8 @@ cloud.google.com/go/bigquery v1.7.0/go.mod h1://okPTzCYNXSlb24MZs83e2Do+h+VXtc4g cloud.google.com/go/bigquery v1.8.0/go.mod h1:J5hqkt3O0uAFnINi6JXValWIb1v0goeZM77hZzJN/fQ= cloud.google.com/go/datastore v1.0.0/go.mod h1:LXYbyblFSglQ5pkeyhO+Qmw7ukd3C+pD7TKLgZqpHYE= cloud.google.com/go/datastore v1.1.0/go.mod h1:umbIZjpQpHh4hmRpGhH4tLFup+FVzqBi1b3c64qFpCk= -cloud.google.com/go/internal/godocfx v0.0.0-20210621170140-22ffc18e522c h1:c3v7d0rhtI8Sz5ysyMhZRAbqR5v3njasTlRtb5JVqfU= -cloud.google.com/go/internal/godocfx v0.0.0-20210621170140-22ffc18e522c/go.mod h1:NFLrMLw/yENI4t6bupRMhFJ/WMAeT81B2nJmqkPdPaQ= +cloud.google.com/go/internal/godocfx v0.0.0-20210629140244-1672234f50c8 h1:Sz/TijbG39Ku7vRa2uBB9QguitOqr6krqWSPQEx3eYU= +cloud.google.com/go/internal/godocfx v0.0.0-20210629140244-1672234f50c8/go.mod h1:rla1u/NA8QrJKFqEh9/xJRhI5X3BSYLpaePjjuEG3qo= cloud.google.com/go/pubsub v1.0.1/go.mod h1:R0Gpsv3s54REJCy4fxDixWD93lHJMoZTyQ2kNxGRt3I= cloud.google.com/go/pubsub v1.1.0/go.mod h1:EwwdRX2sKPjnvnqCa270oGRyludottCI76h+R3AArQw= cloud.google.com/go/pubsub v1.2.0/go.mod h1:jhfEVHT8odbXTkndysNHCcx0awwzvfOlguIAii9o8iA= @@ -197,7 +197,7 @@ github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9de github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= -github.com/yuin/goldmark v1.3.7/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= +github.com/yuin/goldmark v1.3.8/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU= go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8= go.opencensus.io v0.22.2/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= @@ -298,8 +298,8 @@ golang.org/x/oauth2 v0.0.0-20210218202405-ba52d332ba99/go.mod h1:KelEdhl1UZF7XfJ golang.org/x/oauth2 v0.0.0-20210220000619-9bb904979d93/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= golang.org/x/oauth2 v0.0.0-20210313182246-cd4f82c27b84/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= golang.org/x/oauth2 v0.0.0-20210514164344-f6687ab2804c/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= -golang.org/x/oauth2 v0.0.0-20210615190721-d04028783cf1 h1:x622Z2o4hgCr/4CiKWc51jHVKaWdtVpBNmEI8wI9Qns= -golang.org/x/oauth2 v0.0.0-20210615190721-d04028783cf1/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= +golang.org/x/oauth2 v0.0.0-20210628180205-a41e5a781914 h1:3B43BWw0xEBsLZ/NO1VALz6fppU3481pik+2Ksv45z8= +golang.org/x/oauth2 v0.0.0-20210628180205-a41e5a781914/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= @@ -419,8 +419,9 @@ golang.org/x/tools v0.0.0-20210105154028-b0ab187a4818/go.mod h1:emZCQorbCU4vsT4f golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0= golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.2/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= -golang.org/x/tools v0.1.3 h1:L69ShwSZEyCsLKoAxDKeMvLDZkumEe8gXUZAjab0tX8= golang.org/x/tools v0.1.3/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= +golang.org/x/tools v0.1.4 h1:cVngSRcfgyZCzys3KYOpCFa+4dqX/Oub9tAq00ttGVs= +golang.org/x/tools v0.1.4/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= @@ -501,8 +502,9 @@ google.golang.org/genproto v0.0.0-20210402141018-6c239bbf2bb1/go.mod h1:9lPAdzaE google.golang.org/genproto v0.0.0-20210513213006-bf773b8c8384/go.mod h1:P3QM42oQyzQSnHPnZ/vqoCdDmzH28fzWByN9asMeM8A= google.golang.org/genproto v0.0.0-20210602131652-f16073e35f0c/go.mod h1:UODoCrxHCcBojKKwX1terBiRUaqAsFqJiF615XL43r0= google.golang.org/genproto v0.0.0-20210604141403-392c879c8b08/go.mod h1:UODoCrxHCcBojKKwX1terBiRUaqAsFqJiF615XL43r0= -google.golang.org/genproto v0.0.0-20210608205507-b6d2f5bf0d7d h1:KzwjikDymrEmYYbdyfievTwjEeGlu+OM6oiKBkF3Jfg= google.golang.org/genproto v0.0.0-20210608205507-b6d2f5bf0d7d/go.mod h1:UODoCrxHCcBojKKwX1terBiRUaqAsFqJiF615XL43r0= +google.golang.org/genproto v0.0.0-20210630183607-d20f26d13c79 h1:s1jFTXJryg4a1mew7xv03VZD8N9XjxFhk1o4Js4WvPQ= +google.golang.org/genproto v0.0.0-20210630183607-d20f26d13c79/go.mod h1:yiaVoXHpRzHGyxV3o4DktVWY4mSUErTKaeEOq6C3t3U= google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38= google.golang.org/grpc v1.21.1/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM= @@ -536,8 +538,9 @@ google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpAD google.golang.org/protobuf v1.24.0/go.mod h1:r/3tXBNzIEhYS9I1OUVjXDlt8tc493IdKGjtUeSXeh4= google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c= google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= -google.golang.org/protobuf v1.26.0 h1:bxAC2xTBsZGibn2RTntX0oH50xLsqy1OxA9tTL3p/lk= google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= +google.golang.org/protobuf v1.27.1 h1:SnqbnDw1V7RiZcXPx5MEeqPv2s79L9i7BJUlG/+RurQ= +google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= diff --git a/internal/generated/snippets/analytics/admin/apiv1alpha/AnalyticsAdminClient/CreateIosAppDataStream/main.go b/internal/generated/snippets/dataflow/apiv1beta3/FlexTemplatesClient/LaunchFlexTemplate/main.go similarity index 60% rename from internal/generated/snippets/analytics/admin/apiv1alpha/AnalyticsAdminClient/CreateIosAppDataStream/main.go rename to internal/generated/snippets/dataflow/apiv1beta3/FlexTemplatesClient/LaunchFlexTemplate/main.go index efd03615068..cd47c65b129 100644 --- a/internal/generated/snippets/analytics/admin/apiv1alpha/AnalyticsAdminClient/CreateIosAppDataStream/main.go +++ b/internal/generated/snippets/dataflow/apiv1beta3/FlexTemplatesClient/LaunchFlexTemplate/main.go @@ -12,30 +12,31 @@ // See the License for the specific language governing permissions and // limitations under the License. -// [START analyticsadmin_v1alpha_generated_AnalyticsAdminService_CreateIosAppDataStream_sync] +// Code generated by cloud.google.com/go/internal/gapicgen/gensnippets. DO NOT EDIT. + +// [START dataflow_v1beta3_generated_FlexTemplatesService_LaunchFlexTemplate_sync] package main import ( "context" - admin "cloud.google.com/go/analytics/admin/apiv1alpha" - adminpb "google.golang.org/genproto/googleapis/analytics/admin/v1alpha" + dataflow "cloud.google.com/go/dataflow/apiv1beta3" + dataflowpb "google.golang.org/genproto/googleapis/dataflow/v1beta3" ) func main() { - // import adminpb "google.golang.org/genproto/googleapis/analytics/admin/v1alpha" - ctx := context.Background() - c, err := admin.NewAnalyticsAdminClient(ctx) + c, err := dataflow.NewFlexTemplatesClient(ctx) if err != nil { // TODO: Handle error. } + defer c.Close() - req := &adminpb.CreateIosAppDataStreamRequest{ + req := &dataflowpb.LaunchFlexTemplateRequest{ // TODO: Fill request struct fields. } - resp, err := c.CreateIosAppDataStream(ctx, req) + resp, err := c.LaunchFlexTemplate(ctx, req) if err != nil { // TODO: Handle error. } @@ -43,4 +44,4 @@ func main() { _ = resp } -// [END analyticsadmin_v1alpha_generated_AnalyticsAdminService_CreateIosAppDataStream_sync] +// [END dataflow_v1beta3_generated_FlexTemplatesService_LaunchFlexTemplate_sync] diff --git a/internal/generated/snippets/dataflow/apiv1beta3/JobsV1Beta3Client/AggregatedListJobs/main.go b/internal/generated/snippets/dataflow/apiv1beta3/JobsV1Beta3Client/AggregatedListJobs/main.go new file mode 100644 index 00000000000..1cdb96de836 --- /dev/null +++ b/internal/generated/snippets/dataflow/apiv1beta3/JobsV1Beta3Client/AggregatedListJobs/main.go @@ -0,0 +1,54 @@ +// 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 +// +// http://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 cloud.google.com/go/internal/gapicgen/gensnippets. DO NOT EDIT. + +// [START dataflow_v1beta3_generated_JobsV1Beta3_AggregatedListJobs_sync] + +package main + +import ( + "context" + + dataflow "cloud.google.com/go/dataflow/apiv1beta3" + "google.golang.org/api/iterator" + dataflowpb "google.golang.org/genproto/googleapis/dataflow/v1beta3" +) + +func main() { + ctx := context.Background() + c, err := dataflow.NewJobsV1Beta3Client(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &dataflowpb.ListJobsRequest{ + // TODO: Fill request struct fields. + } + it := c.AggregatedListJobs(ctx, req) + for { + resp, err := it.Next() + if err == iterator.Done { + break + } + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp + } +} + +// [END dataflow_v1beta3_generated_JobsV1Beta3_AggregatedListJobs_sync] diff --git a/internal/generated/snippets/dataflow/apiv1beta3/JobsV1Beta3Client/CheckActiveJobs/main.go b/internal/generated/snippets/dataflow/apiv1beta3/JobsV1Beta3Client/CheckActiveJobs/main.go new file mode 100644 index 00000000000..30533616e1c --- /dev/null +++ b/internal/generated/snippets/dataflow/apiv1beta3/JobsV1Beta3Client/CheckActiveJobs/main.go @@ -0,0 +1,47 @@ +// 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 +// +// http://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 cloud.google.com/go/internal/gapicgen/gensnippets. DO NOT EDIT. + +// [START dataflow_v1beta3_generated_JobsV1Beta3_CheckActiveJobs_sync] + +package main + +import ( + "context" + + dataflow "cloud.google.com/go/dataflow/apiv1beta3" + dataflowpb "google.golang.org/genproto/googleapis/dataflow/v1beta3" +) + +func main() { + ctx := context.Background() + c, err := dataflow.NewJobsV1Beta3Client(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &dataflowpb.CheckActiveJobsRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.CheckActiveJobs(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +// [END dataflow_v1beta3_generated_JobsV1Beta3_CheckActiveJobs_sync] diff --git a/internal/generated/snippets/dataflow/apiv1beta3/JobsV1Beta3Client/CreateJob/main.go b/internal/generated/snippets/dataflow/apiv1beta3/JobsV1Beta3Client/CreateJob/main.go new file mode 100644 index 00000000000..32087203c33 --- /dev/null +++ b/internal/generated/snippets/dataflow/apiv1beta3/JobsV1Beta3Client/CreateJob/main.go @@ -0,0 +1,47 @@ +// 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 +// +// http://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 cloud.google.com/go/internal/gapicgen/gensnippets. DO NOT EDIT. + +// [START dataflow_v1beta3_generated_JobsV1Beta3_CreateJob_sync] + +package main + +import ( + "context" + + dataflow "cloud.google.com/go/dataflow/apiv1beta3" + dataflowpb "google.golang.org/genproto/googleapis/dataflow/v1beta3" +) + +func main() { + ctx := context.Background() + c, err := dataflow.NewJobsV1Beta3Client(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &dataflowpb.CreateJobRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.CreateJob(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +// [END dataflow_v1beta3_generated_JobsV1Beta3_CreateJob_sync] diff --git a/internal/generated/snippets/dataflow/apiv1beta3/JobsV1Beta3Client/GetJob/main.go b/internal/generated/snippets/dataflow/apiv1beta3/JobsV1Beta3Client/GetJob/main.go new file mode 100644 index 00000000000..8a57334e4a1 --- /dev/null +++ b/internal/generated/snippets/dataflow/apiv1beta3/JobsV1Beta3Client/GetJob/main.go @@ -0,0 +1,47 @@ +// 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 +// +// http://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 cloud.google.com/go/internal/gapicgen/gensnippets. DO NOT EDIT. + +// [START dataflow_v1beta3_generated_JobsV1Beta3_GetJob_sync] + +package main + +import ( + "context" + + dataflow "cloud.google.com/go/dataflow/apiv1beta3" + dataflowpb "google.golang.org/genproto/googleapis/dataflow/v1beta3" +) + +func main() { + ctx := context.Background() + c, err := dataflow.NewJobsV1Beta3Client(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &dataflowpb.GetJobRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.GetJob(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +// [END dataflow_v1beta3_generated_JobsV1Beta3_GetJob_sync] diff --git a/internal/generated/snippets/dataflow/apiv1beta3/JobsV1Beta3Client/ListJobs/main.go b/internal/generated/snippets/dataflow/apiv1beta3/JobsV1Beta3Client/ListJobs/main.go new file mode 100644 index 00000000000..81dd44e621f --- /dev/null +++ b/internal/generated/snippets/dataflow/apiv1beta3/JobsV1Beta3Client/ListJobs/main.go @@ -0,0 +1,54 @@ +// 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 +// +// http://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 cloud.google.com/go/internal/gapicgen/gensnippets. DO NOT EDIT. + +// [START dataflow_v1beta3_generated_JobsV1Beta3_ListJobs_sync] + +package main + +import ( + "context" + + dataflow "cloud.google.com/go/dataflow/apiv1beta3" + "google.golang.org/api/iterator" + dataflowpb "google.golang.org/genproto/googleapis/dataflow/v1beta3" +) + +func main() { + ctx := context.Background() + c, err := dataflow.NewJobsV1Beta3Client(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &dataflowpb.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 + } +} + +// [END dataflow_v1beta3_generated_JobsV1Beta3_ListJobs_sync] diff --git a/internal/generated/snippets/dataflow/apiv1beta3/JobsV1Beta3Client/SnapshotJob/main.go b/internal/generated/snippets/dataflow/apiv1beta3/JobsV1Beta3Client/SnapshotJob/main.go new file mode 100644 index 00000000000..be232a1cadc --- /dev/null +++ b/internal/generated/snippets/dataflow/apiv1beta3/JobsV1Beta3Client/SnapshotJob/main.go @@ -0,0 +1,47 @@ +// 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 +// +// http://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 cloud.google.com/go/internal/gapicgen/gensnippets. DO NOT EDIT. + +// [START dataflow_v1beta3_generated_JobsV1Beta3_SnapshotJob_sync] + +package main + +import ( + "context" + + dataflow "cloud.google.com/go/dataflow/apiv1beta3" + dataflowpb "google.golang.org/genproto/googleapis/dataflow/v1beta3" +) + +func main() { + ctx := context.Background() + c, err := dataflow.NewJobsV1Beta3Client(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &dataflowpb.SnapshotJobRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.SnapshotJob(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +// [END dataflow_v1beta3_generated_JobsV1Beta3_SnapshotJob_sync] diff --git a/internal/generated/snippets/dataflow/apiv1beta3/JobsV1Beta3Client/UpdateJob/main.go b/internal/generated/snippets/dataflow/apiv1beta3/JobsV1Beta3Client/UpdateJob/main.go new file mode 100644 index 00000000000..5e4912c751e --- /dev/null +++ b/internal/generated/snippets/dataflow/apiv1beta3/JobsV1Beta3Client/UpdateJob/main.go @@ -0,0 +1,47 @@ +// 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 +// +// http://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 cloud.google.com/go/internal/gapicgen/gensnippets. DO NOT EDIT. + +// [START dataflow_v1beta3_generated_JobsV1Beta3_UpdateJob_sync] + +package main + +import ( + "context" + + dataflow "cloud.google.com/go/dataflow/apiv1beta3" + dataflowpb "google.golang.org/genproto/googleapis/dataflow/v1beta3" +) + +func main() { + ctx := context.Background() + c, err := dataflow.NewJobsV1Beta3Client(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &dataflowpb.UpdateJobRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.UpdateJob(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +// [END dataflow_v1beta3_generated_JobsV1Beta3_UpdateJob_sync] diff --git a/internal/generated/snippets/dataflow/apiv1beta3/MessagesV1Beta3Client/ListJobMessages/main.go b/internal/generated/snippets/dataflow/apiv1beta3/MessagesV1Beta3Client/ListJobMessages/main.go new file mode 100644 index 00000000000..f1c51e885ed --- /dev/null +++ b/internal/generated/snippets/dataflow/apiv1beta3/MessagesV1Beta3Client/ListJobMessages/main.go @@ -0,0 +1,54 @@ +// 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 +// +// http://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 cloud.google.com/go/internal/gapicgen/gensnippets. DO NOT EDIT. + +// [START dataflow_v1beta3_generated_MessagesV1Beta3_ListJobMessages_sync] + +package main + +import ( + "context" + + dataflow "cloud.google.com/go/dataflow/apiv1beta3" + "google.golang.org/api/iterator" + dataflowpb "google.golang.org/genproto/googleapis/dataflow/v1beta3" +) + +func main() { + ctx := context.Background() + c, err := dataflow.NewMessagesV1Beta3Client(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &dataflowpb.ListJobMessagesRequest{ + // TODO: Fill request struct fields. + } + it := c.ListJobMessages(ctx, req) + for { + resp, err := it.Next() + if err == iterator.Done { + break + } + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp + } +} + +// [END dataflow_v1beta3_generated_MessagesV1Beta3_ListJobMessages_sync] diff --git a/internal/generated/snippets/dataflow/apiv1beta3/MetricsV1Beta3Client/GetJobExecutionDetails/main.go b/internal/generated/snippets/dataflow/apiv1beta3/MetricsV1Beta3Client/GetJobExecutionDetails/main.go new file mode 100644 index 00000000000..92445f65612 --- /dev/null +++ b/internal/generated/snippets/dataflow/apiv1beta3/MetricsV1Beta3Client/GetJobExecutionDetails/main.go @@ -0,0 +1,54 @@ +// 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 +// +// http://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 cloud.google.com/go/internal/gapicgen/gensnippets. DO NOT EDIT. + +// [START dataflow_v1beta3_generated_MetricsV1Beta3_GetJobExecutionDetails_sync] + +package main + +import ( + "context" + + dataflow "cloud.google.com/go/dataflow/apiv1beta3" + "google.golang.org/api/iterator" + dataflowpb "google.golang.org/genproto/googleapis/dataflow/v1beta3" +) + +func main() { + ctx := context.Background() + c, err := dataflow.NewMetricsV1Beta3Client(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &dataflowpb.GetJobExecutionDetailsRequest{ + // TODO: Fill request struct fields. + } + it := c.GetJobExecutionDetails(ctx, req) + for { + resp, err := it.Next() + if err == iterator.Done { + break + } + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp + } +} + +// [END dataflow_v1beta3_generated_MetricsV1Beta3_GetJobExecutionDetails_sync] diff --git a/internal/generated/snippets/dataflow/apiv1beta3/MetricsV1Beta3Client/GetJobMetrics/main.go b/internal/generated/snippets/dataflow/apiv1beta3/MetricsV1Beta3Client/GetJobMetrics/main.go new file mode 100644 index 00000000000..accdb4ba03a --- /dev/null +++ b/internal/generated/snippets/dataflow/apiv1beta3/MetricsV1Beta3Client/GetJobMetrics/main.go @@ -0,0 +1,47 @@ +// 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 +// +// http://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 cloud.google.com/go/internal/gapicgen/gensnippets. DO NOT EDIT. + +// [START dataflow_v1beta3_generated_MetricsV1Beta3_GetJobMetrics_sync] + +package main + +import ( + "context" + + dataflow "cloud.google.com/go/dataflow/apiv1beta3" + dataflowpb "google.golang.org/genproto/googleapis/dataflow/v1beta3" +) + +func main() { + ctx := context.Background() + c, err := dataflow.NewMetricsV1Beta3Client(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &dataflowpb.GetJobMetricsRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.GetJobMetrics(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +// [END dataflow_v1beta3_generated_MetricsV1Beta3_GetJobMetrics_sync] diff --git a/internal/generated/snippets/dataflow/apiv1beta3/MetricsV1Beta3Client/GetStageExecutionDetails/main.go b/internal/generated/snippets/dataflow/apiv1beta3/MetricsV1Beta3Client/GetStageExecutionDetails/main.go new file mode 100644 index 00000000000..fcb77b62f80 --- /dev/null +++ b/internal/generated/snippets/dataflow/apiv1beta3/MetricsV1Beta3Client/GetStageExecutionDetails/main.go @@ -0,0 +1,54 @@ +// 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 +// +// http://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 cloud.google.com/go/internal/gapicgen/gensnippets. DO NOT EDIT. + +// [START dataflow_v1beta3_generated_MetricsV1Beta3_GetStageExecutionDetails_sync] + +package main + +import ( + "context" + + dataflow "cloud.google.com/go/dataflow/apiv1beta3" + "google.golang.org/api/iterator" + dataflowpb "google.golang.org/genproto/googleapis/dataflow/v1beta3" +) + +func main() { + ctx := context.Background() + c, err := dataflow.NewMetricsV1Beta3Client(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &dataflowpb.GetStageExecutionDetailsRequest{ + // TODO: Fill request struct fields. + } + it := c.GetStageExecutionDetails(ctx, req) + for { + resp, err := it.Next() + if err == iterator.Done { + break + } + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp + } +} + +// [END dataflow_v1beta3_generated_MetricsV1Beta3_GetStageExecutionDetails_sync] diff --git a/internal/generated/snippets/dataflow/apiv1beta3/SnapshotsV1Beta3Client/DeleteSnapshot/main.go b/internal/generated/snippets/dataflow/apiv1beta3/SnapshotsV1Beta3Client/DeleteSnapshot/main.go new file mode 100644 index 00000000000..cd6f98438f6 --- /dev/null +++ b/internal/generated/snippets/dataflow/apiv1beta3/SnapshotsV1Beta3Client/DeleteSnapshot/main.go @@ -0,0 +1,47 @@ +// 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 +// +// http://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 cloud.google.com/go/internal/gapicgen/gensnippets. DO NOT EDIT. + +// [START dataflow_v1beta3_generated_SnapshotsV1Beta3_DeleteSnapshot_sync] + +package main + +import ( + "context" + + dataflow "cloud.google.com/go/dataflow/apiv1beta3" + dataflowpb "google.golang.org/genproto/googleapis/dataflow/v1beta3" +) + +func main() { + ctx := context.Background() + c, err := dataflow.NewSnapshotsV1Beta3Client(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &dataflowpb.DeleteSnapshotRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.DeleteSnapshot(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +// [END dataflow_v1beta3_generated_SnapshotsV1Beta3_DeleteSnapshot_sync] diff --git a/internal/generated/snippets/dataflow/apiv1beta3/SnapshotsV1Beta3Client/GetSnapshot/main.go b/internal/generated/snippets/dataflow/apiv1beta3/SnapshotsV1Beta3Client/GetSnapshot/main.go new file mode 100644 index 00000000000..bddb53d155f --- /dev/null +++ b/internal/generated/snippets/dataflow/apiv1beta3/SnapshotsV1Beta3Client/GetSnapshot/main.go @@ -0,0 +1,47 @@ +// 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 +// +// http://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 cloud.google.com/go/internal/gapicgen/gensnippets. DO NOT EDIT. + +// [START dataflow_v1beta3_generated_SnapshotsV1Beta3_GetSnapshot_sync] + +package main + +import ( + "context" + + dataflow "cloud.google.com/go/dataflow/apiv1beta3" + dataflowpb "google.golang.org/genproto/googleapis/dataflow/v1beta3" +) + +func main() { + ctx := context.Background() + c, err := dataflow.NewSnapshotsV1Beta3Client(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &dataflowpb.GetSnapshotRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.GetSnapshot(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +// [END dataflow_v1beta3_generated_SnapshotsV1Beta3_GetSnapshot_sync] diff --git a/internal/generated/snippets/dataflow/apiv1beta3/SnapshotsV1Beta3Client/ListSnapshots/main.go b/internal/generated/snippets/dataflow/apiv1beta3/SnapshotsV1Beta3Client/ListSnapshots/main.go new file mode 100644 index 00000000000..5a0542fea0a --- /dev/null +++ b/internal/generated/snippets/dataflow/apiv1beta3/SnapshotsV1Beta3Client/ListSnapshots/main.go @@ -0,0 +1,47 @@ +// 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 +// +// http://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 cloud.google.com/go/internal/gapicgen/gensnippets. DO NOT EDIT. + +// [START dataflow_v1beta3_generated_SnapshotsV1Beta3_ListSnapshots_sync] + +package main + +import ( + "context" + + dataflow "cloud.google.com/go/dataflow/apiv1beta3" + dataflowpb "google.golang.org/genproto/googleapis/dataflow/v1beta3" +) + +func main() { + ctx := context.Background() + c, err := dataflow.NewSnapshotsV1Beta3Client(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &dataflowpb.ListSnapshotsRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.ListSnapshots(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +// [END dataflow_v1beta3_generated_SnapshotsV1Beta3_ListSnapshots_sync] diff --git a/internal/generated/snippets/dataflow/apiv1beta3/TemplatesClient/CreateJobFromTemplate/main.go b/internal/generated/snippets/dataflow/apiv1beta3/TemplatesClient/CreateJobFromTemplate/main.go new file mode 100644 index 00000000000..861997eb98e --- /dev/null +++ b/internal/generated/snippets/dataflow/apiv1beta3/TemplatesClient/CreateJobFromTemplate/main.go @@ -0,0 +1,47 @@ +// 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 +// +// http://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 cloud.google.com/go/internal/gapicgen/gensnippets. DO NOT EDIT. + +// [START dataflow_v1beta3_generated_TemplatesService_CreateJobFromTemplate_sync] + +package main + +import ( + "context" + + dataflow "cloud.google.com/go/dataflow/apiv1beta3" + dataflowpb "google.golang.org/genproto/googleapis/dataflow/v1beta3" +) + +func main() { + ctx := context.Background() + c, err := dataflow.NewTemplatesClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &dataflowpb.CreateJobFromTemplateRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.CreateJobFromTemplate(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +// [END dataflow_v1beta3_generated_TemplatesService_CreateJobFromTemplate_sync] diff --git a/internal/generated/snippets/dataflow/apiv1beta3/TemplatesClient/GetTemplate/main.go b/internal/generated/snippets/dataflow/apiv1beta3/TemplatesClient/GetTemplate/main.go new file mode 100644 index 00000000000..e4c49448997 --- /dev/null +++ b/internal/generated/snippets/dataflow/apiv1beta3/TemplatesClient/GetTemplate/main.go @@ -0,0 +1,47 @@ +// 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 +// +// http://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 cloud.google.com/go/internal/gapicgen/gensnippets. DO NOT EDIT. + +// [START dataflow_v1beta3_generated_TemplatesService_GetTemplate_sync] + +package main + +import ( + "context" + + dataflow "cloud.google.com/go/dataflow/apiv1beta3" + dataflowpb "google.golang.org/genproto/googleapis/dataflow/v1beta3" +) + +func main() { + ctx := context.Background() + c, err := dataflow.NewTemplatesClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &dataflowpb.GetTemplateRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.GetTemplate(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +// [END dataflow_v1beta3_generated_TemplatesService_GetTemplate_sync] diff --git a/internal/generated/snippets/dataflow/apiv1beta3/TemplatesClient/LaunchTemplate/main.go b/internal/generated/snippets/dataflow/apiv1beta3/TemplatesClient/LaunchTemplate/main.go new file mode 100644 index 00000000000..6331330a8a7 --- /dev/null +++ b/internal/generated/snippets/dataflow/apiv1beta3/TemplatesClient/LaunchTemplate/main.go @@ -0,0 +1,47 @@ +// 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 +// +// http://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 cloud.google.com/go/internal/gapicgen/gensnippets. DO NOT EDIT. + +// [START dataflow_v1beta3_generated_TemplatesService_LaunchTemplate_sync] + +package main + +import ( + "context" + + dataflow "cloud.google.com/go/dataflow/apiv1beta3" + dataflowpb "google.golang.org/genproto/googleapis/dataflow/v1beta3" +) + +func main() { + ctx := context.Background() + c, err := dataflow.NewTemplatesClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &dataflowpb.LaunchTemplateRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.LaunchTemplate(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +// [END dataflow_v1beta3_generated_TemplatesService_LaunchTemplate_sync] diff --git a/internal/generated/snippets/datastream/apiv1alpha1/Client/CreateConnectionProfile/main.go b/internal/generated/snippets/datastream/apiv1alpha1/Client/CreateConnectionProfile/main.go new file mode 100644 index 00000000000..e723189121c --- /dev/null +++ b/internal/generated/snippets/datastream/apiv1alpha1/Client/CreateConnectionProfile/main.go @@ -0,0 +1,52 @@ +// 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 +// +// http://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 cloud.google.com/go/internal/gapicgen/gensnippets. DO NOT EDIT. + +// [START datastream_v1alpha1_generated_Datastream_CreateConnectionProfile_sync] + +package main + +import ( + "context" + + datastream "cloud.google.com/go/datastream/apiv1alpha1" + datastreampb "google.golang.org/genproto/googleapis/cloud/datastream/v1alpha1" +) + +func main() { + ctx := context.Background() + c, err := datastream.NewClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &datastreampb.CreateConnectionProfileRequest{ + // TODO: Fill request struct fields. + } + op, err := c.CreateConnectionProfile(ctx, req) + if err != nil { + // TODO: Handle error. + } + + resp, err := op.Wait(ctx) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +// [END datastream_v1alpha1_generated_Datastream_CreateConnectionProfile_sync] diff --git a/internal/generated/snippets/datastream/apiv1alpha1/Client/CreatePrivateConnection/main.go b/internal/generated/snippets/datastream/apiv1alpha1/Client/CreatePrivateConnection/main.go new file mode 100644 index 00000000000..e7c955af5a1 --- /dev/null +++ b/internal/generated/snippets/datastream/apiv1alpha1/Client/CreatePrivateConnection/main.go @@ -0,0 +1,52 @@ +// 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 +// +// http://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 cloud.google.com/go/internal/gapicgen/gensnippets. DO NOT EDIT. + +// [START datastream_v1alpha1_generated_Datastream_CreatePrivateConnection_sync] + +package main + +import ( + "context" + + datastream "cloud.google.com/go/datastream/apiv1alpha1" + datastreampb "google.golang.org/genproto/googleapis/cloud/datastream/v1alpha1" +) + +func main() { + ctx := context.Background() + c, err := datastream.NewClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &datastreampb.CreatePrivateConnectionRequest{ + // TODO: Fill request struct fields. + } + op, err := c.CreatePrivateConnection(ctx, req) + if err != nil { + // TODO: Handle error. + } + + resp, err := op.Wait(ctx) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +// [END datastream_v1alpha1_generated_Datastream_CreatePrivateConnection_sync] diff --git a/internal/generated/snippets/datastream/apiv1alpha1/Client/CreateRoute/main.go b/internal/generated/snippets/datastream/apiv1alpha1/Client/CreateRoute/main.go new file mode 100644 index 00000000000..22f97c8e0ba --- /dev/null +++ b/internal/generated/snippets/datastream/apiv1alpha1/Client/CreateRoute/main.go @@ -0,0 +1,52 @@ +// 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 +// +// http://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 cloud.google.com/go/internal/gapicgen/gensnippets. DO NOT EDIT. + +// [START datastream_v1alpha1_generated_Datastream_CreateRoute_sync] + +package main + +import ( + "context" + + datastream "cloud.google.com/go/datastream/apiv1alpha1" + datastreampb "google.golang.org/genproto/googleapis/cloud/datastream/v1alpha1" +) + +func main() { + ctx := context.Background() + c, err := datastream.NewClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &datastreampb.CreateRouteRequest{ + // TODO: Fill request struct fields. + } + op, err := c.CreateRoute(ctx, req) + if err != nil { + // TODO: Handle error. + } + + resp, err := op.Wait(ctx) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +// [END datastream_v1alpha1_generated_Datastream_CreateRoute_sync] diff --git a/internal/generated/snippets/datastream/apiv1alpha1/Client/CreateStream/main.go b/internal/generated/snippets/datastream/apiv1alpha1/Client/CreateStream/main.go new file mode 100644 index 00000000000..f574bf4c330 --- /dev/null +++ b/internal/generated/snippets/datastream/apiv1alpha1/Client/CreateStream/main.go @@ -0,0 +1,52 @@ +// 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 +// +// http://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 cloud.google.com/go/internal/gapicgen/gensnippets. DO NOT EDIT. + +// [START datastream_v1alpha1_generated_Datastream_CreateStream_sync] + +package main + +import ( + "context" + + datastream "cloud.google.com/go/datastream/apiv1alpha1" + datastreampb "google.golang.org/genproto/googleapis/cloud/datastream/v1alpha1" +) + +func main() { + ctx := context.Background() + c, err := datastream.NewClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &datastreampb.CreateStreamRequest{ + // TODO: Fill request struct fields. + } + op, err := c.CreateStream(ctx, req) + if err != nil { + // TODO: Handle error. + } + + resp, err := op.Wait(ctx) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +// [END datastream_v1alpha1_generated_Datastream_CreateStream_sync] diff --git a/internal/generated/snippets/datastream/apiv1alpha1/Client/DeleteConnectionProfile/main.go b/internal/generated/snippets/datastream/apiv1alpha1/Client/DeleteConnectionProfile/main.go new file mode 100644 index 00000000000..7cf078c85e1 --- /dev/null +++ b/internal/generated/snippets/datastream/apiv1alpha1/Client/DeleteConnectionProfile/main.go @@ -0,0 +1,50 @@ +// 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 +// +// http://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 cloud.google.com/go/internal/gapicgen/gensnippets. DO NOT EDIT. + +// [START datastream_v1alpha1_generated_Datastream_DeleteConnectionProfile_sync] + +package main + +import ( + "context" + + datastream "cloud.google.com/go/datastream/apiv1alpha1" + datastreampb "google.golang.org/genproto/googleapis/cloud/datastream/v1alpha1" +) + +func main() { + ctx := context.Background() + c, err := datastream.NewClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &datastreampb.DeleteConnectionProfileRequest{ + // TODO: Fill request struct fields. + } + op, err := c.DeleteConnectionProfile(ctx, req) + if err != nil { + // TODO: Handle error. + } + + err = op.Wait(ctx) + if err != nil { + // TODO: Handle error. + } +} + +// [END datastream_v1alpha1_generated_Datastream_DeleteConnectionProfile_sync] diff --git a/internal/generated/snippets/datastream/apiv1alpha1/Client/DeletePrivateConnection/main.go b/internal/generated/snippets/datastream/apiv1alpha1/Client/DeletePrivateConnection/main.go new file mode 100644 index 00000000000..3578a7bb0bb --- /dev/null +++ b/internal/generated/snippets/datastream/apiv1alpha1/Client/DeletePrivateConnection/main.go @@ -0,0 +1,50 @@ +// 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 +// +// http://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 cloud.google.com/go/internal/gapicgen/gensnippets. DO NOT EDIT. + +// [START datastream_v1alpha1_generated_Datastream_DeletePrivateConnection_sync] + +package main + +import ( + "context" + + datastream "cloud.google.com/go/datastream/apiv1alpha1" + datastreampb "google.golang.org/genproto/googleapis/cloud/datastream/v1alpha1" +) + +func main() { + ctx := context.Background() + c, err := datastream.NewClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &datastreampb.DeletePrivateConnectionRequest{ + // TODO: Fill request struct fields. + } + op, err := c.DeletePrivateConnection(ctx, req) + if err != nil { + // TODO: Handle error. + } + + err = op.Wait(ctx) + if err != nil { + // TODO: Handle error. + } +} + +// [END datastream_v1alpha1_generated_Datastream_DeletePrivateConnection_sync] diff --git a/internal/generated/snippets/datastream/apiv1alpha1/Client/DeleteRoute/main.go b/internal/generated/snippets/datastream/apiv1alpha1/Client/DeleteRoute/main.go new file mode 100644 index 00000000000..9a9ddedb4e9 --- /dev/null +++ b/internal/generated/snippets/datastream/apiv1alpha1/Client/DeleteRoute/main.go @@ -0,0 +1,50 @@ +// 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 +// +// http://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 cloud.google.com/go/internal/gapicgen/gensnippets. DO NOT EDIT. + +// [START datastream_v1alpha1_generated_Datastream_DeleteRoute_sync] + +package main + +import ( + "context" + + datastream "cloud.google.com/go/datastream/apiv1alpha1" + datastreampb "google.golang.org/genproto/googleapis/cloud/datastream/v1alpha1" +) + +func main() { + ctx := context.Background() + c, err := datastream.NewClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &datastreampb.DeleteRouteRequest{ + // TODO: Fill request struct fields. + } + op, err := c.DeleteRoute(ctx, req) + if err != nil { + // TODO: Handle error. + } + + err = op.Wait(ctx) + if err != nil { + // TODO: Handle error. + } +} + +// [END datastream_v1alpha1_generated_Datastream_DeleteRoute_sync] diff --git a/internal/generated/snippets/datastream/apiv1alpha1/Client/DeleteStream/main.go b/internal/generated/snippets/datastream/apiv1alpha1/Client/DeleteStream/main.go new file mode 100644 index 00000000000..4ca4c07c414 --- /dev/null +++ b/internal/generated/snippets/datastream/apiv1alpha1/Client/DeleteStream/main.go @@ -0,0 +1,50 @@ +// 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 +// +// http://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 cloud.google.com/go/internal/gapicgen/gensnippets. DO NOT EDIT. + +// [START datastream_v1alpha1_generated_Datastream_DeleteStream_sync] + +package main + +import ( + "context" + + datastream "cloud.google.com/go/datastream/apiv1alpha1" + datastreampb "google.golang.org/genproto/googleapis/cloud/datastream/v1alpha1" +) + +func main() { + ctx := context.Background() + c, err := datastream.NewClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &datastreampb.DeleteStreamRequest{ + // TODO: Fill request struct fields. + } + op, err := c.DeleteStream(ctx, req) + if err != nil { + // TODO: Handle error. + } + + err = op.Wait(ctx) + if err != nil { + // TODO: Handle error. + } +} + +// [END datastream_v1alpha1_generated_Datastream_DeleteStream_sync] diff --git a/internal/generated/snippets/datastream/apiv1alpha1/Client/DiscoverConnectionProfile/main.go b/internal/generated/snippets/datastream/apiv1alpha1/Client/DiscoverConnectionProfile/main.go new file mode 100644 index 00000000000..e616aa7abff --- /dev/null +++ b/internal/generated/snippets/datastream/apiv1alpha1/Client/DiscoverConnectionProfile/main.go @@ -0,0 +1,47 @@ +// 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 +// +// http://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 cloud.google.com/go/internal/gapicgen/gensnippets. DO NOT EDIT. + +// [START datastream_v1alpha1_generated_Datastream_DiscoverConnectionProfile_sync] + +package main + +import ( + "context" + + datastream "cloud.google.com/go/datastream/apiv1alpha1" + datastreampb "google.golang.org/genproto/googleapis/cloud/datastream/v1alpha1" +) + +func main() { + ctx := context.Background() + c, err := datastream.NewClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &datastreampb.DiscoverConnectionProfileRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.DiscoverConnectionProfile(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +// [END datastream_v1alpha1_generated_Datastream_DiscoverConnectionProfile_sync] diff --git a/internal/generated/snippets/datastream/apiv1alpha1/Client/FetchErrors/main.go b/internal/generated/snippets/datastream/apiv1alpha1/Client/FetchErrors/main.go new file mode 100644 index 00000000000..e5cd267aff7 --- /dev/null +++ b/internal/generated/snippets/datastream/apiv1alpha1/Client/FetchErrors/main.go @@ -0,0 +1,52 @@ +// 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 +// +// http://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 cloud.google.com/go/internal/gapicgen/gensnippets. DO NOT EDIT. + +// [START datastream_v1alpha1_generated_Datastream_FetchErrors_sync] + +package main + +import ( + "context" + + datastream "cloud.google.com/go/datastream/apiv1alpha1" + datastreampb "google.golang.org/genproto/googleapis/cloud/datastream/v1alpha1" +) + +func main() { + ctx := context.Background() + c, err := datastream.NewClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &datastreampb.FetchErrorsRequest{ + // TODO: Fill request struct fields. + } + op, err := c.FetchErrors(ctx, req) + if err != nil { + // TODO: Handle error. + } + + resp, err := op.Wait(ctx) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +// [END datastream_v1alpha1_generated_Datastream_FetchErrors_sync] diff --git a/internal/generated/snippets/datastream/apiv1alpha1/Client/FetchStaticIps/main.go b/internal/generated/snippets/datastream/apiv1alpha1/Client/FetchStaticIps/main.go new file mode 100644 index 00000000000..deb583ac14e --- /dev/null +++ b/internal/generated/snippets/datastream/apiv1alpha1/Client/FetchStaticIps/main.go @@ -0,0 +1,54 @@ +// 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 +// +// http://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 cloud.google.com/go/internal/gapicgen/gensnippets. DO NOT EDIT. + +// [START datastream_v1alpha1_generated_Datastream_FetchStaticIps_sync] + +package main + +import ( + "context" + + datastream "cloud.google.com/go/datastream/apiv1alpha1" + "google.golang.org/api/iterator" + datastreampb "google.golang.org/genproto/googleapis/cloud/datastream/v1alpha1" +) + +func main() { + ctx := context.Background() + c, err := datastream.NewClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &datastreampb.FetchStaticIpsRequest{ + // TODO: Fill request struct fields. + } + it := c.FetchStaticIps(ctx, req) + for { + resp, err := it.Next() + if err == iterator.Done { + break + } + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp + } +} + +// [END datastream_v1alpha1_generated_Datastream_FetchStaticIps_sync] diff --git a/internal/generated/snippets/datastream/apiv1alpha1/Client/GetConnectionProfile/main.go b/internal/generated/snippets/datastream/apiv1alpha1/Client/GetConnectionProfile/main.go new file mode 100644 index 00000000000..61392165af4 --- /dev/null +++ b/internal/generated/snippets/datastream/apiv1alpha1/Client/GetConnectionProfile/main.go @@ -0,0 +1,47 @@ +// 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 +// +// http://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 cloud.google.com/go/internal/gapicgen/gensnippets. DO NOT EDIT. + +// [START datastream_v1alpha1_generated_Datastream_GetConnectionProfile_sync] + +package main + +import ( + "context" + + datastream "cloud.google.com/go/datastream/apiv1alpha1" + datastreampb "google.golang.org/genproto/googleapis/cloud/datastream/v1alpha1" +) + +func main() { + ctx := context.Background() + c, err := datastream.NewClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &datastreampb.GetConnectionProfileRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.GetConnectionProfile(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +// [END datastream_v1alpha1_generated_Datastream_GetConnectionProfile_sync] diff --git a/internal/generated/snippets/datastream/apiv1alpha1/Client/GetPrivateConnection/main.go b/internal/generated/snippets/datastream/apiv1alpha1/Client/GetPrivateConnection/main.go new file mode 100644 index 00000000000..05cd5a6f28e --- /dev/null +++ b/internal/generated/snippets/datastream/apiv1alpha1/Client/GetPrivateConnection/main.go @@ -0,0 +1,47 @@ +// 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 +// +// http://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 cloud.google.com/go/internal/gapicgen/gensnippets. DO NOT EDIT. + +// [START datastream_v1alpha1_generated_Datastream_GetPrivateConnection_sync] + +package main + +import ( + "context" + + datastream "cloud.google.com/go/datastream/apiv1alpha1" + datastreampb "google.golang.org/genproto/googleapis/cloud/datastream/v1alpha1" +) + +func main() { + ctx := context.Background() + c, err := datastream.NewClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &datastreampb.GetPrivateConnectionRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.GetPrivateConnection(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +// [END datastream_v1alpha1_generated_Datastream_GetPrivateConnection_sync] diff --git a/internal/generated/snippets/datastream/apiv1alpha1/Client/GetRoute/main.go b/internal/generated/snippets/datastream/apiv1alpha1/Client/GetRoute/main.go new file mode 100644 index 00000000000..67fd497cce2 --- /dev/null +++ b/internal/generated/snippets/datastream/apiv1alpha1/Client/GetRoute/main.go @@ -0,0 +1,47 @@ +// 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 +// +// http://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 cloud.google.com/go/internal/gapicgen/gensnippets. DO NOT EDIT. + +// [START datastream_v1alpha1_generated_Datastream_GetRoute_sync] + +package main + +import ( + "context" + + datastream "cloud.google.com/go/datastream/apiv1alpha1" + datastreampb "google.golang.org/genproto/googleapis/cloud/datastream/v1alpha1" +) + +func main() { + ctx := context.Background() + c, err := datastream.NewClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &datastreampb.GetRouteRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.GetRoute(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +// [END datastream_v1alpha1_generated_Datastream_GetRoute_sync] diff --git a/internal/generated/snippets/datastream/apiv1alpha1/Client/GetStream/main.go b/internal/generated/snippets/datastream/apiv1alpha1/Client/GetStream/main.go new file mode 100644 index 00000000000..3f312d5ca98 --- /dev/null +++ b/internal/generated/snippets/datastream/apiv1alpha1/Client/GetStream/main.go @@ -0,0 +1,47 @@ +// 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 +// +// http://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 cloud.google.com/go/internal/gapicgen/gensnippets. DO NOT EDIT. + +// [START datastream_v1alpha1_generated_Datastream_GetStream_sync] + +package main + +import ( + "context" + + datastream "cloud.google.com/go/datastream/apiv1alpha1" + datastreampb "google.golang.org/genproto/googleapis/cloud/datastream/v1alpha1" +) + +func main() { + ctx := context.Background() + c, err := datastream.NewClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &datastreampb.GetStreamRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.GetStream(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +// [END datastream_v1alpha1_generated_Datastream_GetStream_sync] diff --git a/internal/generated/snippets/datastream/apiv1alpha1/Client/ListConnectionProfiles/main.go b/internal/generated/snippets/datastream/apiv1alpha1/Client/ListConnectionProfiles/main.go new file mode 100644 index 00000000000..4b90347cbcc --- /dev/null +++ b/internal/generated/snippets/datastream/apiv1alpha1/Client/ListConnectionProfiles/main.go @@ -0,0 +1,54 @@ +// 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 +// +// http://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 cloud.google.com/go/internal/gapicgen/gensnippets. DO NOT EDIT. + +// [START datastream_v1alpha1_generated_Datastream_ListConnectionProfiles_sync] + +package main + +import ( + "context" + + datastream "cloud.google.com/go/datastream/apiv1alpha1" + "google.golang.org/api/iterator" + datastreampb "google.golang.org/genproto/googleapis/cloud/datastream/v1alpha1" +) + +func main() { + ctx := context.Background() + c, err := datastream.NewClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &datastreampb.ListConnectionProfilesRequest{ + // TODO: Fill request struct fields. + } + it := c.ListConnectionProfiles(ctx, req) + for { + resp, err := it.Next() + if err == iterator.Done { + break + } + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp + } +} + +// [END datastream_v1alpha1_generated_Datastream_ListConnectionProfiles_sync] diff --git a/internal/generated/snippets/datastream/apiv1alpha1/Client/ListPrivateConnections/main.go b/internal/generated/snippets/datastream/apiv1alpha1/Client/ListPrivateConnections/main.go new file mode 100644 index 00000000000..b2c5a56afd9 --- /dev/null +++ b/internal/generated/snippets/datastream/apiv1alpha1/Client/ListPrivateConnections/main.go @@ -0,0 +1,54 @@ +// 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 +// +// http://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 cloud.google.com/go/internal/gapicgen/gensnippets. DO NOT EDIT. + +// [START datastream_v1alpha1_generated_Datastream_ListPrivateConnections_sync] + +package main + +import ( + "context" + + datastream "cloud.google.com/go/datastream/apiv1alpha1" + "google.golang.org/api/iterator" + datastreampb "google.golang.org/genproto/googleapis/cloud/datastream/v1alpha1" +) + +func main() { + ctx := context.Background() + c, err := datastream.NewClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &datastreampb.ListPrivateConnectionsRequest{ + // TODO: Fill request struct fields. + } + it := c.ListPrivateConnections(ctx, req) + for { + resp, err := it.Next() + if err == iterator.Done { + break + } + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp + } +} + +// [END datastream_v1alpha1_generated_Datastream_ListPrivateConnections_sync] diff --git a/internal/generated/snippets/datastream/apiv1alpha1/Client/ListRoutes/main.go b/internal/generated/snippets/datastream/apiv1alpha1/Client/ListRoutes/main.go new file mode 100644 index 00000000000..c3e3964067b --- /dev/null +++ b/internal/generated/snippets/datastream/apiv1alpha1/Client/ListRoutes/main.go @@ -0,0 +1,54 @@ +// 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 +// +// http://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 cloud.google.com/go/internal/gapicgen/gensnippets. DO NOT EDIT. + +// [START datastream_v1alpha1_generated_Datastream_ListRoutes_sync] + +package main + +import ( + "context" + + datastream "cloud.google.com/go/datastream/apiv1alpha1" + "google.golang.org/api/iterator" + datastreampb "google.golang.org/genproto/googleapis/cloud/datastream/v1alpha1" +) + +func main() { + ctx := context.Background() + c, err := datastream.NewClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &datastreampb.ListRoutesRequest{ + // TODO: Fill request struct fields. + } + it := c.ListRoutes(ctx, req) + for { + resp, err := it.Next() + if err == iterator.Done { + break + } + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp + } +} + +// [END datastream_v1alpha1_generated_Datastream_ListRoutes_sync] diff --git a/internal/generated/snippets/datastream/apiv1alpha1/Client/ListStreams/main.go b/internal/generated/snippets/datastream/apiv1alpha1/Client/ListStreams/main.go new file mode 100644 index 00000000000..33a20779315 --- /dev/null +++ b/internal/generated/snippets/datastream/apiv1alpha1/Client/ListStreams/main.go @@ -0,0 +1,54 @@ +// 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 +// +// http://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 cloud.google.com/go/internal/gapicgen/gensnippets. DO NOT EDIT. + +// [START datastream_v1alpha1_generated_Datastream_ListStreams_sync] + +package main + +import ( + "context" + + datastream "cloud.google.com/go/datastream/apiv1alpha1" + "google.golang.org/api/iterator" + datastreampb "google.golang.org/genproto/googleapis/cloud/datastream/v1alpha1" +) + +func main() { + ctx := context.Background() + c, err := datastream.NewClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &datastreampb.ListStreamsRequest{ + // TODO: Fill request struct fields. + } + it := c.ListStreams(ctx, req) + for { + resp, err := it.Next() + if err == iterator.Done { + break + } + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp + } +} + +// [END datastream_v1alpha1_generated_Datastream_ListStreams_sync] diff --git a/internal/generated/snippets/datastream/apiv1alpha1/Client/UpdateConnectionProfile/main.go b/internal/generated/snippets/datastream/apiv1alpha1/Client/UpdateConnectionProfile/main.go new file mode 100644 index 00000000000..805f8dd36d4 --- /dev/null +++ b/internal/generated/snippets/datastream/apiv1alpha1/Client/UpdateConnectionProfile/main.go @@ -0,0 +1,52 @@ +// 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 +// +// http://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 cloud.google.com/go/internal/gapicgen/gensnippets. DO NOT EDIT. + +// [START datastream_v1alpha1_generated_Datastream_UpdateConnectionProfile_sync] + +package main + +import ( + "context" + + datastream "cloud.google.com/go/datastream/apiv1alpha1" + datastreampb "google.golang.org/genproto/googleapis/cloud/datastream/v1alpha1" +) + +func main() { + ctx := context.Background() + c, err := datastream.NewClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &datastreampb.UpdateConnectionProfileRequest{ + // TODO: Fill request struct fields. + } + op, err := c.UpdateConnectionProfile(ctx, req) + if err != nil { + // TODO: Handle error. + } + + resp, err := op.Wait(ctx) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +// [END datastream_v1alpha1_generated_Datastream_UpdateConnectionProfile_sync] diff --git a/internal/generated/snippets/datastream/apiv1alpha1/Client/UpdateStream/main.go b/internal/generated/snippets/datastream/apiv1alpha1/Client/UpdateStream/main.go new file mode 100644 index 00000000000..f276bbfe416 --- /dev/null +++ b/internal/generated/snippets/datastream/apiv1alpha1/Client/UpdateStream/main.go @@ -0,0 +1,52 @@ +// 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 +// +// http://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 cloud.google.com/go/internal/gapicgen/gensnippets. DO NOT EDIT. + +// [START datastream_v1alpha1_generated_Datastream_UpdateStream_sync] + +package main + +import ( + "context" + + datastream "cloud.google.com/go/datastream/apiv1alpha1" + datastreampb "google.golang.org/genproto/googleapis/cloud/datastream/v1alpha1" +) + +func main() { + ctx := context.Background() + c, err := datastream.NewClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &datastreampb.UpdateStreamRequest{ + // TODO: Fill request struct fields. + } + op, err := c.UpdateStream(ctx, req) + if err != nil { + // TODO: Handle error. + } + + resp, err := op.Wait(ctx) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +// [END datastream_v1alpha1_generated_Datastream_UpdateStream_sync] diff --git a/internal/generated/snippets/eventarc/apiv1/Client/CreateTrigger/main.go b/internal/generated/snippets/eventarc/apiv1/Client/CreateTrigger/main.go new file mode 100644 index 00000000000..74fac44dd11 --- /dev/null +++ b/internal/generated/snippets/eventarc/apiv1/Client/CreateTrigger/main.go @@ -0,0 +1,52 @@ +// 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 +// +// http://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 cloud.google.com/go/internal/gapicgen/gensnippets. DO NOT EDIT. + +// [START eventarc_v1_generated_Eventarc_CreateTrigger_sync] + +package main + +import ( + "context" + + eventarc "cloud.google.com/go/eventarc/apiv1" + eventarcpb "google.golang.org/genproto/googleapis/cloud/eventarc/v1" +) + +func main() { + ctx := context.Background() + c, err := eventarc.NewClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &eventarcpb.CreateTriggerRequest{ + // TODO: Fill request struct fields. + } + op, err := c.CreateTrigger(ctx, req) + if err != nil { + // TODO: Handle error. + } + + resp, err := op.Wait(ctx) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +// [END eventarc_v1_generated_Eventarc_CreateTrigger_sync] diff --git a/internal/generated/snippets/eventarc/apiv1/Client/DeleteTrigger/main.go b/internal/generated/snippets/eventarc/apiv1/Client/DeleteTrigger/main.go new file mode 100644 index 00000000000..0e75aeff8fb --- /dev/null +++ b/internal/generated/snippets/eventarc/apiv1/Client/DeleteTrigger/main.go @@ -0,0 +1,52 @@ +// 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 +// +// http://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 cloud.google.com/go/internal/gapicgen/gensnippets. DO NOT EDIT. + +// [START eventarc_v1_generated_Eventarc_DeleteTrigger_sync] + +package main + +import ( + "context" + + eventarc "cloud.google.com/go/eventarc/apiv1" + eventarcpb "google.golang.org/genproto/googleapis/cloud/eventarc/v1" +) + +func main() { + ctx := context.Background() + c, err := eventarc.NewClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &eventarcpb.DeleteTriggerRequest{ + // TODO: Fill request struct fields. + } + op, err := c.DeleteTrigger(ctx, req) + if err != nil { + // TODO: Handle error. + } + + resp, err := op.Wait(ctx) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +// [END eventarc_v1_generated_Eventarc_DeleteTrigger_sync] diff --git a/internal/generated/snippets/eventarc/apiv1/Client/GetTrigger/main.go b/internal/generated/snippets/eventarc/apiv1/Client/GetTrigger/main.go new file mode 100644 index 00000000000..ff021d175a6 --- /dev/null +++ b/internal/generated/snippets/eventarc/apiv1/Client/GetTrigger/main.go @@ -0,0 +1,47 @@ +// 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 +// +// http://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 cloud.google.com/go/internal/gapicgen/gensnippets. DO NOT EDIT. + +// [START eventarc_v1_generated_Eventarc_GetTrigger_sync] + +package main + +import ( + "context" + + eventarc "cloud.google.com/go/eventarc/apiv1" + eventarcpb "google.golang.org/genproto/googleapis/cloud/eventarc/v1" +) + +func main() { + ctx := context.Background() + c, err := eventarc.NewClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &eventarcpb.GetTriggerRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.GetTrigger(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +// [END eventarc_v1_generated_Eventarc_GetTrigger_sync] diff --git a/internal/generated/snippets/eventarc/apiv1/Client/ListTriggers/main.go b/internal/generated/snippets/eventarc/apiv1/Client/ListTriggers/main.go new file mode 100644 index 00000000000..02fb96631e2 --- /dev/null +++ b/internal/generated/snippets/eventarc/apiv1/Client/ListTriggers/main.go @@ -0,0 +1,54 @@ +// 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 +// +// http://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 cloud.google.com/go/internal/gapicgen/gensnippets. DO NOT EDIT. + +// [START eventarc_v1_generated_Eventarc_ListTriggers_sync] + +package main + +import ( + "context" + + eventarc "cloud.google.com/go/eventarc/apiv1" + "google.golang.org/api/iterator" + eventarcpb "google.golang.org/genproto/googleapis/cloud/eventarc/v1" +) + +func main() { + ctx := context.Background() + c, err := eventarc.NewClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &eventarcpb.ListTriggersRequest{ + // TODO: Fill request struct fields. + } + it := c.ListTriggers(ctx, req) + for { + resp, err := it.Next() + if err == iterator.Done { + break + } + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp + } +} + +// [END eventarc_v1_generated_Eventarc_ListTriggers_sync] diff --git a/internal/generated/snippets/eventarc/apiv1/Client/UpdateTrigger/main.go b/internal/generated/snippets/eventarc/apiv1/Client/UpdateTrigger/main.go new file mode 100644 index 00000000000..9b5748b2dfc --- /dev/null +++ b/internal/generated/snippets/eventarc/apiv1/Client/UpdateTrigger/main.go @@ -0,0 +1,52 @@ +// 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 +// +// http://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 cloud.google.com/go/internal/gapicgen/gensnippets. DO NOT EDIT. + +// [START eventarc_v1_generated_Eventarc_UpdateTrigger_sync] + +package main + +import ( + "context" + + eventarc "cloud.google.com/go/eventarc/apiv1" + eventarcpb "google.golang.org/genproto/googleapis/cloud/eventarc/v1" +) + +func main() { + ctx := context.Background() + c, err := eventarc.NewClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &eventarcpb.UpdateTriggerRequest{ + // TODO: Fill request struct fields. + } + op, err := c.UpdateTrigger(ctx, req) + if err != nil { + // TODO: Handle error. + } + + resp, err := op.Wait(ctx) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +// [END eventarc_v1_generated_Eventarc_UpdateTrigger_sync] diff --git a/internal/generated/snippets/go.mod b/internal/generated/snippets/go.mod index 12bd2fffe4f..b4d069b007d 100644 --- a/internal/generated/snippets/go.mod +++ b/internal/generated/snippets/go.mod @@ -31,6 +31,6 @@ require ( cloud.google.com/go/pubsub v1.9.1 cloud.google.com/go/pubsublite v0.84.0 cloud.google.com/go/spanner v0.84.0 - google.golang.org/api v0.48.0 - google.golang.org/genproto v0.0.0-20210617175327-b9e0b3197ced + google.golang.org/api v0.50.0 + google.golang.org/genproto v0.0.0-20210630183607-d20f26d13c79 ) diff --git a/internal/generated/snippets/go.sum b/internal/generated/snippets/go.sum index 6da54d93c2c..344e7341ff1 100644 --- a/internal/generated/snippets/go.sum +++ b/internal/generated/snippets/go.sum @@ -81,9 +81,8 @@ golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96b golang.org/x/net v0.0.0-20210503060351-7fd8e65b6420 h1:a8jGStKg0XqKDlKqjLrXn0ioF5MH36pT7Z0BRTqLhbk= golang.org/x/net v0.0.0-20210503060351-7fd8e65b6420/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= -golang.org/x/oauth2 v0.0.0-20210514164344-f6687ab2804c/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= -golang.org/x/oauth2 v0.0.0-20210615190721-d04028783cf1 h1:x622Z2o4hgCr/4CiKWc51jHVKaWdtVpBNmEI8wI9Qns= -golang.org/x/oauth2 v0.0.0-20210615190721-d04028783cf1/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= +golang.org/x/oauth2 v0.0.0-20210628180205-a41e5a781914 h1:3B43BWw0xEBsLZ/NO1VALz6fppU3481pik+2Ksv45z8= +golang.org/x/oauth2 v0.0.0-20210628180205-a41e5a781914/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= @@ -98,8 +97,8 @@ golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20210603125802-9665404d3644 h1:CA1DEQ4NdKphKeL70tvsWNdT5oFh1lOjihRcEDROi0I= -golang.org/x/sys v0.0.0-20210603125802-9665404d3644/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20210616094352-59db8d763f22 h1:RqytpXGR1iVNX7psjB3ff8y7sNFinVFvkx1c8SjBkio= +golang.org/x/sys v0.0.0-20210616094352-59db8d763f22/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= @@ -116,15 +115,15 @@ golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBn golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20200130002326-2f3ba24bd6e7/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= -golang.org/x/tools v0.1.2/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.3/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= +golang.org/x/tools v0.1.4/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE= golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -google.golang.org/api v0.48.0 h1:RDAPWfNFY06dffEXfn7hZF5Fr1ZbnChzfQZAPyBd1+I= -google.golang.org/api v0.48.0/go.mod h1:71Pr1vy+TAZRPkPs/xlCf5SsU8WjuAWv1Pfjbtukyy4= +google.golang.org/api v0.50.0 h1:LX7NFCFYOHzr7WHaYiRUpeipZe9o5L8T+2F4Z798VDw= +google.golang.org/api v0.50.0/go.mod h1:4bNT5pAuq5ji4SRZm+5QIkjny9JAyVD/3gaSihNefaw= google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= google.golang.org/appengine v1.6.6/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc= @@ -133,11 +132,9 @@ google.golang.org/appengine v1.6.7/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCID google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo= -google.golang.org/genproto v0.0.0-20210604141403-392c879c8b08/go.mod h1:UODoCrxHCcBojKKwX1terBiRUaqAsFqJiF615XL43r0= -google.golang.org/genproto v0.0.0-20210608205507-b6d2f5bf0d7d/go.mod h1:UODoCrxHCcBojKKwX1terBiRUaqAsFqJiF615XL43r0= -google.golang.org/genproto v0.0.0-20210614143202-012ab6975634/go.mod h1:SzzZ/N+nwJDaO1kznhnlzqS8ocJICar6hYhVyhi++24= -google.golang.org/genproto v0.0.0-20210617175327-b9e0b3197ced h1:c5geK1iMU3cDKtFrCVQIcjR3W+JOZMuhIyICMCTbtus= -google.golang.org/genproto v0.0.0-20210617175327-b9e0b3197ced/go.mod h1:SzzZ/N+nwJDaO1kznhnlzqS8ocJICar6hYhVyhi++24= +google.golang.org/genproto v0.0.0-20210624195500-8bfb893ecb84/go.mod h1:SzzZ/N+nwJDaO1kznhnlzqS8ocJICar6hYhVyhi++24= +google.golang.org/genproto v0.0.0-20210630183607-d20f26d13c79 h1:s1jFTXJryg4a1mew7xv03VZD8N9XjxFhk1o4Js4WvPQ= +google.golang.org/genproto v0.0.0-20210630183607-d20f26d13c79/go.mod h1:yiaVoXHpRzHGyxV3o4DktVWY4mSUErTKaeEOq6C3t3U= google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY= @@ -157,8 +154,9 @@ google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2 google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c= google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= -google.golang.org/protobuf v1.26.0 h1:bxAC2xTBsZGibn2RTntX0oH50xLsqy1OxA9tTL3p/lk= google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= +google.golang.org/protobuf v1.27.1 h1:SnqbnDw1V7RiZcXPx5MEeqPv2s79L9i7BJUlG/+RurQ= +google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/internal/generated/snippets/pubsublite/apiv1/AdminClient/SeekSubscription/main.go b/internal/generated/snippets/pubsublite/apiv1/AdminClient/SeekSubscription/main.go new file mode 100644 index 00000000000..617794932d1 --- /dev/null +++ b/internal/generated/snippets/pubsublite/apiv1/AdminClient/SeekSubscription/main.go @@ -0,0 +1,52 @@ +// 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 +// +// http://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 cloud.google.com/go/internal/gapicgen/gensnippets. DO NOT EDIT. + +// [START pubsublite_v1_generated_AdminService_SeekSubscription_sync] + +package main + +import ( + "context" + + pubsublite "cloud.google.com/go/pubsublite/apiv1" + pubsublitepb "google.golang.org/genproto/googleapis/cloud/pubsublite/v1" +) + +func main() { + ctx := context.Background() + c, err := pubsublite.NewAdminClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &pubsublitepb.SeekSubscriptionRequest{ + // TODO: Fill request struct fields. + } + op, err := c.SeekSubscription(ctx, req) + if err != nil { + // TODO: Handle error. + } + + resp, err := op.Wait(ctx) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +// [END pubsublite_v1_generated_AdminService_SeekSubscription_sync] diff --git a/internal/generated/snippets/workflows/executions/apiv1/Client/CancelExecution/main.go b/internal/generated/snippets/workflows/executions/apiv1/Client/CancelExecution/main.go new file mode 100644 index 00000000000..5b3b578c7e7 --- /dev/null +++ b/internal/generated/snippets/workflows/executions/apiv1/Client/CancelExecution/main.go @@ -0,0 +1,47 @@ +// 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 +// +// http://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 cloud.google.com/go/internal/gapicgen/gensnippets. DO NOT EDIT. + +// [START workflowexecutions_v1_generated_Executions_CancelExecution_sync] + +package main + +import ( + "context" + + executions "cloud.google.com/go/workflows/executions/apiv1" + executionspb "google.golang.org/genproto/googleapis/cloud/workflows/executions/v1" +) + +func main() { + ctx := context.Background() + c, err := executions.NewClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &executionspb.CancelExecutionRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.CancelExecution(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +// [END workflowexecutions_v1_generated_Executions_CancelExecution_sync] diff --git a/internal/generated/snippets/workflows/executions/apiv1/Client/CreateExecution/main.go b/internal/generated/snippets/workflows/executions/apiv1/Client/CreateExecution/main.go new file mode 100644 index 00000000000..6e897df78ff --- /dev/null +++ b/internal/generated/snippets/workflows/executions/apiv1/Client/CreateExecution/main.go @@ -0,0 +1,47 @@ +// 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 +// +// http://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 cloud.google.com/go/internal/gapicgen/gensnippets. DO NOT EDIT. + +// [START workflowexecutions_v1_generated_Executions_CreateExecution_sync] + +package main + +import ( + "context" + + executions "cloud.google.com/go/workflows/executions/apiv1" + executionspb "google.golang.org/genproto/googleapis/cloud/workflows/executions/v1" +) + +func main() { + ctx := context.Background() + c, err := executions.NewClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &executionspb.CreateExecutionRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.CreateExecution(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +// [END workflowexecutions_v1_generated_Executions_CreateExecution_sync] diff --git a/internal/generated/snippets/workflows/executions/apiv1/Client/GetExecution/main.go b/internal/generated/snippets/workflows/executions/apiv1/Client/GetExecution/main.go new file mode 100644 index 00000000000..6cd08576fee --- /dev/null +++ b/internal/generated/snippets/workflows/executions/apiv1/Client/GetExecution/main.go @@ -0,0 +1,47 @@ +// 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 +// +// http://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 cloud.google.com/go/internal/gapicgen/gensnippets. DO NOT EDIT. + +// [START workflowexecutions_v1_generated_Executions_GetExecution_sync] + +package main + +import ( + "context" + + executions "cloud.google.com/go/workflows/executions/apiv1" + executionspb "google.golang.org/genproto/googleapis/cloud/workflows/executions/v1" +) + +func main() { + ctx := context.Background() + c, err := executions.NewClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &executionspb.GetExecutionRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.GetExecution(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +// [END workflowexecutions_v1_generated_Executions_GetExecution_sync] diff --git a/internal/generated/snippets/workflows/executions/apiv1/Client/ListExecutions/main.go b/internal/generated/snippets/workflows/executions/apiv1/Client/ListExecutions/main.go new file mode 100644 index 00000000000..875a9825717 --- /dev/null +++ b/internal/generated/snippets/workflows/executions/apiv1/Client/ListExecutions/main.go @@ -0,0 +1,54 @@ +// 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 +// +// http://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 cloud.google.com/go/internal/gapicgen/gensnippets. DO NOT EDIT. + +// [START workflowexecutions_v1_generated_Executions_ListExecutions_sync] + +package main + +import ( + "context" + + executions "cloud.google.com/go/workflows/executions/apiv1" + "google.golang.org/api/iterator" + executionspb "google.golang.org/genproto/googleapis/cloud/workflows/executions/v1" +) + +func main() { + ctx := context.Background() + c, err := executions.NewClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &executionspb.ListExecutionsRequest{ + // TODO: Fill request struct fields. + } + it := c.ListExecutions(ctx, req) + for { + resp, err := it.Next() + if err == iterator.Done { + break + } + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp + } +} + +// [END workflowexecutions_v1_generated_Executions_ListExecutions_sync] diff --git a/internal/godocfx/go.mod b/internal/godocfx/go.mod index 4a36b56fe3c..63f394b4daf 100644 --- a/internal/godocfx/go.mod +++ b/internal/godocfx/go.mod @@ -8,8 +8,8 @@ require ( cloud.google.com/go/datastore v1.1.0 cloud.google.com/go/storage v1.11.0 github.com/google/go-cmp v0.5.6 - github.com/yuin/goldmark v1.3.8 - golang.org/x/tools v0.1.3 + github.com/yuin/goldmark v1.3.9 + golang.org/x/tools v0.1.4 gopkg.in/yaml.v2 v2.4.0 ) diff --git a/internal/godocfx/go.sum b/internal/godocfx/go.sum index c5bb7e54c2a..390cdff2ac3 100644 --- a/internal/godocfx/go.sum +++ b/internal/godocfx/go.sum @@ -100,8 +100,8 @@ github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9de github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= -github.com/yuin/goldmark v1.3.8 h1:Nw158Q8QN+CPgTmVRByhVwapp8Mm1e2blinhmx4wx5E= -github.com/yuin/goldmark v1.3.8/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= +github.com/yuin/goldmark v1.3.9 h1:XsVHmzm4P6g84IBbAj+WYMF/IEZ3J9+3I1wlqCNa/SQ= +github.com/yuin/goldmark v1.3.9/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU= go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8= go.opencensus.io v0.22.2/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= @@ -169,9 +169,9 @@ golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAG golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/oauth2 v0.0.0-20191202225959-858c2ad4c8b6/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= -golang.org/x/oauth2 v0.0.0-20210514164344-f6687ab2804c/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= -golang.org/x/oauth2 v0.0.0-20210615190721-d04028783cf1 h1:x622Z2o4hgCr/4CiKWc51jHVKaWdtVpBNmEI8wI9Qns= golang.org/x/oauth2 v0.0.0-20210615190721-d04028783cf1/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= +golang.org/x/oauth2 v0.0.0-20210628180205-a41e5a781914 h1:3B43BWw0xEBsLZ/NO1VALz6fppU3481pik+2Ksv45z8= +golang.org/x/oauth2 v0.0.0-20210628180205-a41e5a781914/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= @@ -206,8 +206,8 @@ golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20210603125802-9665404d3644 h1:CA1DEQ4NdKphKeL70tvsWNdT5oFh1lOjihRcEDROi0I= -golang.org/x/sys v0.0.0-20210603125802-9665404d3644/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20210616094352-59db8d763f22 h1:RqytpXGR1iVNX7psjB3ff8y7sNFinVFvkx1c8SjBkio= +golang.org/x/sys v0.0.0-20210616094352-59db8d763f22/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= @@ -245,9 +245,9 @@ golang.org/x/tools v0.0.0-20200618134242-20370b0cb4b2/go.mod h1:EkVYQZoAsY45+roY golang.org/x/tools v0.0.0-20200804011535-6c149bb5ef0d/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA= golang.org/x/tools v0.0.0-20200827163409-021d7c6f1ec3/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA= golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= -golang.org/x/tools v0.1.2/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= -golang.org/x/tools v0.1.3 h1:L69ShwSZEyCsLKoAxDKeMvLDZkumEe8gXUZAjab0tX8= golang.org/x/tools v0.1.3/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= +golang.org/x/tools v0.1.4 h1:cVngSRcfgyZCzys3KYOpCFa+4dqX/Oub9tAq00ttGVs= +golang.org/x/tools v0.1.4/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= @@ -265,8 +265,8 @@ google.golang.org/api v0.22.0/go.mod h1:BwFmGc8tA3vsd7r/7kR8DY7iEEGSU04BFxCo5jP/ google.golang.org/api v0.24.0/go.mod h1:lIXQywCXRcnZPGlsd8NbLnOjtAoL6em04bJ9+z0MncE= google.golang.org/api v0.28.0/go.mod h1:lIXQywCXRcnZPGlsd8NbLnOjtAoL6em04bJ9+z0MncE= google.golang.org/api v0.30.0/go.mod h1:QGmEvQ87FHZNiUVJkT14jQNYJ4ZJjdRF23ZXz5138Fc= -google.golang.org/api v0.48.0 h1:RDAPWfNFY06dffEXfn7hZF5Fr1ZbnChzfQZAPyBd1+I= -google.golang.org/api v0.48.0/go.mod h1:71Pr1vy+TAZRPkPs/xlCf5SsU8WjuAWv1Pfjbtukyy4= +google.golang.org/api v0.49.0 h1:gjIBDxlTG7vnzMmEnYwTnvLTF8Rjzo+ETCgEX1YZ/fY= +google.golang.org/api v0.49.0/go.mod h1:BECiH72wsfwUvOVn3+btPD5WHi0LzavZReBndi42L18= google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= google.golang.org/appengine v1.5.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= @@ -297,9 +297,9 @@ google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEY google.golang.org/genproto v0.0.0-20200618031413-b414f8b61790/go.mod h1:jDfRM7FcilCzHH/e9qn6dsT145K34l5v+OpcnNgKAAA= google.golang.org/genproto v0.0.0-20200804131852-c06518451d9c/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= google.golang.org/genproto v0.0.0-20200827165113-ac2560b5e952/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= -google.golang.org/genproto v0.0.0-20210604141403-392c879c8b08/go.mod h1:UODoCrxHCcBojKKwX1terBiRUaqAsFqJiF615XL43r0= -google.golang.org/genproto v0.0.0-20210617175327-b9e0b3197ced h1:c5geK1iMU3cDKtFrCVQIcjR3W+JOZMuhIyICMCTbtus= google.golang.org/genproto v0.0.0-20210617175327-b9e0b3197ced/go.mod h1:SzzZ/N+nwJDaO1kznhnlzqS8ocJICar6hYhVyhi++24= +google.golang.org/genproto v0.0.0-20210630183607-d20f26d13c79 h1:s1jFTXJryg4a1mew7xv03VZD8N9XjxFhk1o4Js4WvPQ= +google.golang.org/genproto v0.0.0-20210630183607-d20f26d13c79/go.mod h1:yiaVoXHpRzHGyxV3o4DktVWY4mSUErTKaeEOq6C3t3U= google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38= google.golang.org/grpc v1.21.1/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM= @@ -327,8 +327,9 @@ google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpAD google.golang.org/protobuf v1.24.0/go.mod h1:r/3tXBNzIEhYS9I1OUVjXDlt8tc493IdKGjtUeSXeh4= google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c= google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= -google.golang.org/protobuf v1.26.0 h1:bxAC2xTBsZGibn2RTntX0oH50xLsqy1OxA9tTL3p/lk= google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= +google.golang.org/protobuf v1.27.1 h1:SnqbnDw1V7RiZcXPx5MEeqPv2s79L9i7BJUlG/+RurQ= +google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= diff --git a/iot/apiv1/device_manager_client.go b/iot/apiv1/device_manager_client.go index 2d38b0e8c14..fe512496d00 100644 --- a/iot/apiv1/device_manager_client.go +++ b/iot/apiv1/device_manager_client.go @@ -23,7 +23,6 @@ import ( "net/url" "time" - "github.com/golang/protobuf/proto" gax "github.com/googleapis/gax-go/v2" "google.golang.org/api/iterator" "google.golang.org/api/option" @@ -34,6 +33,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newDeviceManagerClientHook clientHook @@ -67,6 +67,7 @@ func defaultDeviceManagerGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("cloudiot.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://cloudiot.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/iot/apiv1/doc.go b/iot/apiv1/doc.go index dc9fb05871b..bc1f04dd90b 100644 --- a/iot/apiv1/doc.go +++ b/iot/apiv1/doc.go @@ -49,7 +49,7 @@ import ( type clientHookParams struct{} type clientHook func(context.Context, clientHookParams) ([]option.ClientOption, error) -const versionClient = "20210612" +const versionClient = "20210701" func insertMetadata(ctx context.Context, mds ...metadata.MD) context.Context { out, _ := metadata.FromOutgoingContext(ctx) diff --git a/kms/apiv1/doc.go b/kms/apiv1/doc.go index 3df03db477b..a8d4ec31c4b 100644 --- a/kms/apiv1/doc.go +++ b/kms/apiv1/doc.go @@ -49,7 +49,7 @@ import ( type clientHookParams struct{} type clientHook func(context.Context, clientHookParams) ([]option.ClientOption, error) -const versionClient = "20210617" +const versionClient = "20210701" func insertMetadata(ctx context.Context, mds ...metadata.MD) context.Context { out, _ := metadata.FromOutgoingContext(ctx) diff --git a/kms/apiv1/key_management_client.go b/kms/apiv1/key_management_client.go index 9f4c7917a9e..9f25b6d6fca 100644 --- a/kms/apiv1/key_management_client.go +++ b/kms/apiv1/key_management_client.go @@ -23,7 +23,6 @@ import ( "net/url" "time" - "github.com/golang/protobuf/proto" gax "github.com/googleapis/gax-go/v2" "google.golang.org/api/iterator" "google.golang.org/api/option" @@ -34,6 +33,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newKeyManagementClientHook clientHook @@ -74,6 +74,7 @@ func defaultKeyManagementGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("cloudkms.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://cloudkms.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/language/apiv1/doc.go b/language/apiv1/doc.go index 84bf34b6755..5dc45017abd 100644 --- a/language/apiv1/doc.go +++ b/language/apiv1/doc.go @@ -50,7 +50,7 @@ import ( type clientHookParams struct{} type clientHook func(context.Context, clientHookParams) ([]option.ClientOption, error) -const versionClient = "20210612" +const versionClient = "20210701" func insertMetadata(ctx context.Context, mds ...metadata.MD) context.Context { out, _ := metadata.FromOutgoingContext(ctx) diff --git a/language/apiv1/language_client.go b/language/apiv1/language_client.go index 1eaca05eb5b..2ab47ab4259 100644 --- a/language/apiv1/language_client.go +++ b/language/apiv1/language_client.go @@ -49,6 +49,7 @@ func defaultGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("language.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://language.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/language/apiv1beta2/doc.go b/language/apiv1beta2/doc.go index 59062085934..c5464428fee 100644 --- a/language/apiv1beta2/doc.go +++ b/language/apiv1beta2/doc.go @@ -52,7 +52,7 @@ import ( type clientHookParams struct{} type clientHook func(context.Context, clientHookParams) ([]option.ClientOption, error) -const versionClient = "20210612" +const versionClient = "20210701" func insertMetadata(ctx context.Context, mds ...metadata.MD) context.Context { out, _ := metadata.FromOutgoingContext(ctx) diff --git a/language/apiv1beta2/language_client.go b/language/apiv1beta2/language_client.go index 4cec1c63fb1..2b6e0ae509c 100644 --- a/language/apiv1beta2/language_client.go +++ b/language/apiv1beta2/language_client.go @@ -49,6 +49,7 @@ func defaultGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("language.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://language.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/lifesciences/apiv2beta/doc.go b/lifesciences/apiv2beta/doc.go index 2daa57e8e23..ef3dbf75a8b 100644 --- a/lifesciences/apiv2beta/doc.go +++ b/lifesciences/apiv2beta/doc.go @@ -51,7 +51,7 @@ import ( type clientHookParams struct{} type clientHook func(context.Context, clientHookParams) ([]option.ClientOption, error) -const versionClient = "20210612" +const versionClient = "20210701" func insertMetadata(ctx context.Context, mds ...metadata.MD) context.Context { out, _ := metadata.FromOutgoingContext(ctx) diff --git a/lifesciences/apiv2beta/workflows_service_v2_beta_client.go b/lifesciences/apiv2beta/workflows_service_v2_beta_client.go index 1f4c81814a4..13dcac8ab09 100644 --- a/lifesciences/apiv2beta/workflows_service_v2_beta_client.go +++ b/lifesciences/apiv2beta/workflows_service_v2_beta_client.go @@ -48,6 +48,7 @@ func defaultWorkflowsServiceV2BetaGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("lifesciences.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://lifesciences.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/logging/apiv2/config_client.go b/logging/apiv2/config_client.go index 685f020f6ec..e6ff0a9a0d3 100644 --- a/logging/apiv2/config_client.go +++ b/logging/apiv2/config_client.go @@ -23,7 +23,6 @@ import ( "net/url" "time" - "github.com/golang/protobuf/proto" gax "github.com/googleapis/gax-go/v2" "google.golang.org/api/iterator" "google.golang.org/api/option" @@ -33,6 +32,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newConfigClientHook clientHook @@ -70,6 +70,7 @@ func defaultConfigGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("logging.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://logging.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/logging/apiv2/doc.go b/logging/apiv2/doc.go index 27245ed42c0..4958f8c808f 100644 --- a/logging/apiv2/doc.go +++ b/logging/apiv2/doc.go @@ -52,7 +52,7 @@ import ( type clientHookParams struct{} type clientHook func(context.Context, clientHookParams) ([]option.ClientOption, error) -const versionClient = "20210612" +const versionClient = "20210701" func insertMetadata(ctx context.Context, mds ...metadata.MD) context.Context { out, _ := metadata.FromOutgoingContext(ctx) diff --git a/logging/apiv2/logging_client.go b/logging/apiv2/logging_client.go index 4f3aa6224d6..42c529d019e 100644 --- a/logging/apiv2/logging_client.go +++ b/logging/apiv2/logging_client.go @@ -23,7 +23,6 @@ import ( "net/url" "time" - "github.com/golang/protobuf/proto" gax "github.com/googleapis/gax-go/v2" "google.golang.org/api/iterator" "google.golang.org/api/option" @@ -34,6 +33,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newClientHook clientHook @@ -54,6 +54,7 @@ func defaultGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("logging.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://logging.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/logging/apiv2/metrics_client.go b/logging/apiv2/metrics_client.go index df616772d59..0eb53c5bf7b 100644 --- a/logging/apiv2/metrics_client.go +++ b/logging/apiv2/metrics_client.go @@ -23,7 +23,6 @@ import ( "net/url" "time" - "github.com/golang/protobuf/proto" gax "github.com/googleapis/gax-go/v2" "google.golang.org/api/iterator" "google.golang.org/api/option" @@ -33,6 +32,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newMetricsClientHook clientHook @@ -52,6 +52,7 @@ func defaultMetricsGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("logging.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://logging.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/logging/go.mod b/logging/go.mod index 72b5a17cf39..b0f7fe80ff6 100644 --- a/logging/go.mod +++ b/logging/go.mod @@ -9,8 +9,9 @@ require ( github.com/google/go-cmp v0.5.6 github.com/googleapis/gax-go/v2 v2.0.5 go.opencensus.io v0.23.0 - golang.org/x/oauth2 v0.0.0-20210615190721-d04028783cf1 - google.golang.org/api v0.48.0 - google.golang.org/genproto v0.0.0-20210614143202-012ab6975634 + golang.org/x/oauth2 v0.0.0-20210628180205-a41e5a781914 + google.golang.org/api v0.50.0 + google.golang.org/genproto v0.0.0-20210701133433-6b8dcf568a95 google.golang.org/grpc v1.38.0 + google.golang.org/protobuf v1.27.1 ) diff --git a/logging/go.sum b/logging/go.sum index 3631c91394f..41ab982999f 100644 --- a/logging/go.sum +++ b/logging/go.sum @@ -253,8 +253,8 @@ golang.org/x/oauth2 v0.0.0-20210218202405-ba52d332ba99/go.mod h1:KelEdhl1UZF7XfJ golang.org/x/oauth2 v0.0.0-20210220000619-9bb904979d93/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= golang.org/x/oauth2 v0.0.0-20210313182246-cd4f82c27b84/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= golang.org/x/oauth2 v0.0.0-20210514164344-f6687ab2804c/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= -golang.org/x/oauth2 v0.0.0-20210615190721-d04028783cf1 h1:x622Z2o4hgCr/4CiKWc51jHVKaWdtVpBNmEI8wI9Qns= -golang.org/x/oauth2 v0.0.0-20210615190721-d04028783cf1/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= +golang.org/x/oauth2 v0.0.0-20210628180205-a41e5a781914 h1:3B43BWw0xEBsLZ/NO1VALz6fppU3481pik+2Ksv45z8= +golang.org/x/oauth2 v0.0.0-20210628180205-a41e5a781914/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= @@ -306,8 +306,9 @@ golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210514084401-e8d321eab015/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20210603125802-9665404d3644 h1:CA1DEQ4NdKphKeL70tvsWNdT5oFh1lOjihRcEDROi0I= golang.org/x/sys v0.0.0-20210603125802-9665404d3644/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20210616094352-59db8d763f22 h1:RqytpXGR1iVNX7psjB3ff8y7sNFinVFvkx1c8SjBkio= +golang.org/x/sys v0.0.0-20210616094352-59db8d763f22/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= @@ -369,8 +370,9 @@ golang.org/x/tools v0.0.0-20210105154028-b0ab187a4818/go.mod h1:emZCQorbCU4vsT4f golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0= golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.2/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= -golang.org/x/tools v0.1.3 h1:L69ShwSZEyCsLKoAxDKeMvLDZkumEe8gXUZAjab0tX8= golang.org/x/tools v0.1.3/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= +golang.org/x/tools v0.1.4 h1:cVngSRcfgyZCzys3KYOpCFa+4dqX/Oub9tAq00ttGVs= +golang.org/x/tools v0.1.4/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= @@ -398,8 +400,9 @@ google.golang.org/api v0.40.0/go.mod h1:fYKFpnQN0DsDSKRVRcQSDQNtqWPfM9i+zNPxepjR google.golang.org/api v0.41.0/go.mod h1:RkxM5lITDfTzmyKFPt+wGrCJbVfniCr2ool8kTBzRTU= google.golang.org/api v0.43.0/go.mod h1:nQsDGjRXMo4lvh5hP0TKqF244gqhGcr/YSIykhUk/94= google.golang.org/api v0.47.0/go.mod h1:Wbvgpq1HddcWVtzsVLyfLp8lDg6AA241LmgIL59tHXo= -google.golang.org/api v0.48.0 h1:RDAPWfNFY06dffEXfn7hZF5Fr1ZbnChzfQZAPyBd1+I= google.golang.org/api v0.48.0/go.mod h1:71Pr1vy+TAZRPkPs/xlCf5SsU8WjuAWv1Pfjbtukyy4= +google.golang.org/api v0.50.0 h1:LX7NFCFYOHzr7WHaYiRUpeipZe9o5L8T+2F4Z798VDw= +google.golang.org/api v0.50.0/go.mod h1:4bNT5pAuq5ji4SRZm+5QIkjny9JAyVD/3gaSihNefaw= google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= google.golang.org/appengine v1.5.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= @@ -451,8 +454,9 @@ google.golang.org/genproto v0.0.0-20210513213006-bf773b8c8384/go.mod h1:P3QM42oQ google.golang.org/genproto v0.0.0-20210602131652-f16073e35f0c/go.mod h1:UODoCrxHCcBojKKwX1terBiRUaqAsFqJiF615XL43r0= google.golang.org/genproto v0.0.0-20210604141403-392c879c8b08/go.mod h1:UODoCrxHCcBojKKwX1terBiRUaqAsFqJiF615XL43r0= google.golang.org/genproto v0.0.0-20210608205507-b6d2f5bf0d7d/go.mod h1:UODoCrxHCcBojKKwX1terBiRUaqAsFqJiF615XL43r0= -google.golang.org/genproto v0.0.0-20210614143202-012ab6975634 h1:LnkHrvncK4mYysgs+R1wPeMAILrmunf0Tzl0Li71pxo= -google.golang.org/genproto v0.0.0-20210614143202-012ab6975634/go.mod h1:SzzZ/N+nwJDaO1kznhnlzqS8ocJICar6hYhVyhi++24= +google.golang.org/genproto v0.0.0-20210624195500-8bfb893ecb84/go.mod h1:SzzZ/N+nwJDaO1kznhnlzqS8ocJICar6hYhVyhi++24= +google.golang.org/genproto v0.0.0-20210701133433-6b8dcf568a95 h1:xyRjacsGcaSoZ2fTcaLCSzh2JEceLLOT4X8k32Q0xAQ= +google.golang.org/genproto v0.0.0-20210701133433-6b8dcf568a95/go.mod h1:yiaVoXHpRzHGyxV3o4DktVWY4mSUErTKaeEOq6C3t3U= google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38= google.golang.org/grpc v1.21.1/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM= @@ -487,8 +491,9 @@ google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpAD google.golang.org/protobuf v1.24.0/go.mod h1:r/3tXBNzIEhYS9I1OUVjXDlt8tc493IdKGjtUeSXeh4= google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c= google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= -google.golang.org/protobuf v1.26.0 h1:bxAC2xTBsZGibn2RTntX0oH50xLsqy1OxA9tTL3p/lk= google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= +google.golang.org/protobuf v1.27.1 h1:SnqbnDw1V7RiZcXPx5MEeqPv2s79L9i7BJUlG/+RurQ= +google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= diff --git a/logging/logging.go b/logging/logging.go index d478ac0f060..6f990f26a14 100644 --- a/logging/logging.go +++ b/logging/logging.go @@ -75,7 +75,7 @@ const ( DefaultEntryCountThreshold = 1000 // DefaultEntryByteThreshold is the default value for the EntryByteThreshold LoggerOption. - DefaultEntryByteThreshold = 1 << 20 // 1MiB + DefaultEntryByteThreshold = 1 << 23 // 8MiB // DefaultBufferedByteLimit is the default value for the BufferedByteLimit LoggerOption. DefaultBufferedByteLimit = 1 << 30 // 1GiB diff --git a/longrunning/autogen/doc.go b/longrunning/autogen/doc.go index 2fbfa1d27b4..33bf0f3db74 100644 --- a/longrunning/autogen/doc.go +++ b/longrunning/autogen/doc.go @@ -48,7 +48,7 @@ import ( type clientHookParams struct{} type clientHook func(context.Context, clientHookParams) ([]option.ClientOption, error) -const versionClient = "20210612" +const versionClient = "20210701" func insertMetadata(ctx context.Context, mds ...metadata.MD) context.Context { out, _ := metadata.FromOutgoingContext(ctx) diff --git a/longrunning/autogen/operations_client.go b/longrunning/autogen/operations_client.go index 3fd6b76bf5c..4d96cbc08c3 100644 --- a/longrunning/autogen/operations_client.go +++ b/longrunning/autogen/operations_client.go @@ -23,7 +23,6 @@ import ( "net/url" "time" - "github.com/golang/protobuf/proto" gax "github.com/googleapis/gax-go/v2" "google.golang.org/api/iterator" "google.golang.org/api/option" @@ -33,6 +32,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newOperationsClientHook clientHook @@ -52,6 +52,7 @@ func defaultOperationsGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("longrunning.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://longrunning.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/managedidentities/apiv1/doc.go b/managedidentities/apiv1/doc.go index 8f7403bbc84..e9b40495836 100644 --- a/managedidentities/apiv1/doc.go +++ b/managedidentities/apiv1/doc.go @@ -50,7 +50,7 @@ import ( type clientHookParams struct{} type clientHook func(context.Context, clientHookParams) ([]option.ClientOption, error) -const versionClient = "20210612" +const versionClient = "20210701" func insertMetadata(ctx context.Context, mds ...metadata.MD) context.Context { out, _ := metadata.FromOutgoingContext(ctx) diff --git a/managedidentities/apiv1/managed_identities_client.go b/managedidentities/apiv1/managed_identities_client.go index e1919a6525a..6f9f83464f4 100644 --- a/managedidentities/apiv1/managed_identities_client.go +++ b/managedidentities/apiv1/managed_identities_client.go @@ -25,7 +25,6 @@ import ( "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" @@ -35,6 +34,7 @@ import ( longrunningpb "google.golang.org/genproto/googleapis/longrunning" "google.golang.org/grpc" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newClientHook clientHook @@ -59,6 +59,7 @@ func defaultGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("managedidentities.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://managedidentities.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/mediatranslation/apiv1beta1/doc.go b/mediatranslation/apiv1beta1/doc.go index 496d83daba4..80c2dfc4ec5 100644 --- a/mediatranslation/apiv1beta1/doc.go +++ b/mediatranslation/apiv1beta1/doc.go @@ -48,7 +48,7 @@ import ( type clientHookParams struct{} type clientHook func(context.Context, clientHookParams) ([]option.ClientOption, error) -const versionClient = "20210612" +const versionClient = "20210701" func insertMetadata(ctx context.Context, mds ...metadata.MD) context.Context { out, _ := metadata.FromOutgoingContext(ctx) diff --git a/mediatranslation/apiv1beta1/speech_translation_client.go b/mediatranslation/apiv1beta1/speech_translation_client.go index 22e27a76ebd..3108120637c 100644 --- a/mediatranslation/apiv1beta1/speech_translation_client.go +++ b/mediatranslation/apiv1beta1/speech_translation_client.go @@ -42,6 +42,7 @@ func defaultSpeechTranslationGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("mediatranslation.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://mediatranslation.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/memcache/apiv1/cloud_memcache_client.go b/memcache/apiv1/cloud_memcache_client.go index 0843235c94a..0980f443293 100644 --- a/memcache/apiv1/cloud_memcache_client.go +++ b/memcache/apiv1/cloud_memcache_client.go @@ -25,7 +25,6 @@ import ( "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" @@ -35,6 +34,7 @@ import ( longrunningpb "google.golang.org/genproto/googleapis/longrunning" "google.golang.org/grpc" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newCloudMemcacheClientHook clientHook @@ -56,6 +56,7 @@ func defaultCloudMemcacheGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("memcache.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://memcache.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/memcache/apiv1/doc.go b/memcache/apiv1/doc.go index 6ceb30b0d76..f891f3f3dd0 100644 --- a/memcache/apiv1/doc.go +++ b/memcache/apiv1/doc.go @@ -49,7 +49,7 @@ import ( type clientHookParams struct{} type clientHook func(context.Context, clientHookParams) ([]option.ClientOption, error) -const versionClient = "20210612" +const versionClient = "20210701" func insertMetadata(ctx context.Context, mds ...metadata.MD) context.Context { out, _ := metadata.FromOutgoingContext(ctx) diff --git a/memcache/apiv1beta2/cloud_memcache_client.go b/memcache/apiv1beta2/cloud_memcache_client.go index 7778682ddb0..02c60899004 100644 --- a/memcache/apiv1beta2/cloud_memcache_client.go +++ b/memcache/apiv1beta2/cloud_memcache_client.go @@ -25,7 +25,6 @@ import ( "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" @@ -35,6 +34,7 @@ import ( longrunningpb "google.golang.org/genproto/googleapis/longrunning" "google.golang.org/grpc" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newCloudMemcacheClientHook clientHook @@ -57,6 +57,7 @@ func defaultCloudMemcacheGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("memcache.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://memcache.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/memcache/apiv1beta2/doc.go b/memcache/apiv1beta2/doc.go index 04005be9126..da5a4241192 100644 --- a/memcache/apiv1beta2/doc.go +++ b/memcache/apiv1beta2/doc.go @@ -51,7 +51,7 @@ import ( type clientHookParams struct{} type clientHook func(context.Context, clientHookParams) ([]option.ClientOption, error) -const versionClient = "20210612" +const versionClient = "20210701" func insertMetadata(ctx context.Context, mds ...metadata.MD) context.Context { out, _ := metadata.FromOutgoingContext(ctx) diff --git a/metastore/apiv1/dataproc_metastore_client.go b/metastore/apiv1/dataproc_metastore_client.go index 69a6531f7f9..4563813e357 100644 --- a/metastore/apiv1/dataproc_metastore_client.go +++ b/metastore/apiv1/dataproc_metastore_client.go @@ -25,7 +25,6 @@ import ( "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" @@ -36,6 +35,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newDataprocMetastoreClientHook clientHook @@ -60,6 +60,7 @@ func defaultDataprocMetastoreGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("metastore.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://metastore.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/metastore/apiv1/doc.go b/metastore/apiv1/doc.go index 513aabcc507..cc4984a4ec6 100644 --- a/metastore/apiv1/doc.go +++ b/metastore/apiv1/doc.go @@ -20,8 +20,6 @@ // The Dataproc Metastore API is used to manage the lifecycle and // configuration of metastore services. // -// 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 @@ -51,7 +49,7 @@ import ( type clientHookParams struct{} type clientHook func(context.Context, clientHookParams) ([]option.ClientOption, error) -const versionClient = "20210612" +const versionClient = "20210701" func insertMetadata(ctx context.Context, mds ...metadata.MD) context.Context { out, _ := metadata.FromOutgoingContext(ctx) diff --git a/metastore/apiv1alpha/dataproc_metastore_client.go b/metastore/apiv1alpha/dataproc_metastore_client.go index 56b0147b99a..dd5d147d91f 100644 --- a/metastore/apiv1alpha/dataproc_metastore_client.go +++ b/metastore/apiv1alpha/dataproc_metastore_client.go @@ -25,7 +25,6 @@ import ( "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" @@ -36,6 +35,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newDataprocMetastoreClientHook clientHook @@ -65,6 +65,7 @@ func defaultDataprocMetastoreGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("metastore.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://metastore.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/metastore/apiv1alpha/doc.go b/metastore/apiv1alpha/doc.go index 52f579ac643..c7abcb3c484 100644 --- a/metastore/apiv1alpha/doc.go +++ b/metastore/apiv1alpha/doc.go @@ -51,7 +51,7 @@ import ( type clientHookParams struct{} type clientHook func(context.Context, clientHookParams) ([]option.ClientOption, error) -const versionClient = "20210612" +const versionClient = "20210701" func insertMetadata(ctx context.Context, mds ...metadata.MD) context.Context { out, _ := metadata.FromOutgoingContext(ctx) diff --git a/metastore/apiv1beta/dataproc_metastore_client.go b/metastore/apiv1beta/dataproc_metastore_client.go index 00098d7258d..f949c53524e 100644 --- a/metastore/apiv1beta/dataproc_metastore_client.go +++ b/metastore/apiv1beta/dataproc_metastore_client.go @@ -25,7 +25,6 @@ import ( "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" @@ -36,6 +35,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newDataprocMetastoreClientHook clientHook @@ -65,6 +65,7 @@ func defaultDataprocMetastoreGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("metastore.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://metastore.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/metastore/apiv1beta/doc.go b/metastore/apiv1beta/doc.go index c11cc59d0b9..2f95d1c0f45 100644 --- a/metastore/apiv1beta/doc.go +++ b/metastore/apiv1beta/doc.go @@ -51,7 +51,7 @@ import ( type clientHookParams struct{} type clientHook func(context.Context, clientHookParams) ([]option.ClientOption, error) -const versionClient = "20210612" +const versionClient = "20210701" func insertMetadata(ctx context.Context, mds ...metadata.MD) context.Context { out, _ := metadata.FromOutgoingContext(ctx) diff --git a/monitoring/apiv3/doc.go b/monitoring/apiv3/doc.go index 0cc49957692..1a6d259f5df 100644 --- a/monitoring/apiv3/doc.go +++ b/monitoring/apiv3/doc.go @@ -53,7 +53,7 @@ import ( type clientHookParams struct{} type clientHook func(context.Context, clientHookParams) ([]option.ClientOption, error) -const versionClient = "20210612" +const versionClient = "20210624" func insertMetadata(ctx context.Context, mds ...metadata.MD) context.Context { out, _ := metadata.FromOutgoingContext(ctx) diff --git a/monitoring/apiv3/v2/alert_policy_client.go b/monitoring/apiv3/v2/alert_policy_client.go index 1082d0edae0..e875fec123e 100644 --- a/monitoring/apiv3/v2/alert_policy_client.go +++ b/monitoring/apiv3/v2/alert_policy_client.go @@ -23,7 +23,6 @@ import ( "net/url" "time" - "github.com/golang/protobuf/proto" gax "github.com/googleapis/gax-go/v2" "google.golang.org/api/iterator" "google.golang.org/api/option" @@ -33,6 +32,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newAlertPolicyClientHook clientHook @@ -52,6 +52,7 @@ func defaultAlertPolicyGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("monitoring.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://monitoring.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/monitoring/apiv3/v2/doc.go b/monitoring/apiv3/v2/doc.go index 70f497d7dd7..e8f1d363d8d 100644 --- a/monitoring/apiv3/v2/doc.go +++ b/monitoring/apiv3/v2/doc.go @@ -53,7 +53,7 @@ import ( type clientHookParams struct{} type clientHook func(context.Context, clientHookParams) ([]option.ClientOption, error) -const versionClient = "20210612" +const versionClient = "20210701" func insertMetadata(ctx context.Context, mds ...metadata.MD) context.Context { out, _ := metadata.FromOutgoingContext(ctx) diff --git a/monitoring/apiv3/v2/group_client.go b/monitoring/apiv3/v2/group_client.go index 4c2e897dc26..29291c164c6 100644 --- a/monitoring/apiv3/v2/group_client.go +++ b/monitoring/apiv3/v2/group_client.go @@ -23,7 +23,6 @@ import ( "net/url" "time" - "github.com/golang/protobuf/proto" gax "github.com/googleapis/gax-go/v2" "google.golang.org/api/iterator" "google.golang.org/api/option" @@ -34,6 +33,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newGroupClientHook clientHook @@ -54,6 +54,7 @@ func defaultGroupGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("monitoring.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://monitoring.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/monitoring/apiv3/v2/metric_client.go b/monitoring/apiv3/v2/metric_client.go index 4220a46c043..59949cb7bfd 100644 --- a/monitoring/apiv3/v2/metric_client.go +++ b/monitoring/apiv3/v2/metric_client.go @@ -23,7 +23,6 @@ import ( "net/url" "time" - "github.com/golang/protobuf/proto" gax "github.com/googleapis/gax-go/v2" "google.golang.org/api/iterator" "google.golang.org/api/option" @@ -35,6 +34,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newMetricClientHook clientHook @@ -57,6 +57,7 @@ func defaultMetricGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("monitoring.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://monitoring.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/monitoring/apiv3/v2/notification_channel_client.go b/monitoring/apiv3/v2/notification_channel_client.go index f9bc9436619..a7d17a01105 100644 --- a/monitoring/apiv3/v2/notification_channel_client.go +++ b/monitoring/apiv3/v2/notification_channel_client.go @@ -23,7 +23,6 @@ import ( "net/url" "time" - "github.com/golang/protobuf/proto" gax "github.com/googleapis/gax-go/v2" "google.golang.org/api/iterator" "google.golang.org/api/option" @@ -33,6 +32,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newNotificationChannelClientHook clientHook @@ -57,6 +57,7 @@ func defaultNotificationChannelGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("monitoring.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://monitoring.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/monitoring/apiv3/v2/query_client.go b/monitoring/apiv3/v2/query_client.go index 9fceb1efb25..adef424e002 100644 --- a/monitoring/apiv3/v2/query_client.go +++ b/monitoring/apiv3/v2/query_client.go @@ -22,7 +22,6 @@ import ( "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" @@ -31,6 +30,7 @@ import ( monitoringpb "google.golang.org/genproto/googleapis/monitoring/v3" "google.golang.org/grpc" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newQueryClientHook clientHook @@ -46,6 +46,7 @@ func defaultQueryGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("monitoring.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://monitoring.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/monitoring/apiv3/v2/service_monitoring_client.go b/monitoring/apiv3/v2/service_monitoring_client.go index b8fcfade00d..84ad1a302f8 100644 --- a/monitoring/apiv3/v2/service_monitoring_client.go +++ b/monitoring/apiv3/v2/service_monitoring_client.go @@ -23,7 +23,6 @@ import ( "net/url" "time" - "github.com/golang/protobuf/proto" gax "github.com/googleapis/gax-go/v2" "google.golang.org/api/iterator" "google.golang.org/api/option" @@ -33,6 +32,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newServiceMonitoringClientHook clientHook @@ -57,6 +57,7 @@ func defaultServiceMonitoringGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("monitoring.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://monitoring.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/monitoring/apiv3/v2/uptime_check_client.go b/monitoring/apiv3/v2/uptime_check_client.go index 2bcff7dec4d..cb9591d708e 100644 --- a/monitoring/apiv3/v2/uptime_check_client.go +++ b/monitoring/apiv3/v2/uptime_check_client.go @@ -23,7 +23,6 @@ import ( "net/url" "time" - "github.com/golang/protobuf/proto" gax "github.com/googleapis/gax-go/v2" "google.golang.org/api/iterator" "google.golang.org/api/option" @@ -33,6 +32,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newUptimeCheckClientHook clientHook @@ -53,6 +53,7 @@ func defaultUptimeCheckGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("monitoring.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://monitoring.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/monitoring/dashboard/apiv1/dashboards_client.go b/monitoring/dashboard/apiv1/dashboards_client.go index 59ac8478ea2..3d0b2951c70 100644 --- a/monitoring/dashboard/apiv1/dashboards_client.go +++ b/monitoring/dashboard/apiv1/dashboards_client.go @@ -23,7 +23,6 @@ import ( "net/url" "time" - "github.com/golang/protobuf/proto" gax "github.com/googleapis/gax-go/v2" "google.golang.org/api/iterator" "google.golang.org/api/option" @@ -33,6 +32,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newDashboardsClientHook clientHook @@ -52,6 +52,7 @@ func defaultDashboardsGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("monitoring.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://monitoring.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/monitoring/dashboard/apiv1/doc.go b/monitoring/dashboard/apiv1/doc.go index 8e3e36e30b8..271cc826068 100644 --- a/monitoring/dashboard/apiv1/doc.go +++ b/monitoring/dashboard/apiv1/doc.go @@ -53,7 +53,7 @@ import ( type clientHookParams struct{} type clientHook func(context.Context, clientHookParams) ([]option.ClientOption, error) -const versionClient = "20210612" +const versionClient = "20210701" func insertMetadata(ctx context.Context, mds ...metadata.MD) context.Context { out, _ := metadata.FromOutgoingContext(ctx) diff --git a/networkconnectivity/apiv1alpha1/doc.go b/networkconnectivity/apiv1alpha1/doc.go index 574ca7aa093..f93d846129a 100644 --- a/networkconnectivity/apiv1alpha1/doc.go +++ b/networkconnectivity/apiv1alpha1/doc.go @@ -51,7 +51,7 @@ import ( type clientHookParams struct{} type clientHook func(context.Context, clientHookParams) ([]option.ClientOption, error) -const versionClient = "20210612" +const versionClient = "20210701" func insertMetadata(ctx context.Context, mds ...metadata.MD) context.Context { out, _ := metadata.FromOutgoingContext(ctx) diff --git a/networkconnectivity/apiv1alpha1/hub_client.go b/networkconnectivity/apiv1alpha1/hub_client.go index fe06cfa963d..21dda2292ef 100644 --- a/networkconnectivity/apiv1alpha1/hub_client.go +++ b/networkconnectivity/apiv1alpha1/hub_client.go @@ -25,7 +25,6 @@ import ( "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" @@ -36,6 +35,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newHubClientHook clientHook @@ -60,6 +60,7 @@ func defaultHubGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("networkconnectivity.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://networkconnectivity.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/notebooks/apiv1beta1/doc.go b/notebooks/apiv1beta1/doc.go index 81378add14d..2402a2cc469 100644 --- a/notebooks/apiv1beta1/doc.go +++ b/notebooks/apiv1beta1/doc.go @@ -51,7 +51,7 @@ import ( type clientHookParams struct{} type clientHook func(context.Context, clientHookParams) ([]option.ClientOption, error) -const versionClient = "20210612" +const versionClient = "20210701" func insertMetadata(ctx context.Context, mds ...metadata.MD) context.Context { out, _ := metadata.FromOutgoingContext(ctx) diff --git a/notebooks/apiv1beta1/notebook_client.go b/notebooks/apiv1beta1/notebook_client.go index 1208d7ab60c..dd8dc76fd89 100644 --- a/notebooks/apiv1beta1/notebook_client.go +++ b/notebooks/apiv1beta1/notebook_client.go @@ -25,7 +25,6 @@ import ( "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" @@ -35,6 +34,7 @@ import ( longrunningpb "google.golang.org/genproto/googleapis/longrunning" "google.golang.org/grpc" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newNotebookClientHook clientHook @@ -68,6 +68,7 @@ func defaultNotebookGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("notebooks.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://notebooks.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/orgpolicy/apiv2/doc.go b/orgpolicy/apiv2/doc.go index 9d0a474f0fc..1bfd1d41b86 100644 --- a/orgpolicy/apiv2/doc.go +++ b/orgpolicy/apiv2/doc.go @@ -49,7 +49,7 @@ import ( type clientHookParams struct{} type clientHook func(context.Context, clientHookParams) ([]option.ClientOption, error) -const versionClient = "20210612" +const versionClient = "20210701" func insertMetadata(ctx context.Context, mds ...metadata.MD) context.Context { out, _ := metadata.FromOutgoingContext(ctx) diff --git a/orgpolicy/apiv2/org_policy_client.go b/orgpolicy/apiv2/org_policy_client.go index 3a9368d5eab..d61e2ff57dd 100644 --- a/orgpolicy/apiv2/org_policy_client.go +++ b/orgpolicy/apiv2/org_policy_client.go @@ -23,7 +23,6 @@ import ( "net/url" "time" - "github.com/golang/protobuf/proto" gax "github.com/googleapis/gax-go/v2" "google.golang.org/api/iterator" "google.golang.org/api/option" @@ -33,6 +32,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newClientHook clientHook @@ -54,6 +54,7 @@ func defaultGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("orgpolicy.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://orgpolicy.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/osconfig/agentendpoint/apiv1/agent_endpoint_client.go b/osconfig/agentendpoint/apiv1/agent_endpoint_client.go index 90e9fdbb100..ec28aef02c5 100644 --- a/osconfig/agentendpoint/apiv1/agent_endpoint_client.go +++ b/osconfig/agentendpoint/apiv1/agent_endpoint_client.go @@ -49,6 +49,7 @@ func defaultGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("osconfig.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://osconfig.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/osconfig/agentendpoint/apiv1/doc.go b/osconfig/agentendpoint/apiv1/doc.go index 5ce173a2fe6..685cb443fdc 100644 --- a/osconfig/agentendpoint/apiv1/doc.go +++ b/osconfig/agentendpoint/apiv1/doc.go @@ -49,7 +49,7 @@ import ( type clientHookParams struct{} type clientHook func(context.Context, clientHookParams) ([]option.ClientOption, error) -const versionClient = "20210612" +const versionClient = "20210701" func insertMetadata(ctx context.Context, mds ...metadata.MD) context.Context { out, _ := metadata.FromOutgoingContext(ctx) diff --git a/osconfig/agentendpoint/apiv1beta/agent_endpoint_client.go b/osconfig/agentendpoint/apiv1beta/agent_endpoint_client.go index f66140bac7e..67a079bc9fb 100644 --- a/osconfig/agentendpoint/apiv1beta/agent_endpoint_client.go +++ b/osconfig/agentendpoint/apiv1beta/agent_endpoint_client.go @@ -49,6 +49,7 @@ func defaultGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("osconfig.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://osconfig.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/osconfig/agentendpoint/apiv1beta/doc.go b/osconfig/agentendpoint/apiv1beta/doc.go index 14bb88927af..1a76b52d9ad 100644 --- a/osconfig/agentendpoint/apiv1beta/doc.go +++ b/osconfig/agentendpoint/apiv1beta/doc.go @@ -51,7 +51,7 @@ import ( type clientHookParams struct{} type clientHook func(context.Context, clientHookParams) ([]option.ClientOption, error) -const versionClient = "20210612" +const versionClient = "20210701" func insertMetadata(ctx context.Context, mds ...metadata.MD) context.Context { out, _ := metadata.FromOutgoingContext(ctx) diff --git a/osconfig/apiv1/doc.go b/osconfig/apiv1/doc.go index 27d82dd045c..11d02031618 100644 --- a/osconfig/apiv1/doc.go +++ b/osconfig/apiv1/doc.go @@ -49,7 +49,7 @@ import ( type clientHookParams struct{} type clientHook func(context.Context, clientHookParams) ([]option.ClientOption, error) -const versionClient = "20210612" +const versionClient = "20210701" func insertMetadata(ctx context.Context, mds ...metadata.MD) context.Context { out, _ := metadata.FromOutgoingContext(ctx) diff --git a/osconfig/apiv1/os_config_client.go b/osconfig/apiv1/os_config_client.go index 30729927a4d..3da4c4e7d24 100644 --- a/osconfig/apiv1/os_config_client.go +++ b/osconfig/apiv1/os_config_client.go @@ -23,7 +23,6 @@ import ( "net/url" "time" - "github.com/golang/protobuf/proto" gax "github.com/googleapis/gax-go/v2" "google.golang.org/api/iterator" "google.golang.org/api/option" @@ -33,6 +32,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newClientHook clientHook @@ -56,6 +56,7 @@ func defaultGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("osconfig.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://osconfig.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/osconfig/apiv1alpha/doc.go b/osconfig/apiv1alpha/doc.go index 06161c49883..4712c64c232 100644 --- a/osconfig/apiv1alpha/doc.go +++ b/osconfig/apiv1alpha/doc.go @@ -51,7 +51,7 @@ import ( type clientHookParams struct{} type clientHook func(context.Context, clientHookParams) ([]option.ClientOption, error) -const versionClient = "20210612" +const versionClient = "20210701" func insertMetadata(ctx context.Context, mds ...metadata.MD) context.Context { out, _ := metadata.FromOutgoingContext(ctx) diff --git a/osconfig/apiv1alpha/os_config_zonal_client.go b/osconfig/apiv1alpha/os_config_zonal_client.go index 1d20992ee28..05cd54e5c0f 100644 --- a/osconfig/apiv1alpha/os_config_zonal_client.go +++ b/osconfig/apiv1alpha/os_config_zonal_client.go @@ -25,7 +25,6 @@ import ( "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" @@ -36,6 +35,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newOsConfigZonalClientHook clientHook @@ -62,6 +62,7 @@ func defaultOsConfigZonalGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("osconfig.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://osconfig.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/osconfig/apiv1beta/doc.go b/osconfig/apiv1beta/doc.go index fc3b4047975..2d0e46f1003 100644 --- a/osconfig/apiv1beta/doc.go +++ b/osconfig/apiv1beta/doc.go @@ -51,7 +51,7 @@ import ( type clientHookParams struct{} type clientHook func(context.Context, clientHookParams) ([]option.ClientOption, error) -const versionClient = "20210612" +const versionClient = "20210701" func insertMetadata(ctx context.Context, mds ...metadata.MD) context.Context { out, _ := metadata.FromOutgoingContext(ctx) diff --git a/osconfig/apiv1beta/os_config_client.go b/osconfig/apiv1beta/os_config_client.go index ce907ff9c6b..eed122d4b10 100644 --- a/osconfig/apiv1beta/os_config_client.go +++ b/osconfig/apiv1beta/os_config_client.go @@ -23,7 +23,6 @@ import ( "net/url" "time" - "github.com/golang/protobuf/proto" gax "github.com/googleapis/gax-go/v2" "google.golang.org/api/iterator" "google.golang.org/api/option" @@ -33,6 +32,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newClientHook clientHook @@ -62,6 +62,7 @@ func defaultGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("osconfig.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://osconfig.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/oslogin/apiv1/doc.go b/oslogin/apiv1/doc.go index f5cdb1f29ff..b238bbcfc96 100644 --- a/oslogin/apiv1/doc.go +++ b/oslogin/apiv1/doc.go @@ -49,7 +49,7 @@ import ( type clientHookParams struct{} type clientHook func(context.Context, clientHookParams) ([]option.ClientOption, error) -const versionClient = "20210612" +const versionClient = "20210701" func insertMetadata(ctx context.Context, mds ...metadata.MD) context.Context { out, _ := metadata.FromOutgoingContext(ctx) diff --git a/oslogin/apiv1/os_login_client.go b/oslogin/apiv1/os_login_client.go index 1594af36ba0..7c8b2581864 100644 --- a/oslogin/apiv1/os_login_client.go +++ b/oslogin/apiv1/os_login_client.go @@ -52,6 +52,7 @@ func defaultGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("oslogin.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://oslogin.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/oslogin/apiv1beta/doc.go b/oslogin/apiv1beta/doc.go index 2f260a64f78..8d1df6e5073 100644 --- a/oslogin/apiv1beta/doc.go +++ b/oslogin/apiv1beta/doc.go @@ -51,7 +51,7 @@ import ( type clientHookParams struct{} type clientHook func(context.Context, clientHookParams) ([]option.ClientOption, error) -const versionClient = "20210612" +const versionClient = "20210701" func insertMetadata(ctx context.Context, mds ...metadata.MD) context.Context { out, _ := metadata.FromOutgoingContext(ctx) diff --git a/oslogin/apiv1beta/os_login_client.go b/oslogin/apiv1beta/os_login_client.go index 8e63d4706a8..3bc85d090bf 100644 --- a/oslogin/apiv1beta/os_login_client.go +++ b/oslogin/apiv1beta/os_login_client.go @@ -52,6 +52,7 @@ func defaultGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("oslogin.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://oslogin.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/phishingprotection/apiv1beta1/doc.go b/phishingprotection/apiv1beta1/doc.go index 6189411b9a4..9de824a3ff4 100644 --- a/phishingprotection/apiv1beta1/doc.go +++ b/phishingprotection/apiv1beta1/doc.go @@ -48,7 +48,7 @@ import ( type clientHookParams struct{} type clientHook func(context.Context, clientHookParams) ([]option.ClientOption, error) -const versionClient = "20210612" +const versionClient = "20210701" func insertMetadata(ctx context.Context, mds ...metadata.MD) context.Context { out, _ := metadata.FromOutgoingContext(ctx) diff --git a/phishingprotection/apiv1beta1/phishing_protection_service_v1_beta1_client.go b/phishingprotection/apiv1beta1/phishing_protection_service_v1_beta1_client.go index 64943acc500..70769c204d2 100644 --- a/phishingprotection/apiv1beta1/phishing_protection_service_v1_beta1_client.go +++ b/phishingprotection/apiv1beta1/phishing_protection_service_v1_beta1_client.go @@ -45,6 +45,7 @@ func defaultPhishingProtectionServiceV1Beta1GRPCClientOptions() []option.ClientO internaloption.WithDefaultMTLSEndpoint("phishingprotection.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://phishingprotection.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/policytroubleshooter/apiv1/doc.go b/policytroubleshooter/apiv1/doc.go index b3646e405d8..41b2bbaf26f 100644 --- a/policytroubleshooter/apiv1/doc.go +++ b/policytroubleshooter/apiv1/doc.go @@ -46,7 +46,7 @@ import ( type clientHookParams struct{} type clientHook func(context.Context, clientHookParams) ([]option.ClientOption, error) -const versionClient = "20210612" +const versionClient = "20210701" func insertMetadata(ctx context.Context, mds ...metadata.MD) context.Context { out, _ := metadata.FromOutgoingContext(ctx) diff --git a/policytroubleshooter/apiv1/iam_checker_client.go b/policytroubleshooter/apiv1/iam_checker_client.go index 47dcd1c9bb2..e7286bb16e9 100644 --- a/policytroubleshooter/apiv1/iam_checker_client.go +++ b/policytroubleshooter/apiv1/iam_checker_client.go @@ -43,6 +43,7 @@ func defaultIamCheckerGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("policytroubleshooter.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://policytroubleshooter.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/privatecatalog/apiv1beta1/doc.go b/privatecatalog/apiv1beta1/doc.go index 3297377305f..59b32641b76 100644 --- a/privatecatalog/apiv1beta1/doc.go +++ b/privatecatalog/apiv1beta1/doc.go @@ -51,7 +51,7 @@ import ( type clientHookParams struct{} type clientHook func(context.Context, clientHookParams) ([]option.ClientOption, error) -const versionClient = "20210612" +const versionClient = "20210701" func insertMetadata(ctx context.Context, mds ...metadata.MD) context.Context { out, _ := metadata.FromOutgoingContext(ctx) diff --git a/privatecatalog/apiv1beta1/private_catalog_client.go b/privatecatalog/apiv1beta1/private_catalog_client.go index 2f848409fcb..858e0a2a12a 100644 --- a/privatecatalog/apiv1beta1/private_catalog_client.go +++ b/privatecatalog/apiv1beta1/private_catalog_client.go @@ -22,7 +22,6 @@ import ( "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" @@ -31,6 +30,7 @@ import ( privatecatalogpb "google.golang.org/genproto/googleapis/cloud/privatecatalog/v1beta1" "google.golang.org/grpc" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newClientHook clientHook @@ -48,6 +48,7 @@ func defaultGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("cloudprivatecatalog.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://cloudprivatecatalog.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/pubsub/CHANGES.md b/pubsub/CHANGES.md index a625eaa0fcf..6cfb5e026ef 100644 --- a/pubsub/CHANGES.md +++ b/pubsub/CHANGES.md @@ -1,5 +1,24 @@ # Changes +### [1.12.1](https://www.github.com/googleapis/google-cloud-go/compare/pubsub/v1.12.0...pubsub/v1.12.1) (2021-07-01) + + +### Bug Fixes + +* **pubsub:** retry GOAWAY errors ([#4313](https://www.github.com/googleapis/google-cloud-go/issues/4313)) ([7076fef](https://www.github.com/googleapis/google-cloud-go/commit/7076fef5fef81cce47dbfbab3d7257cc7d3776bc)) + +## [1.12.0](https://www.github.com/googleapis/google-cloud-go/compare/pubsub/v1.11.0...pubsub/v1.12.0) (2021-06-23) + + +### Features + +* **pubsub/pstest:** add channel to support user-defined publish responses ([#4251](https://www.github.com/googleapis/google-cloud-go/issues/4251)) ([e1304f4](https://www.github.com/googleapis/google-cloud-go/commit/e1304f435fed4a767f4a652f32f1386979ff794f)) + + +### Bug Fixes + +* **pubsub:** fix memory leak issue in publish scheduler ([#4282](https://www.github.com/googleapis/google-cloud-go/issues/4282)) ([22ffc18](https://www.github.com/googleapis/google-cloud-go/commit/22ffc18e522c0f943db57f8c943e7356067bedfd)) + ## [1.11.0](https://www.github.com/googleapis/google-cloud-go/compare/pubsub/v1.10.3...pubsub/v1.11.0) (2021-05-27) diff --git a/pubsub/apiv1/doc.go b/pubsub/apiv1/doc.go index 8e3353b7e64..d415a1724df 100644 --- a/pubsub/apiv1/doc.go +++ b/pubsub/apiv1/doc.go @@ -49,7 +49,7 @@ import ( type clientHookParams struct{} type clientHook func(context.Context, clientHookParams) ([]option.ClientOption, error) -const versionClient = "20210612" +const versionClient = "20210701" func insertMetadata(ctx context.Context, mds ...metadata.MD) context.Context { out, _ := metadata.FromOutgoingContext(ctx) diff --git a/pubsub/apiv1/publisher_client.go b/pubsub/apiv1/publisher_client.go index 8eb7a8cc6ce..c91def3a905 100644 --- a/pubsub/apiv1/publisher_client.go +++ b/pubsub/apiv1/publisher_client.go @@ -23,7 +23,6 @@ import ( "net/url" "time" - "github.com/golang/protobuf/proto" gax "github.com/googleapis/gax-go/v2" "google.golang.org/api/iterator" "google.golang.org/api/option" @@ -34,6 +33,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newPublisherClientHook clientHook @@ -60,6 +60,7 @@ func defaultPublisherGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("pubsub.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://pubsub.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/pubsub/apiv1/schema_client.go b/pubsub/apiv1/schema_client.go index cc77f14ff8b..7d9774ef3f3 100644 --- a/pubsub/apiv1/schema_client.go +++ b/pubsub/apiv1/schema_client.go @@ -22,7 +22,6 @@ import ( "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" @@ -32,6 +31,7 @@ import ( pubsubpb "google.golang.org/genproto/googleapis/pubsub/v1" "google.golang.org/grpc" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newSchemaClientHook clientHook @@ -55,6 +55,7 @@ func defaultSchemaGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("pubsub.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://pubsub.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/pubsub/apiv1/subscriber_client.go b/pubsub/apiv1/subscriber_client.go index 136462f4772..eb78a4d41e8 100644 --- a/pubsub/apiv1/subscriber_client.go +++ b/pubsub/apiv1/subscriber_client.go @@ -23,7 +23,6 @@ import ( "net/url" "time" - "github.com/golang/protobuf/proto" gax "github.com/googleapis/gax-go/v2" "google.golang.org/api/iterator" "google.golang.org/api/option" @@ -34,6 +33,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newSubscriberClientHook clientHook @@ -67,6 +67,7 @@ func defaultSubscriberGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("pubsub.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://pubsub.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/pubsub/go.mod b/pubsub/go.mod index da99e396ca0..c9853a19eae 100644 --- a/pubsub/go.mod +++ b/pubsub/go.mod @@ -8,11 +8,11 @@ require ( github.com/google/go-cmp v0.5.6 github.com/googleapis/gax-go/v2 v2.0.5 go.opencensus.io v0.23.0 - golang.org/x/oauth2 v0.0.0-20210615190721-d04028783cf1 + golang.org/x/oauth2 v0.0.0-20210628180205-a41e5a781914 golang.org/x/sync v0.0.0-20210220032951-036812b2e83c golang.org/x/time v0.0.0-20210611083556-38a9dc6acbc6 - google.golang.org/api v0.48.0 - google.golang.org/genproto v0.0.0-20210614143202-012ab6975634 + google.golang.org/api v0.50.0 + google.golang.org/genproto v0.0.0-20210701133433-6b8dcf568a95 google.golang.org/grpc v1.38.0 - google.golang.org/protobuf v1.26.0 + google.golang.org/protobuf v1.27.1 ) diff --git a/pubsub/go.sum b/pubsub/go.sum index 0d513311ab2..424a7ba5550 100644 --- a/pubsub/go.sum +++ b/pubsub/go.sum @@ -249,8 +249,8 @@ golang.org/x/oauth2 v0.0.0-20210218202405-ba52d332ba99/go.mod h1:KelEdhl1UZF7XfJ golang.org/x/oauth2 v0.0.0-20210220000619-9bb904979d93/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= golang.org/x/oauth2 v0.0.0-20210313182246-cd4f82c27b84/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= golang.org/x/oauth2 v0.0.0-20210514164344-f6687ab2804c/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= -golang.org/x/oauth2 v0.0.0-20210615190721-d04028783cf1 h1:x622Z2o4hgCr/4CiKWc51jHVKaWdtVpBNmEI8wI9Qns= -golang.org/x/oauth2 v0.0.0-20210615190721-d04028783cf1/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= +golang.org/x/oauth2 v0.0.0-20210628180205-a41e5a781914 h1:3B43BWw0xEBsLZ/NO1VALz6fppU3481pik+2Ksv45z8= +golang.org/x/oauth2 v0.0.0-20210628180205-a41e5a781914/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= @@ -302,8 +302,9 @@ golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210514084401-e8d321eab015/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20210603125802-9665404d3644 h1:CA1DEQ4NdKphKeL70tvsWNdT5oFh1lOjihRcEDROi0I= golang.org/x/sys v0.0.0-20210603125802-9665404d3644/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20210616094352-59db8d763f22 h1:RqytpXGR1iVNX7psjB3ff8y7sNFinVFvkx1c8SjBkio= +golang.org/x/sys v0.0.0-20210616094352-59db8d763f22/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= @@ -367,8 +368,9 @@ golang.org/x/tools v0.0.0-20210105154028-b0ab187a4818/go.mod h1:emZCQorbCU4vsT4f golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0= golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.2/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= -golang.org/x/tools v0.1.3 h1:L69ShwSZEyCsLKoAxDKeMvLDZkumEe8gXUZAjab0tX8= golang.org/x/tools v0.1.3/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= +golang.org/x/tools v0.1.4 h1:cVngSRcfgyZCzys3KYOpCFa+4dqX/Oub9tAq00ttGVs= +golang.org/x/tools v0.1.4/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= @@ -396,8 +398,9 @@ google.golang.org/api v0.40.0/go.mod h1:fYKFpnQN0DsDSKRVRcQSDQNtqWPfM9i+zNPxepjR google.golang.org/api v0.41.0/go.mod h1:RkxM5lITDfTzmyKFPt+wGrCJbVfniCr2ool8kTBzRTU= google.golang.org/api v0.43.0/go.mod h1:nQsDGjRXMo4lvh5hP0TKqF244gqhGcr/YSIykhUk/94= google.golang.org/api v0.47.0/go.mod h1:Wbvgpq1HddcWVtzsVLyfLp8lDg6AA241LmgIL59tHXo= -google.golang.org/api v0.48.0 h1:RDAPWfNFY06dffEXfn7hZF5Fr1ZbnChzfQZAPyBd1+I= google.golang.org/api v0.48.0/go.mod h1:71Pr1vy+TAZRPkPs/xlCf5SsU8WjuAWv1Pfjbtukyy4= +google.golang.org/api v0.50.0 h1:LX7NFCFYOHzr7WHaYiRUpeipZe9o5L8T+2F4Z798VDw= +google.golang.org/api v0.50.0/go.mod h1:4bNT5pAuq5ji4SRZm+5QIkjny9JAyVD/3gaSihNefaw= google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= google.golang.org/appengine v1.5.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= @@ -449,8 +452,9 @@ google.golang.org/genproto v0.0.0-20210513213006-bf773b8c8384/go.mod h1:P3QM42oQ google.golang.org/genproto v0.0.0-20210602131652-f16073e35f0c/go.mod h1:UODoCrxHCcBojKKwX1terBiRUaqAsFqJiF615XL43r0= google.golang.org/genproto v0.0.0-20210604141403-392c879c8b08/go.mod h1:UODoCrxHCcBojKKwX1terBiRUaqAsFqJiF615XL43r0= google.golang.org/genproto v0.0.0-20210608205507-b6d2f5bf0d7d/go.mod h1:UODoCrxHCcBojKKwX1terBiRUaqAsFqJiF615XL43r0= -google.golang.org/genproto v0.0.0-20210614143202-012ab6975634 h1:LnkHrvncK4mYysgs+R1wPeMAILrmunf0Tzl0Li71pxo= -google.golang.org/genproto v0.0.0-20210614143202-012ab6975634/go.mod h1:SzzZ/N+nwJDaO1kznhnlzqS8ocJICar6hYhVyhi++24= +google.golang.org/genproto v0.0.0-20210624195500-8bfb893ecb84/go.mod h1:SzzZ/N+nwJDaO1kznhnlzqS8ocJICar6hYhVyhi++24= +google.golang.org/genproto v0.0.0-20210701133433-6b8dcf568a95 h1:xyRjacsGcaSoZ2fTcaLCSzh2JEceLLOT4X8k32Q0xAQ= +google.golang.org/genproto v0.0.0-20210701133433-6b8dcf568a95/go.mod h1:yiaVoXHpRzHGyxV3o4DktVWY4mSUErTKaeEOq6C3t3U= google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38= google.golang.org/grpc v1.21.1/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM= @@ -485,8 +489,9 @@ google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpAD google.golang.org/protobuf v1.24.0/go.mod h1:r/3tXBNzIEhYS9I1OUVjXDlt8tc493IdKGjtUeSXeh4= google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c= google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= -google.golang.org/protobuf v1.26.0 h1:bxAC2xTBsZGibn2RTntX0oH50xLsqy1OxA9tTL3p/lk= google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= +google.golang.org/protobuf v1.27.1 h1:SnqbnDw1V7RiZcXPx5MEeqPv2s79L9i7BJUlG/+RurQ= +google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= diff --git a/pubsub/service.go b/pubsub/service.go index d9a00021eb0..0c24be25a69 100644 --- a/pubsub/service.go +++ b/pubsub/service.go @@ -62,6 +62,14 @@ func (r *defaultRetryer) Retry(err error) (pause time.Duration, shouldRetry bool return r.bo.Pause(), true } return 0, false + case codes.Unknown: + // Retry GOAWAY, see https://github.com/googleapis/google-cloud-go/issues/4257. + isGoaway := strings.Contains(s.Message(), "error reading from server: EOF") && + strings.Contains(s.Message(), "received prior goaway") + if isGoaway { + return r.bo.Pause(), true + } + return 0, false default: return 0, false } diff --git a/pubsublite/CHANGES.md b/pubsublite/CHANGES.md index 1e8ca888e3a..e66499929ca 100644 --- a/pubsublite/CHANGES.md +++ b/pubsublite/CHANGES.md @@ -1,5 +1,13 @@ # Changes +### [0.10.2](https://www.github.com/googleapis/google-cloud-go/compare/pubsublite/v0.10.1...pubsublite/v0.10.2) (2021-06-29) + + +### Bug Fixes + +* **pubsublite:** ensure timeout settings are respected ([#4329](https://www.github.com/googleapis/google-cloud-go/issues/4329)) ([e75262c](https://www.github.com/googleapis/google-cloud-go/commit/e75262cf5eba845271965eab3c28c0a23bec14c4)) +* **pubsublite:** wire user context to api clients ([#4318](https://www.github.com/googleapis/google-cloud-go/issues/4318)) ([ae34396](https://www.github.com/googleapis/google-cloud-go/commit/ae34396b1a2a970a0d871cd5496527294f3310d4)) + ### [0.10.1](https://www.github.com/googleapis/google-cloud-go/compare/pubsublite/v0.10.0...pubsublite/v0.10.1) (2021-06-22) diff --git a/pubsublite/admin.go b/pubsublite/admin.go index 5cd00800490..ec83aff3778 100644 --- a/pubsublite/admin.go +++ b/pubsublite/admin.go @@ -165,14 +165,14 @@ type createSubscriptionSettings struct { // CreateSubscriptionOption is an option for AdminClient.CreateSubscription. type CreateSubscriptionOption interface { - Apply(*createSubscriptionSettings) + apply(*createSubscriptionSettings) } type startingOffset struct { backlogLocation BacklogLocation } -func (so startingOffset) Apply(settings *createSubscriptionSettings) { +func (so startingOffset) apply(settings *createSubscriptionSettings) { settings.backlogLocation = so.backlogLocation } @@ -190,7 +190,7 @@ func StartingOffset(location BacklogLocation) CreateSubscriptionOption { func (ac *AdminClient) CreateSubscription(ctx context.Context, config SubscriptionConfig, opts ...CreateSubscriptionOption) (*SubscriptionConfig, error) { var settings createSubscriptionSettings for _, opt := range opts { - opt.Apply(&settings) + opt.apply(&settings) } subsPath, err := wire.ParseSubscriptionPath(config.Name) diff --git a/pubsublite/apiv1/admin_client.go b/pubsublite/apiv1/admin_client.go index 81339cdfd02..c4097fdcd54 100644 --- a/pubsublite/apiv1/admin_client.go +++ b/pubsublite/apiv1/admin_client.go @@ -23,16 +23,19 @@ import ( "net/url" "time" - "github.com/golang/protobuf/proto" + "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" pubsublitepb "google.golang.org/genproto/googleapis/cloud/pubsublite/v1" + longrunningpb "google.golang.org/genproto/googleapis/longrunning" "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newAdminClientHook clientHook @@ -51,6 +54,7 @@ type AdminCallOptions struct { ListSubscriptions []gax.CallOption UpdateSubscription []gax.CallOption DeleteSubscription []gax.CallOption + SeekSubscription []gax.CallOption CreateReservation []gax.CallOption GetReservation []gax.CallOption ListReservations []gax.CallOption @@ -65,6 +69,7 @@ func defaultAdminGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("pubsublite.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://pubsublite.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), @@ -253,6 +258,21 @@ func defaultAdminCallOptions() *AdminCallOptions { }) }), }, + SeekSubscription: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.DeadlineExceeded, + codes.Unavailable, + codes.Aborted, + codes.Internal, + codes.Unknown, + }, gax.Backoff{ + Initial: 100 * time.Millisecond, + Max: 60000 * time.Millisecond, + Multiplier: 1.30, + }) + }), + }, CreateReservation: []gax.CallOption{ gax.WithRetry(func() gax.Retryer { return gax.OnCodes([]codes.Code{ @@ -363,6 +383,8 @@ type internalAdminClient interface { ListSubscriptions(context.Context, *pubsublitepb.ListSubscriptionsRequest, ...gax.CallOption) *SubscriptionIterator UpdateSubscription(context.Context, *pubsublitepb.UpdateSubscriptionRequest, ...gax.CallOption) (*pubsublitepb.Subscription, error) DeleteSubscription(context.Context, *pubsublitepb.DeleteSubscriptionRequest, ...gax.CallOption) error + SeekSubscription(context.Context, *pubsublitepb.SeekSubscriptionRequest, ...gax.CallOption) (*SeekSubscriptionOperation, error) + SeekSubscriptionOperation(name string) *SeekSubscriptionOperation CreateReservation(context.Context, *pubsublitepb.CreateReservationRequest, ...gax.CallOption) (*pubsublitepb.Reservation, error) GetReservation(context.Context, *pubsublitepb.GetReservationRequest, ...gax.CallOption) (*pubsublitepb.Reservation, error) ListReservations(context.Context, *pubsublitepb.ListReservationsRequest, ...gax.CallOption) *ReservationIterator @@ -382,6 +404,11 @@ type AdminClient struct { // The call options for this service. CallOptions *AdminCallOptions + + // 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. @@ -466,6 +493,37 @@ func (c *AdminClient) DeleteSubscription(ctx context.Context, req *pubsublitepb. return c.internalClient.DeleteSubscription(ctx, req, opts...) } +// SeekSubscription performs an out-of-band seek for a subscription to a specified target, +// which may be timestamps or named positions within the message backlog. +// Seek translates these targets to cursors for each partition and +// orchestrates subscribers to start consuming messages from these seek +// cursors. +// +// If an operation is returned, the seek has been registered and subscribers +// will eventually receive messages from the seek cursors (i.e. eventual +// consistency), as long as they are using a minimum supported client library +// version and not a system that tracks cursors independently of Pub/Sub Lite +// (e.g. Apache Beam, Dataflow, Spark). The seek operation will fail for +// unsupported clients. +// +// If clients would like to know when subscribers react to the seek (or not), +// they can poll the operation. The seek operation will succeed and complete +// once subscribers are ready to receive messages from the seek cursors for +// all partitions of the topic. This means that the seek operation will not +// complete until all subscribers come online. +// +// If the previous seek operation has not yet completed, it will be aborted +// and the new invocation of seek will supersede it. +func (c *AdminClient) SeekSubscription(ctx context.Context, req *pubsublitepb.SeekSubscriptionRequest, opts ...gax.CallOption) (*SeekSubscriptionOperation, error) { + return c.internalClient.SeekSubscription(ctx, req, opts...) +} + +// SeekSubscriptionOperation returns a new SeekSubscriptionOperation from a given name. +// The name must be that of a previously created SeekSubscriptionOperation, possibly from a different process. +func (c *AdminClient) SeekSubscriptionOperation(name string) *SeekSubscriptionOperation { + return c.internalClient.SeekSubscriptionOperation(name) +} + // CreateReservation creates a new reservation. func (c *AdminClient) CreateReservation(ctx context.Context, req *pubsublitepb.CreateReservationRequest, opts ...gax.CallOption) (*pubsublitepb.Reservation, error) { return c.internalClient.CreateReservation(ctx, req, opts...) @@ -512,6 +570,11 @@ type adminGRPCClient struct { // The gRPC API client. adminClient pubsublitepb.AdminServiceClient + // 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 } @@ -552,6 +615,17 @@ func NewAdminClient(ctx context.Context, opts ...option.ClientOption) (*AdminCli 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 } @@ -878,6 +952,29 @@ func (c *adminGRPCClient) DeleteSubscription(ctx context.Context, req *pubsublit return err } +func (c *adminGRPCClient) SeekSubscription(ctx context.Context, req *pubsublitepb.SeekSubscriptionRequest, opts ...gax.CallOption) (*SeekSubscriptionOperation, error) { + if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { + cctx, cancel := context.WithTimeout(ctx, 600000*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).SeekSubscription[0:len((*c.CallOptions).SeekSubscription):len((*c.CallOptions).SeekSubscription)], opts...) + var resp *longrunningpb.Operation + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.adminClient.SeekSubscription(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return &SeekSubscriptionOperation{ + lro: longrunning.InternalNewOperation(*c.LROClient, resp), + }, nil +} + func (c *adminGRPCClient) CreateReservation(ctx context.Context, req *pubsublitepb.CreateReservationRequest, opts ...gax.CallOption) (*pubsublitepb.Reservation, error) { if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { cctx, cancel := context.WithTimeout(ctx, 600000*time.Millisecond) @@ -1038,6 +1135,75 @@ func (c *adminGRPCClient) ListReservationTopics(ctx context.Context, req *pubsub return it } +// SeekSubscriptionOperation manages a long-running operation from SeekSubscription. +type SeekSubscriptionOperation struct { + lro *longrunning.Operation +} + +// SeekSubscriptionOperation returns a new SeekSubscriptionOperation from a given name. +// The name must be that of a previously created SeekSubscriptionOperation, possibly from a different process. +func (c *adminGRPCClient) SeekSubscriptionOperation(name string) *SeekSubscriptionOperation { + return &SeekSubscriptionOperation{ + 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 *SeekSubscriptionOperation) Wait(ctx context.Context, opts ...gax.CallOption) (*pubsublitepb.SeekSubscriptionResponse, error) { + var resp pubsublitepb.SeekSubscriptionResponse + 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 *SeekSubscriptionOperation) Poll(ctx context.Context, opts ...gax.CallOption) (*pubsublitepb.SeekSubscriptionResponse, error) { + var resp pubsublitepb.SeekSubscriptionResponse + 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 *SeekSubscriptionOperation) Metadata() (*pubsublitepb.OperationMetadata, error) { + var meta pubsublitepb.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 *SeekSubscriptionOperation) 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 *SeekSubscriptionOperation) Name() string { + return op.lro.Name() +} + // ReservationIterator manages a stream of *pubsublitepb.Reservation. type ReservationIterator struct { items []*pubsublitepb.Reservation diff --git a/pubsublite/apiv1/admin_client_example_test.go b/pubsublite/apiv1/admin_client_example_test.go index dcec2c2a66f..f7eaf6d7260 100644 --- a/pubsublite/apiv1/admin_client_example_test.go +++ b/pubsublite/apiv1/admin_client_example_test.go @@ -278,6 +278,30 @@ func ExampleAdminClient_DeleteSubscription() { } } +func ExampleAdminClient_SeekSubscription() { + ctx := context.Background() + c, err := pubsublite.NewAdminClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &pubsublitepb.SeekSubscriptionRequest{ + // TODO: Fill request struct fields. + } + op, err := c.SeekSubscription(ctx, req) + if err != nil { + // TODO: Handle error. + } + + resp, err := op.Wait(ctx) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + func ExampleAdminClient_CreateReservation() { ctx := context.Background() c, err := pubsublite.NewAdminClient(ctx) diff --git a/pubsublite/apiv1/cursor_client.go b/pubsublite/apiv1/cursor_client.go index 298dc93b2d9..4bf0e3779a9 100644 --- a/pubsublite/apiv1/cursor_client.go +++ b/pubsublite/apiv1/cursor_client.go @@ -23,7 +23,6 @@ import ( "net/url" "time" - "github.com/golang/protobuf/proto" gax "github.com/googleapis/gax-go/v2" "google.golang.org/api/iterator" "google.golang.org/api/option" @@ -33,6 +32,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newCursorClientHook clientHook @@ -50,6 +50,7 @@ func defaultCursorGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("pubsublite.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://pubsublite.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/pubsublite/apiv1/doc.go b/pubsublite/apiv1/doc.go index a90a5562647..24882873059 100644 --- a/pubsublite/apiv1/doc.go +++ b/pubsublite/apiv1/doc.go @@ -48,7 +48,7 @@ import ( type clientHookParams struct{} type clientHook func(context.Context, clientHookParams) ([]option.ClientOption, error) -const versionClient = "20210612" +const versionClient = "20210701" func insertMetadata(ctx context.Context, mds ...metadata.MD) context.Context { out, _ := metadata.FromOutgoingContext(ctx) diff --git a/pubsublite/apiv1/gapic_metadata.json b/pubsublite/apiv1/gapic_metadata.json index 3c04ceb94cf..4d82bdaf696 100644 --- a/pubsublite/apiv1/gapic_metadata.json +++ b/pubsublite/apiv1/gapic_metadata.json @@ -85,6 +85,11 @@ "ListTopics" ] }, + "SeekSubscription": { + "methods": [ + "SeekSubscription" + ] + }, "UpdateReservation": { "methods": [ "UpdateReservation" diff --git a/pubsublite/apiv1/partition_assignment_client.go b/pubsublite/apiv1/partition_assignment_client.go index 29b9ec8578f..46fcdae435c 100644 --- a/pubsublite/apiv1/partition_assignment_client.go +++ b/pubsublite/apiv1/partition_assignment_client.go @@ -42,6 +42,7 @@ func defaultPartitionAssignmentGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("pubsublite.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://pubsublite.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/pubsublite/apiv1/publisher_client.go b/pubsublite/apiv1/publisher_client.go index 41ed5b94ba0..34722003252 100644 --- a/pubsublite/apiv1/publisher_client.go +++ b/pubsublite/apiv1/publisher_client.go @@ -42,6 +42,7 @@ func defaultPublisherGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("pubsublite.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://pubsublite.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/pubsublite/apiv1/subscriber_client.go b/pubsublite/apiv1/subscriber_client.go index 7b076748002..995bc80c55e 100644 --- a/pubsublite/apiv1/subscriber_client.go +++ b/pubsublite/apiv1/subscriber_client.go @@ -42,6 +42,7 @@ func defaultSubscriberGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("pubsublite.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://pubsublite.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/pubsublite/apiv1/topic_stats_client.go b/pubsublite/apiv1/topic_stats_client.go index 6b43a3a69bd..dd1c5afc1cb 100644 --- a/pubsublite/apiv1/topic_stats_client.go +++ b/pubsublite/apiv1/topic_stats_client.go @@ -48,6 +48,7 @@ func defaultTopicStatsGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("pubsublite.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://pubsublite.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/pubsublite/go.mod b/pubsublite/go.mod index 17ec3b3de9f..6329bc5686a 100644 --- a/pubsublite/go.mod +++ b/pubsublite/go.mod @@ -11,8 +11,8 @@ require ( github.com/googleapis/gax-go/v2 v2.0.5 golang.org/x/sync v0.0.0-20210220032951-036812b2e83c golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 - google.golang.org/api v0.48.0 - google.golang.org/genproto v0.0.0-20210614143202-012ab6975634 + google.golang.org/api v0.50.0 + google.golang.org/genproto v0.0.0-20210701133433-6b8dcf568a95 google.golang.org/grpc v1.38.0 - google.golang.org/protobuf v1.26.0 + google.golang.org/protobuf v1.27.1 ) diff --git a/pubsublite/go.sum b/pubsublite/go.sum index d67a6aa2b3a..0e3eacfcd53 100644 --- a/pubsublite/go.sum +++ b/pubsublite/go.sum @@ -254,8 +254,9 @@ golang.org/x/oauth2 v0.0.0-20201208152858-08078c50e5b5/go.mod h1:KelEdhl1UZF7XfJ golang.org/x/oauth2 v0.0.0-20210218202405-ba52d332ba99/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= golang.org/x/oauth2 v0.0.0-20210220000619-9bb904979d93/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= golang.org/x/oauth2 v0.0.0-20210313182246-cd4f82c27b84/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= -golang.org/x/oauth2 v0.0.0-20210514164344-f6687ab2804c h1:pkQiBZBvdos9qq4wBAHqlzuZHEXo07pqV06ef90u1WI= golang.org/x/oauth2 v0.0.0-20210514164344-f6687ab2804c/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= +golang.org/x/oauth2 v0.0.0-20210628180205-a41e5a781914 h1:3B43BWw0xEBsLZ/NO1VALz6fppU3481pik+2Ksv45z8= +golang.org/x/oauth2 v0.0.0-20210628180205-a41e5a781914/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= @@ -307,8 +308,9 @@ golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210514084401-e8d321eab015/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20210603125802-9665404d3644 h1:CA1DEQ4NdKphKeL70tvsWNdT5oFh1lOjihRcEDROi0I= golang.org/x/sys v0.0.0-20210603125802-9665404d3644/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20210616094352-59db8d763f22 h1:RqytpXGR1iVNX7psjB3ff8y7sNFinVFvkx1c8SjBkio= +golang.org/x/sys v0.0.0-20210616094352-59db8d763f22/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= @@ -372,8 +374,9 @@ golang.org/x/tools v0.0.0-20210105154028-b0ab187a4818/go.mod h1:emZCQorbCU4vsT4f golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0= golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.2/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= -golang.org/x/tools v0.1.3 h1:L69ShwSZEyCsLKoAxDKeMvLDZkumEe8gXUZAjab0tX8= golang.org/x/tools v0.1.3/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= +golang.org/x/tools v0.1.4 h1:cVngSRcfgyZCzys3KYOpCFa+4dqX/Oub9tAq00ttGVs= +golang.org/x/tools v0.1.4/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= @@ -401,8 +404,9 @@ google.golang.org/api v0.40.0/go.mod h1:fYKFpnQN0DsDSKRVRcQSDQNtqWPfM9i+zNPxepjR google.golang.org/api v0.41.0/go.mod h1:RkxM5lITDfTzmyKFPt+wGrCJbVfniCr2ool8kTBzRTU= google.golang.org/api v0.43.0/go.mod h1:nQsDGjRXMo4lvh5hP0TKqF244gqhGcr/YSIykhUk/94= google.golang.org/api v0.47.0/go.mod h1:Wbvgpq1HddcWVtzsVLyfLp8lDg6AA241LmgIL59tHXo= -google.golang.org/api v0.48.0 h1:RDAPWfNFY06dffEXfn7hZF5Fr1ZbnChzfQZAPyBd1+I= google.golang.org/api v0.48.0/go.mod h1:71Pr1vy+TAZRPkPs/xlCf5SsU8WjuAWv1Pfjbtukyy4= +google.golang.org/api v0.50.0 h1:LX7NFCFYOHzr7WHaYiRUpeipZe9o5L8T+2F4Z798VDw= +google.golang.org/api v0.50.0/go.mod h1:4bNT5pAuq5ji4SRZm+5QIkjny9JAyVD/3gaSihNefaw= google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= google.golang.org/appengine v1.5.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= @@ -456,8 +460,9 @@ google.golang.org/genproto v0.0.0-20210513213006-bf773b8c8384/go.mod h1:P3QM42oQ google.golang.org/genproto v0.0.0-20210602131652-f16073e35f0c/go.mod h1:UODoCrxHCcBojKKwX1terBiRUaqAsFqJiF615XL43r0= google.golang.org/genproto v0.0.0-20210604141403-392c879c8b08/go.mod h1:UODoCrxHCcBojKKwX1terBiRUaqAsFqJiF615XL43r0= google.golang.org/genproto v0.0.0-20210608205507-b6d2f5bf0d7d/go.mod h1:UODoCrxHCcBojKKwX1terBiRUaqAsFqJiF615XL43r0= -google.golang.org/genproto v0.0.0-20210614143202-012ab6975634 h1:LnkHrvncK4mYysgs+R1wPeMAILrmunf0Tzl0Li71pxo= -google.golang.org/genproto v0.0.0-20210614143202-012ab6975634/go.mod h1:SzzZ/N+nwJDaO1kznhnlzqS8ocJICar6hYhVyhi++24= +google.golang.org/genproto v0.0.0-20210624195500-8bfb893ecb84/go.mod h1:SzzZ/N+nwJDaO1kznhnlzqS8ocJICar6hYhVyhi++24= +google.golang.org/genproto v0.0.0-20210701133433-6b8dcf568a95 h1:xyRjacsGcaSoZ2fTcaLCSzh2JEceLLOT4X8k32Q0xAQ= +google.golang.org/genproto v0.0.0-20210701133433-6b8dcf568a95/go.mod h1:yiaVoXHpRzHGyxV3o4DktVWY4mSUErTKaeEOq6C3t3U= google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38= google.golang.org/grpc v1.21.1/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM= @@ -492,8 +497,9 @@ google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpAD google.golang.org/protobuf v1.24.0/go.mod h1:r/3tXBNzIEhYS9I1OUVjXDlt8tc493IdKGjtUeSXeh4= google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c= google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= -google.golang.org/protobuf v1.26.0 h1:bxAC2xTBsZGibn2RTntX0oH50xLsqy1OxA9tTL3p/lk= google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= +google.golang.org/protobuf v1.27.1 h1:SnqbnDw1V7RiZcXPx5MEeqPv2s79L9i7BJUlG/+RurQ= +google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= diff --git a/pubsublite/integration_test.go b/pubsublite/integration_test.go index 80076f59a01..53aff1ba399 100644 --- a/pubsublite/integration_test.go +++ b/pubsublite/integration_test.go @@ -130,7 +130,7 @@ func TestIntegration_ResourceAdminOperations(t *testing.T) { region, _ := wire.ZoneToRegion(zone) resourceID := resourceIDs.New() - locationPath := wire.LocationPath{Project: proj, Zone: zone}.String() + locationPath := wire.LocationPath{Project: proj, Location: zone}.String() topicPath := wire.TopicPath{Project: proj, Zone: zone, TopicID: resourceID}.String() subscriptionPath := wire.SubscriptionPath{Project: proj, Zone: zone, SubscriptionID: resourceID}.String() t.Logf("Topic path: %s", topicPath) diff --git a/pubsublite/internal/test/mock.go b/pubsublite/internal/test/mock.go index 425cda76c37..770e5b4c24d 100644 --- a/pubsublite/internal/test/mock.go +++ b/pubsublite/internal/test/mock.go @@ -29,6 +29,7 @@ import ( emptypb "github.com/golang/protobuf/ptypes/empty" pb "google.golang.org/genproto/googleapis/cloud/pubsublite/v1" + lrpb "google.golang.org/genproto/googleapis/longrunning" ) // MockServer is an in-memory mock implementation of a Pub/Sub Lite service, @@ -62,6 +63,7 @@ func NewServer() (*Server, error) { pb.RegisterSubscriberServiceServer(srv.Gsrv, liteServer) pb.RegisterCursorServiceServer(srv.Gsrv, liteServer) pb.RegisterPartitionAssignmentServiceServer(srv.Gsrv, liteServer) + lrpb.RegisterOperationsServer(srv.Gsrv, liteServer) srv.Start() return &Server{LiteServer: liteServer, gRPCServer: srv}, nil } @@ -87,6 +89,7 @@ type mockLiteServer struct { pb.SubscriberServiceServer pb.CursorServiceServer pb.PartitionAssignmentServiceServer + lrpb.OperationsServer mu sync.Mutex @@ -277,7 +280,7 @@ func (s *mockLiteServer) doTopicResponse(ctx context.Context, req interface{}) ( } resp, ok := retResponse.(*pb.Topic) if !ok { - return nil, status.Errorf(codes.FailedPrecondition, "mockserver: invalid response type %v", reflect.TypeOf(retResponse)) + return nil, status.Errorf(codes.FailedPrecondition, "mockserver: invalid response type %T", retResponse) } return resp, nil } @@ -289,7 +292,31 @@ func (s *mockLiteServer) doSubscriptionResponse(ctx context.Context, req interfa } resp, ok := retResponse.(*pb.Subscription) if !ok { - return nil, status.Errorf(codes.FailedPrecondition, "mockserver: invalid response type %v", reflect.TypeOf(retResponse)) + return nil, status.Errorf(codes.FailedPrecondition, "mockserver: invalid response type %T", retResponse) + } + return resp, nil +} + +func (s *mockLiteServer) doOperationResponse(ctx context.Context, req interface{}) (*lrpb.Operation, error) { + retResponse, retErr := s.popGlobalVerifiers(req) + if retErr != nil { + return nil, retErr + } + resp, ok := retResponse.(*lrpb.Operation) + if !ok { + return nil, status.Errorf(codes.FailedPrecondition, "mockserver: invalid response type %T", retResponse) + } + return resp, nil +} + +func (s *mockLiteServer) doReservationResponse(ctx context.Context, req interface{}) (*pb.Reservation, error) { + retResponse, retErr := s.popGlobalVerifiers(req) + if retErr != nil { + return nil, retErr + } + resp, ok := retResponse.(*pb.Reservation) + if !ok { + return nil, status.Errorf(codes.FailedPrecondition, "mockserver: invalid response type %T", retResponse) } return resp, nil } @@ -301,7 +328,7 @@ func (s *mockLiteServer) doEmptyResponse(ctx context.Context, req interface{}) ( } resp, ok := retResponse.(*emptypb.Empty) if !ok { - return nil, status.Errorf(codes.FailedPrecondition, "mockserver: invalid response type %v", reflect.TypeOf(retResponse)) + return nil, status.Errorf(codes.FailedPrecondition, "mockserver: invalid response type %T", retResponse) } return resp, nil } @@ -325,7 +352,7 @@ func (s *mockLiteServer) GetTopicPartitions(ctx context.Context, req *pb.GetTopi } resp, ok := retResponse.(*pb.TopicPartitions) if !ok { - return nil, status.Errorf(codes.FailedPrecondition, "mockserver: invalid response type %v", reflect.TypeOf(retResponse)) + return nil, status.Errorf(codes.FailedPrecondition, "mockserver: invalid response type %T", retResponse) } return resp, nil } @@ -346,10 +373,30 @@ func (s *mockLiteServer) UpdateSubscription(ctx context.Context, req *pb.UpdateS return s.doSubscriptionResponse(ctx, req) } +func (s *mockLiteServer) SeekSubscription(ctx context.Context, req *pb.SeekSubscriptionRequest) (*lrpb.Operation, error) { + return s.doOperationResponse(ctx, req) +} + func (s *mockLiteServer) DeleteSubscription(ctx context.Context, req *pb.DeleteSubscriptionRequest) (*emptypb.Empty, error) { return s.doEmptyResponse(ctx, req) } +func (s *mockLiteServer) CreateReservation(ctx context.Context, req *pb.CreateReservationRequest) (*pb.Reservation, error) { + return s.doReservationResponse(ctx, req) +} + +func (s *mockLiteServer) GetReservation(ctx context.Context, req *pb.GetReservationRequest) (*pb.Reservation, error) { + return s.doReservationResponse(ctx, req) +} + +func (s *mockLiteServer) UpdateReservation(ctx context.Context, req *pb.UpdateReservationRequest) (*pb.Reservation, error) { + return s.doReservationResponse(ctx, req) +} + +func (s *mockLiteServer) DeleteReservation(ctx context.Context, req *pb.DeleteReservationRequest) (*emptypb.Empty, error) { + return s.doEmptyResponse(ctx, req) +} + func (s *mockLiteServer) ListTopics(ctx context.Context, req *pb.ListTopicsRequest) (*pb.ListTopicsResponse, error) { retResponse, retErr := s.popGlobalVerifiers(req) if retErr != nil { @@ -357,7 +404,7 @@ func (s *mockLiteServer) ListTopics(ctx context.Context, req *pb.ListTopicsReque } resp, ok := retResponse.(*pb.ListTopicsResponse) if !ok { - return nil, status.Errorf(codes.FailedPrecondition, "mockserver: invalid response type %v", reflect.TypeOf(retResponse)) + return nil, status.Errorf(codes.FailedPrecondition, "mockserver: invalid response type %T", retResponse) } return resp, nil } @@ -369,7 +416,7 @@ func (s *mockLiteServer) ListTopicSubscriptions(ctx context.Context, req *pb.Lis } resp, ok := retResponse.(*pb.ListTopicSubscriptionsResponse) if !ok { - return nil, status.Errorf(codes.FailedPrecondition, "mockserver: invalid response type %v", reflect.TypeOf(retResponse)) + return nil, status.Errorf(codes.FailedPrecondition, "mockserver: invalid response type %T", retResponse) } return resp, nil } @@ -381,7 +428,51 @@ func (s *mockLiteServer) ListSubscriptions(ctx context.Context, req *pb.ListSubs } resp, ok := retResponse.(*pb.ListSubscriptionsResponse) if !ok { - return nil, status.Errorf(codes.FailedPrecondition, "mockserver: invalid response type %v", reflect.TypeOf(retResponse)) + return nil, status.Errorf(codes.FailedPrecondition, "mockserver: invalid response type %T", retResponse) } return resp, nil } + +func (s *mockLiteServer) ListReservations(ctx context.Context, req *pb.ListReservationsRequest) (*pb.ListReservationsResponse, error) { + retResponse, retErr := s.popGlobalVerifiers(req) + if retErr != nil { + return nil, retErr + } + resp, ok := retResponse.(*pb.ListReservationsResponse) + if !ok { + return nil, status.Errorf(codes.FailedPrecondition, "mockserver: invalid response type %T", retResponse) + } + return resp, nil +} + +func (s *mockLiteServer) ListReservationTopics(ctx context.Context, req *pb.ListReservationTopicsRequest) (*pb.ListReservationTopicsResponse, error) { + retResponse, retErr := s.popGlobalVerifiers(req) + if retErr != nil { + return nil, retErr + } + resp, ok := retResponse.(*pb.ListReservationTopicsResponse) + if !ok { + return nil, status.Errorf(codes.FailedPrecondition, "mockserver: invalid response type %T", retResponse) + } + return resp, nil +} + +func (s *mockLiteServer) GetOperation(ctx context.Context, req *lrpb.GetOperationRequest) (*lrpb.Operation, error) { + return s.doOperationResponse(ctx, req) +} + +func (s *mockLiteServer) ListOperations(ctx context.Context, req *lrpb.ListOperationsRequest) (*lrpb.ListOperationsResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "Unexpected ListOperations call") +} + +func (s *mockLiteServer) DeleteOperation(ctx context.Context, req *lrpb.DeleteOperationRequest) (*emptypb.Empty, error) { + return nil, status.Errorf(codes.Unimplemented, "Unexpected DeleteOperation call") +} + +func (s *mockLiteServer) CancelOperation(ctx context.Context, req *lrpb.CancelOperationRequest) (*emptypb.Empty, error) { + return nil, status.Errorf(codes.Unimplemented, "Unexpected CancelOperation call") +} + +func (s *mockLiteServer) WaitOperation(ctx context.Context, req *lrpb.WaitOperationRequest) (*lrpb.Operation, error) { + return nil, status.Errorf(codes.Unimplemented, "Unexpected WaitOperation call") +} diff --git a/pubsublite/internal/test/util.go b/pubsublite/internal/test/util.go index 6a35095afdf..29afb9a35f8 100644 --- a/pubsublite/internal/test/util.go +++ b/pubsublite/internal/test/util.go @@ -14,6 +14,7 @@ package test import ( + "log" "strings" "github.com/google/go-cmp/cmp" @@ -21,6 +22,8 @@ import ( "golang.org/x/xerrors" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" + "google.golang.org/protobuf/proto" + "google.golang.org/protobuf/types/known/anypb" ) // ErrorEqual compares two errors for equivalence. @@ -54,3 +57,12 @@ func (f *FakeSource) Int63() int64 { return f.Ret } // Seed is unimplemented. func (f *FakeSource) Seed(seed int64) {} + +// MakeAny packs a message into an Any proto. +func MakeAny(msg proto.Message) *anypb.Any { + any, err := anypb.New(msg) + if err != nil { + log.Fatalf("Failed to make Any: %v", err) + } + return any +} diff --git a/pubsublite/internal/wire/partition_count.go b/pubsublite/internal/wire/partition_count.go index c4319a536f0..4255a647443 100644 --- a/pubsublite/internal/wire/partition_count.go +++ b/pubsublite/internal/wire/partition_count.go @@ -16,6 +16,9 @@ package wire import ( "context" "fmt" + "time" + + "golang.org/x/xerrors" vkit "cloud.google.com/go/pubsublite/apiv1" gax "github.com/googleapis/gax-go/v2" @@ -30,11 +33,13 @@ type partitionCountReceiver func(partitionCount int) // topic and notifies a receiver if it changes. type partitionCountWatcher struct { // Immutable after creation. - ctx context.Context - adminClient *vkit.AdminClient - topicPath string - receiver partitionCountReceiver - callOption gax.CallOption + ctx context.Context + adminClient *vkit.AdminClient + topicPath string + receiver partitionCountReceiver + callOption gax.CallOption + initialTimeout time.Duration + pollPeriod time.Duration // Fields below must be guarded with mu. partitionCount int @@ -47,11 +52,13 @@ func newPartitionCountWatcher(ctx context.Context, adminClient *vkit.AdminClient settings PublishSettings, topicPath string, receiver partitionCountReceiver) *partitionCountWatcher { p := &partitionCountWatcher{ - ctx: ctx, - adminClient: adminClient, - topicPath: topicPath, - receiver: receiver, - callOption: resourceExhaustedRetryer(), + ctx: ctx, + adminClient: adminClient, + topicPath: topicPath, + receiver: receiver, + callOption: resourceExhaustedRetryer(), + initialTimeout: settings.Timeout, + pollPeriod: settings.ConfigPollPeriod, } // Polling the topic partition count can be disabled in settings if the period @@ -88,8 +95,17 @@ func (p *partitionCountWatcher) updatePartitionCount() { p.mu.Unlock() newPartitionCount, err := func() (int, error) { + // Ensure the first update respects PublishSettings.Timeout. + timeout := p.initialTimeout + if prevPartitionCount > 0 { + timeout = p.pollPeriod + } + cctx, cancel := context.WithCancel(p.ctx) + rt := newRequestTimer(timeout, cancel, ErrBackendUnavailable) + req := &pb.GetTopicPartitionsRequest{Name: p.topicPath} - resp, err := p.adminClient.GetTopicPartitions(p.ctx, req, p.callOption) + resp, err := p.adminClient.GetTopicPartitions(cctx, req, p.callOption) + rt.Stop() p.mu.Lock() defer p.mu.Unlock() @@ -105,7 +121,7 @@ func (p *partitionCountWatcher) updatePartitionCount() { // TODO: Log the error. return p.partitionCount, nil } - err = fmt.Errorf("pubsublite: failed to update topic partition count: %v", err) + err = xerrors.Errorf("pubsublite: failed to update topic partition count: %w", rt.ResolveError(err)) p.unsafeInitiateShutdown(err) return 0, err } diff --git a/pubsublite/internal/wire/partition_count_test.go b/pubsublite/internal/wire/partition_count_test.go index aef4387e0b9..b203425eecf 100644 --- a/pubsublite/internal/wire/partition_count_test.go +++ b/pubsublite/internal/wire/partition_count_test.go @@ -16,6 +16,7 @@ package wire import ( "context" "testing" + "time" "cloud.google.com/go/internal/testutil" "cloud.google.com/go/pubsublite/internal/test" @@ -54,7 +55,7 @@ func newTestPartitionCountWatcher(t *testing.T, topicPath string, settings Publi tw := &testPartitionCountWatcher{ t: t, } - tw.watcher = newPartitionCountWatcher(ctx, adminClient, testPublishSettings(), topicPath, tw.onCountChanged) + tw.watcher = newPartitionCountWatcher(ctx, adminClient, settings, topicPath, tw.onCountChanged) tw.initAndStart(t, tw.watcher, "PartitionCountWatcher", adminClient) return tw } @@ -95,6 +96,59 @@ func TestPartitionCountWatcherZeroPartitionCountFails(t *testing.T) { watcher.VerifyCounts(nil) } +func TestPartitionCountWatcherInitialRequestTimesOut(t *testing.T) { + const topic = "projects/123456/locations/us-central1-b/topics/my-topic" + + verifiers := test.NewVerifiers(t) + barrier := verifiers.GlobalVerifier.PushWithBarrier(topicPartitionsReq(topic), topicPartitionsResp(1), nil) + + mockServer.OnTestStart(verifiers) + defer mockServer.OnTestEnd() + + settings := testPublishSettings() + settings.Timeout = 20 * time.Millisecond // Set low timeout for initial request + watcher := newTestPartitionCountWatcher(t, topic, settings) + + if gotErr, wantErr := watcher.StartError(), ErrBackendUnavailable; !test.ErrorEqual(gotErr, wantErr) { + t.Errorf("Start() got err: (%v), want err: (%v)", gotErr, wantErr) + } + barrier.Release() + watcher.VerifyCounts(nil) +} + +func TestPartitionCountWatcherUpdateLongerTimeouts(t *testing.T) { + const topic = "projects/123456/locations/us-central1-b/topics/my-topic" + wantPartitionCount1 := 1 + wantPartitionCount2 := 2 + + verifiers := test.NewVerifiers(t) + verifiers.GlobalVerifier.Push(topicPartitionsReq(topic), topicPartitionsResp(wantPartitionCount1), nil) + // Barrier used to delay response. + barrier := verifiers.GlobalVerifier.PushWithBarrier(topicPartitionsReq(topic), topicPartitionsResp(wantPartitionCount2), nil) + + mockServer.OnTestStart(verifiers) + defer mockServer.OnTestEnd() + + watcher := newTestPartitionCountWatcher(t, topic, testPublishSettings()) + if gotErr := watcher.StartError(); gotErr != nil { + t.Errorf("Start() got err: (%v)", gotErr) + } + watcher.VerifyCounts([]int{wantPartitionCount1}) + + // Override the initial timeout after the first request to verify that it + // isn't used. If set at creation, the first request will fail. + const timeout = time.Millisecond + watcher.watcher.initialTimeout = timeout + go func() { + barrier.ReleaseAfter(func() { + time.Sleep(5 * timeout) + }) + }() + watcher.UpdatePartitionCount() + watcher.VerifyCounts([]int{wantPartitionCount1, wantPartitionCount2}) + watcher.StopVerifyNoError() +} + func TestPartitionCountWatcherPartitionCountUnchanged(t *testing.T) { const topic = "projects/123456/locations/us-central1-b/topics/my-topic" wantPartitionCount1 := 4 diff --git a/pubsublite/internal/wire/publisher_test.go b/pubsublite/internal/wire/publisher_test.go index b407c651dc4..47eda71f5be 100644 --- a/pubsublite/internal/wire/publisher_test.go +++ b/pubsublite/internal/wire/publisher_test.go @@ -34,8 +34,9 @@ func testPublishSettings() PublishSettings { // Send messages with minimal delay to speed up tests. settings.DelayThreshold = time.Millisecond settings.Timeout = 5 * time.Second - // Disable topic partition count background polling. - settings.ConfigPollPeriod = 0 + // Set long poll period to prevent background update, but still have non-zero + // request timeout. + settings.ConfigPollPeriod = 1 * time.Minute return settings } diff --git a/pubsublite/internal/wire/request_timer.go b/pubsublite/internal/wire/request_timer.go new file mode 100644 index 00000000000..ee3a1565e54 --- /dev/null +++ b/pubsublite/internal/wire/request_timer.go @@ -0,0 +1,78 @@ +// 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 + +package wire + +import ( + "sync" + "time" +) + +type requestTimerStatus int + +const ( + requestTimerNew requestTimerStatus = iota + requestTimerStopped + requestTimerTriggered +) + +// requestTimer bounds the duration of a request and executes `onTimeout` if +// the timer is triggered. +type requestTimer struct { + onTimeout func() + timeoutErr error + timer *time.Timer + mu sync.Mutex + status requestTimerStatus +} + +func newRequestTimer(duration time.Duration, onTimeout func(), timeoutErr error) *requestTimer { + rt := &requestTimer{ + onTimeout: onTimeout, + timeoutErr: timeoutErr, + status: requestTimerNew, + } + rt.timer = time.AfterFunc(duration, rt.onTriggered) + return rt +} + +func (rt *requestTimer) onTriggered() { + rt.mu.Lock() + defer rt.mu.Unlock() + if rt.status == requestTimerNew { + rt.status = requestTimerTriggered + rt.onTimeout() + } +} + +// Stop should be called upon a successful request to prevent the timer from +// expiring. +func (rt *requestTimer) Stop() { + rt.mu.Lock() + defer rt.mu.Unlock() + if rt.status == requestTimerNew { + rt.status = requestTimerStopped + rt.timer.Stop() + } +} + +// ResolveError returns `timeoutErr` if the timer triggered, or otherwise +// `originalErr`. +func (rt *requestTimer) ResolveError(originalErr error) error { + rt.mu.Lock() + defer rt.mu.Unlock() + if rt.status == requestTimerTriggered { + return rt.timeoutErr + } + return originalErr +} diff --git a/pubsublite/internal/wire/request_timer_test.go b/pubsublite/internal/wire/request_timer_test.go new file mode 100644 index 00000000000..86c96c2b9dd --- /dev/null +++ b/pubsublite/internal/wire/request_timer_test.go @@ -0,0 +1,61 @@ +// 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 + +package wire + +import ( + "errors" + "testing" + "time" + + "cloud.google.com/go/pubsublite/internal/test" +) + +func TestRequestTimerStop(t *testing.T) { + const timeout = 5 * time.Millisecond + onTimeout := func() { + t.Error("onTimeout should not be called") + } + + rt := newRequestTimer(timeout, onTimeout, errors.New("unused")) + rt.Stop() + time.Sleep(2 * timeout) + + if err := rt.ResolveError(nil); err != nil { + t.Errorf("ResolveError() got gotErr: %v", err) + } + wantErr := errors.New("original error") + if gotErr := rt.ResolveError(wantErr); !test.ErrorEqual(gotErr, wantErr) { + t.Errorf("ResolveError() got err: %v, want err: %v", gotErr, wantErr) + } +} + +func TestRequestTimerExpires(t *testing.T) { + const timeout = 5 * time.Millisecond + timeoutErr := errors.New("on timeout") + + expired := test.NewCondition("request timer expired") + onTimeout := func() { + expired.SetDone() + } + + rt := newRequestTimer(timeout, onTimeout, timeoutErr) + expired.WaitUntilDone(t, serviceTestWaitTimeout) + + if gotErr := rt.ResolveError(nil); !test.ErrorEqual(gotErr, timeoutErr) { + t.Errorf("ResolveError() got err: %v, want err: %v", gotErr, timeoutErr) + } + if gotErr := rt.ResolveError(errors.New("ignored")); !test.ErrorEqual(gotErr, timeoutErr) { + t.Errorf("ResolveError() got err: %v, want err: %v", gotErr, timeoutErr) + } +} diff --git a/pubsublite/internal/wire/resources.go b/pubsublite/internal/wire/resources.go index 228d632235b..f76bf5cedaf 100644 --- a/pubsublite/internal/wire/resources.go +++ b/pubsublite/internal/wire/resources.go @@ -49,18 +49,18 @@ func ZoneToRegion(zone string) (string, error) { return zone[0:strings.LastIndex(zone, "-")], nil } -// LocationPath stores a path consisting of a project and zone. +// LocationPath stores a path consisting of a project and zone/region. type LocationPath struct { // A Google Cloud project. The project ID (e.g. "my-project") or the project // number (e.g. "987654321") can be provided. Project string - // A Google Cloud zone, for example "us-central1-a". - Zone string + // A Google Cloud zone or region, for example "us-central1-a", "us-central1". + Location string } func (l LocationPath) String() string { - return fmt.Sprintf("projects/%s/locations/%s", l.Project, l.Zone) + return fmt.Sprintf("projects/%s/locations/%s", l.Project, l.Location) } var locPathRE = regexp.MustCompile(`^projects/([^/]+)/locations/([^/]+)$`) @@ -72,7 +72,7 @@ func ParseLocationPath(input string) (LocationPath, error) { return LocationPath{}, fmt.Errorf("pubsublite: invalid location path %q. valid format is %q", input, "projects/PROJECT_ID/locations/ZONE") } - return LocationPath{Project: parts[1], Zone: parts[2]}, nil + return LocationPath{Project: parts[1], Location: parts[2]}, nil } // TopicPath stores the full path of a Pub/Sub Lite topic. @@ -94,7 +94,7 @@ func (t TopicPath) String() string { // Location returns the topic's location path. func (t TopicPath) Location() LocationPath { - return LocationPath{Project: t.Project, Zone: t.Zone} + return LocationPath{Project: t.Project, Location: t.Zone} } var topicPathRE = regexp.MustCompile(`^projects/([^/]+)/locations/([^/]+)/topics/([^/]+)$`) @@ -129,7 +129,7 @@ func (s SubscriptionPath) String() string { // Location returns the subscription's location path. func (s SubscriptionPath) Location() LocationPath { - return LocationPath{Project: s.Project, Zone: s.Zone} + return LocationPath{Project: s.Project, Location: s.Zone} } var subsPathRE = regexp.MustCompile(`^projects/([^/]+)/locations/([^/]+)/subscriptions/([^/]+)$`) @@ -144,6 +144,40 @@ func ParseSubscriptionPath(input string) (SubscriptionPath, error) { return SubscriptionPath{Project: parts[1], Zone: parts[2], SubscriptionID: parts[3]}, nil } +// ReservationPath stores the full path of a Pub/Sub Lite reservation. +type ReservationPath struct { + // A Google Cloud project. The project ID (e.g. "my-project") or the project + // number (e.g. "987654321") can be provided. + Project string + + // A Google Cloud region. An example region is "us-central1". + Region string + + // The ID of the Pub/Sub Lite reservation, for example "my-reservation-name". + ReservationID string +} + +func (r ReservationPath) String() string { + return fmt.Sprintf("projects/%s/locations/%s/reservations/%s", r.Project, r.Region, r.ReservationID) +} + +// Location returns the reservation's location path. +func (r ReservationPath) Location() LocationPath { + return LocationPath{Project: r.Project, Location: r.Region} +} + +var reservationPathRE = regexp.MustCompile(`^projects/([^/]+)/locations/([^/]+)/reservations/([^/]+)$`) + +// ParseReservationPath parses the full path of a Pub/Sub Lite reservation. +func ParseReservationPath(input string) (ReservationPath, error) { + parts := reservationPathRE.FindStringSubmatch(input) + if len(parts) < 4 { + return ReservationPath{}, fmt.Errorf("pubsublite: invalid reservation path %q. valid format is %q", + input, "projects/PROJECT_ID/locations/REGION/reservations/RESERVATION_ID") + } + return ReservationPath{Project: parts[1], Region: parts[2], ReservationID: parts[3]}, nil +} + type topicPartition struct { Path string Partition int diff --git a/pubsublite/internal/wire/resources_test.go b/pubsublite/internal/wire/resources_test.go index 40582ebbde8..45772fbcaf6 100644 --- a/pubsublite/internal/wire/resources_test.go +++ b/pubsublite/internal/wire/resources_test.go @@ -120,7 +120,7 @@ func TestParseLocationPath(t *testing.T) { { desc: "valid: location path", input: "projects/987654321/locations/europe-west1-d", - wantPath: LocationPath{Project: "987654321", Zone: "europe-west1-d"}, + wantPath: LocationPath{Project: "987654321", Location: "europe-west1-d"}, }, { desc: "invalid: zone", @@ -270,3 +270,60 @@ func TestParseSubscriptionPath(t *testing.T) { }) } } + +func TestParseReservationPath(t *testing.T) { + for _, tc := range []struct { + desc string + input string + wantPath ReservationPath + wantErr bool + }{ + { + desc: "valid: reservation path", + input: "projects/987654321/locations/europe-west1/reservations/my-reservation", + wantPath: ReservationPath{Project: "987654321", Region: "europe-west1", ReservationID: "my-reservation"}, + }, + { + desc: "invalid: region only", + input: "europe-west1", + wantErr: true, + }, + { + desc: "invalid: topic path", + input: "projects/987654321/locations/europe-west1-d/topics/my-topic", + wantErr: true, + }, + { + desc: "invalid: missing project", + input: "projects//locations/europe-west1/reservations/my-reservation", + wantErr: true, + }, + { + desc: "invalid: missing region", + input: "projects/987654321/locations//reservations/my-reservation", + wantErr: true, + }, + { + desc: "invalid: missing reservation id", + input: "projects/987654321/locations/europe-west1/reservations/", + wantErr: true, + }, + { + desc: "invalid: has prefix", + input: "prefix/projects/987654321/locations/europe-west1/reservations/my-reservation", + wantErr: true, + }, + { + desc: "invalid: has suffix", + input: "projects/my-project/locations/us-west1/reservations/my-reservation/subresource/desc", + wantErr: true, + }, + } { + t.Run(tc.desc, func(t *testing.T) { + gotPath, gotErr := ParseReservationPath(tc.input) + if gotPath != tc.wantPath || (gotErr != nil) != tc.wantErr { + t.Errorf("ParseReservationPath(%q) = (%v, %v), want (%v, err=%v)", tc.input, gotPath, gotErr, tc.wantPath, tc.wantErr) + } + }) + } +} diff --git a/pubsublite/internal/wire/rpc.go b/pubsublite/internal/wire/rpc.go index 188f148bb9c..b77df47db41 100644 --- a/pubsublite/internal/wire/rpc.go +++ b/pubsublite/internal/wire/rpc.go @@ -183,9 +183,11 @@ func isStreamResetSignal(err error) bool { func defaultClientOptions(region string) []option.ClientOption { return []option.ClientOption{ internaloption.WithDefaultEndpoint(region + pubsubLiteDefaultEndpoint), - // Keep inactive connections alive. + // Detect if transport is still alive if there is inactivity. option.WithGRPCDialOption(grpc.WithKeepaliveParams(keepalive.ClientParameters{ - Time: 5 * time.Minute, + Time: 1 * time.Minute, + Timeout: 1 * time.Minute, + PermitWithoutStream: true, })), } } diff --git a/pubsublite/internal/wire/rpc_test.go b/pubsublite/internal/wire/rpc_test.go index 850a946a76f..e624b9e70e2 100644 --- a/pubsublite/internal/wire/rpc_test.go +++ b/pubsublite/internal/wire/rpc_test.go @@ -16,10 +16,10 @@ package wire import ( "encoding/base64" "errors" - "log" "testing" "cloud.google.com/go/internal/testutil" + "cloud.google.com/go/pubsublite/internal/test" "google.golang.org/genproto/googleapis/rpc/errdetails" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" @@ -30,18 +30,10 @@ import ( spb "google.golang.org/genproto/googleapis/rpc/status" ) -func makeAny(msg proto.Message) *anypb.Any { - any, err := anypb.New(msg) - if err != nil { - log.Fatalf("Failed to make Any: %v", err) - } - return any -} - func makeStreamResetSignal() error { statuspb := &spb.Status{ Code: int32(codes.Aborted), - Details: []*anypb.Any{makeAny(&errdetails.ErrorInfo{ + Details: []*anypb.Any{test.MakeAny(&errdetails.ErrorInfo{ Reason: "RESET", Domain: "pubsublite.googleapis.com", })}, } @@ -63,7 +55,7 @@ func TestIsStreamResetSignal(t *testing.T) { desc: "non-retryable code", err: status.ErrorProto(&spb.Status{ Code: int32(codes.FailedPrecondition), - Details: []*anypb.Any{makeAny(&errdetails.ErrorInfo{Reason: "RESET", Domain: "pubsublite.googleapis.com"})}, + Details: []*anypb.Any{test.MakeAny(&errdetails.ErrorInfo{Reason: "RESET", Domain: "pubsublite.googleapis.com"})}, }), want: false, }, @@ -71,7 +63,7 @@ func TestIsStreamResetSignal(t *testing.T) { desc: "wrong domain", err: status.ErrorProto(&spb.Status{ Code: int32(codes.Aborted), - Details: []*anypb.Any{makeAny(&errdetails.ErrorInfo{Reason: "RESET"})}, + Details: []*anypb.Any{test.MakeAny(&errdetails.ErrorInfo{Reason: "RESET"})}, }), want: false, }, @@ -79,7 +71,7 @@ func TestIsStreamResetSignal(t *testing.T) { desc: "wrong reason", err: status.ErrorProto(&spb.Status{ Code: int32(codes.Aborted), - Details: []*anypb.Any{makeAny(&errdetails.ErrorInfo{Domain: "pubsublite.googleapis.com"})}, + Details: []*anypb.Any{test.MakeAny(&errdetails.ErrorInfo{Domain: "pubsublite.googleapis.com"})}, }), want: false, }, diff --git a/pubsublite/internal/wire/streams.go b/pubsublite/internal/wire/streams.go index a8cc1edacba..76624178c07 100644 --- a/pubsublite/internal/wire/streams.go +++ b/pubsublite/internal/wire/streams.go @@ -22,6 +22,8 @@ import ( "golang.org/x/xerrors" "google.golang.org/grpc" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" gax "github.com/googleapis/gax-go/v2" ) @@ -40,6 +42,11 @@ const ( streamTerminated ) +// Abort a stream initialization attempt after this duration to mitigate delays. +const defaultInitTimeout = 2 * time.Minute + +var errStreamInitTimeout = status.Error(codes.DeadlineExceeded, "pubsublite: stream initialization timed out") + type initialResponseRequired bool type notifyReset bool @@ -95,10 +102,11 @@ type streamHandler interface { // are private implementation. type retryableStream struct { // Immutable after creation. - ctx context.Context - handler streamHandler - responseType reflect.Type - timeout time.Duration + ctx context.Context + handler streamHandler + responseType reflect.Type + connectTimeout time.Duration + initTimeout time.Duration // Guards access to fields below. mu sync.Mutex @@ -115,11 +123,16 @@ type retryableStream struct { // maximum duration for reconnection. `responseType` is the type of the response // proto received on the stream. func newRetryableStream(ctx context.Context, handler streamHandler, timeout time.Duration, responseType reflect.Type) *retryableStream { + initTimeout := defaultInitTimeout + if timeout < defaultInitTimeout { + initTimeout = timeout + } return &retryableStream{ - ctx: ctx, - handler: handler, - responseType: responseType, - timeout: timeout, + ctx: ctx, + handler: handler, + responseType: responseType, + connectTimeout: timeout, + initTimeout: initTimeout, } } @@ -198,12 +211,14 @@ func (rs *retryableStream) unsafeClearStream() { } } -func (rs *retryableStream) setCancel(cancel context.CancelFunc) { +func (rs *retryableStream) newStreamContext() (ctx context.Context, cancel context.CancelFunc) { rs.mu.Lock() defer rs.mu.Unlock() rs.unsafeClearStream() + ctx, cancel = context.WithCancel(rs.ctx) rs.cancelStream = cancel + return } // connectStream attempts to establish a valid connection with the server. Due @@ -241,7 +256,7 @@ func (rs *retryableStream) connectStream(notifyReset notifyReset) { return } - newStream, cancelFunc, err := rs.initNewStream() + newStream, err := rs.initNewStream() if err != nil { rs.terminate(err) return @@ -257,7 +272,6 @@ func (rs *retryableStream) connectStream(notifyReset notifyReset) { } rs.status = streamConnected rs.stream = newStream - rs.cancelStream = cancelFunc return true } if !connected() { @@ -268,27 +282,32 @@ func (rs *retryableStream) connectStream(notifyReset notifyReset) { rs.listen(newStream) } -func (rs *retryableStream) initNewStream() (newStream grpc.ClientStream, cancelFunc context.CancelFunc, err error) { - r := newStreamRetryer(rs.timeout) +func (rs *retryableStream) newInitTimer(cancelFunc func()) *requestTimer { + return newRequestTimer(rs.initTimeout, cancelFunc, errStreamInitTimeout) +} + +func (rs *retryableStream) initNewStream() (newStream grpc.ClientStream, err error) { + var cancelFunc context.CancelFunc + r := newStreamRetryer(rs.connectTimeout) for { backoff, shouldRetry := func() (time.Duration, bool) { var cctx context.Context - cctx, cancelFunc = context.WithCancel(rs.ctx) - // Store the cancel func to quickly cancel reconnecting if the stream is - // terminated. - rs.setCancel(cancelFunc) + cctx, cancelFunc = rs.newStreamContext() + // Bound the duration of the stream initialization attempt. + it := rs.newInitTimer(cancelFunc) + defer it.Stop() newStream, err = rs.handler.newStream(cctx) - if err != nil { + if err = it.ResolveError(err); err != nil { return r.RetryRecv(err) } initReq, needsResponse := rs.handler.initialRequest() - if err = newStream.SendMsg(initReq); err != nil { + if err = it.ResolveError(newStream.SendMsg(initReq)); err != nil { return r.RetrySend(err) } if needsResponse { response := reflect.New(rs.responseType).Interface() - if err = newStream.RecvMsg(response); err != nil { + if err = it.ResolveError(newStream.RecvMsg(response)); err != nil { if isStreamResetSignal(err) { rs.handler.onStreamStatusChange(streamResetState) } @@ -301,6 +320,12 @@ func (rs *retryableStream) initNewStream() (newStream grpc.ClientStream, cancelF } } + // If the init timer fired due to a race, the stream would be unusable. + it.Stop() + if err = it.ResolveError(nil); err != nil { + return r.RetryRecv(err) + } + // We have a valid connection and should break from the outer loop. return 0, false }() diff --git a/pubsublite/internal/wire/streams_test.go b/pubsublite/internal/wire/streams_test.go index fb8e84e414e..368f39dacaf 100644 --- a/pubsublite/internal/wire/streams_test.go +++ b/pubsublite/internal/wire/streams_test.go @@ -284,6 +284,7 @@ func TestRetryableStreamConnectTimeout(t *testing.T) { // Set a very low timeout to ensure no retries. timeout := time.Millisecond pub := newTestStreamHandler(t, timeout) + pub.Stream.initTimeout = defaultInitTimeout wantErr := status.Error(codes.DeadlineExceeded, "timeout") verifiers := test.NewVerifiers(t) @@ -314,6 +315,46 @@ func TestRetryableStreamConnectTimeout(t *testing.T) { } } +func TestRetryableStreamInitTimeout(t *testing.T) { + const streamInitTimeout = 50 * time.Millisecond + const streamResponseDelay = 75 * time.Millisecond + + pub := newTestStreamHandler(t, defaultStreamTimeout) + pub.Stream.initTimeout = streamInitTimeout + + verifiers := test.NewVerifiers(t) + + // First stream will have a delayed response. + stream1 := test.NewRPCVerifier(t) + barrier := stream1.PushWithBarrier(pub.InitialReq, initPubResp(), nil) + verifiers.AddPublishStream(pub.Topic.Path, pub.Topic.Partition, stream1) + + // Second stream should succeed. + stream2 := test.NewRPCVerifier(t) + stream2.Push(pub.InitialReq, initPubResp(), nil) + verifiers.AddPublishStream(pub.Topic.Path, pub.Topic.Partition, stream2) + + mockServer.OnTestStart(verifiers) + defer mockServer.OnTestEnd() + + pub.Stream.Start() + if got, want := pub.NextStatus(), streamReconnecting; got != want { + t.Errorf("Stream status change: got %d, want %d", got, want) + } + + barrier.ReleaseAfter(func() { + time.Sleep(streamResponseDelay) + }) + if got, want := pub.NextStatus(), streamConnected; got != want { + t.Errorf("Stream status change: got %d, want %d", got, want) + } + + pub.Stream.Stop() + if got, want := pub.NextStatus(), streamTerminated; got != want { + t.Errorf("Stream status change: got %d, want %d", got, want) + } +} + func TestRetryableStreamSendReceive(t *testing.T) { pub := newTestStreamHandler(t, defaultStreamTimeout) req := msgPubReq(&pb.PubSubMessage{Data: []byte("msg")}) diff --git a/pubsublite/pscompat/integration_test.go b/pubsublite/pscompat/integration_test.go index a22358ead8e..ab14ad7b973 100644 --- a/pubsublite/pscompat/integration_test.go +++ b/pubsublite/pscompat/integration_test.go @@ -30,7 +30,9 @@ import ( "cloud.google.com/go/pubsublite/internal/wire" "github.com/google/go-cmp/cmp/cmpopts" "golang.org/x/sync/errgroup" + "golang.org/x/xerrors" "google.golang.org/api/option" + "google.golang.org/grpc/codes" vkit "cloud.google.com/go/pubsublite/apiv1" pb "google.golang.org/genproto/googleapis/cloud/pubsublite/v1" @@ -167,7 +169,7 @@ func partitionNumbers(partitionCount int) []int { func publishMessages(t *testing.T, settings PublishSettings, topic wire.TopicPath, msgs ...*pubsub.Message) { ctx := context.Background() - publisher := publisherClient(ctx, t, settings, topic) + publisher := publisherClient(context.Background(), t, settings, topic) defer publisher.Stop() var pubResults []*pubsub.PublishResult @@ -179,7 +181,7 @@ func publishMessages(t *testing.T, settings PublishSettings, topic wire.TopicPat func publishPrefixedMessages(t *testing.T, settings PublishSettings, topic wire.TopicPath, msgPrefix string, msgCount, msgSize int) []string { ctx := context.Background() - publisher := publisherClient(ctx, t, settings, topic) + publisher := publisherClient(context.Background(), t, settings, topic) defer publisher.Stop() orderingSender := test.NewOrderingSender() @@ -271,7 +273,7 @@ func receiveAllMessages(t *testing.T, msgTracker *test.MsgTracker, settings Rece } } - subscriber := subscriberClient(cctx, t, settings, subscription) + subscriber := subscriberClient(context.Background(), t, settings, subscription) if err := subscriber.Receive(cctx, messageReceiver); err != nil { t.Errorf("Receive() got err: %v", err) } @@ -298,7 +300,7 @@ func receiveAndVerifyMessage(t *testing.T, want *pubsub.Message, settings Receiv } } - subscriber := subscriberClient(cctx, t, settings, subscription) + subscriber := subscriberClient(context.Background(), t, settings, subscription) if err := subscriber.Receive(cctx, messageReceiver); err != nil { t.Errorf("Receive() got err: %v", err) } @@ -383,7 +385,7 @@ func TestIntegration_PublishSubscribeSinglePartition(t *testing.T) { } got.Nack() } - subscriber := subscriberClient(cctx, t, recvSettings, subscriptionPath) + subscriber := subscriberClient(context.Background(), t, recvSettings, subscriptionPath) if gotErr := subscriber.Receive(cctx, messageReceiver1); !test.ErrorEqual(gotErr, errNackCalled) { t.Errorf("Receive() got err: (%v), want err: (%v)", gotErr, errNackCalled) } @@ -400,7 +402,7 @@ func TestIntegration_PublishSubscribeSinglePartition(t *testing.T) { } return fmt.Errorf("Received unexpected message: %q", truncateMsg(string(msg.Data))) } - subscriber = subscriberClient(cctx, t, customSettings, subscriptionPath) + subscriber = subscriberClient(context.Background(), t, customSettings, subscriptionPath) messageReceiver2 := func(ctx context.Context, got *pubsub.Message) { got.Nack() @@ -434,7 +436,7 @@ func TestIntegration_PublishSubscribeSinglePartition(t *testing.T) { got.Ack() stopSubscriber() } - subscriber := subscriberClient(cctx, t, recvSettings, subscriptionPath) + subscriber := subscriberClient(context.Background(), t, recvSettings, subscriptionPath) // The message receiver stops the subscriber after receiving the first // message. However, the subscriber isn't guaranteed to immediately stop, so @@ -485,7 +487,7 @@ func TestIntegration_PublishSubscribeSinglePartition(t *testing.T) { // next test, which would receive an incorrect message. got.Ack() } - subscriber := subscriberClient(cctx, t, recvSettings, subscriptionPath) + subscriber := subscriberClient(context.Background(), t, recvSettings, subscriptionPath) if err := subscriber.Receive(cctx, messageReceiver); err != nil { t.Errorf("Receive() got err: %v", err) @@ -539,6 +541,44 @@ func TestIntegration_PublishSubscribeSinglePartition(t *testing.T) { receiveAllMessages(t, msgTracker, recvSettings, subscriptionPath) }) + // Verifies that cancelling the context passed to NewPublisherClient can shut + // down the publisher. + t.Run("CancelPublisherContext", func(t *testing.T) { + cctx, cancel := context.WithCancel(context.Background()) + publisher := publisherClient(cctx, t, DefaultPublishSettings, topicPath) + + cancel() + + wantCode := codes.Canceled + result := publisher.Publish(ctx, &pubsub.Message{Data: []byte("cancel_publisher_context")}) + if _, err := result.Get(ctx); !test.ErrorHasCode(err, wantCode) { + t.Errorf("Publish() got err: %v, want code: %v", err, wantCode) + } + if err := xerrors.Unwrap(publisher.Error()); !test.ErrorHasCode(err, wantCode) { + t.Errorf("Error() got err: %v, want code: %v", err, wantCode) + } + publisher.Stop() + }) + + // Verifies that cancelling the context passed to NewSubscriberClient can shut + // down the subscriber. + t.Run("CancelSubscriberContext", func(t *testing.T) { + msg := &pubsub.Message{Data: []byte("cancel_subscriber_context")} + publishMessages(t, DefaultPublishSettings, topicPath, msg) + + cctx, cancel := context.WithCancel(context.Background()) + subscriber := subscriberClient(cctx, t, recvSettings, subscriptionPath) + + subsErr := subscriber.Receive(context.Background(), func(ctx context.Context, got *pubsub.Message) { + got.Ack() + cancel() + }) + + if err, wantCode := xerrors.Unwrap(subsErr), codes.Canceled; !test.ErrorHasCode(err, wantCode) { + t.Errorf("Receive() got err: %v, want code: %v", err, wantCode) + } + }) + // NOTE: This should be the last test case. // Verifies that increasing the number of topic partitions is handled // correctly by publishers. @@ -547,7 +587,7 @@ func TestIntegration_PublishSubscribeSinglePartition(t *testing.T) { const pollPeriod = 5 * time.Second pubSettings := DefaultPublishSettings pubSettings.configPollPeriod = pollPeriod // Poll updates more frequently - publisher := publisherClient(ctx, t, pubSettings, topicPath) + publisher := publisherClient(context.Background(), t, pubSettings, topicPath) defer publisher.Stop() // Update the number of partitions. @@ -661,7 +701,7 @@ func TestIntegration_PublishSubscribeMultiPartition(t *testing.T) { for i := 0; i < subscriberCount; i++ { // Subscribers must be started in a goroutine as Receive() blocks. g.Go(func() error { - subscriber := subscriberClient(cctx, t, DefaultReceiveSettings, subscriptionPath) + subscriber := subscriberClient(context.Background(), t, DefaultReceiveSettings, subscriptionPath) err := subscriber.Receive(cctx, messageReceiver) if err != nil { t.Errorf("Receive() got err: %v", err) diff --git a/pubsublite/pscompat/publisher.go b/pubsublite/pscompat/publisher.go index 6f4e9415a82..b9f8c82e19a 100644 --- a/pubsublite/pscompat/publisher.go +++ b/pubsublite/pscompat/publisher.go @@ -82,10 +82,7 @@ func NewPublisherClientWithSettings(ctx context.Context, topic string, settings return nil, err } - // Note: ctx is not used to create the wire publisher, because if it is - // cancelled, the publisher will not be able to perform graceful shutdown - // (e.g. flush pending messages). - wirePub, err := wire.NewPublisher(context.Background(), settings.toWireSettings(), region, topic, opts...) + wirePub, err := wire.NewPublisher(ctx, settings.toWireSettings(), region, topic, opts...) if err != nil { return nil, err } diff --git a/pubsublite/pscompat/subscriber.go b/pubsublite/pscompat/subscriber.go index dafb25ee526..d76cc9d290b 100644 --- a/pubsublite/pscompat/subscriber.go +++ b/pubsublite/pscompat/subscriber.go @@ -72,7 +72,7 @@ func (ah *pslAckHandler) OnNack() { // wireSubscriberFactory is a factory for creating wire subscribers, which can // be overridden with a mock in unit tests. type wireSubscriberFactory interface { - New(wire.MessageReceiverFunc) (wire.Subscriber, error) + New(context.Context, wire.MessageReceiverFunc) (wire.Subscriber, error) } type wireSubscriberFactoryImpl struct { @@ -82,8 +82,8 @@ type wireSubscriberFactoryImpl struct { options []option.ClientOption } -func (f *wireSubscriberFactoryImpl) New(receiver wire.MessageReceiverFunc) (wire.Subscriber, error) { - return wire.NewSubscriber(context.Background(), f.settings, receiver, f.region, f.subscription.String(), f.options...) +func (f *wireSubscriberFactoryImpl) New(ctx context.Context, receiver wire.MessageReceiverFunc) (wire.Subscriber, error) { + return wire.NewSubscriber(ctx, f.settings, receiver, f.region, f.subscription.String(), f.options...) } type messageReceiverFunc = func(context.Context, *pubsub.Message) @@ -103,8 +103,8 @@ type subscriberInstance struct { err error } -func newSubscriberInstance(ctx context.Context, factory wireSubscriberFactory, settings ReceiveSettings, receiver messageReceiverFunc) (*subscriberInstance, error) { - recvCtx, recvCancel := context.WithCancel(ctx) +func newSubscriberInstance(recvCtx, clientCtx context.Context, factory wireSubscriberFactory, settings ReceiveSettings, receiver messageReceiverFunc) (*subscriberInstance, error) { + recvCtx, recvCancel := context.WithCancel(recvCtx) subInstance := &subscriberInstance{ settings: settings, recvCtx: recvCtx, @@ -112,10 +112,11 @@ func newSubscriberInstance(ctx context.Context, factory wireSubscriberFactory, s receiver: receiver, } - // Note: ctx is not used to create the wire subscriber, because if it is - // cancelled, the subscriber will not be able to perform graceful shutdown - // (e.g. process acks and commit the final cursor offset). - wireSub, err := factory.New(subInstance.onMessage) + // Note: The context from Receive (recvCtx) should not be used, as when it is + // cancelled, the gRPC streams will be disconnected and the subscriber will + // not be able to process acks and commit the final cursor offset. Use the + // context from NewSubscriberClient (clientCtx) instead. + wireSub, err := factory.New(clientCtx, subInstance.onMessage) if err != nil { return nil, err } @@ -229,6 +230,7 @@ func (si *subscriberInstance) Wait(ctx context.Context) error { // See https://cloud.google.com/pubsub/lite/docs/subscribing for more // information about receiving messages. type SubscriberClient struct { + clientCtx context.Context settings ReceiveSettings wireSubFactory wireSubscriberFactory @@ -265,6 +267,7 @@ func NewSubscriberClientWithSettings(ctx context.Context, subscription string, s options: opts, } subClient := &SubscriberClient{ + clientCtx: ctx, settings: settings, wireSubFactory: factory, } @@ -303,7 +306,7 @@ func (s *SubscriberClient) Receive(ctx context.Context, f func(context.Context, defer s.setReceiveActive(false) // Initialize a subscriber instance. - subInstance, err := newSubscriberInstance(ctx, s.wireSubFactory, s.settings, f) + subInstance, err := newSubscriberInstance(ctx, s.clientCtx, s.wireSubFactory, s.settings, f) if err != nil { return err } diff --git a/pubsublite/pscompat/subscriber_test.go b/pubsublite/pscompat/subscriber_test.go index 429c9f55141..5c737f8ff42 100644 --- a/pubsublite/pscompat/subscriber_test.go +++ b/pubsublite/pscompat/subscriber_test.go @@ -113,7 +113,7 @@ func (ms *mockWireSubscriber) WaitStopped() error { type mockWireSubscriberFactory struct{} -func (f *mockWireSubscriberFactory) New(receiver wire.MessageReceiverFunc) (wire.Subscriber, error) { +func (f *mockWireSubscriberFactory) New(ctx context.Context, receiver wire.MessageReceiverFunc) (wire.Subscriber, error) { return &mockWireSubscriber{ receiver: receiver, msgsC: make(chan *wire.ReceivedMessage, 10), @@ -122,7 +122,7 @@ func (f *mockWireSubscriberFactory) New(receiver wire.MessageReceiverFunc) (wire } func newTestSubscriberInstance(ctx context.Context, settings ReceiveSettings, receiver messageReceiverFunc) *subscriberInstance { - sub, _ := newSubscriberInstance(ctx, new(mockWireSubscriberFactory), settings, receiver) + sub, _ := newSubscriberInstance(ctx, context.Background(), new(mockWireSubscriberFactory), settings, receiver) return sub } diff --git a/recaptchaenterprise/apiv1/doc.go b/recaptchaenterprise/apiv1/doc.go index ffca0f14bbc..25f7abce78e 100644 --- a/recaptchaenterprise/apiv1/doc.go +++ b/recaptchaenterprise/apiv1/doc.go @@ -46,7 +46,7 @@ import ( type clientHookParams struct{} type clientHook func(context.Context, clientHookParams) ([]option.ClientOption, error) -const versionClient = "20210612" +const versionClient = "20210701" func insertMetadata(ctx context.Context, mds ...metadata.MD) context.Context { out, _ := metadata.FromOutgoingContext(ctx) diff --git a/recaptchaenterprise/apiv1/recaptcha_enterprise_client.go b/recaptchaenterprise/apiv1/recaptcha_enterprise_client.go index a844c4d0222..35c8184e0ad 100644 --- a/recaptchaenterprise/apiv1/recaptcha_enterprise_client.go +++ b/recaptchaenterprise/apiv1/recaptcha_enterprise_client.go @@ -23,7 +23,6 @@ import ( "net/url" "time" - "github.com/golang/protobuf/proto" gax "github.com/googleapis/gax-go/v2" "google.golang.org/api/iterator" "google.golang.org/api/option" @@ -32,6 +31,7 @@ import ( recaptchaenterprisepb "google.golang.org/genproto/googleapis/cloud/recaptchaenterprise/v1" "google.golang.org/grpc" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newClientHook clientHook @@ -53,6 +53,7 @@ func defaultGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("recaptchaenterprise.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://recaptchaenterprise.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/recaptchaenterprise/apiv1beta1/doc.go b/recaptchaenterprise/apiv1beta1/doc.go index c99a071410e..d0a1985401a 100644 --- a/recaptchaenterprise/apiv1beta1/doc.go +++ b/recaptchaenterprise/apiv1beta1/doc.go @@ -48,7 +48,7 @@ import ( type clientHookParams struct{} type clientHook func(context.Context, clientHookParams) ([]option.ClientOption, error) -const versionClient = "20210612" +const versionClient = "20210701" func insertMetadata(ctx context.Context, mds ...metadata.MD) context.Context { out, _ := metadata.FromOutgoingContext(ctx) diff --git a/recaptchaenterprise/apiv1beta1/recaptcha_enterprise_service_v1_beta1_client.go b/recaptchaenterprise/apiv1beta1/recaptcha_enterprise_service_v1_beta1_client.go index 8bb1bbb5dd1..14f4f9d8789 100644 --- a/recaptchaenterprise/apiv1beta1/recaptcha_enterprise_service_v1_beta1_client.go +++ b/recaptchaenterprise/apiv1beta1/recaptcha_enterprise_service_v1_beta1_client.go @@ -23,7 +23,6 @@ import ( "net/url" "time" - "github.com/golang/protobuf/proto" gax "github.com/googleapis/gax-go/v2" "google.golang.org/api/iterator" "google.golang.org/api/option" @@ -32,6 +31,7 @@ import ( recaptchaenterprisepb "google.golang.org/genproto/googleapis/cloud/recaptchaenterprise/v1beta1" "google.golang.org/grpc" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newRecaptchaEnterpriseServiceV1Beta1ClientHook clientHook @@ -53,6 +53,7 @@ func defaultRecaptchaEnterpriseServiceV1Beta1GRPCClientOptions() []option.Client internaloption.WithDefaultMTLSEndpoint("recaptchaenterprise.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://recaptchaenterprise.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/recommendationengine/apiv1beta1/doc.go b/recommendationengine/apiv1beta1/doc.go index ddf6c16d07d..e2d95502e79 100644 --- a/recommendationengine/apiv1beta1/doc.go +++ b/recommendationengine/apiv1beta1/doc.go @@ -52,7 +52,7 @@ import ( type clientHookParams struct{} type clientHook func(context.Context, clientHookParams) ([]option.ClientOption, error) -const versionClient = "20210612" +const versionClient = "20210624" func insertMetadata(ctx context.Context, mds ...metadata.MD) context.Context { out, _ := metadata.FromOutgoingContext(ctx) diff --git a/recommender/apiv1/doc.go b/recommender/apiv1/doc.go index 25a08ec3868..34e45a5412d 100644 --- a/recommender/apiv1/doc.go +++ b/recommender/apiv1/doc.go @@ -46,7 +46,7 @@ import ( type clientHookParams struct{} type clientHook func(context.Context, clientHookParams) ([]option.ClientOption, error) -const versionClient = "20210612" +const versionClient = "20210701" func insertMetadata(ctx context.Context, mds ...metadata.MD) context.Context { out, _ := metadata.FromOutgoingContext(ctx) diff --git a/recommender/apiv1/recommender_client.go b/recommender/apiv1/recommender_client.go index 09fb9364b26..970818a5c33 100644 --- a/recommender/apiv1/recommender_client.go +++ b/recommender/apiv1/recommender_client.go @@ -23,7 +23,6 @@ import ( "net/url" "time" - "github.com/golang/protobuf/proto" gax "github.com/googleapis/gax-go/v2" "google.golang.org/api/iterator" "google.golang.org/api/option" @@ -33,6 +32,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newClientHook clientHook @@ -55,6 +55,7 @@ func defaultGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("recommender.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://recommender.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/recommender/apiv1beta1/doc.go b/recommender/apiv1beta1/doc.go index 33bb57b4643..e688e486a37 100644 --- a/recommender/apiv1beta1/doc.go +++ b/recommender/apiv1beta1/doc.go @@ -48,7 +48,7 @@ import ( type clientHookParams struct{} type clientHook func(context.Context, clientHookParams) ([]option.ClientOption, error) -const versionClient = "20210612" +const versionClient = "20210701" func insertMetadata(ctx context.Context, mds ...metadata.MD) context.Context { out, _ := metadata.FromOutgoingContext(ctx) diff --git a/recommender/apiv1beta1/recommender_client.go b/recommender/apiv1beta1/recommender_client.go index fb5414e9b8d..78b7508dfc0 100644 --- a/recommender/apiv1beta1/recommender_client.go +++ b/recommender/apiv1beta1/recommender_client.go @@ -23,7 +23,6 @@ import ( "net/url" "time" - "github.com/golang/protobuf/proto" gax "github.com/googleapis/gax-go/v2" "google.golang.org/api/iterator" "google.golang.org/api/option" @@ -33,6 +32,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newClientHook clientHook @@ -55,6 +55,7 @@ func defaultGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("recommender.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://recommender.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/redis/apiv1/cloud_redis_client.go b/redis/apiv1/cloud_redis_client.go index 9512205699c..513bb8ec2a5 100644 --- a/redis/apiv1/cloud_redis_client.go +++ b/redis/apiv1/cloud_redis_client.go @@ -25,7 +25,6 @@ import ( "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" @@ -35,6 +34,7 @@ import ( longrunningpb "google.golang.org/genproto/googleapis/longrunning" "google.golang.org/grpc" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newCloudRedisClientHook clientHook @@ -58,6 +58,7 @@ func defaultCloudRedisGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("redis.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://redis.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/redis/apiv1/doc.go b/redis/apiv1/doc.go index 6c063479359..88c276f4a1c 100644 --- a/redis/apiv1/doc.go +++ b/redis/apiv1/doc.go @@ -48,7 +48,7 @@ import ( type clientHookParams struct{} type clientHook func(context.Context, clientHookParams) ([]option.ClientOption, error) -const versionClient = "20210612" +const versionClient = "20210701" func insertMetadata(ctx context.Context, mds ...metadata.MD) context.Context { out, _ := metadata.FromOutgoingContext(ctx) diff --git a/redis/apiv1beta1/cloud_redis_client.go b/redis/apiv1beta1/cloud_redis_client.go index a31e5147a0f..6d4ed1fe6b2 100644 --- a/redis/apiv1beta1/cloud_redis_client.go +++ b/redis/apiv1beta1/cloud_redis_client.go @@ -25,7 +25,6 @@ import ( "cloud.google.com/go/longrunning" lroauto "cloud.google.com/go/longrunning/autogen" - "github.com/golang/protobuf/proto" anypb "github.com/golang/protobuf/ptypes/any" gax "github.com/googleapis/gax-go/v2" "google.golang.org/api/iterator" @@ -36,6 +35,7 @@ import ( longrunningpb "google.golang.org/genproto/googleapis/longrunning" "google.golang.org/grpc" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newCloudRedisClientHook clientHook @@ -59,6 +59,7 @@ func defaultCloudRedisGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("redis.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://redis.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/redis/apiv1beta1/doc.go b/redis/apiv1beta1/doc.go index 817b3d05ad9..2db6db9eb5e 100644 --- a/redis/apiv1beta1/doc.go +++ b/redis/apiv1beta1/doc.go @@ -50,7 +50,7 @@ import ( type clientHookParams struct{} type clientHook func(context.Context, clientHookParams) ([]option.ClientOption, error) -const versionClient = "20210612" +const versionClient = "20210701" func insertMetadata(ctx context.Context, mds ...metadata.MD) context.Context { out, _ := metadata.FromOutgoingContext(ctx) diff --git a/resourcemanager/apiv2/doc.go b/resourcemanager/apiv2/doc.go index 495d5f230a1..64f94499fea 100644 --- a/resourcemanager/apiv2/doc.go +++ b/resourcemanager/apiv2/doc.go @@ -49,7 +49,7 @@ import ( type clientHookParams struct{} type clientHook func(context.Context, clientHookParams) ([]option.ClientOption, error) -const versionClient = "20210612" +const versionClient = "20210701" func insertMetadata(ctx context.Context, mds ...metadata.MD) context.Context { out, _ := metadata.FromOutgoingContext(ctx) diff --git a/resourcemanager/apiv2/folders_client.go b/resourcemanager/apiv2/folders_client.go index a5bc2ffd578..647b4f42190 100644 --- a/resourcemanager/apiv2/folders_client.go +++ b/resourcemanager/apiv2/folders_client.go @@ -25,7 +25,6 @@ import ( "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" @@ -36,6 +35,7 @@ import ( longrunningpb "google.golang.org/genproto/googleapis/longrunning" "google.golang.org/grpc" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newFoldersClientHook clientHook @@ -61,6 +61,7 @@ func defaultFoldersGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("cloudresourcemanager.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://cloudresourcemanager.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/resourcesettings/apiv1/doc.go b/resourcesettings/apiv1/doc.go index f972343d62a..0a8ab6112d9 100644 --- a/resourcesettings/apiv1/doc.go +++ b/resourcesettings/apiv1/doc.go @@ -21,8 +21,6 @@ // of their GCP resources (e.g., VM, firewall, Project, etc.) across the // Cloud Resource Hierarchy. // -// 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 @@ -52,7 +50,7 @@ import ( type clientHookParams struct{} type clientHook func(context.Context, clientHookParams) ([]option.ClientOption, error) -const versionClient = "20210612" +const versionClient = "20210701" func insertMetadata(ctx context.Context, mds ...metadata.MD) context.Context { out, _ := metadata.FromOutgoingContext(ctx) diff --git a/resourcesettings/apiv1/resource_settings_client.go b/resourcesettings/apiv1/resource_settings_client.go index ca109f991f2..90df08f7465 100644 --- a/resourcesettings/apiv1/resource_settings_client.go +++ b/resourcesettings/apiv1/resource_settings_client.go @@ -23,7 +23,6 @@ import ( "net/url" "time" - "github.com/golang/protobuf/proto" gax "github.com/googleapis/gax-go/v2" "google.golang.org/api/iterator" "google.golang.org/api/option" @@ -33,6 +32,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newClientHook clientHook @@ -50,6 +50,7 @@ func defaultGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("resourcesettings.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://resourcesettings.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/retail/apiv2/catalog_client.go b/retail/apiv2/catalog_client.go index aec48be83c6..9dcf9fa8f79 100644 --- a/retail/apiv2/catalog_client.go +++ b/retail/apiv2/catalog_client.go @@ -23,7 +23,6 @@ import ( "net/url" "time" - "github.com/golang/protobuf/proto" gax "github.com/googleapis/gax-go/v2" "google.golang.org/api/iterator" "google.golang.org/api/option" @@ -33,6 +32,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newCatalogClientHook clientHook @@ -49,6 +49,7 @@ func defaultCatalogGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("retail.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://retail.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/retail/apiv2/doc.go b/retail/apiv2/doc.go index e5e7c73591d..e11dd65c9d1 100644 --- a/retail/apiv2/doc.go +++ b/retail/apiv2/doc.go @@ -50,7 +50,7 @@ import ( type clientHookParams struct{} type clientHook func(context.Context, clientHookParams) ([]option.ClientOption, error) -const versionClient = "20210612" +const versionClient = "20210701" func insertMetadata(ctx context.Context, mds ...metadata.MD) context.Context { out, _ := metadata.FromOutgoingContext(ctx) diff --git a/retail/apiv2/prediction_client.go b/retail/apiv2/prediction_client.go index a07bba9331d..6e0f384adcc 100644 --- a/retail/apiv2/prediction_client.go +++ b/retail/apiv2/prediction_client.go @@ -46,6 +46,7 @@ func defaultPredictionGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("retail.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://retail.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/retail/apiv2/product_client.go b/retail/apiv2/product_client.go index 93054baf414..44cb5bbc0ea 100644 --- a/retail/apiv2/product_client.go +++ b/retail/apiv2/product_client.go @@ -53,6 +53,7 @@ func defaultProductGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("retail.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://retail.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/retail/apiv2/user_event_client.go b/retail/apiv2/user_event_client.go index 28f6e7ec233..b4cc464f4f6 100644 --- a/retail/apiv2/user_event_client.go +++ b/retail/apiv2/user_event_client.go @@ -54,6 +54,7 @@ func defaultUserEventGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("retail.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://retail.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/scheduler/apiv1/cloud_scheduler_client.go b/scheduler/apiv1/cloud_scheduler_client.go index 303d89be095..b8452e56e52 100644 --- a/scheduler/apiv1/cloud_scheduler_client.go +++ b/scheduler/apiv1/cloud_scheduler_client.go @@ -23,7 +23,6 @@ import ( "net/url" "time" - "github.com/golang/protobuf/proto" gax "github.com/googleapis/gax-go/v2" "google.golang.org/api/iterator" "google.golang.org/api/option" @@ -33,6 +32,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newCloudSchedulerClientHook clientHook @@ -55,6 +55,7 @@ func defaultCloudSchedulerGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("cloudscheduler.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://cloudscheduler.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/scheduler/apiv1/doc.go b/scheduler/apiv1/doc.go index f3e2743fbe0..2ee425905fe 100644 --- a/scheduler/apiv1/doc.go +++ b/scheduler/apiv1/doc.go @@ -48,7 +48,7 @@ import ( type clientHookParams struct{} type clientHook func(context.Context, clientHookParams) ([]option.ClientOption, error) -const versionClient = "20210612" +const versionClient = "20210701" func insertMetadata(ctx context.Context, mds ...metadata.MD) context.Context { out, _ := metadata.FromOutgoingContext(ctx) diff --git a/scheduler/apiv1beta1/cloud_scheduler_client.go b/scheduler/apiv1beta1/cloud_scheduler_client.go index 9ec0cb77023..3c9e663d978 100644 --- a/scheduler/apiv1beta1/cloud_scheduler_client.go +++ b/scheduler/apiv1beta1/cloud_scheduler_client.go @@ -23,7 +23,6 @@ import ( "net/url" "time" - "github.com/golang/protobuf/proto" gax "github.com/googleapis/gax-go/v2" "google.golang.org/api/iterator" "google.golang.org/api/option" @@ -33,6 +32,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newCloudSchedulerClientHook clientHook @@ -55,6 +55,7 @@ func defaultCloudSchedulerGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("cloudscheduler.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://cloudscheduler.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/scheduler/apiv1beta1/doc.go b/scheduler/apiv1beta1/doc.go index 1f65d87e86a..4814fa38d3a 100644 --- a/scheduler/apiv1beta1/doc.go +++ b/scheduler/apiv1beta1/doc.go @@ -50,7 +50,7 @@ import ( type clientHookParams struct{} type clientHook func(context.Context, clientHookParams) ([]option.ClientOption, error) -const versionClient = "20210612" +const versionClient = "20210701" func insertMetadata(ctx context.Context, mds ...metadata.MD) context.Context { out, _ := metadata.FromOutgoingContext(ctx) diff --git a/secretmanager/apiv1/doc.go b/secretmanager/apiv1/doc.go index 6456f2382e2..80bb5b816a7 100644 --- a/secretmanager/apiv1/doc.go +++ b/secretmanager/apiv1/doc.go @@ -49,7 +49,7 @@ import ( type clientHookParams struct{} type clientHook func(context.Context, clientHookParams) ([]option.ClientOption, error) -const versionClient = "20210612" +const versionClient = "20210701" func insertMetadata(ctx context.Context, mds ...metadata.MD) context.Context { out, _ := metadata.FromOutgoingContext(ctx) diff --git a/secretmanager/apiv1/secret_manager_client.go b/secretmanager/apiv1/secret_manager_client.go index b6e735954fe..eb17f812bed 100644 --- a/secretmanager/apiv1/secret_manager_client.go +++ b/secretmanager/apiv1/secret_manager_client.go @@ -23,7 +23,6 @@ import ( "net/url" "time" - "github.com/golang/protobuf/proto" gax "github.com/googleapis/gax-go/v2" "google.golang.org/api/iterator" "google.golang.org/api/option" @@ -34,6 +33,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newClientHook clientHook @@ -63,6 +63,7 @@ func defaultGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("secretmanager.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://secretmanager.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/secretmanager/apiv1beta1/doc.go b/secretmanager/apiv1beta1/doc.go index 18740d2e74e..b0a58a1ed99 100644 --- a/secretmanager/apiv1beta1/doc.go +++ b/secretmanager/apiv1beta1/doc.go @@ -51,7 +51,7 @@ import ( type clientHookParams struct{} type clientHook func(context.Context, clientHookParams) ([]option.ClientOption, error) -const versionClient = "20210612" +const versionClient = "20210701" func insertMetadata(ctx context.Context, mds ...metadata.MD) context.Context { out, _ := metadata.FromOutgoingContext(ctx) diff --git a/secretmanager/apiv1beta1/secret_manager_client.go b/secretmanager/apiv1beta1/secret_manager_client.go index 1be0e0142ba..6a5dcab8395 100644 --- a/secretmanager/apiv1beta1/secret_manager_client.go +++ b/secretmanager/apiv1beta1/secret_manager_client.go @@ -23,7 +23,6 @@ import ( "net/url" "time" - "github.com/golang/protobuf/proto" gax "github.com/googleapis/gax-go/v2" "google.golang.org/api/iterator" "google.golang.org/api/option" @@ -34,6 +33,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newClientHook clientHook @@ -63,6 +63,7 @@ func defaultGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("secretmanager.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://secretmanager.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/security/privateca/apiv1/certificate_authority_client.go b/security/privateca/apiv1/certificate_authority_client.go index 3866f65828c..e8526626769 100644 --- a/security/privateca/apiv1/certificate_authority_client.go +++ b/security/privateca/apiv1/certificate_authority_client.go @@ -25,7 +25,6 @@ import ( "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" @@ -36,6 +35,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newCertificateAuthorityClientHook clientHook @@ -79,6 +79,7 @@ func defaultCertificateAuthorityGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("privateca.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://privateca.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/security/privateca/apiv1/doc.go b/security/privateca/apiv1/doc.go index b08acff0edf..4b0d63a0d11 100644 --- a/security/privateca/apiv1/doc.go +++ b/security/privateca/apiv1/doc.go @@ -22,8 +22,6 @@ // private certificate authorities (CAs) while staying in control of your // private keys." // -// 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 @@ -53,7 +51,7 @@ import ( type clientHookParams struct{} type clientHook func(context.Context, clientHookParams) ([]option.ClientOption, error) -const versionClient = "20210617" +const versionClient = "20210701" func insertMetadata(ctx context.Context, mds ...metadata.MD) context.Context { out, _ := metadata.FromOutgoingContext(ctx) diff --git a/security/privateca/apiv1beta1/certificate_authority_client.go b/security/privateca/apiv1beta1/certificate_authority_client.go index 2dcfc4c1354..4f5f9c043e5 100644 --- a/security/privateca/apiv1beta1/certificate_authority_client.go +++ b/security/privateca/apiv1beta1/certificate_authority_client.go @@ -25,7 +25,6 @@ import ( "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" @@ -36,6 +35,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newCertificateAuthorityClientHook clientHook @@ -70,6 +70,7 @@ func defaultCertificateAuthorityGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("privateca.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://privateca.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/security/privateca/apiv1beta1/doc.go b/security/privateca/apiv1beta1/doc.go index 9ccc060ef6b..469b3288171 100644 --- a/security/privateca/apiv1beta1/doc.go +++ b/security/privateca/apiv1beta1/doc.go @@ -48,7 +48,7 @@ import ( type clientHookParams struct{} type clientHook func(context.Context, clientHookParams) ([]option.ClientOption, error) -const versionClient = "20210612" +const versionClient = "20210701" func insertMetadata(ctx context.Context, mds ...metadata.MD) context.Context { out, _ := metadata.FromOutgoingContext(ctx) diff --git a/securitycenter/apiv1/doc.go b/securitycenter/apiv1/doc.go index 68b359c489e..5a1c5e3d4bf 100644 --- a/securitycenter/apiv1/doc.go +++ b/securitycenter/apiv1/doc.go @@ -49,7 +49,7 @@ import ( type clientHookParams struct{} type clientHook func(context.Context, clientHookParams) ([]option.ClientOption, error) -const versionClient = "20210612" +const versionClient = "20210701" func insertMetadata(ctx context.Context, mds ...metadata.MD) context.Context { out, _ := metadata.FromOutgoingContext(ctx) diff --git a/securitycenter/apiv1/security_center_client.go b/securitycenter/apiv1/security_center_client.go index 30cbaffc834..f9fa23a6181 100644 --- a/securitycenter/apiv1/security_center_client.go +++ b/securitycenter/apiv1/security_center_client.go @@ -25,7 +25,6 @@ import ( "cloud.google.com/go/longrunning" lroauto "cloud.google.com/go/longrunning/autogen" - "github.com/golang/protobuf/proto" emptypb "github.com/golang/protobuf/ptypes/empty" gax "github.com/googleapis/gax-go/v2" "google.golang.org/api/iterator" @@ -38,6 +37,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newClientHook clientHook @@ -75,6 +75,7 @@ func defaultGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("securitycenter.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://securitycenter.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/securitycenter/apiv1beta1/doc.go b/securitycenter/apiv1beta1/doc.go index 2d6e15815ed..2d9d312d199 100644 --- a/securitycenter/apiv1beta1/doc.go +++ b/securitycenter/apiv1beta1/doc.go @@ -51,7 +51,7 @@ import ( type clientHookParams struct{} type clientHook func(context.Context, clientHookParams) ([]option.ClientOption, error) -const versionClient = "20210612" +const versionClient = "20210701" func insertMetadata(ctx context.Context, mds ...metadata.MD) context.Context { out, _ := metadata.FromOutgoingContext(ctx) diff --git a/securitycenter/apiv1beta1/security_center_client.go b/securitycenter/apiv1beta1/security_center_client.go index faef96b77b4..1068c0c2b9a 100644 --- a/securitycenter/apiv1beta1/security_center_client.go +++ b/securitycenter/apiv1beta1/security_center_client.go @@ -25,7 +25,6 @@ import ( "cloud.google.com/go/longrunning" lroauto "cloud.google.com/go/longrunning/autogen" - "github.com/golang/protobuf/proto" emptypb "github.com/golang/protobuf/ptypes/empty" gax "github.com/googleapis/gax-go/v2" "google.golang.org/api/iterator" @@ -38,6 +37,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newClientHook clientHook @@ -70,6 +70,7 @@ func defaultGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("securitycenter.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://securitycenter.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/securitycenter/apiv1p1beta1/doc.go b/securitycenter/apiv1p1beta1/doc.go index d11dca063a0..e84de24b574 100644 --- a/securitycenter/apiv1p1beta1/doc.go +++ b/securitycenter/apiv1p1beta1/doc.go @@ -51,7 +51,7 @@ import ( type clientHookParams struct{} type clientHook func(context.Context, clientHookParams) ([]option.ClientOption, error) -const versionClient = "20210612" +const versionClient = "20210701" func insertMetadata(ctx context.Context, mds ...metadata.MD) context.Context { out, _ := metadata.FromOutgoingContext(ctx) diff --git a/securitycenter/apiv1p1beta1/security_center_client.go b/securitycenter/apiv1p1beta1/security_center_client.go index c6abd15f6a2..a61c3830b4c 100644 --- a/securitycenter/apiv1p1beta1/security_center_client.go +++ b/securitycenter/apiv1p1beta1/security_center_client.go @@ -25,7 +25,6 @@ import ( "cloud.google.com/go/longrunning" lroauto "cloud.google.com/go/longrunning/autogen" - "github.com/golang/protobuf/proto" emptypb "github.com/golang/protobuf/ptypes/empty" gax "github.com/googleapis/gax-go/v2" "google.golang.org/api/iterator" @@ -38,6 +37,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newClientHook clientHook @@ -75,6 +75,7 @@ func defaultGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("securitycenter.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://securitycenter.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/securitycenter/settings/apiv1beta1/doc.go b/securitycenter/settings/apiv1beta1/doc.go index 26dd0350710..dc35f507e48 100644 --- a/securitycenter/settings/apiv1beta1/doc.go +++ b/securitycenter/settings/apiv1beta1/doc.go @@ -51,7 +51,7 @@ import ( type clientHookParams struct{} type clientHook func(context.Context, clientHookParams) ([]option.ClientOption, error) -const versionClient = "20210612" +const versionClient = "20210701" func insertMetadata(ctx context.Context, mds ...metadata.MD) context.Context { out, _ := metadata.FromOutgoingContext(ctx) diff --git a/securitycenter/settings/apiv1beta1/security_center_settings_client.go b/securitycenter/settings/apiv1beta1/security_center_settings_client.go index 6937378ba46..4e97fad52f4 100644 --- a/securitycenter/settings/apiv1beta1/security_center_settings_client.go +++ b/securitycenter/settings/apiv1beta1/security_center_settings_client.go @@ -23,7 +23,6 @@ import ( "net/url" "time" - "github.com/golang/protobuf/proto" gax "github.com/googleapis/gax-go/v2" "google.golang.org/api/iterator" "google.golang.org/api/option" @@ -33,6 +32,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newSecurityCenterSettingsClientHook clientHook @@ -60,6 +60,7 @@ func defaultSecurityCenterSettingsGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("securitycenter.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://securitycenter.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/servicecontrol/apiv1/doc.go b/servicecontrol/apiv1/doc.go index 9aca6d9cb05..5995fa3623c 100644 --- a/servicecontrol/apiv1/doc.go +++ b/servicecontrol/apiv1/doc.go @@ -17,8 +17,8 @@ // Package servicecontrol is an auto-generated package for the // Service Control API. // -// Provides control plane functionality to managed services, such as logging, -// monitoring, and status checks. +// Provides admission control and telemetry reporting for services integrated +// with Service Infrastructure. // // Use of Context // @@ -49,7 +49,7 @@ import ( type clientHookParams struct{} type clientHook func(context.Context, clientHookParams) ([]option.ClientOption, error) -const versionClient = "20210612" +const versionClient = "20210701" func insertMetadata(ctx context.Context, mds ...metadata.MD) context.Context { out, _ := metadata.FromOutgoingContext(ctx) diff --git a/servicecontrol/apiv1/quota_controller_client.go b/servicecontrol/apiv1/quota_controller_client.go index 531210a45b9..d8fe6b93b86 100644 --- a/servicecontrol/apiv1/quota_controller_client.go +++ b/servicecontrol/apiv1/quota_controller_client.go @@ -44,6 +44,7 @@ func defaultQuotaControllerGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("servicecontrol.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://servicecontrol.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), @@ -67,7 +68,7 @@ type internalQuotaControllerClient interface { // QuotaControllerClient is a client for interacting with Service Control API. // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. // -// Google Quota Control API (at https://cloud.google.com/service-control/overview) +// Google Quota Control API (at /service-control/overview) // // Allows clients to allocate and release quota against a managed // service (at https://cloud.google.com/service-management/reference/rpc/google.api/servicemanagement.v1#google.api.servicemanagement.v1.ManagedService). @@ -139,7 +140,7 @@ type quotaControllerGRPCClient struct { // NewQuotaControllerClient creates a new quota controller client based on gRPC. // The returned client must be Closed when it is done being used to clean up its underlying connections. // -// Google Quota Control API (at https://cloud.google.com/service-control/overview) +// Google Quota Control API (at /service-control/overview) // // Allows clients to allocate and release quota against a managed // service (at https://cloud.google.com/service-management/reference/rpc/google.api/servicemanagement.v1#google.api.servicemanagement.v1.ManagedService). diff --git a/servicecontrol/apiv1/service_controller_client.go b/servicecontrol/apiv1/service_controller_client.go index e7541ad1428..6755e31039a 100644 --- a/servicecontrol/apiv1/service_controller_client.go +++ b/servicecontrol/apiv1/service_controller_client.go @@ -45,6 +45,7 @@ func defaultServiceControllerGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("servicecontrol.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://servicecontrol.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), @@ -70,7 +71,7 @@ type internalServiceControllerClient interface { // ServiceControllerClient is a client for interacting with Service Control API. // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. // -// Google Service Control API (at https://cloud.google.com/service-control/overview) +// Google Service Control API (at /service-control/overview) // // Lets clients check and report operations against a managed // service (at https://cloud.google.com/service-management/reference/rpc/google.api/servicemanagement.v1#google.api.servicemanagement.v1.ManagedService). @@ -115,7 +116,8 @@ func (c *ServiceControllerClient) Connection() *grpc.ClientConn { // propagation, therefore callers MUST NOT depend on the Check method having // the latest policy information. // -// NOTE: the CheckRequest has the size limit of 64KB. +// NOTE: the CheckRequest has +// the size limit (wire-format byte size) of 1MB. // // This method requires the servicemanagement.services.check permission // on the specified service. For more information, see @@ -133,8 +135,8 @@ func (c *ServiceControllerClient) Check(ctx context.Context, req *servicecontrol // the aggregation time window to avoid data loss risk more than 0.01% // for business and compliance reasons. // -// NOTE: the ReportRequest has the size limit (wire-format byte size) of -// 1MB. +// NOTE: the ReportRequest has +// the size limit (wire-format byte size) of 1MB. // // This method requires the servicemanagement.services.report permission // on the specified service. For more information, see @@ -166,7 +168,7 @@ type serviceControllerGRPCClient struct { // NewServiceControllerClient creates a new service controller client based on gRPC. // The returned client must be Closed when it is done being used to clean up its underlying connections. // -// Google Service Control API (at https://cloud.google.com/service-control/overview) +// Google Service Control API (at /service-control/overview) // // Lets clients check and report operations against a managed // service (at https://cloud.google.com/service-management/reference/rpc/google.api/servicemanagement.v1#google.api.servicemanagement.v1.ManagedService). diff --git a/servicedirectory/apiv1/doc.go b/servicedirectory/apiv1/doc.go index f93f136dbf0..2f164c581b0 100644 --- a/servicedirectory/apiv1/doc.go +++ b/servicedirectory/apiv1/doc.go @@ -49,7 +49,7 @@ import ( type clientHookParams struct{} type clientHook func(context.Context, clientHookParams) ([]option.ClientOption, error) -const versionClient = "20210612" +const versionClient = "20210701" func insertMetadata(ctx context.Context, mds ...metadata.MD) context.Context { out, _ := metadata.FromOutgoingContext(ctx) diff --git a/servicedirectory/apiv1/lookup_client.go b/servicedirectory/apiv1/lookup_client.go index 703884d9612..c11a74ac8d4 100644 --- a/servicedirectory/apiv1/lookup_client.go +++ b/servicedirectory/apiv1/lookup_client.go @@ -46,6 +46,7 @@ func defaultLookupGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("servicedirectory.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://servicedirectory.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/servicedirectory/apiv1/registration_client.go b/servicedirectory/apiv1/registration_client.go index 3d34574d02a..00256e4996e 100644 --- a/servicedirectory/apiv1/registration_client.go +++ b/servicedirectory/apiv1/registration_client.go @@ -23,7 +23,6 @@ import ( "net/url" "time" - "github.com/golang/protobuf/proto" gax "github.com/googleapis/gax-go/v2" "google.golang.org/api/iterator" "google.golang.org/api/option" @@ -34,6 +33,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newRegistrationClientHook clientHook @@ -66,6 +66,7 @@ func defaultRegistrationGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("servicedirectory.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://servicedirectory.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/servicedirectory/apiv1beta1/doc.go b/servicedirectory/apiv1beta1/doc.go index 19602a22a18..fa7b8e51b9f 100644 --- a/servicedirectory/apiv1beta1/doc.go +++ b/servicedirectory/apiv1beta1/doc.go @@ -17,7 +17,8 @@ // Package servicedirectory is an auto-generated package for the // Service Directory API. // -// Allows the registration and lookup of services. +// Service Directory is a platform for discovering, publishing, and +// connecting services. // // NOTE: This package is in beta. It is not stable, and may be subject to changes. // @@ -50,7 +51,7 @@ import ( type clientHookParams struct{} type clientHook func(context.Context, clientHookParams) ([]option.ClientOption, error) -const versionClient = "20210612" +const versionClient = "20210701" func insertMetadata(ctx context.Context, mds ...metadata.MD) context.Context { out, _ := metadata.FromOutgoingContext(ctx) diff --git a/servicedirectory/apiv1beta1/lookup_client.go b/servicedirectory/apiv1beta1/lookup_client.go index 5d2aa982639..c0ff1660231 100644 --- a/servicedirectory/apiv1beta1/lookup_client.go +++ b/servicedirectory/apiv1beta1/lookup_client.go @@ -46,6 +46,7 @@ func defaultLookupGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("servicedirectory.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://servicedirectory.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/servicedirectory/apiv1beta1/registration_client.go b/servicedirectory/apiv1beta1/registration_client.go index fd720de9409..deda537b10e 100644 --- a/servicedirectory/apiv1beta1/registration_client.go +++ b/servicedirectory/apiv1beta1/registration_client.go @@ -23,7 +23,6 @@ import ( "net/url" "time" - "github.com/golang/protobuf/proto" gax "github.com/googleapis/gax-go/v2" "google.golang.org/api/iterator" "google.golang.org/api/option" @@ -34,6 +33,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newRegistrationClientHook clientHook @@ -66,6 +66,7 @@ func defaultRegistrationGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("servicedirectory.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://servicedirectory.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), @@ -366,7 +367,7 @@ func (c *RegistrationClient) Connection() *grpc.ClientConn { return c.internalClient.Connection() } -// CreateNamespace creates a namespace, and returns the new Namespace. +// CreateNamespace creates a namespace, and returns the new namespace. func (c *RegistrationClient) CreateNamespace(ctx context.Context, req *servicedirectorypb.CreateNamespaceRequest, opts ...gax.CallOption) (*servicedirectorypb.Namespace, error) { return c.internalClient.CreateNamespace(ctx, req, opts...) } @@ -392,7 +393,7 @@ func (c *RegistrationClient) DeleteNamespace(ctx context.Context, req *servicedi return c.internalClient.DeleteNamespace(ctx, req, opts...) } -// CreateService creates a service, and returns the new Service. +// CreateService creates a service, and returns the new service. func (c *RegistrationClient) CreateService(ctx context.Context, req *servicedirectorypb.CreateServiceRequest, opts ...gax.CallOption) (*servicedirectorypb.Service, error) { return c.internalClient.CreateService(ctx, req, opts...) } @@ -418,7 +419,7 @@ func (c *RegistrationClient) DeleteService(ctx context.Context, req *servicedire return c.internalClient.DeleteService(ctx, req, opts...) } -// CreateEndpoint creates a endpoint, and returns the new Endpoint. +// CreateEndpoint creates an endpoint, and returns the new endpoint. func (c *RegistrationClient) CreateEndpoint(ctx context.Context, req *servicedirectorypb.CreateEndpointRequest, opts ...gax.CallOption) (*servicedirectorypb.Endpoint, error) { return c.internalClient.CreateEndpoint(ctx, req, opts...) } @@ -428,17 +429,17 @@ func (c *RegistrationClient) ListEndpoints(ctx context.Context, req *servicedire return c.internalClient.ListEndpoints(ctx, req, opts...) } -// GetEndpoint gets a endpoint. +// GetEndpoint gets an endpoint. func (c *RegistrationClient) GetEndpoint(ctx context.Context, req *servicedirectorypb.GetEndpointRequest, opts ...gax.CallOption) (*servicedirectorypb.Endpoint, error) { return c.internalClient.GetEndpoint(ctx, req, opts...) } -// UpdateEndpoint updates a endpoint. +// UpdateEndpoint updates an endpoint. func (c *RegistrationClient) UpdateEndpoint(ctx context.Context, req *servicedirectorypb.UpdateEndpointRequest, opts ...gax.CallOption) (*servicedirectorypb.Endpoint, error) { return c.internalClient.UpdateEndpoint(ctx, req, opts...) } -// DeleteEndpoint deletes a endpoint. +// DeleteEndpoint deletes an endpoint. func (c *RegistrationClient) DeleteEndpoint(ctx context.Context, req *servicedirectorypb.DeleteEndpointRequest, opts ...gax.CallOption) error { return c.internalClient.DeleteEndpoint(ctx, req, opts...) } diff --git a/servicemanagement/apiv1/doc.go b/servicemanagement/apiv1/doc.go index dd2760f31c6..7b126a8d0d4 100644 --- a/servicemanagement/apiv1/doc.go +++ b/servicemanagement/apiv1/doc.go @@ -50,7 +50,7 @@ import ( type clientHookParams struct{} type clientHook func(context.Context, clientHookParams) ([]option.ClientOption, error) -const versionClient = "20210612" +const versionClient = "20210701" func insertMetadata(ctx context.Context, mds ...metadata.MD) context.Context { out, _ := metadata.FromOutgoingContext(ctx) diff --git a/servicemanagement/apiv1/service_manager_client.go b/servicemanagement/apiv1/service_manager_client.go index 8069cc18457..c9ee320b88c 100644 --- a/servicemanagement/apiv1/service_manager_client.go +++ b/servicemanagement/apiv1/service_manager_client.go @@ -25,7 +25,6 @@ import ( "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" @@ -36,6 +35,7 @@ import ( longrunningpb "google.golang.org/genproto/googleapis/longrunning" "google.golang.org/grpc" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newServiceManagerClientHook clientHook @@ -65,6 +65,7 @@ func defaultServiceManagerGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("servicemanagement.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://servicemanagement.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/serviceusage/apiv1/doc.go b/serviceusage/apiv1/doc.go index 3e8607a539c..85c71b37b55 100644 --- a/serviceusage/apiv1/doc.go +++ b/serviceusage/apiv1/doc.go @@ -21,8 +21,6 @@ // Platform, lists the available or enabled services, or disables services // that service consumers no longer use. // -// 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 @@ -52,7 +50,7 @@ import ( type clientHookParams struct{} type clientHook func(context.Context, clientHookParams) ([]option.ClientOption, error) -const versionClient = "20210612" +const versionClient = "20210701" func insertMetadata(ctx context.Context, mds ...metadata.MD) context.Context { out, _ := metadata.FromOutgoingContext(ctx) diff --git a/serviceusage/apiv1/service_usage_client.go b/serviceusage/apiv1/service_usage_client.go index 2865f4750d2..acba7fe148d 100644 --- a/serviceusage/apiv1/service_usage_client.go +++ b/serviceusage/apiv1/service_usage_client.go @@ -25,7 +25,6 @@ import ( "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" @@ -35,6 +34,7 @@ import ( longrunningpb "google.golang.org/genproto/googleapis/longrunning" "google.golang.org/grpc" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newClientHook clientHook @@ -55,6 +55,7 @@ func defaultGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("serviceusage.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://serviceusage.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/shell/apiv1/cloud_shell_client.go b/shell/apiv1/cloud_shell_client.go index 8917de48634..6f3affcf05b 100644 --- a/shell/apiv1/cloud_shell_client.go +++ b/shell/apiv1/cloud_shell_client.go @@ -53,6 +53,7 @@ func defaultCloudShellGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("cloudshell.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://cloudshell.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/shell/apiv1/doc.go b/shell/apiv1/doc.go index b4bf82126c5..519481b1aaf 100644 --- a/shell/apiv1/doc.go +++ b/shell/apiv1/doc.go @@ -51,7 +51,7 @@ import ( type clientHookParams struct{} type clientHook func(context.Context, clientHookParams) ([]option.ClientOption, error) -const versionClient = "20210612" +const versionClient = "20210701" func insertMetadata(ctx context.Context, mds ...metadata.MD) context.Context { out, _ := metadata.FromOutgoingContext(ctx) diff --git a/spanner/CHANGES.md b/spanner/CHANGES.md index c54c4915a31..7e8c701e379 100644 --- a/spanner/CHANGES.md +++ b/spanner/CHANGES.md @@ -1,5 +1,20 @@ # Changes +## [1.22.0](https://www.github.com/googleapis/google-cloud-go/compare/spanner/v1.21.0...spanner/v1.22.0) (2021-06-30) + + +### Features + +* **spanner:** support request and transaction tags ([#4336](https://www.github.com/googleapis/google-cloud-go/issues/4336)) ([f08c73a](https://www.github.com/googleapis/google-cloud-go/commit/f08c73a75e2d2a8b9a0b184179346cb97c82e9e5)) +* **spanner:** enable request options for batch read ([#4337](https://www.github.com/googleapis/google-cloud-go/issues/4337)) ([b9081c3](https://www.github.com/googleapis/google-cloud-go/commit/b9081c36ed6495a67f8e458ad884bdb8da5b7fbc)) + +## [1.21.0](https://www.github.com/googleapis/google-cloud-go/compare/spanner/v1.20.0...spanner/v1.21.0) (2021-06-23) + + +### Miscellaneous Chores + +* **spanner:** trigger a release for low cost instance ([#4264](https://www.github.com/googleapis/google-cloud-go/issues/4264)) ([24c4451](https://www.github.com/googleapis/google-cloud-go/commit/24c4451404cdf4a83cc7a35ee1911d654d2ba132)) + ## [1.20.0](https://www.github.com/googleapis/google-cloud-go/compare/spanner/v1.19.0...spanner/v1.20.0) (2021-06-08) diff --git a/spanner/admin/database/apiv1/database_admin_client.go b/spanner/admin/database/apiv1/database_admin_client.go index 20f6dcfb4be..6829ec0e5ef 100644 --- a/spanner/admin/database/apiv1/database_admin_client.go +++ b/spanner/admin/database/apiv1/database_admin_client.go @@ -25,7 +25,6 @@ import ( "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" @@ -37,6 +36,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newDatabaseAdminClientHook clientHook @@ -68,6 +68,7 @@ func defaultDatabaseAdminGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("spanner.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://spanner.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/spanner/admin/database/apiv1/doc.go b/spanner/admin/database/apiv1/doc.go index 850b41026c6..9830571ea07 100644 --- a/spanner/admin/database/apiv1/doc.go +++ b/spanner/admin/database/apiv1/doc.go @@ -46,7 +46,7 @@ import ( type clientHookParams struct{} type clientHook func(context.Context, clientHookParams) ([]option.ClientOption, error) -const versionClient = "20210612" +const versionClient = "20210701" func insertMetadata(ctx context.Context, mds ...metadata.MD) context.Context { out, _ := metadata.FromOutgoingContext(ctx) diff --git a/spanner/admin/instance/apiv1/doc.go b/spanner/admin/instance/apiv1/doc.go index dd79429bdf7..eb313b2c3c1 100644 --- a/spanner/admin/instance/apiv1/doc.go +++ b/spanner/admin/instance/apiv1/doc.go @@ -46,7 +46,7 @@ import ( type clientHookParams struct{} type clientHook func(context.Context, clientHookParams) ([]option.ClientOption, error) -const versionClient = "20210612" +const versionClient = "20210701" func insertMetadata(ctx context.Context, mds ...metadata.MD) context.Context { out, _ := metadata.FromOutgoingContext(ctx) diff --git a/spanner/admin/instance/apiv1/instance_admin_client.go b/spanner/admin/instance/apiv1/instance_admin_client.go index be3e807205e..a5441e56aaa 100644 --- a/spanner/admin/instance/apiv1/instance_admin_client.go +++ b/spanner/admin/instance/apiv1/instance_admin_client.go @@ -25,7 +25,6 @@ import ( "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" @@ -37,6 +36,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newInstanceAdminClientHook clientHook @@ -61,6 +61,7 @@ func defaultInstanceAdminGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("spanner.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://spanner.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/spanner/apiv1/doc.go b/spanner/apiv1/doc.go index 25796fd9e0f..512f60f25f6 100644 --- a/spanner/apiv1/doc.go +++ b/spanner/apiv1/doc.go @@ -49,7 +49,7 @@ import ( type clientHookParams struct{} type clientHook func(context.Context, clientHookParams) ([]option.ClientOption, error) -const versionClient = "20210612" +const versionClient = "20210701" func insertMetadata(ctx context.Context, mds ...metadata.MD) context.Context { out, _ := metadata.FromOutgoingContext(ctx) diff --git a/spanner/apiv1/spanner_client.go b/spanner/apiv1/spanner_client.go index daf6c274cb4..1067e2f3885 100644 --- a/spanner/apiv1/spanner_client.go +++ b/spanner/apiv1/spanner_client.go @@ -23,7 +23,6 @@ import ( "net/url" "time" - "github.com/golang/protobuf/proto" gax "github.com/googleapis/gax-go/v2" "google.golang.org/api/iterator" "google.golang.org/api/option" @@ -33,6 +32,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newClientHook clientHook @@ -62,6 +62,7 @@ func defaultGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("spanner.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://spanner.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/spanner/batch.go b/spanner/batch.go index 0e38768ae1c..82346bfcebd 100644 --- a/spanner/batch.go +++ b/spanner/batch.go @@ -94,9 +94,25 @@ func (t *BatchReadOnlyTransaction) PartitionRead(ctx context.Context, table stri return t.PartitionReadUsingIndex(ctx, table, "", keys, columns, opt) } +// PartitionReadWithOptions returns a list of Partitions that can be used to +// read rows from the database. These partitions can be executed across multiple +// processes, even across different machines. The partition size and count hints +// can be configured using PartitionOptions. Pass a ReadOptions to modify the +// read operation. +func (t *BatchReadOnlyTransaction) PartitionReadWithOptions(ctx context.Context, table string, keys KeySet, columns []string, opt PartitionOptions, readOptions ReadOptions) ([]*Partition, error) { + return t.PartitionReadUsingIndexWithOptions(ctx, table, "", keys, columns, opt, readOptions) +} + // PartitionReadUsingIndex returns a list of Partitions that can be used to read // rows from the database using an index. func (t *BatchReadOnlyTransaction) PartitionReadUsingIndex(ctx context.Context, table, index string, keys KeySet, columns []string, opt PartitionOptions) ([]*Partition, error) { + return t.PartitionReadUsingIndexWithOptions(ctx, table, index, keys, columns, opt, ReadOptions{}) +} + +// PartitionReadUsingIndexWithOptions returns a list of Partitions that can be +// used to read rows from the database using an index. Pass a ReadOptions to +// modify the read operation. +func (t *BatchReadOnlyTransaction) PartitionReadUsingIndexWithOptions(ctx context.Context, table, index string, keys KeySet, columns []string, opt PartitionOptions, readOptions ReadOptions) ([]*Partition, error) { sh, ts, err := t.acquire(ctx) if err != nil { return nil, err @@ -123,12 +139,13 @@ func (t *BatchReadOnlyTransaction) PartitionReadUsingIndex(ctx context.Context, }) // Prepare ReadRequest. req := &sppb.ReadRequest{ - Session: sid, - Transaction: ts, - Table: table, - Index: index, - Columns: columns, - KeySet: kset, + Session: sid, + Transaction: ts, + Table: table, + Index: index, + Columns: columns, + KeySet: kset, + RequestOptions: createRequestOptions(readOptions.Priority, readOptions.RequestTag, ""), } // Generate partitions. for _, p := range resp.GetPartitions() { @@ -177,12 +194,13 @@ func (t *BatchReadOnlyTransaction) partitionQuery(ctx context.Context, statement // prepare ExecuteSqlRequest r := &sppb.ExecuteSqlRequest{ - Session: sid, - Transaction: ts, - Sql: statement.SQL, - Params: params, - ParamTypes: paramTypes, - QueryOptions: qOpts.Options, + Session: sid, + Transaction: ts, + Sql: statement.SQL, + Params: params, + ParamTypes: paramTypes, + QueryOptions: qOpts.Options, + RequestOptions: createRequestOptions(qOpts.Priority, qOpts.RequestTag, ""), } // generate Partitions @@ -270,6 +288,7 @@ func (t *BatchReadOnlyTransaction) Execute(ctx context.Context, p *Partition) *R Columns: p.rreq.Columns, KeySet: p.rreq.KeySet, PartitionToken: p.pt, + RequestOptions: p.rreq.RequestOptions, ResumeToken: resumeToken, }) } @@ -283,6 +302,7 @@ func (t *BatchReadOnlyTransaction) Execute(ctx context.Context, p *Partition) *R ParamTypes: p.qreq.ParamTypes, QueryOptions: p.qreq.QueryOptions, PartitionToken: p.pt, + RequestOptions: p.qreq.RequestOptions, ResumeToken: resumeToken, }) } diff --git a/spanner/client.go b/spanner/client.go index 9659bb566fc..254468a0a90 100644 --- a/spanner/client.go +++ b/spanner/client.go @@ -497,6 +497,8 @@ type applyOption struct { // If atLeastOnce == true, Client.Apply will execute the mutations on Cloud // Spanner at least once. atLeastOnce bool + // transactionTag will be included with the CommitRequest. + transactionTag string // priority is the RPC priority that is used for the commit operation. priority sppb.RequestOptions_Priority } @@ -521,6 +523,14 @@ func ApplyAtLeastOnce() ApplyOption { } } +// TransactionTag returns an ApplyOption that will include the given tag as a +// transaction tag for a write-only transaction. +func TransactionTag(tag string) ApplyOption { + return func(ao *applyOption) { + ao.transactionTag = tag + } +} + // Priority returns an ApplyOptions that sets the RPC priority to use for the // commit operation. func Priority(priority sppb.RequestOptions_Priority) ApplyOption { @@ -542,10 +552,10 @@ func (c *Client) Apply(ctx context.Context, ms []*Mutation, opts ...ApplyOption) if !ao.atLeastOnce { resp, err := c.ReadWriteTransactionWithOptions(ctx, func(ctx context.Context, t *ReadWriteTransaction) error { return t.BufferWrite(ms) - }, TransactionOptions{CommitPriority: ao.priority}) + }, TransactionOptions{CommitPriority: ao.priority, TransactionTag: ao.transactionTag}) return resp.CommitTs, err } - t := &writeOnlyTransaction{sp: c.idleSessions, commitPriority: ao.priority} + t := &writeOnlyTransaction{sp: c.idleSessions, commitPriority: ao.priority, transactionTag: ao.transactionTag} return t.applyAtLeastOnce(ctx, ms...) } diff --git a/spanner/client_test.go b/spanner/client_test.go index 2b09d1b5ee2..faae43dbe84 100644 --- a/spanner/client_test.go +++ b/spanner/client_test.go @@ -2530,6 +2530,189 @@ func TestClient_Apply_Priority(t *testing.T) { checkCommitForExpectedRequestOptions(t, server.TestSpanner, sppb.RequestOptions{Priority: sppb.RequestOptions_PRIORITY_MEDIUM}) } +func TestClient_ReadOnlyTransaction_Tag(t *testing.T) { + t.Parallel() + + server, client, teardown := setupMockedTestServer(t) + defer teardown() + for _, qo := range []QueryOptions{ + {}, + {RequestTag: "tag-1"}, + } { + for _, tx := range []*ReadOnlyTransaction{ + client.Single(), + client.ReadOnlyTransaction(), + } { + iter := tx.QueryWithOptions(context.Background(), NewStatement(SelectSingerIDAlbumIDAlbumTitleFromAlbums), qo) + iter.Next() + iter.Stop() + + if tx.singleUse { + tx = client.Single() + } + iter = tx.ReadWithOptions(context.Background(), "FOO", AllKeys(), []string{"BAR"}, &ReadOptions{RequestTag: qo.RequestTag}) + iter.Next() + iter.Stop() + + checkRequestsForExpectedRequestOptions(t, server.TestSpanner, 2, sppb.RequestOptions{RequestTag: qo.RequestTag}) + tx.Close() + } + } +} + +func TestClient_ReadWriteTransaction_Tag(t *testing.T) { + t.Parallel() + + server, client, teardown := setupMockedTestServer(t) + defer teardown() + for _, to := range []TransactionOptions{ + {}, + {TransactionTag: "tx-tag-1"}, + } { + for _, qo := range []QueryOptions{ + {}, + {RequestTag: "request-tag-1"}, + } { + client.ReadWriteTransactionWithOptions(context.Background(), func(ctx context.Context, tx *ReadWriteTransaction) error { + iter := tx.QueryWithOptions(context.Background(), NewStatement(SelectSingerIDAlbumIDAlbumTitleFromAlbums), qo) + iter.Next() + iter.Stop() + + iter = tx.ReadWithOptions(context.Background(), "FOO", AllKeys(), []string{"BAR"}, &ReadOptions{RequestTag: qo.RequestTag}) + iter.Next() + iter.Stop() + + tx.UpdateWithOptions(context.Background(), NewStatement(UpdateBarSetFoo), qo) + tx.BatchUpdateWithOptions(context.Background(), []Statement{ + NewStatement(UpdateBarSetFoo), + }, qo) + + // Check for SQL requests inside the transaction to prevent the check to + // drain the commit request from the server. + checkRequestsForExpectedRequestOptions(t, server.TestSpanner, 4, sppb.RequestOptions{RequestTag: qo.RequestTag, TransactionTag: to.TransactionTag}) + return nil + }, to) + checkCommitForExpectedRequestOptions(t, server.TestSpanner, sppb.RequestOptions{TransactionTag: to.TransactionTag}) + } + } +} + +func TestClient_StmtBasedReadWriteTransaction_Tag(t *testing.T) { + t.Parallel() + + server, client, teardown := setupMockedTestServer(t) + defer teardown() + for _, to := range []TransactionOptions{ + {}, + {TransactionTag: "tx-tag-1"}, + } { + for _, qo := range []QueryOptions{ + {}, + {RequestTag: "request-tag-1"}, + } { + tx, _ := NewReadWriteStmtBasedTransactionWithOptions(context.Background(), client, to) + iter := tx.QueryWithOptions(context.Background(), NewStatement(SelectSingerIDAlbumIDAlbumTitleFromAlbums), qo) + iter.Next() + iter.Stop() + + iter = tx.ReadWithOptions(context.Background(), "FOO", AllKeys(), []string{"BAR"}, &ReadOptions{RequestTag: qo.RequestTag}) + iter.Next() + iter.Stop() + + tx.UpdateWithOptions(context.Background(), NewStatement(UpdateBarSetFoo), qo) + tx.BatchUpdateWithOptions(context.Background(), []Statement{ + NewStatement(UpdateBarSetFoo), + }, qo) + checkRequestsForExpectedRequestOptions(t, server.TestSpanner, 4, sppb.RequestOptions{RequestTag: qo.RequestTag, TransactionTag: to.TransactionTag}) + + tx.Commit(context.Background()) + checkCommitForExpectedRequestOptions(t, server.TestSpanner, sppb.RequestOptions{TransactionTag: to.TransactionTag}) + } + } +} + +func TestClient_PDML_Tag(t *testing.T) { + t.Parallel() + + server, client, teardown := setupMockedTestServer(t) + defer teardown() + + for _, qo := range []QueryOptions{ + {}, + {RequestTag: "request-tag-1"}, + } { + client.PartitionedUpdateWithOptions(context.Background(), NewStatement(UpdateBarSetFoo), qo) + checkRequestsForExpectedRequestOptions(t, server.TestSpanner, 1, sppb.RequestOptions{RequestTag: qo.RequestTag}) + } +} + +func TestClient_Apply_Tagging(t *testing.T) { + t.Parallel() + + server, client, teardown := setupMockedTestServer(t) + defer teardown() + + client.Apply(context.Background(), []*Mutation{Insert("foo", []string{"col1"}, []interface{}{"val1"})}) + checkCommitForExpectedRequestOptions(t, server.TestSpanner, sppb.RequestOptions{}) + + client.Apply(context.Background(), []*Mutation{Insert("foo", []string{"col1"}, []interface{}{"val1"})}, TransactionTag("tx-tag")) + checkCommitForExpectedRequestOptions(t, server.TestSpanner, sppb.RequestOptions{TransactionTag: "tx-tag"}) + + client.Apply(context.Background(), []*Mutation{Insert("foo", []string{"col1"}, []interface{}{"val1"})}, ApplyAtLeastOnce()) + checkCommitForExpectedRequestOptions(t, server.TestSpanner, sppb.RequestOptions{}) + + client.Apply(context.Background(), []*Mutation{Insert("foo", []string{"col1"}, []interface{}{"val1"})}, ApplyAtLeastOnce(), TransactionTag("tx-tag")) + checkCommitForExpectedRequestOptions(t, server.TestSpanner, sppb.RequestOptions{TransactionTag: "tx-tag"}) +} + +func TestClient_PartitionQuery_RequestOptions(t *testing.T) { + t.Parallel() + + server, client, teardown := setupMockedTestServer(t) + defer teardown() + + for _, qo := range []QueryOptions{ + {}, + {Priority: sppb.RequestOptions_PRIORITY_LOW}, + {RequestTag: "batch-query-tag"}, + {Priority: sppb.RequestOptions_PRIORITY_MEDIUM, RequestTag: "batch-query-with-medium-prio"}, + } { + ctx := context.Background() + txn, _ := client.BatchReadOnlyTransaction(ctx, StrongRead()) + partitions, _ := txn.PartitionQueryWithOptions(ctx, NewStatement(SelectFooFromBar), PartitionOptions{MaxPartitions: 10}, qo) + for _, p := range partitions { + iter := txn.Execute(ctx, p) + iter.Next() + iter.Stop() + } + checkRequestsForExpectedRequestOptions(t, server.TestSpanner, len(partitions), sppb.RequestOptions{RequestTag: qo.RequestTag, Priority: qo.Priority}) + } +} + +func TestClient_PartitionRead_RequestOptions(t *testing.T) { + t.Parallel() + + server, client, teardown := setupMockedTestServer(t) + defer teardown() + + for _, ro := range []ReadOptions{ + {}, + {Priority: sppb.RequestOptions_PRIORITY_LOW}, + {RequestTag: "batch-read-tag"}, + {Priority: sppb.RequestOptions_PRIORITY_MEDIUM, RequestTag: "batch-read-with-medium-prio"}, + } { + ctx := context.Background() + txn, _ := client.BatchReadOnlyTransaction(ctx, StrongRead()) + partitions, _ := txn.PartitionReadWithOptions(ctx, "Albums", KeySets(Key{"foo"}), []string{"SingerId", "AlbumId", "AlbumTitle"}, PartitionOptions{MaxPartitions: 10}, ro) + for _, p := range partitions { + iter := txn.Execute(ctx, p) + iter.Next() + iter.Stop() + } + checkRequestsForExpectedRequestOptions(t, server.TestSpanner, len(partitions), sppb.RequestOptions{RequestTag: ro.RequestTag, Priority: ro.Priority}) + } +} + func checkRequestsForExpectedRequestOptions(t *testing.T, server InMemSpannerServer, reqCount int, ro sppb.RequestOptions) { reqs := drainRequestsFromServer(server) reqOptions := []*sppb.RequestOptions{} @@ -2551,14 +2734,18 @@ func checkRequestsForExpectedRequestOptions(t *testing.T, server InMemSpannerSer } for _, opts := range reqOptions { - var got sppb.RequestOptions_Priority - if opts != nil { - got = opts.Priority + if opts == nil { + opts = &sppb.RequestOptions{} } - want := ro.Priority - if got != want { + if got, want := opts.Priority, ro.Priority; got != want { t.Fatalf("Request priority mismatch\nGot: %v\nWant: %v", got, want) } + if got, want := opts.RequestTag, ro.RequestTag; got != want { + t.Fatalf("Request tag mismatch\nGot: %v\nWant: %v", got, want) + } + if got, want := opts.TransactionTag, ro.TransactionTag; got != want { + t.Fatalf("Transaction tag mismatch\nGot: %v\nWant: %v", got, want) + } } } @@ -2585,6 +2772,19 @@ func checkCommitForExpectedRequestOptions(t *testing.T, server InMemSpannerServe if got != want { t.Fatalf("Commit priority mismatch\nGot: %v\nWant: %v", got, want) } + + var requestTag string + var transactionTag string + if commit.RequestOptions != nil { + requestTag = commit.RequestOptions.RequestTag + transactionTag = commit.RequestOptions.TransactionTag + } + if got, want := requestTag, ro.RequestTag; got != want { + t.Fatalf("Commit request tag mismatch\nGot: %v\nWant: %v", got, want) + } + if got, want := transactionTag, ro.TransactionTag; got != want { + t.Fatalf("Commit transaction tag mismatch\nGot: %v\nWant: %v", got, want) + } } func TestClient_Single_Read_WithNumericKey(t *testing.T) { diff --git a/spanner/go.mod b/spanner/go.mod index 5740b19b27c..457a68aea49 100644 --- a/spanner/go.mod +++ b/spanner/go.mod @@ -9,8 +9,8 @@ require ( github.com/googleapis/gax-go/v2 v2.0.5 go.opencensus.io v0.23.0 golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 - google.golang.org/api v0.48.0 - google.golang.org/genproto v0.0.0-20210614143202-012ab6975634 + google.golang.org/api v0.50.0 + google.golang.org/genproto v0.0.0-20210701133433-6b8dcf568a95 google.golang.org/grpc v1.38.0 - google.golang.org/protobuf v1.26.0 + google.golang.org/protobuf v1.27.1 ) diff --git a/spanner/go.sum b/spanner/go.sum index 51829ee2af9..aa8fd5de0a2 100644 --- a/spanner/go.sum +++ b/spanner/go.sum @@ -248,8 +248,9 @@ golang.org/x/oauth2 v0.0.0-20201208152858-08078c50e5b5/go.mod h1:KelEdhl1UZF7XfJ golang.org/x/oauth2 v0.0.0-20210218202405-ba52d332ba99/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= golang.org/x/oauth2 v0.0.0-20210220000619-9bb904979d93/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= golang.org/x/oauth2 v0.0.0-20210313182246-cd4f82c27b84/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= -golang.org/x/oauth2 v0.0.0-20210514164344-f6687ab2804c h1:pkQiBZBvdos9qq4wBAHqlzuZHEXo07pqV06ef90u1WI= golang.org/x/oauth2 v0.0.0-20210514164344-f6687ab2804c/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= +golang.org/x/oauth2 v0.0.0-20210628180205-a41e5a781914 h1:3B43BWw0xEBsLZ/NO1VALz6fppU3481pik+2Ksv45z8= +golang.org/x/oauth2 v0.0.0-20210628180205-a41e5a781914/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= @@ -300,8 +301,9 @@ golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210514084401-e8d321eab015/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20210603125802-9665404d3644 h1:CA1DEQ4NdKphKeL70tvsWNdT5oFh1lOjihRcEDROi0I= golang.org/x/sys v0.0.0-20210603125802-9665404d3644/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20210616094352-59db8d763f22 h1:RqytpXGR1iVNX7psjB3ff8y7sNFinVFvkx1c8SjBkio= +golang.org/x/sys v0.0.0-20210616094352-59db8d763f22/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= @@ -363,8 +365,9 @@ golang.org/x/tools v0.0.0-20210105154028-b0ab187a4818/go.mod h1:emZCQorbCU4vsT4f golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0= golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.2/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= -golang.org/x/tools v0.1.3 h1:L69ShwSZEyCsLKoAxDKeMvLDZkumEe8gXUZAjab0tX8= golang.org/x/tools v0.1.3/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= +golang.org/x/tools v0.1.4 h1:cVngSRcfgyZCzys3KYOpCFa+4dqX/Oub9tAq00ttGVs= +golang.org/x/tools v0.1.4/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= @@ -392,8 +395,9 @@ google.golang.org/api v0.40.0/go.mod h1:fYKFpnQN0DsDSKRVRcQSDQNtqWPfM9i+zNPxepjR google.golang.org/api v0.41.0/go.mod h1:RkxM5lITDfTzmyKFPt+wGrCJbVfniCr2ool8kTBzRTU= google.golang.org/api v0.43.0/go.mod h1:nQsDGjRXMo4lvh5hP0TKqF244gqhGcr/YSIykhUk/94= google.golang.org/api v0.47.0/go.mod h1:Wbvgpq1HddcWVtzsVLyfLp8lDg6AA241LmgIL59tHXo= -google.golang.org/api v0.48.0 h1:RDAPWfNFY06dffEXfn7hZF5Fr1ZbnChzfQZAPyBd1+I= google.golang.org/api v0.48.0/go.mod h1:71Pr1vy+TAZRPkPs/xlCf5SsU8WjuAWv1Pfjbtukyy4= +google.golang.org/api v0.50.0 h1:LX7NFCFYOHzr7WHaYiRUpeipZe9o5L8T+2F4Z798VDw= +google.golang.org/api v0.50.0/go.mod h1:4bNT5pAuq5ji4SRZm+5QIkjny9JAyVD/3gaSihNefaw= google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= google.golang.org/appengine v1.5.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= @@ -445,8 +449,9 @@ google.golang.org/genproto v0.0.0-20210513213006-bf773b8c8384/go.mod h1:P3QM42oQ google.golang.org/genproto v0.0.0-20210602131652-f16073e35f0c/go.mod h1:UODoCrxHCcBojKKwX1terBiRUaqAsFqJiF615XL43r0= google.golang.org/genproto v0.0.0-20210604141403-392c879c8b08/go.mod h1:UODoCrxHCcBojKKwX1terBiRUaqAsFqJiF615XL43r0= google.golang.org/genproto v0.0.0-20210608205507-b6d2f5bf0d7d/go.mod h1:UODoCrxHCcBojKKwX1terBiRUaqAsFqJiF615XL43r0= -google.golang.org/genproto v0.0.0-20210614143202-012ab6975634 h1:LnkHrvncK4mYysgs+R1wPeMAILrmunf0Tzl0Li71pxo= -google.golang.org/genproto v0.0.0-20210614143202-012ab6975634/go.mod h1:SzzZ/N+nwJDaO1kznhnlzqS8ocJICar6hYhVyhi++24= +google.golang.org/genproto v0.0.0-20210624195500-8bfb893ecb84/go.mod h1:SzzZ/N+nwJDaO1kznhnlzqS8ocJICar6hYhVyhi++24= +google.golang.org/genproto v0.0.0-20210701133433-6b8dcf568a95 h1:xyRjacsGcaSoZ2fTcaLCSzh2JEceLLOT4X8k32Q0xAQ= +google.golang.org/genproto v0.0.0-20210701133433-6b8dcf568a95/go.mod h1:yiaVoXHpRzHGyxV3o4DktVWY4mSUErTKaeEOq6C3t3U= google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38= google.golang.org/grpc v1.21.1/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM= @@ -481,8 +486,9 @@ google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpAD google.golang.org/protobuf v1.24.0/go.mod h1:r/3tXBNzIEhYS9I1OUVjXDlt8tc493IdKGjtUeSXeh4= google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c= google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= -google.golang.org/protobuf v1.26.0 h1:bxAC2xTBsZGibn2RTntX0oH50xLsqy1OxA9tTL3p/lk= google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= +google.golang.org/protobuf v1.27.1 h1:SnqbnDw1V7RiZcXPx5MEeqPv2s79L9i7BJUlG/+RurQ= +google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= diff --git a/spanner/internal/testutil/inmem_spanner_server.go b/spanner/internal/testutil/inmem_spanner_server.go index c2b1b8894e4..ac6f9bdfd04 100644 --- a/spanner/internal/testutil/inmem_spanner_server.go +++ b/spanner/internal/testutil/inmem_spanner_server.go @@ -1057,14 +1057,17 @@ func (s *inMemSpannerServer) PartitionQuery(ctx context.Context, req *spannerpb. } func (s *inMemSpannerServer) PartitionRead(ctx context.Context, req *spannerpb.PartitionReadRequest) (*spannerpb.PartitionResponse, error) { - s.mu.Lock() - if s.stopped { - s.mu.Unlock() - return nil, gstatus.Error(codes.Unavailable, "server has been stopped") - } - s.receivedRequests <- req - s.mu.Unlock() - return nil, gstatus.Error(codes.Unimplemented, "Method not yet implemented") + return s.PartitionQuery(ctx, &spannerpb.PartitionQueryRequest{ + Session: req.Session, + Transaction: req.Transaction, + PartitionOptions: req.PartitionOptions, + // KeySet is currently ignored. + Sql: fmt.Sprintf( + "SELECT %s FROM %s", + strings.Join(req.Columns, ", "), + req.Table, + ), + }) } // EncodeResumeToken return mock resume token encoding for an uint64 integer. diff --git a/spanner/pdml.go b/spanner/pdml.go index 5a663ee1ecf..d24a8767ab9 100644 --- a/spanner/pdml.go +++ b/spanner/pdml.go @@ -69,7 +69,7 @@ func (c *Client) partitionedUpdate(ctx context.Context, statement Statement, opt Params: params, ParamTypes: paramTypes, QueryOptions: options.Options, - RequestOptions: createRequestOptions(&options), + RequestOptions: createRequestOptions(options.Priority, options.RequestTag, ""), } // Make a retryer for Aborted and certain Internal errors. diff --git a/spanner/pdml_test.go b/spanner/pdml_test.go index ca4ac323044..45fcf8b7eb0 100644 --- a/spanner/pdml_test.go +++ b/spanner/pdml_test.go @@ -166,3 +166,15 @@ func TestPartitionedUpdate_QueryOptions(t *testing.T) { }) } } + +func TestPartitionedUpdate_Tagging(t *testing.T) { + ctx := context.Background() + server, client, teardown := setupMockedTestServer(t) + defer teardown() + + _, err := client.PartitionedUpdateWithOptions(ctx, NewStatement(UpdateBarSetFoo), QueryOptions{RequestTag: "pdml-tag"}) + if err != nil { + t.Fatalf("expect no errors, but got %v", err) + } + checkRequestsForExpectedRequestOptions(t, server.TestSpanner, 1, sppb.RequestOptions{RequestTag: "pdml-tag"}) +} diff --git a/spanner/session.go b/spanner/session.go index 49b046a6616..a41276026b6 100644 --- a/spanner/session.go +++ b/spanner/session.go @@ -404,7 +404,8 @@ type SessionPoolConfig struct { // Defaults to 100. MinOpened uint64 - // MaxIdle is the maximum number of idle sessions, pool is allowed to keep. + // MaxIdle is the maximum number of idle sessions that are allowed in the + // session pool. // // Defaults to 0. MaxIdle uint64 diff --git a/spanner/transaction.go b/spanner/transaction.go index 019d35f5a2c..b9da4f401fe 100644 --- a/spanner/transaction.go +++ b/spanner/transaction.go @@ -77,15 +77,15 @@ type txReadOnly struct { txOpts TransactionOptions } -// Internal interface for types that can configure the priority of an RPC. -type requestPrioritizer interface { - requestPriority() sppb.RequestOptions_Priority -} - // TransactionOptions provides options for a transaction. type TransactionOptions struct { CommitOptions CommitOptions + // The transaction tag to use for a read/write transaction. + // This tag is automatically included with each statement and the commit + // request of a read/write transaction. + TransactionTag string + // CommitPriority is the priority to use for the Commit RPC for the // transaction. CommitPriority sppb.RequestOptions_Priority @@ -95,6 +95,10 @@ func (to *TransactionOptions) requestPriority() sppb.RequestOptions_Priority { return to.CommitPriority } +func (to *TransactionOptions) requestTag() string { + return "" +} + // errSessionClosed returns error for using a recycled/destroyed session func errSessionClosed(sh *sessionHandle) error { return spannerErrorf(codes.FailedPrecondition, @@ -122,12 +126,11 @@ type ReadOptions struct { // limit. Limit int - // Priority is the RPC priority to use for the read operation. + // Priority is the RPC priority to use for the operation. Priority sppb.RequestOptions_Priority -} -func (ro *ReadOptions) requestPriority() sppb.RequestOptions_Priority { - return ro.Priority + // The request tag to use for this request. + RequestTag string } // ReadWithOptions returns a RowIterator for reading multiple rows from the @@ -155,13 +158,15 @@ func (t *txReadOnly) ReadWithOptions(ctx context.Context, table string, keys Key } index := "" limit := 0 - var ro *sppb.RequestOptions + prio := sppb.RequestOptions_PRIORITY_UNSPECIFIED + requestTag := "" if opts != nil { index = opts.Index if opts.Limit > 0 { limit = opts.Limit } - ro = createRequestOptions(opts) + prio = opts.Priority + requestTag = opts.RequestTag } return streamWithReplaceSessionFunc( contextWithOutgoingMetadata(ctx, sh.getMetadata()), @@ -177,7 +182,7 @@ func (t *txReadOnly) ReadWithOptions(ctx context.Context, table string, keys Key KeySet: kset, ResumeToken: resumeToken, Limit: int64(limit), - RequestOptions: ro, + RequestOptions: createRequestOptions(prio, requestTag, t.txOpts.TransactionTag), }) }, t.replaceSessionFunc, @@ -257,23 +262,26 @@ type QueryOptions struct { // Priority is the RPC priority to use for the query/update. Priority sppb.RequestOptions_Priority -} -func (qo *QueryOptions) requestPriority() sppb.RequestOptions_Priority { - return qo.Priority + // The request tag to use for this request. + RequestTag string } // merge combines two QueryOptions that the input parameter will have higher // order of precedence. func (qo QueryOptions) merge(opts QueryOptions) QueryOptions { merged := QueryOptions{ - Mode: qo.Mode, - Options: &sppb.ExecuteSqlRequest_QueryOptions{}, - Priority: qo.Priority, + Mode: qo.Mode, + Options: &sppb.ExecuteSqlRequest_QueryOptions{}, + RequestTag: qo.RequestTag, + Priority: qo.Priority, } if opts.Mode != nil { merged.Mode = opts.Mode } + if opts.RequestTag != "" { + merged.RequestTag = opts.RequestTag + } if opts.Priority != sppb.RequestOptions_PRIORITY_UNSPECIFIED { merged.Priority = opts.Priority } @@ -282,12 +290,16 @@ func (qo QueryOptions) merge(opts QueryOptions) QueryOptions { return merged } -func createRequestOptions(prioritizer requestPrioritizer) (ro *sppb.RequestOptions) { - if prioritizer == nil { - return nil +func createRequestOptions(prio sppb.RequestOptions_Priority, requestTag, transactionTag string) (ro *sppb.RequestOptions) { + ro = &sppb.RequestOptions{} + if prio != sppb.RequestOptions_PRIORITY_UNSPECIFIED { + ro.Priority = prio } - if prioritizer.requestPriority() != sppb.RequestOptions_PRIORITY_UNSPECIFIED { - ro = &sppb.RequestOptions{Priority: prioritizer.requestPriority()} + if requestTag != "" { + ro.RequestTag = requestTag + } + if transactionTag != "" { + ro.TransactionTag = transactionTag } return ro } @@ -396,7 +408,7 @@ func (t *txReadOnly) prepareExecuteSQL(ctx context.Context, stmt Statement, opti Params: params, ParamTypes: paramTypes, QueryOptions: options.Options, - RequestOptions: createRequestOptions(&options), + RequestOptions: createRequestOptions(options.Priority, options.RequestTag, t.txOpts.TransactionTag), } return req, sh, nil } @@ -902,9 +914,13 @@ func (t *ReadWriteTransaction) BatchUpdate(ctx context.Context, stmts []Statemen // affected rows for the given query at the same index. If an error occurs, // counts will be returned up to the query that encountered the error. // -// The priority given in the QueryOptions will be included with the RPC. -// Any other options that are set in the QueryOptions struct will be ignored. +// The request tag and priority given in the QueryOptions are included with the +// RPC. Any other options that are set in the QueryOptions struct are ignored. func (t *ReadWriteTransaction) BatchUpdateWithOptions(ctx context.Context, stmts []Statement, opts QueryOptions) (_ []int64, err error) { + return t.batchUpdateWithOptions(ctx, stmts, t.qo.merge(opts)) +} + +func (t *ReadWriteTransaction) batchUpdateWithOptions(ctx context.Context, stmts []Statement, opts QueryOptions) (_ []int64, err error) { ctx = trace.StartSpan(ctx, "cloud.google.com/go/spanner.BatchUpdate") defer func() { trace.EndSpan(ctx, err) }() @@ -937,7 +953,7 @@ func (t *ReadWriteTransaction) BatchUpdateWithOptions(ctx context.Context, stmts Transaction: ts, Statements: sppbStmts, Seqno: atomic.AddInt64(&t.sequenceNumber, 1), - RequestOptions: createRequestOptions(&opts), + RequestOptions: createRequestOptions(opts.Priority, opts.RequestTag, t.txOpts.TransactionTag), }) if err != nil { return nil, ToSpannerError(err) @@ -1059,7 +1075,7 @@ func (t *ReadWriteTransaction) commit(ctx context.Context, options CommitOptions Transaction: &sppb.CommitRequest_TransactionId{ TransactionId: t.tx, }, - RequestOptions: createRequestOptions(&t.txOpts), + RequestOptions: createRequestOptions(t.txOpts.CommitPriority, "", t.txOpts.TransactionTag), Mutations: mPb, ReturnCommitStats: options.ReturnCommitStats, }) @@ -1240,14 +1256,13 @@ type writeOnlyTransaction struct { // sp is the session pool which writeOnlyTransaction uses to get Cloud // Spanner sessions for blind writes. sp *sessionPool + // transactionTag is the tag that will be included with the CommitRequest + // of the write-only transaction. + transactionTag string // commitPriority is the RPC priority to use for the commit operation. commitPriority sppb.RequestOptions_Priority } -func (t *writeOnlyTransaction) requestPriority() sppb.RequestOptions_Priority { - return t.commitPriority -} - // applyAtLeastOnce commits a list of mutations to Cloud Spanner at least once, // unless one of the following happens: // @@ -1288,7 +1303,7 @@ func (t *writeOnlyTransaction) applyAtLeastOnce(ctx context.Context, ms ...*Muta }, }, Mutations: mPb, - RequestOptions: createRequestOptions(t), + RequestOptions: createRequestOptions(t.commitPriority, "", t.transactionTag), }) if err != nil && !isAbortedErr(err) { if isSessionNotFoundError(err) { diff --git a/speech/apiv1/doc.go b/speech/apiv1/doc.go index 87a2a09a70f..37405d8bb7b 100644 --- a/speech/apiv1/doc.go +++ b/speech/apiv1/doc.go @@ -48,7 +48,7 @@ import ( type clientHookParams struct{} type clientHook func(context.Context, clientHookParams) ([]option.ClientOption, error) -const versionClient = "20210612" +const versionClient = "20210701" func insertMetadata(ctx context.Context, mds ...metadata.MD) context.Context { out, _ := metadata.FromOutgoingContext(ctx) diff --git a/speech/apiv1/speech_client.go b/speech/apiv1/speech_client.go index a14239940c3..c418232d7e9 100644 --- a/speech/apiv1/speech_client.go +++ b/speech/apiv1/speech_client.go @@ -49,6 +49,7 @@ func defaultGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("speech.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://speech.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/speech/apiv1p1beta1/adaptation_client.go b/speech/apiv1p1beta1/adaptation_client.go index 826101772e9..4c75b8e46c5 100644 --- a/speech/apiv1p1beta1/adaptation_client.go +++ b/speech/apiv1p1beta1/adaptation_client.go @@ -22,7 +22,6 @@ import ( "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" @@ -31,6 +30,7 @@ import ( speechpb "google.golang.org/genproto/googleapis/cloud/speech/v1p1beta1" "google.golang.org/grpc" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newAdaptationClientHook clientHook @@ -55,6 +55,7 @@ func defaultAdaptationGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("speech.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://speech.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/speech/apiv1p1beta1/doc.go b/speech/apiv1p1beta1/doc.go index 79816a293b3..3b2a00d5ec1 100644 --- a/speech/apiv1p1beta1/doc.go +++ b/speech/apiv1p1beta1/doc.go @@ -50,7 +50,7 @@ import ( type clientHookParams struct{} type clientHook func(context.Context, clientHookParams) ([]option.ClientOption, error) -const versionClient = "20210612" +const versionClient = "20210701" func insertMetadata(ctx context.Context, mds ...metadata.MD) context.Context { out, _ := metadata.FromOutgoingContext(ctx) diff --git a/speech/apiv1p1beta1/speech_client.go b/speech/apiv1p1beta1/speech_client.go index 115574e5ee0..32decf2ba5a 100644 --- a/speech/apiv1p1beta1/speech_client.go +++ b/speech/apiv1p1beta1/speech_client.go @@ -49,6 +49,7 @@ func defaultGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("speech.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://speech.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/storage/CHANGES.md b/storage/CHANGES.md index 661e0b1cb4b..8b4754edc44 100644 --- a/storage/CHANGES.md +++ b/storage/CHANGES.md @@ -1,5 +1,18 @@ # Changes +## [1.16.0](https://www.github.com/googleapis/google-cloud-go/compare/storage/v1.15.0...storage/v1.16.0) (2021-06-28) + + +### Features + +* **storage:** support PublicAccessPrevention ([#3608](https://www.github.com/googleapis/google-cloud-go/issues/3608)) ([99bc782](https://www.github.com/googleapis/google-cloud-go/commit/99bc782fb50a47602b45278384ef5d5b5da9263b)), refs [#3203](https://www.github.com/googleapis/google-cloud-go/issues/3203) + + +### Bug Fixes + +* **storage:** fix Writer.ChunkSize validation ([#4255](https://www.github.com/googleapis/google-cloud-go/issues/4255)) ([69c2e9d](https://www.github.com/googleapis/google-cloud-go/commit/69c2e9dc6303e1a004d3104a8178532fa738e742)), refs [#4167](https://www.github.com/googleapis/google-cloud-go/issues/4167) +* **storage:** try to reopen for failed Reads ([#4226](https://www.github.com/googleapis/google-cloud-go/issues/4226)) ([564102b](https://www.github.com/googleapis/google-cloud-go/commit/564102b335dbfb558bec8af883e5f898efb5dd10)), refs [#3040](https://www.github.com/googleapis/google-cloud-go/issues/3040) + ## [1.15.0](https://www.github.com/googleapis/google-cloud-go/compare/storage/v1.13.0...storage/v1.15.0) (2021-04-21) diff --git a/storage/bucket.go b/storage/bucket.go index 7b1757b83de..7208f577e66 100644 --- a/storage/bucket.go +++ b/storage/bucket.go @@ -244,6 +244,13 @@ type BucketAttrs struct { // for more information. UniformBucketLevelAccess UniformBucketLevelAccess + // PublicAccessPrevention is the setting for the bucket's + // PublicAccessPrevention policy, which can be used to prevent public access + // of data in the bucket. See + // https://cloud.google.com/storage/docs/public-access-prevention for more + // information. + PublicAccessPrevention PublicAccessPrevention + // DefaultObjectACL is the list of access controls to // apply to new objects when no object ACL is provided. DefaultObjectACL []ACLRule @@ -353,6 +360,41 @@ type UniformBucketLevelAccess struct { LockedTime time.Time } +// PublicAccessPrevention configures the Public Access Prevention feature, which +// can be used to disallow public access to any data in a bucket. See +// https://cloud.google.com/storage/docs/public-access-prevention for more +// information. +type PublicAccessPrevention int + +const ( + // PublicAccessPreventionUnknown is a zero value, used only if this field is + // not set in a call to GCS. + PublicAccessPreventionUnknown PublicAccessPrevention = iota + + // PublicAccessPreventionUnspecified corresponds to a value of "unspecified" + // and is the default for buckets. + PublicAccessPreventionUnspecified + + // PublicAccessPreventionEnforced corresponds to a value of "enforced". This + // enforces Public Access Prevention on the bucket. + PublicAccessPreventionEnforced + + publicAccessPreventionUnknown string = "" + publicAccessPreventionUnspecified = "unspecified" + publicAccessPreventionEnforced = "enforced" +) + +func (p PublicAccessPrevention) String() string { + switch p { + case PublicAccessPreventionUnspecified: + return publicAccessPreventionUnspecified + case PublicAccessPreventionEnforced: + return publicAccessPreventionEnforced + default: + return publicAccessPreventionUnknown + } +} + // Lifecycle is the lifecycle configuration for objects in the bucket. type Lifecycle struct { Rules []LifecycleRule @@ -551,6 +593,7 @@ func newBucket(b *raw.Bucket) (*BucketAttrs, error) { Website: toBucketWebsite(b.Website), BucketPolicyOnly: toBucketPolicyOnly(b.IamConfiguration), UniformBucketLevelAccess: toUniformBucketLevelAccess(b.IamConfiguration), + PublicAccessPrevention: toPublicAccessPrevention(b.IamConfiguration), Etag: b.Etag, LocationType: b.LocationType, }, nil @@ -578,11 +621,15 @@ func (b *BucketAttrs) toRawBucket() *raw.Bucket { bb = &raw.BucketBilling{RequesterPays: true} } var bktIAM *raw.BucketIamConfiguration - if b.UniformBucketLevelAccess.Enabled || b.BucketPolicyOnly.Enabled { - bktIAM = &raw.BucketIamConfiguration{ - UniformBucketLevelAccess: &raw.BucketIamConfigurationUniformBucketLevelAccess{ + if b.UniformBucketLevelAccess.Enabled || b.BucketPolicyOnly.Enabled || b.PublicAccessPrevention != PublicAccessPreventionUnknown { + bktIAM = &raw.BucketIamConfiguration{} + if b.UniformBucketLevelAccess.Enabled || b.BucketPolicyOnly.Enabled { + bktIAM.UniformBucketLevelAccess = &raw.BucketIamConfigurationUniformBucketLevelAccess{ Enabled: true, - }, + } + } + if b.PublicAccessPrevention != PublicAccessPreventionUnknown { + bktIAM.PublicAccessPrevention = b.PublicAccessPrevention.String() } } return &raw.Bucket{ @@ -661,6 +708,13 @@ type BucketAttrsToUpdate struct { // for more information. UniformBucketLevelAccess *UniformBucketLevelAccess + // PublicAccessPrevention is the setting for the bucket's + // PublicAccessPrevention policy, which can be used to prevent public access + // of data in the bucket. See + // https://cloud.google.com/storage/docs/public-access-prevention for more + // information. + PublicAccessPrevention PublicAccessPrevention + // StorageClass is the default storage class of the bucket. This defines // how objects in the bucket are stored and determines the SLA // and the cost of storage. Typical values are "STANDARD", "NEARLINE", @@ -771,6 +825,12 @@ func (ua *BucketAttrsToUpdate) toRawBucket() *raw.Bucket { }, } } + if ua.PublicAccessPrevention != PublicAccessPreventionUnknown { + if rb.IamConfiguration == nil { + rb.IamConfiguration = &raw.BucketIamConfiguration{} + } + rb.IamConfiguration.PublicAccessPrevention = ua.PublicAccessPrevention.String() + } if ua.Encryption != nil { if ua.Encryption.DefaultKMSKeyName == "" { rb.NullFields = append(rb.NullFields, "Encryption") @@ -1139,6 +1199,20 @@ func toUniformBucketLevelAccess(b *raw.BucketIamConfiguration) UniformBucketLeve } } +func toPublicAccessPrevention(b *raw.BucketIamConfiguration) PublicAccessPrevention { + if b == nil { + return PublicAccessPreventionUnknown + } + switch b.PublicAccessPrevention { + case publicAccessPreventionUnspecified: + return PublicAccessPreventionUnspecified + case publicAccessPreventionEnforced: + return PublicAccessPreventionEnforced + default: + return PublicAccessPreventionUnknown + } +} + // Objects returns an iterator over the objects in the bucket that match the // Query q. If q is nil, no filtering is done. Objects will be iterated over // lexicographically by name. diff --git a/storage/bucket_test.go b/storage/bucket_test.go index 123e319a84e..4ff5f5cc5ed 100644 --- a/storage/bucket_test.go +++ b/storage/bucket_test.go @@ -42,6 +42,7 @@ func TestBucketAttrsToRawBucket(t *testing.T) { }, BucketPolicyOnly: BucketPolicyOnly{Enabled: true}, UniformBucketLevelAccess: UniformBucketLevelAccess{Enabled: true}, + PublicAccessPrevention: PublicAccessPreventionEnforced, VersioningEnabled: false, // should be ignored: MetaGeneration: 39, @@ -121,6 +122,7 @@ func TestBucketAttrsToRawBucket(t *testing.T) { UniformBucketLevelAccess: &raw.BucketIamConfigurationUniformBucketLevelAccess{ Enabled: true, }, + PublicAccessPrevention: "enforced", }, Versioning: nil, // ignore VersioningEnabled if false Labels: map[string]string{"label": "value"}, @@ -205,6 +207,7 @@ func TestBucketAttrsToRawBucket(t *testing.T) { UniformBucketLevelAccess: &raw.BucketIamConfigurationUniformBucketLevelAccess{ Enabled: true, }, + PublicAccessPrevention: "enforced", } if msg := testutil.Diff(got, want); msg != "" { t.Errorf(msg) @@ -219,6 +222,7 @@ func TestBucketAttrsToRawBucket(t *testing.T) { UniformBucketLevelAccess: &raw.BucketIamConfigurationUniformBucketLevelAccess{ Enabled: true, }, + PublicAccessPrevention: "enforced", } if msg := testutil.Diff(got, want); msg != "" { t.Errorf(msg) @@ -234,6 +238,7 @@ func TestBucketAttrsToRawBucket(t *testing.T) { UniformBucketLevelAccess: &raw.BucketIamConfigurationUniformBucketLevelAccess{ Enabled: true, }, + PublicAccessPrevention: "enforced", } if msg := testutil.Diff(got, want); msg != "" { t.Errorf(msg) @@ -244,6 +249,42 @@ func TestBucketAttrsToRawBucket(t *testing.T) { attrs.BucketPolicyOnly = BucketPolicyOnly{} attrs.UniformBucketLevelAccess = UniformBucketLevelAccess{} got = attrs.toRawBucket() + want.IamConfiguration = &raw.BucketIamConfiguration{ + PublicAccessPrevention: "enforced", + } + if msg := testutil.Diff(got, want); msg != "" { + t.Errorf(msg) + } + + // Test that setting PublicAccessPrevention to "unspecified" leads to the + // setting being propagated in the proto. + attrs.PublicAccessPrevention = PublicAccessPreventionUnspecified + got = attrs.toRawBucket() + want.IamConfiguration = &raw.BucketIamConfiguration{ + PublicAccessPrevention: "unspecified", + } + if msg := testutil.Diff(got, want); msg != "" { + t.Errorf(msg) + } + + // Re-enable UBLA and confirm that it does not affect the PAP setting. + attrs.UniformBucketLevelAccess = UniformBucketLevelAccess{Enabled: true} + got = attrs.toRawBucket() + want.IamConfiguration = &raw.BucketIamConfiguration{ + UniformBucketLevelAccess: &raw.BucketIamConfigurationUniformBucketLevelAccess{ + Enabled: true, + }, + PublicAccessPrevention: "unspecified", + } + if msg := testutil.Diff(got, want); msg != "" { + t.Errorf(msg) + } + + // Disable UBLA and reset PAP to default. Confirm that the IAM config is set + // to nil in the proto. + attrs.UniformBucketLevelAccess = UniformBucketLevelAccess{Enabled: false} + attrs.PublicAccessPrevention = PublicAccessPreventionUnknown + got = attrs.toRawBucket() want.IamConfiguration = nil if msg := testutil.Diff(got, want); msg != "" { t.Errorf(msg) diff --git a/storage/go.mod b/storage/go.mod index 49afaa129d5..5651bf0eee3 100644 --- a/storage/go.mod +++ b/storage/go.mod @@ -7,9 +7,9 @@ require ( github.com/golang/protobuf v1.5.2 github.com/google/go-cmp v0.5.6 github.com/googleapis/gax-go/v2 v2.0.5 - golang.org/x/oauth2 v0.0.0-20210615190721-d04028783cf1 + golang.org/x/oauth2 v0.0.0-20210628180205-a41e5a781914 golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 - google.golang.org/api v0.48.0 - google.golang.org/genproto v0.0.0-20210608205507-b6d2f5bf0d7d + google.golang.org/api v0.50.0 + google.golang.org/genproto v0.0.0-20210701133433-6b8dcf568a95 google.golang.org/grpc v1.38.0 ) diff --git a/storage/go.sum b/storage/go.sum index 33b470ce572..0d994fb54e3 100644 --- a/storage/go.sum +++ b/storage/go.sum @@ -252,8 +252,8 @@ golang.org/x/oauth2 v0.0.0-20210218202405-ba52d332ba99/go.mod h1:KelEdhl1UZF7XfJ golang.org/x/oauth2 v0.0.0-20210220000619-9bb904979d93/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= golang.org/x/oauth2 v0.0.0-20210313182246-cd4f82c27b84/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= golang.org/x/oauth2 v0.0.0-20210514164344-f6687ab2804c/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= -golang.org/x/oauth2 v0.0.0-20210615190721-d04028783cf1 h1:x622Z2o4hgCr/4CiKWc51jHVKaWdtVpBNmEI8wI9Qns= -golang.org/x/oauth2 v0.0.0-20210615190721-d04028783cf1/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= +golang.org/x/oauth2 v0.0.0-20210628180205-a41e5a781914 h1:3B43BWw0xEBsLZ/NO1VALz6fppU3481pik+2Ksv45z8= +golang.org/x/oauth2 v0.0.0-20210628180205-a41e5a781914/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= @@ -304,8 +304,9 @@ golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210514084401-e8d321eab015/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20210603125802-9665404d3644 h1:CA1DEQ4NdKphKeL70tvsWNdT5oFh1lOjihRcEDROi0I= golang.org/x/sys v0.0.0-20210603125802-9665404d3644/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20210616094352-59db8d763f22 h1:RqytpXGR1iVNX7psjB3ff8y7sNFinVFvkx1c8SjBkio= +golang.org/x/sys v0.0.0-20210616094352-59db8d763f22/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= @@ -366,8 +367,10 @@ golang.org/x/tools v0.0.0-20201208233053-a543418bbed2/go.mod h1:emZCQorbCU4vsT4f golang.org/x/tools v0.0.0-20210105154028-b0ab187a4818/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0= golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= -golang.org/x/tools v0.1.2 h1:kRBLX7v7Af8W7Gdbbc908OJcdgtK8bOz9Uaj8/F1ACA= golang.org/x/tools v0.1.2/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= +golang.org/x/tools v0.1.3/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= +golang.org/x/tools v0.1.4 h1:cVngSRcfgyZCzys3KYOpCFa+4dqX/Oub9tAq00ttGVs= +golang.org/x/tools v0.1.4/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= @@ -395,8 +398,9 @@ google.golang.org/api v0.40.0/go.mod h1:fYKFpnQN0DsDSKRVRcQSDQNtqWPfM9i+zNPxepjR google.golang.org/api v0.41.0/go.mod h1:RkxM5lITDfTzmyKFPt+wGrCJbVfniCr2ool8kTBzRTU= google.golang.org/api v0.43.0/go.mod h1:nQsDGjRXMo4lvh5hP0TKqF244gqhGcr/YSIykhUk/94= google.golang.org/api v0.47.0/go.mod h1:Wbvgpq1HddcWVtzsVLyfLp8lDg6AA241LmgIL59tHXo= -google.golang.org/api v0.48.0 h1:RDAPWfNFY06dffEXfn7hZF5Fr1ZbnChzfQZAPyBd1+I= google.golang.org/api v0.48.0/go.mod h1:71Pr1vy+TAZRPkPs/xlCf5SsU8WjuAWv1Pfjbtukyy4= +google.golang.org/api v0.50.0 h1:LX7NFCFYOHzr7WHaYiRUpeipZe9o5L8T+2F4Z798VDw= +google.golang.org/api v0.50.0/go.mod h1:4bNT5pAuq5ji4SRZm+5QIkjny9JAyVD/3gaSihNefaw= google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= google.golang.org/appengine v1.5.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= @@ -447,8 +451,10 @@ google.golang.org/genproto v0.0.0-20210402141018-6c239bbf2bb1/go.mod h1:9lPAdzaE google.golang.org/genproto v0.0.0-20210513213006-bf773b8c8384/go.mod h1:P3QM42oQyzQSnHPnZ/vqoCdDmzH28fzWByN9asMeM8A= google.golang.org/genproto v0.0.0-20210602131652-f16073e35f0c/go.mod h1:UODoCrxHCcBojKKwX1terBiRUaqAsFqJiF615XL43r0= google.golang.org/genproto v0.0.0-20210604141403-392c879c8b08/go.mod h1:UODoCrxHCcBojKKwX1terBiRUaqAsFqJiF615XL43r0= -google.golang.org/genproto v0.0.0-20210608205507-b6d2f5bf0d7d h1:KzwjikDymrEmYYbdyfievTwjEeGlu+OM6oiKBkF3Jfg= google.golang.org/genproto v0.0.0-20210608205507-b6d2f5bf0d7d/go.mod h1:UODoCrxHCcBojKKwX1terBiRUaqAsFqJiF615XL43r0= +google.golang.org/genproto v0.0.0-20210624195500-8bfb893ecb84/go.mod h1:SzzZ/N+nwJDaO1kznhnlzqS8ocJICar6hYhVyhi++24= +google.golang.org/genproto v0.0.0-20210701133433-6b8dcf568a95 h1:xyRjacsGcaSoZ2fTcaLCSzh2JEceLLOT4X8k32Q0xAQ= +google.golang.org/genproto v0.0.0-20210701133433-6b8dcf568a95/go.mod h1:yiaVoXHpRzHGyxV3o4DktVWY4mSUErTKaeEOq6C3t3U= google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38= google.golang.org/grpc v1.21.1/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM= @@ -483,8 +489,9 @@ google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpAD google.golang.org/protobuf v1.24.0/go.mod h1:r/3tXBNzIEhYS9I1OUVjXDlt8tc493IdKGjtUeSXeh4= google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c= google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= -google.golang.org/protobuf v1.26.0 h1:bxAC2xTBsZGibn2RTntX0oH50xLsqy1OxA9tTL3p/lk= google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= +google.golang.org/protobuf v1.27.1 h1:SnqbnDw1V7RiZcXPx5MEeqPv2s79L9i7BJUlG/+RurQ= +google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= diff --git a/storage/integration_test.go b/storage/integration_test.go index 7faa31dbd3e..7ea61e3c47e 100644 --- a/storage/integration_test.go +++ b/storage/integration_test.go @@ -52,6 +52,7 @@ import ( "google.golang.org/api/iterator" itesting "google.golang.org/api/iterator/testing" "google.golang.org/api/option" + iampb "google.golang.org/genproto/googleapis/iam/v1" ) const ( @@ -575,6 +576,92 @@ func TestIntegration_UniformBucketLevelAccess(t *testing.T) { } } +func TestIntegration_PublicAccessPrevention(t *testing.T) { + ctx := context.Background() + client := testConfig(ctx, t) + defer client.Close() + h := testHelper{t} + + // Create a bucket with PublicAccessPrevention enforced. + bkt := client.Bucket(uidSpace.New()) + h.mustCreate(bkt, testutil.ProjID(), &BucketAttrs{PublicAccessPrevention: PublicAccessPreventionEnforced}) + defer h.mustDeleteBucket(bkt) + + // Making bucket public should fail. + policy, err := bkt.IAM().V3().Policy(ctx) + if err != nil { + t.Fatalf("fetching bucket IAM policy: %v", err) + } + policy.Bindings = append(policy.Bindings, &iampb.Binding{ + Role: "roles/storage.objectViewer", + Members: []string{iam.AllUsers}, + }) + if err := bkt.IAM().V3().SetPolicy(ctx, policy); err == nil { + t.Error("SetPolicy: expected adding AllUsers policy to bucket should fail") + } + + // Making object public via ACL should fail. + o := bkt.Object("publicAccessPrevention") + defer func() { + if err := o.Delete(ctx); err != nil { + log.Printf("failed to delete test object: %v", err) + } + }() + wc := o.NewWriter(ctx) + wc.ContentType = "text/plain" + h.mustWrite(wc, []byte("test")) + a := o.ACL() + if err := a.Set(ctx, AllUsers, RoleReader); err == nil { + t.Error("ACL.Set: expected adding AllUsers ACL to object should fail") + } + + // Update PAP setting to unspecified should work and not affect UBLA setting. + attrs, err := bkt.Update(ctx, BucketAttrsToUpdate{PublicAccessPrevention: PublicAccessPreventionUnspecified}) + if err != nil { + t.Fatalf("updating PublicAccessPrevention failed: %v", err) + } + if attrs.PublicAccessPrevention != PublicAccessPreventionUnspecified { + t.Errorf("updating PublicAccessPrevention: got %s, want %s", attrs.PublicAccessPrevention, PublicAccessPreventionUnspecified) + } + if attrs.UniformBucketLevelAccess.Enabled || attrs.BucketPolicyOnly.Enabled { + t.Error("updating PublicAccessPrevention changed UBLA setting") + } + + // Now, making object public or making bucket public should succeed. Run with + // retry because ACL settings may take time to propagate. + if err := retry(ctx, + func() error { + a = o.ACL() + return a.Set(ctx, AllUsers, RoleReader) + }, + nil); err != nil { + t.Errorf("ACL.Set: making object public failed: %v", err) + } + policy, err = bkt.IAM().V3().Policy(ctx) + if err != nil { + t.Fatalf("fetching bucket IAM policy: %v", err) + } + policy.Bindings = append(policy.Bindings, &iampb.Binding{ + Role: "roles/storage.objectViewer", + Members: []string{iam.AllUsers}, + }) + if err := bkt.IAM().V3().SetPolicy(ctx, policy); err != nil { + t.Errorf("SetPolicy: making bucket public failed: %v", err) + } + + // Updating UBLA should not affect PAP setting. + attrs, err = bkt.Update(ctx, BucketAttrsToUpdate{UniformBucketLevelAccess: &UniformBucketLevelAccess{Enabled: true}}) + if err != nil { + t.Fatalf("updating UBLA failed: %v", err) + } + if !attrs.UniformBucketLevelAccess.Enabled { + t.Error("updating UBLA: got UBLA not enabled, want enabled") + } + if attrs.PublicAccessPrevention != PublicAccessPreventionUnspecified { + t.Errorf("updating UBLA: got %s, want %s", attrs.PublicAccessPrevention, PublicAccessPreventionUnspecified) + } +} + func TestIntegration_ConditionalDelete(t *testing.T) { ctx := context.Background() client := testConfig(ctx, t) @@ -3178,6 +3265,54 @@ func TestIntegration_ReaderAttrs(t *testing.T) { } } +// Test that context cancellation correctly stops a download before completion. +func TestIntegration_ReaderCancel(t *testing.T) { + ctx := context.Background() + client := testConfig(ctx, t) + defer client.Close() + + bkt := client.Bucket(bucketName) + + // Upload a 1MB object. + obj := bkt.Object("reader-cancel-obj") + w := obj.NewWriter(ctx) + c := randomContents() + for i := 0; i < 62500; i++ { + if _, err := w.Write(c); err != nil { + t.Fatalf("writer.Write: %v", err) + } + + } + w.Close() + + // Create a reader (which makes a GET request to GCS and opens the body to + // read the object) and then cancel the context before reading. + readerCtx, cancel := context.WithCancel(ctx) + r, err := obj.NewReader(readerCtx) + if err != nil { + t.Fatalf("obj.NewReader: %v", err) + } + defer r.Close() + + cancel() + + // Read the object 1KB a time. We cannot guarantee that Reads will return a + // context canceled error immediately, but they should always do so before we + // reach EOF. + var readErr error + for i := 0; i < 1000; i++ { + buf := make([]byte, 1000) + _, readErr = r.Read(buf) + if readErr != nil { + if readErr == context.Canceled { + return + } + break + } + } + t.Fatalf("Reader.Read: got %v, want context.Canceled", readErr) +} + // Ensures that a file stored with a: // * Content-Encoding of "gzip" // * Content-Type of "text/plain" diff --git a/storage/internal/apiv1/doc.go b/storage/internal/apiv1/doc.go new file mode 100644 index 00000000000..f99c1727c55 --- /dev/null +++ b/storage/internal/apiv1/doc.go @@ -0,0 +1,122 @@ +// 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 storage is an auto-generated package for the +// Cloud Storage API. +// +// Lets you store and retrieve potentially-large, immutable data objects. +// +// NOTE: This package is in alpha. It is not stable, and is likely to change. +// +// 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 storage // import "cloud.google.com/go/storage/internal/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 = "20210701" + +func insertMetadata(ctx context.Context, mds ...metadata.MD) context.Context { + out, _ := metadata.FromOutgoingContext(ctx) + out = out.Copy() + for _, md := range mds { + for k, v := range md { + out[k] = append(out[k], v...) + } + } + return metadata.NewOutgoingContext(ctx, out) +} + +func checkDisableDeadlines() (bool, error) { + raw, ok := os.LookupEnv("GOOGLE_API_GO_EXPERIMENTAL_DISABLE_DEFAULT_DEADLINE") + if !ok { + return false, nil + } + + b, err := strconv.ParseBool(raw) + return b, err +} + +// DefaultAuthScopes reports the default set of authentication scopes to use with this package. +func DefaultAuthScopes() []string { + return []string{ + "https://www.googleapis.com/auth/cloud-platform", + "https://www.googleapis.com/auth/cloud-platform.read-only", + "https://www.googleapis.com/auth/devstorage.full_control", + "https://www.googleapis.com/auth/devstorage.read_only", + "https://www.googleapis.com/auth/devstorage.read_write", + } +} + +// 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/storage/internal/apiv1/gapic_metadata.json b/storage/internal/apiv1/gapic_metadata.json new file mode 100644 index 00000000000..d7b93b754de --- /dev/null +++ b/storage/internal/apiv1/gapic_metadata.json @@ -0,0 +1,298 @@ +{ + "schema": "1.0", + "comment": "This file maps proto services/RPCs to the corresponding library clients/methods.", + "language": "go", + "protoPackage": "google.storage.v1", + "libraryPackage": "cloud.google.com/go/storage/internal/apiv1", + "services": { + "Storage": { + "clients": { + "grpc": { + "libraryClient": "Client", + "rpcs": { + "ComposeObject": { + "methods": [ + "ComposeObject" + ] + }, + "CopyObject": { + "methods": [ + "CopyObject" + ] + }, + "CreateHmacKey": { + "methods": [ + "CreateHmacKey" + ] + }, + "DeleteBucket": { + "methods": [ + "DeleteBucket" + ] + }, + "DeleteBucketAccessControl": { + "methods": [ + "DeleteBucketAccessControl" + ] + }, + "DeleteDefaultObjectAccessControl": { + "methods": [ + "DeleteDefaultObjectAccessControl" + ] + }, + "DeleteHmacKey": { + "methods": [ + "DeleteHmacKey" + ] + }, + "DeleteNotification": { + "methods": [ + "DeleteNotification" + ] + }, + "DeleteObject": { + "methods": [ + "DeleteObject" + ] + }, + "DeleteObjectAccessControl": { + "methods": [ + "DeleteObjectAccessControl" + ] + }, + "GetBucket": { + "methods": [ + "GetBucket" + ] + }, + "GetBucketAccessControl": { + "methods": [ + "GetBucketAccessControl" + ] + }, + "GetBucketIamPolicy": { + "methods": [ + "GetBucketIamPolicy" + ] + }, + "GetDefaultObjectAccessControl": { + "methods": [ + "GetDefaultObjectAccessControl" + ] + }, + "GetHmacKey": { + "methods": [ + "GetHmacKey" + ] + }, + "GetNotification": { + "methods": [ + "GetNotification" + ] + }, + "GetObject": { + "methods": [ + "GetObject" + ] + }, + "GetObjectAccessControl": { + "methods": [ + "GetObjectAccessControl" + ] + }, + "GetObjectIamPolicy": { + "methods": [ + "GetObjectIamPolicy" + ] + }, + "GetObjectMedia": { + "methods": [ + "GetObjectMedia" + ] + }, + "GetServiceAccount": { + "methods": [ + "GetServiceAccount" + ] + }, + "InsertBucket": { + "methods": [ + "InsertBucket" + ] + }, + "InsertBucketAccessControl": { + "methods": [ + "InsertBucketAccessControl" + ] + }, + "InsertDefaultObjectAccessControl": { + "methods": [ + "InsertDefaultObjectAccessControl" + ] + }, + "InsertNotification": { + "methods": [ + "InsertNotification" + ] + }, + "InsertObject": { + "methods": [ + "InsertObject" + ] + }, + "InsertObjectAccessControl": { + "methods": [ + "InsertObjectAccessControl" + ] + }, + "ListBucketAccessControls": { + "methods": [ + "ListBucketAccessControls" + ] + }, + "ListBuckets": { + "methods": [ + "ListBuckets" + ] + }, + "ListChannels": { + "methods": [ + "ListChannels" + ] + }, + "ListDefaultObjectAccessControls": { + "methods": [ + "ListDefaultObjectAccessControls" + ] + }, + "ListHmacKeys": { + "methods": [ + "ListHmacKeys" + ] + }, + "ListNotifications": { + "methods": [ + "ListNotifications" + ] + }, + "ListObjectAccessControls": { + "methods": [ + "ListObjectAccessControls" + ] + }, + "ListObjects": { + "methods": [ + "ListObjects" + ] + }, + "LockBucketRetentionPolicy": { + "methods": [ + "LockBucketRetentionPolicy" + ] + }, + "PatchBucket": { + "methods": [ + "PatchBucket" + ] + }, + "PatchBucketAccessControl": { + "methods": [ + "PatchBucketAccessControl" + ] + }, + "PatchDefaultObjectAccessControl": { + "methods": [ + "PatchDefaultObjectAccessControl" + ] + }, + "PatchObject": { + "methods": [ + "PatchObject" + ] + }, + "PatchObjectAccessControl": { + "methods": [ + "PatchObjectAccessControl" + ] + }, + "QueryWriteStatus": { + "methods": [ + "QueryWriteStatus" + ] + }, + "RewriteObject": { + "methods": [ + "RewriteObject" + ] + }, + "SetBucketIamPolicy": { + "methods": [ + "SetBucketIamPolicy" + ] + }, + "SetObjectIamPolicy": { + "methods": [ + "SetObjectIamPolicy" + ] + }, + "StartResumableWrite": { + "methods": [ + "StartResumableWrite" + ] + }, + "StopChannel": { + "methods": [ + "StopChannel" + ] + }, + "TestBucketIamPermissions": { + "methods": [ + "TestBucketIamPermissions" + ] + }, + "TestObjectIamPermissions": { + "methods": [ + "TestObjectIamPermissions" + ] + }, + "UpdateBucket": { + "methods": [ + "UpdateBucket" + ] + }, + "UpdateBucketAccessControl": { + "methods": [ + "UpdateBucketAccessControl" + ] + }, + "UpdateDefaultObjectAccessControl": { + "methods": [ + "UpdateDefaultObjectAccessControl" + ] + }, + "UpdateHmacKey": { + "methods": [ + "UpdateHmacKey" + ] + }, + "UpdateObject": { + "methods": [ + "UpdateObject" + ] + }, + "UpdateObjectAccessControl": { + "methods": [ + "UpdateObjectAccessControl" + ] + }, + "WatchAllObjects": { + "methods": [ + "WatchAllObjects" + ] + } + } + } + } + } + } +} diff --git a/storage/internal/apiv1/storage_client.go b/storage/internal/apiv1/storage_client.go new file mode 100644 index 00000000000..994ed4556f9 --- /dev/null +++ b/storage/internal/apiv1/storage_client.go @@ -0,0 +1,2388 @@ +// 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 storage + +import ( + "context" + "math" + "time" + + 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" + iampb "google.golang.org/genproto/googleapis/iam/v1" + storagepb "google.golang.org/genproto/googleapis/storage/v1" + "google.golang.org/grpc" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/metadata" +) + +var newClientHook clientHook + +// CallOptions contains the retry settings for each method of Client. +type CallOptions struct { + DeleteBucketAccessControl []gax.CallOption + GetBucketAccessControl []gax.CallOption + InsertBucketAccessControl []gax.CallOption + ListBucketAccessControls []gax.CallOption + UpdateBucketAccessControl []gax.CallOption + PatchBucketAccessControl []gax.CallOption + DeleteBucket []gax.CallOption + GetBucket []gax.CallOption + InsertBucket []gax.CallOption + ListChannels []gax.CallOption + ListBuckets []gax.CallOption + LockBucketRetentionPolicy []gax.CallOption + GetBucketIamPolicy []gax.CallOption + SetBucketIamPolicy []gax.CallOption + TestBucketIamPermissions []gax.CallOption + PatchBucket []gax.CallOption + UpdateBucket []gax.CallOption + StopChannel []gax.CallOption + DeleteDefaultObjectAccessControl []gax.CallOption + GetDefaultObjectAccessControl []gax.CallOption + InsertDefaultObjectAccessControl []gax.CallOption + ListDefaultObjectAccessControls []gax.CallOption + PatchDefaultObjectAccessControl []gax.CallOption + UpdateDefaultObjectAccessControl []gax.CallOption + DeleteNotification []gax.CallOption + GetNotification []gax.CallOption + InsertNotification []gax.CallOption + ListNotifications []gax.CallOption + DeleteObjectAccessControl []gax.CallOption + GetObjectAccessControl []gax.CallOption + InsertObjectAccessControl []gax.CallOption + ListObjectAccessControls []gax.CallOption + PatchObjectAccessControl []gax.CallOption + UpdateObjectAccessControl []gax.CallOption + ComposeObject []gax.CallOption + CopyObject []gax.CallOption + DeleteObject []gax.CallOption + GetObject []gax.CallOption + GetObjectMedia []gax.CallOption + InsertObject []gax.CallOption + ListObjects []gax.CallOption + RewriteObject []gax.CallOption + StartResumableWrite []gax.CallOption + QueryWriteStatus []gax.CallOption + PatchObject []gax.CallOption + UpdateObject []gax.CallOption + GetObjectIamPolicy []gax.CallOption + SetObjectIamPolicy []gax.CallOption + TestObjectIamPermissions []gax.CallOption + WatchAllObjects []gax.CallOption + GetServiceAccount []gax.CallOption + CreateHmacKey []gax.CallOption + DeleteHmacKey []gax.CallOption + GetHmacKey []gax.CallOption + ListHmacKeys []gax.CallOption + UpdateHmacKey []gax.CallOption +} + +func defaultGRPCClientOptions() []option.ClientOption { + return []option.ClientOption{ + internaloption.WithDefaultEndpoint("storage.googleapis.com:443"), + internaloption.WithDefaultMTLSEndpoint("storage.mtls.googleapis.com:443"), + internaloption.WithDefaultAudience("https://storage.googleapis.com/"), + internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), + option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), + option.WithGRPCDialOption(grpc.WithDefaultCallOptions( + grpc.MaxCallRecvMsgSize(math.MaxInt32))), + } +} + +func defaultCallOptions() *CallOptions { + return &CallOptions{ + DeleteBucketAccessControl: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.DeadlineExceeded, + codes.Unavailable, + }, gax.Backoff{ + Initial: 1000 * time.Millisecond, + Max: 60000 * time.Millisecond, + Multiplier: 2.00, + }) + }), + }, + GetBucketAccessControl: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.DeadlineExceeded, + codes.Unavailable, + }, gax.Backoff{ + Initial: 1000 * time.Millisecond, + Max: 60000 * time.Millisecond, + Multiplier: 2.00, + }) + }), + }, + InsertBucketAccessControl: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.DeadlineExceeded, + codes.Unavailable, + }, gax.Backoff{ + Initial: 1000 * time.Millisecond, + Max: 60000 * time.Millisecond, + Multiplier: 2.00, + }) + }), + }, + ListBucketAccessControls: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.DeadlineExceeded, + codes.Unavailable, + }, gax.Backoff{ + Initial: 1000 * time.Millisecond, + Max: 60000 * time.Millisecond, + Multiplier: 2.00, + }) + }), + }, + UpdateBucketAccessControl: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.DeadlineExceeded, + codes.Unavailable, + }, gax.Backoff{ + Initial: 1000 * time.Millisecond, + Max: 60000 * time.Millisecond, + Multiplier: 2.00, + }) + }), + }, + PatchBucketAccessControl: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.DeadlineExceeded, + codes.Unavailable, + }, gax.Backoff{ + Initial: 1000 * time.Millisecond, + Max: 60000 * time.Millisecond, + Multiplier: 2.00, + }) + }), + }, + DeleteBucket: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.DeadlineExceeded, + codes.Unavailable, + }, gax.Backoff{ + Initial: 1000 * time.Millisecond, + Max: 60000 * time.Millisecond, + Multiplier: 2.00, + }) + }), + }, + GetBucket: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.DeadlineExceeded, + codes.Unavailable, + }, gax.Backoff{ + Initial: 1000 * time.Millisecond, + Max: 60000 * time.Millisecond, + Multiplier: 2.00, + }) + }), + }, + InsertBucket: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.DeadlineExceeded, + codes.Unavailable, + }, gax.Backoff{ + Initial: 1000 * time.Millisecond, + Max: 60000 * time.Millisecond, + Multiplier: 2.00, + }) + }), + }, + ListChannels: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.DeadlineExceeded, + codes.Unavailable, + }, gax.Backoff{ + Initial: 1000 * time.Millisecond, + Max: 60000 * time.Millisecond, + Multiplier: 2.00, + }) + }), + }, + ListBuckets: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.DeadlineExceeded, + codes.Unavailable, + }, gax.Backoff{ + Initial: 1000 * time.Millisecond, + Max: 60000 * time.Millisecond, + Multiplier: 2.00, + }) + }), + }, + LockBucketRetentionPolicy: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.DeadlineExceeded, + codes.Unavailable, + }, gax.Backoff{ + Initial: 1000 * time.Millisecond, + Max: 60000 * time.Millisecond, + Multiplier: 2.00, + }) + }), + }, + GetBucketIamPolicy: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.DeadlineExceeded, + codes.Unavailable, + }, gax.Backoff{ + Initial: 1000 * time.Millisecond, + Max: 60000 * time.Millisecond, + Multiplier: 2.00, + }) + }), + }, + SetBucketIamPolicy: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.DeadlineExceeded, + codes.Unavailable, + }, gax.Backoff{ + Initial: 1000 * time.Millisecond, + Max: 60000 * time.Millisecond, + Multiplier: 2.00, + }) + }), + }, + TestBucketIamPermissions: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.DeadlineExceeded, + codes.Unavailable, + }, gax.Backoff{ + Initial: 1000 * time.Millisecond, + Max: 60000 * time.Millisecond, + Multiplier: 2.00, + }) + }), + }, + PatchBucket: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.DeadlineExceeded, + codes.Unavailable, + }, gax.Backoff{ + Initial: 1000 * time.Millisecond, + Max: 60000 * time.Millisecond, + Multiplier: 2.00, + }) + }), + }, + UpdateBucket: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.DeadlineExceeded, + codes.Unavailable, + }, gax.Backoff{ + Initial: 1000 * time.Millisecond, + Max: 60000 * time.Millisecond, + Multiplier: 2.00, + }) + }), + }, + StopChannel: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.DeadlineExceeded, + codes.Unavailable, + }, gax.Backoff{ + Initial: 1000 * time.Millisecond, + Max: 60000 * time.Millisecond, + Multiplier: 2.00, + }) + }), + }, + DeleteDefaultObjectAccessControl: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.DeadlineExceeded, + codes.Unavailable, + }, gax.Backoff{ + Initial: 1000 * time.Millisecond, + Max: 60000 * time.Millisecond, + Multiplier: 2.00, + }) + }), + }, + GetDefaultObjectAccessControl: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.DeadlineExceeded, + codes.Unavailable, + }, gax.Backoff{ + Initial: 1000 * time.Millisecond, + Max: 60000 * time.Millisecond, + Multiplier: 2.00, + }) + }), + }, + InsertDefaultObjectAccessControl: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.DeadlineExceeded, + codes.Unavailable, + }, gax.Backoff{ + Initial: 1000 * time.Millisecond, + Max: 60000 * time.Millisecond, + Multiplier: 2.00, + }) + }), + }, + ListDefaultObjectAccessControls: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.DeadlineExceeded, + codes.Unavailable, + }, gax.Backoff{ + Initial: 1000 * time.Millisecond, + Max: 60000 * time.Millisecond, + Multiplier: 2.00, + }) + }), + }, + PatchDefaultObjectAccessControl: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.DeadlineExceeded, + codes.Unavailable, + }, gax.Backoff{ + Initial: 1000 * time.Millisecond, + Max: 60000 * time.Millisecond, + Multiplier: 2.00, + }) + }), + }, + UpdateDefaultObjectAccessControl: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.DeadlineExceeded, + codes.Unavailable, + }, gax.Backoff{ + Initial: 1000 * time.Millisecond, + Max: 60000 * time.Millisecond, + Multiplier: 2.00, + }) + }), + }, + DeleteNotification: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.DeadlineExceeded, + codes.Unavailable, + }, gax.Backoff{ + Initial: 1000 * time.Millisecond, + Max: 60000 * time.Millisecond, + Multiplier: 2.00, + }) + }), + }, + GetNotification: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.DeadlineExceeded, + codes.Unavailable, + }, gax.Backoff{ + Initial: 1000 * time.Millisecond, + Max: 60000 * time.Millisecond, + Multiplier: 2.00, + }) + }), + }, + InsertNotification: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.DeadlineExceeded, + codes.Unavailable, + }, gax.Backoff{ + Initial: 1000 * time.Millisecond, + Max: 60000 * time.Millisecond, + Multiplier: 2.00, + }) + }), + }, + ListNotifications: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.DeadlineExceeded, + codes.Unavailable, + }, gax.Backoff{ + Initial: 1000 * time.Millisecond, + Max: 60000 * time.Millisecond, + Multiplier: 2.00, + }) + }), + }, + DeleteObjectAccessControl: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.DeadlineExceeded, + codes.Unavailable, + }, gax.Backoff{ + Initial: 1000 * time.Millisecond, + Max: 60000 * time.Millisecond, + Multiplier: 2.00, + }) + }), + }, + GetObjectAccessControl: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.DeadlineExceeded, + codes.Unavailable, + }, gax.Backoff{ + Initial: 1000 * time.Millisecond, + Max: 60000 * time.Millisecond, + Multiplier: 2.00, + }) + }), + }, + InsertObjectAccessControl: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.DeadlineExceeded, + codes.Unavailable, + }, gax.Backoff{ + Initial: 1000 * time.Millisecond, + Max: 60000 * time.Millisecond, + Multiplier: 2.00, + }) + }), + }, + ListObjectAccessControls: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.DeadlineExceeded, + codes.Unavailable, + }, gax.Backoff{ + Initial: 1000 * time.Millisecond, + Max: 60000 * time.Millisecond, + Multiplier: 2.00, + }) + }), + }, + PatchObjectAccessControl: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.DeadlineExceeded, + codes.Unavailable, + }, gax.Backoff{ + Initial: 1000 * time.Millisecond, + Max: 60000 * time.Millisecond, + Multiplier: 2.00, + }) + }), + }, + UpdateObjectAccessControl: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.DeadlineExceeded, + codes.Unavailable, + }, gax.Backoff{ + Initial: 1000 * time.Millisecond, + Max: 60000 * time.Millisecond, + Multiplier: 2.00, + }) + }), + }, + ComposeObject: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.DeadlineExceeded, + codes.Unavailable, + }, gax.Backoff{ + Initial: 1000 * time.Millisecond, + Max: 60000 * time.Millisecond, + Multiplier: 2.00, + }) + }), + }, + CopyObject: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.DeadlineExceeded, + codes.Unavailable, + }, gax.Backoff{ + Initial: 1000 * time.Millisecond, + Max: 60000 * time.Millisecond, + Multiplier: 2.00, + }) + }), + }, + DeleteObject: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.DeadlineExceeded, + codes.Unavailable, + }, gax.Backoff{ + Initial: 1000 * time.Millisecond, + Max: 60000 * time.Millisecond, + Multiplier: 2.00, + }) + }), + }, + GetObject: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.DeadlineExceeded, + codes.Unavailable, + }, gax.Backoff{ + Initial: 1000 * time.Millisecond, + Max: 60000 * time.Millisecond, + Multiplier: 2.00, + }) + }), + }, + GetObjectMedia: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.DeadlineExceeded, + codes.Unavailable, + }, gax.Backoff{ + Initial: 1000 * time.Millisecond, + Max: 60000 * time.Millisecond, + Multiplier: 2.00, + }) + }), + }, + InsertObject: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.DeadlineExceeded, + codes.Unavailable, + }, gax.Backoff{ + Initial: 1000 * time.Millisecond, + Max: 60000 * time.Millisecond, + Multiplier: 2.00, + }) + }), + }, + ListObjects: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.DeadlineExceeded, + codes.Unavailable, + }, gax.Backoff{ + Initial: 1000 * time.Millisecond, + Max: 60000 * time.Millisecond, + Multiplier: 2.00, + }) + }), + }, + RewriteObject: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.DeadlineExceeded, + codes.Unavailable, + }, gax.Backoff{ + Initial: 1000 * time.Millisecond, + Max: 60000 * time.Millisecond, + Multiplier: 2.00, + }) + }), + }, + StartResumableWrite: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.DeadlineExceeded, + codes.Unavailable, + }, gax.Backoff{ + Initial: 1000 * time.Millisecond, + Max: 60000 * time.Millisecond, + Multiplier: 2.00, + }) + }), + }, + QueryWriteStatus: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.DeadlineExceeded, + codes.Unavailable, + }, gax.Backoff{ + Initial: 1000 * time.Millisecond, + Max: 60000 * time.Millisecond, + Multiplier: 2.00, + }) + }), + }, + PatchObject: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.DeadlineExceeded, + codes.Unavailable, + }, gax.Backoff{ + Initial: 1000 * time.Millisecond, + Max: 60000 * time.Millisecond, + Multiplier: 2.00, + }) + }), + }, + UpdateObject: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.DeadlineExceeded, + codes.Unavailable, + }, gax.Backoff{ + Initial: 1000 * time.Millisecond, + Max: 60000 * time.Millisecond, + Multiplier: 2.00, + }) + }), + }, + GetObjectIamPolicy: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.DeadlineExceeded, + codes.Unavailable, + }, gax.Backoff{ + Initial: 1000 * time.Millisecond, + Max: 60000 * time.Millisecond, + Multiplier: 2.00, + }) + }), + }, + SetObjectIamPolicy: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.DeadlineExceeded, + codes.Unavailable, + }, gax.Backoff{ + Initial: 1000 * time.Millisecond, + Max: 60000 * time.Millisecond, + Multiplier: 2.00, + }) + }), + }, + TestObjectIamPermissions: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.DeadlineExceeded, + codes.Unavailable, + }, gax.Backoff{ + Initial: 1000 * time.Millisecond, + Max: 60000 * time.Millisecond, + Multiplier: 2.00, + }) + }), + }, + WatchAllObjects: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.DeadlineExceeded, + codes.Unavailable, + }, gax.Backoff{ + Initial: 1000 * time.Millisecond, + Max: 60000 * time.Millisecond, + Multiplier: 2.00, + }) + }), + }, + GetServiceAccount: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.DeadlineExceeded, + codes.Unavailable, + }, gax.Backoff{ + Initial: 1000 * time.Millisecond, + Max: 60000 * time.Millisecond, + Multiplier: 2.00, + }) + }), + }, + CreateHmacKey: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.DeadlineExceeded, + codes.Unavailable, + }, gax.Backoff{ + Initial: 1000 * time.Millisecond, + Max: 60000 * time.Millisecond, + Multiplier: 2.00, + }) + }), + }, + DeleteHmacKey: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.DeadlineExceeded, + codes.Unavailable, + }, gax.Backoff{ + Initial: 1000 * time.Millisecond, + Max: 60000 * time.Millisecond, + Multiplier: 2.00, + }) + }), + }, + GetHmacKey: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.DeadlineExceeded, + codes.Unavailable, + }, gax.Backoff{ + Initial: 1000 * time.Millisecond, + Max: 60000 * time.Millisecond, + Multiplier: 2.00, + }) + }), + }, + ListHmacKeys: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.DeadlineExceeded, + codes.Unavailable, + }, gax.Backoff{ + Initial: 1000 * time.Millisecond, + Max: 60000 * time.Millisecond, + Multiplier: 2.00, + }) + }), + }, + UpdateHmacKey: []gax.CallOption{ + gax.WithRetry(func() gax.Retryer { + return gax.OnCodes([]codes.Code{ + codes.DeadlineExceeded, + codes.Unavailable, + }, gax.Backoff{ + Initial: 1000 * time.Millisecond, + Max: 60000 * time.Millisecond, + Multiplier: 2.00, + }) + }), + }, + } +} + +// internalClient is an interface that defines the methods availaible from Cloud Storage API. +type internalClient interface { + Close() error + setGoogleClientInfo(...string) + Connection() *grpc.ClientConn + DeleteBucketAccessControl(context.Context, *storagepb.DeleteBucketAccessControlRequest, ...gax.CallOption) error + GetBucketAccessControl(context.Context, *storagepb.GetBucketAccessControlRequest, ...gax.CallOption) (*storagepb.BucketAccessControl, error) + InsertBucketAccessControl(context.Context, *storagepb.InsertBucketAccessControlRequest, ...gax.CallOption) (*storagepb.BucketAccessControl, error) + ListBucketAccessControls(context.Context, *storagepb.ListBucketAccessControlsRequest, ...gax.CallOption) (*storagepb.ListBucketAccessControlsResponse, error) + UpdateBucketAccessControl(context.Context, *storagepb.UpdateBucketAccessControlRequest, ...gax.CallOption) (*storagepb.BucketAccessControl, error) + PatchBucketAccessControl(context.Context, *storagepb.PatchBucketAccessControlRequest, ...gax.CallOption) (*storagepb.BucketAccessControl, error) + DeleteBucket(context.Context, *storagepb.DeleteBucketRequest, ...gax.CallOption) error + GetBucket(context.Context, *storagepb.GetBucketRequest, ...gax.CallOption) (*storagepb.Bucket, error) + InsertBucket(context.Context, *storagepb.InsertBucketRequest, ...gax.CallOption) (*storagepb.Bucket, error) + ListChannels(context.Context, *storagepb.ListChannelsRequest, ...gax.CallOption) (*storagepb.ListChannelsResponse, error) + ListBuckets(context.Context, *storagepb.ListBucketsRequest, ...gax.CallOption) (*storagepb.ListBucketsResponse, error) + LockBucketRetentionPolicy(context.Context, *storagepb.LockRetentionPolicyRequest, ...gax.CallOption) (*storagepb.Bucket, error) + GetBucketIamPolicy(context.Context, *storagepb.GetIamPolicyRequest, ...gax.CallOption) (*iampb.Policy, error) + SetBucketIamPolicy(context.Context, *storagepb.SetIamPolicyRequest, ...gax.CallOption) (*iampb.Policy, error) + TestBucketIamPermissions(context.Context, *storagepb.TestIamPermissionsRequest, ...gax.CallOption) (*iampb.TestIamPermissionsResponse, error) + PatchBucket(context.Context, *storagepb.PatchBucketRequest, ...gax.CallOption) (*storagepb.Bucket, error) + UpdateBucket(context.Context, *storagepb.UpdateBucketRequest, ...gax.CallOption) (*storagepb.Bucket, error) + StopChannel(context.Context, *storagepb.StopChannelRequest, ...gax.CallOption) error + DeleteDefaultObjectAccessControl(context.Context, *storagepb.DeleteDefaultObjectAccessControlRequest, ...gax.CallOption) error + GetDefaultObjectAccessControl(context.Context, *storagepb.GetDefaultObjectAccessControlRequest, ...gax.CallOption) (*storagepb.ObjectAccessControl, error) + InsertDefaultObjectAccessControl(context.Context, *storagepb.InsertDefaultObjectAccessControlRequest, ...gax.CallOption) (*storagepb.ObjectAccessControl, error) + ListDefaultObjectAccessControls(context.Context, *storagepb.ListDefaultObjectAccessControlsRequest, ...gax.CallOption) (*storagepb.ListObjectAccessControlsResponse, error) + PatchDefaultObjectAccessControl(context.Context, *storagepb.PatchDefaultObjectAccessControlRequest, ...gax.CallOption) (*storagepb.ObjectAccessControl, error) + UpdateDefaultObjectAccessControl(context.Context, *storagepb.UpdateDefaultObjectAccessControlRequest, ...gax.CallOption) (*storagepb.ObjectAccessControl, error) + DeleteNotification(context.Context, *storagepb.DeleteNotificationRequest, ...gax.CallOption) error + GetNotification(context.Context, *storagepb.GetNotificationRequest, ...gax.CallOption) (*storagepb.Notification, error) + InsertNotification(context.Context, *storagepb.InsertNotificationRequest, ...gax.CallOption) (*storagepb.Notification, error) + ListNotifications(context.Context, *storagepb.ListNotificationsRequest, ...gax.CallOption) (*storagepb.ListNotificationsResponse, error) + DeleteObjectAccessControl(context.Context, *storagepb.DeleteObjectAccessControlRequest, ...gax.CallOption) error + GetObjectAccessControl(context.Context, *storagepb.GetObjectAccessControlRequest, ...gax.CallOption) (*storagepb.ObjectAccessControl, error) + InsertObjectAccessControl(context.Context, *storagepb.InsertObjectAccessControlRequest, ...gax.CallOption) (*storagepb.ObjectAccessControl, error) + ListObjectAccessControls(context.Context, *storagepb.ListObjectAccessControlsRequest, ...gax.CallOption) (*storagepb.ListObjectAccessControlsResponse, error) + PatchObjectAccessControl(context.Context, *storagepb.PatchObjectAccessControlRequest, ...gax.CallOption) (*storagepb.ObjectAccessControl, error) + UpdateObjectAccessControl(context.Context, *storagepb.UpdateObjectAccessControlRequest, ...gax.CallOption) (*storagepb.ObjectAccessControl, error) + ComposeObject(context.Context, *storagepb.ComposeObjectRequest, ...gax.CallOption) (*storagepb.Object, error) + CopyObject(context.Context, *storagepb.CopyObjectRequest, ...gax.CallOption) (*storagepb.Object, error) + DeleteObject(context.Context, *storagepb.DeleteObjectRequest, ...gax.CallOption) error + GetObject(context.Context, *storagepb.GetObjectRequest, ...gax.CallOption) (*storagepb.Object, error) + GetObjectMedia(context.Context, *storagepb.GetObjectMediaRequest, ...gax.CallOption) (storagepb.Storage_GetObjectMediaClient, error) + InsertObject(context.Context, ...gax.CallOption) (storagepb.Storage_InsertObjectClient, error) + ListObjects(context.Context, *storagepb.ListObjectsRequest, ...gax.CallOption) (*storagepb.ListObjectsResponse, error) + RewriteObject(context.Context, *storagepb.RewriteObjectRequest, ...gax.CallOption) (*storagepb.RewriteResponse, error) + StartResumableWrite(context.Context, *storagepb.StartResumableWriteRequest, ...gax.CallOption) (*storagepb.StartResumableWriteResponse, error) + QueryWriteStatus(context.Context, *storagepb.QueryWriteStatusRequest, ...gax.CallOption) (*storagepb.QueryWriteStatusResponse, error) + PatchObject(context.Context, *storagepb.PatchObjectRequest, ...gax.CallOption) (*storagepb.Object, error) + UpdateObject(context.Context, *storagepb.UpdateObjectRequest, ...gax.CallOption) (*storagepb.Object, error) + GetObjectIamPolicy(context.Context, *storagepb.GetIamPolicyRequest, ...gax.CallOption) (*iampb.Policy, error) + SetObjectIamPolicy(context.Context, *storagepb.SetIamPolicyRequest, ...gax.CallOption) (*iampb.Policy, error) + TestObjectIamPermissions(context.Context, *storagepb.TestIamPermissionsRequest, ...gax.CallOption) (*iampb.TestIamPermissionsResponse, error) + WatchAllObjects(context.Context, *storagepb.WatchAllObjectsRequest, ...gax.CallOption) (*storagepb.Channel, error) + GetServiceAccount(context.Context, *storagepb.GetProjectServiceAccountRequest, ...gax.CallOption) (*storagepb.ServiceAccount, error) + CreateHmacKey(context.Context, *storagepb.CreateHmacKeyRequest, ...gax.CallOption) (*storagepb.CreateHmacKeyResponse, error) + DeleteHmacKey(context.Context, *storagepb.DeleteHmacKeyRequest, ...gax.CallOption) error + GetHmacKey(context.Context, *storagepb.GetHmacKeyRequest, ...gax.CallOption) (*storagepb.HmacKeyMetadata, error) + ListHmacKeys(context.Context, *storagepb.ListHmacKeysRequest, ...gax.CallOption) (*storagepb.ListHmacKeysResponse, error) + UpdateHmacKey(context.Context, *storagepb.UpdateHmacKeyRequest, ...gax.CallOption) (*storagepb.HmacKeyMetadata, error) +} + +// Client is a client for interacting with Cloud Storage API. +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +// +// Manages Google Cloud Storage resources. +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() +} + +// DeleteBucketAccessControl permanently deletes the ACL entry for the specified entity on the specified +// bucket. +func (c *Client) DeleteBucketAccessControl(ctx context.Context, req *storagepb.DeleteBucketAccessControlRequest, opts ...gax.CallOption) error { + return c.internalClient.DeleteBucketAccessControl(ctx, req, opts...) +} + +// GetBucketAccessControl returns the ACL entry for the specified entity on the specified bucket. +func (c *Client) GetBucketAccessControl(ctx context.Context, req *storagepb.GetBucketAccessControlRequest, opts ...gax.CallOption) (*storagepb.BucketAccessControl, error) { + return c.internalClient.GetBucketAccessControl(ctx, req, opts...) +} + +// InsertBucketAccessControl creates a new ACL entry on the specified bucket. +func (c *Client) InsertBucketAccessControl(ctx context.Context, req *storagepb.InsertBucketAccessControlRequest, opts ...gax.CallOption) (*storagepb.BucketAccessControl, error) { + return c.internalClient.InsertBucketAccessControl(ctx, req, opts...) +} + +// ListBucketAccessControls retrieves ACL entries on the specified bucket. +func (c *Client) ListBucketAccessControls(ctx context.Context, req *storagepb.ListBucketAccessControlsRequest, opts ...gax.CallOption) (*storagepb.ListBucketAccessControlsResponse, error) { + return c.internalClient.ListBucketAccessControls(ctx, req, opts...) +} + +// UpdateBucketAccessControl updates an ACL entry on the specified bucket. Equivalent to +// PatchBucketAccessControl, but all unspecified fields will be +// reset to their default values. +func (c *Client) UpdateBucketAccessControl(ctx context.Context, req *storagepb.UpdateBucketAccessControlRequest, opts ...gax.CallOption) (*storagepb.BucketAccessControl, error) { + return c.internalClient.UpdateBucketAccessControl(ctx, req, opts...) +} + +// PatchBucketAccessControl updates an ACL entry on the specified bucket. +func (c *Client) PatchBucketAccessControl(ctx context.Context, req *storagepb.PatchBucketAccessControlRequest, opts ...gax.CallOption) (*storagepb.BucketAccessControl, error) { + return c.internalClient.PatchBucketAccessControl(ctx, req, opts...) +} + +// DeleteBucket permanently deletes an empty bucket. +func (c *Client) DeleteBucket(ctx context.Context, req *storagepb.DeleteBucketRequest, opts ...gax.CallOption) error { + return c.internalClient.DeleteBucket(ctx, req, opts...) +} + +// GetBucket returns metadata for the specified bucket. +func (c *Client) GetBucket(ctx context.Context, req *storagepb.GetBucketRequest, opts ...gax.CallOption) (*storagepb.Bucket, error) { + return c.internalClient.GetBucket(ctx, req, opts...) +} + +// InsertBucket creates a new bucket. +func (c *Client) InsertBucket(ctx context.Context, req *storagepb.InsertBucketRequest, opts ...gax.CallOption) (*storagepb.Bucket, error) { + return c.internalClient.InsertBucket(ctx, req, opts...) +} + +// ListChannels list active object change notification channels for this bucket. +func (c *Client) ListChannels(ctx context.Context, req *storagepb.ListChannelsRequest, opts ...gax.CallOption) (*storagepb.ListChannelsResponse, error) { + return c.internalClient.ListChannels(ctx, req, opts...) +} + +// ListBuckets retrieves a list of buckets for a given project. +func (c *Client) ListBuckets(ctx context.Context, req *storagepb.ListBucketsRequest, opts ...gax.CallOption) (*storagepb.ListBucketsResponse, error) { + return c.internalClient.ListBuckets(ctx, req, opts...) +} + +// LockBucketRetentionPolicy locks retention policy on a bucket. +func (c *Client) LockBucketRetentionPolicy(ctx context.Context, req *storagepb.LockRetentionPolicyRequest, opts ...gax.CallOption) (*storagepb.Bucket, error) { + return c.internalClient.LockBucketRetentionPolicy(ctx, req, opts...) +} + +// GetBucketIamPolicy gets the IAM policy for the specified bucket. +func (c *Client) GetBucketIamPolicy(ctx context.Context, req *storagepb.GetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) { + return c.internalClient.GetBucketIamPolicy(ctx, req, opts...) +} + +// SetBucketIamPolicy updates an IAM policy for the specified bucket. +func (c *Client) SetBucketIamPolicy(ctx context.Context, req *storagepb.SetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) { + return c.internalClient.SetBucketIamPolicy(ctx, req, opts...) +} + +// TestBucketIamPermissions tests a set of permissions on the given bucket to see which, if +// any, are held by the caller. +func (c *Client) TestBucketIamPermissions(ctx context.Context, req *storagepb.TestIamPermissionsRequest, opts ...gax.CallOption) (*iampb.TestIamPermissionsResponse, error) { + return c.internalClient.TestBucketIamPermissions(ctx, req, opts...) +} + +// PatchBucket updates a bucket. Changes to the bucket will be readable immediately after +// writing, but configuration changes may take time to propagate. +func (c *Client) PatchBucket(ctx context.Context, req *storagepb.PatchBucketRequest, opts ...gax.CallOption) (*storagepb.Bucket, error) { + return c.internalClient.PatchBucket(ctx, req, opts...) +} + +// UpdateBucket updates a bucket. Equivalent to PatchBucket, but always replaces all +// mutatable fields of the bucket with new values, reverting all +// unspecified fields to their default values. +// Like PatchBucket, Changes to the bucket will be readable immediately after +// writing, but configuration changes may take time to propagate. +func (c *Client) UpdateBucket(ctx context.Context, req *storagepb.UpdateBucketRequest, opts ...gax.CallOption) (*storagepb.Bucket, error) { + return c.internalClient.UpdateBucket(ctx, req, opts...) +} + +// StopChannel halts “Object Change Notification” push messagages. +// See https://cloud.google.com/storage/docs/object-change-notification (at https://cloud.google.com/storage/docs/object-change-notification) +// Note: this is not related to the newer “Notifications” resource, which +// are stopped using DeleteNotification. +func (c *Client) StopChannel(ctx context.Context, req *storagepb.StopChannelRequest, opts ...gax.CallOption) error { + return c.internalClient.StopChannel(ctx, req, opts...) +} + +// DeleteDefaultObjectAccessControl permanently deletes the default object ACL entry for the specified entity +// on the specified bucket. +func (c *Client) DeleteDefaultObjectAccessControl(ctx context.Context, req *storagepb.DeleteDefaultObjectAccessControlRequest, opts ...gax.CallOption) error { + return c.internalClient.DeleteDefaultObjectAccessControl(ctx, req, opts...) +} + +// GetDefaultObjectAccessControl returns the default object ACL entry for the specified entity on the +// specified bucket. +func (c *Client) GetDefaultObjectAccessControl(ctx context.Context, req *storagepb.GetDefaultObjectAccessControlRequest, opts ...gax.CallOption) (*storagepb.ObjectAccessControl, error) { + return c.internalClient.GetDefaultObjectAccessControl(ctx, req, opts...) +} + +// InsertDefaultObjectAccessControl creates a new default object ACL entry on the specified bucket. +func (c *Client) InsertDefaultObjectAccessControl(ctx context.Context, req *storagepb.InsertDefaultObjectAccessControlRequest, opts ...gax.CallOption) (*storagepb.ObjectAccessControl, error) { + return c.internalClient.InsertDefaultObjectAccessControl(ctx, req, opts...) +} + +// ListDefaultObjectAccessControls retrieves default object ACL entries on the specified bucket. +func (c *Client) ListDefaultObjectAccessControls(ctx context.Context, req *storagepb.ListDefaultObjectAccessControlsRequest, opts ...gax.CallOption) (*storagepb.ListObjectAccessControlsResponse, error) { + return c.internalClient.ListDefaultObjectAccessControls(ctx, req, opts...) +} + +// PatchDefaultObjectAccessControl updates a default object ACL entry on the specified bucket. +func (c *Client) PatchDefaultObjectAccessControl(ctx context.Context, req *storagepb.PatchDefaultObjectAccessControlRequest, opts ...gax.CallOption) (*storagepb.ObjectAccessControl, error) { + return c.internalClient.PatchDefaultObjectAccessControl(ctx, req, opts...) +} + +// UpdateDefaultObjectAccessControl updates a default object ACL entry on the specified bucket. Equivalent to +// PatchDefaultObjectAccessControl, but modifies all unspecified fields to +// their default values. +func (c *Client) UpdateDefaultObjectAccessControl(ctx context.Context, req *storagepb.UpdateDefaultObjectAccessControlRequest, opts ...gax.CallOption) (*storagepb.ObjectAccessControl, error) { + return c.internalClient.UpdateDefaultObjectAccessControl(ctx, req, opts...) +} + +// DeleteNotification permanently deletes a notification subscription. +// Note: Older, “Object Change Notification” push subscriptions should be +// deleted using StopChannel instead. +func (c *Client) DeleteNotification(ctx context.Context, req *storagepb.DeleteNotificationRequest, opts ...gax.CallOption) error { + return c.internalClient.DeleteNotification(ctx, req, opts...) +} + +// GetNotification view a notification configuration. +func (c *Client) GetNotification(ctx context.Context, req *storagepb.GetNotificationRequest, opts ...gax.CallOption) (*storagepb.Notification, error) { + return c.internalClient.GetNotification(ctx, req, opts...) +} + +// InsertNotification creates a notification subscription for a given bucket. +// These notifications, when triggered, publish messages to the specified +// Cloud Pub/Sub topics. +// See https://cloud.google.com/storage/docs/pubsub-notifications (at https://cloud.google.com/storage/docs/pubsub-notifications). +func (c *Client) InsertNotification(ctx context.Context, req *storagepb.InsertNotificationRequest, opts ...gax.CallOption) (*storagepb.Notification, error) { + return c.internalClient.InsertNotification(ctx, req, opts...) +} + +// ListNotifications retrieves a list of notification subscriptions for a given bucket. +func (c *Client) ListNotifications(ctx context.Context, req *storagepb.ListNotificationsRequest, opts ...gax.CallOption) (*storagepb.ListNotificationsResponse, error) { + return c.internalClient.ListNotifications(ctx, req, opts...) +} + +// DeleteObjectAccessControl permanently deletes the ACL entry for the specified entity on the specified +// object. +func (c *Client) DeleteObjectAccessControl(ctx context.Context, req *storagepb.DeleteObjectAccessControlRequest, opts ...gax.CallOption) error { + return c.internalClient.DeleteObjectAccessControl(ctx, req, opts...) +} + +// GetObjectAccessControl returns the ACL entry for the specified entity on the specified object. +func (c *Client) GetObjectAccessControl(ctx context.Context, req *storagepb.GetObjectAccessControlRequest, opts ...gax.CallOption) (*storagepb.ObjectAccessControl, error) { + return c.internalClient.GetObjectAccessControl(ctx, req, opts...) +} + +// InsertObjectAccessControl creates a new ACL entry on the specified object. +func (c *Client) InsertObjectAccessControl(ctx context.Context, req *storagepb.InsertObjectAccessControlRequest, opts ...gax.CallOption) (*storagepb.ObjectAccessControl, error) { + return c.internalClient.InsertObjectAccessControl(ctx, req, opts...) +} + +// ListObjectAccessControls retrieves ACL entries on the specified object. +func (c *Client) ListObjectAccessControls(ctx context.Context, req *storagepb.ListObjectAccessControlsRequest, opts ...gax.CallOption) (*storagepb.ListObjectAccessControlsResponse, error) { + return c.internalClient.ListObjectAccessControls(ctx, req, opts...) +} + +// PatchObjectAccessControl patches an ACL entry on the specified object. Patch is similar to update, +// but only applies or appends the specified fields in the +// object_access_control object. Other fields are unaffected. +func (c *Client) PatchObjectAccessControl(ctx context.Context, req *storagepb.PatchObjectAccessControlRequest, opts ...gax.CallOption) (*storagepb.ObjectAccessControl, error) { + return c.internalClient.PatchObjectAccessControl(ctx, req, opts...) +} + +// UpdateObjectAccessControl updates an ACL entry on the specified object. +func (c *Client) UpdateObjectAccessControl(ctx context.Context, req *storagepb.UpdateObjectAccessControlRequest, opts ...gax.CallOption) (*storagepb.ObjectAccessControl, error) { + return c.internalClient.UpdateObjectAccessControl(ctx, req, opts...) +} + +// ComposeObject concatenates a list of existing objects into a new object in the same +// bucket. +func (c *Client) ComposeObject(ctx context.Context, req *storagepb.ComposeObjectRequest, opts ...gax.CallOption) (*storagepb.Object, error) { + return c.internalClient.ComposeObject(ctx, req, opts...) +} + +// CopyObject copies a source object to a destination object. Optionally overrides +// metadata. +func (c *Client) CopyObject(ctx context.Context, req *storagepb.CopyObjectRequest, opts ...gax.CallOption) (*storagepb.Object, error) { + return c.internalClient.CopyObject(ctx, req, opts...) +} + +// DeleteObject deletes an object and its metadata. Deletions are permanent if versioning +// is not enabled for the bucket, or if the generation parameter +// is used. +func (c *Client) DeleteObject(ctx context.Context, req *storagepb.DeleteObjectRequest, opts ...gax.CallOption) error { + return c.internalClient.DeleteObject(ctx, req, opts...) +} + +// GetObject retrieves an object’s metadata. +func (c *Client) GetObject(ctx context.Context, req *storagepb.GetObjectRequest, opts ...gax.CallOption) (*storagepb.Object, error) { + return c.internalClient.GetObject(ctx, req, opts...) +} + +// GetObjectMedia reads an object’s data. +func (c *Client) GetObjectMedia(ctx context.Context, req *storagepb.GetObjectMediaRequest, opts ...gax.CallOption) (storagepb.Storage_GetObjectMediaClient, error) { + return c.internalClient.GetObjectMedia(ctx, req, opts...) +} + +// InsertObject stores a new object and metadata. +// +// An object can be written either in a single message stream or in a +// resumable sequence of message streams. To write using a single stream, +// the client should include in the first message of the stream an +// InsertObjectSpec describing the destination bucket, object, and any +// preconditions. Additionally, the final message must set ‘finish_write’ to +// true, or else it is an error. +// +// For a resumable write, the client should instead call +// StartResumableWrite() and provide that method an InsertObjectSpec. +// They should then attach the returned upload_id to the first message of +// each following call to Insert. If there is an error or the connection is +// broken during the resumable Insert(), the client should check the status +// of the Insert() by calling QueryWriteStatus() and continue writing from +// the returned committed_size. This may be less than the amount of data the +// client previously sent. +// +// The service will not view the object as complete until the client has +// sent an Insert with finish_write set to true. Sending any +// requests on a stream after sending a request with finish_write set to +// true will cause an error. The client should check the +// Object it receives to determine how much data the service was +// able to commit and whether the service views the object as complete. +func (c *Client) InsertObject(ctx context.Context, opts ...gax.CallOption) (storagepb.Storage_InsertObjectClient, error) { + return c.internalClient.InsertObject(ctx, opts...) +} + +// ListObjects retrieves a list of objects matching the criteria. +func (c *Client) ListObjects(ctx context.Context, req *storagepb.ListObjectsRequest, opts ...gax.CallOption) (*storagepb.ListObjectsResponse, error) { + return c.internalClient.ListObjects(ctx, req, opts...) +} + +// RewriteObject rewrites a source object to a destination object. Optionally overrides +// metadata. +func (c *Client) RewriteObject(ctx context.Context, req *storagepb.RewriteObjectRequest, opts ...gax.CallOption) (*storagepb.RewriteResponse, error) { + return c.internalClient.RewriteObject(ctx, req, opts...) +} + +// StartResumableWrite starts a resumable write. How long the write operation remains valid, and +// what happens when the write operation becomes invalid, are +// service-dependent. +func (c *Client) StartResumableWrite(ctx context.Context, req *storagepb.StartResumableWriteRequest, opts ...gax.CallOption) (*storagepb.StartResumableWriteResponse, error) { + return c.internalClient.StartResumableWrite(ctx, req, opts...) +} + +// QueryWriteStatus determines the committed_size for an object that is being written, which +// can then be used as the write_offset for the next Write() call. +// +// If the object does not exist (i.e., the object has been deleted, or the +// first Write() has not yet reached the service), this method returns the +// error NOT_FOUND. +// +// The client may call QueryWriteStatus() at any time to determine how +// much data has been processed for this object. This is useful if the +// client is buffering data and needs to know which data can be safely +// evicted. For any sequence of QueryWriteStatus() calls for a given +// object name, the sequence of returned committed_size values will be +// non-decreasing. +func (c *Client) QueryWriteStatus(ctx context.Context, req *storagepb.QueryWriteStatusRequest, opts ...gax.CallOption) (*storagepb.QueryWriteStatusResponse, error) { + return c.internalClient.QueryWriteStatus(ctx, req, opts...) +} + +// PatchObject updates an object’s metadata. +func (c *Client) PatchObject(ctx context.Context, req *storagepb.PatchObjectRequest, opts ...gax.CallOption) (*storagepb.Object, error) { + return c.internalClient.PatchObject(ctx, req, opts...) +} + +// UpdateObject updates an object’s metadata. Equivalent to PatchObject, but always +// replaces all mutatable fields of the bucket with new values, reverting all +// unspecified fields to their default values. +func (c *Client) UpdateObject(ctx context.Context, req *storagepb.UpdateObjectRequest, opts ...gax.CallOption) (*storagepb.Object, error) { + return c.internalClient.UpdateObject(ctx, req, opts...) +} + +// GetObjectIamPolicy gets the IAM policy for the specified object. +func (c *Client) GetObjectIamPolicy(ctx context.Context, req *storagepb.GetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) { + return c.internalClient.GetObjectIamPolicy(ctx, req, opts...) +} + +// SetObjectIamPolicy updates an IAM policy for the specified object. +func (c *Client) SetObjectIamPolicy(ctx context.Context, req *storagepb.SetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) { + return c.internalClient.SetObjectIamPolicy(ctx, req, opts...) +} + +// TestObjectIamPermissions tests a set of permissions on the given object to see which, if +// any, are held by the caller. +func (c *Client) TestObjectIamPermissions(ctx context.Context, req *storagepb.TestIamPermissionsRequest, opts ...gax.CallOption) (*iampb.TestIamPermissionsResponse, error) { + return c.internalClient.TestObjectIamPermissions(ctx, req, opts...) +} + +// WatchAllObjects watch for changes on all objects in a bucket. +func (c *Client) WatchAllObjects(ctx context.Context, req *storagepb.WatchAllObjectsRequest, opts ...gax.CallOption) (*storagepb.Channel, error) { + return c.internalClient.WatchAllObjects(ctx, req, opts...) +} + +// GetServiceAccount retrieves the name of a project’s Google Cloud Storage service account. +func (c *Client) GetServiceAccount(ctx context.Context, req *storagepb.GetProjectServiceAccountRequest, opts ...gax.CallOption) (*storagepb.ServiceAccount, error) { + return c.internalClient.GetServiceAccount(ctx, req, opts...) +} + +// CreateHmacKey creates a new HMAC key for the given service account. +func (c *Client) CreateHmacKey(ctx context.Context, req *storagepb.CreateHmacKeyRequest, opts ...gax.CallOption) (*storagepb.CreateHmacKeyResponse, error) { + return c.internalClient.CreateHmacKey(ctx, req, opts...) +} + +// DeleteHmacKey deletes a given HMAC key. Key must be in an INACTIVE state. +func (c *Client) DeleteHmacKey(ctx context.Context, req *storagepb.DeleteHmacKeyRequest, opts ...gax.CallOption) error { + return c.internalClient.DeleteHmacKey(ctx, req, opts...) +} + +// GetHmacKey gets an existing HMAC key metadata for the given id. +func (c *Client) GetHmacKey(ctx context.Context, req *storagepb.GetHmacKeyRequest, opts ...gax.CallOption) (*storagepb.HmacKeyMetadata, error) { + return c.internalClient.GetHmacKey(ctx, req, opts...) +} + +// ListHmacKeys lists HMAC keys under a given project with the additional filters provided. +func (c *Client) ListHmacKeys(ctx context.Context, req *storagepb.ListHmacKeysRequest, opts ...gax.CallOption) (*storagepb.ListHmacKeysResponse, error) { + return c.internalClient.ListHmacKeys(ctx, req, opts...) +} + +// UpdateHmacKey updates a given HMAC key state between ACTIVE and INACTIVE. +func (c *Client) UpdateHmacKey(ctx context.Context, req *storagepb.UpdateHmacKeyRequest, opts ...gax.CallOption) (*storagepb.HmacKeyMetadata, error) { + return c.internalClient.UpdateHmacKey(ctx, req, opts...) +} + +// gRPCClient is a client for interacting with Cloud Storage 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 storagepb.StorageClient + + // The x-goog-* metadata to be sent with each request. + xGoogMetadata metadata.MD +} + +// NewClient creates a new storage client based on gRPC. +// The returned client must be Closed when it is done being used to clean up its underlying connections. +// +// Manages Google Cloud Storage resources. +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: storagepb.NewStorageClient(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) DeleteBucketAccessControl(ctx context.Context, req *storagepb.DeleteBucketAccessControlRequest, opts ...gax.CallOption) error { + if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { + cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond) + defer cancel() + ctx = cctx + } + ctx = insertMetadata(ctx, c.xGoogMetadata) + opts = append((*c.CallOptions).DeleteBucketAccessControl[0:len((*c.CallOptions).DeleteBucketAccessControl):len((*c.CallOptions).DeleteBucketAccessControl)], opts...) + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + _, err = c.client.DeleteBucketAccessControl(ctx, req, settings.GRPC...) + return err + }, opts...) + return err +} + +func (c *gRPCClient) GetBucketAccessControl(ctx context.Context, req *storagepb.GetBucketAccessControlRequest, opts ...gax.CallOption) (*storagepb.BucketAccessControl, error) { + if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { + cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond) + defer cancel() + ctx = cctx + } + ctx = insertMetadata(ctx, c.xGoogMetadata) + opts = append((*c.CallOptions).GetBucketAccessControl[0:len((*c.CallOptions).GetBucketAccessControl):len((*c.CallOptions).GetBucketAccessControl)], opts...) + var resp *storagepb.BucketAccessControl + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.client.GetBucketAccessControl(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} + +func (c *gRPCClient) InsertBucketAccessControl(ctx context.Context, req *storagepb.InsertBucketAccessControlRequest, opts ...gax.CallOption) (*storagepb.BucketAccessControl, error) { + if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { + cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond) + defer cancel() + ctx = cctx + } + ctx = insertMetadata(ctx, c.xGoogMetadata) + opts = append((*c.CallOptions).InsertBucketAccessControl[0:len((*c.CallOptions).InsertBucketAccessControl):len((*c.CallOptions).InsertBucketAccessControl)], opts...) + var resp *storagepb.BucketAccessControl + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.client.InsertBucketAccessControl(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} + +func (c *gRPCClient) ListBucketAccessControls(ctx context.Context, req *storagepb.ListBucketAccessControlsRequest, opts ...gax.CallOption) (*storagepb.ListBucketAccessControlsResponse, error) { + if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { + cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond) + defer cancel() + ctx = cctx + } + ctx = insertMetadata(ctx, c.xGoogMetadata) + opts = append((*c.CallOptions).ListBucketAccessControls[0:len((*c.CallOptions).ListBucketAccessControls):len((*c.CallOptions).ListBucketAccessControls)], opts...) + var resp *storagepb.ListBucketAccessControlsResponse + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.client.ListBucketAccessControls(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} + +func (c *gRPCClient) UpdateBucketAccessControl(ctx context.Context, req *storagepb.UpdateBucketAccessControlRequest, opts ...gax.CallOption) (*storagepb.BucketAccessControl, error) { + if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { + cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond) + defer cancel() + ctx = cctx + } + ctx = insertMetadata(ctx, c.xGoogMetadata) + opts = append((*c.CallOptions).UpdateBucketAccessControl[0:len((*c.CallOptions).UpdateBucketAccessControl):len((*c.CallOptions).UpdateBucketAccessControl)], opts...) + var resp *storagepb.BucketAccessControl + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.client.UpdateBucketAccessControl(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} + +func (c *gRPCClient) PatchBucketAccessControl(ctx context.Context, req *storagepb.PatchBucketAccessControlRequest, opts ...gax.CallOption) (*storagepb.BucketAccessControl, error) { + if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { + cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond) + defer cancel() + ctx = cctx + } + ctx = insertMetadata(ctx, c.xGoogMetadata) + opts = append((*c.CallOptions).PatchBucketAccessControl[0:len((*c.CallOptions).PatchBucketAccessControl):len((*c.CallOptions).PatchBucketAccessControl)], opts...) + var resp *storagepb.BucketAccessControl + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.client.PatchBucketAccessControl(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} + +func (c *gRPCClient) DeleteBucket(ctx context.Context, req *storagepb.DeleteBucketRequest, opts ...gax.CallOption) error { + if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { + cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond) + defer cancel() + ctx = cctx + } + ctx = insertMetadata(ctx, c.xGoogMetadata) + opts = append((*c.CallOptions).DeleteBucket[0:len((*c.CallOptions).DeleteBucket):len((*c.CallOptions).DeleteBucket)], opts...) + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + _, err = c.client.DeleteBucket(ctx, req, settings.GRPC...) + return err + }, opts...) + return err +} + +func (c *gRPCClient) GetBucket(ctx context.Context, req *storagepb.GetBucketRequest, opts ...gax.CallOption) (*storagepb.Bucket, error) { + if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { + cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond) + defer cancel() + ctx = cctx + } + ctx = insertMetadata(ctx, c.xGoogMetadata) + opts = append((*c.CallOptions).GetBucket[0:len((*c.CallOptions).GetBucket):len((*c.CallOptions).GetBucket)], opts...) + var resp *storagepb.Bucket + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.client.GetBucket(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} + +func (c *gRPCClient) InsertBucket(ctx context.Context, req *storagepb.InsertBucketRequest, opts ...gax.CallOption) (*storagepb.Bucket, error) { + if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { + cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond) + defer cancel() + ctx = cctx + } + ctx = insertMetadata(ctx, c.xGoogMetadata) + opts = append((*c.CallOptions).InsertBucket[0:len((*c.CallOptions).InsertBucket):len((*c.CallOptions).InsertBucket)], opts...) + var resp *storagepb.Bucket + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.client.InsertBucket(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} + +func (c *gRPCClient) ListChannels(ctx context.Context, req *storagepb.ListChannelsRequest, opts ...gax.CallOption) (*storagepb.ListChannelsResponse, error) { + if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { + cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond) + defer cancel() + ctx = cctx + } + ctx = insertMetadata(ctx, c.xGoogMetadata) + opts = append((*c.CallOptions).ListChannels[0:len((*c.CallOptions).ListChannels):len((*c.CallOptions).ListChannels)], opts...) + var resp *storagepb.ListChannelsResponse + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.client.ListChannels(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} + +func (c *gRPCClient) ListBuckets(ctx context.Context, req *storagepb.ListBucketsRequest, opts ...gax.CallOption) (*storagepb.ListBucketsResponse, error) { + if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { + cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond) + defer cancel() + ctx = cctx + } + ctx = insertMetadata(ctx, c.xGoogMetadata) + opts = append((*c.CallOptions).ListBuckets[0:len((*c.CallOptions).ListBuckets):len((*c.CallOptions).ListBuckets)], opts...) + var resp *storagepb.ListBucketsResponse + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.client.ListBuckets(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} + +func (c *gRPCClient) LockBucketRetentionPolicy(ctx context.Context, req *storagepb.LockRetentionPolicyRequest, opts ...gax.CallOption) (*storagepb.Bucket, error) { + if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { + cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond) + defer cancel() + ctx = cctx + } + ctx = insertMetadata(ctx, c.xGoogMetadata) + opts = append((*c.CallOptions).LockBucketRetentionPolicy[0:len((*c.CallOptions).LockBucketRetentionPolicy):len((*c.CallOptions).LockBucketRetentionPolicy)], opts...) + var resp *storagepb.Bucket + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.client.LockBucketRetentionPolicy(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} + +func (c *gRPCClient) GetBucketIamPolicy(ctx context.Context, req *storagepb.GetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) { + if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { + cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond) + defer cancel() + ctx = cctx + } + ctx = insertMetadata(ctx, c.xGoogMetadata) + opts = append((*c.CallOptions).GetBucketIamPolicy[0:len((*c.CallOptions).GetBucketIamPolicy):len((*c.CallOptions).GetBucketIamPolicy)], opts...) + var resp *iampb.Policy + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.client.GetBucketIamPolicy(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} + +func (c *gRPCClient) SetBucketIamPolicy(ctx context.Context, req *storagepb.SetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) { + if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { + cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond) + defer cancel() + ctx = cctx + } + ctx = insertMetadata(ctx, c.xGoogMetadata) + opts = append((*c.CallOptions).SetBucketIamPolicy[0:len((*c.CallOptions).SetBucketIamPolicy):len((*c.CallOptions).SetBucketIamPolicy)], opts...) + var resp *iampb.Policy + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.client.SetBucketIamPolicy(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} + +func (c *gRPCClient) TestBucketIamPermissions(ctx context.Context, req *storagepb.TestIamPermissionsRequest, opts ...gax.CallOption) (*iampb.TestIamPermissionsResponse, error) { + if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { + cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond) + defer cancel() + ctx = cctx + } + ctx = insertMetadata(ctx, c.xGoogMetadata) + opts = append((*c.CallOptions).TestBucketIamPermissions[0:len((*c.CallOptions).TestBucketIamPermissions):len((*c.CallOptions).TestBucketIamPermissions)], opts...) + var resp *iampb.TestIamPermissionsResponse + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.client.TestBucketIamPermissions(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} + +func (c *gRPCClient) PatchBucket(ctx context.Context, req *storagepb.PatchBucketRequest, opts ...gax.CallOption) (*storagepb.Bucket, error) { + if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { + cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond) + defer cancel() + ctx = cctx + } + ctx = insertMetadata(ctx, c.xGoogMetadata) + opts = append((*c.CallOptions).PatchBucket[0:len((*c.CallOptions).PatchBucket):len((*c.CallOptions).PatchBucket)], opts...) + var resp *storagepb.Bucket + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.client.PatchBucket(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} + +func (c *gRPCClient) UpdateBucket(ctx context.Context, req *storagepb.UpdateBucketRequest, opts ...gax.CallOption) (*storagepb.Bucket, error) { + if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { + cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond) + defer cancel() + ctx = cctx + } + ctx = insertMetadata(ctx, c.xGoogMetadata) + opts = append((*c.CallOptions).UpdateBucket[0:len((*c.CallOptions).UpdateBucket):len((*c.CallOptions).UpdateBucket)], opts...) + var resp *storagepb.Bucket + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.client.UpdateBucket(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} + +func (c *gRPCClient) StopChannel(ctx context.Context, req *storagepb.StopChannelRequest, opts ...gax.CallOption) error { + if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { + cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond) + defer cancel() + ctx = cctx + } + ctx = insertMetadata(ctx, c.xGoogMetadata) + opts = append((*c.CallOptions).StopChannel[0:len((*c.CallOptions).StopChannel):len((*c.CallOptions).StopChannel)], opts...) + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + _, err = c.client.StopChannel(ctx, req, settings.GRPC...) + return err + }, opts...) + return err +} + +func (c *gRPCClient) DeleteDefaultObjectAccessControl(ctx context.Context, req *storagepb.DeleteDefaultObjectAccessControlRequest, opts ...gax.CallOption) error { + if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { + cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond) + defer cancel() + ctx = cctx + } + ctx = insertMetadata(ctx, c.xGoogMetadata) + opts = append((*c.CallOptions).DeleteDefaultObjectAccessControl[0:len((*c.CallOptions).DeleteDefaultObjectAccessControl):len((*c.CallOptions).DeleteDefaultObjectAccessControl)], opts...) + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + _, err = c.client.DeleteDefaultObjectAccessControl(ctx, req, settings.GRPC...) + return err + }, opts...) + return err +} + +func (c *gRPCClient) GetDefaultObjectAccessControl(ctx context.Context, req *storagepb.GetDefaultObjectAccessControlRequest, opts ...gax.CallOption) (*storagepb.ObjectAccessControl, error) { + if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { + cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond) + defer cancel() + ctx = cctx + } + ctx = insertMetadata(ctx, c.xGoogMetadata) + opts = append((*c.CallOptions).GetDefaultObjectAccessControl[0:len((*c.CallOptions).GetDefaultObjectAccessControl):len((*c.CallOptions).GetDefaultObjectAccessControl)], opts...) + var resp *storagepb.ObjectAccessControl + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.client.GetDefaultObjectAccessControl(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} + +func (c *gRPCClient) InsertDefaultObjectAccessControl(ctx context.Context, req *storagepb.InsertDefaultObjectAccessControlRequest, opts ...gax.CallOption) (*storagepb.ObjectAccessControl, error) { + if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { + cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond) + defer cancel() + ctx = cctx + } + ctx = insertMetadata(ctx, c.xGoogMetadata) + opts = append((*c.CallOptions).InsertDefaultObjectAccessControl[0:len((*c.CallOptions).InsertDefaultObjectAccessControl):len((*c.CallOptions).InsertDefaultObjectAccessControl)], opts...) + var resp *storagepb.ObjectAccessControl + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.client.InsertDefaultObjectAccessControl(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} + +func (c *gRPCClient) ListDefaultObjectAccessControls(ctx context.Context, req *storagepb.ListDefaultObjectAccessControlsRequest, opts ...gax.CallOption) (*storagepb.ListObjectAccessControlsResponse, error) { + if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { + cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond) + defer cancel() + ctx = cctx + } + ctx = insertMetadata(ctx, c.xGoogMetadata) + opts = append((*c.CallOptions).ListDefaultObjectAccessControls[0:len((*c.CallOptions).ListDefaultObjectAccessControls):len((*c.CallOptions).ListDefaultObjectAccessControls)], opts...) + var resp *storagepb.ListObjectAccessControlsResponse + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.client.ListDefaultObjectAccessControls(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} + +func (c *gRPCClient) PatchDefaultObjectAccessControl(ctx context.Context, req *storagepb.PatchDefaultObjectAccessControlRequest, opts ...gax.CallOption) (*storagepb.ObjectAccessControl, error) { + if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { + cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond) + defer cancel() + ctx = cctx + } + ctx = insertMetadata(ctx, c.xGoogMetadata) + opts = append((*c.CallOptions).PatchDefaultObjectAccessControl[0:len((*c.CallOptions).PatchDefaultObjectAccessControl):len((*c.CallOptions).PatchDefaultObjectAccessControl)], opts...) + var resp *storagepb.ObjectAccessControl + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.client.PatchDefaultObjectAccessControl(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} + +func (c *gRPCClient) UpdateDefaultObjectAccessControl(ctx context.Context, req *storagepb.UpdateDefaultObjectAccessControlRequest, opts ...gax.CallOption) (*storagepb.ObjectAccessControl, error) { + if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { + cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond) + defer cancel() + ctx = cctx + } + ctx = insertMetadata(ctx, c.xGoogMetadata) + opts = append((*c.CallOptions).UpdateDefaultObjectAccessControl[0:len((*c.CallOptions).UpdateDefaultObjectAccessControl):len((*c.CallOptions).UpdateDefaultObjectAccessControl)], opts...) + var resp *storagepb.ObjectAccessControl + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.client.UpdateDefaultObjectAccessControl(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} + +func (c *gRPCClient) DeleteNotification(ctx context.Context, req *storagepb.DeleteNotificationRequest, opts ...gax.CallOption) error { + if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { + cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond) + defer cancel() + ctx = cctx + } + ctx = insertMetadata(ctx, c.xGoogMetadata) + opts = append((*c.CallOptions).DeleteNotification[0:len((*c.CallOptions).DeleteNotification):len((*c.CallOptions).DeleteNotification)], opts...) + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + _, err = c.client.DeleteNotification(ctx, req, settings.GRPC...) + return err + }, opts...) + return err +} + +func (c *gRPCClient) GetNotification(ctx context.Context, req *storagepb.GetNotificationRequest, opts ...gax.CallOption) (*storagepb.Notification, error) { + if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { + cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond) + defer cancel() + ctx = cctx + } + ctx = insertMetadata(ctx, c.xGoogMetadata) + opts = append((*c.CallOptions).GetNotification[0:len((*c.CallOptions).GetNotification):len((*c.CallOptions).GetNotification)], opts...) + var resp *storagepb.Notification + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.client.GetNotification(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} + +func (c *gRPCClient) InsertNotification(ctx context.Context, req *storagepb.InsertNotificationRequest, opts ...gax.CallOption) (*storagepb.Notification, error) { + if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { + cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond) + defer cancel() + ctx = cctx + } + ctx = insertMetadata(ctx, c.xGoogMetadata) + opts = append((*c.CallOptions).InsertNotification[0:len((*c.CallOptions).InsertNotification):len((*c.CallOptions).InsertNotification)], opts...) + var resp *storagepb.Notification + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.client.InsertNotification(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} + +func (c *gRPCClient) ListNotifications(ctx context.Context, req *storagepb.ListNotificationsRequest, opts ...gax.CallOption) (*storagepb.ListNotificationsResponse, error) { + if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { + cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond) + defer cancel() + ctx = cctx + } + ctx = insertMetadata(ctx, c.xGoogMetadata) + opts = append((*c.CallOptions).ListNotifications[0:len((*c.CallOptions).ListNotifications):len((*c.CallOptions).ListNotifications)], opts...) + var resp *storagepb.ListNotificationsResponse + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.client.ListNotifications(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} + +func (c *gRPCClient) DeleteObjectAccessControl(ctx context.Context, req *storagepb.DeleteObjectAccessControlRequest, opts ...gax.CallOption) error { + if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { + cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond) + defer cancel() + ctx = cctx + } + ctx = insertMetadata(ctx, c.xGoogMetadata) + opts = append((*c.CallOptions).DeleteObjectAccessControl[0:len((*c.CallOptions).DeleteObjectAccessControl):len((*c.CallOptions).DeleteObjectAccessControl)], opts...) + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + _, err = c.client.DeleteObjectAccessControl(ctx, req, settings.GRPC...) + return err + }, opts...) + return err +} + +func (c *gRPCClient) GetObjectAccessControl(ctx context.Context, req *storagepb.GetObjectAccessControlRequest, opts ...gax.CallOption) (*storagepb.ObjectAccessControl, error) { + if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { + cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond) + defer cancel() + ctx = cctx + } + ctx = insertMetadata(ctx, c.xGoogMetadata) + opts = append((*c.CallOptions).GetObjectAccessControl[0:len((*c.CallOptions).GetObjectAccessControl):len((*c.CallOptions).GetObjectAccessControl)], opts...) + var resp *storagepb.ObjectAccessControl + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.client.GetObjectAccessControl(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} + +func (c *gRPCClient) InsertObjectAccessControl(ctx context.Context, req *storagepb.InsertObjectAccessControlRequest, opts ...gax.CallOption) (*storagepb.ObjectAccessControl, error) { + if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { + cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond) + defer cancel() + ctx = cctx + } + ctx = insertMetadata(ctx, c.xGoogMetadata) + opts = append((*c.CallOptions).InsertObjectAccessControl[0:len((*c.CallOptions).InsertObjectAccessControl):len((*c.CallOptions).InsertObjectAccessControl)], opts...) + var resp *storagepb.ObjectAccessControl + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.client.InsertObjectAccessControl(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} + +func (c *gRPCClient) ListObjectAccessControls(ctx context.Context, req *storagepb.ListObjectAccessControlsRequest, opts ...gax.CallOption) (*storagepb.ListObjectAccessControlsResponse, error) { + if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { + cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond) + defer cancel() + ctx = cctx + } + ctx = insertMetadata(ctx, c.xGoogMetadata) + opts = append((*c.CallOptions).ListObjectAccessControls[0:len((*c.CallOptions).ListObjectAccessControls):len((*c.CallOptions).ListObjectAccessControls)], opts...) + var resp *storagepb.ListObjectAccessControlsResponse + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.client.ListObjectAccessControls(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} + +func (c *gRPCClient) PatchObjectAccessControl(ctx context.Context, req *storagepb.PatchObjectAccessControlRequest, opts ...gax.CallOption) (*storagepb.ObjectAccessControl, error) { + if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { + cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond) + defer cancel() + ctx = cctx + } + ctx = insertMetadata(ctx, c.xGoogMetadata) + opts = append((*c.CallOptions).PatchObjectAccessControl[0:len((*c.CallOptions).PatchObjectAccessControl):len((*c.CallOptions).PatchObjectAccessControl)], opts...) + var resp *storagepb.ObjectAccessControl + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.client.PatchObjectAccessControl(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} + +func (c *gRPCClient) UpdateObjectAccessControl(ctx context.Context, req *storagepb.UpdateObjectAccessControlRequest, opts ...gax.CallOption) (*storagepb.ObjectAccessControl, error) { + if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { + cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond) + defer cancel() + ctx = cctx + } + ctx = insertMetadata(ctx, c.xGoogMetadata) + opts = append((*c.CallOptions).UpdateObjectAccessControl[0:len((*c.CallOptions).UpdateObjectAccessControl):len((*c.CallOptions).UpdateObjectAccessControl)], opts...) + var resp *storagepb.ObjectAccessControl + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.client.UpdateObjectAccessControl(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} + +func (c *gRPCClient) ComposeObject(ctx context.Context, req *storagepb.ComposeObjectRequest, opts ...gax.CallOption) (*storagepb.Object, error) { + if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { + cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond) + defer cancel() + ctx = cctx + } + ctx = insertMetadata(ctx, c.xGoogMetadata) + opts = append((*c.CallOptions).ComposeObject[0:len((*c.CallOptions).ComposeObject):len((*c.CallOptions).ComposeObject)], opts...) + var resp *storagepb.Object + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.client.ComposeObject(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} + +func (c *gRPCClient) CopyObject(ctx context.Context, req *storagepb.CopyObjectRequest, opts ...gax.CallOption) (*storagepb.Object, error) { + if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { + cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond) + defer cancel() + ctx = cctx + } + ctx = insertMetadata(ctx, c.xGoogMetadata) + opts = append((*c.CallOptions).CopyObject[0:len((*c.CallOptions).CopyObject):len((*c.CallOptions).CopyObject)], opts...) + var resp *storagepb.Object + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.client.CopyObject(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} + +func (c *gRPCClient) DeleteObject(ctx context.Context, req *storagepb.DeleteObjectRequest, opts ...gax.CallOption) error { + if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { + cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond) + defer cancel() + ctx = cctx + } + ctx = insertMetadata(ctx, c.xGoogMetadata) + opts = append((*c.CallOptions).DeleteObject[0:len((*c.CallOptions).DeleteObject):len((*c.CallOptions).DeleteObject)], opts...) + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + _, err = c.client.DeleteObject(ctx, req, settings.GRPC...) + return err + }, opts...) + return err +} + +func (c *gRPCClient) GetObject(ctx context.Context, req *storagepb.GetObjectRequest, opts ...gax.CallOption) (*storagepb.Object, error) { + if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { + cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond) + defer cancel() + ctx = cctx + } + ctx = insertMetadata(ctx, c.xGoogMetadata) + opts = append((*c.CallOptions).GetObject[0:len((*c.CallOptions).GetObject):len((*c.CallOptions).GetObject)], opts...) + var resp *storagepb.Object + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.client.GetObject(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} + +func (c *gRPCClient) GetObjectMedia(ctx context.Context, req *storagepb.GetObjectMediaRequest, opts ...gax.CallOption) (storagepb.Storage_GetObjectMediaClient, error) { + ctx = insertMetadata(ctx, c.xGoogMetadata) + var resp storagepb.Storage_GetObjectMediaClient + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.client.GetObjectMedia(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} + +func (c *gRPCClient) InsertObject(ctx context.Context, opts ...gax.CallOption) (storagepb.Storage_InsertObjectClient, error) { + ctx = insertMetadata(ctx, c.xGoogMetadata) + var resp storagepb.Storage_InsertObjectClient + opts = append((*c.CallOptions).InsertObject[0:len((*c.CallOptions).InsertObject):len((*c.CallOptions).InsertObject)], opts...) + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.client.InsertObject(ctx, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} + +func (c *gRPCClient) ListObjects(ctx context.Context, req *storagepb.ListObjectsRequest, opts ...gax.CallOption) (*storagepb.ListObjectsResponse, error) { + if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { + cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond) + defer cancel() + ctx = cctx + } + ctx = insertMetadata(ctx, c.xGoogMetadata) + opts = append((*c.CallOptions).ListObjects[0:len((*c.CallOptions).ListObjects):len((*c.CallOptions).ListObjects)], opts...) + var resp *storagepb.ListObjectsResponse + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.client.ListObjects(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} + +func (c *gRPCClient) RewriteObject(ctx context.Context, req *storagepb.RewriteObjectRequest, opts ...gax.CallOption) (*storagepb.RewriteResponse, error) { + if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { + cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond) + defer cancel() + ctx = cctx + } + ctx = insertMetadata(ctx, c.xGoogMetadata) + opts = append((*c.CallOptions).RewriteObject[0:len((*c.CallOptions).RewriteObject):len((*c.CallOptions).RewriteObject)], opts...) + var resp *storagepb.RewriteResponse + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.client.RewriteObject(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} + +func (c *gRPCClient) StartResumableWrite(ctx context.Context, req *storagepb.StartResumableWriteRequest, opts ...gax.CallOption) (*storagepb.StartResumableWriteResponse, error) { + if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { + cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond) + defer cancel() + ctx = cctx + } + ctx = insertMetadata(ctx, c.xGoogMetadata) + opts = append((*c.CallOptions).StartResumableWrite[0:len((*c.CallOptions).StartResumableWrite):len((*c.CallOptions).StartResumableWrite)], opts...) + var resp *storagepb.StartResumableWriteResponse + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.client.StartResumableWrite(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} + +func (c *gRPCClient) QueryWriteStatus(ctx context.Context, req *storagepb.QueryWriteStatusRequest, opts ...gax.CallOption) (*storagepb.QueryWriteStatusResponse, error) { + if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { + cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond) + defer cancel() + ctx = cctx + } + ctx = insertMetadata(ctx, c.xGoogMetadata) + opts = append((*c.CallOptions).QueryWriteStatus[0:len((*c.CallOptions).QueryWriteStatus):len((*c.CallOptions).QueryWriteStatus)], opts...) + var resp *storagepb.QueryWriteStatusResponse + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.client.QueryWriteStatus(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} + +func (c *gRPCClient) PatchObject(ctx context.Context, req *storagepb.PatchObjectRequest, opts ...gax.CallOption) (*storagepb.Object, error) { + if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { + cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond) + defer cancel() + ctx = cctx + } + ctx = insertMetadata(ctx, c.xGoogMetadata) + opts = append((*c.CallOptions).PatchObject[0:len((*c.CallOptions).PatchObject):len((*c.CallOptions).PatchObject)], opts...) + var resp *storagepb.Object + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.client.PatchObject(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} + +func (c *gRPCClient) UpdateObject(ctx context.Context, req *storagepb.UpdateObjectRequest, opts ...gax.CallOption) (*storagepb.Object, error) { + if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { + cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond) + defer cancel() + ctx = cctx + } + ctx = insertMetadata(ctx, c.xGoogMetadata) + opts = append((*c.CallOptions).UpdateObject[0:len((*c.CallOptions).UpdateObject):len((*c.CallOptions).UpdateObject)], opts...) + var resp *storagepb.Object + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.client.UpdateObject(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} + +func (c *gRPCClient) GetObjectIamPolicy(ctx context.Context, req *storagepb.GetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) { + if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { + cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond) + defer cancel() + ctx = cctx + } + ctx = insertMetadata(ctx, c.xGoogMetadata) + opts = append((*c.CallOptions).GetObjectIamPolicy[0:len((*c.CallOptions).GetObjectIamPolicy):len((*c.CallOptions).GetObjectIamPolicy)], opts...) + var resp *iampb.Policy + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.client.GetObjectIamPolicy(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} + +func (c *gRPCClient) SetObjectIamPolicy(ctx context.Context, req *storagepb.SetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) { + if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { + cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond) + defer cancel() + ctx = cctx + } + ctx = insertMetadata(ctx, c.xGoogMetadata) + opts = append((*c.CallOptions).SetObjectIamPolicy[0:len((*c.CallOptions).SetObjectIamPolicy):len((*c.CallOptions).SetObjectIamPolicy)], opts...) + var resp *iampb.Policy + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.client.SetObjectIamPolicy(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} + +func (c *gRPCClient) TestObjectIamPermissions(ctx context.Context, req *storagepb.TestIamPermissionsRequest, opts ...gax.CallOption) (*iampb.TestIamPermissionsResponse, error) { + if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { + cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond) + defer cancel() + ctx = cctx + } + ctx = insertMetadata(ctx, c.xGoogMetadata) + opts = append((*c.CallOptions).TestObjectIamPermissions[0:len((*c.CallOptions).TestObjectIamPermissions):len((*c.CallOptions).TestObjectIamPermissions)], opts...) + var resp *iampb.TestIamPermissionsResponse + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.client.TestObjectIamPermissions(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} + +func (c *gRPCClient) WatchAllObjects(ctx context.Context, req *storagepb.WatchAllObjectsRequest, opts ...gax.CallOption) (*storagepb.Channel, error) { + if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { + cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond) + defer cancel() + ctx = cctx + } + ctx = insertMetadata(ctx, c.xGoogMetadata) + opts = append((*c.CallOptions).WatchAllObjects[0:len((*c.CallOptions).WatchAllObjects):len((*c.CallOptions).WatchAllObjects)], opts...) + var resp *storagepb.Channel + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.client.WatchAllObjects(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} + +func (c *gRPCClient) GetServiceAccount(ctx context.Context, req *storagepb.GetProjectServiceAccountRequest, opts ...gax.CallOption) (*storagepb.ServiceAccount, error) { + if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { + cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond) + defer cancel() + ctx = cctx + } + ctx = insertMetadata(ctx, c.xGoogMetadata) + opts = append((*c.CallOptions).GetServiceAccount[0:len((*c.CallOptions).GetServiceAccount):len((*c.CallOptions).GetServiceAccount)], opts...) + var resp *storagepb.ServiceAccount + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.client.GetServiceAccount(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} + +func (c *gRPCClient) CreateHmacKey(ctx context.Context, req *storagepb.CreateHmacKeyRequest, opts ...gax.CallOption) (*storagepb.CreateHmacKeyResponse, error) { + if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { + cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond) + defer cancel() + ctx = cctx + } + ctx = insertMetadata(ctx, c.xGoogMetadata) + opts = append((*c.CallOptions).CreateHmacKey[0:len((*c.CallOptions).CreateHmacKey):len((*c.CallOptions).CreateHmacKey)], opts...) + var resp *storagepb.CreateHmacKeyResponse + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.client.CreateHmacKey(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} + +func (c *gRPCClient) DeleteHmacKey(ctx context.Context, req *storagepb.DeleteHmacKeyRequest, opts ...gax.CallOption) error { + if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { + cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond) + defer cancel() + ctx = cctx + } + ctx = insertMetadata(ctx, c.xGoogMetadata) + opts = append((*c.CallOptions).DeleteHmacKey[0:len((*c.CallOptions).DeleteHmacKey):len((*c.CallOptions).DeleteHmacKey)], opts...) + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + _, err = c.client.DeleteHmacKey(ctx, req, settings.GRPC...) + return err + }, opts...) + return err +} + +func (c *gRPCClient) GetHmacKey(ctx context.Context, req *storagepb.GetHmacKeyRequest, opts ...gax.CallOption) (*storagepb.HmacKeyMetadata, error) { + if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { + cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond) + defer cancel() + ctx = cctx + } + ctx = insertMetadata(ctx, c.xGoogMetadata) + opts = append((*c.CallOptions).GetHmacKey[0:len((*c.CallOptions).GetHmacKey):len((*c.CallOptions).GetHmacKey)], opts...) + var resp *storagepb.HmacKeyMetadata + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.client.GetHmacKey(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} + +func (c *gRPCClient) ListHmacKeys(ctx context.Context, req *storagepb.ListHmacKeysRequest, opts ...gax.CallOption) (*storagepb.ListHmacKeysResponse, error) { + if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { + cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond) + defer cancel() + ctx = cctx + } + ctx = insertMetadata(ctx, c.xGoogMetadata) + opts = append((*c.CallOptions).ListHmacKeys[0:len((*c.CallOptions).ListHmacKeys):len((*c.CallOptions).ListHmacKeys)], opts...) + var resp *storagepb.ListHmacKeysResponse + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.client.ListHmacKeys(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} + +func (c *gRPCClient) UpdateHmacKey(ctx context.Context, req *storagepb.UpdateHmacKeyRequest, opts ...gax.CallOption) (*storagepb.HmacKeyMetadata, error) { + if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { + cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond) + defer cancel() + ctx = cctx + } + ctx = insertMetadata(ctx, c.xGoogMetadata) + opts = append((*c.CallOptions).UpdateHmacKey[0:len((*c.CallOptions).UpdateHmacKey):len((*c.CallOptions).UpdateHmacKey)], opts...) + var resp *storagepb.HmacKeyMetadata + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.client.UpdateHmacKey(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} diff --git a/storage/internal/apiv1/storage_client_example_test.go b/storage/internal/apiv1/storage_client_example_test.go new file mode 100644 index 00000000000..8dbd77f7fbe --- /dev/null +++ b/storage/internal/apiv1/storage_client_example_test.go @@ -0,0 +1,1046 @@ +// 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 storage_test + +import ( + "context" + + storage "cloud.google.com/go/storage/internal/apiv1" + storagepb "google.golang.org/genproto/googleapis/storage/v1" +) + +func ExampleNewClient() { + ctx := context.Background() + c, err := storage.NewClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + // TODO: Use client. + _ = c +} + +func ExampleClient_DeleteBucketAccessControl() { + ctx := context.Background() + c, err := storage.NewClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &storagepb.DeleteBucketAccessControlRequest{ + // TODO: Fill request struct fields. + } + err = c.DeleteBucketAccessControl(ctx, req) + if err != nil { + // TODO: Handle error. + } +} + +func ExampleClient_GetBucketAccessControl() { + ctx := context.Background() + c, err := storage.NewClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &storagepb.GetBucketAccessControlRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.GetBucketAccessControl(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleClient_InsertBucketAccessControl() { + ctx := context.Background() + c, err := storage.NewClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &storagepb.InsertBucketAccessControlRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.InsertBucketAccessControl(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleClient_ListBucketAccessControls() { + ctx := context.Background() + c, err := storage.NewClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &storagepb.ListBucketAccessControlsRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.ListBucketAccessControls(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleClient_UpdateBucketAccessControl() { + ctx := context.Background() + c, err := storage.NewClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &storagepb.UpdateBucketAccessControlRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.UpdateBucketAccessControl(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleClient_PatchBucketAccessControl() { + ctx := context.Background() + c, err := storage.NewClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &storagepb.PatchBucketAccessControlRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.PatchBucketAccessControl(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleClient_DeleteBucket() { + ctx := context.Background() + c, err := storage.NewClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &storagepb.DeleteBucketRequest{ + // TODO: Fill request struct fields. + } + err = c.DeleteBucket(ctx, req) + if err != nil { + // TODO: Handle error. + } +} + +func ExampleClient_GetBucket() { + ctx := context.Background() + c, err := storage.NewClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &storagepb.GetBucketRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.GetBucket(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleClient_InsertBucket() { + ctx := context.Background() + c, err := storage.NewClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &storagepb.InsertBucketRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.InsertBucket(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleClient_ListChannels() { + ctx := context.Background() + c, err := storage.NewClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &storagepb.ListChannelsRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.ListChannels(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleClient_ListBuckets() { + ctx := context.Background() + c, err := storage.NewClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &storagepb.ListBucketsRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.ListBuckets(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleClient_LockBucketRetentionPolicy() { + ctx := context.Background() + c, err := storage.NewClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &storagepb.LockRetentionPolicyRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.LockBucketRetentionPolicy(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleClient_GetBucketIamPolicy() { + ctx := context.Background() + c, err := storage.NewClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &storagepb.GetIamPolicyRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.GetBucketIamPolicy(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleClient_SetBucketIamPolicy() { + ctx := context.Background() + c, err := storage.NewClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &storagepb.SetIamPolicyRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.SetBucketIamPolicy(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleClient_TestBucketIamPermissions() { + ctx := context.Background() + c, err := storage.NewClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &storagepb.TestIamPermissionsRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.TestBucketIamPermissions(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleClient_PatchBucket() { + ctx := context.Background() + c, err := storage.NewClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &storagepb.PatchBucketRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.PatchBucket(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleClient_UpdateBucket() { + ctx := context.Background() + c, err := storage.NewClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &storagepb.UpdateBucketRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.UpdateBucket(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleClient_StopChannel() { + ctx := context.Background() + c, err := storage.NewClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &storagepb.StopChannelRequest{ + // TODO: Fill request struct fields. + } + err = c.StopChannel(ctx, req) + if err != nil { + // TODO: Handle error. + } +} + +func ExampleClient_DeleteDefaultObjectAccessControl() { + ctx := context.Background() + c, err := storage.NewClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &storagepb.DeleteDefaultObjectAccessControlRequest{ + // TODO: Fill request struct fields. + } + err = c.DeleteDefaultObjectAccessControl(ctx, req) + if err != nil { + // TODO: Handle error. + } +} + +func ExampleClient_GetDefaultObjectAccessControl() { + ctx := context.Background() + c, err := storage.NewClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &storagepb.GetDefaultObjectAccessControlRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.GetDefaultObjectAccessControl(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleClient_InsertDefaultObjectAccessControl() { + ctx := context.Background() + c, err := storage.NewClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &storagepb.InsertDefaultObjectAccessControlRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.InsertDefaultObjectAccessControl(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleClient_ListDefaultObjectAccessControls() { + ctx := context.Background() + c, err := storage.NewClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &storagepb.ListDefaultObjectAccessControlsRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.ListDefaultObjectAccessControls(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleClient_PatchDefaultObjectAccessControl() { + ctx := context.Background() + c, err := storage.NewClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &storagepb.PatchDefaultObjectAccessControlRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.PatchDefaultObjectAccessControl(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleClient_UpdateDefaultObjectAccessControl() { + ctx := context.Background() + c, err := storage.NewClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &storagepb.UpdateDefaultObjectAccessControlRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.UpdateDefaultObjectAccessControl(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleClient_DeleteNotification() { + ctx := context.Background() + c, err := storage.NewClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &storagepb.DeleteNotificationRequest{ + // TODO: Fill request struct fields. + } + err = c.DeleteNotification(ctx, req) + if err != nil { + // TODO: Handle error. + } +} + +func ExampleClient_GetNotification() { + ctx := context.Background() + c, err := storage.NewClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &storagepb.GetNotificationRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.GetNotification(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleClient_InsertNotification() { + ctx := context.Background() + c, err := storage.NewClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &storagepb.InsertNotificationRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.InsertNotification(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleClient_ListNotifications() { + ctx := context.Background() + c, err := storage.NewClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &storagepb.ListNotificationsRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.ListNotifications(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleClient_DeleteObjectAccessControl() { + ctx := context.Background() + c, err := storage.NewClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &storagepb.DeleteObjectAccessControlRequest{ + // TODO: Fill request struct fields. + } + err = c.DeleteObjectAccessControl(ctx, req) + if err != nil { + // TODO: Handle error. + } +} + +func ExampleClient_GetObjectAccessControl() { + ctx := context.Background() + c, err := storage.NewClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &storagepb.GetObjectAccessControlRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.GetObjectAccessControl(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleClient_InsertObjectAccessControl() { + ctx := context.Background() + c, err := storage.NewClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &storagepb.InsertObjectAccessControlRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.InsertObjectAccessControl(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleClient_ListObjectAccessControls() { + ctx := context.Background() + c, err := storage.NewClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &storagepb.ListObjectAccessControlsRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.ListObjectAccessControls(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleClient_PatchObjectAccessControl() { + ctx := context.Background() + c, err := storage.NewClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &storagepb.PatchObjectAccessControlRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.PatchObjectAccessControl(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleClient_UpdateObjectAccessControl() { + ctx := context.Background() + c, err := storage.NewClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &storagepb.UpdateObjectAccessControlRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.UpdateObjectAccessControl(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleClient_ComposeObject() { + ctx := context.Background() + c, err := storage.NewClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &storagepb.ComposeObjectRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.ComposeObject(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleClient_CopyObject() { + ctx := context.Background() + c, err := storage.NewClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &storagepb.CopyObjectRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.CopyObject(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleClient_DeleteObject() { + ctx := context.Background() + c, err := storage.NewClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &storagepb.DeleteObjectRequest{ + // TODO: Fill request struct fields. + } + err = c.DeleteObject(ctx, req) + if err != nil { + // TODO: Handle error. + } +} + +func ExampleClient_GetObject() { + ctx := context.Background() + c, err := storage.NewClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &storagepb.GetObjectRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.GetObject(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleClient_ListObjects() { + ctx := context.Background() + c, err := storage.NewClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &storagepb.ListObjectsRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.ListObjects(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleClient_RewriteObject() { + ctx := context.Background() + c, err := storage.NewClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &storagepb.RewriteObjectRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.RewriteObject(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleClient_StartResumableWrite() { + ctx := context.Background() + c, err := storage.NewClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &storagepb.StartResumableWriteRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.StartResumableWrite(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleClient_QueryWriteStatus() { + ctx := context.Background() + c, err := storage.NewClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &storagepb.QueryWriteStatusRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.QueryWriteStatus(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleClient_PatchObject() { + ctx := context.Background() + c, err := storage.NewClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &storagepb.PatchObjectRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.PatchObject(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleClient_UpdateObject() { + ctx := context.Background() + c, err := storage.NewClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &storagepb.UpdateObjectRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.UpdateObject(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleClient_GetObjectIamPolicy() { + ctx := context.Background() + c, err := storage.NewClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &storagepb.GetIamPolicyRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.GetObjectIamPolicy(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleClient_SetObjectIamPolicy() { + ctx := context.Background() + c, err := storage.NewClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &storagepb.SetIamPolicyRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.SetObjectIamPolicy(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleClient_TestObjectIamPermissions() { + ctx := context.Background() + c, err := storage.NewClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &storagepb.TestIamPermissionsRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.TestObjectIamPermissions(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleClient_WatchAllObjects() { + ctx := context.Background() + c, err := storage.NewClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &storagepb.WatchAllObjectsRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.WatchAllObjects(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleClient_GetServiceAccount() { + ctx := context.Background() + c, err := storage.NewClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &storagepb.GetProjectServiceAccountRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.GetServiceAccount(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleClient_CreateHmacKey() { + ctx := context.Background() + c, err := storage.NewClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &storagepb.CreateHmacKeyRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.CreateHmacKey(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleClient_DeleteHmacKey() { + ctx := context.Background() + c, err := storage.NewClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &storagepb.DeleteHmacKeyRequest{ + // TODO: Fill request struct fields. + } + err = c.DeleteHmacKey(ctx, req) + if err != nil { + // TODO: Handle error. + } +} + +func ExampleClient_GetHmacKey() { + ctx := context.Background() + c, err := storage.NewClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &storagepb.GetHmacKeyRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.GetHmacKey(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleClient_ListHmacKeys() { + ctx := context.Background() + c, err := storage.NewClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &storagepb.ListHmacKeysRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.ListHmacKeys(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleClient_UpdateHmacKey() { + ctx := context.Background() + c, err := storage.NewClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &storagepb.UpdateHmacKeyRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.UpdateHmacKey(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} diff --git a/storage/reader.go b/storage/reader.go index d64f5ec778c..94563c2afee 100644 --- a/storage/reader.go +++ b/storage/reader.go @@ -23,7 +23,6 @@ import ( "io/ioutil" "net/http" "net/url" - "reflect" "strconv" "strings" "time" @@ -135,6 +134,11 @@ func (o *ObjectHandle) NewRangeReader(ctx context.Context, offset, length int64) // Define a function that initiates a Read with offset and length, assuming we // have already read seen bytes. reopen := func(seen int64) (*http.Response, error) { + // If the context has already expired, return immediately without making a + // call. + if err := ctx.Err(); err != nil { + return nil, err + } start := offset + seen if length < 0 && start < 0 { req.Header.Set("Range", fmt.Sprintf("bytes=%d", start)) @@ -369,11 +373,12 @@ func (r *Reader) readWithRetry(p []byte) (int, error) { m, err := r.body.Read(p[n:]) n += m r.seen += int64(m) - if !shouldRetryRead(err) { + if err == nil || err == io.EOF { return n, err } - // Read failed, but we will try again. Send a ranged read request that takes - // into account the number of bytes we've already seen. + // Read failed (likely due to connection issues), but we will try to reopen + // the pipe and continue. Send a ranged read request that takes into account + // the number of bytes we've already seen. res, err := r.reopen(r.seen) if err != nil { // reopen already retries @@ -385,13 +390,6 @@ func (r *Reader) readWithRetry(p []byte) (int, error) { return n, nil } -func shouldRetryRead(err error) bool { - if err == nil { - return false - } - return strings.HasSuffix(err.Error(), "INTERNAL_ERROR") && strings.Contains(reflect.TypeOf(err).String(), "http2") -} - // Size returns the size of the object in bytes. // The returned value is always the same and is not affected by // calls to Read or Close. diff --git a/storage/reader_test.go b/storage/reader_test.go index 4b35f3c94c0..81c9a0c6d80 100644 --- a/storage/reader_test.go +++ b/storage/reader_test.go @@ -131,7 +131,8 @@ func (h http2Error) Error() string { } func TestRangeReaderRetry(t *testing.T) { - retryErr := http2Error("blah blah INTERNAL_ERROR") + internalErr := http2Error("blah blah INTERNAL_ERROR") + goawayErr := http2Error("http2: server sent GOAWAY and closed the connection; LastStreamID=15, ErrCode=NO_ERROR, debug=\"load_shed\"") readBytes := []byte(readData) hc, close := newTestServer(handleRangeRead) defer close() @@ -159,7 +160,7 @@ func TestRangeReaderRetry(t *testing.T) { offset: 0, length: -1, bodies: []fakeReadCloser{ - {data: readBytes, counts: []int{3}, err: retryErr}, + {data: readBytes, counts: []int{3}, err: internalErr}, {data: readBytes[3:], counts: []int{5, 2}, err: io.EOF}, }, want: readData, @@ -168,8 +169,8 @@ func TestRangeReaderRetry(t *testing.T) { offset: 0, length: -1, bodies: []fakeReadCloser{ - {data: readBytes, counts: []int{5}, err: retryErr}, - {data: readBytes[5:], counts: []int{1, 3}, err: retryErr}, + {data: readBytes, counts: []int{5}, err: internalErr}, + {data: readBytes[5:], counts: []int{1, 3}, err: goawayErr}, {data: readBytes[9:], counts: []int{1}, err: io.EOF}, }, want: readData, @@ -178,7 +179,16 @@ func TestRangeReaderRetry(t *testing.T) { offset: 0, length: 5, bodies: []fakeReadCloser{ - {data: readBytes, counts: []int{3}, err: retryErr}, + {data: readBytes, counts: []int{3}, err: internalErr}, + {data: readBytes[3:], counts: []int{2}, err: io.EOF}, + }, + want: readData[:5], + }, + { + offset: 0, + length: 5, + bodies: []fakeReadCloser{ + {data: readBytes, counts: []int{3}, err: goawayErr}, {data: readBytes[3:], counts: []int{2}, err: io.EOF}, }, want: readData[:5], @@ -187,7 +197,7 @@ func TestRangeReaderRetry(t *testing.T) { offset: 1, length: 5, bodies: []fakeReadCloser{ - {data: readBytes, counts: []int{3}, err: retryErr}, + {data: readBytes, counts: []int{3}, err: internalErr}, {data: readBytes[3:], counts: []int{2}, err: io.EOF}, }, want: readData[:5], @@ -196,7 +206,7 @@ func TestRangeReaderRetry(t *testing.T) { offset: 1, length: 3, bodies: []fakeReadCloser{ - {data: readBytes[1:], counts: []int{1}, err: retryErr}, + {data: readBytes[1:], counts: []int{1}, err: internalErr}, {data: readBytes[2:], counts: []int{2}, err: io.EOF}, }, want: readData[1:4], @@ -205,8 +215,8 @@ func TestRangeReaderRetry(t *testing.T) { offset: 4, length: -1, bodies: []fakeReadCloser{ - {data: readBytes[4:], counts: []int{1}, err: retryErr}, - {data: readBytes[5:], counts: []int{4}, err: retryErr}, + {data: readBytes[4:], counts: []int{1}, err: internalErr}, + {data: readBytes[5:], counts: []int{4}, err: internalErr}, {data: readBytes[9:], counts: []int{1}, err: io.EOF}, }, want: readData[4:], @@ -215,7 +225,7 @@ func TestRangeReaderRetry(t *testing.T) { offset: -4, length: -1, bodies: []fakeReadCloser{ - {data: readBytes[6:], counts: []int{1}, err: retryErr}, + {data: readBytes[6:], counts: []int{1}, err: internalErr}, {data: readBytes[7:], counts: []int{3}, err: io.EOF}, }, want: readData[6:], diff --git a/talent/apiv4/company_client.go b/talent/apiv4/company_client.go index 55a1a3a8313..5ab5da229ef 100644 --- a/talent/apiv4/company_client.go +++ b/talent/apiv4/company_client.go @@ -23,7 +23,6 @@ import ( "net/url" "time" - "github.com/golang/protobuf/proto" gax "github.com/googleapis/gax-go/v2" "google.golang.org/api/iterator" "google.golang.org/api/option" @@ -33,6 +32,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newCompanyClientHook clientHook @@ -52,6 +52,7 @@ func defaultCompanyGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("jobs.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://jobs.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/talent/apiv4/completion_client.go b/talent/apiv4/completion_client.go index b87afb21b22..86e33e83766 100644 --- a/talent/apiv4/completion_client.go +++ b/talent/apiv4/completion_client.go @@ -46,6 +46,7 @@ func defaultCompletionGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("jobs.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://jobs.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/talent/apiv4/doc.go b/talent/apiv4/doc.go index 8da945dceb9..d516d2ccb0f 100644 --- a/talent/apiv4/doc.go +++ b/talent/apiv4/doc.go @@ -51,7 +51,7 @@ import ( type clientHookParams struct{} type clientHook func(context.Context, clientHookParams) ([]option.ClientOption, error) -const versionClient = "20210612" +const versionClient = "20210701" func insertMetadata(ctx context.Context, mds ...metadata.MD) context.Context { out, _ := metadata.FromOutgoingContext(ctx) diff --git a/talent/apiv4/event_client.go b/talent/apiv4/event_client.go index ae43881bb5d..24a7b46360a 100644 --- a/talent/apiv4/event_client.go +++ b/talent/apiv4/event_client.go @@ -45,6 +45,7 @@ func defaultEventGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("jobs.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://jobs.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/talent/apiv4/job_client.go b/talent/apiv4/job_client.go index 80364f9cdae..835d0bd9957 100644 --- a/talent/apiv4/job_client.go +++ b/talent/apiv4/job_client.go @@ -25,7 +25,6 @@ import ( "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" @@ -36,6 +35,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newJobClientHook clientHook @@ -60,6 +60,7 @@ func defaultJobGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("jobs.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://jobs.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/talent/apiv4/tenant_client.go b/talent/apiv4/tenant_client.go index dd0d84a4602..5e7623443b5 100644 --- a/talent/apiv4/tenant_client.go +++ b/talent/apiv4/tenant_client.go @@ -23,7 +23,6 @@ import ( "net/url" "time" - "github.com/golang/protobuf/proto" gax "github.com/googleapis/gax-go/v2" "google.golang.org/api/iterator" "google.golang.org/api/option" @@ -33,6 +32,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newTenantClientHook clientHook @@ -52,6 +52,7 @@ func defaultTenantGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("jobs.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://jobs.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/talent/apiv4beta1/application_client.go b/talent/apiv4beta1/application_client.go index 04c6c850346..aaf972f68f4 100644 --- a/talent/apiv4beta1/application_client.go +++ b/talent/apiv4beta1/application_client.go @@ -23,7 +23,6 @@ import ( "net/url" "time" - "github.com/golang/protobuf/proto" gax "github.com/googleapis/gax-go/v2" "google.golang.org/api/iterator" "google.golang.org/api/option" @@ -33,6 +32,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newApplicationClientHook clientHook @@ -52,6 +52,7 @@ func defaultApplicationGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("jobs.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://jobs.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/talent/apiv4beta1/company_client.go b/talent/apiv4beta1/company_client.go index adc945b34c1..0d1ff8027e2 100644 --- a/talent/apiv4beta1/company_client.go +++ b/talent/apiv4beta1/company_client.go @@ -23,7 +23,6 @@ import ( "net/url" "time" - "github.com/golang/protobuf/proto" gax "github.com/googleapis/gax-go/v2" "google.golang.org/api/iterator" "google.golang.org/api/option" @@ -33,6 +32,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newCompanyClientHook clientHook @@ -52,6 +52,7 @@ func defaultCompanyGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("jobs.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://jobs.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/talent/apiv4beta1/completion_client.go b/talent/apiv4beta1/completion_client.go index 9ce07f67213..47ee671726f 100644 --- a/talent/apiv4beta1/completion_client.go +++ b/talent/apiv4beta1/completion_client.go @@ -46,6 +46,7 @@ func defaultCompletionGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("jobs.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://jobs.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/talent/apiv4beta1/doc.go b/talent/apiv4beta1/doc.go index 3740f9943b3..42177b8b532 100644 --- a/talent/apiv4beta1/doc.go +++ b/talent/apiv4beta1/doc.go @@ -51,7 +51,7 @@ import ( type clientHookParams struct{} type clientHook func(context.Context, clientHookParams) ([]option.ClientOption, error) -const versionClient = "20210612" +const versionClient = "20210701" func insertMetadata(ctx context.Context, mds ...metadata.MD) context.Context { out, _ := metadata.FromOutgoingContext(ctx) diff --git a/talent/apiv4beta1/event_client.go b/talent/apiv4beta1/event_client.go index 0b4fb355e95..bd75be01c44 100644 --- a/talent/apiv4beta1/event_client.go +++ b/talent/apiv4beta1/event_client.go @@ -45,6 +45,7 @@ func defaultEventGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("jobs.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://jobs.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/talent/apiv4beta1/job_client.go b/talent/apiv4beta1/job_client.go index eb3db308caf..6b177c3802d 100644 --- a/talent/apiv4beta1/job_client.go +++ b/talent/apiv4beta1/job_client.go @@ -25,7 +25,6 @@ import ( "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" @@ -36,6 +35,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newJobClientHook clientHook @@ -60,6 +60,7 @@ func defaultJobGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("jobs.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://jobs.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/talent/apiv4beta1/profile_client.go b/talent/apiv4beta1/profile_client.go index c560b18913c..059aa352933 100644 --- a/talent/apiv4beta1/profile_client.go +++ b/talent/apiv4beta1/profile_client.go @@ -23,7 +23,6 @@ import ( "net/url" "time" - "github.com/golang/protobuf/proto" gax "github.com/googleapis/gax-go/v2" "google.golang.org/api/iterator" "google.golang.org/api/option" @@ -33,6 +32,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newProfileClientHook clientHook @@ -53,6 +53,7 @@ func defaultProfileGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("jobs.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://jobs.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/talent/apiv4beta1/tenant_client.go b/talent/apiv4beta1/tenant_client.go index 43185d4be66..c3e95c8afc1 100644 --- a/talent/apiv4beta1/tenant_client.go +++ b/talent/apiv4beta1/tenant_client.go @@ -23,7 +23,6 @@ import ( "net/url" "time" - "github.com/golang/protobuf/proto" gax "github.com/googleapis/gax-go/v2" "google.golang.org/api/iterator" "google.golang.org/api/option" @@ -33,6 +32,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newTenantClientHook clientHook @@ -52,6 +52,7 @@ func defaultTenantGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("jobs.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://jobs.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/texttospeech/apiv1/doc.go b/texttospeech/apiv1/doc.go index 8b517b678b9..24ba20cf8ea 100644 --- a/texttospeech/apiv1/doc.go +++ b/texttospeech/apiv1/doc.go @@ -49,7 +49,7 @@ import ( type clientHookParams struct{} type clientHook func(context.Context, clientHookParams) ([]option.ClientOption, error) -const versionClient = "20210612" +const versionClient = "20210701" func insertMetadata(ctx context.Context, mds ...metadata.MD) context.Context { out, _ := metadata.FromOutgoingContext(ctx) diff --git a/texttospeech/apiv1/text_to_speech_client.go b/texttospeech/apiv1/text_to_speech_client.go index 6d13f31d4ba..aae16301c18 100644 --- a/texttospeech/apiv1/text_to_speech_client.go +++ b/texttospeech/apiv1/text_to_speech_client.go @@ -45,6 +45,7 @@ func defaultGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("texttospeech.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://texttospeech.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/tpu/apiv1/doc.go b/tpu/apiv1/doc.go index cef448e3407..dad0e41b400 100644 --- a/tpu/apiv1/doc.go +++ b/tpu/apiv1/doc.go @@ -50,7 +50,7 @@ import ( type clientHookParams struct{} type clientHook func(context.Context, clientHookParams) ([]option.ClientOption, error) -const versionClient = "20210612" +const versionClient = "20210701" func insertMetadata(ctx context.Context, mds ...metadata.MD) context.Context { out, _ := metadata.FromOutgoingContext(ctx) diff --git a/tpu/apiv1/tpu_client.go b/tpu/apiv1/tpu_client.go index baa260c9317..6852cce80a5 100644 --- a/tpu/apiv1/tpu_client.go +++ b/tpu/apiv1/tpu_client.go @@ -25,7 +25,6 @@ import ( "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" @@ -35,6 +34,7 @@ import ( longrunningpb "google.golang.org/genproto/googleapis/longrunning" "google.golang.org/grpc" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newClientHook clientHook @@ -60,6 +60,7 @@ func defaultGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("tpu.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://tpu.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/trace/apiv1/doc.go b/trace/apiv1/doc.go index 2d939089be3..e0a78f4aa7f 100644 --- a/trace/apiv1/doc.go +++ b/trace/apiv1/doc.go @@ -52,7 +52,7 @@ import ( type clientHookParams struct{} type clientHook func(context.Context, clientHookParams) ([]option.ClientOption, error) -const versionClient = "20210612" +const versionClient = "20210701" func insertMetadata(ctx context.Context, mds ...metadata.MD) context.Context { out, _ := metadata.FromOutgoingContext(ctx) diff --git a/trace/apiv1/trace_client.go b/trace/apiv1/trace_client.go index 62a3071395e..f9ad4b2a130 100644 --- a/trace/apiv1/trace_client.go +++ b/trace/apiv1/trace_client.go @@ -23,7 +23,6 @@ import ( "net/url" "time" - "github.com/golang/protobuf/proto" gax "github.com/googleapis/gax-go/v2" "google.golang.org/api/iterator" "google.golang.org/api/option" @@ -33,6 +32,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newClientHook clientHook @@ -50,6 +50,7 @@ func defaultGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("cloudtrace.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://cloudtrace.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/trace/apiv2/doc.go b/trace/apiv2/doc.go index 7e3bc4729c2..d0c58d96532 100644 --- a/trace/apiv2/doc.go +++ b/trace/apiv2/doc.go @@ -52,7 +52,7 @@ import ( type clientHookParams struct{} type clientHook func(context.Context, clientHookParams) ([]option.ClientOption, error) -const versionClient = "20210612" +const versionClient = "20210701" func insertMetadata(ctx context.Context, mds ...metadata.MD) context.Context { out, _ := metadata.FromOutgoingContext(ctx) diff --git a/trace/apiv2/trace_client.go b/trace/apiv2/trace_client.go index e0b33f60c75..3159d1fbd65 100644 --- a/trace/apiv2/trace_client.go +++ b/trace/apiv2/trace_client.go @@ -47,6 +47,7 @@ func defaultGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("cloudtrace.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://cloudtrace.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/translate/apiv3/doc.go b/translate/apiv3/doc.go index af8810b26d3..8fec30345a2 100644 --- a/translate/apiv3/doc.go +++ b/translate/apiv3/doc.go @@ -48,7 +48,7 @@ import ( type clientHookParams struct{} type clientHook func(context.Context, clientHookParams) ([]option.ClientOption, error) -const versionClient = "20210612" +const versionClient = "20210701" func insertMetadata(ctx context.Context, mds ...metadata.MD) context.Context { out, _ := metadata.FromOutgoingContext(ctx) diff --git a/translate/apiv3/translation_client.go b/translate/apiv3/translation_client.go index cf5d6fd2016..d350b0276f5 100644 --- a/translate/apiv3/translation_client.go +++ b/translate/apiv3/translation_client.go @@ -25,7 +25,6 @@ import ( "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" @@ -36,6 +35,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newTranslationClientHook clientHook @@ -58,6 +58,7 @@ func defaultTranslationGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("translate.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://translate.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/video/transcoder/apiv1beta1/doc.go b/video/transcoder/apiv1beta1/doc.go index 55550282a65..f6b78a3a542 100644 --- a/video/transcoder/apiv1beta1/doc.go +++ b/video/transcoder/apiv1beta1/doc.go @@ -51,7 +51,7 @@ import ( type clientHookParams struct{} type clientHook func(context.Context, clientHookParams) ([]option.ClientOption, error) -const versionClient = "20210612" +const versionClient = "20210701" func insertMetadata(ctx context.Context, mds ...metadata.MD) context.Context { out, _ := metadata.FromOutgoingContext(ctx) diff --git a/video/transcoder/apiv1beta1/transcoder_client.go b/video/transcoder/apiv1beta1/transcoder_client.go index 8e992d5aa01..8bf2e8ceb15 100644 --- a/video/transcoder/apiv1beta1/transcoder_client.go +++ b/video/transcoder/apiv1beta1/transcoder_client.go @@ -23,7 +23,6 @@ import ( "net/url" "time" - "github.com/golang/protobuf/proto" gax "github.com/googleapis/gax-go/v2" "google.golang.org/api/iterator" "google.golang.org/api/option" @@ -32,6 +31,7 @@ import ( transcoderpb "google.golang.org/genproto/googleapis/cloud/video/transcoder/v1beta1" "google.golang.org/grpc" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newClientHook clientHook @@ -54,6 +54,7 @@ func defaultGRPCClientOptions() []option.ClientOption { 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))), diff --git a/videointelligence/apiv1/doc.go b/videointelligence/apiv1/doc.go index 0c34e7e22f1..54494b31bf2 100644 --- a/videointelligence/apiv1/doc.go +++ b/videointelligence/apiv1/doc.go @@ -50,7 +50,7 @@ import ( type clientHookParams struct{} type clientHook func(context.Context, clientHookParams) ([]option.ClientOption, error) -const versionClient = "20210612" +const versionClient = "20210701" func insertMetadata(ctx context.Context, mds ...metadata.MD) context.Context { out, _ := metadata.FromOutgoingContext(ctx) diff --git a/videointelligence/apiv1/video_intelligence_client.go b/videointelligence/apiv1/video_intelligence_client.go index 1f113b78865..1cb25f30be7 100644 --- a/videointelligence/apiv1/video_intelligence_client.go +++ b/videointelligence/apiv1/video_intelligence_client.go @@ -47,6 +47,7 @@ func defaultGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("videointelligence.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://videointelligence.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/videointelligence/apiv1beta2/doc.go b/videointelligence/apiv1beta2/doc.go index 0bce103e07f..3ca9b3f113b 100644 --- a/videointelligence/apiv1beta2/doc.go +++ b/videointelligence/apiv1beta2/doc.go @@ -52,7 +52,7 @@ import ( type clientHookParams struct{} type clientHook func(context.Context, clientHookParams) ([]option.ClientOption, error) -const versionClient = "20210612" +const versionClient = "20210701" func insertMetadata(ctx context.Context, mds ...metadata.MD) context.Context { out, _ := metadata.FromOutgoingContext(ctx) diff --git a/videointelligence/apiv1beta2/video_intelligence_client.go b/videointelligence/apiv1beta2/video_intelligence_client.go index f33c1ece815..d83c966514b 100644 --- a/videointelligence/apiv1beta2/video_intelligence_client.go +++ b/videointelligence/apiv1beta2/video_intelligence_client.go @@ -47,6 +47,7 @@ func defaultGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("videointelligence.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://videointelligence.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/vision/apiv1/doc.go b/vision/apiv1/doc.go index fd64d2e8775..d8eb6e74870 100644 --- a/vision/apiv1/doc.go +++ b/vision/apiv1/doc.go @@ -50,7 +50,7 @@ import ( type clientHookParams struct{} type clientHook func(context.Context, clientHookParams) ([]option.ClientOption, error) -const versionClient = "20210612" +const versionClient = "20210701" func insertMetadata(ctx context.Context, mds ...metadata.MD) context.Context { out, _ := metadata.FromOutgoingContext(ctx) diff --git a/vision/apiv1/image_annotator_client.go b/vision/apiv1/image_annotator_client.go index c2b8198f946..2d0f169cf58 100644 --- a/vision/apiv1/image_annotator_client.go +++ b/vision/apiv1/image_annotator_client.go @@ -52,6 +52,7 @@ func defaultImageAnnotatorGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("vision.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://vision.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/vision/apiv1/product_search_client.go b/vision/apiv1/product_search_client.go index 9ea807f529a..695b7553b04 100644 --- a/vision/apiv1/product_search_client.go +++ b/vision/apiv1/product_search_client.go @@ -25,7 +25,6 @@ import ( "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" @@ -36,6 +35,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newProductSearchClientHook clientHook @@ -69,6 +69,7 @@ func defaultProductSearchGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("vision.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://vision.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/vision/apiv1p1beta1/doc.go b/vision/apiv1p1beta1/doc.go index dbad2cdbae6..780ad088ca6 100644 --- a/vision/apiv1p1beta1/doc.go +++ b/vision/apiv1p1beta1/doc.go @@ -52,7 +52,7 @@ import ( type clientHookParams struct{} type clientHook func(context.Context, clientHookParams) ([]option.ClientOption, error) -const versionClient = "20210612" +const versionClient = "20210701" func insertMetadata(ctx context.Context, mds ...metadata.MD) context.Context { out, _ := metadata.FromOutgoingContext(ctx) diff --git a/vision/apiv1p1beta1/image_annotator_client.go b/vision/apiv1p1beta1/image_annotator_client.go index ba8fcbd3cc2..13c3299477a 100644 --- a/vision/apiv1p1beta1/image_annotator_client.go +++ b/vision/apiv1p1beta1/image_annotator_client.go @@ -44,6 +44,7 @@ func defaultImageAnnotatorGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("vision.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://vision.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/vpcaccess/apiv1/doc.go b/vpcaccess/apiv1/doc.go index 741bf3d2af8..cc9820231b8 100644 --- a/vpcaccess/apiv1/doc.go +++ b/vpcaccess/apiv1/doc.go @@ -50,7 +50,7 @@ import ( type clientHookParams struct{} type clientHook func(context.Context, clientHookParams) ([]option.ClientOption, error) -const versionClient = "20210612" +const versionClient = "20210701" func insertMetadata(ctx context.Context, mds ...metadata.MD) context.Context { out, _ := metadata.FromOutgoingContext(ctx) diff --git a/vpcaccess/apiv1/vpc_access_client.go b/vpcaccess/apiv1/vpc_access_client.go index 443261256c3..f1a0dee1e7f 100644 --- a/vpcaccess/apiv1/vpc_access_client.go +++ b/vpcaccess/apiv1/vpc_access_client.go @@ -25,7 +25,6 @@ import ( "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" @@ -35,6 +34,7 @@ import ( longrunningpb "google.golang.org/genproto/googleapis/longrunning" "google.golang.org/grpc" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newClientHook clientHook @@ -53,6 +53,7 @@ func defaultGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("vpcaccess.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://vpcaccess.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/webrisk/apiv1/doc.go b/webrisk/apiv1/doc.go index 3b63631ed00..cf39af86ed7 100644 --- a/webrisk/apiv1/doc.go +++ b/webrisk/apiv1/doc.go @@ -46,7 +46,7 @@ import ( type clientHookParams struct{} type clientHook func(context.Context, clientHookParams) ([]option.ClientOption, error) -const versionClient = "20210612" +const versionClient = "20210701" func insertMetadata(ctx context.Context, mds ...metadata.MD) context.Context { out, _ := metadata.FromOutgoingContext(ctx) diff --git a/webrisk/apiv1/web_risk_client.go b/webrisk/apiv1/web_risk_client.go index a0bf0628c11..96c72b018f6 100644 --- a/webrisk/apiv1/web_risk_client.go +++ b/webrisk/apiv1/web_risk_client.go @@ -49,6 +49,7 @@ func defaultGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("webrisk.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://webrisk.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/webrisk/apiv1beta1/doc.go b/webrisk/apiv1beta1/doc.go index 8a097b68896..d6278cbfffe 100644 --- a/webrisk/apiv1beta1/doc.go +++ b/webrisk/apiv1beta1/doc.go @@ -48,7 +48,7 @@ import ( type clientHookParams struct{} type clientHook func(context.Context, clientHookParams) ([]option.ClientOption, error) -const versionClient = "20210612" +const versionClient = "20210701" func insertMetadata(ctx context.Context, mds ...metadata.MD) context.Context { out, _ := metadata.FromOutgoingContext(ctx) diff --git a/webrisk/apiv1beta1/web_risk_service_v1_beta1_client.go b/webrisk/apiv1beta1/web_risk_service_v1_beta1_client.go index 346b784f070..639818d30a0 100644 --- a/webrisk/apiv1beta1/web_risk_service_v1_beta1_client.go +++ b/webrisk/apiv1beta1/web_risk_service_v1_beta1_client.go @@ -46,6 +46,7 @@ func defaultWebRiskServiceV1Beta1GRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("webrisk.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://webrisk.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/websecurityscanner/apiv1/doc.go b/websecurityscanner/apiv1/doc.go index 6b53c0b753c..7065fdfd358 100644 --- a/websecurityscanner/apiv1/doc.go +++ b/websecurityscanner/apiv1/doc.go @@ -48,7 +48,7 @@ import ( type clientHookParams struct{} type clientHook func(context.Context, clientHookParams) ([]option.ClientOption, error) -const versionClient = "20210612" +const versionClient = "20210701" func insertMetadata(ctx context.Context, mds ...metadata.MD) context.Context { out, _ := metadata.FromOutgoingContext(ctx) diff --git a/websecurityscanner/apiv1/web_security_scanner_client.go b/websecurityscanner/apiv1/web_security_scanner_client.go index 28192840014..02474402de7 100644 --- a/websecurityscanner/apiv1/web_security_scanner_client.go +++ b/websecurityscanner/apiv1/web_security_scanner_client.go @@ -23,7 +23,6 @@ import ( "net/url" "time" - "github.com/golang/protobuf/proto" gax "github.com/googleapis/gax-go/v2" "google.golang.org/api/iterator" "google.golang.org/api/option" @@ -33,6 +32,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newClientHook clientHook @@ -60,6 +60,7 @@ func defaultGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("websecurityscanner.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://websecurityscanner.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/workflows/apiv1beta/doc.go b/workflows/apiv1beta/doc.go index 581dd2f7cdb..d2eaf175289 100644 --- a/workflows/apiv1beta/doc.go +++ b/workflows/apiv1beta/doc.go @@ -48,7 +48,7 @@ import ( type clientHookParams struct{} type clientHook func(context.Context, clientHookParams) ([]option.ClientOption, error) -const versionClient = "20210612" +const versionClient = "20210701" func insertMetadata(ctx context.Context, mds ...metadata.MD) context.Context { out, _ := metadata.FromOutgoingContext(ctx) diff --git a/workflows/apiv1beta/workflows_client.go b/workflows/apiv1beta/workflows_client.go index 406ddf8ce52..9169f065f0c 100644 --- a/workflows/apiv1beta/workflows_client.go +++ b/workflows/apiv1beta/workflows_client.go @@ -25,7 +25,6 @@ import ( "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" @@ -35,6 +34,7 @@ import ( longrunningpb "google.golang.org/genproto/googleapis/longrunning" "google.golang.org/grpc" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newClientHook clientHook @@ -54,6 +54,7 @@ func defaultGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("workflows.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://workflows.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))), diff --git a/workflows/executions/apiv1/doc.go b/workflows/executions/apiv1/doc.go new file mode 100644 index 00000000000..302fe9c08fc --- /dev/null +++ b/workflows/executions/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 executions is an auto-generated package for the +// Workflow Executions API. +// +// Execute workflows created with Workflows API. +// +// 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 executions // import "cloud.google.com/go/workflows/executions/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 = "20210701" + +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/workflows/executions/apiv1/executions_client.go b/workflows/executions/apiv1/executions_client.go new file mode 100644 index 00000000000..d83ac03b02c --- /dev/null +++ b/workflows/executions/apiv1/executions_client.go @@ -0,0 +1,351 @@ +// 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 executions + +import ( + "context" + "fmt" + "math" + "net/url" + + 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" + executionspb "google.golang.org/genproto/googleapis/cloud/workflows/executions/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 { + ListExecutions []gax.CallOption + CreateExecution []gax.CallOption + GetExecution []gax.CallOption + CancelExecution []gax.CallOption +} + +func defaultGRPCClientOptions() []option.ClientOption { + return []option.ClientOption{ + internaloption.WithDefaultEndpoint("workflowexecutions.googleapis.com:443"), + internaloption.WithDefaultMTLSEndpoint("workflowexecutions.mtls.googleapis.com:443"), + internaloption.WithDefaultAudience("https://workflowexecutions.googleapis.com/"), + internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), + option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), + option.WithGRPCDialOption(grpc.WithDefaultCallOptions( + grpc.MaxCallRecvMsgSize(math.MaxInt32))), + } +} + +func defaultCallOptions() *CallOptions { + return &CallOptions{ + ListExecutions: []gax.CallOption{}, + CreateExecution: []gax.CallOption{}, + GetExecution: []gax.CallOption{}, + CancelExecution: []gax.CallOption{}, + } +} + +// internalClient is an interface that defines the methods availaible from Workflow Executions API. +type internalClient interface { + Close() error + setGoogleClientInfo(...string) + Connection() *grpc.ClientConn + ListExecutions(context.Context, *executionspb.ListExecutionsRequest, ...gax.CallOption) *ExecutionIterator + CreateExecution(context.Context, *executionspb.CreateExecutionRequest, ...gax.CallOption) (*executionspb.Execution, error) + GetExecution(context.Context, *executionspb.GetExecutionRequest, ...gax.CallOption) (*executionspb.Execution, error) + CancelExecution(context.Context, *executionspb.CancelExecutionRequest, ...gax.CallOption) (*executionspb.Execution, error) +} + +// Client is a client for interacting with Workflow Executions API. +// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. +// +// Executions is used to start and manage running instances of +// Workflows called executions. +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() +} + +// ListExecutions returns a list of executions which belong to the workflow with +// the given name. The method returns executions of all workflow +// revisions. Returned executions are ordered by their start time (newest +// first). +func (c *Client) ListExecutions(ctx context.Context, req *executionspb.ListExecutionsRequest, opts ...gax.CallOption) *ExecutionIterator { + return c.internalClient.ListExecutions(ctx, req, opts...) +} + +// CreateExecution creates a new execution using the latest revision of the given workflow. +func (c *Client) CreateExecution(ctx context.Context, req *executionspb.CreateExecutionRequest, opts ...gax.CallOption) (*executionspb.Execution, error) { + return c.internalClient.CreateExecution(ctx, req, opts...) +} + +// GetExecution returns an execution of the given name. +func (c *Client) GetExecution(ctx context.Context, req *executionspb.GetExecutionRequest, opts ...gax.CallOption) (*executionspb.Execution, error) { + return c.internalClient.GetExecution(ctx, req, opts...) +} + +// CancelExecution cancels an execution of the given name. +func (c *Client) CancelExecution(ctx context.Context, req *executionspb.CancelExecutionRequest, opts ...gax.CallOption) (*executionspb.Execution, error) { + return c.internalClient.CancelExecution(ctx, req, opts...) +} + +// gRPCClient is a client for interacting with Workflow Executions 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 executionspb.ExecutionsClient + + // The x-goog-* metadata to be sent with each request. + xGoogMetadata metadata.MD +} + +// NewClient creates a new executions client based on gRPC. +// The returned client must be Closed when it is done being used to clean up its underlying connections. +// +// Executions is used to start and manage running instances of +// Workflows called executions. +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: executionspb.NewExecutionsClient(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) ListExecutions(ctx context.Context, req *executionspb.ListExecutionsRequest, opts ...gax.CallOption) *ExecutionIterator { + 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).ListExecutions[0:len((*c.CallOptions).ListExecutions):len((*c.CallOptions).ListExecutions)], opts...) + it := &ExecutionIterator{} + req = proto.Clone(req).(*executionspb.ListExecutionsRequest) + it.InternalFetch = func(pageSize int, pageToken string) ([]*executionspb.Execution, string, error) { + var resp *executionspb.ListExecutionsResponse + 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.ListExecutions(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, "", err + } + + it.Response = resp + return resp.GetExecutions(), 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) CreateExecution(ctx context.Context, req *executionspb.CreateExecutionRequest, opts ...gax.CallOption) (*executionspb.Execution, error) { + 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).CreateExecution[0:len((*c.CallOptions).CreateExecution):len((*c.CallOptions).CreateExecution)], opts...) + var resp *executionspb.Execution + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.client.CreateExecution(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} + +func (c *gRPCClient) GetExecution(ctx context.Context, req *executionspb.GetExecutionRequest, opts ...gax.CallOption) (*executionspb.Execution, error) { + 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).GetExecution[0:len((*c.CallOptions).GetExecution):len((*c.CallOptions).GetExecution)], opts...) + var resp *executionspb.Execution + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.client.GetExecution(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} + +func (c *gRPCClient) CancelExecution(ctx context.Context, req *executionspb.CancelExecutionRequest, opts ...gax.CallOption) (*executionspb.Execution, error) { + 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).CancelExecution[0:len((*c.CallOptions).CancelExecution):len((*c.CallOptions).CancelExecution)], opts...) + var resp *executionspb.Execution + err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { + var err error + resp, err = c.client.CancelExecution(ctx, req, settings.GRPC...) + return err + }, opts...) + if err != nil { + return nil, err + } + return resp, nil +} + +// ExecutionIterator manages a stream of *executionspb.Execution. +type ExecutionIterator struct { + items []*executionspb.Execution + 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 []*executionspb.Execution, nextPageToken string, err error) +} + +// PageInfo supports pagination. See the google.golang.org/api/iterator package for details. +func (it *ExecutionIterator) 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 *ExecutionIterator) Next() (*executionspb.Execution, error) { + var item *executionspb.Execution + if err := it.nextFunc(); err != nil { + return item, err + } + item = it.items[0] + it.items = it.items[1:] + return item, nil +} + +func (it *ExecutionIterator) bufLen() int { + return len(it.items) +} + +func (it *ExecutionIterator) takeBuf() interface{} { + b := it.items + it.items = nil + return b +} diff --git a/workflows/executions/apiv1/executions_client_example_test.go b/workflows/executions/apiv1/executions_client_example_test.go new file mode 100644 index 00000000000..9e1166407f3 --- /dev/null +++ b/workflows/executions/apiv1/executions_client_example_test.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 executions_test + +import ( + "context" + + executions "cloud.google.com/go/workflows/executions/apiv1" + "google.golang.org/api/iterator" + executionspb "google.golang.org/genproto/googleapis/cloud/workflows/executions/v1" +) + +func ExampleNewClient() { + ctx := context.Background() + c, err := executions.NewClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + // TODO: Use client. + _ = c +} + +func ExampleClient_ListExecutions() { + ctx := context.Background() + c, err := executions.NewClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &executionspb.ListExecutionsRequest{ + // TODO: Fill request struct fields. + } + it := c.ListExecutions(ctx, req) + for { + resp, err := it.Next() + if err == iterator.Done { + break + } + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp + } +} + +func ExampleClient_CreateExecution() { + ctx := context.Background() + c, err := executions.NewClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &executionspb.CreateExecutionRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.CreateExecution(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleClient_GetExecution() { + ctx := context.Background() + c, err := executions.NewClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &executionspb.GetExecutionRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.GetExecution(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} + +func ExampleClient_CancelExecution() { + ctx := context.Background() + c, err := executions.NewClient(ctx) + if err != nil { + // TODO: Handle error. + } + defer c.Close() + + req := &executionspb.CancelExecutionRequest{ + // TODO: Fill request struct fields. + } + resp, err := c.CancelExecution(ctx, req) + if err != nil { + // TODO: Handle error. + } + // TODO: Use resp. + _ = resp +} diff --git a/workflows/executions/apiv1/gapic_metadata.json b/workflows/executions/apiv1/gapic_metadata.json new file mode 100644 index 00000000000..cade633f7da --- /dev/null +++ b/workflows/executions/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.workflows.executions.v1", + "libraryPackage": "cloud.google.com/go/workflows/executions/apiv1", + "services": { + "Executions": { + "clients": { + "grpc": { + "libraryClient": "Client", + "rpcs": { + "CancelExecution": { + "methods": [ + "CancelExecution" + ] + }, + "CreateExecution": { + "methods": [ + "CreateExecution" + ] + }, + "GetExecution": { + "methods": [ + "GetExecution" + ] + }, + "ListExecutions": { + "methods": [ + "ListExecutions" + ] + } + } + } + } + } + } +} diff --git a/workflows/executions/apiv1beta/doc.go b/workflows/executions/apiv1beta/doc.go index d11a0b320ee..25969c4bed2 100644 --- a/workflows/executions/apiv1beta/doc.go +++ b/workflows/executions/apiv1beta/doc.go @@ -50,7 +50,7 @@ import ( type clientHookParams struct{} type clientHook func(context.Context, clientHookParams) ([]option.ClientOption, error) -const versionClient = "20210612" +const versionClient = "20210701" func insertMetadata(ctx context.Context, mds ...metadata.MD) context.Context { out, _ := metadata.FromOutgoingContext(ctx) diff --git a/workflows/executions/apiv1beta/executions_client.go b/workflows/executions/apiv1beta/executions_client.go index d8934360c7d..a074fd6e3b1 100644 --- a/workflows/executions/apiv1beta/executions_client.go +++ b/workflows/executions/apiv1beta/executions_client.go @@ -22,7 +22,6 @@ import ( "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" @@ -31,6 +30,7 @@ import ( executionspb "google.golang.org/genproto/googleapis/cloud/workflows/executions/v1beta" "google.golang.org/grpc" "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/proto" ) var newClientHook clientHook @@ -49,6 +49,7 @@ func defaultGRPCClientOptions() []option.ClientOption { internaloption.WithDefaultMTLSEndpoint("workflowexecutions.mtls.googleapis.com:443"), internaloption.WithDefaultAudience("https://workflowexecutions.googleapis.com/"), internaloption.WithDefaultScopes(DefaultAuthScopes()...), + internaloption.EnableJwtWithScope(), option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), option.WithGRPCDialOption(grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(math.MaxInt32))),