google-cloud-service_usage-v1 0.3.1 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,923 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright 2023 Google LLC
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # https://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+
17
+ # Auto-generated by gapic-generator-ruby. DO NOT EDIT!
18
+
19
+ require "google/cloud/errors"
20
+ require "google/api/serviceusage/v1/serviceusage_pb"
21
+ require "google/cloud/service_usage/v1/service_usage/rest/service_stub"
22
+
23
+ module Google
24
+ module Cloud
25
+ module ServiceUsage
26
+ module V1
27
+ module ServiceUsage
28
+ module Rest
29
+ ##
30
+ # REST client for the ServiceUsage service.
31
+ #
32
+ # Enables services that service consumers want to use on Google Cloud Platform,
33
+ # lists the available or enabled services, or disables services that service
34
+ # consumers no longer use.
35
+ #
36
+ # See [Service Usage API](https://cloud.google.com/service-usage/docs/overview)
37
+ #
38
+ class Client
39
+ # @private
40
+ attr_reader :service_usage_stub
41
+
42
+ ##
43
+ # Configure the ServiceUsage Client class.
44
+ #
45
+ # See {::Google::Cloud::ServiceUsage::V1::ServiceUsage::Rest::Client::Configuration}
46
+ # for a description of the configuration fields.
47
+ #
48
+ # @example
49
+ #
50
+ # # Modify the configuration for all ServiceUsage clients
51
+ # ::Google::Cloud::ServiceUsage::V1::ServiceUsage::Rest::Client.configure do |config|
52
+ # config.timeout = 10.0
53
+ # end
54
+ #
55
+ # @yield [config] Configure the Client client.
56
+ # @yieldparam config [Client::Configuration]
57
+ #
58
+ # @return [Client::Configuration]
59
+ #
60
+ def self.configure
61
+ @configure ||= begin
62
+ namespace = ["Google", "Cloud", "ServiceUsage", "V1"]
63
+ parent_config = while namespace.any?
64
+ parent_name = namespace.join "::"
65
+ parent_const = const_get parent_name
66
+ break parent_const.configure if parent_const.respond_to? :configure
67
+ namespace.pop
68
+ end
69
+ default_config = Client::Configuration.new parent_config
70
+
71
+ default_config.timeout = 60.0
72
+
73
+ default_config
74
+ end
75
+ yield @configure if block_given?
76
+ @configure
77
+ end
78
+
79
+ ##
80
+ # Configure the ServiceUsage Client instance.
81
+ #
82
+ # The configuration is set to the derived mode, meaning that values can be changed,
83
+ # but structural changes (adding new fields, etc.) are not allowed. Structural changes
84
+ # should be made on {Client.configure}.
85
+ #
86
+ # See {::Google::Cloud::ServiceUsage::V1::ServiceUsage::Rest::Client::Configuration}
87
+ # for a description of the configuration fields.
88
+ #
89
+ # @yield [config] Configure the Client client.
90
+ # @yieldparam config [Client::Configuration]
91
+ #
92
+ # @return [Client::Configuration]
93
+ #
94
+ def configure
95
+ yield @config if block_given?
96
+ @config
97
+ end
98
+
99
+ ##
100
+ # Create a new ServiceUsage REST client object.
101
+ #
102
+ # @example
103
+ #
104
+ # # Create a client using the default configuration
105
+ # client = ::Google::Cloud::ServiceUsage::V1::ServiceUsage::Rest::Client.new
106
+ #
107
+ # # Create a client using a custom configuration
108
+ # client = ::Google::Cloud::ServiceUsage::V1::ServiceUsage::Rest::Client.new do |config|
109
+ # config.timeout = 10.0
110
+ # end
111
+ #
112
+ # @yield [config] Configure the ServiceUsage client.
113
+ # @yieldparam config [Client::Configuration]
114
+ #
115
+ def initialize
116
+ # Create the configuration object
117
+ @config = Configuration.new Client.configure
118
+
119
+ # Yield the configuration if needed
120
+ yield @config if block_given?
121
+
122
+ # Create credentials
123
+ credentials = @config.credentials
124
+ # Use self-signed JWT if the endpoint is unchanged from default,
125
+ # but only if the default endpoint does not have a region prefix.
126
+ enable_self_signed_jwt = @config.endpoint == Configuration::DEFAULT_ENDPOINT &&
127
+ !@config.endpoint.split(".").first.include?("-")
128
+ credentials ||= Credentials.default scope: @config.scope,
129
+ enable_self_signed_jwt: enable_self_signed_jwt
130
+ if credentials.is_a?(::String) || credentials.is_a?(::Hash)
131
+ credentials = Credentials.new credentials, scope: @config.scope
132
+ end
133
+
134
+ @quota_project_id = @config.quota_project
135
+ @quota_project_id ||= credentials.quota_project_id if credentials.respond_to? :quota_project_id
136
+
137
+ @operations_client = ::Google::Cloud::ServiceUsage::V1::ServiceUsage::Rest::Operations.new do |config|
138
+ config.credentials = credentials
139
+ config.quota_project = @quota_project_id
140
+ config.endpoint = @config.endpoint
141
+ end
142
+
143
+ @service_usage_stub = ::Google::Cloud::ServiceUsage::V1::ServiceUsage::Rest::ServiceStub.new endpoint: @config.endpoint, credentials: credentials
144
+ end
145
+
146
+ ##
147
+ # Get the associated client for long-running operations.
148
+ #
149
+ # @return [::Google::Cloud::ServiceUsage::V1::ServiceUsage::Rest::Operations]
150
+ #
151
+ attr_reader :operations_client
152
+
153
+ # Service calls
154
+
155
+ ##
156
+ # Enable a service so that it can be used with a project.
157
+ #
158
+ # @overload enable_service(request, options = nil)
159
+ # Pass arguments to `enable_service` via a request object, either of type
160
+ # {::Google::Cloud::ServiceUsage::V1::EnableServiceRequest} or an equivalent Hash.
161
+ #
162
+ # @param request [::Google::Cloud::ServiceUsage::V1::EnableServiceRequest, ::Hash]
163
+ # A request object representing the call parameters. Required. To specify no
164
+ # parameters, or to keep all the default parameter values, pass an empty Hash.
165
+ # @param options [::Gapic::CallOptions, ::Hash]
166
+ # Overrides the default settings for this call, e.g, timeout, retries etc. Optional.
167
+ #
168
+ # @overload enable_service(name: nil)
169
+ # Pass arguments to `enable_service` via keyword arguments. Note that at
170
+ # least one keyword argument is required. To specify no parameters, or to keep all
171
+ # the default parameter values, pass an empty Hash as a request object (see above).
172
+ #
173
+ # @param name [::String]
174
+ # Name of the consumer and service to enable the service on.
175
+ #
176
+ # The `EnableService` and `DisableService` methods currently only support
177
+ # projects.
178
+ #
179
+ # Enabling a service requires that the service is public or is shared with
180
+ # the user enabling the service.
181
+ #
182
+ # An example name would be:
183
+ # `projects/123/services/serviceusage.googleapis.com` where `123` is the
184
+ # project number.
185
+ # @yield [result, operation] Access the result along with the TransportOperation object
186
+ # @yieldparam result [::Gapic::Operation]
187
+ # @yieldparam operation [::Gapic::Rest::TransportOperation]
188
+ #
189
+ # @return [::Gapic::Operation]
190
+ #
191
+ # @raise [::Google::Cloud::Error] if the REST call is aborted.
192
+ #
193
+ # @example Basic example
194
+ # require "google/cloud/service_usage/v1"
195
+ #
196
+ # # Create a client object. The client can be reused for multiple calls.
197
+ # client = Google::Cloud::ServiceUsage::V1::ServiceUsage::Rest::Client.new
198
+ #
199
+ # # Create a request. To set request fields, pass in keyword arguments.
200
+ # request = Google::Cloud::ServiceUsage::V1::EnableServiceRequest.new
201
+ #
202
+ # # Call the enable_service method.
203
+ # result = client.enable_service request
204
+ #
205
+ # # The returned object is of type Gapic::Operation. You can use it to
206
+ # # check the status of an operation, cancel it, or wait for results.
207
+ # # Here is how to wait for a response.
208
+ # result.wait_until_done! timeout: 60
209
+ # if result.response?
210
+ # p result.response
211
+ # else
212
+ # puts "No response received."
213
+ # end
214
+ #
215
+ def enable_service request, options = nil
216
+ raise ::ArgumentError, "request must be provided" if request.nil?
217
+
218
+ request = ::Gapic::Protobuf.coerce request, to: ::Google::Cloud::ServiceUsage::V1::EnableServiceRequest
219
+
220
+ # Converts hash and nil to an options object
221
+ options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h
222
+
223
+ # Customize the options with defaults
224
+ call_metadata = @config.rpcs.enable_service.metadata.to_h
225
+
226
+ # Set x-goog-api-client and x-goog-user-project headers
227
+ call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \
228
+ lib_name: @config.lib_name, lib_version: @config.lib_version,
229
+ gapic_version: ::Google::Cloud::ServiceUsage::V1::VERSION,
230
+ transports_version_send: [:rest]
231
+
232
+ call_metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id
233
+
234
+ options.apply_defaults timeout: @config.rpcs.enable_service.timeout,
235
+ metadata: call_metadata,
236
+ retry_policy: @config.rpcs.enable_service.retry_policy
237
+
238
+ options.apply_defaults timeout: @config.timeout,
239
+ metadata: @config.metadata,
240
+ retry_policy: @config.retry_policy
241
+
242
+ @service_usage_stub.enable_service request, options do |result, operation|
243
+ result = ::Gapic::Operation.new result, @operations_client, options: options
244
+ yield result, operation if block_given?
245
+ return result
246
+ end
247
+ rescue ::Gapic::Rest::Error => e
248
+ raise ::Google::Cloud::Error.from_error(e)
249
+ end
250
+
251
+ ##
252
+ # Disable a service so that it can no longer be used with a project.
253
+ # This prevents unintended usage that may cause unexpected billing
254
+ # charges or security leaks.
255
+ #
256
+ # It is not valid to call the disable method on a service that is not
257
+ # currently enabled. Callers will receive a `FAILED_PRECONDITION` status if
258
+ # the target service is not currently enabled.
259
+ #
260
+ # @overload disable_service(request, options = nil)
261
+ # Pass arguments to `disable_service` via a request object, either of type
262
+ # {::Google::Cloud::ServiceUsage::V1::DisableServiceRequest} or an equivalent Hash.
263
+ #
264
+ # @param request [::Google::Cloud::ServiceUsage::V1::DisableServiceRequest, ::Hash]
265
+ # A request object representing the call parameters. Required. To specify no
266
+ # parameters, or to keep all the default parameter values, pass an empty Hash.
267
+ # @param options [::Gapic::CallOptions, ::Hash]
268
+ # Overrides the default settings for this call, e.g, timeout, retries etc. Optional.
269
+ #
270
+ # @overload disable_service(name: nil, disable_dependent_services: nil, check_if_service_has_usage: nil)
271
+ # Pass arguments to `disable_service` via keyword arguments. Note that at
272
+ # least one keyword argument is required. To specify no parameters, or to keep all
273
+ # the default parameter values, pass an empty Hash as a request object (see above).
274
+ #
275
+ # @param name [::String]
276
+ # Name of the consumer and service to disable the service on.
277
+ #
278
+ # The enable and disable methods currently only support projects.
279
+ #
280
+ # An example name would be:
281
+ # `projects/123/services/serviceusage.googleapis.com` where `123` is the
282
+ # project number.
283
+ # @param disable_dependent_services [::Boolean]
284
+ # Indicates if services that are enabled and which depend on this service
285
+ # should also be disabled. If not set, an error will be generated if any
286
+ # enabled services depend on the service to be disabled. When set, the
287
+ # service, and any enabled services that depend on it, will be disabled
288
+ # together.
289
+ # @param check_if_service_has_usage [::Google::Cloud::ServiceUsage::V1::DisableServiceRequest::CheckIfServiceHasUsage]
290
+ # Defines the behavior for checking service usage when disabling a service.
291
+ # @yield [result, operation] Access the result along with the TransportOperation object
292
+ # @yieldparam result [::Gapic::Operation]
293
+ # @yieldparam operation [::Gapic::Rest::TransportOperation]
294
+ #
295
+ # @return [::Gapic::Operation]
296
+ #
297
+ # @raise [::Google::Cloud::Error] if the REST call is aborted.
298
+ #
299
+ # @example Basic example
300
+ # require "google/cloud/service_usage/v1"
301
+ #
302
+ # # Create a client object. The client can be reused for multiple calls.
303
+ # client = Google::Cloud::ServiceUsage::V1::ServiceUsage::Rest::Client.new
304
+ #
305
+ # # Create a request. To set request fields, pass in keyword arguments.
306
+ # request = Google::Cloud::ServiceUsage::V1::DisableServiceRequest.new
307
+ #
308
+ # # Call the disable_service method.
309
+ # result = client.disable_service request
310
+ #
311
+ # # The returned object is of type Gapic::Operation. You can use it to
312
+ # # check the status of an operation, cancel it, or wait for results.
313
+ # # Here is how to wait for a response.
314
+ # result.wait_until_done! timeout: 60
315
+ # if result.response?
316
+ # p result.response
317
+ # else
318
+ # puts "No response received."
319
+ # end
320
+ #
321
+ def disable_service request, options = nil
322
+ raise ::ArgumentError, "request must be provided" if request.nil?
323
+
324
+ request = ::Gapic::Protobuf.coerce request, to: ::Google::Cloud::ServiceUsage::V1::DisableServiceRequest
325
+
326
+ # Converts hash and nil to an options object
327
+ options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h
328
+
329
+ # Customize the options with defaults
330
+ call_metadata = @config.rpcs.disable_service.metadata.to_h
331
+
332
+ # Set x-goog-api-client and x-goog-user-project headers
333
+ call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \
334
+ lib_name: @config.lib_name, lib_version: @config.lib_version,
335
+ gapic_version: ::Google::Cloud::ServiceUsage::V1::VERSION,
336
+ transports_version_send: [:rest]
337
+
338
+ call_metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id
339
+
340
+ options.apply_defaults timeout: @config.rpcs.disable_service.timeout,
341
+ metadata: call_metadata,
342
+ retry_policy: @config.rpcs.disable_service.retry_policy
343
+
344
+ options.apply_defaults timeout: @config.timeout,
345
+ metadata: @config.metadata,
346
+ retry_policy: @config.retry_policy
347
+
348
+ @service_usage_stub.disable_service request, options do |result, operation|
349
+ result = ::Gapic::Operation.new result, @operations_client, options: options
350
+ yield result, operation if block_given?
351
+ return result
352
+ end
353
+ rescue ::Gapic::Rest::Error => e
354
+ raise ::Google::Cloud::Error.from_error(e)
355
+ end
356
+
357
+ ##
358
+ # Returns the service configuration and enabled state for a given service.
359
+ #
360
+ # @overload get_service(request, options = nil)
361
+ # Pass arguments to `get_service` via a request object, either of type
362
+ # {::Google::Cloud::ServiceUsage::V1::GetServiceRequest} or an equivalent Hash.
363
+ #
364
+ # @param request [::Google::Cloud::ServiceUsage::V1::GetServiceRequest, ::Hash]
365
+ # A request object representing the call parameters. Required. To specify no
366
+ # parameters, or to keep all the default parameter values, pass an empty Hash.
367
+ # @param options [::Gapic::CallOptions, ::Hash]
368
+ # Overrides the default settings for this call, e.g, timeout, retries etc. Optional.
369
+ #
370
+ # @overload get_service(name: nil)
371
+ # Pass arguments to `get_service` via keyword arguments. Note that at
372
+ # least one keyword argument is required. To specify no parameters, or to keep all
373
+ # the default parameter values, pass an empty Hash as a request object (see above).
374
+ #
375
+ # @param name [::String]
376
+ # Name of the consumer and service to get the `ConsumerState` for.
377
+ #
378
+ # An example name would be:
379
+ # `projects/123/services/serviceusage.googleapis.com` where `123` is the
380
+ # project number.
381
+ # @yield [result, operation] Access the result along with the TransportOperation object
382
+ # @yieldparam result [::Google::Cloud::ServiceUsage::V1::Service]
383
+ # @yieldparam operation [::Gapic::Rest::TransportOperation]
384
+ #
385
+ # @return [::Google::Cloud::ServiceUsage::V1::Service]
386
+ #
387
+ # @raise [::Google::Cloud::Error] if the REST call is aborted.
388
+ #
389
+ # @example Basic example
390
+ # require "google/cloud/service_usage/v1"
391
+ #
392
+ # # Create a client object. The client can be reused for multiple calls.
393
+ # client = Google::Cloud::ServiceUsage::V1::ServiceUsage::Rest::Client.new
394
+ #
395
+ # # Create a request. To set request fields, pass in keyword arguments.
396
+ # request = Google::Cloud::ServiceUsage::V1::GetServiceRequest.new
397
+ #
398
+ # # Call the get_service method.
399
+ # result = client.get_service request
400
+ #
401
+ # # The returned object is of type Google::Cloud::ServiceUsage::V1::Service.
402
+ # p result
403
+ #
404
+ def get_service request, options = nil
405
+ raise ::ArgumentError, "request must be provided" if request.nil?
406
+
407
+ request = ::Gapic::Protobuf.coerce request, to: ::Google::Cloud::ServiceUsage::V1::GetServiceRequest
408
+
409
+ # Converts hash and nil to an options object
410
+ options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h
411
+
412
+ # Customize the options with defaults
413
+ call_metadata = @config.rpcs.get_service.metadata.to_h
414
+
415
+ # Set x-goog-api-client and x-goog-user-project headers
416
+ call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \
417
+ lib_name: @config.lib_name, lib_version: @config.lib_version,
418
+ gapic_version: ::Google::Cloud::ServiceUsage::V1::VERSION,
419
+ transports_version_send: [:rest]
420
+
421
+ call_metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id
422
+
423
+ options.apply_defaults timeout: @config.rpcs.get_service.timeout,
424
+ metadata: call_metadata,
425
+ retry_policy: @config.rpcs.get_service.retry_policy
426
+
427
+ options.apply_defaults timeout: @config.timeout,
428
+ metadata: @config.metadata,
429
+ retry_policy: @config.retry_policy
430
+
431
+ @service_usage_stub.get_service request, options do |result, operation|
432
+ yield result, operation if block_given?
433
+ return result
434
+ end
435
+ rescue ::Gapic::Rest::Error => e
436
+ raise ::Google::Cloud::Error.from_error(e)
437
+ end
438
+
439
+ ##
440
+ # List all services available to the specified project, and the current
441
+ # state of those services with respect to the project. The list includes
442
+ # all public services, all services for which the calling user has the
443
+ # `servicemanagement.services.bind` permission, and all services that have
444
+ # already been enabled on the project. The list can be filtered to
445
+ # only include services in a specific state, for example to only include
446
+ # services enabled on the project.
447
+ #
448
+ # WARNING: If you need to query enabled services frequently or across
449
+ # an organization, you should use
450
+ # [Cloud Asset Inventory
451
+ # API](https://cloud.google.com/asset-inventory/docs/apis), which provides
452
+ # higher throughput and richer filtering capability.
453
+ #
454
+ # @overload list_services(request, options = nil)
455
+ # Pass arguments to `list_services` via a request object, either of type
456
+ # {::Google::Cloud::ServiceUsage::V1::ListServicesRequest} or an equivalent Hash.
457
+ #
458
+ # @param request [::Google::Cloud::ServiceUsage::V1::ListServicesRequest, ::Hash]
459
+ # A request object representing the call parameters. Required. To specify no
460
+ # parameters, or to keep all the default parameter values, pass an empty Hash.
461
+ # @param options [::Gapic::CallOptions, ::Hash]
462
+ # Overrides the default settings for this call, e.g, timeout, retries etc. Optional.
463
+ #
464
+ # @overload list_services(parent: nil, page_size: nil, page_token: nil, filter: nil)
465
+ # Pass arguments to `list_services` via keyword arguments. Note that at
466
+ # least one keyword argument is required. To specify no parameters, or to keep all
467
+ # the default parameter values, pass an empty Hash as a request object (see above).
468
+ #
469
+ # @param parent [::String]
470
+ # Parent to search for services on.
471
+ #
472
+ # An example name would be:
473
+ # `projects/123` where `123` is the project number.
474
+ # @param page_size [::Integer]
475
+ # Requested size of the next page of data.
476
+ # Requested page size cannot exceed 200.
477
+ # If not set, the default page size is 50.
478
+ # @param page_token [::String]
479
+ # Token identifying which result to start with, which is returned by a
480
+ # previous list call.
481
+ # @param filter [::String]
482
+ # Only list services that conform to the given filter.
483
+ # The allowed filter strings are `state:ENABLED` and `state:DISABLED`.
484
+ # @yield [result, operation] Access the result along with the TransportOperation object
485
+ # @yieldparam result [::Gapic::Rest::PagedEnumerable<::Google::Cloud::ServiceUsage::V1::Service>]
486
+ # @yieldparam operation [::Gapic::Rest::TransportOperation]
487
+ #
488
+ # @return [::Gapic::Rest::PagedEnumerable<::Google::Cloud::ServiceUsage::V1::Service>]
489
+ #
490
+ # @raise [::Google::Cloud::Error] if the REST call is aborted.
491
+ #
492
+ # @example Basic example
493
+ # require "google/cloud/service_usage/v1"
494
+ #
495
+ # # Create a client object. The client can be reused for multiple calls.
496
+ # client = Google::Cloud::ServiceUsage::V1::ServiceUsage::Rest::Client.new
497
+ #
498
+ # # Create a request. To set request fields, pass in keyword arguments.
499
+ # request = Google::Cloud::ServiceUsage::V1::ListServicesRequest.new
500
+ #
501
+ # # Call the list_services method.
502
+ # result = client.list_services request
503
+ #
504
+ # # The returned object is of type Gapic::PagedEnumerable. You can iterate
505
+ # # over elements, and API calls will be issued to fetch pages as needed.
506
+ # result.each do |item|
507
+ # # Each element is of type ::Google::Cloud::ServiceUsage::V1::Service.
508
+ # p item
509
+ # end
510
+ #
511
+ def list_services request, options = nil
512
+ raise ::ArgumentError, "request must be provided" if request.nil?
513
+
514
+ request = ::Gapic::Protobuf.coerce request, to: ::Google::Cloud::ServiceUsage::V1::ListServicesRequest
515
+
516
+ # Converts hash and nil to an options object
517
+ options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h
518
+
519
+ # Customize the options with defaults
520
+ call_metadata = @config.rpcs.list_services.metadata.to_h
521
+
522
+ # Set x-goog-api-client and x-goog-user-project headers
523
+ call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \
524
+ lib_name: @config.lib_name, lib_version: @config.lib_version,
525
+ gapic_version: ::Google::Cloud::ServiceUsage::V1::VERSION,
526
+ transports_version_send: [:rest]
527
+
528
+ call_metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id
529
+
530
+ options.apply_defaults timeout: @config.rpcs.list_services.timeout,
531
+ metadata: call_metadata,
532
+ retry_policy: @config.rpcs.list_services.retry_policy
533
+
534
+ options.apply_defaults timeout: @config.timeout,
535
+ metadata: @config.metadata,
536
+ retry_policy: @config.retry_policy
537
+
538
+ @service_usage_stub.list_services request, options do |result, operation|
539
+ result = ::Gapic::Rest::PagedEnumerable.new @service_usage_stub, :list_services, "services", request, result, options
540
+ yield result, operation if block_given?
541
+ return result
542
+ end
543
+ rescue ::Gapic::Rest::Error => e
544
+ raise ::Google::Cloud::Error.from_error(e)
545
+ end
546
+
547
+ ##
548
+ # Enable multiple services on a project. The operation is atomic: if enabling
549
+ # any service fails, then the entire batch fails, and no state changes occur.
550
+ # To enable a single service, use the `EnableService` method instead.
551
+ #
552
+ # @overload batch_enable_services(request, options = nil)
553
+ # Pass arguments to `batch_enable_services` via a request object, either of type
554
+ # {::Google::Cloud::ServiceUsage::V1::BatchEnableServicesRequest} or an equivalent Hash.
555
+ #
556
+ # @param request [::Google::Cloud::ServiceUsage::V1::BatchEnableServicesRequest, ::Hash]
557
+ # A request object representing the call parameters. Required. To specify no
558
+ # parameters, or to keep all the default parameter values, pass an empty Hash.
559
+ # @param options [::Gapic::CallOptions, ::Hash]
560
+ # Overrides the default settings for this call, e.g, timeout, retries etc. Optional.
561
+ #
562
+ # @overload batch_enable_services(parent: nil, service_ids: nil)
563
+ # Pass arguments to `batch_enable_services` via keyword arguments. Note that at
564
+ # least one keyword argument is required. To specify no parameters, or to keep all
565
+ # the default parameter values, pass an empty Hash as a request object (see above).
566
+ #
567
+ # @param parent [::String]
568
+ # Parent to enable services on.
569
+ #
570
+ # An example name would be:
571
+ # `projects/123` where `123` is the project number.
572
+ #
573
+ # The `BatchEnableServices` method currently only supports projects.
574
+ # @param service_ids [::Array<::String>]
575
+ # The identifiers of the services to enable on the project.
576
+ #
577
+ # A valid identifier would be:
578
+ # serviceusage.googleapis.com
579
+ #
580
+ # Enabling services requires that each service is public or is shared with
581
+ # the user enabling the service.
582
+ #
583
+ # A single request can enable a maximum of 20 services at a time. If more
584
+ # than 20 services are specified, the request will fail, and no state changes
585
+ # will occur.
586
+ # @yield [result, operation] Access the result along with the TransportOperation object
587
+ # @yieldparam result [::Gapic::Operation]
588
+ # @yieldparam operation [::Gapic::Rest::TransportOperation]
589
+ #
590
+ # @return [::Gapic::Operation]
591
+ #
592
+ # @raise [::Google::Cloud::Error] if the REST call is aborted.
593
+ #
594
+ # @example Basic example
595
+ # require "google/cloud/service_usage/v1"
596
+ #
597
+ # # Create a client object. The client can be reused for multiple calls.
598
+ # client = Google::Cloud::ServiceUsage::V1::ServiceUsage::Rest::Client.new
599
+ #
600
+ # # Create a request. To set request fields, pass in keyword arguments.
601
+ # request = Google::Cloud::ServiceUsage::V1::BatchEnableServicesRequest.new
602
+ #
603
+ # # Call the batch_enable_services method.
604
+ # result = client.batch_enable_services request
605
+ #
606
+ # # The returned object is of type Gapic::Operation. You can use it to
607
+ # # check the status of an operation, cancel it, or wait for results.
608
+ # # Here is how to wait for a response.
609
+ # result.wait_until_done! timeout: 60
610
+ # if result.response?
611
+ # p result.response
612
+ # else
613
+ # puts "No response received."
614
+ # end
615
+ #
616
+ def batch_enable_services request, options = nil
617
+ raise ::ArgumentError, "request must be provided" if request.nil?
618
+
619
+ request = ::Gapic::Protobuf.coerce request, to: ::Google::Cloud::ServiceUsage::V1::BatchEnableServicesRequest
620
+
621
+ # Converts hash and nil to an options object
622
+ options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h
623
+
624
+ # Customize the options with defaults
625
+ call_metadata = @config.rpcs.batch_enable_services.metadata.to_h
626
+
627
+ # Set x-goog-api-client and x-goog-user-project headers
628
+ call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \
629
+ lib_name: @config.lib_name, lib_version: @config.lib_version,
630
+ gapic_version: ::Google::Cloud::ServiceUsage::V1::VERSION,
631
+ transports_version_send: [:rest]
632
+
633
+ call_metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id
634
+
635
+ options.apply_defaults timeout: @config.rpcs.batch_enable_services.timeout,
636
+ metadata: call_metadata,
637
+ retry_policy: @config.rpcs.batch_enable_services.retry_policy
638
+
639
+ options.apply_defaults timeout: @config.timeout,
640
+ metadata: @config.metadata,
641
+ retry_policy: @config.retry_policy
642
+
643
+ @service_usage_stub.batch_enable_services request, options do |result, operation|
644
+ result = ::Gapic::Operation.new result, @operations_client, options: options
645
+ yield result, operation if block_given?
646
+ return result
647
+ end
648
+ rescue ::Gapic::Rest::Error => e
649
+ raise ::Google::Cloud::Error.from_error(e)
650
+ end
651
+
652
+ ##
653
+ # Returns the service configurations and enabled states for a given list of
654
+ # services.
655
+ #
656
+ # @overload batch_get_services(request, options = nil)
657
+ # Pass arguments to `batch_get_services` via a request object, either of type
658
+ # {::Google::Cloud::ServiceUsage::V1::BatchGetServicesRequest} or an equivalent Hash.
659
+ #
660
+ # @param request [::Google::Cloud::ServiceUsage::V1::BatchGetServicesRequest, ::Hash]
661
+ # A request object representing the call parameters. Required. To specify no
662
+ # parameters, or to keep all the default parameter values, pass an empty Hash.
663
+ # @param options [::Gapic::CallOptions, ::Hash]
664
+ # Overrides the default settings for this call, e.g, timeout, retries etc. Optional.
665
+ #
666
+ # @overload batch_get_services(parent: nil, names: nil)
667
+ # Pass arguments to `batch_get_services` via keyword arguments. Note that at
668
+ # least one keyword argument is required. To specify no parameters, or to keep all
669
+ # the default parameter values, pass an empty Hash as a request object (see above).
670
+ #
671
+ # @param parent [::String]
672
+ # Parent to retrieve services from.
673
+ # If this is set, the parent of all of the services specified in `names` must
674
+ # match this field. An example name would be: `projects/123` where `123` is
675
+ # the project number. The `BatchGetServices` method currently only supports
676
+ # projects.
677
+ # @param names [::Array<::String>]
678
+ # Names of the services to retrieve.
679
+ #
680
+ # An example name would be:
681
+ # `projects/123/services/serviceusage.googleapis.com` where `123` is the
682
+ # project number.
683
+ # A single request can get a maximum of 30 services at a time.
684
+ # @yield [result, operation] Access the result along with the TransportOperation object
685
+ # @yieldparam result [::Google::Cloud::ServiceUsage::V1::BatchGetServicesResponse]
686
+ # @yieldparam operation [::Gapic::Rest::TransportOperation]
687
+ #
688
+ # @return [::Google::Cloud::ServiceUsage::V1::BatchGetServicesResponse]
689
+ #
690
+ # @raise [::Google::Cloud::Error] if the REST call is aborted.
691
+ #
692
+ # @example Basic example
693
+ # require "google/cloud/service_usage/v1"
694
+ #
695
+ # # Create a client object. The client can be reused for multiple calls.
696
+ # client = Google::Cloud::ServiceUsage::V1::ServiceUsage::Rest::Client.new
697
+ #
698
+ # # Create a request. To set request fields, pass in keyword arguments.
699
+ # request = Google::Cloud::ServiceUsage::V1::BatchGetServicesRequest.new
700
+ #
701
+ # # Call the batch_get_services method.
702
+ # result = client.batch_get_services request
703
+ #
704
+ # # The returned object is of type Google::Cloud::ServiceUsage::V1::BatchGetServicesResponse.
705
+ # p result
706
+ #
707
+ def batch_get_services request, options = nil
708
+ raise ::ArgumentError, "request must be provided" if request.nil?
709
+
710
+ request = ::Gapic::Protobuf.coerce request, to: ::Google::Cloud::ServiceUsage::V1::BatchGetServicesRequest
711
+
712
+ # Converts hash and nil to an options object
713
+ options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h
714
+
715
+ # Customize the options with defaults
716
+ call_metadata = @config.rpcs.batch_get_services.metadata.to_h
717
+
718
+ # Set x-goog-api-client and x-goog-user-project headers
719
+ call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \
720
+ lib_name: @config.lib_name, lib_version: @config.lib_version,
721
+ gapic_version: ::Google::Cloud::ServiceUsage::V1::VERSION,
722
+ transports_version_send: [:rest]
723
+
724
+ call_metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id
725
+
726
+ options.apply_defaults timeout: @config.rpcs.batch_get_services.timeout,
727
+ metadata: call_metadata,
728
+ retry_policy: @config.rpcs.batch_get_services.retry_policy
729
+
730
+ options.apply_defaults timeout: @config.timeout,
731
+ metadata: @config.metadata,
732
+ retry_policy: @config.retry_policy
733
+
734
+ @service_usage_stub.batch_get_services request, options do |result, operation|
735
+ yield result, operation if block_given?
736
+ return result
737
+ end
738
+ rescue ::Gapic::Rest::Error => e
739
+ raise ::Google::Cloud::Error.from_error(e)
740
+ end
741
+
742
+ ##
743
+ # Configuration class for the ServiceUsage REST API.
744
+ #
745
+ # This class represents the configuration for ServiceUsage REST,
746
+ # providing control over timeouts, retry behavior, logging, transport
747
+ # parameters, and other low-level controls. Certain parameters can also be
748
+ # applied individually to specific RPCs. See
749
+ # {::Google::Cloud::ServiceUsage::V1::ServiceUsage::Rest::Client::Configuration::Rpcs}
750
+ # for a list of RPCs that can be configured independently.
751
+ #
752
+ # Configuration can be applied globally to all clients, or to a single client
753
+ # on construction.
754
+ #
755
+ # @example
756
+ #
757
+ # # Modify the global config, setting the timeout for
758
+ # # enable_service to 20 seconds,
759
+ # # and all remaining timeouts to 10 seconds.
760
+ # ::Google::Cloud::ServiceUsage::V1::ServiceUsage::Rest::Client.configure do |config|
761
+ # config.timeout = 10.0
762
+ # config.rpcs.enable_service.timeout = 20.0
763
+ # end
764
+ #
765
+ # # Apply the above configuration only to a new client.
766
+ # client = ::Google::Cloud::ServiceUsage::V1::ServiceUsage::Rest::Client.new do |config|
767
+ # config.timeout = 10.0
768
+ # config.rpcs.enable_service.timeout = 20.0
769
+ # end
770
+ #
771
+ # @!attribute [rw] endpoint
772
+ # The hostname or hostname:port of the service endpoint.
773
+ # Defaults to `"serviceusage.googleapis.com"`.
774
+ # @return [::String]
775
+ # @!attribute [rw] credentials
776
+ # Credentials to send with calls. You may provide any of the following types:
777
+ # * (`String`) The path to a service account key file in JSON format
778
+ # * (`Hash`) A service account key as a Hash
779
+ # * (`Google::Auth::Credentials`) A googleauth credentials object
780
+ # (see the [googleauth docs](https://rubydoc.info/gems/googleauth/Google/Auth/Credentials))
781
+ # * (`Signet::OAuth2::Client`) A signet oauth2 client object
782
+ # (see the [signet docs](https://rubydoc.info/gems/signet/Signet/OAuth2/Client))
783
+ # * (`nil`) indicating no credentials
784
+ # @return [::Object]
785
+ # @!attribute [rw] scope
786
+ # The OAuth scopes
787
+ # @return [::Array<::String>]
788
+ # @!attribute [rw] lib_name
789
+ # The library name as recorded in instrumentation and logging
790
+ # @return [::String]
791
+ # @!attribute [rw] lib_version
792
+ # The library version as recorded in instrumentation and logging
793
+ # @return [::String]
794
+ # @!attribute [rw] timeout
795
+ # The call timeout in seconds.
796
+ # @return [::Numeric]
797
+ # @!attribute [rw] metadata
798
+ # Additional headers to be sent with the call.
799
+ # @return [::Hash{::Symbol=>::String}]
800
+ # @!attribute [rw] retry_policy
801
+ # The retry policy. The value is a hash with the following keys:
802
+ # * `:initial_delay` (*type:* `Numeric`) - The initial delay in seconds.
803
+ # * `:max_delay` (*type:* `Numeric`) - The max delay in seconds.
804
+ # * `:multiplier` (*type:* `Numeric`) - The incremental backoff multiplier.
805
+ # * `:retry_codes` (*type:* `Array<String>`) - The error codes that should
806
+ # trigger a retry.
807
+ # @return [::Hash]
808
+ # @!attribute [rw] quota_project
809
+ # A separate project against which to charge quota.
810
+ # @return [::String]
811
+ #
812
+ class Configuration
813
+ extend ::Gapic::Config
814
+
815
+ DEFAULT_ENDPOINT = "serviceusage.googleapis.com"
816
+
817
+ config_attr :endpoint, DEFAULT_ENDPOINT, ::String
818
+ config_attr :credentials, nil do |value|
819
+ allowed = [::String, ::Hash, ::Proc, ::Symbol, ::Google::Auth::Credentials, ::Signet::OAuth2::Client, nil]
820
+ allowed.any? { |klass| klass === value }
821
+ end
822
+ config_attr :scope, nil, ::String, ::Array, nil
823
+ config_attr :lib_name, nil, ::String, nil
824
+ config_attr :lib_version, nil, ::String, nil
825
+ config_attr :timeout, nil, ::Numeric, nil
826
+ config_attr :metadata, nil, ::Hash, nil
827
+ config_attr :retry_policy, nil, ::Hash, ::Proc, nil
828
+ config_attr :quota_project, nil, ::String, nil
829
+
830
+ # @private
831
+ def initialize parent_config = nil
832
+ @parent_config = parent_config unless parent_config.nil?
833
+
834
+ yield self if block_given?
835
+ end
836
+
837
+ ##
838
+ # Configurations for individual RPCs
839
+ # @return [Rpcs]
840
+ #
841
+ def rpcs
842
+ @rpcs ||= begin
843
+ parent_rpcs = nil
844
+ parent_rpcs = @parent_config.rpcs if defined?(@parent_config) && @parent_config.respond_to?(:rpcs)
845
+ Rpcs.new parent_rpcs
846
+ end
847
+ end
848
+
849
+ ##
850
+ # Configuration RPC class for the ServiceUsage API.
851
+ #
852
+ # Includes fields providing the configuration for each RPC in this service.
853
+ # Each configuration object is of type `Gapic::Config::Method` and includes
854
+ # the following configuration fields:
855
+ #
856
+ # * `timeout` (*type:* `Numeric`) - The call timeout in seconds
857
+ # * `metadata` (*type:* `Hash{Symbol=>String}`) - Additional headers
858
+ # * `retry_policy (*type:* `Hash`) - The retry policy. The policy fields
859
+ # include the following keys:
860
+ # * `:initial_delay` (*type:* `Numeric`) - The initial delay in seconds.
861
+ # * `:max_delay` (*type:* `Numeric`) - The max delay in seconds.
862
+ # * `:multiplier` (*type:* `Numeric`) - The incremental backoff multiplier.
863
+ # * `:retry_codes` (*type:* `Array<String>`) - The error codes that should
864
+ # trigger a retry.
865
+ #
866
+ class Rpcs
867
+ ##
868
+ # RPC-specific configuration for `enable_service`
869
+ # @return [::Gapic::Config::Method]
870
+ #
871
+ attr_reader :enable_service
872
+ ##
873
+ # RPC-specific configuration for `disable_service`
874
+ # @return [::Gapic::Config::Method]
875
+ #
876
+ attr_reader :disable_service
877
+ ##
878
+ # RPC-specific configuration for `get_service`
879
+ # @return [::Gapic::Config::Method]
880
+ #
881
+ attr_reader :get_service
882
+ ##
883
+ # RPC-specific configuration for `list_services`
884
+ # @return [::Gapic::Config::Method]
885
+ #
886
+ attr_reader :list_services
887
+ ##
888
+ # RPC-specific configuration for `batch_enable_services`
889
+ # @return [::Gapic::Config::Method]
890
+ #
891
+ attr_reader :batch_enable_services
892
+ ##
893
+ # RPC-specific configuration for `batch_get_services`
894
+ # @return [::Gapic::Config::Method]
895
+ #
896
+ attr_reader :batch_get_services
897
+
898
+ # @private
899
+ def initialize parent_rpcs = nil
900
+ enable_service_config = parent_rpcs.enable_service if parent_rpcs.respond_to? :enable_service
901
+ @enable_service = ::Gapic::Config::Method.new enable_service_config
902
+ disable_service_config = parent_rpcs.disable_service if parent_rpcs.respond_to? :disable_service
903
+ @disable_service = ::Gapic::Config::Method.new disable_service_config
904
+ get_service_config = parent_rpcs.get_service if parent_rpcs.respond_to? :get_service
905
+ @get_service = ::Gapic::Config::Method.new get_service_config
906
+ list_services_config = parent_rpcs.list_services if parent_rpcs.respond_to? :list_services
907
+ @list_services = ::Gapic::Config::Method.new list_services_config
908
+ batch_enable_services_config = parent_rpcs.batch_enable_services if parent_rpcs.respond_to? :batch_enable_services
909
+ @batch_enable_services = ::Gapic::Config::Method.new batch_enable_services_config
910
+ batch_get_services_config = parent_rpcs.batch_get_services if parent_rpcs.respond_to? :batch_get_services
911
+ @batch_get_services = ::Gapic::Config::Method.new batch_get_services_config
912
+
913
+ yield self if block_given?
914
+ end
915
+ end
916
+ end
917
+ end
918
+ end
919
+ end
920
+ end
921
+ end
922
+ end
923
+ end