google-iam-v2 0.1.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,1029 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright 2022 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/iam/v2/policy_pb"
21
+
22
+ module Google
23
+ module Iam
24
+ module V2
25
+ module Policies
26
+ ##
27
+ # Client for the Policies service.
28
+ #
29
+ # An interface for managing Identity and Access Management (IAM) policies.
30
+ #
31
+ class Client
32
+ # @private
33
+ attr_reader :policies_stub
34
+
35
+ ##
36
+ # Configure the Policies Client class.
37
+ #
38
+ # See {::Google::Iam::V2::Policies::Client::Configuration}
39
+ # for a description of the configuration fields.
40
+ #
41
+ # @example
42
+ #
43
+ # # Modify the configuration for all Policies clients
44
+ # ::Google::Iam::V2::Policies::Client.configure do |config|
45
+ # config.timeout = 10.0
46
+ # end
47
+ #
48
+ # @yield [config] Configure the Client client.
49
+ # @yieldparam config [Client::Configuration]
50
+ #
51
+ # @return [Client::Configuration]
52
+ #
53
+ def self.configure
54
+ @configure ||= begin
55
+ namespace = ["Google", "Iam", "V2"]
56
+ parent_config = while namespace.any?
57
+ parent_name = namespace.join "::"
58
+ parent_const = const_get parent_name
59
+ break parent_const.configure if parent_const.respond_to? :configure
60
+ namespace.pop
61
+ end
62
+ default_config = Client::Configuration.new parent_config
63
+
64
+ default_config.rpcs.list_policies.timeout = 60.0
65
+ default_config.rpcs.list_policies.retry_policy = {
66
+ initial_delay: 1.0, max_delay: 10.0, multiplier: 1.3, retry_codes: [14]
67
+ }
68
+
69
+ default_config.rpcs.get_policy.timeout = 60.0
70
+ default_config.rpcs.get_policy.retry_policy = {
71
+ initial_delay: 1.0, max_delay: 10.0, multiplier: 1.3, retry_codes: [14]
72
+ }
73
+
74
+ default_config.rpcs.create_policy.timeout = 60.0
75
+ default_config.rpcs.create_policy.retry_policy = {
76
+ initial_delay: 1.0, max_delay: 10.0, multiplier: 1.3, retry_codes: [14]
77
+ }
78
+
79
+ default_config.rpcs.update_policy.timeout = 60.0
80
+ default_config.rpcs.update_policy.retry_policy = {
81
+ initial_delay: 1.0, max_delay: 10.0, multiplier: 1.3, retry_codes: [14]
82
+ }
83
+
84
+ default_config.rpcs.delete_policy.timeout = 60.0
85
+ default_config.rpcs.delete_policy.retry_policy = {
86
+ initial_delay: 1.0, max_delay: 10.0, multiplier: 1.3, retry_codes: [14]
87
+ }
88
+
89
+ default_config
90
+ end
91
+ yield @configure if block_given?
92
+ @configure
93
+ end
94
+
95
+ ##
96
+ # Configure the Policies Client instance.
97
+ #
98
+ # The configuration is set to the derived mode, meaning that values can be changed,
99
+ # but structural changes (adding new fields, etc.) are not allowed. Structural changes
100
+ # should be made on {Client.configure}.
101
+ #
102
+ # See {::Google::Iam::V2::Policies::Client::Configuration}
103
+ # for a description of the configuration fields.
104
+ #
105
+ # @yield [config] Configure the Client client.
106
+ # @yieldparam config [Client::Configuration]
107
+ #
108
+ # @return [Client::Configuration]
109
+ #
110
+ def configure
111
+ yield @config if block_given?
112
+ @config
113
+ end
114
+
115
+ ##
116
+ # Create a new Policies client object.
117
+ #
118
+ # @example
119
+ #
120
+ # # Create a client using the default configuration
121
+ # client = ::Google::Iam::V2::Policies::Client.new
122
+ #
123
+ # # Create a client using a custom configuration
124
+ # client = ::Google::Iam::V2::Policies::Client.new do |config|
125
+ # config.timeout = 10.0
126
+ # end
127
+ #
128
+ # @yield [config] Configure the Policies client.
129
+ # @yieldparam config [Client::Configuration]
130
+ #
131
+ def initialize
132
+ # These require statements are intentionally placed here to initialize
133
+ # the gRPC module only when it's required.
134
+ # See https://github.com/googleapis/toolkit/issues/446
135
+ require "gapic/grpc"
136
+ require "google/iam/v2/policy_services_pb"
137
+
138
+ # Create the configuration object
139
+ @config = Configuration.new Client.configure
140
+
141
+ # Yield the configuration if needed
142
+ yield @config if block_given?
143
+
144
+ # Create credentials
145
+ credentials = @config.credentials
146
+ # Use self-signed JWT if the endpoint is unchanged from default,
147
+ # but only if the default endpoint does not have a region prefix.
148
+ enable_self_signed_jwt = @config.endpoint == Client.configure.endpoint &&
149
+ !@config.endpoint.split(".").first.include?("-")
150
+ credentials ||= Credentials.default scope: @config.scope,
151
+ enable_self_signed_jwt: enable_self_signed_jwt
152
+ if credentials.is_a?(::String) || credentials.is_a?(::Hash)
153
+ credentials = Credentials.new credentials, scope: @config.scope
154
+ end
155
+ @quota_project_id = @config.quota_project
156
+ @quota_project_id ||= credentials.quota_project_id if credentials.respond_to? :quota_project_id
157
+
158
+ @operations_client = Operations.new do |config|
159
+ config.credentials = credentials
160
+ config.quota_project = @quota_project_id
161
+ config.endpoint = @config.endpoint
162
+ end
163
+
164
+ @policies_stub = ::Gapic::ServiceStub.new(
165
+ ::Google::Iam::V2::Policies::Stub,
166
+ credentials: credentials,
167
+ endpoint: @config.endpoint,
168
+ channel_args: @config.channel_args,
169
+ interceptors: @config.interceptors
170
+ )
171
+ end
172
+
173
+ ##
174
+ # Get the associated client for long-running operations.
175
+ #
176
+ # @return [::Google::Iam::V2::Policies::Operations]
177
+ #
178
+ attr_reader :operations_client
179
+
180
+ # Service calls
181
+
182
+ ##
183
+ # Retrieves the policies of the specified kind that are attached to a
184
+ # resource.
185
+ #
186
+ # The response lists only policy metadata. In particular, policy rules are
187
+ # omitted.
188
+ #
189
+ # @overload list_policies(request, options = nil)
190
+ # Pass arguments to `list_policies` via a request object, either of type
191
+ # {::Google::Iam::V2::ListPoliciesRequest} or an equivalent Hash.
192
+ #
193
+ # @param request [::Google::Iam::V2::ListPoliciesRequest, ::Hash]
194
+ # A request object representing the call parameters. Required. To specify no
195
+ # parameters, or to keep all the default parameter values, pass an empty Hash.
196
+ # @param options [::Gapic::CallOptions, ::Hash]
197
+ # Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.
198
+ #
199
+ # @overload list_policies(parent: nil, page_size: nil, page_token: nil)
200
+ # Pass arguments to `list_policies` via keyword arguments. Note that at
201
+ # least one keyword argument is required. To specify no parameters, or to keep all
202
+ # the default parameter values, pass an empty Hash as a request object (see above).
203
+ #
204
+ # @param parent [::String]
205
+ # Required. The resource that the policy is attached to, along with the kind
206
+ # of policy to list. Format: `policies/{attachment_point}/denypolicies`
207
+ #
208
+ #
209
+ # The attachment point is identified by its URL-encoded full resource name,
210
+ # which means that the forward-slash character, `/`, must be written as
211
+ # `%2F`. For example,
212
+ # `policies/cloudresourcemanager.googleapis.com%2Fprojects%2Fmy-project/denypolicies`.
213
+ #
214
+ # For organizations and folders, use the numeric ID in the full resource
215
+ # name. For projects, you can use the alphanumeric or the numeric ID.
216
+ # @param page_size [::Integer]
217
+ # The maximum number of policies to return. IAM ignores this value and uses
218
+ # the value 1000.
219
+ # @param page_token [::String]
220
+ # A page token received in a
221
+ # {::Google::Iam::V2::ListPoliciesResponse ListPoliciesResponse}. Provide this
222
+ # token to retrieve the next page.
223
+ #
224
+ # @yield [response, operation] Access the result along with the RPC operation
225
+ # @yieldparam response [::Gapic::PagedEnumerable<::Google::Iam::V2::Policy>]
226
+ # @yieldparam operation [::GRPC::ActiveCall::Operation]
227
+ #
228
+ # @return [::Gapic::PagedEnumerable<::Google::Iam::V2::Policy>]
229
+ #
230
+ # @raise [::Google::Cloud::Error] if the RPC is aborted.
231
+ #
232
+ # @example Basic example
233
+ # require "google/iam/v2"
234
+ #
235
+ # # Create a client object. The client can be reused for multiple calls.
236
+ # client = Google::Iam::V2::Policies::Client.new
237
+ #
238
+ # # Create a request. To set request fields, pass in keyword arguments.
239
+ # request = Google::Iam::V2::ListPoliciesRequest.new
240
+ #
241
+ # # Call the list_policies method.
242
+ # result = client.list_policies request
243
+ #
244
+ # # The returned object is of type Gapic::PagedEnumerable. You can
245
+ # # iterate over all elements by calling #each, and the enumerable
246
+ # # will lazily make API calls to fetch subsequent pages. Other
247
+ # # methods are also available for managing paging directly.
248
+ # result.each do |response|
249
+ # # Each element is of type ::Google::Iam::V2::Policy.
250
+ # p response
251
+ # end
252
+ #
253
+ def list_policies request, options = nil
254
+ raise ::ArgumentError, "request must be provided" if request.nil?
255
+
256
+ request = ::Gapic::Protobuf.coerce request, to: ::Google::Iam::V2::ListPoliciesRequest
257
+
258
+ # Converts hash and nil to an options object
259
+ options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h
260
+
261
+ # Customize the options with defaults
262
+ metadata = @config.rpcs.list_policies.metadata.to_h
263
+
264
+ # Set x-goog-api-client and x-goog-user-project headers
265
+ metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \
266
+ lib_name: @config.lib_name, lib_version: @config.lib_version,
267
+ gapic_version: ::Google::Iam::V2::VERSION
268
+ metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id
269
+
270
+ header_params = {}
271
+ if request.parent
272
+ header_params["parent"] = request.parent
273
+ end
274
+
275
+ request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&")
276
+ metadata[:"x-goog-request-params"] ||= request_params_header
277
+
278
+ options.apply_defaults timeout: @config.rpcs.list_policies.timeout,
279
+ metadata: metadata,
280
+ retry_policy: @config.rpcs.list_policies.retry_policy
281
+
282
+ options.apply_defaults timeout: @config.timeout,
283
+ metadata: @config.metadata,
284
+ retry_policy: @config.retry_policy
285
+
286
+ @policies_stub.call_rpc :list_policies, request, options: options do |response, operation|
287
+ response = ::Gapic::PagedEnumerable.new @policies_stub, :list_policies, request, response, operation, options
288
+ yield response, operation if block_given?
289
+ return response
290
+ end
291
+ rescue ::GRPC::BadStatus => e
292
+ raise ::Google::Cloud::Error.from_error(e)
293
+ end
294
+
295
+ ##
296
+ # Gets a policy.
297
+ #
298
+ # @overload get_policy(request, options = nil)
299
+ # Pass arguments to `get_policy` via a request object, either of type
300
+ # {::Google::Iam::V2::GetPolicyRequest} or an equivalent Hash.
301
+ #
302
+ # @param request [::Google::Iam::V2::GetPolicyRequest, ::Hash]
303
+ # A request object representing the call parameters. Required. To specify no
304
+ # parameters, or to keep all the default parameter values, pass an empty Hash.
305
+ # @param options [::Gapic::CallOptions, ::Hash]
306
+ # Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.
307
+ #
308
+ # @overload get_policy(name: nil)
309
+ # Pass arguments to `get_policy` via keyword arguments. Note that at
310
+ # least one keyword argument is required. To specify no parameters, or to keep all
311
+ # the default parameter values, pass an empty Hash as a request object (see above).
312
+ #
313
+ # @param name [::String]
314
+ # Required. The resource name of the policy to retrieve. Format:
315
+ # `policies/{attachment_point}/denypolicies/{policy_id}`
316
+ #
317
+ #
318
+ # Use the URL-encoded full resource name, which means that the forward-slash
319
+ # character, `/`, must be written as `%2F`. For example,
320
+ # `policies/cloudresourcemanager.googleapis.com%2Fprojects%2Fmy-project/denypolicies/my-policy`.
321
+ #
322
+ # For organizations and folders, use the numeric ID in the full resource
323
+ # name. For projects, you can use the alphanumeric or the numeric ID.
324
+ #
325
+ # @yield [response, operation] Access the result along with the RPC operation
326
+ # @yieldparam response [::Google::Iam::V2::Policy]
327
+ # @yieldparam operation [::GRPC::ActiveCall::Operation]
328
+ #
329
+ # @return [::Google::Iam::V2::Policy]
330
+ #
331
+ # @raise [::Google::Cloud::Error] if the RPC is aborted.
332
+ #
333
+ # @example Basic example
334
+ # require "google/iam/v2"
335
+ #
336
+ # # Create a client object. The client can be reused for multiple calls.
337
+ # client = Google::Iam::V2::Policies::Client.new
338
+ #
339
+ # # Create a request. To set request fields, pass in keyword arguments.
340
+ # request = Google::Iam::V2::GetPolicyRequest.new
341
+ #
342
+ # # Call the get_policy method.
343
+ # result = client.get_policy request
344
+ #
345
+ # # The returned object is of type Google::Iam::V2::Policy.
346
+ # p result
347
+ #
348
+ def get_policy request, options = nil
349
+ raise ::ArgumentError, "request must be provided" if request.nil?
350
+
351
+ request = ::Gapic::Protobuf.coerce request, to: ::Google::Iam::V2::GetPolicyRequest
352
+
353
+ # Converts hash and nil to an options object
354
+ options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h
355
+
356
+ # Customize the options with defaults
357
+ metadata = @config.rpcs.get_policy.metadata.to_h
358
+
359
+ # Set x-goog-api-client and x-goog-user-project headers
360
+ metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \
361
+ lib_name: @config.lib_name, lib_version: @config.lib_version,
362
+ gapic_version: ::Google::Iam::V2::VERSION
363
+ metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id
364
+
365
+ header_params = {}
366
+ if request.name
367
+ header_params["name"] = request.name
368
+ end
369
+
370
+ request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&")
371
+ metadata[:"x-goog-request-params"] ||= request_params_header
372
+
373
+ options.apply_defaults timeout: @config.rpcs.get_policy.timeout,
374
+ metadata: metadata,
375
+ retry_policy: @config.rpcs.get_policy.retry_policy
376
+
377
+ options.apply_defaults timeout: @config.timeout,
378
+ metadata: @config.metadata,
379
+ retry_policy: @config.retry_policy
380
+
381
+ @policies_stub.call_rpc :get_policy, request, options: options do |response, operation|
382
+ yield response, operation if block_given?
383
+ return response
384
+ end
385
+ rescue ::GRPC::BadStatus => e
386
+ raise ::Google::Cloud::Error.from_error(e)
387
+ end
388
+
389
+ ##
390
+ # Creates a policy.
391
+ #
392
+ # @overload create_policy(request, options = nil)
393
+ # Pass arguments to `create_policy` via a request object, either of type
394
+ # {::Google::Iam::V2::CreatePolicyRequest} or an equivalent Hash.
395
+ #
396
+ # @param request [::Google::Iam::V2::CreatePolicyRequest, ::Hash]
397
+ # A request object representing the call parameters. Required. To specify no
398
+ # parameters, or to keep all the default parameter values, pass an empty Hash.
399
+ # @param options [::Gapic::CallOptions, ::Hash]
400
+ # Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.
401
+ #
402
+ # @overload create_policy(parent: nil, policy: nil, policy_id: nil)
403
+ # Pass arguments to `create_policy` via keyword arguments. Note that at
404
+ # least one keyword argument is required. To specify no parameters, or to keep all
405
+ # the default parameter values, pass an empty Hash as a request object (see above).
406
+ #
407
+ # @param parent [::String]
408
+ # Required. The resource that the policy is attached to, along with the kind
409
+ # of policy to create. Format: `policies/{attachment_point}/denypolicies`
410
+ #
411
+ #
412
+ # The attachment point is identified by its URL-encoded full resource name,
413
+ # which means that the forward-slash character, `/`, must be written as
414
+ # `%2F`. For example,
415
+ # `policies/cloudresourcemanager.googleapis.com%2Fprojects%2Fmy-project/denypolicies`.
416
+ #
417
+ # For organizations and folders, use the numeric ID in the full resource
418
+ # name. For projects, you can use the alphanumeric or the numeric ID.
419
+ # @param policy [::Google::Iam::V2::Policy, ::Hash]
420
+ # Required. The policy to create.
421
+ # @param policy_id [::String]
422
+ # The ID to use for this policy, which will become the final component of
423
+ # the policy's resource name. The ID must contain 3 to 63 characters. It can
424
+ # contain lowercase letters and numbers, as well as dashes (`-`) and periods
425
+ # (`.`). The first character must be a lowercase letter.
426
+ #
427
+ # @yield [response, operation] Access the result along with the RPC operation
428
+ # @yieldparam response [::Gapic::Operation]
429
+ # @yieldparam operation [::GRPC::ActiveCall::Operation]
430
+ #
431
+ # @return [::Gapic::Operation]
432
+ #
433
+ # @raise [::Google::Cloud::Error] if the RPC is aborted.
434
+ #
435
+ # @example Basic example
436
+ # require "google/iam/v2"
437
+ #
438
+ # # Create a client object. The client can be reused for multiple calls.
439
+ # client = Google::Iam::V2::Policies::Client.new
440
+ #
441
+ # # Create a request. To set request fields, pass in keyword arguments.
442
+ # request = Google::Iam::V2::CreatePolicyRequest.new
443
+ #
444
+ # # Call the create_policy method.
445
+ # result = client.create_policy request
446
+ #
447
+ # # The returned object is of type Gapic::Operation. You can use this
448
+ # # object to check the status of an operation, cancel it, or wait
449
+ # # for results. Here is how to block until completion:
450
+ # result.wait_until_done! timeout: 60
451
+ # if result.response?
452
+ # p result.response
453
+ # else
454
+ # puts "Error!"
455
+ # end
456
+ #
457
+ def create_policy request, options = nil
458
+ raise ::ArgumentError, "request must be provided" if request.nil?
459
+
460
+ request = ::Gapic::Protobuf.coerce request, to: ::Google::Iam::V2::CreatePolicyRequest
461
+
462
+ # Converts hash and nil to an options object
463
+ options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h
464
+
465
+ # Customize the options with defaults
466
+ metadata = @config.rpcs.create_policy.metadata.to_h
467
+
468
+ # Set x-goog-api-client and x-goog-user-project headers
469
+ metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \
470
+ lib_name: @config.lib_name, lib_version: @config.lib_version,
471
+ gapic_version: ::Google::Iam::V2::VERSION
472
+ metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id
473
+
474
+ header_params = {}
475
+ if request.parent
476
+ header_params["parent"] = request.parent
477
+ end
478
+
479
+ request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&")
480
+ metadata[:"x-goog-request-params"] ||= request_params_header
481
+
482
+ options.apply_defaults timeout: @config.rpcs.create_policy.timeout,
483
+ metadata: metadata,
484
+ retry_policy: @config.rpcs.create_policy.retry_policy
485
+
486
+ options.apply_defaults timeout: @config.timeout,
487
+ metadata: @config.metadata,
488
+ retry_policy: @config.retry_policy
489
+
490
+ @policies_stub.call_rpc :create_policy, request, options: options do |response, operation|
491
+ response = ::Gapic::Operation.new response, @operations_client, options: options
492
+ yield response, operation if block_given?
493
+ return response
494
+ end
495
+ rescue ::GRPC::BadStatus => e
496
+ raise ::Google::Cloud::Error.from_error(e)
497
+ end
498
+
499
+ ##
500
+ # Updates the specified policy.
501
+ #
502
+ # You can update only the rules and the display name for the policy.
503
+ #
504
+ # To update a policy, you should use a read-modify-write loop:
505
+ #
506
+ # 1. Use {::Google::Iam::V2::Policies::Client#get_policy GetPolicy} to read the current
507
+ # version of the policy.
508
+ # 2. Modify the policy as needed.
509
+ # 3. Use `UpdatePolicy` to write the updated policy.
510
+ #
511
+ # This pattern helps prevent conflicts between concurrent updates.
512
+ #
513
+ # @overload update_policy(request, options = nil)
514
+ # Pass arguments to `update_policy` via a request object, either of type
515
+ # {::Google::Iam::V2::UpdatePolicyRequest} or an equivalent Hash.
516
+ #
517
+ # @param request [::Google::Iam::V2::UpdatePolicyRequest, ::Hash]
518
+ # A request object representing the call parameters. Required. To specify no
519
+ # parameters, or to keep all the default parameter values, pass an empty Hash.
520
+ # @param options [::Gapic::CallOptions, ::Hash]
521
+ # Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.
522
+ #
523
+ # @overload update_policy(policy: nil)
524
+ # Pass arguments to `update_policy` via keyword arguments. Note that at
525
+ # least one keyword argument is required. To specify no parameters, or to keep all
526
+ # the default parameter values, pass an empty Hash as a request object (see above).
527
+ #
528
+ # @param policy [::Google::Iam::V2::Policy, ::Hash]
529
+ # Required. The policy to update.
530
+ #
531
+ # To prevent conflicting updates, the `etag` value must match the value that
532
+ # is stored in IAM. If the `etag` values do not match, the request fails with
533
+ # a `409` error code and `ABORTED` status.
534
+ #
535
+ # @yield [response, operation] Access the result along with the RPC operation
536
+ # @yieldparam response [::Gapic::Operation]
537
+ # @yieldparam operation [::GRPC::ActiveCall::Operation]
538
+ #
539
+ # @return [::Gapic::Operation]
540
+ #
541
+ # @raise [::Google::Cloud::Error] if the RPC is aborted.
542
+ #
543
+ # @example Basic example
544
+ # require "google/iam/v2"
545
+ #
546
+ # # Create a client object. The client can be reused for multiple calls.
547
+ # client = Google::Iam::V2::Policies::Client.new
548
+ #
549
+ # # Create a request. To set request fields, pass in keyword arguments.
550
+ # request = Google::Iam::V2::UpdatePolicyRequest.new
551
+ #
552
+ # # Call the update_policy method.
553
+ # result = client.update_policy request
554
+ #
555
+ # # The returned object is of type Gapic::Operation. You can use this
556
+ # # object to check the status of an operation, cancel it, or wait
557
+ # # for results. Here is how to block until completion:
558
+ # result.wait_until_done! timeout: 60
559
+ # if result.response?
560
+ # p result.response
561
+ # else
562
+ # puts "Error!"
563
+ # end
564
+ #
565
+ def update_policy request, options = nil
566
+ raise ::ArgumentError, "request must be provided" if request.nil?
567
+
568
+ request = ::Gapic::Protobuf.coerce request, to: ::Google::Iam::V2::UpdatePolicyRequest
569
+
570
+ # Converts hash and nil to an options object
571
+ options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h
572
+
573
+ # Customize the options with defaults
574
+ metadata = @config.rpcs.update_policy.metadata.to_h
575
+
576
+ # Set x-goog-api-client and x-goog-user-project headers
577
+ metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \
578
+ lib_name: @config.lib_name, lib_version: @config.lib_version,
579
+ gapic_version: ::Google::Iam::V2::VERSION
580
+ metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id
581
+
582
+ header_params = {}
583
+ if request.policy&.name
584
+ header_params["policy.name"] = request.policy.name
585
+ end
586
+
587
+ request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&")
588
+ metadata[:"x-goog-request-params"] ||= request_params_header
589
+
590
+ options.apply_defaults timeout: @config.rpcs.update_policy.timeout,
591
+ metadata: metadata,
592
+ retry_policy: @config.rpcs.update_policy.retry_policy
593
+
594
+ options.apply_defaults timeout: @config.timeout,
595
+ metadata: @config.metadata,
596
+ retry_policy: @config.retry_policy
597
+
598
+ @policies_stub.call_rpc :update_policy, request, options: options do |response, operation|
599
+ response = ::Gapic::Operation.new response, @operations_client, options: options
600
+ yield response, operation if block_given?
601
+ return response
602
+ end
603
+ rescue ::GRPC::BadStatus => e
604
+ raise ::Google::Cloud::Error.from_error(e)
605
+ end
606
+
607
+ ##
608
+ # Deletes a policy. This action is permanent.
609
+ #
610
+ # @overload delete_policy(request, options = nil)
611
+ # Pass arguments to `delete_policy` via a request object, either of type
612
+ # {::Google::Iam::V2::DeletePolicyRequest} or an equivalent Hash.
613
+ #
614
+ # @param request [::Google::Iam::V2::DeletePolicyRequest, ::Hash]
615
+ # A request object representing the call parameters. Required. To specify no
616
+ # parameters, or to keep all the default parameter values, pass an empty Hash.
617
+ # @param options [::Gapic::CallOptions, ::Hash]
618
+ # Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.
619
+ #
620
+ # @overload delete_policy(name: nil, etag: nil)
621
+ # Pass arguments to `delete_policy` via keyword arguments. Note that at
622
+ # least one keyword argument is required. To specify no parameters, or to keep all
623
+ # the default parameter values, pass an empty Hash as a request object (see above).
624
+ #
625
+ # @param name [::String]
626
+ # Required. The resource name of the policy to delete. Format:
627
+ # `policies/{attachment_point}/denypolicies/{policy_id}`
628
+ #
629
+ #
630
+ # Use the URL-encoded full resource name, which means that the forward-slash
631
+ # character, `/`, must be written as `%2F`. For example,
632
+ # `policies/cloudresourcemanager.googleapis.com%2Fprojects%2Fmy-project/denypolicies/my-policy`.
633
+ #
634
+ # For organizations and folders, use the numeric ID in the full resource
635
+ # name. For projects, you can use the alphanumeric or the numeric ID.
636
+ # @param etag [::String]
637
+ # Optional. The expected `etag` of the policy to delete. If the value does
638
+ # not match the value that is stored in IAM, the request fails with a `409`
639
+ # error code and `ABORTED` status.
640
+ #
641
+ # If you omit this field, the policy is deleted regardless of its current
642
+ # `etag`.
643
+ #
644
+ # @yield [response, operation] Access the result along with the RPC operation
645
+ # @yieldparam response [::Gapic::Operation]
646
+ # @yieldparam operation [::GRPC::ActiveCall::Operation]
647
+ #
648
+ # @return [::Gapic::Operation]
649
+ #
650
+ # @raise [::Google::Cloud::Error] if the RPC is aborted.
651
+ #
652
+ # @example Basic example
653
+ # require "google/iam/v2"
654
+ #
655
+ # # Create a client object. The client can be reused for multiple calls.
656
+ # client = Google::Iam::V2::Policies::Client.new
657
+ #
658
+ # # Create a request. To set request fields, pass in keyword arguments.
659
+ # request = Google::Iam::V2::DeletePolicyRequest.new
660
+ #
661
+ # # Call the delete_policy method.
662
+ # result = client.delete_policy request
663
+ #
664
+ # # The returned object is of type Gapic::Operation. You can use this
665
+ # # object to check the status of an operation, cancel it, or wait
666
+ # # for results. Here is how to block until completion:
667
+ # result.wait_until_done! timeout: 60
668
+ # if result.response?
669
+ # p result.response
670
+ # else
671
+ # puts "Error!"
672
+ # end
673
+ #
674
+ def delete_policy request, options = nil
675
+ raise ::ArgumentError, "request must be provided" if request.nil?
676
+
677
+ request = ::Gapic::Protobuf.coerce request, to: ::Google::Iam::V2::DeletePolicyRequest
678
+
679
+ # Converts hash and nil to an options object
680
+ options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h
681
+
682
+ # Customize the options with defaults
683
+ metadata = @config.rpcs.delete_policy.metadata.to_h
684
+
685
+ # Set x-goog-api-client and x-goog-user-project headers
686
+ metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \
687
+ lib_name: @config.lib_name, lib_version: @config.lib_version,
688
+ gapic_version: ::Google::Iam::V2::VERSION
689
+ metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id
690
+
691
+ header_params = {}
692
+ if request.name
693
+ header_params["name"] = request.name
694
+ end
695
+
696
+ request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&")
697
+ metadata[:"x-goog-request-params"] ||= request_params_header
698
+
699
+ options.apply_defaults timeout: @config.rpcs.delete_policy.timeout,
700
+ metadata: metadata,
701
+ retry_policy: @config.rpcs.delete_policy.retry_policy
702
+
703
+ options.apply_defaults timeout: @config.timeout,
704
+ metadata: @config.metadata,
705
+ retry_policy: @config.retry_policy
706
+
707
+ @policies_stub.call_rpc :delete_policy, request, options: options do |response, operation|
708
+ response = ::Gapic::Operation.new response, @operations_client, options: options
709
+ yield response, operation if block_given?
710
+ return response
711
+ end
712
+ rescue ::GRPC::BadStatus => e
713
+ raise ::Google::Cloud::Error.from_error(e)
714
+ end
715
+
716
+ ##
717
+ # Retrieves all the policies that are attached to the specified resource,
718
+ # or anywhere in the ancestry of the resource. For example, for a project
719
+ # this endpoint would return all the `denyPolicy` kind policies attached to
720
+ # the project, its parent folder (if any), and its parent organization (if
721
+ # any).
722
+ # The endpoint requires the same permissions that it would take to call
723
+ # `ListPolicies` or `GetPolicy`.
724
+ #
725
+ # The main reason to use this endpoint is as a policy admin to debug access
726
+ # issues for a resource.
727
+ #
728
+ # @overload list_applicable_policies(request, options = nil)
729
+ # Pass arguments to `list_applicable_policies` via a request object, either of type
730
+ # {::Google::Iam::V2::ListApplicablePoliciesRequest} or an equivalent Hash.
731
+ #
732
+ # @param request [::Google::Iam::V2::ListApplicablePoliciesRequest, ::Hash]
733
+ # A request object representing the call parameters. Required. To specify no
734
+ # parameters, or to keep all the default parameter values, pass an empty Hash.
735
+ # @param options [::Gapic::CallOptions, ::Hash]
736
+ # Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.
737
+ #
738
+ # @overload list_applicable_policies(attachment_point: nil, filter: nil, page_token: nil, page_size: nil)
739
+ # Pass arguments to `list_applicable_policies` via keyword arguments. Note that at
740
+ # least one keyword argument is required. To specify no parameters, or to keep all
741
+ # the default parameter values, pass an empty Hash as a request object (see above).
742
+ #
743
+ # @param attachment_point [::String]
744
+ # Required. The Cloud resource at which the applicable policies are to be
745
+ # retrieved. Format: `{attachment-point}` Use the URL-encoded full resource
746
+ # name, which means that the forward-slash character, `/`, must be written as
747
+ # `%2F`. For example,
748
+ # `cloudresourcemanager.googleapis.com%2Fprojects%2Fmy-project`.
749
+ # @param filter [::String]
750
+ # Filtering currently only supports the kind of policies to return, and
751
+ # must be in the format “kind:[policyKind1] OR kind:[policyKind2]”. New
752
+ # policy kinds may be added in the future without notice.
753
+ #
754
+ # Example value: “kind:denyPolicies”
755
+ # @param page_token [::String]
756
+ # If present, then retrieve the batch of results following the results from
757
+ # the preceding call to this method. `page_token` must be the value of
758
+ # `next_page_token`
759
+ # {::Google::Iam::V2::ListApplicablePoliciesResponse#next_page_token ListApplicablePoliciesResponse.next_page_token}
760
+ # from the previous response. The values of other method parameters should
761
+ # be identical to those in the previous call.
762
+ # @param page_size [::Integer]
763
+ # Limit on the number of policies to include in the response.
764
+ # Further policies can subsequently be obtained by including the
765
+ # [ListApplicablePoliciesResponse.next_page_token][google.iam.admin.v1.ListApplicablePoliciesResponse.next_page_token]
766
+ # in a subsequent request.
767
+ # The minimum is 25, and the maximum is 100.
768
+ #
769
+ # @yield [response, operation] Access the result along with the RPC operation
770
+ # @yieldparam response [::Gapic::PagedEnumerable<::Google::Iam::V2::Policy>]
771
+ # @yieldparam operation [::GRPC::ActiveCall::Operation]
772
+ #
773
+ # @return [::Gapic::PagedEnumerable<::Google::Iam::V2::Policy>]
774
+ #
775
+ # @raise [::Google::Cloud::Error] if the RPC is aborted.
776
+ #
777
+ # @example Basic example
778
+ # require "google/iam/v2"
779
+ #
780
+ # # Create a client object. The client can be reused for multiple calls.
781
+ # client = Google::Iam::V2::Policies::Client.new
782
+ #
783
+ # # Create a request. To set request fields, pass in keyword arguments.
784
+ # request = Google::Iam::V2::ListApplicablePoliciesRequest.new
785
+ #
786
+ # # Call the list_applicable_policies method.
787
+ # result = client.list_applicable_policies request
788
+ #
789
+ # # The returned object is of type Gapic::PagedEnumerable. You can
790
+ # # iterate over all elements by calling #each, and the enumerable
791
+ # # will lazily make API calls to fetch subsequent pages. Other
792
+ # # methods are also available for managing paging directly.
793
+ # result.each do |response|
794
+ # # Each element is of type ::Google::Iam::V2::Policy.
795
+ # p response
796
+ # end
797
+ #
798
+ def list_applicable_policies request, options = nil
799
+ raise ::ArgumentError, "request must be provided" if request.nil?
800
+
801
+ request = ::Gapic::Protobuf.coerce request, to: ::Google::Iam::V2::ListApplicablePoliciesRequest
802
+
803
+ # Converts hash and nil to an options object
804
+ options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h
805
+
806
+ # Customize the options with defaults
807
+ metadata = @config.rpcs.list_applicable_policies.metadata.to_h
808
+
809
+ # Set x-goog-api-client and x-goog-user-project headers
810
+ metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \
811
+ lib_name: @config.lib_name, lib_version: @config.lib_version,
812
+ gapic_version: ::Google::Iam::V2::VERSION
813
+ metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id
814
+
815
+ header_params = {}
816
+ if request.attachment_point
817
+ header_params["attachment_point"] = request.attachment_point
818
+ end
819
+
820
+ request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&")
821
+ metadata[:"x-goog-request-params"] ||= request_params_header
822
+
823
+ options.apply_defaults timeout: @config.rpcs.list_applicable_policies.timeout,
824
+ metadata: metadata,
825
+ retry_policy: @config.rpcs.list_applicable_policies.retry_policy
826
+
827
+ options.apply_defaults timeout: @config.timeout,
828
+ metadata: @config.metadata,
829
+ retry_policy: @config.retry_policy
830
+
831
+ @policies_stub.call_rpc :list_applicable_policies, request, options: options do |response, operation|
832
+ response = ::Gapic::PagedEnumerable.new @policies_stub, :list_applicable_policies, request, response, operation, options
833
+ yield response, operation if block_given?
834
+ return response
835
+ end
836
+ rescue ::GRPC::BadStatus => e
837
+ raise ::Google::Cloud::Error.from_error(e)
838
+ end
839
+
840
+ ##
841
+ # Configuration class for the Policies API.
842
+ #
843
+ # This class represents the configuration for Policies,
844
+ # providing control over timeouts, retry behavior, logging, transport
845
+ # parameters, and other low-level controls. Certain parameters can also be
846
+ # applied individually to specific RPCs. See
847
+ # {::Google::Iam::V2::Policies::Client::Configuration::Rpcs}
848
+ # for a list of RPCs that can be configured independently.
849
+ #
850
+ # Configuration can be applied globally to all clients, or to a single client
851
+ # on construction.
852
+ #
853
+ # @example
854
+ #
855
+ # # Modify the global config, setting the timeout for
856
+ # # list_policies to 20 seconds,
857
+ # # and all remaining timeouts to 10 seconds.
858
+ # ::Google::Iam::V2::Policies::Client.configure do |config|
859
+ # config.timeout = 10.0
860
+ # config.rpcs.list_policies.timeout = 20.0
861
+ # end
862
+ #
863
+ # # Apply the above configuration only to a new client.
864
+ # client = ::Google::Iam::V2::Policies::Client.new do |config|
865
+ # config.timeout = 10.0
866
+ # config.rpcs.list_policies.timeout = 20.0
867
+ # end
868
+ #
869
+ # @!attribute [rw] endpoint
870
+ # The hostname or hostname:port of the service endpoint.
871
+ # Defaults to `"iam.googleapis.com"`.
872
+ # @return [::String]
873
+ # @!attribute [rw] credentials
874
+ # Credentials to send with calls. You may provide any of the following types:
875
+ # * (`String`) The path to a service account key file in JSON format
876
+ # * (`Hash`) A service account key as a Hash
877
+ # * (`Google::Auth::Credentials`) A googleauth credentials object
878
+ # (see the [googleauth docs](https://googleapis.dev/ruby/googleauth/latest/index.html))
879
+ # * (`Signet::OAuth2::Client`) A signet oauth2 client object
880
+ # (see the [signet docs](https://googleapis.dev/ruby/signet/latest/Signet/OAuth2/Client.html))
881
+ # * (`GRPC::Core::Channel`) a gRPC channel with included credentials
882
+ # * (`GRPC::Core::ChannelCredentials`) a gRPC credentails object
883
+ # * (`nil`) indicating no credentials
884
+ # @return [::Object]
885
+ # @!attribute [rw] scope
886
+ # The OAuth scopes
887
+ # @return [::Array<::String>]
888
+ # @!attribute [rw] lib_name
889
+ # The library name as recorded in instrumentation and logging
890
+ # @return [::String]
891
+ # @!attribute [rw] lib_version
892
+ # The library version as recorded in instrumentation and logging
893
+ # @return [::String]
894
+ # @!attribute [rw] channel_args
895
+ # Extra parameters passed to the gRPC channel. Note: this is ignored if a
896
+ # `GRPC::Core::Channel` object is provided as the credential.
897
+ # @return [::Hash]
898
+ # @!attribute [rw] interceptors
899
+ # An array of interceptors that are run before calls are executed.
900
+ # @return [::Array<::GRPC::ClientInterceptor>]
901
+ # @!attribute [rw] timeout
902
+ # The call timeout in seconds.
903
+ # @return [::Numeric]
904
+ # @!attribute [rw] metadata
905
+ # Additional gRPC headers to be sent with the call.
906
+ # @return [::Hash{::Symbol=>::String}]
907
+ # @!attribute [rw] retry_policy
908
+ # The retry policy. The value is a hash with the following keys:
909
+ # * `:initial_delay` (*type:* `Numeric`) - The initial delay in seconds.
910
+ # * `:max_delay` (*type:* `Numeric`) - The max delay in seconds.
911
+ # * `:multiplier` (*type:* `Numeric`) - The incremental backoff multiplier.
912
+ # * `:retry_codes` (*type:* `Array<String>`) - The error codes that should
913
+ # trigger a retry.
914
+ # @return [::Hash]
915
+ # @!attribute [rw] quota_project
916
+ # A separate project against which to charge quota.
917
+ # @return [::String]
918
+ #
919
+ class Configuration
920
+ extend ::Gapic::Config
921
+
922
+ config_attr :endpoint, "iam.googleapis.com", ::String
923
+ config_attr :credentials, nil do |value|
924
+ allowed = [::String, ::Hash, ::Proc, ::Symbol, ::Google::Auth::Credentials, ::Signet::OAuth2::Client, nil]
925
+ allowed += [::GRPC::Core::Channel, ::GRPC::Core::ChannelCredentials] if defined? ::GRPC
926
+ allowed.any? { |klass| klass === value }
927
+ end
928
+ config_attr :scope, nil, ::String, ::Array, nil
929
+ config_attr :lib_name, nil, ::String, nil
930
+ config_attr :lib_version, nil, ::String, nil
931
+ config_attr(:channel_args, { "grpc.service_config_disable_resolution" => 1 }, ::Hash, nil)
932
+ config_attr :interceptors, nil, ::Array, nil
933
+ config_attr :timeout, nil, ::Numeric, nil
934
+ config_attr :metadata, nil, ::Hash, nil
935
+ config_attr :retry_policy, nil, ::Hash, ::Proc, nil
936
+ config_attr :quota_project, nil, ::String, nil
937
+
938
+ # @private
939
+ def initialize parent_config = nil
940
+ @parent_config = parent_config unless parent_config.nil?
941
+
942
+ yield self if block_given?
943
+ end
944
+
945
+ ##
946
+ # Configurations for individual RPCs
947
+ # @return [Rpcs]
948
+ #
949
+ def rpcs
950
+ @rpcs ||= begin
951
+ parent_rpcs = nil
952
+ parent_rpcs = @parent_config.rpcs if defined?(@parent_config) && @parent_config.respond_to?(:rpcs)
953
+ Rpcs.new parent_rpcs
954
+ end
955
+ end
956
+
957
+ ##
958
+ # Configuration RPC class for the Policies API.
959
+ #
960
+ # Includes fields providing the configuration for each RPC in this service.
961
+ # Each configuration object is of type `Gapic::Config::Method` and includes
962
+ # the following configuration fields:
963
+ #
964
+ # * `timeout` (*type:* `Numeric`) - The call timeout in seconds
965
+ # * `metadata` (*type:* `Hash{Symbol=>String}`) - Additional gRPC headers
966
+ # * `retry_policy (*type:* `Hash`) - The retry policy. The policy fields
967
+ # include the following keys:
968
+ # * `:initial_delay` (*type:* `Numeric`) - The initial delay in seconds.
969
+ # * `:max_delay` (*type:* `Numeric`) - The max delay in seconds.
970
+ # * `:multiplier` (*type:* `Numeric`) - The incremental backoff multiplier.
971
+ # * `:retry_codes` (*type:* `Array<String>`) - The error codes that should
972
+ # trigger a retry.
973
+ #
974
+ class Rpcs
975
+ ##
976
+ # RPC-specific configuration for `list_policies`
977
+ # @return [::Gapic::Config::Method]
978
+ #
979
+ attr_reader :list_policies
980
+ ##
981
+ # RPC-specific configuration for `get_policy`
982
+ # @return [::Gapic::Config::Method]
983
+ #
984
+ attr_reader :get_policy
985
+ ##
986
+ # RPC-specific configuration for `create_policy`
987
+ # @return [::Gapic::Config::Method]
988
+ #
989
+ attr_reader :create_policy
990
+ ##
991
+ # RPC-specific configuration for `update_policy`
992
+ # @return [::Gapic::Config::Method]
993
+ #
994
+ attr_reader :update_policy
995
+ ##
996
+ # RPC-specific configuration for `delete_policy`
997
+ # @return [::Gapic::Config::Method]
998
+ #
999
+ attr_reader :delete_policy
1000
+ ##
1001
+ # RPC-specific configuration for `list_applicable_policies`
1002
+ # @return [::Gapic::Config::Method]
1003
+ #
1004
+ attr_reader :list_applicable_policies
1005
+
1006
+ # @private
1007
+ def initialize parent_rpcs = nil
1008
+ list_policies_config = parent_rpcs.list_policies if parent_rpcs.respond_to? :list_policies
1009
+ @list_policies = ::Gapic::Config::Method.new list_policies_config
1010
+ get_policy_config = parent_rpcs.get_policy if parent_rpcs.respond_to? :get_policy
1011
+ @get_policy = ::Gapic::Config::Method.new get_policy_config
1012
+ create_policy_config = parent_rpcs.create_policy if parent_rpcs.respond_to? :create_policy
1013
+ @create_policy = ::Gapic::Config::Method.new create_policy_config
1014
+ update_policy_config = parent_rpcs.update_policy if parent_rpcs.respond_to? :update_policy
1015
+ @update_policy = ::Gapic::Config::Method.new update_policy_config
1016
+ delete_policy_config = parent_rpcs.delete_policy if parent_rpcs.respond_to? :delete_policy
1017
+ @delete_policy = ::Gapic::Config::Method.new delete_policy_config
1018
+ list_applicable_policies_config = parent_rpcs.list_applicable_policies if parent_rpcs.respond_to? :list_applicable_policies
1019
+ @list_applicable_policies = ::Gapic::Config::Method.new list_applicable_policies_config
1020
+
1021
+ yield self if block_given?
1022
+ end
1023
+ end
1024
+ end
1025
+ end
1026
+ end
1027
+ end
1028
+ end
1029
+ end