google-iam-v2 0.1.1 → 0.2.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,791 @@
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 "gapic/operation"
20
+
21
+ module Google
22
+ module Iam
23
+ module V2
24
+ module Policies
25
+ module Rest
26
+ # Service that implements Longrunning Operations API.
27
+ class Operations
28
+ # @private
29
+ attr_reader :operations_stub
30
+
31
+ ##
32
+ # Configuration for the Policies Operations API.
33
+ #
34
+ # @yield [config] Configure the Operations client.
35
+ # @yieldparam config [Operations::Configuration]
36
+ #
37
+ # @return [Operations::Configuration]
38
+ #
39
+ def self.configure
40
+ @configure ||= Operations::Configuration.new
41
+ yield @configure if block_given?
42
+ @configure
43
+ end
44
+
45
+ ##
46
+ # Configure the Policies Operations instance.
47
+ #
48
+ # The configuration is set to the derived mode, meaning that values can be changed,
49
+ # but structural changes (adding new fields, etc.) are not allowed. Structural changes
50
+ # should be made on {Operations.configure}.
51
+ #
52
+ # @yield [config] Configure the Operations client.
53
+ # @yieldparam config [Operations::Configuration]
54
+ #
55
+ # @return [Operations::Configuration]
56
+ #
57
+ def configure
58
+ yield @config if block_given?
59
+ @config
60
+ end
61
+
62
+ ##
63
+ # Create a new Operations client object.
64
+ #
65
+ # @yield [config] Configure the Client client.
66
+ # @yieldparam config [Operations::Configuration]
67
+ #
68
+ def initialize
69
+ # Create the configuration object
70
+ @config = Configuration.new Operations.configure
71
+
72
+ # Yield the configuration if needed
73
+ yield @config if block_given?
74
+
75
+ # Create credentials
76
+ credentials = @config.credentials
77
+ credentials ||= Credentials.default scope: @config.scope
78
+ if credentials.is_a?(::String) || credentials.is_a?(::Hash)
79
+ credentials = Credentials.new credentials, scope: @config.scope
80
+ end
81
+
82
+ @quota_project_id = @config.quota_project
83
+ @quota_project_id ||= credentials.quota_project_id if credentials.respond_to? :quota_project_id
84
+
85
+ @operations_stub = OperationsServiceStub.new(
86
+ endpoint: @config.endpoint,
87
+ credentials: credentials
88
+ )
89
+
90
+ # Used by an LRO wrapper for some methods of this service
91
+ @operations_client = self
92
+ end
93
+
94
+ # Service calls
95
+
96
+ ##
97
+ # Lists operations that match the specified filter in the request. If the
98
+ # server doesn't support this method, it returns `UNIMPLEMENTED`.
99
+ #
100
+ # NOTE: the `name` binding allows API services to override the binding
101
+ # to use different resource name schemes, such as `users/*/operations`. To
102
+ # override the binding, API services can add a binding such as
103
+ # `"/v1/{name=users/*}/operations"` to their service configuration.
104
+ # For backwards compatibility, the default name includes the operations
105
+ # collection id, however overriding users must ensure the name binding
106
+ # is the parent resource, without the operations collection id.
107
+ #
108
+ # @overload list_operations(request, options = nil)
109
+ # Pass arguments to `list_operations` via a request object, either of type
110
+ # {::Google::Longrunning::ListOperationsRequest} or an equivalent Hash.
111
+ #
112
+ # @param request [::Google::Longrunning::ListOperationsRequest, ::Hash]
113
+ # A request object representing the call parameters. Required. To specify no
114
+ # parameters, or to keep all the default parameter values, pass an empty Hash.
115
+ # @param options [::Gapic::CallOptions, ::Hash]
116
+ # Overrides the default settings for this call, e.g, timeout, retries etc. Optional.
117
+ #
118
+ # @overload list_operations(name: nil, filter: nil, page_size: nil, page_token: nil)
119
+ # Pass arguments to `list_operations` via keyword arguments. Note that at
120
+ # least one keyword argument is required. To specify no parameters, or to keep all
121
+ # the default parameter values, pass an empty Hash as a request object (see above).
122
+ #
123
+ # @param name [::String]
124
+ # The name of the operation's parent resource.
125
+ # @param filter [::String]
126
+ # The standard list filter.
127
+ # @param page_size [::Integer]
128
+ # The standard list page size.
129
+ # @param page_token [::String]
130
+ # The standard list page token.
131
+ # @yield [result, operation] Access the result along with the TransportOperation object
132
+ # @yieldparam result [::Gapic::Operation]
133
+ # @yieldparam operation [::Gapic::Rest::TransportOperation]
134
+ #
135
+ # @return [::Gapic::Operation]
136
+ #
137
+ # @raise [::Google::Cloud::Error] if the REST call is aborted.
138
+ def list_operations request, options = nil
139
+ raise ::ArgumentError, "request must be provided" if request.nil?
140
+
141
+ request = ::Gapic::Protobuf.coerce request, to: ::Google::Longrunning::ListOperationsRequest
142
+
143
+ # Converts hash and nil to an options object
144
+ options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h
145
+
146
+ # Customize the options with defaults
147
+ call_metadata = @config.rpcs.list_operations.metadata.to_h
148
+
149
+ # Set x-goog-api-client and x-goog-user-project headers
150
+ call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \
151
+ lib_name: @config.lib_name, lib_version: @config.lib_version,
152
+ gapic_version: ::Google::Iam::V2::VERSION,
153
+ transports_version_send: [:rest]
154
+
155
+ call_metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id
156
+
157
+ options.apply_defaults timeout: @config.rpcs.list_operations.timeout,
158
+ metadata: call_metadata,
159
+ retry_policy: @config.rpcs.list_operations.retry_policy
160
+
161
+ options.apply_defaults timeout: @config.timeout,
162
+ metadata: @config.metadata,
163
+ retry_policy: @config.retry_policy
164
+
165
+ @operations_stub.list_operations request, options do |result, operation|
166
+ result = ::Gapic::Rest::PagedEnumerable.new @operations_stub, :list_operations, "operations", request, result, options
167
+ yield result, operation if block_given?
168
+ return result
169
+ end
170
+ rescue ::Gapic::Rest::Error => e
171
+ raise ::Google::Cloud::Error.from_error(e)
172
+ end
173
+
174
+ ##
175
+ # Gets the latest state of a long-running operation. Clients can use this
176
+ # method to poll the operation result at intervals as recommended by the API
177
+ # service.
178
+ #
179
+ # @overload get_operation(request, options = nil)
180
+ # Pass arguments to `get_operation` via a request object, either of type
181
+ # {::Google::Longrunning::GetOperationRequest} or an equivalent Hash.
182
+ #
183
+ # @param request [::Google::Longrunning::GetOperationRequest, ::Hash]
184
+ # A request object representing the call parameters. Required. To specify no
185
+ # parameters, or to keep all the default parameter values, pass an empty Hash.
186
+ # @param options [::Gapic::CallOptions, ::Hash]
187
+ # Overrides the default settings for this call, e.g, timeout, retries etc. Optional.
188
+ #
189
+ # @overload get_operation(name: nil)
190
+ # Pass arguments to `get_operation` via keyword arguments. Note that at
191
+ # least one keyword argument is required. To specify no parameters, or to keep all
192
+ # the default parameter values, pass an empty Hash as a request object (see above).
193
+ #
194
+ # @param name [::String]
195
+ # The name of the operation resource.
196
+ # @yield [result, operation] Access the result along with the TransportOperation object
197
+ # @yieldparam result [::Gapic::Operation]
198
+ # @yieldparam operation [::Gapic::Rest::TransportOperation]
199
+ #
200
+ # @return [::Gapic::Operation]
201
+ #
202
+ # @raise [::Google::Cloud::Error] if the REST call is aborted.
203
+ def get_operation request, options = nil
204
+ raise ::ArgumentError, "request must be provided" if request.nil?
205
+
206
+ request = ::Gapic::Protobuf.coerce request, to: ::Google::Longrunning::GetOperationRequest
207
+
208
+ # Converts hash and nil to an options object
209
+ options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h
210
+
211
+ # Customize the options with defaults
212
+ call_metadata = @config.rpcs.get_operation.metadata.to_h
213
+
214
+ # Set x-goog-api-client and x-goog-user-project headers
215
+ call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \
216
+ lib_name: @config.lib_name, lib_version: @config.lib_version,
217
+ gapic_version: ::Google::Iam::V2::VERSION,
218
+ transports_version_send: [:rest]
219
+
220
+ call_metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id
221
+
222
+ options.apply_defaults timeout: @config.rpcs.get_operation.timeout,
223
+ metadata: call_metadata,
224
+ retry_policy: @config.rpcs.get_operation.retry_policy
225
+
226
+ options.apply_defaults timeout: @config.timeout,
227
+ metadata: @config.metadata,
228
+ retry_policy: @config.retry_policy
229
+
230
+ @operations_stub.get_operation request, options do |result, operation|
231
+ result = ::Gapic::Operation.new result, @operations_client, options: options
232
+ yield result, operation if block_given?
233
+ return result
234
+ end
235
+ rescue ::Gapic::Rest::Error => e
236
+ raise ::Google::Cloud::Error.from_error(e)
237
+ end
238
+
239
+ ##
240
+ # Deletes a long-running operation. This method indicates that the client is
241
+ # no longer interested in the operation result. It does not cancel the
242
+ # operation. If the server doesn't support this method, it returns
243
+ # `google.rpc.Code.UNIMPLEMENTED`.
244
+ #
245
+ # @overload delete_operation(request, options = nil)
246
+ # Pass arguments to `delete_operation` via a request object, either of type
247
+ # {::Google::Longrunning::DeleteOperationRequest} or an equivalent Hash.
248
+ #
249
+ # @param request [::Google::Longrunning::DeleteOperationRequest, ::Hash]
250
+ # A request object representing the call parameters. Required. To specify no
251
+ # parameters, or to keep all the default parameter values, pass an empty Hash.
252
+ # @param options [::Gapic::CallOptions, ::Hash]
253
+ # Overrides the default settings for this call, e.g, timeout, retries etc. Optional.
254
+ #
255
+ # @overload delete_operation(name: nil)
256
+ # Pass arguments to `delete_operation` via keyword arguments. Note that at
257
+ # least one keyword argument is required. To specify no parameters, or to keep all
258
+ # the default parameter values, pass an empty Hash as a request object (see above).
259
+ #
260
+ # @param name [::String]
261
+ # The name of the operation resource to be deleted.
262
+ # @yield [result, operation] Access the result along with the TransportOperation object
263
+ # @yieldparam result [::Google::Protobuf::Empty]
264
+ # @yieldparam operation [::Gapic::Rest::TransportOperation]
265
+ #
266
+ # @return [::Google::Protobuf::Empty]
267
+ #
268
+ # @raise [::Google::Cloud::Error] if the REST call is aborted.
269
+ def delete_operation request, options = nil
270
+ raise ::ArgumentError, "request must be provided" if request.nil?
271
+
272
+ request = ::Gapic::Protobuf.coerce request, to: ::Google::Longrunning::DeleteOperationRequest
273
+
274
+ # Converts hash and nil to an options object
275
+ options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h
276
+
277
+ # Customize the options with defaults
278
+ call_metadata = @config.rpcs.delete_operation.metadata.to_h
279
+
280
+ # Set x-goog-api-client and x-goog-user-project headers
281
+ call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \
282
+ lib_name: @config.lib_name, lib_version: @config.lib_version,
283
+ gapic_version: ::Google::Iam::V2::VERSION,
284
+ transports_version_send: [:rest]
285
+
286
+ call_metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id
287
+
288
+ options.apply_defaults timeout: @config.rpcs.delete_operation.timeout,
289
+ metadata: call_metadata,
290
+ retry_policy: @config.rpcs.delete_operation.retry_policy
291
+
292
+ options.apply_defaults timeout: @config.timeout,
293
+ metadata: @config.metadata,
294
+ retry_policy: @config.retry_policy
295
+
296
+ @operations_stub.delete_operation request, options do |result, operation|
297
+ yield result, operation if block_given?
298
+ return result
299
+ end
300
+ rescue ::Gapic::Rest::Error => e
301
+ raise ::Google::Cloud::Error.from_error(e)
302
+ end
303
+
304
+ ##
305
+ # Starts asynchronous cancellation on a long-running operation. The server
306
+ # makes a best effort to cancel the operation, but success is not
307
+ # guaranteed. If the server doesn't support this method, it returns
308
+ # `google.rpc.Code.UNIMPLEMENTED`. Clients can use
309
+ # Operations.GetOperation or
310
+ # other methods to check whether the cancellation succeeded or whether the
311
+ # operation completed despite cancellation. On successful cancellation,
312
+ # the operation is not deleted; instead, it becomes an operation with
313
+ # an {::Google::Longrunning::Operation#error Operation.error} value with a {::Google::Rpc::Status#code google.rpc.Status.code} of 1,
314
+ # corresponding to `Code.CANCELLED`.
315
+ #
316
+ # @overload cancel_operation(request, options = nil)
317
+ # Pass arguments to `cancel_operation` via a request object, either of type
318
+ # {::Google::Longrunning::CancelOperationRequest} or an equivalent Hash.
319
+ #
320
+ # @param request [::Google::Longrunning::CancelOperationRequest, ::Hash]
321
+ # A request object representing the call parameters. Required. To specify no
322
+ # parameters, or to keep all the default parameter values, pass an empty Hash.
323
+ # @param options [::Gapic::CallOptions, ::Hash]
324
+ # Overrides the default settings for this call, e.g, timeout, retries etc. Optional.
325
+ #
326
+ # @overload cancel_operation(name: nil)
327
+ # Pass arguments to `cancel_operation` via keyword arguments. Note that at
328
+ # least one keyword argument is required. To specify no parameters, or to keep all
329
+ # the default parameter values, pass an empty Hash as a request object (see above).
330
+ #
331
+ # @param name [::String]
332
+ # The name of the operation resource to be cancelled.
333
+ # @yield [result, operation] Access the result along with the TransportOperation object
334
+ # @yieldparam result [::Google::Protobuf::Empty]
335
+ # @yieldparam operation [::Gapic::Rest::TransportOperation]
336
+ #
337
+ # @return [::Google::Protobuf::Empty]
338
+ #
339
+ # @raise [::Google::Cloud::Error] if the REST call is aborted.
340
+ def cancel_operation request, options = nil
341
+ raise ::ArgumentError, "request must be provided" if request.nil?
342
+
343
+ request = ::Gapic::Protobuf.coerce request, to: ::Google::Longrunning::CancelOperationRequest
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.cancel_operation.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::Iam::V2::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.cancel_operation.timeout,
360
+ metadata: call_metadata,
361
+ retry_policy: @config.rpcs.cancel_operation.retry_policy
362
+
363
+ options.apply_defaults timeout: @config.timeout,
364
+ metadata: @config.metadata,
365
+ retry_policy: @config.retry_policy
366
+
367
+ @operations_stub.cancel_operation request, options do |result, operation|
368
+ yield result, operation if block_given?
369
+ return result
370
+ end
371
+ rescue ::Gapic::Rest::Error => e
372
+ raise ::Google::Cloud::Error.from_error(e)
373
+ end
374
+
375
+ ##
376
+ # Configuration class for the Operations REST API.
377
+ #
378
+ # This class represents the configuration for Operations REST,
379
+ # providing control over timeouts, retry behavior, logging, transport
380
+ # parameters, and other low-level controls. Certain parameters can also be
381
+ # applied individually to specific RPCs. See
382
+ # {::Google::Longrunning::Operations::Rest::Client::Configuration::Rpcs}
383
+ # for a list of RPCs that can be configured independently.
384
+ #
385
+ # Configuration can be applied globally to all clients, or to a single client
386
+ # on construction.
387
+ #
388
+ # @example
389
+ #
390
+ # # Modify the global config, setting the timeout for
391
+ # # list_operations to 20 seconds,
392
+ # # and all remaining timeouts to 10 seconds.
393
+ # ::Google::Longrunning::Operations::Rest::Client.configure do |config|
394
+ # config.timeout = 10.0
395
+ # config.rpcs.list_operations.timeout = 20.0
396
+ # end
397
+ #
398
+ # # Apply the above configuration only to a new client.
399
+ # client = ::Google::Longrunning::Operations::Rest::Client.new do |config|
400
+ # config.timeout = 10.0
401
+ # config.rpcs.list_operations.timeout = 20.0
402
+ # end
403
+ #
404
+ # @!attribute [rw] endpoint
405
+ # The hostname or hostname:port of the service endpoint.
406
+ # Defaults to `"iam.googleapis.com"`.
407
+ # @return [::String]
408
+ # @!attribute [rw] credentials
409
+ # Credentials to send with calls. You may provide any of the following types:
410
+ # * (`String`) The path to a service account key file in JSON format
411
+ # * (`Hash`) A service account key as a Hash
412
+ # * (`Google::Auth::Credentials`) A googleauth credentials object
413
+ # (see the [googleauth docs](https://googleapis.dev/ruby/googleauth/latest/index.html))
414
+ # * (`Signet::OAuth2::Client`) A signet oauth2 client object
415
+ # (see the [signet docs](https://googleapis.dev/ruby/signet/latest/Signet/OAuth2/Client.html))
416
+ # * (`nil`) indicating no credentials
417
+ # @return [::Object]
418
+ # @!attribute [rw] scope
419
+ # The OAuth scopes
420
+ # @return [::Array<::String>]
421
+ # @!attribute [rw] lib_name
422
+ # The library name as recorded in instrumentation and logging
423
+ # @return [::String]
424
+ # @!attribute [rw] lib_version
425
+ # The library version as recorded in instrumentation and logging
426
+ # @return [::String]
427
+ # @!attribute [rw] timeout
428
+ # The call timeout in seconds.
429
+ # @return [::Numeric]
430
+ # @!attribute [rw] metadata
431
+ # Additional headers to be sent with the call.
432
+ # @return [::Hash{::Symbol=>::String}]
433
+ # @!attribute [rw] retry_policy
434
+ # The retry policy. The value is a hash with the following keys:
435
+ # * `:initial_delay` (*type:* `Numeric`) - The initial delay in seconds.
436
+ # * `:max_delay` (*type:* `Numeric`) - The max delay in seconds.
437
+ # * `:multiplier` (*type:* `Numeric`) - The incremental backoff multiplier.
438
+ # * `:retry_codes` (*type:* `Array<String>`) - The error codes that should
439
+ # trigger a retry.
440
+ # @return [::Hash]
441
+ # @!attribute [rw] quota_project
442
+ # A separate project against which to charge quota.
443
+ # @return [::String]
444
+ #
445
+ class Configuration
446
+ extend ::Gapic::Config
447
+
448
+ config_attr :endpoint, "iam.googleapis.com", ::String
449
+ config_attr :credentials, nil do |value|
450
+ allowed = [::String, ::Hash, ::Proc, ::Symbol, ::Google::Auth::Credentials, ::Signet::OAuth2::Client, nil]
451
+ allowed.any? { |klass| klass === value }
452
+ end
453
+ config_attr :scope, nil, ::String, ::Array, nil
454
+ config_attr :lib_name, nil, ::String, nil
455
+ config_attr :lib_version, nil, ::String, nil
456
+ config_attr :timeout, nil, ::Numeric, nil
457
+ config_attr :metadata, nil, ::Hash, nil
458
+ config_attr :retry_policy, nil, ::Hash, ::Proc, nil
459
+ config_attr :quota_project, nil, ::String, nil
460
+
461
+ # @private
462
+ def initialize parent_config = nil
463
+ @parent_config = parent_config unless parent_config.nil?
464
+
465
+ yield self if block_given?
466
+ end
467
+
468
+ ##
469
+ # Configurations for individual RPCs
470
+ # @return [Rpcs]
471
+ #
472
+ def rpcs
473
+ @rpcs ||= begin
474
+ parent_rpcs = nil
475
+ parent_rpcs = @parent_config.rpcs if defined?(@parent_config) && @parent_config.respond_to?(:rpcs)
476
+ Rpcs.new parent_rpcs
477
+ end
478
+ end
479
+
480
+ ##
481
+ # Configuration RPC class for the Operations API.
482
+ #
483
+ # Includes fields providing the configuration for each RPC in this service.
484
+ # Each configuration object is of type `Gapic::Config::Method` and includes
485
+ # the following configuration fields:
486
+ #
487
+ # * `timeout` (*type:* `Numeric`) - The call timeout in seconds
488
+ # * `metadata` (*type:* `Hash{Symbol=>String}`) - Additional headers
489
+ # * `retry_policy (*type:* `Hash`) - The retry policy. The policy fields
490
+ # include the following keys:
491
+ # * `:initial_delay` (*type:* `Numeric`) - The initial delay in seconds.
492
+ # * `:max_delay` (*type:* `Numeric`) - The max delay in seconds.
493
+ # * `:multiplier` (*type:* `Numeric`) - The incremental backoff multiplier.
494
+ # * `:retry_codes` (*type:* `Array<String>`) - The error codes that should
495
+ # trigger a retry.
496
+ #
497
+ class Rpcs
498
+ ##
499
+ # RPC-specific configuration for `list_operations`
500
+ # @return [::Gapic::Config::Method]
501
+ #
502
+ attr_reader :list_operations
503
+ ##
504
+ # RPC-specific configuration for `get_operation`
505
+ # @return [::Gapic::Config::Method]
506
+ #
507
+ attr_reader :get_operation
508
+ ##
509
+ # RPC-specific configuration for `delete_operation`
510
+ # @return [::Gapic::Config::Method]
511
+ #
512
+ attr_reader :delete_operation
513
+ ##
514
+ # RPC-specific configuration for `cancel_operation`
515
+ # @return [::Gapic::Config::Method]
516
+ #
517
+ attr_reader :cancel_operation
518
+
519
+ # @private
520
+ def initialize parent_rpcs = nil
521
+ list_operations_config = parent_rpcs.list_operations if parent_rpcs.respond_to? :list_operations
522
+ @list_operations = ::Gapic::Config::Method.new list_operations_config
523
+ get_operation_config = parent_rpcs.get_operation if parent_rpcs.respond_to? :get_operation
524
+ @get_operation = ::Gapic::Config::Method.new get_operation_config
525
+ delete_operation_config = parent_rpcs.delete_operation if parent_rpcs.respond_to? :delete_operation
526
+ @delete_operation = ::Gapic::Config::Method.new delete_operation_config
527
+ cancel_operation_config = parent_rpcs.cancel_operation if parent_rpcs.respond_to? :cancel_operation
528
+ @cancel_operation = ::Gapic::Config::Method.new cancel_operation_config
529
+
530
+ yield self if block_given?
531
+ end
532
+ end
533
+ end
534
+ end
535
+
536
+ ##
537
+ # @private
538
+ # REST service stub for the Longrunning Operations API.
539
+ # Service stub contains baseline method implementations
540
+ # including transcoding, making the REST call, and deserialing the response.
541
+ class OperationsServiceStub
542
+ def initialize endpoint:, credentials:
543
+ # These require statements are intentionally placed here to initialize
544
+ # the REST modules only when it's required.
545
+ require "gapic/rest"
546
+
547
+ @client_stub = ::Gapic::Rest::ClientStub.new endpoint: endpoint, credentials: credentials
548
+ end
549
+
550
+ ##
551
+ # Baseline implementation for the list_operations REST call
552
+ #
553
+ # @param request_pb [::Google::Longrunning::ListOperationsRequest]
554
+ # A request object representing the call parameters. Required.
555
+ # @param options [::Gapic::CallOptions]
556
+ # Overrides the default settings for this call, e.g, timeout, retries etc. Optional.
557
+ #
558
+ # @yield [result, operation] Access the result along with the TransportOperation object
559
+ # @yieldparam result [::Google::Longrunning::ListOperationsResponse]
560
+ # @yieldparam operation [::Gapic::Rest::TransportOperation]
561
+ #
562
+ # @return [::Google::Longrunning::ListOperationsResponse]
563
+ # A result object deserialized from the server's reply
564
+ def list_operations request_pb, options = nil
565
+ raise ::ArgumentError, "request must be provided" if request_pb.nil?
566
+
567
+ verb, uri, query_string_params, body = OperationsServiceStub.transcode_list_operations_request request_pb
568
+ query_string_params = if query_string_params.any?
569
+ query_string_params.to_h { |p| p.split("=", 2) }
570
+ else
571
+ {}
572
+ end
573
+
574
+ response = @client_stub.make_http_request(
575
+ verb,
576
+ uri: uri,
577
+ body: body || "",
578
+ params: query_string_params,
579
+ options: options
580
+ )
581
+ operation = ::Gapic::Rest::TransportOperation.new response
582
+ result = ::Google::Longrunning::ListOperationsResponse.decode_json response.body, ignore_unknown_fields: true
583
+
584
+ yield result, operation if block_given?
585
+ result
586
+ end
587
+
588
+ ##
589
+ # Baseline implementation for the get_operation REST call
590
+ #
591
+ # @param request_pb [::Google::Longrunning::GetOperationRequest]
592
+ # A request object representing the call parameters. Required.
593
+ # @param options [::Gapic::CallOptions]
594
+ # Overrides the default settings for this call, e.g, timeout, retries etc. Optional.
595
+ #
596
+ # @yield [result, operation] Access the result along with the TransportOperation object
597
+ # @yieldparam result [::Google::Longrunning::Operation]
598
+ # @yieldparam operation [::Gapic::Rest::TransportOperation]
599
+ #
600
+ # @return [::Google::Longrunning::Operation]
601
+ # A result object deserialized from the server's reply
602
+ def get_operation request_pb, options = nil
603
+ raise ::ArgumentError, "request must be provided" if request_pb.nil?
604
+
605
+ verb, uri, query_string_params, body = OperationsServiceStub.transcode_get_operation_request request_pb
606
+ query_string_params = if query_string_params.any?
607
+ query_string_params.to_h { |p| p.split("=", 2) }
608
+ else
609
+ {}
610
+ end
611
+
612
+ response = @client_stub.make_http_request(
613
+ verb,
614
+ uri: uri,
615
+ body: body || "",
616
+ params: query_string_params,
617
+ options: options
618
+ )
619
+ operation = ::Gapic::Rest::TransportOperation.new response
620
+ result = ::Google::Longrunning::Operation.decode_json response.body, ignore_unknown_fields: true
621
+
622
+ yield result, operation if block_given?
623
+ result
624
+ end
625
+
626
+ ##
627
+ # Baseline implementation for the delete_operation REST call
628
+ #
629
+ # @param request_pb [::Google::Longrunning::DeleteOperationRequest]
630
+ # A request object representing the call parameters. Required.
631
+ # @param options [::Gapic::CallOptions]
632
+ # Overrides the default settings for this call, e.g, timeout, retries etc. Optional.
633
+ #
634
+ # @yield [result, operation] Access the result along with the TransportOperation object
635
+ # @yieldparam result [::Google::Protobuf::Empty]
636
+ # @yieldparam operation [::Gapic::Rest::TransportOperation]
637
+ #
638
+ # @return [::Google::Protobuf::Empty]
639
+ # A result object deserialized from the server's reply
640
+ def delete_operation request_pb, options = nil
641
+ raise ::ArgumentError, "request must be provided" if request_pb.nil?
642
+
643
+ verb, uri, query_string_params, body = OperationsServiceStub.transcode_delete_operation_request request_pb
644
+ query_string_params = if query_string_params.any?
645
+ query_string_params.to_h { |p| p.split("=", 2) }
646
+ else
647
+ {}
648
+ end
649
+
650
+ response = @client_stub.make_http_request(
651
+ verb,
652
+ uri: uri,
653
+ body: body || "",
654
+ params: query_string_params,
655
+ options: options
656
+ )
657
+ operation = ::Gapic::Rest::TransportOperation.new response
658
+ result = ::Google::Protobuf::Empty.decode_json response.body, ignore_unknown_fields: true
659
+
660
+ yield result, operation if block_given?
661
+ result
662
+ end
663
+
664
+ ##
665
+ # Baseline implementation for the cancel_operation REST call
666
+ #
667
+ # @param request_pb [::Google::Longrunning::CancelOperationRequest]
668
+ # A request object representing the call parameters. Required.
669
+ # @param options [::Gapic::CallOptions]
670
+ # Overrides the default settings for this call, e.g, timeout, retries etc. Optional.
671
+ #
672
+ # @yield [result, operation] Access the result along with the TransportOperation object
673
+ # @yieldparam result [::Google::Protobuf::Empty]
674
+ # @yieldparam operation [::Gapic::Rest::TransportOperation]
675
+ #
676
+ # @return [::Google::Protobuf::Empty]
677
+ # A result object deserialized from the server's reply
678
+ def cancel_operation request_pb, options = nil
679
+ raise ::ArgumentError, "request must be provided" if request_pb.nil?
680
+
681
+ verb, uri, query_string_params, body = OperationsServiceStub.transcode_cancel_operation_request request_pb
682
+ query_string_params = if query_string_params.any?
683
+ query_string_params.to_h { |p| p.split("=", 2) }
684
+ else
685
+ {}
686
+ end
687
+
688
+ response = @client_stub.make_http_request(
689
+ verb,
690
+ uri: uri,
691
+ body: body || "",
692
+ params: query_string_params,
693
+ options: options
694
+ )
695
+ operation = ::Gapic::Rest::TransportOperation.new response
696
+ result = ::Google::Protobuf::Empty.decode_json response.body, ignore_unknown_fields: true
697
+
698
+ yield result, operation if block_given?
699
+ result
700
+ end
701
+
702
+ ##
703
+ # @private
704
+ #
705
+ # GRPC transcoding helper method for the list_operations REST call
706
+ #
707
+ # @param request_pb [::Google::Longrunning::ListOperationsRequest]
708
+ # A request object representing the call parameters. Required.
709
+ # @return [Array(String, [String, nil], Hash{String => String})]
710
+ # Uri, Body, Query string parameters
711
+ def self.transcode_list_operations_request request_pb
712
+ transcoder = Gapic::Rest::GrpcTranscoder.new
713
+ .with_bindings(
714
+ uri_method: :get,
715
+ uri_template: "/v1/{name}",
716
+ matches: [
717
+ ["name", %r{^operations/?$}, false]
718
+ ]
719
+ )
720
+ transcoder.transcode request_pb
721
+ end
722
+
723
+ ##
724
+ # @private
725
+ #
726
+ # GRPC transcoding helper method for the get_operation REST call
727
+ #
728
+ # @param request_pb [::Google::Longrunning::GetOperationRequest]
729
+ # A request object representing the call parameters. Required.
730
+ # @return [Array(String, [String, nil], Hash{String => String})]
731
+ # Uri, Body, Query string parameters
732
+ def self.transcode_get_operation_request request_pb
733
+ transcoder = Gapic::Rest::GrpcTranscoder.new
734
+ .with_bindings(
735
+ uri_method: :get,
736
+ uri_template: "/v2/{name}",
737
+ matches: [
738
+ ["name", %r{^policies/[^/]+/[^/]+/[^/]+/operations/[^/]+/?$}, false]
739
+ ]
740
+ )
741
+ transcoder.transcode request_pb
742
+ end
743
+
744
+ ##
745
+ # @private
746
+ #
747
+ # GRPC transcoding helper method for the delete_operation REST call
748
+ #
749
+ # @param request_pb [::Google::Longrunning::DeleteOperationRequest]
750
+ # A request object representing the call parameters. Required.
751
+ # @return [Array(String, [String, nil], Hash{String => String})]
752
+ # Uri, Body, Query string parameters
753
+ def self.transcode_delete_operation_request request_pb
754
+ transcoder = Gapic::Rest::GrpcTranscoder.new
755
+ .with_bindings(
756
+ uri_method: :delete,
757
+ uri_template: "/v1/{name}",
758
+ matches: [
759
+ ["name", %r{^operations(?:/.*)?$}, true]
760
+ ]
761
+ )
762
+ transcoder.transcode request_pb
763
+ end
764
+
765
+ ##
766
+ # @private
767
+ #
768
+ # GRPC transcoding helper method for the cancel_operation REST call
769
+ #
770
+ # @param request_pb [::Google::Longrunning::CancelOperationRequest]
771
+ # A request object representing the call parameters. Required.
772
+ # @return [Array(String, [String, nil], Hash{String => String})]
773
+ # Uri, Body, Query string parameters
774
+ def self.transcode_cancel_operation_request request_pb
775
+ transcoder = Gapic::Rest::GrpcTranscoder.new
776
+ .with_bindings(
777
+ uri_method: :post,
778
+ uri_template: "/v1/{name}:cancel",
779
+ body: "*",
780
+ matches: [
781
+ ["name", %r{^operations(?:/.*)?$}, true]
782
+ ]
783
+ )
784
+ transcoder.transcode request_pb
785
+ end
786
+ end
787
+ end
788
+ end
789
+ end
790
+ end
791
+ end