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