diff --git a/google-cloud-service_usage-v1/.owlbot-manifest.json b/google-cloud-service_usage-v1/.owlbot-manifest.json index 345902175b1e..b57d705b117e 100644 --- a/google-cloud-service_usage-v1/.owlbot-manifest.json +++ b/google-cloud-service_usage-v1/.owlbot-manifest.json @@ -17,10 +17,15 @@ "lib/google/api/serviceusage/v1/serviceusage_pb.rb", "lib/google/api/serviceusage/v1/serviceusage_services_pb.rb", "lib/google/cloud/service_usage/v1.rb", + "lib/google/cloud/service_usage/v1/rest.rb", "lib/google/cloud/service_usage/v1/service_usage.rb", "lib/google/cloud/service_usage/v1/service_usage/client.rb", "lib/google/cloud/service_usage/v1/service_usage/credentials.rb", "lib/google/cloud/service_usage/v1/service_usage/operations.rb", + "lib/google/cloud/service_usage/v1/service_usage/rest.rb", + "lib/google/cloud/service_usage/v1/service_usage/rest/client.rb", + "lib/google/cloud/service_usage/v1/service_usage/rest/operations.rb", + "lib/google/cloud/service_usage/v1/service_usage/rest/service_stub.rb", "lib/google/cloud/service_usage/v1/version.rb", "proto_docs/README.md", "proto_docs/google/api/auth.rb", @@ -54,6 +59,7 @@ "snippets/service_usage/list_services.rb", "snippets/snippet_metadata_google.api.serviceusage.v1.json", "test/google/cloud/service_usage/v1/service_usage_operations_test.rb", + "test/google/cloud/service_usage/v1/service_usage_rest_test.rb", "test/google/cloud/service_usage/v1/service_usage_test.rb", "test/helper.rb" ], diff --git a/google-cloud-service_usage-v1/lib/google/api/serviceusage/v1/resources_pb.rb b/google-cloud-service_usage-v1/lib/google/api/serviceusage/v1/resources_pb.rb index d36d2e675ce8..960a4761204e 100644 --- a/google-cloud-service_usage-v1/lib/google/api/serviceusage/v1/resources_pb.rb +++ b/google-cloud-service_usage-v1/lib/google/api/serviceusage/v1/resources_pb.rb @@ -10,11 +10,12 @@ require 'google/api/monitored_resource_pb' require 'google/api/monitoring_pb' require 'google/api/quota_pb' +require 'google/api/resource_pb' require 'google/api/usage_pb' require 'google/protobuf/api_pb' -descriptor_data = "\n*google/api/serviceusage/v1/resources.proto\x12\x1agoogle.api.serviceusage.v1\x1a\x15google/api/auth.proto\x1a\x1egoogle/api/documentation.proto\x1a\x19google/api/endpoint.proto\x1a#google/api/monitored_resource.proto\x1a\x1bgoogle/api/monitoring.proto\x1a\x16google/api/quota.proto\x1a\x16google/api/usage.proto\x1a\x19google/protobuf/api.proto\"\x94\x01\n\x07Service\x12\x0c\n\x04name\x18\x01 \x01(\t\x12\x0e\n\x06parent\x18\x05 \x01(\t\x12\x39\n\x06\x63onfig\x18\x02 \x01(\x0b\x32).google.api.serviceusage.v1.ServiceConfig\x12\x30\n\x05state\x18\x04 \x01(\x0e\x32!.google.api.serviceusage.v1.State\"\x95\x03\n\rServiceConfig\x12\x0c\n\x04name\x18\x01 \x01(\t\x12\r\n\x05title\x18\x02 \x01(\t\x12\"\n\x04\x61pis\x18\x03 \x03(\x0b\x32\x14.google.protobuf.Api\x12\x30\n\rdocumentation\x18\x06 \x01(\x0b\x32\x19.google.api.Documentation\x12 \n\x05quota\x18\n \x01(\x0b\x32\x11.google.api.Quota\x12\x32\n\x0e\x61uthentication\x18\x0b \x01(\x0b\x32\x1a.google.api.Authentication\x12 \n\x05usage\x18\x0f \x01(\x0b\x32\x11.google.api.Usage\x12\'\n\tendpoints\x18\x12 \x03(\x0b\x32\x14.google.api.Endpoint\x12\x44\n\x13monitored_resources\x18\x19 \x03(\x0b\x32\'.google.api.MonitoredResourceDescriptor\x12*\n\nmonitoring\x18\x1c \x01(\x0b\x32\x16.google.api.Monitoring\"+\n\x11OperationMetadata\x12\x16\n\x0eresource_names\x18\x02 \x03(\t*9\n\x05State\x12\x15\n\x11STATE_UNSPECIFIED\x10\x00\x12\x0c\n\x08\x44ISABLED\x10\x01\x12\x0b\n\x07\x45NABLED\x10\x02\x42\xd8\x01\n\x1e\x63om.google.api.serviceusage.v1B\x0eResourcesProtoP\x01ZDcloud.google.com/go/serviceusage/apiv1/serviceusagepb;serviceusagepb\xaa\x02\x1cGoogle.Cloud.ServiceUsage.V1\xca\x02\x1cGoogle\\Cloud\\ServiceUsage\\V1\xea\x02\x1fGoogle::Cloud::ServiceUsage::V1b\x06proto3" +descriptor_data = "\n*google/api/serviceusage/v1/resources.proto\x12\x1agoogle.api.serviceusage.v1\x1a\x15google/api/auth.proto\x1a\x1egoogle/api/documentation.proto\x1a\x19google/api/endpoint.proto\x1a#google/api/monitored_resource.proto\x1a\x1bgoogle/api/monitoring.proto\x1a\x16google/api/quota.proto\x1a\x19google/api/resource.proto\x1a\x16google/api/usage.proto\x1a\x19google/protobuf/api.proto\"\xbd\x02\n\x07Service\x12\x0c\n\x04name\x18\x01 \x01(\t\x12\x0e\n\x06parent\x18\x05 \x01(\t\x12\x39\n\x06\x63onfig\x18\x02 \x01(\x0b\x32).google.api.serviceusage.v1.ServiceConfig\x12\x30\n\x05state\x18\x04 \x01(\x0e\x32!.google.api.serviceusage.v1.State:\xa6\x01\xea\x41\xa2\x01\n#serviceusage.googleapis.com/Service\x12%projects/{project}/services/{service}\x12#folders/{folder}/services/{service}\x12/organizations/{organization}/services/{service}\"\x95\x03\n\rServiceConfig\x12\x0c\n\x04name\x18\x01 \x01(\t\x12\r\n\x05title\x18\x02 \x01(\t\x12\"\n\x04\x61pis\x18\x03 \x03(\x0b\x32\x14.google.protobuf.Api\x12\x30\n\rdocumentation\x18\x06 \x01(\x0b\x32\x19.google.api.Documentation\x12 \n\x05quota\x18\n \x01(\x0b\x32\x11.google.api.Quota\x12\x32\n\x0e\x61uthentication\x18\x0b \x01(\x0b\x32\x1a.google.api.Authentication\x12 \n\x05usage\x18\x0f \x01(\x0b\x32\x11.google.api.Usage\x12\'\n\tendpoints\x18\x12 \x03(\x0b\x32\x14.google.api.Endpoint\x12\x44\n\x13monitored_resources\x18\x19 \x03(\x0b\x32\'.google.api.MonitoredResourceDescriptor\x12*\n\nmonitoring\x18\x1c \x01(\x0b\x32\x16.google.api.Monitoring\"+\n\x11OperationMetadata\x12\x16\n\x0eresource_names\x18\x02 \x03(\t*9\n\x05State\x12\x15\n\x11STATE_UNSPECIFIED\x10\x00\x12\x0c\n\x08\x44ISABLED\x10\x01\x12\x0b\n\x07\x45NABLED\x10\x02\x42\xd8\x01\n\x1e\x63om.google.api.serviceusage.v1B\x0eResourcesProtoP\x01ZDcloud.google.com/go/serviceusage/apiv1/serviceusagepb;serviceusagepb\xaa\x02\x1cGoogle.Cloud.ServiceUsage.V1\xca\x02\x1cGoogle\\Cloud\\ServiceUsage\\V1\xea\x02\x1fGoogle::Cloud::ServiceUsage::V1b\x06proto3" pool = Google::Protobuf::DescriptorPool.generated_pool diff --git a/google-cloud-service_usage-v1/lib/google/api/serviceusage/v1/serviceusage_pb.rb b/google-cloud-service_usage-v1/lib/google/api/serviceusage/v1/serviceusage_pb.rb index a3bef7cd6f67..e658f3b6ce3b 100644 --- a/google-cloud-service_usage-v1/lib/google/api/serviceusage/v1/serviceusage_pb.rb +++ b/google-cloud-service_usage-v1/lib/google/api/serviceusage/v1/serviceusage_pb.rb @@ -5,12 +5,12 @@ require 'google/protobuf' require 'google/api/annotations_pb' +require 'google/api/client_pb' require 'google/api/serviceusage/v1/resources_pb' require 'google/longrunning/operations_pb' -require 'google/api/client_pb' -descriptor_data = "\n-google/api/serviceusage/v1/serviceusage.proto\x12\x1agoogle.api.serviceusage.v1\x1a\x1cgoogle/api/annotations.proto\x1a*google/api/serviceusage/v1/resources.proto\x1a#google/longrunning/operations.proto\x1a\x17google/api/client.proto\"$\n\x14\x45nableServiceRequest\x12\x0c\n\x04name\x18\x01 \x01(\t\"M\n\x15\x45nableServiceResponse\x12\x34\n\x07service\x18\x01 \x01(\x0b\x32#.google.api.serviceusage.v1.Service\"\x92\x02\n\x15\x44isableServiceRequest\x12\x0c\n\x04name\x18\x01 \x01(\t\x12\"\n\x1a\x64isable_dependent_services\x18\x02 \x01(\x08\x12l\n\x1a\x63heck_if_service_has_usage\x18\x03 \x01(\x0e\x32H.google.api.serviceusage.v1.DisableServiceRequest.CheckIfServiceHasUsage\"Y\n\x16\x43heckIfServiceHasUsage\x12*\n&CHECK_IF_SERVICE_HAS_USAGE_UNSPECIFIED\x10\x00\x12\x08\n\x04SKIP\x10\x01\x12\t\n\x05\x43HECK\x10\x02\"N\n\x16\x44isableServiceResponse\x12\x34\n\x07service\x18\x01 \x01(\x0b\x32#.google.api.serviceusage.v1.Service\"!\n\x11GetServiceRequest\x12\x0c\n\x04name\x18\x01 \x01(\t\"\\\n\x13ListServicesRequest\x12\x0e\n\x06parent\x18\x01 \x01(\t\x12\x11\n\tpage_size\x18\x02 \x01(\x05\x12\x12\n\npage_token\x18\x03 \x01(\t\x12\x0e\n\x06\x66ilter\x18\x04 \x01(\t\"f\n\x14ListServicesResponse\x12\x35\n\x08services\x18\x01 \x03(\x0b\x32#.google.api.serviceusage.v1.Service\x12\x17\n\x0fnext_page_token\x18\x02 \x01(\t\"A\n\x1a\x42\x61tchEnableServicesRequest\x12\x0e\n\x06parent\x18\x01 \x01(\t\x12\x13\n\x0bservice_ids\x18\x02 \x03(\t\"\xe9\x01\n\x1b\x42\x61tchEnableServicesResponse\x12\x35\n\x08services\x18\x01 \x03(\x0b\x32#.google.api.serviceusage.v1.Service\x12W\n\x08\x66\x61ilures\x18\x02 \x03(\x0b\x32\x45.google.api.serviceusage.v1.BatchEnableServicesResponse.EnableFailure\x1a:\n\rEnableFailure\x12\x12\n\nservice_id\x18\x01 \x01(\t\x12\x15\n\rerror_message\x18\x02 \x01(\t\"8\n\x17\x42\x61tchGetServicesRequest\x12\x0e\n\x06parent\x18\x01 \x01(\t\x12\r\n\x05names\x18\x02 \x03(\t\"Q\n\x18\x42\x61tchGetServicesResponse\x12\x35\n\x08services\x18\x01 \x03(\x0b\x32#.google.api.serviceusage.v1.Service2\xe8\t\n\x0cServiceUsage\x12\xba\x01\n\rEnableService\x12\x30.google.api.serviceusage.v1.EnableServiceRequest\x1a\x1d.google.longrunning.Operation\"X\x82\xd3\xe4\x93\x02%\" /v1/{name=*/*/services/*}:enable:\x01*\xca\x41*\n\x15\x45nableServiceResponse\x12\x11OperationMetadata\x12\xbe\x01\n\x0e\x44isableService\x12\x31.google.api.serviceusage.v1.DisableServiceRequest\x1a\x1d.google.longrunning.Operation\"Z\x82\xd3\xe4\x93\x02&\"!/v1/{name=*/*/services/*}:disable:\x01*\xca\x41+\n\x16\x44isableServiceResponse\x12\x11OperationMetadata\x12\x83\x01\n\nGetService\x12-.google.api.serviceusage.v1.GetServiceRequest\x1a#.google.api.serviceusage.v1.Service\"!\x82\xd3\xe4\x93\x02\x1b\x12\x19/v1/{name=*/*/services/*}\x12\x94\x01\n\x0cListServices\x12/.google.api.serviceusage.v1.ListServicesRequest\x1a\x30.google.api.serviceusage.v1.ListServicesResponse\"!\x82\xd3\xe4\x93\x02\x1b\x12\x19/v1/{parent=*/*}/services\x12\xd1\x01\n\x13\x42\x61tchEnableServices\x12\x36.google.api.serviceusage.v1.BatchEnableServicesRequest\x1a\x1d.google.longrunning.Operation\"c\x82\xd3\xe4\x93\x02*\"%/v1/{parent=*/*}/services:batchEnable:\x01*\xca\x41\x30\n\x1b\x42\x61tchEnableServicesResponse\x12\x11OperationMetadata\x12\xa9\x01\n\x10\x42\x61tchGetServices\x12\x33.google.api.serviceusage.v1.BatchGetServicesRequest\x1a\x34.google.api.serviceusage.v1.BatchGetServicesResponse\"*\x82\xd3\xe4\x93\x02$\x12\"/v1/{parent=*/*}/services:batchGet\x1a\xbc\x01\xca\x41\x1bserviceusage.googleapis.com\xd2\x41\x9a\x01https://www.googleapis.com/auth/cloud-platform,https://www.googleapis.com/auth/cloud-platform.read-only,https://www.googleapis.com/auth/service.managementB\xdb\x01\n\x1e\x63om.google.api.serviceusage.v1B\x11ServiceUsageProtoP\x01ZDcloud.google.com/go/serviceusage/apiv1/serviceusagepb;serviceusagepb\xaa\x02\x1cGoogle.Cloud.ServiceUsage.V1\xca\x02\x1cGoogle\\Cloud\\ServiceUsage\\V1\xea\x02\x1fGoogle::Cloud::ServiceUsage::V1b\x06proto3" +descriptor_data = "\n-google/api/serviceusage/v1/serviceusage.proto\x12\x1agoogle.api.serviceusage.v1\x1a\x1cgoogle/api/annotations.proto\x1a\x17google/api/client.proto\x1a*google/api/serviceusage/v1/resources.proto\x1a#google/longrunning/operations.proto\"$\n\x14\x45nableServiceRequest\x12\x0c\n\x04name\x18\x01 \x01(\t\"M\n\x15\x45nableServiceResponse\x12\x34\n\x07service\x18\x01 \x01(\x0b\x32#.google.api.serviceusage.v1.Service\"\x92\x02\n\x15\x44isableServiceRequest\x12\x0c\n\x04name\x18\x01 \x01(\t\x12\"\n\x1a\x64isable_dependent_services\x18\x02 \x01(\x08\x12l\n\x1a\x63heck_if_service_has_usage\x18\x03 \x01(\x0e\x32H.google.api.serviceusage.v1.DisableServiceRequest.CheckIfServiceHasUsage\"Y\n\x16\x43heckIfServiceHasUsage\x12*\n&CHECK_IF_SERVICE_HAS_USAGE_UNSPECIFIED\x10\x00\x12\x08\n\x04SKIP\x10\x01\x12\t\n\x05\x43HECK\x10\x02\"N\n\x16\x44isableServiceResponse\x12\x34\n\x07service\x18\x01 \x01(\x0b\x32#.google.api.serviceusage.v1.Service\"!\n\x11GetServiceRequest\x12\x0c\n\x04name\x18\x01 \x01(\t\"\\\n\x13ListServicesRequest\x12\x0e\n\x06parent\x18\x01 \x01(\t\x12\x11\n\tpage_size\x18\x02 \x01(\x05\x12\x12\n\npage_token\x18\x03 \x01(\t\x12\x0e\n\x06\x66ilter\x18\x04 \x01(\t\"f\n\x14ListServicesResponse\x12\x35\n\x08services\x18\x01 \x03(\x0b\x32#.google.api.serviceusage.v1.Service\x12\x17\n\x0fnext_page_token\x18\x02 \x01(\t\"A\n\x1a\x42\x61tchEnableServicesRequest\x12\x0e\n\x06parent\x18\x01 \x01(\t\x12\x13\n\x0bservice_ids\x18\x02 \x03(\t\"\xe9\x01\n\x1b\x42\x61tchEnableServicesResponse\x12\x35\n\x08services\x18\x01 \x03(\x0b\x32#.google.api.serviceusage.v1.Service\x12W\n\x08\x66\x61ilures\x18\x02 \x03(\x0b\x32\x45.google.api.serviceusage.v1.BatchEnableServicesResponse.EnableFailure\x1a:\n\rEnableFailure\x12\x12\n\nservice_id\x18\x01 \x01(\t\x12\x15\n\rerror_message\x18\x02 \x01(\t\"8\n\x17\x42\x61tchGetServicesRequest\x12\x0e\n\x06parent\x18\x01 \x01(\t\x12\r\n\x05names\x18\x02 \x03(\t\"Q\n\x18\x42\x61tchGetServicesResponse\x12\x35\n\x08services\x18\x01 \x03(\x0b\x32#.google.api.serviceusage.v1.Service2\xe8\t\n\x0cServiceUsage\x12\xba\x01\n\rEnableService\x12\x30.google.api.serviceusage.v1.EnableServiceRequest\x1a\x1d.google.longrunning.Operation\"X\x82\xd3\xe4\x93\x02%\" /v1/{name=*/*/services/*}:enable:\x01*\xca\x41*\n\x15\x45nableServiceResponse\x12\x11OperationMetadata\x12\xbe\x01\n\x0e\x44isableService\x12\x31.google.api.serviceusage.v1.DisableServiceRequest\x1a\x1d.google.longrunning.Operation\"Z\x82\xd3\xe4\x93\x02&\"!/v1/{name=*/*/services/*}:disable:\x01*\xca\x41+\n\x16\x44isableServiceResponse\x12\x11OperationMetadata\x12\x83\x01\n\nGetService\x12-.google.api.serviceusage.v1.GetServiceRequest\x1a#.google.api.serviceusage.v1.Service\"!\x82\xd3\xe4\x93\x02\x1b\x12\x19/v1/{name=*/*/services/*}\x12\x94\x01\n\x0cListServices\x12/.google.api.serviceusage.v1.ListServicesRequest\x1a\x30.google.api.serviceusage.v1.ListServicesResponse\"!\x82\xd3\xe4\x93\x02\x1b\x12\x19/v1/{parent=*/*}/services\x12\xd1\x01\n\x13\x42\x61tchEnableServices\x12\x36.google.api.serviceusage.v1.BatchEnableServicesRequest\x1a\x1d.google.longrunning.Operation\"c\x82\xd3\xe4\x93\x02*\"%/v1/{parent=*/*}/services:batchEnable:\x01*\xca\x41\x30\n\x1b\x42\x61tchEnableServicesResponse\x12\x11OperationMetadata\x12\xa9\x01\n\x10\x42\x61tchGetServices\x12\x33.google.api.serviceusage.v1.BatchGetServicesRequest\x1a\x34.google.api.serviceusage.v1.BatchGetServicesResponse\"*\x82\xd3\xe4\x93\x02$\x12\"/v1/{parent=*/*}/services:batchGet\x1a\xbc\x01\xca\x41\x1bserviceusage.googleapis.com\xd2\x41\x9a\x01https://www.googleapis.com/auth/cloud-platform,https://www.googleapis.com/auth/cloud-platform.read-only,https://www.googleapis.com/auth/service.managementB\xdb\x01\n\x1e\x63om.google.api.serviceusage.v1B\x11ServiceUsageProtoP\x01ZDcloud.google.com/go/serviceusage/apiv1/serviceusagepb;serviceusagepb\xaa\x02\x1cGoogle.Cloud.ServiceUsage.V1\xca\x02\x1cGoogle\\Cloud\\ServiceUsage\\V1\xea\x02\x1fGoogle::Cloud::ServiceUsage::V1b\x06proto3" pool = Google::Protobuf::DescriptorPool.generated_pool diff --git a/google-cloud-service_usage-v1/lib/google/cloud/service_usage/v1.rb b/google-cloud-service_usage-v1/lib/google/cloud/service_usage/v1.rb index f0e1e236e574..14a4c4440db1 100644 --- a/google-cloud-service_usage-v1/lib/google/cloud/service_usage/v1.rb +++ b/google-cloud-service_usage-v1/lib/google/cloud/service_usage/v1.rb @@ -30,6 +30,11 @@ module ServiceUsage # require "google/cloud/service_usage/v1" # client = ::Google::Cloud::ServiceUsage::V1::ServiceUsage::Client.new # + # @example Load this package, including all its services, and instantiate a REST client + # + # require "google/cloud/service_usage/v1" + # client = ::Google::Cloud::ServiceUsage::V1::ServiceUsage::Rest::Client.new + # module V1 end end diff --git a/google-cloud-service_usage-v1/lib/google/cloud/service_usage/v1/rest.rb b/google-cloud-service_usage-v1/lib/google/cloud/service_usage/v1/rest.rb new file mode 100644 index 000000000000..4c8dfae9efcf --- /dev/null +++ b/google-cloud-service_usage-v1/lib/google/cloud/service_usage/v1/rest.rb @@ -0,0 +1,37 @@ +# frozen_string_literal: true + +# Copyright 2023 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. + +# Auto-generated by gapic-generator-ruby. DO NOT EDIT! + +require "google/cloud/service_usage/v1/service_usage/rest" +require "google/cloud/service_usage/v1/version" + +module Google + module Cloud + module ServiceUsage + ## + # To load just the REST part of this package, including all its services, and instantiate a REST client: + # + # @example + # + # require "google/cloud/service_usage/v1/rest" + # client = ::Google::Cloud::ServiceUsage::V1::ServiceUsage::Rest::Client.new + # + module V1 + end + end + end +end diff --git a/google-cloud-service_usage-v1/lib/google/cloud/service_usage/v1/service_usage.rb b/google-cloud-service_usage-v1/lib/google/cloud/service_usage/v1/service_usage.rb index 9098c39cef78..8c56b02b003b 100644 --- a/google-cloud-service_usage-v1/lib/google/cloud/service_usage/v1/service_usage.rb +++ b/google-cloud-service_usage-v1/lib/google/cloud/service_usage/v1/service_usage.rb @@ -25,6 +25,7 @@ require "google/cloud/service_usage/v1/service_usage/credentials" require "google/cloud/service_usage/v1/service_usage/operations" require "google/cloud/service_usage/v1/service_usage/client" +require "google/cloud/service_usage/v1/service_usage/rest" module Google module Cloud @@ -42,6 +43,11 @@ module V1 # require "google/cloud/service_usage/v1/service_usage" # client = ::Google::Cloud::ServiceUsage::V1::ServiceUsage::Client.new # + # @example Load this service and instantiate a REST client + # + # require "google/cloud/service_usage/v1/service_usage/rest" + # client = ::Google::Cloud::ServiceUsage::V1::ServiceUsage::Rest::Client.new + # module ServiceUsage end end diff --git a/google-cloud-service_usage-v1/lib/google/cloud/service_usage/v1/service_usage/rest.rb b/google-cloud-service_usage-v1/lib/google/cloud/service_usage/v1/service_usage/rest.rb new file mode 100644 index 000000000000..edfc98fd1a0c --- /dev/null +++ b/google-cloud-service_usage-v1/lib/google/cloud/service_usage/v1/service_usage/rest.rb @@ -0,0 +1,56 @@ +# frozen_string_literal: true + +# Copyright 2023 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. + +# Auto-generated by gapic-generator-ruby. DO NOT EDIT! + +require "gapic/rest" +require "gapic/config" +require "gapic/config/method" + +require "google/cloud/service_usage/v1/version" + +require "google/cloud/service_usage/v1/service_usage/credentials" +require "google/cloud/service_usage/v1/service_usage/rest/operations" +require "google/cloud/service_usage/v1/service_usage/rest/client" + +module Google + module Cloud + module ServiceUsage + module V1 + ## + # Enables services that service consumers want to use on Google Cloud Platform, + # lists the available or enabled services, or disables services that service + # consumers no longer use. + # + # See [Service Usage API](https://cloud.google.com/service-usage/docs/overview) + # + # To load this service and instantiate a REST client: + # + # require "google/cloud/service_usage/v1/service_usage/rest" + # client = ::Google::Cloud::ServiceUsage::V1::ServiceUsage::Rest::Client.new + # + module ServiceUsage + # Client for the REST transport + module Rest + end + end + end + end + end +end + +helper_path = ::File.join __dir__, "rest", "helpers.rb" +require "google/cloud/service_usage/v1/service_usage/rest/helpers" if ::File.file? helper_path diff --git a/google-cloud-service_usage-v1/lib/google/cloud/service_usage/v1/service_usage/rest/client.rb b/google-cloud-service_usage-v1/lib/google/cloud/service_usage/v1/service_usage/rest/client.rb new file mode 100644 index 000000000000..8eea3ac18373 --- /dev/null +++ b/google-cloud-service_usage-v1/lib/google/cloud/service_usage/v1/service_usage/rest/client.rb @@ -0,0 +1,923 @@ +# frozen_string_literal: true + +# Copyright 2023 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. + +# Auto-generated by gapic-generator-ruby. DO NOT EDIT! + +require "google/cloud/errors" +require "google/api/serviceusage/v1/serviceusage_pb" +require "google/cloud/service_usage/v1/service_usage/rest/service_stub" + +module Google + module Cloud + module ServiceUsage + module V1 + module ServiceUsage + module Rest + ## + # REST client for the ServiceUsage service. + # + # Enables services that service consumers want to use on Google Cloud Platform, + # lists the available or enabled services, or disables services that service + # consumers no longer use. + # + # See [Service Usage API](https://cloud.google.com/service-usage/docs/overview) + # + class Client + # @private + attr_reader :service_usage_stub + + ## + # Configure the ServiceUsage Client class. + # + # See {::Google::Cloud::ServiceUsage::V1::ServiceUsage::Rest::Client::Configuration} + # for a description of the configuration fields. + # + # @example + # + # # Modify the configuration for all ServiceUsage clients + # ::Google::Cloud::ServiceUsage::V1::ServiceUsage::Rest::Client.configure do |config| + # config.timeout = 10.0 + # end + # + # @yield [config] Configure the Client client. + # @yieldparam config [Client::Configuration] + # + # @return [Client::Configuration] + # + def self.configure + @configure ||= begin + namespace = ["Google", "Cloud", "ServiceUsage", "V1"] + parent_config = while namespace.any? + parent_name = namespace.join "::" + parent_const = const_get parent_name + break parent_const.configure if parent_const.respond_to? :configure + namespace.pop + end + default_config = Client::Configuration.new parent_config + + default_config.timeout = 60.0 + + default_config + end + yield @configure if block_given? + @configure + end + + ## + # Configure the ServiceUsage Client instance. + # + # The configuration is set to the derived mode, meaning that values can be changed, + # but structural changes (adding new fields, etc.) are not allowed. Structural changes + # should be made on {Client.configure}. + # + # See {::Google::Cloud::ServiceUsage::V1::ServiceUsage::Rest::Client::Configuration} + # for a description of the configuration fields. + # + # @yield [config] Configure the Client client. + # @yieldparam config [Client::Configuration] + # + # @return [Client::Configuration] + # + def configure + yield @config if block_given? + @config + end + + ## + # Create a new ServiceUsage REST client object. + # + # @example + # + # # Create a client using the default configuration + # client = ::Google::Cloud::ServiceUsage::V1::ServiceUsage::Rest::Client.new + # + # # Create a client using a custom configuration + # client = ::Google::Cloud::ServiceUsage::V1::ServiceUsage::Rest::Client.new do |config| + # config.timeout = 10.0 + # end + # + # @yield [config] Configure the ServiceUsage client. + # @yieldparam config [Client::Configuration] + # + def initialize + # Create the configuration object + @config = Configuration.new Client.configure + + # Yield the configuration if needed + yield @config if block_given? + + # Create credentials + credentials = @config.credentials + # Use self-signed JWT if the endpoint is unchanged from default, + # but only if the default endpoint does not have a region prefix. + enable_self_signed_jwt = @config.endpoint == Configuration::DEFAULT_ENDPOINT && + !@config.endpoint.split(".").first.include?("-") + credentials ||= Credentials.default scope: @config.scope, + enable_self_signed_jwt: enable_self_signed_jwt + if credentials.is_a?(::String) || credentials.is_a?(::Hash) + credentials = Credentials.new credentials, scope: @config.scope + end + + @quota_project_id = @config.quota_project + @quota_project_id ||= credentials.quota_project_id if credentials.respond_to? :quota_project_id + + @operations_client = ::Google::Cloud::ServiceUsage::V1::ServiceUsage::Rest::Operations.new do |config| + config.credentials = credentials + config.quota_project = @quota_project_id + config.endpoint = @config.endpoint + end + + @service_usage_stub = ::Google::Cloud::ServiceUsage::V1::ServiceUsage::Rest::ServiceStub.new endpoint: @config.endpoint, credentials: credentials + end + + ## + # Get the associated client for long-running operations. + # + # @return [::Google::Cloud::ServiceUsage::V1::ServiceUsage::Rest::Operations] + # + attr_reader :operations_client + + # Service calls + + ## + # Enable a service so that it can be used with a project. + # + # @overload enable_service(request, options = nil) + # Pass arguments to `enable_service` via a request object, either of type + # {::Google::Cloud::ServiceUsage::V1::EnableServiceRequest} or an equivalent Hash. + # + # @param request [::Google::Cloud::ServiceUsage::V1::EnableServiceRequest, ::Hash] + # A request object representing the call parameters. Required. To specify no + # parameters, or to keep all the default parameter values, pass an empty Hash. + # @param options [::Gapic::CallOptions, ::Hash] + # Overrides the default settings for this call, e.g, timeout, retries etc. Optional. + # + # @overload enable_service(name: nil) + # Pass arguments to `enable_service` via keyword arguments. Note that at + # least one keyword argument is required. To specify no parameters, or to keep all + # the default parameter values, pass an empty Hash as a request object (see above). + # + # @param name [::String] + # Name of the consumer and service to enable the service on. + # + # The `EnableService` and `DisableService` methods currently only support + # projects. + # + # Enabling a service requires that the service is public or is shared with + # the user enabling the service. + # + # An example name would be: + # `projects/123/services/serviceusage.googleapis.com` where `123` is the + # project number. + # @yield [result, operation] Access the result along with the TransportOperation object + # @yieldparam result [::Gapic::Operation] + # @yieldparam operation [::Gapic::Rest::TransportOperation] + # + # @return [::Gapic::Operation] + # + # @raise [::Google::Cloud::Error] if the REST call is aborted. + # + # @example Basic example + # require "google/cloud/service_usage/v1" + # + # # Create a client object. The client can be reused for multiple calls. + # client = Google::Cloud::ServiceUsage::V1::ServiceUsage::Rest::Client.new + # + # # Create a request. To set request fields, pass in keyword arguments. + # request = Google::Cloud::ServiceUsage::V1::EnableServiceRequest.new + # + # # Call the enable_service method. + # result = client.enable_service request + # + # # The returned object is of type Gapic::Operation. You can use it to + # # check the status of an operation, cancel it, or wait for results. + # # Here is how to wait for a response. + # result.wait_until_done! timeout: 60 + # if result.response? + # p result.response + # else + # puts "No response received." + # end + # + def enable_service request, options = nil + raise ::ArgumentError, "request must be provided" if request.nil? + + request = ::Gapic::Protobuf.coerce request, to: ::Google::Cloud::ServiceUsage::V1::EnableServiceRequest + + # Converts hash and nil to an options object + options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h + + # Customize the options with defaults + call_metadata = @config.rpcs.enable_service.metadata.to_h + + # Set x-goog-api-client and x-goog-user-project headers + call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ + lib_name: @config.lib_name, lib_version: @config.lib_version, + gapic_version: ::Google::Cloud::ServiceUsage::V1::VERSION, + transports_version_send: [:rest] + + call_metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + + options.apply_defaults timeout: @config.rpcs.enable_service.timeout, + metadata: call_metadata, + retry_policy: @config.rpcs.enable_service.retry_policy + + options.apply_defaults timeout: @config.timeout, + metadata: @config.metadata, + retry_policy: @config.retry_policy + + @service_usage_stub.enable_service request, options do |result, operation| + result = ::Gapic::Operation.new result, @operations_client, options: options + yield result, operation if block_given? + return result + end + rescue ::Gapic::Rest::Error => e + raise ::Google::Cloud::Error.from_error(e) + end + + ## + # Disable a service so that it can no longer be used with a project. + # This prevents unintended usage that may cause unexpected billing + # charges or security leaks. + # + # It is not valid to call the disable method on a service that is not + # currently enabled. Callers will receive a `FAILED_PRECONDITION` status if + # the target service is not currently enabled. + # + # @overload disable_service(request, options = nil) + # Pass arguments to `disable_service` via a request object, either of type + # {::Google::Cloud::ServiceUsage::V1::DisableServiceRequest} or an equivalent Hash. + # + # @param request [::Google::Cloud::ServiceUsage::V1::DisableServiceRequest, ::Hash] + # A request object representing the call parameters. Required. To specify no + # parameters, or to keep all the default parameter values, pass an empty Hash. + # @param options [::Gapic::CallOptions, ::Hash] + # Overrides the default settings for this call, e.g, timeout, retries etc. Optional. + # + # @overload disable_service(name: nil, disable_dependent_services: nil, check_if_service_has_usage: nil) + # Pass arguments to `disable_service` via keyword arguments. Note that at + # least one keyword argument is required. To specify no parameters, or to keep all + # the default parameter values, pass an empty Hash as a request object (see above). + # + # @param name [::String] + # Name of the consumer and service to disable the service on. + # + # The enable and disable methods currently only support projects. + # + # An example name would be: + # `projects/123/services/serviceusage.googleapis.com` where `123` is the + # project number. + # @param disable_dependent_services [::Boolean] + # Indicates if services that are enabled and which depend on this service + # should also be disabled. If not set, an error will be generated if any + # enabled services depend on the service to be disabled. When set, the + # service, and any enabled services that depend on it, will be disabled + # together. + # @param check_if_service_has_usage [::Google::Cloud::ServiceUsage::V1::DisableServiceRequest::CheckIfServiceHasUsage] + # Defines the behavior for checking service usage when disabling a service. + # @yield [result, operation] Access the result along with the TransportOperation object + # @yieldparam result [::Gapic::Operation] + # @yieldparam operation [::Gapic::Rest::TransportOperation] + # + # @return [::Gapic::Operation] + # + # @raise [::Google::Cloud::Error] if the REST call is aborted. + # + # @example Basic example + # require "google/cloud/service_usage/v1" + # + # # Create a client object. The client can be reused for multiple calls. + # client = Google::Cloud::ServiceUsage::V1::ServiceUsage::Rest::Client.new + # + # # Create a request. To set request fields, pass in keyword arguments. + # request = Google::Cloud::ServiceUsage::V1::DisableServiceRequest.new + # + # # Call the disable_service method. + # result = client.disable_service request + # + # # The returned object is of type Gapic::Operation. You can use it to + # # check the status of an operation, cancel it, or wait for results. + # # Here is how to wait for a response. + # result.wait_until_done! timeout: 60 + # if result.response? + # p result.response + # else + # puts "No response received." + # end + # + def disable_service request, options = nil + raise ::ArgumentError, "request must be provided" if request.nil? + + request = ::Gapic::Protobuf.coerce request, to: ::Google::Cloud::ServiceUsage::V1::DisableServiceRequest + + # Converts hash and nil to an options object + options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h + + # Customize the options with defaults + call_metadata = @config.rpcs.disable_service.metadata.to_h + + # Set x-goog-api-client and x-goog-user-project headers + call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ + lib_name: @config.lib_name, lib_version: @config.lib_version, + gapic_version: ::Google::Cloud::ServiceUsage::V1::VERSION, + transports_version_send: [:rest] + + call_metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + + options.apply_defaults timeout: @config.rpcs.disable_service.timeout, + metadata: call_metadata, + retry_policy: @config.rpcs.disable_service.retry_policy + + options.apply_defaults timeout: @config.timeout, + metadata: @config.metadata, + retry_policy: @config.retry_policy + + @service_usage_stub.disable_service request, options do |result, operation| + result = ::Gapic::Operation.new result, @operations_client, options: options + yield result, operation if block_given? + return result + end + rescue ::Gapic::Rest::Error => e + raise ::Google::Cloud::Error.from_error(e) + end + + ## + # Returns the service configuration and enabled state for a given service. + # + # @overload get_service(request, options = nil) + # Pass arguments to `get_service` via a request object, either of type + # {::Google::Cloud::ServiceUsage::V1::GetServiceRequest} or an equivalent Hash. + # + # @param request [::Google::Cloud::ServiceUsage::V1::GetServiceRequest, ::Hash] + # A request object representing the call parameters. Required. To specify no + # parameters, or to keep all the default parameter values, pass an empty Hash. + # @param options [::Gapic::CallOptions, ::Hash] + # Overrides the default settings for this call, e.g, timeout, retries etc. Optional. + # + # @overload get_service(name: nil) + # Pass arguments to `get_service` via keyword arguments. Note that at + # least one keyword argument is required. To specify no parameters, or to keep all + # the default parameter values, pass an empty Hash as a request object (see above). + # + # @param name [::String] + # Name of the consumer and service to get the `ConsumerState` for. + # + # An example name would be: + # `projects/123/services/serviceusage.googleapis.com` where `123` is the + # project number. + # @yield [result, operation] Access the result along with the TransportOperation object + # @yieldparam result [::Google::Cloud::ServiceUsage::V1::Service] + # @yieldparam operation [::Gapic::Rest::TransportOperation] + # + # @return [::Google::Cloud::ServiceUsage::V1::Service] + # + # @raise [::Google::Cloud::Error] if the REST call is aborted. + # + # @example Basic example + # require "google/cloud/service_usage/v1" + # + # # Create a client object. The client can be reused for multiple calls. + # client = Google::Cloud::ServiceUsage::V1::ServiceUsage::Rest::Client.new + # + # # Create a request. To set request fields, pass in keyword arguments. + # request = Google::Cloud::ServiceUsage::V1::GetServiceRequest.new + # + # # Call the get_service method. + # result = client.get_service request + # + # # The returned object is of type Google::Cloud::ServiceUsage::V1::Service. + # p result + # + def get_service request, options = nil + raise ::ArgumentError, "request must be provided" if request.nil? + + request = ::Gapic::Protobuf.coerce request, to: ::Google::Cloud::ServiceUsage::V1::GetServiceRequest + + # Converts hash and nil to an options object + options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h + + # Customize the options with defaults + call_metadata = @config.rpcs.get_service.metadata.to_h + + # Set x-goog-api-client and x-goog-user-project headers + call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ + lib_name: @config.lib_name, lib_version: @config.lib_version, + gapic_version: ::Google::Cloud::ServiceUsage::V1::VERSION, + transports_version_send: [:rest] + + call_metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + + options.apply_defaults timeout: @config.rpcs.get_service.timeout, + metadata: call_metadata, + retry_policy: @config.rpcs.get_service.retry_policy + + options.apply_defaults timeout: @config.timeout, + metadata: @config.metadata, + retry_policy: @config.retry_policy + + @service_usage_stub.get_service request, options do |result, operation| + yield result, operation if block_given? + return result + end + rescue ::Gapic::Rest::Error => e + raise ::Google::Cloud::Error.from_error(e) + end + + ## + # List all services available to the specified project, and the current + # state of those services with respect to the project. The list includes + # all public services, all services for which the calling user has the + # `servicemanagement.services.bind` permission, and all services that have + # already been enabled on the project. The list can be filtered to + # only include services in a specific state, for example to only include + # services enabled on the project. + # + # WARNING: If you need to query enabled services frequently or across + # an organization, you should use + # [Cloud Asset Inventory + # API](https://cloud.google.com/asset-inventory/docs/apis), which provides + # higher throughput and richer filtering capability. + # + # @overload list_services(request, options = nil) + # Pass arguments to `list_services` via a request object, either of type + # {::Google::Cloud::ServiceUsage::V1::ListServicesRequest} or an equivalent Hash. + # + # @param request [::Google::Cloud::ServiceUsage::V1::ListServicesRequest, ::Hash] + # A request object representing the call parameters. Required. To specify no + # parameters, or to keep all the default parameter values, pass an empty Hash. + # @param options [::Gapic::CallOptions, ::Hash] + # Overrides the default settings for this call, e.g, timeout, retries etc. Optional. + # + # @overload list_services(parent: nil, page_size: nil, page_token: nil, filter: nil) + # Pass arguments to `list_services` via keyword arguments. Note that at + # least one keyword argument is required. To specify no parameters, or to keep all + # the default parameter values, pass an empty Hash as a request object (see above). + # + # @param parent [::String] + # Parent to search for services on. + # + # An example name would be: + # `projects/123` where `123` is the project number. + # @param page_size [::Integer] + # Requested size of the next page of data. + # Requested page size cannot exceed 200. + # If not set, the default page size is 50. + # @param page_token [::String] + # Token identifying which result to start with, which is returned by a + # previous list call. + # @param filter [::String] + # Only list services that conform to the given filter. + # The allowed filter strings are `state:ENABLED` and `state:DISABLED`. + # @yield [result, operation] Access the result along with the TransportOperation object + # @yieldparam result [::Gapic::Rest::PagedEnumerable<::Google::Cloud::ServiceUsage::V1::Service>] + # @yieldparam operation [::Gapic::Rest::TransportOperation] + # + # @return [::Gapic::Rest::PagedEnumerable<::Google::Cloud::ServiceUsage::V1::Service>] + # + # @raise [::Google::Cloud::Error] if the REST call is aborted. + # + # @example Basic example + # require "google/cloud/service_usage/v1" + # + # # Create a client object. The client can be reused for multiple calls. + # client = Google::Cloud::ServiceUsage::V1::ServiceUsage::Rest::Client.new + # + # # Create a request. To set request fields, pass in keyword arguments. + # request = Google::Cloud::ServiceUsage::V1::ListServicesRequest.new + # + # # Call the list_services method. + # result = client.list_services request + # + # # The returned object is of type Gapic::PagedEnumerable. You can iterate + # # over elements, and API calls will be issued to fetch pages as needed. + # result.each do |item| + # # Each element is of type ::Google::Cloud::ServiceUsage::V1::Service. + # p item + # end + # + def list_services request, options = nil + raise ::ArgumentError, "request must be provided" if request.nil? + + request = ::Gapic::Protobuf.coerce request, to: ::Google::Cloud::ServiceUsage::V1::ListServicesRequest + + # Converts hash and nil to an options object + options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h + + # Customize the options with defaults + call_metadata = @config.rpcs.list_services.metadata.to_h + + # Set x-goog-api-client and x-goog-user-project headers + call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ + lib_name: @config.lib_name, lib_version: @config.lib_version, + gapic_version: ::Google::Cloud::ServiceUsage::V1::VERSION, + transports_version_send: [:rest] + + call_metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + + options.apply_defaults timeout: @config.rpcs.list_services.timeout, + metadata: call_metadata, + retry_policy: @config.rpcs.list_services.retry_policy + + options.apply_defaults timeout: @config.timeout, + metadata: @config.metadata, + retry_policy: @config.retry_policy + + @service_usage_stub.list_services request, options do |result, operation| + result = ::Gapic::Rest::PagedEnumerable.new @service_usage_stub, :list_services, "services", request, result, options + yield result, operation if block_given? + return result + end + rescue ::Gapic::Rest::Error => e + raise ::Google::Cloud::Error.from_error(e) + end + + ## + # Enable multiple services on a project. The operation is atomic: if enabling + # any service fails, then the entire batch fails, and no state changes occur. + # To enable a single service, use the `EnableService` method instead. + # + # @overload batch_enable_services(request, options = nil) + # Pass arguments to `batch_enable_services` via a request object, either of type + # {::Google::Cloud::ServiceUsage::V1::BatchEnableServicesRequest} or an equivalent Hash. + # + # @param request [::Google::Cloud::ServiceUsage::V1::BatchEnableServicesRequest, ::Hash] + # A request object representing the call parameters. Required. To specify no + # parameters, or to keep all the default parameter values, pass an empty Hash. + # @param options [::Gapic::CallOptions, ::Hash] + # Overrides the default settings for this call, e.g, timeout, retries etc. Optional. + # + # @overload batch_enable_services(parent: nil, service_ids: nil) + # Pass arguments to `batch_enable_services` via keyword arguments. Note that at + # least one keyword argument is required. To specify no parameters, or to keep all + # the default parameter values, pass an empty Hash as a request object (see above). + # + # @param parent [::String] + # Parent to enable services on. + # + # An example name would be: + # `projects/123` where `123` is the project number. + # + # The `BatchEnableServices` method currently only supports projects. + # @param service_ids [::Array<::String>] + # The identifiers of the services to enable on the project. + # + # A valid identifier would be: + # serviceusage.googleapis.com + # + # Enabling services requires that each service is public or is shared with + # the user enabling the service. + # + # A single request can enable a maximum of 20 services at a time. If more + # than 20 services are specified, the request will fail, and no state changes + # will occur. + # @yield [result, operation] Access the result along with the TransportOperation object + # @yieldparam result [::Gapic::Operation] + # @yieldparam operation [::Gapic::Rest::TransportOperation] + # + # @return [::Gapic::Operation] + # + # @raise [::Google::Cloud::Error] if the REST call is aborted. + # + # @example Basic example + # require "google/cloud/service_usage/v1" + # + # # Create a client object. The client can be reused for multiple calls. + # client = Google::Cloud::ServiceUsage::V1::ServiceUsage::Rest::Client.new + # + # # Create a request. To set request fields, pass in keyword arguments. + # request = Google::Cloud::ServiceUsage::V1::BatchEnableServicesRequest.new + # + # # Call the batch_enable_services method. + # result = client.batch_enable_services request + # + # # The returned object is of type Gapic::Operation. You can use it to + # # check the status of an operation, cancel it, or wait for results. + # # Here is how to wait for a response. + # result.wait_until_done! timeout: 60 + # if result.response? + # p result.response + # else + # puts "No response received." + # end + # + def batch_enable_services request, options = nil + raise ::ArgumentError, "request must be provided" if request.nil? + + request = ::Gapic::Protobuf.coerce request, to: ::Google::Cloud::ServiceUsage::V1::BatchEnableServicesRequest + + # Converts hash and nil to an options object + options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h + + # Customize the options with defaults + call_metadata = @config.rpcs.batch_enable_services.metadata.to_h + + # Set x-goog-api-client and x-goog-user-project headers + call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ + lib_name: @config.lib_name, lib_version: @config.lib_version, + gapic_version: ::Google::Cloud::ServiceUsage::V1::VERSION, + transports_version_send: [:rest] + + call_metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + + options.apply_defaults timeout: @config.rpcs.batch_enable_services.timeout, + metadata: call_metadata, + retry_policy: @config.rpcs.batch_enable_services.retry_policy + + options.apply_defaults timeout: @config.timeout, + metadata: @config.metadata, + retry_policy: @config.retry_policy + + @service_usage_stub.batch_enable_services request, options do |result, operation| + result = ::Gapic::Operation.new result, @operations_client, options: options + yield result, operation if block_given? + return result + end + rescue ::Gapic::Rest::Error => e + raise ::Google::Cloud::Error.from_error(e) + end + + ## + # Returns the service configurations and enabled states for a given list of + # services. + # + # @overload batch_get_services(request, options = nil) + # Pass arguments to `batch_get_services` via a request object, either of type + # {::Google::Cloud::ServiceUsage::V1::BatchGetServicesRequest} or an equivalent Hash. + # + # @param request [::Google::Cloud::ServiceUsage::V1::BatchGetServicesRequest, ::Hash] + # A request object representing the call parameters. Required. To specify no + # parameters, or to keep all the default parameter values, pass an empty Hash. + # @param options [::Gapic::CallOptions, ::Hash] + # Overrides the default settings for this call, e.g, timeout, retries etc. Optional. + # + # @overload batch_get_services(parent: nil, names: nil) + # Pass arguments to `batch_get_services` via keyword arguments. Note that at + # least one keyword argument is required. To specify no parameters, or to keep all + # the default parameter values, pass an empty Hash as a request object (see above). + # + # @param parent [::String] + # Parent to retrieve services from. + # If this is set, the parent of all of the services specified in `names` must + # match this field. An example name would be: `projects/123` where `123` is + # the project number. The `BatchGetServices` method currently only supports + # projects. + # @param names [::Array<::String>] + # Names of the services to retrieve. + # + # An example name would be: + # `projects/123/services/serviceusage.googleapis.com` where `123` is the + # project number. + # A single request can get a maximum of 30 services at a time. + # @yield [result, operation] Access the result along with the TransportOperation object + # @yieldparam result [::Google::Cloud::ServiceUsage::V1::BatchGetServicesResponse] + # @yieldparam operation [::Gapic::Rest::TransportOperation] + # + # @return [::Google::Cloud::ServiceUsage::V1::BatchGetServicesResponse] + # + # @raise [::Google::Cloud::Error] if the REST call is aborted. + # + # @example Basic example + # require "google/cloud/service_usage/v1" + # + # # Create a client object. The client can be reused for multiple calls. + # client = Google::Cloud::ServiceUsage::V1::ServiceUsage::Rest::Client.new + # + # # Create a request. To set request fields, pass in keyword arguments. + # request = Google::Cloud::ServiceUsage::V1::BatchGetServicesRequest.new + # + # # Call the batch_get_services method. + # result = client.batch_get_services request + # + # # The returned object is of type Google::Cloud::ServiceUsage::V1::BatchGetServicesResponse. + # p result + # + def batch_get_services request, options = nil + raise ::ArgumentError, "request must be provided" if request.nil? + + request = ::Gapic::Protobuf.coerce request, to: ::Google::Cloud::ServiceUsage::V1::BatchGetServicesRequest + + # Converts hash and nil to an options object + options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h + + # Customize the options with defaults + call_metadata = @config.rpcs.batch_get_services.metadata.to_h + + # Set x-goog-api-client and x-goog-user-project headers + call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ + lib_name: @config.lib_name, lib_version: @config.lib_version, + gapic_version: ::Google::Cloud::ServiceUsage::V1::VERSION, + transports_version_send: [:rest] + + call_metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + + options.apply_defaults timeout: @config.rpcs.batch_get_services.timeout, + metadata: call_metadata, + retry_policy: @config.rpcs.batch_get_services.retry_policy + + options.apply_defaults timeout: @config.timeout, + metadata: @config.metadata, + retry_policy: @config.retry_policy + + @service_usage_stub.batch_get_services request, options do |result, operation| + yield result, operation if block_given? + return result + end + rescue ::Gapic::Rest::Error => e + raise ::Google::Cloud::Error.from_error(e) + end + + ## + # Configuration class for the ServiceUsage REST API. + # + # This class represents the configuration for ServiceUsage REST, + # providing control over timeouts, retry behavior, logging, transport + # parameters, and other low-level controls. Certain parameters can also be + # applied individually to specific RPCs. See + # {::Google::Cloud::ServiceUsage::V1::ServiceUsage::Rest::Client::Configuration::Rpcs} + # for a list of RPCs that can be configured independently. + # + # Configuration can be applied globally to all clients, or to a single client + # on construction. + # + # @example + # + # # Modify the global config, setting the timeout for + # # enable_service to 20 seconds, + # # and all remaining timeouts to 10 seconds. + # ::Google::Cloud::ServiceUsage::V1::ServiceUsage::Rest::Client.configure do |config| + # config.timeout = 10.0 + # config.rpcs.enable_service.timeout = 20.0 + # end + # + # # Apply the above configuration only to a new client. + # client = ::Google::Cloud::ServiceUsage::V1::ServiceUsage::Rest::Client.new do |config| + # config.timeout = 10.0 + # config.rpcs.enable_service.timeout = 20.0 + # end + # + # @!attribute [rw] endpoint + # The hostname or hostname:port of the service endpoint. + # Defaults to `"serviceusage.googleapis.com"`. + # @return [::String] + # @!attribute [rw] credentials + # Credentials to send with calls. You may provide any of the following types: + # * (`String`) The path to a service account key file in JSON format + # * (`Hash`) A service account key as a Hash + # * (`Google::Auth::Credentials`) A googleauth credentials object + # (see the [googleauth docs](https://rubydoc.info/gems/googleauth/Google/Auth/Credentials)) + # * (`Signet::OAuth2::Client`) A signet oauth2 client object + # (see the [signet docs](https://rubydoc.info/gems/signet/Signet/OAuth2/Client)) + # * (`nil`) indicating no credentials + # @return [::Object] + # @!attribute [rw] scope + # The OAuth scopes + # @return [::Array<::String>] + # @!attribute [rw] lib_name + # The library name as recorded in instrumentation and logging + # @return [::String] + # @!attribute [rw] lib_version + # The library version as recorded in instrumentation and logging + # @return [::String] + # @!attribute [rw] timeout + # The call timeout in seconds. + # @return [::Numeric] + # @!attribute [rw] metadata + # Additional headers to be sent with the call. + # @return [::Hash{::Symbol=>::String}] + # @!attribute [rw] retry_policy + # The retry policy. The value is a hash with the following keys: + # * `:initial_delay` (*type:* `Numeric`) - The initial delay in seconds. + # * `:max_delay` (*type:* `Numeric`) - The max delay in seconds. + # * `:multiplier` (*type:* `Numeric`) - The incremental backoff multiplier. + # * `:retry_codes` (*type:* `Array`) - The error codes that should + # trigger a retry. + # @return [::Hash] + # @!attribute [rw] quota_project + # A separate project against which to charge quota. + # @return [::String] + # + class Configuration + extend ::Gapic::Config + + DEFAULT_ENDPOINT = "serviceusage.googleapis.com" + + config_attr :endpoint, DEFAULT_ENDPOINT, ::String + config_attr :credentials, nil do |value| + allowed = [::String, ::Hash, ::Proc, ::Symbol, ::Google::Auth::Credentials, ::Signet::OAuth2::Client, nil] + allowed.any? { |klass| klass === value } + end + config_attr :scope, nil, ::String, ::Array, nil + config_attr :lib_name, nil, ::String, nil + config_attr :lib_version, nil, ::String, nil + config_attr :timeout, nil, ::Numeric, nil + config_attr :metadata, nil, ::Hash, nil + config_attr :retry_policy, nil, ::Hash, ::Proc, nil + config_attr :quota_project, nil, ::String, nil + + # @private + def initialize parent_config = nil + @parent_config = parent_config unless parent_config.nil? + + yield self if block_given? + end + + ## + # Configurations for individual RPCs + # @return [Rpcs] + # + def rpcs + @rpcs ||= begin + parent_rpcs = nil + parent_rpcs = @parent_config.rpcs if defined?(@parent_config) && @parent_config.respond_to?(:rpcs) + Rpcs.new parent_rpcs + end + end + + ## + # Configuration RPC class for the ServiceUsage API. + # + # Includes fields providing the configuration for each RPC in this service. + # Each configuration object is of type `Gapic::Config::Method` and includes + # the following configuration fields: + # + # * `timeout` (*type:* `Numeric`) - The call timeout in seconds + # * `metadata` (*type:* `Hash{Symbol=>String}`) - Additional headers + # * `retry_policy (*type:* `Hash`) - The retry policy. The policy fields + # include the following keys: + # * `:initial_delay` (*type:* `Numeric`) - The initial delay in seconds. + # * `:max_delay` (*type:* `Numeric`) - The max delay in seconds. + # * `:multiplier` (*type:* `Numeric`) - The incremental backoff multiplier. + # * `:retry_codes` (*type:* `Array`) - The error codes that should + # trigger a retry. + # + class Rpcs + ## + # RPC-specific configuration for `enable_service` + # @return [::Gapic::Config::Method] + # + attr_reader :enable_service + ## + # RPC-specific configuration for `disable_service` + # @return [::Gapic::Config::Method] + # + attr_reader :disable_service + ## + # RPC-specific configuration for `get_service` + # @return [::Gapic::Config::Method] + # + attr_reader :get_service + ## + # RPC-specific configuration for `list_services` + # @return [::Gapic::Config::Method] + # + attr_reader :list_services + ## + # RPC-specific configuration for `batch_enable_services` + # @return [::Gapic::Config::Method] + # + attr_reader :batch_enable_services + ## + # RPC-specific configuration for `batch_get_services` + # @return [::Gapic::Config::Method] + # + attr_reader :batch_get_services + + # @private + def initialize parent_rpcs = nil + enable_service_config = parent_rpcs.enable_service if parent_rpcs.respond_to? :enable_service + @enable_service = ::Gapic::Config::Method.new enable_service_config + disable_service_config = parent_rpcs.disable_service if parent_rpcs.respond_to? :disable_service + @disable_service = ::Gapic::Config::Method.new disable_service_config + get_service_config = parent_rpcs.get_service if parent_rpcs.respond_to? :get_service + @get_service = ::Gapic::Config::Method.new get_service_config + list_services_config = parent_rpcs.list_services if parent_rpcs.respond_to? :list_services + @list_services = ::Gapic::Config::Method.new list_services_config + batch_enable_services_config = parent_rpcs.batch_enable_services if parent_rpcs.respond_to? :batch_enable_services + @batch_enable_services = ::Gapic::Config::Method.new batch_enable_services_config + batch_get_services_config = parent_rpcs.batch_get_services if parent_rpcs.respond_to? :batch_get_services + @batch_get_services = ::Gapic::Config::Method.new batch_get_services_config + + yield self if block_given? + end + end + end + end + end + end + end + end + end +end diff --git a/google-cloud-service_usage-v1/lib/google/cloud/service_usage/v1/service_usage/rest/operations.rb b/google-cloud-service_usage-v1/lib/google/cloud/service_usage/v1/service_usage/rest/operations.rb new file mode 100644 index 000000000000..5869fdcc1075 --- /dev/null +++ b/google-cloud-service_usage-v1/lib/google/cloud/service_usage/v1/service_usage/rest/operations.rb @@ -0,0 +1,868 @@ +# frozen_string_literal: true + +# Copyright 2023 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. + +# Auto-generated by gapic-generator-ruby. DO NOT EDIT! + +require "gapic/operation" + +module Google + module Cloud + module ServiceUsage + module V1 + module ServiceUsage + module Rest + # Service that implements Longrunning Operations API. + class Operations + # @private + attr_reader :operations_stub + + ## + # Configuration for the ServiceUsage Operations API. + # + # @yield [config] Configure the Operations client. + # @yieldparam config [Operations::Configuration] + # + # @return [Operations::Configuration] + # + def self.configure + @configure ||= Operations::Configuration.new + yield @configure if block_given? + @configure + end + + ## + # Configure the ServiceUsage Operations instance. + # + # The configuration is set to the derived mode, meaning that values can be changed, + # but structural changes (adding new fields, etc.) are not allowed. Structural changes + # should be made on {Operations.configure}. + # + # @yield [config] Configure the Operations client. + # @yieldparam config [Operations::Configuration] + # + # @return [Operations::Configuration] + # + def configure + yield @config if block_given? + @config + end + + ## + # Create a new Operations client object. + # + # @yield [config] Configure the Client client. + # @yieldparam config [Operations::Configuration] + # + def initialize + # Create the configuration object + @config = Configuration.new Operations.configure + + # Yield the configuration if needed + yield @config if block_given? + + # Create credentials + credentials = @config.credentials + credentials ||= Credentials.default scope: @config.scope + if credentials.is_a?(::String) || credentials.is_a?(::Hash) + credentials = Credentials.new credentials, scope: @config.scope + end + + @quota_project_id = @config.quota_project + @quota_project_id ||= credentials.quota_project_id if credentials.respond_to? :quota_project_id + + @operations_stub = OperationsServiceStub.new( + endpoint: @config.endpoint, + credentials: credentials + ) + + # Used by an LRO wrapper for some methods of this service + @operations_client = self + end + + # Service calls + + ## + # Lists operations that match the specified filter in the request. If the + # server doesn't support this method, it returns `UNIMPLEMENTED`. + # + # NOTE: the `name` binding allows API services to override the binding + # to use different resource name schemes, such as `users/*/operations`. To + # override the binding, API services can add a binding such as + # `"/v1/{name=users/*}/operations"` to their service configuration. + # For backwards compatibility, the default name includes the operations + # collection id, however overriding users must ensure the name binding + # is the parent resource, without the operations collection id. + # + # @overload list_operations(request, options = nil) + # Pass arguments to `list_operations` via a request object, either of type + # {::Google::Longrunning::ListOperationsRequest} or an equivalent Hash. + # + # @param request [::Google::Longrunning::ListOperationsRequest, ::Hash] + # A request object representing the call parameters. Required. To specify no + # parameters, or to keep all the default parameter values, pass an empty Hash. + # @param options [::Gapic::CallOptions, ::Hash] + # Overrides the default settings for this call, e.g, timeout, retries etc. Optional. + # + # @overload list_operations(name: nil, filter: nil, page_size: nil, page_token: nil) + # Pass arguments to `list_operations` via keyword arguments. Note that at + # least one keyword argument is required. To specify no parameters, or to keep all + # the default parameter values, pass an empty Hash as a request object (see above). + # + # @param name [::String] + # The name of the operation's parent resource. + # @param filter [::String] + # The standard list filter. + # @param page_size [::Integer] + # The standard list page size. + # @param page_token [::String] + # The standard list page token. + # @yield [result, operation] Access the result along with the TransportOperation object + # @yieldparam result [::Gapic::Operation] + # @yieldparam operation [::Gapic::Rest::TransportOperation] + # + # @return [::Gapic::Operation] + # + # @raise [::Google::Cloud::Error] if the REST call is aborted. + # + # @example Basic example + # require "google/longrunning" + # + # # Create a client object. The client can be reused for multiple calls. + # client = Google::Longrunning::Operations::Rest::Client.new + # + # # Create a request. To set request fields, pass in keyword arguments. + # request = Google::Longrunning::ListOperationsRequest.new + # + # # Call the list_operations method. + # result = client.list_operations request + # + # # The returned object is of type Gapic::PagedEnumerable. You can iterate + # # over elements, and API calls will be issued to fetch pages as needed. + # result.each do |item| + # # Each element is of type ::Google::Longrunning::Operation. + # p item + # end + # + def list_operations request, options = nil + raise ::ArgumentError, "request must be provided" if request.nil? + + request = ::Gapic::Protobuf.coerce request, to: ::Google::Longrunning::ListOperationsRequest + + # Converts hash and nil to an options object + options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h + + # Customize the options with defaults + call_metadata = @config.rpcs.list_operations.metadata.to_h + + # Set x-goog-api-client and x-goog-user-project headers + call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ + lib_name: @config.lib_name, lib_version: @config.lib_version, + gapic_version: ::Google::Cloud::ServiceUsage::V1::VERSION, + transports_version_send: [:rest] + + call_metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + + options.apply_defaults timeout: @config.rpcs.list_operations.timeout, + metadata: call_metadata, + retry_policy: @config.rpcs.list_operations.retry_policy + + options.apply_defaults timeout: @config.timeout, + metadata: @config.metadata, + retry_policy: @config.retry_policy + + @operations_stub.list_operations request, options do |result, operation| + result = ::Gapic::Rest::PagedEnumerable.new @operations_stub, :list_operations, "operations", request, result, options + yield result, operation if block_given? + return result + end + rescue ::Gapic::Rest::Error => e + raise ::Google::Cloud::Error.from_error(e) + end + + ## + # Gets the latest state of a long-running operation. Clients can use this + # method to poll the operation result at intervals as recommended by the API + # service. + # + # @overload get_operation(request, options = nil) + # Pass arguments to `get_operation` via a request object, either of type + # {::Google::Longrunning::GetOperationRequest} or an equivalent Hash. + # + # @param request [::Google::Longrunning::GetOperationRequest, ::Hash] + # A request object representing the call parameters. Required. To specify no + # parameters, or to keep all the default parameter values, pass an empty Hash. + # @param options [::Gapic::CallOptions, ::Hash] + # Overrides the default settings for this call, e.g, timeout, retries etc. Optional. + # + # @overload get_operation(name: nil) + # Pass arguments to `get_operation` via keyword arguments. Note that at + # least one keyword argument is required. To specify no parameters, or to keep all + # the default parameter values, pass an empty Hash as a request object (see above). + # + # @param name [::String] + # The name of the operation resource. + # @yield [result, operation] Access the result along with the TransportOperation object + # @yieldparam result [::Gapic::Operation] + # @yieldparam operation [::Gapic::Rest::TransportOperation] + # + # @return [::Gapic::Operation] + # + # @raise [::Google::Cloud::Error] if the REST call is aborted. + # + # @example Basic example + # require "google/longrunning" + # + # # Create a client object. The client can be reused for multiple calls. + # client = Google::Longrunning::Operations::Rest::Client.new + # + # # Create a request. To set request fields, pass in keyword arguments. + # request = Google::Longrunning::GetOperationRequest.new + # + # # Call the get_operation method. + # result = client.get_operation request + # + # # The returned object is of type Gapic::Operation. You can use it to + # # check the status of an operation, cancel it, or wait for results. + # # Here is how to wait for a response. + # result.wait_until_done! timeout: 60 + # if result.response? + # p result.response + # else + # puts "No response received." + # end + # + def get_operation request, options = nil + raise ::ArgumentError, "request must be provided" if request.nil? + + request = ::Gapic::Protobuf.coerce request, to: ::Google::Longrunning::GetOperationRequest + + # Converts hash and nil to an options object + options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h + + # Customize the options with defaults + call_metadata = @config.rpcs.get_operation.metadata.to_h + + # Set x-goog-api-client and x-goog-user-project headers + call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ + lib_name: @config.lib_name, lib_version: @config.lib_version, + gapic_version: ::Google::Cloud::ServiceUsage::V1::VERSION, + transports_version_send: [:rest] + + call_metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + + options.apply_defaults timeout: @config.rpcs.get_operation.timeout, + metadata: call_metadata, + retry_policy: @config.rpcs.get_operation.retry_policy + + options.apply_defaults timeout: @config.timeout, + metadata: @config.metadata, + retry_policy: @config.retry_policy + + @operations_stub.get_operation request, options do |result, operation| + result = ::Gapic::Operation.new result, @operations_client, options: options + yield result, operation if block_given? + return result + end + rescue ::Gapic::Rest::Error => e + raise ::Google::Cloud::Error.from_error(e) + end + + ## + # Deletes a long-running operation. This method indicates that the client is + # no longer interested in the operation result. It does not cancel the + # operation. If the server doesn't support this method, it returns + # `google.rpc.Code.UNIMPLEMENTED`. + # + # @overload delete_operation(request, options = nil) + # Pass arguments to `delete_operation` via a request object, either of type + # {::Google::Longrunning::DeleteOperationRequest} or an equivalent Hash. + # + # @param request [::Google::Longrunning::DeleteOperationRequest, ::Hash] + # A request object representing the call parameters. Required. To specify no + # parameters, or to keep all the default parameter values, pass an empty Hash. + # @param options [::Gapic::CallOptions, ::Hash] + # Overrides the default settings for this call, e.g, timeout, retries etc. Optional. + # + # @overload delete_operation(name: nil) + # Pass arguments to `delete_operation` via keyword arguments. Note that at + # least one keyword argument is required. To specify no parameters, or to keep all + # the default parameter values, pass an empty Hash as a request object (see above). + # + # @param name [::String] + # The name of the operation resource to be deleted. + # @yield [result, operation] Access the result along with the TransportOperation object + # @yieldparam result [::Google::Protobuf::Empty] + # @yieldparam operation [::Gapic::Rest::TransportOperation] + # + # @return [::Google::Protobuf::Empty] + # + # @raise [::Google::Cloud::Error] if the REST call is aborted. + # + # @example Basic example + # require "google/longrunning" + # + # # Create a client object. The client can be reused for multiple calls. + # client = Google::Longrunning::Operations::Rest::Client.new + # + # # Create a request. To set request fields, pass in keyword arguments. + # request = Google::Longrunning::DeleteOperationRequest.new + # + # # Call the delete_operation method. + # result = client.delete_operation request + # + # # The returned object is of type Google::Protobuf::Empty. + # p result + # + def delete_operation request, options = nil + raise ::ArgumentError, "request must be provided" if request.nil? + + request = ::Gapic::Protobuf.coerce request, to: ::Google::Longrunning::DeleteOperationRequest + + # Converts hash and nil to an options object + options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h + + # Customize the options with defaults + call_metadata = @config.rpcs.delete_operation.metadata.to_h + + # Set x-goog-api-client and x-goog-user-project headers + call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ + lib_name: @config.lib_name, lib_version: @config.lib_version, + gapic_version: ::Google::Cloud::ServiceUsage::V1::VERSION, + transports_version_send: [:rest] + + call_metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + + options.apply_defaults timeout: @config.rpcs.delete_operation.timeout, + metadata: call_metadata, + retry_policy: @config.rpcs.delete_operation.retry_policy + + options.apply_defaults timeout: @config.timeout, + metadata: @config.metadata, + retry_policy: @config.retry_policy + + @operations_stub.delete_operation request, options do |result, operation| + yield result, operation if block_given? + return result + end + rescue ::Gapic::Rest::Error => e + raise ::Google::Cloud::Error.from_error(e) + end + + ## + # Starts asynchronous cancellation on a long-running operation. The server + # makes a best effort to cancel the operation, but success is not + # guaranteed. If the server doesn't support this method, it returns + # `google.rpc.Code.UNIMPLEMENTED`. Clients can use + # Operations.GetOperation or + # other methods to check whether the cancellation succeeded or whether the + # operation completed despite cancellation. On successful cancellation, + # the operation is not deleted; instead, it becomes an operation with + # an {::Google::Longrunning::Operation#error Operation.error} value with a {::Google::Rpc::Status#code google.rpc.Status.code} of 1, + # corresponding to `Code.CANCELLED`. + # + # @overload cancel_operation(request, options = nil) + # Pass arguments to `cancel_operation` via a request object, either of type + # {::Google::Longrunning::CancelOperationRequest} or an equivalent Hash. + # + # @param request [::Google::Longrunning::CancelOperationRequest, ::Hash] + # A request object representing the call parameters. Required. To specify no + # parameters, or to keep all the default parameter values, pass an empty Hash. + # @param options [::Gapic::CallOptions, ::Hash] + # Overrides the default settings for this call, e.g, timeout, retries etc. Optional. + # + # @overload cancel_operation(name: nil) + # Pass arguments to `cancel_operation` via keyword arguments. Note that at + # least one keyword argument is required. To specify no parameters, or to keep all + # the default parameter values, pass an empty Hash as a request object (see above). + # + # @param name [::String] + # The name of the operation resource to be cancelled. + # @yield [result, operation] Access the result along with the TransportOperation object + # @yieldparam result [::Google::Protobuf::Empty] + # @yieldparam operation [::Gapic::Rest::TransportOperation] + # + # @return [::Google::Protobuf::Empty] + # + # @raise [::Google::Cloud::Error] if the REST call is aborted. + # + # @example Basic example + # require "google/longrunning" + # + # # Create a client object. The client can be reused for multiple calls. + # client = Google::Longrunning::Operations::Rest::Client.new + # + # # Create a request. To set request fields, pass in keyword arguments. + # request = Google::Longrunning::CancelOperationRequest.new + # + # # Call the cancel_operation method. + # result = client.cancel_operation request + # + # # The returned object is of type Google::Protobuf::Empty. + # p result + # + def cancel_operation request, options = nil + raise ::ArgumentError, "request must be provided" if request.nil? + + request = ::Gapic::Protobuf.coerce request, to: ::Google::Longrunning::CancelOperationRequest + + # Converts hash and nil to an options object + options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h + + # Customize the options with defaults + call_metadata = @config.rpcs.cancel_operation.metadata.to_h + + # Set x-goog-api-client and x-goog-user-project headers + call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ + lib_name: @config.lib_name, lib_version: @config.lib_version, + gapic_version: ::Google::Cloud::ServiceUsage::V1::VERSION, + transports_version_send: [:rest] + + call_metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + + options.apply_defaults timeout: @config.rpcs.cancel_operation.timeout, + metadata: call_metadata, + retry_policy: @config.rpcs.cancel_operation.retry_policy + + options.apply_defaults timeout: @config.timeout, + metadata: @config.metadata, + retry_policy: @config.retry_policy + + @operations_stub.cancel_operation request, options do |result, operation| + yield result, operation if block_given? + return result + end + rescue ::Gapic::Rest::Error => e + raise ::Google::Cloud::Error.from_error(e) + end + + ## + # Configuration class for the Operations REST API. + # + # This class represents the configuration for Operations REST, + # providing control over timeouts, retry behavior, logging, transport + # parameters, and other low-level controls. Certain parameters can also be + # applied individually to specific RPCs. See + # {::Google::Longrunning::Operations::Rest::Client::Configuration::Rpcs} + # for a list of RPCs that can be configured independently. + # + # Configuration can be applied globally to all clients, or to a single client + # on construction. + # + # @example + # + # # Modify the global config, setting the timeout for + # # list_operations to 20 seconds, + # # and all remaining timeouts to 10 seconds. + # ::Google::Longrunning::Operations::Rest::Client.configure do |config| + # config.timeout = 10.0 + # config.rpcs.list_operations.timeout = 20.0 + # end + # + # # Apply the above configuration only to a new client. + # client = ::Google::Longrunning::Operations::Rest::Client.new do |config| + # config.timeout = 10.0 + # config.rpcs.list_operations.timeout = 20.0 + # end + # + # @!attribute [rw] endpoint + # The hostname or hostname:port of the service endpoint. + # Defaults to `"serviceusage.googleapis.com"`. + # @return [::String] + # @!attribute [rw] credentials + # Credentials to send with calls. You may provide any of the following types: + # * (`String`) The path to a service account key file in JSON format + # * (`Hash`) A service account key as a Hash + # * (`Google::Auth::Credentials`) A googleauth credentials object + # (see the [googleauth docs](https://rubydoc.info/gems/googleauth/Google/Auth/Credentials)) + # * (`Signet::OAuth2::Client`) A signet oauth2 client object + # (see the [signet docs](https://rubydoc.info/gems/signet/Signet/OAuth2/Client)) + # * (`nil`) indicating no credentials + # @return [::Object] + # @!attribute [rw] scope + # The OAuth scopes + # @return [::Array<::String>] + # @!attribute [rw] lib_name + # The library name as recorded in instrumentation and logging + # @return [::String] + # @!attribute [rw] lib_version + # The library version as recorded in instrumentation and logging + # @return [::String] + # @!attribute [rw] timeout + # The call timeout in seconds. + # @return [::Numeric] + # @!attribute [rw] metadata + # Additional headers to be sent with the call. + # @return [::Hash{::Symbol=>::String}] + # @!attribute [rw] retry_policy + # The retry policy. The value is a hash with the following keys: + # * `:initial_delay` (*type:* `Numeric`) - The initial delay in seconds. + # * `:max_delay` (*type:* `Numeric`) - The max delay in seconds. + # * `:multiplier` (*type:* `Numeric`) - The incremental backoff multiplier. + # * `:retry_codes` (*type:* `Array`) - The error codes that should + # trigger a retry. + # @return [::Hash] + # @!attribute [rw] quota_project + # A separate project against which to charge quota. + # @return [::String] + # + class Configuration + extend ::Gapic::Config + + DEFAULT_ENDPOINT = "serviceusage.googleapis.com" + + config_attr :endpoint, DEFAULT_ENDPOINT, ::String + config_attr :credentials, nil do |value| + allowed = [::String, ::Hash, ::Proc, ::Symbol, ::Google::Auth::Credentials, ::Signet::OAuth2::Client, nil] + allowed.any? { |klass| klass === value } + end + config_attr :scope, nil, ::String, ::Array, nil + config_attr :lib_name, nil, ::String, nil + config_attr :lib_version, nil, ::String, nil + config_attr :timeout, nil, ::Numeric, nil + config_attr :metadata, nil, ::Hash, nil + config_attr :retry_policy, nil, ::Hash, ::Proc, nil + config_attr :quota_project, nil, ::String, nil + + # @private + def initialize parent_config = nil + @parent_config = parent_config unless parent_config.nil? + + yield self if block_given? + end + + ## + # Configurations for individual RPCs + # @return [Rpcs] + # + def rpcs + @rpcs ||= begin + parent_rpcs = nil + parent_rpcs = @parent_config.rpcs if defined?(@parent_config) && @parent_config.respond_to?(:rpcs) + Rpcs.new parent_rpcs + end + end + + ## + # Configuration RPC class for the Operations API. + # + # Includes fields providing the configuration for each RPC in this service. + # Each configuration object is of type `Gapic::Config::Method` and includes + # the following configuration fields: + # + # * `timeout` (*type:* `Numeric`) - The call timeout in seconds + # * `metadata` (*type:* `Hash{Symbol=>String}`) - Additional headers + # * `retry_policy (*type:* `Hash`) - The retry policy. The policy fields + # include the following keys: + # * `:initial_delay` (*type:* `Numeric`) - The initial delay in seconds. + # * `:max_delay` (*type:* `Numeric`) - The max delay in seconds. + # * `:multiplier` (*type:* `Numeric`) - The incremental backoff multiplier. + # * `:retry_codes` (*type:* `Array`) - The error codes that should + # trigger a retry. + # + class Rpcs + ## + # RPC-specific configuration for `list_operations` + # @return [::Gapic::Config::Method] + # + attr_reader :list_operations + ## + # RPC-specific configuration for `get_operation` + # @return [::Gapic::Config::Method] + # + attr_reader :get_operation + ## + # RPC-specific configuration for `delete_operation` + # @return [::Gapic::Config::Method] + # + attr_reader :delete_operation + ## + # RPC-specific configuration for `cancel_operation` + # @return [::Gapic::Config::Method] + # + attr_reader :cancel_operation + + # @private + def initialize parent_rpcs = nil + list_operations_config = parent_rpcs.list_operations if parent_rpcs.respond_to? :list_operations + @list_operations = ::Gapic::Config::Method.new list_operations_config + get_operation_config = parent_rpcs.get_operation if parent_rpcs.respond_to? :get_operation + @get_operation = ::Gapic::Config::Method.new get_operation_config + delete_operation_config = parent_rpcs.delete_operation if parent_rpcs.respond_to? :delete_operation + @delete_operation = ::Gapic::Config::Method.new delete_operation_config + cancel_operation_config = parent_rpcs.cancel_operation if parent_rpcs.respond_to? :cancel_operation + @cancel_operation = ::Gapic::Config::Method.new cancel_operation_config + + yield self if block_given? + end + end + end + end + + ## + # @private + # REST service stub for the Longrunning Operations API. + # Service stub contains baseline method implementations + # including transcoding, making the REST call, and deserialing the response. + class OperationsServiceStub + def initialize endpoint:, credentials: + # These require statements are intentionally placed here to initialize + # the REST modules only when it's required. + require "gapic/rest" + + @client_stub = ::Gapic::Rest::ClientStub.new endpoint: endpoint, credentials: credentials + end + + ## + # Baseline implementation for the list_operations REST call + # + # @param request_pb [::Google::Longrunning::ListOperationsRequest] + # A request object representing the call parameters. Required. + # @param options [::Gapic::CallOptions] + # Overrides the default settings for this call, e.g, timeout, retries etc. Optional. + # + # @yield [result, operation] Access the result along with the TransportOperation object + # @yieldparam result [::Google::Longrunning::ListOperationsResponse] + # @yieldparam operation [::Gapic::Rest::TransportOperation] + # + # @return [::Google::Longrunning::ListOperationsResponse] + # A result object deserialized from the server's reply + def list_operations request_pb, options = nil + raise ::ArgumentError, "request must be provided" if request_pb.nil? + + verb, uri, query_string_params, body = OperationsServiceStub.transcode_list_operations_request request_pb + query_string_params = if query_string_params.any? + query_string_params.to_h { |p| p.split "=", 2 } + else + {} + end + + response = @client_stub.make_http_request( + verb, + uri: uri, + body: body || "", + params: query_string_params, + options: options + ) + operation = ::Gapic::Rest::TransportOperation.new response + result = ::Google::Longrunning::ListOperationsResponse.decode_json response.body, ignore_unknown_fields: true + + yield result, operation if block_given? + result + end + + ## + # Baseline implementation for the get_operation REST call + # + # @param request_pb [::Google::Longrunning::GetOperationRequest] + # A request object representing the call parameters. Required. + # @param options [::Gapic::CallOptions] + # Overrides the default settings for this call, e.g, timeout, retries etc. Optional. + # + # @yield [result, operation] Access the result along with the TransportOperation object + # @yieldparam result [::Google::Longrunning::Operation] + # @yieldparam operation [::Gapic::Rest::TransportOperation] + # + # @return [::Google::Longrunning::Operation] + # A result object deserialized from the server's reply + def get_operation request_pb, options = nil + raise ::ArgumentError, "request must be provided" if request_pb.nil? + + verb, uri, query_string_params, body = OperationsServiceStub.transcode_get_operation_request request_pb + query_string_params = if query_string_params.any? + query_string_params.to_h { |p| p.split "=", 2 } + else + {} + end + + response = @client_stub.make_http_request( + verb, + uri: uri, + body: body || "", + params: query_string_params, + options: options + ) + operation = ::Gapic::Rest::TransportOperation.new response + result = ::Google::Longrunning::Operation.decode_json response.body, ignore_unknown_fields: true + + yield result, operation if block_given? + result + end + + ## + # Baseline implementation for the delete_operation REST call + # + # @param request_pb [::Google::Longrunning::DeleteOperationRequest] + # A request object representing the call parameters. Required. + # @param options [::Gapic::CallOptions] + # Overrides the default settings for this call, e.g, timeout, retries etc. Optional. + # + # @yield [result, operation] Access the result along with the TransportOperation object + # @yieldparam result [::Google::Protobuf::Empty] + # @yieldparam operation [::Gapic::Rest::TransportOperation] + # + # @return [::Google::Protobuf::Empty] + # A result object deserialized from the server's reply + def delete_operation request_pb, options = nil + raise ::ArgumentError, "request must be provided" if request_pb.nil? + + verb, uri, query_string_params, body = OperationsServiceStub.transcode_delete_operation_request request_pb + query_string_params = if query_string_params.any? + query_string_params.to_h { |p| p.split "=", 2 } + else + {} + end + + response = @client_stub.make_http_request( + verb, + uri: uri, + body: body || "", + params: query_string_params, + options: options + ) + operation = ::Gapic::Rest::TransportOperation.new response + result = ::Google::Protobuf::Empty.decode_json response.body, ignore_unknown_fields: true + + yield result, operation if block_given? + result + end + + ## + # Baseline implementation for the cancel_operation REST call + # + # @param request_pb [::Google::Longrunning::CancelOperationRequest] + # A request object representing the call parameters. Required. + # @param options [::Gapic::CallOptions] + # Overrides the default settings for this call, e.g, timeout, retries etc. Optional. + # + # @yield [result, operation] Access the result along with the TransportOperation object + # @yieldparam result [::Google::Protobuf::Empty] + # @yieldparam operation [::Gapic::Rest::TransportOperation] + # + # @return [::Google::Protobuf::Empty] + # A result object deserialized from the server's reply + def cancel_operation request_pb, options = nil + raise ::ArgumentError, "request must be provided" if request_pb.nil? + + verb, uri, query_string_params, body = OperationsServiceStub.transcode_cancel_operation_request request_pb + query_string_params = if query_string_params.any? + query_string_params.to_h { |p| p.split "=", 2 } + else + {} + end + + response = @client_stub.make_http_request( + verb, + uri: uri, + body: body || "", + params: query_string_params, + options: options + ) + operation = ::Gapic::Rest::TransportOperation.new response + result = ::Google::Protobuf::Empty.decode_json response.body, ignore_unknown_fields: true + + yield result, operation if block_given? + result + end + + ## + # @private + # + # GRPC transcoding helper method for the list_operations REST call + # + # @param request_pb [::Google::Longrunning::ListOperationsRequest] + # A request object representing the call parameters. Required. + # @return [Array(String, [String, nil], Hash{String => String})] + # Uri, Body, Query string parameters + def self.transcode_list_operations_request request_pb + transcoder = Gapic::Rest::GrpcTranscoder.new + .with_bindings( + uri_method: :get, + uri_template: "/v1/operations", + matches: [] + ) + transcoder.transcode request_pb + end + + ## + # @private + # + # GRPC transcoding helper method for the get_operation REST call + # + # @param request_pb [::Google::Longrunning::GetOperationRequest] + # A request object representing the call parameters. Required. + # @return [Array(String, [String, nil], Hash{String => String})] + # Uri, Body, Query string parameters + def self.transcode_get_operation_request request_pb + transcoder = Gapic::Rest::GrpcTranscoder.new + .with_bindings( + uri_method: :get, + uri_template: "/v1/{name}", + matches: [ + ["name", %r{^operations/[^/]+/?$}, false] + ] + ) + transcoder.transcode request_pb + end + + ## + # @private + # + # GRPC transcoding helper method for the delete_operation REST call + # + # @param request_pb [::Google::Longrunning::DeleteOperationRequest] + # A request object representing the call parameters. Required. + # @return [Array(String, [String, nil], Hash{String => String})] + # Uri, Body, Query string parameters + def self.transcode_delete_operation_request request_pb + transcoder = Gapic::Rest::GrpcTranscoder.new + .with_bindings( + uri_method: :delete, + uri_template: "/v1/{name}", + matches: [ + ["name", %r{^operations(?:/.*)?$}, true] + ] + ) + transcoder.transcode request_pb + end + + ## + # @private + # + # GRPC transcoding helper method for the cancel_operation REST call + # + # @param request_pb [::Google::Longrunning::CancelOperationRequest] + # A request object representing the call parameters. Required. + # @return [Array(String, [String, nil], Hash{String => String})] + # Uri, Body, Query string parameters + def self.transcode_cancel_operation_request request_pb + transcoder = Gapic::Rest::GrpcTranscoder.new + .with_bindings( + uri_method: :post, + uri_template: "/v1/{name}:cancel", + body: "*", + matches: [ + ["name", %r{^operations(?:/.*)?$}, true] + ] + ) + transcoder.transcode request_pb + end + end + end + end + end + end + end +end diff --git a/google-cloud-service_usage-v1/lib/google/cloud/service_usage/v1/service_usage/rest/service_stub.rb b/google-cloud-service_usage-v1/lib/google/cloud/service_usage/v1/service_usage/rest/service_stub.rb new file mode 100644 index 000000000000..36d8df1946e0 --- /dev/null +++ b/google-cloud-service_usage-v1/lib/google/cloud/service_usage/v1/service_usage/rest/service_stub.rb @@ -0,0 +1,405 @@ +# frozen_string_literal: true + +# Copyright 2023 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. + +# Auto-generated by gapic-generator-ruby. DO NOT EDIT! + +require "google/api/serviceusage/v1/serviceusage_pb" + +module Google + module Cloud + module ServiceUsage + module V1 + module ServiceUsage + module Rest + ## + # REST service stub for the ServiceUsage service. + # Service stub contains baseline method implementations + # including transcoding, making the REST call, and deserialing the response. + # + class ServiceStub + def initialize endpoint:, credentials: + # These require statements are intentionally placed here to initialize + # the REST modules only when it's required. + require "gapic/rest" + + @client_stub = ::Gapic::Rest::ClientStub.new endpoint: endpoint, credentials: credentials, + numeric_enums: true, + raise_faraday_errors: false + end + + ## + # Baseline implementation for the enable_service REST call + # + # @param request_pb [::Google::Cloud::ServiceUsage::V1::EnableServiceRequest] + # A request object representing the call parameters. Required. + # @param options [::Gapic::CallOptions] + # Overrides the default settings for this call, e.g, timeout, retries etc. Optional. + # + # @yield [result, operation] Access the result along with the TransportOperation object + # @yieldparam result [::Google::Longrunning::Operation] + # @yieldparam operation [::Gapic::Rest::TransportOperation] + # + # @return [::Google::Longrunning::Operation] + # A result object deserialized from the server's reply + def enable_service request_pb, options = nil + raise ::ArgumentError, "request must be provided" if request_pb.nil? + + verb, uri, query_string_params, body = ServiceStub.transcode_enable_service_request request_pb + query_string_params = if query_string_params.any? + query_string_params.to_h { |p| p.split "=", 2 } + else + {} + end + + response = @client_stub.make_http_request( + verb, + uri: uri, + body: body || "", + params: query_string_params, + options: options + ) + operation = ::Gapic::Rest::TransportOperation.new response + result = ::Google::Longrunning::Operation.decode_json response.body, ignore_unknown_fields: true + + yield result, operation if block_given? + result + end + + ## + # Baseline implementation for the disable_service REST call + # + # @param request_pb [::Google::Cloud::ServiceUsage::V1::DisableServiceRequest] + # A request object representing the call parameters. Required. + # @param options [::Gapic::CallOptions] + # Overrides the default settings for this call, e.g, timeout, retries etc. Optional. + # + # @yield [result, operation] Access the result along with the TransportOperation object + # @yieldparam result [::Google::Longrunning::Operation] + # @yieldparam operation [::Gapic::Rest::TransportOperation] + # + # @return [::Google::Longrunning::Operation] + # A result object deserialized from the server's reply + def disable_service request_pb, options = nil + raise ::ArgumentError, "request must be provided" if request_pb.nil? + + verb, uri, query_string_params, body = ServiceStub.transcode_disable_service_request request_pb + query_string_params = if query_string_params.any? + query_string_params.to_h { |p| p.split "=", 2 } + else + {} + end + + response = @client_stub.make_http_request( + verb, + uri: uri, + body: body || "", + params: query_string_params, + options: options + ) + operation = ::Gapic::Rest::TransportOperation.new response + result = ::Google::Longrunning::Operation.decode_json response.body, ignore_unknown_fields: true + + yield result, operation if block_given? + result + end + + ## + # Baseline implementation for the get_service REST call + # + # @param request_pb [::Google::Cloud::ServiceUsage::V1::GetServiceRequest] + # A request object representing the call parameters. Required. + # @param options [::Gapic::CallOptions] + # Overrides the default settings for this call, e.g, timeout, retries etc. Optional. + # + # @yield [result, operation] Access the result along with the TransportOperation object + # @yieldparam result [::Google::Cloud::ServiceUsage::V1::Service] + # @yieldparam operation [::Gapic::Rest::TransportOperation] + # + # @return [::Google::Cloud::ServiceUsage::V1::Service] + # A result object deserialized from the server's reply + def get_service request_pb, options = nil + raise ::ArgumentError, "request must be provided" if request_pb.nil? + + verb, uri, query_string_params, body = ServiceStub.transcode_get_service_request request_pb + query_string_params = if query_string_params.any? + query_string_params.to_h { |p| p.split "=", 2 } + else + {} + end + + response = @client_stub.make_http_request( + verb, + uri: uri, + body: body || "", + params: query_string_params, + options: options + ) + operation = ::Gapic::Rest::TransportOperation.new response + result = ::Google::Cloud::ServiceUsage::V1::Service.decode_json response.body, ignore_unknown_fields: true + + yield result, operation if block_given? + result + end + + ## + # Baseline implementation for the list_services REST call + # + # @param request_pb [::Google::Cloud::ServiceUsage::V1::ListServicesRequest] + # A request object representing the call parameters. Required. + # @param options [::Gapic::CallOptions] + # Overrides the default settings for this call, e.g, timeout, retries etc. Optional. + # + # @yield [result, operation] Access the result along with the TransportOperation object + # @yieldparam result [::Google::Cloud::ServiceUsage::V1::ListServicesResponse] + # @yieldparam operation [::Gapic::Rest::TransportOperation] + # + # @return [::Google::Cloud::ServiceUsage::V1::ListServicesResponse] + # A result object deserialized from the server's reply + def list_services request_pb, options = nil + raise ::ArgumentError, "request must be provided" if request_pb.nil? + + verb, uri, query_string_params, body = ServiceStub.transcode_list_services_request request_pb + query_string_params = if query_string_params.any? + query_string_params.to_h { |p| p.split "=", 2 } + else + {} + end + + response = @client_stub.make_http_request( + verb, + uri: uri, + body: body || "", + params: query_string_params, + options: options + ) + operation = ::Gapic::Rest::TransportOperation.new response + result = ::Google::Cloud::ServiceUsage::V1::ListServicesResponse.decode_json response.body, ignore_unknown_fields: true + + yield result, operation if block_given? + result + end + + ## + # Baseline implementation for the batch_enable_services REST call + # + # @param request_pb [::Google::Cloud::ServiceUsage::V1::BatchEnableServicesRequest] + # A request object representing the call parameters. Required. + # @param options [::Gapic::CallOptions] + # Overrides the default settings for this call, e.g, timeout, retries etc. Optional. + # + # @yield [result, operation] Access the result along with the TransportOperation object + # @yieldparam result [::Google::Longrunning::Operation] + # @yieldparam operation [::Gapic::Rest::TransportOperation] + # + # @return [::Google::Longrunning::Operation] + # A result object deserialized from the server's reply + def batch_enable_services request_pb, options = nil + raise ::ArgumentError, "request must be provided" if request_pb.nil? + + verb, uri, query_string_params, body = ServiceStub.transcode_batch_enable_services_request request_pb + query_string_params = if query_string_params.any? + query_string_params.to_h { |p| p.split "=", 2 } + else + {} + end + + response = @client_stub.make_http_request( + verb, + uri: uri, + body: body || "", + params: query_string_params, + options: options + ) + operation = ::Gapic::Rest::TransportOperation.new response + result = ::Google::Longrunning::Operation.decode_json response.body, ignore_unknown_fields: true + + yield result, operation if block_given? + result + end + + ## + # Baseline implementation for the batch_get_services REST call + # + # @param request_pb [::Google::Cloud::ServiceUsage::V1::BatchGetServicesRequest] + # A request object representing the call parameters. Required. + # @param options [::Gapic::CallOptions] + # Overrides the default settings for this call, e.g, timeout, retries etc. Optional. + # + # @yield [result, operation] Access the result along with the TransportOperation object + # @yieldparam result [::Google::Cloud::ServiceUsage::V1::BatchGetServicesResponse] + # @yieldparam operation [::Gapic::Rest::TransportOperation] + # + # @return [::Google::Cloud::ServiceUsage::V1::BatchGetServicesResponse] + # A result object deserialized from the server's reply + def batch_get_services request_pb, options = nil + raise ::ArgumentError, "request must be provided" if request_pb.nil? + + verb, uri, query_string_params, body = ServiceStub.transcode_batch_get_services_request request_pb + query_string_params = if query_string_params.any? + query_string_params.to_h { |p| p.split "=", 2 } + else + {} + end + + response = @client_stub.make_http_request( + verb, + uri: uri, + body: body || "", + params: query_string_params, + options: options + ) + operation = ::Gapic::Rest::TransportOperation.new response + result = ::Google::Cloud::ServiceUsage::V1::BatchGetServicesResponse.decode_json response.body, ignore_unknown_fields: true + + yield result, operation if block_given? + result + end + + ## + # @private + # + # GRPC transcoding helper method for the enable_service REST call + # + # @param request_pb [::Google::Cloud::ServiceUsage::V1::EnableServiceRequest] + # A request object representing the call parameters. Required. + # @return [Array(String, [String, nil], Hash{String => String})] + # Uri, Body, Query string parameters + def self.transcode_enable_service_request request_pb + transcoder = Gapic::Rest::GrpcTranscoder.new + .with_bindings( + uri_method: :post, + uri_template: "/v1/{name}:enable", + body: "*", + matches: [ + ["name", %r{^[^/]+/[^/]+/services/[^/]+/?$}, false] + ] + ) + transcoder.transcode request_pb + end + + ## + # @private + # + # GRPC transcoding helper method for the disable_service REST call + # + # @param request_pb [::Google::Cloud::ServiceUsage::V1::DisableServiceRequest] + # A request object representing the call parameters. Required. + # @return [Array(String, [String, nil], Hash{String => String})] + # Uri, Body, Query string parameters + def self.transcode_disable_service_request request_pb + transcoder = Gapic::Rest::GrpcTranscoder.new + .with_bindings( + uri_method: :post, + uri_template: "/v1/{name}:disable", + body: "*", + matches: [ + ["name", %r{^[^/]+/[^/]+/services/[^/]+/?$}, false] + ] + ) + transcoder.transcode request_pb + end + + ## + # @private + # + # GRPC transcoding helper method for the get_service REST call + # + # @param request_pb [::Google::Cloud::ServiceUsage::V1::GetServiceRequest] + # A request object representing the call parameters. Required. + # @return [Array(String, [String, nil], Hash{String => String})] + # Uri, Body, Query string parameters + def self.transcode_get_service_request request_pb + transcoder = Gapic::Rest::GrpcTranscoder.new + .with_bindings( + uri_method: :get, + uri_template: "/v1/{name}", + matches: [ + ["name", %r{^[^/]+/[^/]+/services/[^/]+/?$}, false] + ] + ) + transcoder.transcode request_pb + end + + ## + # @private + # + # GRPC transcoding helper method for the list_services REST call + # + # @param request_pb [::Google::Cloud::ServiceUsage::V1::ListServicesRequest] + # A request object representing the call parameters. Required. + # @return [Array(String, [String, nil], Hash{String => String})] + # Uri, Body, Query string parameters + def self.transcode_list_services_request request_pb + transcoder = Gapic::Rest::GrpcTranscoder.new + .with_bindings( + uri_method: :get, + uri_template: "/v1/{parent}/services", + matches: [ + ["parent", %r{^[^/]+/[^/]+/?$}, false] + ] + ) + transcoder.transcode request_pb + end + + ## + # @private + # + # GRPC transcoding helper method for the batch_enable_services REST call + # + # @param request_pb [::Google::Cloud::ServiceUsage::V1::BatchEnableServicesRequest] + # A request object representing the call parameters. Required. + # @return [Array(String, [String, nil], Hash{String => String})] + # Uri, Body, Query string parameters + def self.transcode_batch_enable_services_request request_pb + transcoder = Gapic::Rest::GrpcTranscoder.new + .with_bindings( + uri_method: :post, + uri_template: "/v1/{parent}/services:batchEnable", + body: "*", + matches: [ + ["parent", %r{^[^/]+/[^/]+/?$}, false] + ] + ) + transcoder.transcode request_pb + end + + ## + # @private + # + # GRPC transcoding helper method for the batch_get_services REST call + # + # @param request_pb [::Google::Cloud::ServiceUsage::V1::BatchGetServicesRequest] + # A request object representing the call parameters. Required. + # @return [Array(String, [String, nil], Hash{String => String})] + # Uri, Body, Query string parameters + def self.transcode_batch_get_services_request request_pb + transcoder = Gapic::Rest::GrpcTranscoder.new + .with_bindings( + uri_method: :get, + uri_template: "/v1/{parent}/services:batchGet", + matches: [ + ["parent", %r{^[^/]+/[^/]+/?$}, false] + ] + ) + transcoder.transcode request_pb + end + end + end + end + end + end + end +end diff --git a/google-cloud-service_usage-v1/proto_docs/google/api/serviceusage/v1/resources.rb b/google-cloud-service_usage-v1/proto_docs/google/api/serviceusage/v1/resources.rb index 9d0e299af1a3..1346f80b65ca 100644 --- a/google-cloud-service_usage-v1/proto_docs/google/api/serviceusage/v1/resources.rb +++ b/google-cloud-service_usage-v1/proto_docs/google/api/serviceusage/v1/resources.rb @@ -82,7 +82,8 @@ class Service # @!attribute [rw] monitored_resources # @return [::Array<::Google::Api::MonitoredResourceDescriptor>] # Defines the monitored resources used by this service. This is required - # by the [Service.monitoring][google.api.Service.monitoring] and [Service.logging][google.api.Service.logging] configurations. + # by the [Service.monitoring][google.api.Service.monitoring] and + # [Service.logging][google.api.Service.logging] configurations. # @!attribute [rw] monitoring # @return [::Google::Api::Monitoring] # Monitoring configuration. diff --git a/google-cloud-service_usage-v1/test/google/cloud/service_usage/v1/service_usage_rest_test.rb b/google-cloud-service_usage-v1/test/google/cloud/service_usage/v1/service_usage_rest_test.rb new file mode 100644 index 000000000000..681db95bbfa2 --- /dev/null +++ b/google-cloud-service_usage-v1/test/google/cloud/service_usage/v1/service_usage_rest_test.rb @@ -0,0 +1,413 @@ +# frozen_string_literal: true + +# Copyright 2023 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. + +# Auto-generated by gapic-generator-ruby. DO NOT EDIT! + +require "helper" +require "gapic/rest" +require "google/api/serviceusage/v1/serviceusage_pb" +require "google/cloud/service_usage/v1/service_usage/rest" + + +class ::Google::Cloud::ServiceUsage::V1::ServiceUsage::Rest::ClientTest < Minitest::Test + class ClientStub + attr_accessor :call_count, :requests + + def initialize response, &block + @response = response + @block = block + @call_count = 0 + @requests = [] + end + + def make_get_request uri:, params: {}, options: {} + make_http_request :get, uri: uri, body: nil, params: params, options: options + end + + def make_delete_request uri:, params: {}, options: {} + make_http_request :delete, uri: uri, body: nil, params: params, options: options + end + + def make_post_request uri:, body: nil, params: {}, options: {} + make_http_request :post, uri: uri, body: body, params: params, options: options + end + + def make_patch_request uri:, body:, params: {}, options: {} + make_http_request :patch, uri: uri, body: body, params: params, options: options + end + + def make_put_request uri:, body:, params: {}, options: {} + make_http_request :put, uri: uri, body: body, params: params, options: options + end + + def make_http_request *args, **kwargs + @call_count += 1 + + @requests << @block&.call(*args, **kwargs) + + @response + end + end + + def test_enable_service + # Create test objects. + client_result = ::Google::Longrunning::Operation.new + http_response = OpenStruct.new body: client_result.to_json + + call_options = {} + + # Create request parameters for a unary method. + name = "hello world" + + enable_service_client_stub = ClientStub.new http_response do |_verb, uri:, body:, params:, options:| + assert options.metadata.key? :"x-goog-api-client" + assert options.metadata[:"x-goog-api-client"].include? "rest" + refute options.metadata[:"x-goog-api-client"].include? "grpc" + end + + ::Google::Cloud::ServiceUsage::V1::ServiceUsage::Rest::ServiceStub.stub :transcode_enable_service_request, ["", "", {}] do + Gapic::Rest::ClientStub.stub :new, enable_service_client_stub do + # Create client + client = ::Google::Cloud::ServiceUsage::V1::ServiceUsage::Rest::Client.new do |config| + config.credentials = :dummy_value + end + + # Use hash object + client.enable_service({ name: name }) do |_result, response| + assert_equal http_response, response.underlying_op + end + + # Use named arguments + client.enable_service name: name do |_result, response| + assert_equal http_response, response.underlying_op + end + + # Use protobuf object + client.enable_service ::Google::Cloud::ServiceUsage::V1::EnableServiceRequest.new(name: name) do |_result, response| + assert_equal http_response, response.underlying_op + end + + # Use hash object with options + client.enable_service({ name: name }, call_options) do |_result, response| + assert_equal http_response, response.underlying_op + end + + # Use protobuf object with options + client.enable_service(::Google::Cloud::ServiceUsage::V1::EnableServiceRequest.new(name: name), call_options) do |_result, response| + assert_equal http_response, response.underlying_op + end + + # Verify method calls + assert_equal 5, enable_service_client_stub.call_count + end + end + end + + def test_disable_service + # Create test objects. + client_result = ::Google::Longrunning::Operation.new + http_response = OpenStruct.new body: client_result.to_json + + call_options = {} + + # Create request parameters for a unary method. + name = "hello world" + disable_dependent_services = true + check_if_service_has_usage = :CHECK_IF_SERVICE_HAS_USAGE_UNSPECIFIED + + disable_service_client_stub = ClientStub.new http_response do |_verb, uri:, body:, params:, options:| + assert options.metadata.key? :"x-goog-api-client" + assert options.metadata[:"x-goog-api-client"].include? "rest" + refute options.metadata[:"x-goog-api-client"].include? "grpc" + end + + ::Google::Cloud::ServiceUsage::V1::ServiceUsage::Rest::ServiceStub.stub :transcode_disable_service_request, ["", "", {}] do + Gapic::Rest::ClientStub.stub :new, disable_service_client_stub do + # Create client + client = ::Google::Cloud::ServiceUsage::V1::ServiceUsage::Rest::Client.new do |config| + config.credentials = :dummy_value + end + + # Use hash object + client.disable_service({ name: name, disable_dependent_services: disable_dependent_services, check_if_service_has_usage: check_if_service_has_usage }) do |_result, response| + assert_equal http_response, response.underlying_op + end + + # Use named arguments + client.disable_service name: name, disable_dependent_services: disable_dependent_services, check_if_service_has_usage: check_if_service_has_usage do |_result, response| + assert_equal http_response, response.underlying_op + end + + # Use protobuf object + client.disable_service ::Google::Cloud::ServiceUsage::V1::DisableServiceRequest.new(name: name, disable_dependent_services: disable_dependent_services, check_if_service_has_usage: check_if_service_has_usage) do |_result, response| + assert_equal http_response, response.underlying_op + end + + # Use hash object with options + client.disable_service({ name: name, disable_dependent_services: disable_dependent_services, check_if_service_has_usage: check_if_service_has_usage }, call_options) do |_result, response| + assert_equal http_response, response.underlying_op + end + + # Use protobuf object with options + client.disable_service(::Google::Cloud::ServiceUsage::V1::DisableServiceRequest.new(name: name, disable_dependent_services: disable_dependent_services, check_if_service_has_usage: check_if_service_has_usage), call_options) do |_result, response| + assert_equal http_response, response.underlying_op + end + + # Verify method calls + assert_equal 5, disable_service_client_stub.call_count + end + end + end + + def test_get_service + # Create test objects. + client_result = ::Google::Cloud::ServiceUsage::V1::Service.new + http_response = OpenStruct.new body: client_result.to_json + + call_options = {} + + # Create request parameters for a unary method. + name = "hello world" + + get_service_client_stub = ClientStub.new http_response do |_verb, uri:, body:, params:, options:| + assert options.metadata.key? :"x-goog-api-client" + assert options.metadata[:"x-goog-api-client"].include? "rest" + refute options.metadata[:"x-goog-api-client"].include? "grpc" + end + + ::Google::Cloud::ServiceUsage::V1::ServiceUsage::Rest::ServiceStub.stub :transcode_get_service_request, ["", "", {}] do + Gapic::Rest::ClientStub.stub :new, get_service_client_stub do + # Create client + client = ::Google::Cloud::ServiceUsage::V1::ServiceUsage::Rest::Client.new do |config| + config.credentials = :dummy_value + end + + # Use hash object + client.get_service({ name: name }) do |_result, response| + assert_equal http_response, response.underlying_op + end + + # Use named arguments + client.get_service name: name do |_result, response| + assert_equal http_response, response.underlying_op + end + + # Use protobuf object + client.get_service ::Google::Cloud::ServiceUsage::V1::GetServiceRequest.new(name: name) do |_result, response| + assert_equal http_response, response.underlying_op + end + + # Use hash object with options + client.get_service({ name: name }, call_options) do |_result, response| + assert_equal http_response, response.underlying_op + end + + # Use protobuf object with options + client.get_service(::Google::Cloud::ServiceUsage::V1::GetServiceRequest.new(name: name), call_options) do |_result, response| + assert_equal http_response, response.underlying_op + end + + # Verify method calls + assert_equal 5, get_service_client_stub.call_count + end + end + end + + def test_list_services + # Create test objects. + client_result = ::Google::Cloud::ServiceUsage::V1::ListServicesResponse.new + http_response = OpenStruct.new body: client_result.to_json + + call_options = {} + + # Create request parameters for a unary method. + parent = "hello world" + page_size = 42 + page_token = "hello world" + filter = "hello world" + + list_services_client_stub = ClientStub.new http_response do |_verb, uri:, body:, params:, options:| + assert options.metadata.key? :"x-goog-api-client" + assert options.metadata[:"x-goog-api-client"].include? "rest" + refute options.metadata[:"x-goog-api-client"].include? "grpc" + end + + ::Google::Cloud::ServiceUsage::V1::ServiceUsage::Rest::ServiceStub.stub :transcode_list_services_request, ["", "", {}] do + Gapic::Rest::ClientStub.stub :new, list_services_client_stub do + # Create client + client = ::Google::Cloud::ServiceUsage::V1::ServiceUsage::Rest::Client.new do |config| + config.credentials = :dummy_value + end + + # Use hash object + client.list_services({ parent: parent, page_size: page_size, page_token: page_token, filter: filter }) do |_result, response| + assert_equal http_response, response.underlying_op + end + + # Use named arguments + client.list_services parent: parent, page_size: page_size, page_token: page_token, filter: filter do |_result, response| + assert_equal http_response, response.underlying_op + end + + # Use protobuf object + client.list_services ::Google::Cloud::ServiceUsage::V1::ListServicesRequest.new(parent: parent, page_size: page_size, page_token: page_token, filter: filter) do |_result, response| + assert_equal http_response, response.underlying_op + end + + # Use hash object with options + client.list_services({ parent: parent, page_size: page_size, page_token: page_token, filter: filter }, call_options) do |_result, response| + assert_equal http_response, response.underlying_op + end + + # Use protobuf object with options + client.list_services(::Google::Cloud::ServiceUsage::V1::ListServicesRequest.new(parent: parent, page_size: page_size, page_token: page_token, filter: filter), call_options) do |_result, response| + assert_equal http_response, response.underlying_op + end + + # Verify method calls + assert_equal 5, list_services_client_stub.call_count + end + end + end + + def test_batch_enable_services + # Create test objects. + client_result = ::Google::Longrunning::Operation.new + http_response = OpenStruct.new body: client_result.to_json + + call_options = {} + + # Create request parameters for a unary method. + parent = "hello world" + service_ids = ["hello world"] + + batch_enable_services_client_stub = ClientStub.new http_response do |_verb, uri:, body:, params:, options:| + assert options.metadata.key? :"x-goog-api-client" + assert options.metadata[:"x-goog-api-client"].include? "rest" + refute options.metadata[:"x-goog-api-client"].include? "grpc" + end + + ::Google::Cloud::ServiceUsage::V1::ServiceUsage::Rest::ServiceStub.stub :transcode_batch_enable_services_request, ["", "", {}] do + Gapic::Rest::ClientStub.stub :new, batch_enable_services_client_stub do + # Create client + client = ::Google::Cloud::ServiceUsage::V1::ServiceUsage::Rest::Client.new do |config| + config.credentials = :dummy_value + end + + # Use hash object + client.batch_enable_services({ parent: parent, service_ids: service_ids }) do |_result, response| + assert_equal http_response, response.underlying_op + end + + # Use named arguments + client.batch_enable_services parent: parent, service_ids: service_ids do |_result, response| + assert_equal http_response, response.underlying_op + end + + # Use protobuf object + client.batch_enable_services ::Google::Cloud::ServiceUsage::V1::BatchEnableServicesRequest.new(parent: parent, service_ids: service_ids) do |_result, response| + assert_equal http_response, response.underlying_op + end + + # Use hash object with options + client.batch_enable_services({ parent: parent, service_ids: service_ids }, call_options) do |_result, response| + assert_equal http_response, response.underlying_op + end + + # Use protobuf object with options + client.batch_enable_services(::Google::Cloud::ServiceUsage::V1::BatchEnableServicesRequest.new(parent: parent, service_ids: service_ids), call_options) do |_result, response| + assert_equal http_response, response.underlying_op + end + + # Verify method calls + assert_equal 5, batch_enable_services_client_stub.call_count + end + end + end + + def test_batch_get_services + # Create test objects. + client_result = ::Google::Cloud::ServiceUsage::V1::BatchGetServicesResponse.new + http_response = OpenStruct.new body: client_result.to_json + + call_options = {} + + # Create request parameters for a unary method. + parent = "hello world" + names = ["hello world"] + + batch_get_services_client_stub = ClientStub.new http_response do |_verb, uri:, body:, params:, options:| + assert options.metadata.key? :"x-goog-api-client" + assert options.metadata[:"x-goog-api-client"].include? "rest" + refute options.metadata[:"x-goog-api-client"].include? "grpc" + end + + ::Google::Cloud::ServiceUsage::V1::ServiceUsage::Rest::ServiceStub.stub :transcode_batch_get_services_request, ["", "", {}] do + Gapic::Rest::ClientStub.stub :new, batch_get_services_client_stub do + # Create client + client = ::Google::Cloud::ServiceUsage::V1::ServiceUsage::Rest::Client.new do |config| + config.credentials = :dummy_value + end + + # Use hash object + client.batch_get_services({ parent: parent, names: names }) do |_result, response| + assert_equal http_response, response.underlying_op + end + + # Use named arguments + client.batch_get_services parent: parent, names: names do |_result, response| + assert_equal http_response, response.underlying_op + end + + # Use protobuf object + client.batch_get_services ::Google::Cloud::ServiceUsage::V1::BatchGetServicesRequest.new(parent: parent, names: names) do |_result, response| + assert_equal http_response, response.underlying_op + end + + # Use hash object with options + client.batch_get_services({ parent: parent, names: names }, call_options) do |_result, response| + assert_equal http_response, response.underlying_op + end + + # Use protobuf object with options + client.batch_get_services(::Google::Cloud::ServiceUsage::V1::BatchGetServicesRequest.new(parent: parent, names: names), call_options) do |_result, response| + assert_equal http_response, response.underlying_op + end + + # Verify method calls + assert_equal 5, batch_get_services_client_stub.call_count + end + end + end + + def test_configure + credentials_token = :dummy_value + + client = block_config = config = nil + Gapic::Rest::ClientStub.stub :new, nil do + client = ::Google::Cloud::ServiceUsage::V1::ServiceUsage::Rest::Client.new do |config| + config.credentials = credentials_token + end + end + + config = client.configure do |c| + block_config = c + end + + assert_same block_config, config + assert_kind_of ::Google::Cloud::ServiceUsage::V1::ServiceUsage::Rest::Client::Configuration, config + end +end