Class: Google::Cloud::ApiKeys::V2::ApiKeys::Client

Inherits:
Object
  • Object
show all
Includes:
Paths
Defined in:
lib/google/cloud/api_keys/v2/api_keys/client.rb

Overview

Client for the ApiKeys service.

Manages the API keys associated with projects.

Defined Under Namespace

Classes: Configuration

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Paths

#key_path, #location_path

Constructor Details

#initialize {|config| ... } ⇒ Client

Create a new ApiKeys client object.

Examples:


# Create a client using the default configuration
client = ::Google::Cloud::ApiKeys::V2::ApiKeys::Client.new

# Create a client using a custom configuration
client = ::Google::Cloud::ApiKeys::V2::ApiKeys::Client.new do |config|
  config.timeout = 10.0
end

Yields:

  • (config)

    Configure the ApiKeys client.

Yield Parameters:



111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
# File 'lib/google/cloud/api_keys/v2/api_keys/client.rb', line 111

def initialize
  # These require statements are intentionally placed here to initialize
  # the gRPC module only when it's required.
  # See https://github.com/googleapis/toolkit/issues/446
  require "gapic/grpc"
  require "google/api/apikeys/v2/apikeys_services_pb"

  # Create the configuration object
  @config = Configuration.new Client.configure

  # Yield the configuration if needed
  yield @config if block_given?

  # Create credentials
  credentials = @config.credentials
  # Use self-signed JWT if the endpoint is unchanged from default,
  # but only if the default endpoint does not have a region prefix.
  enable_self_signed_jwt = @config.endpoint == Client.configure.endpoint &&
                           !@config.endpoint.split(".").first.include?("-")
  credentials ||= Credentials.default scope: @config.scope,
                                      enable_self_signed_jwt: enable_self_signed_jwt
  if credentials.is_a?(::String) || credentials.is_a?(::Hash)
    credentials = Credentials.new credentials, scope: @config.scope
  end
  @quota_project_id = @config.quota_project
  @quota_project_id ||= credentials.quota_project_id if credentials.respond_to? :quota_project_id

  @operations_client = Operations.new do |config|
    config.credentials = credentials
    config.quota_project = @quota_project_id
    config.endpoint = @config.endpoint
  end

  @api_keys_stub = ::Gapic::ServiceStub.new(
    ::Google::Cloud::ApiKeys::V2::ApiKeys::Stub,
    credentials:  credentials,
    endpoint:     @config.endpoint,
    channel_args: @config.channel_args,
    interceptors: @config.interceptors
  )
end

Instance Attribute Details

#operations_client::Google::Cloud::ApiKeys::V2::ApiKeys::Operations (readonly)

Get the associated client for long-running operations.



158
159
160
# File 'lib/google/cloud/api_keys/v2/api_keys/client.rb', line 158

def operations_client
  @operations_client
end

Class Method Details

.configure {|config| ... } ⇒ Client::Configuration

Configure the ApiKeys Client class.

See Configuration for a description of the configuration fields.

Examples:


# Modify the configuration for all ApiKeys clients
::Google::Cloud::ApiKeys::V2::ApiKeys::Client.configure do |config|
  config.timeout = 10.0
end

Yields:

  • (config)

    Configure the Client client.

Yield Parameters:

Returns:



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/google/cloud/api_keys/v2/api_keys/client.rb', line 56

def self.configure
  @configure ||= begin
    namespace = ["Google", "Cloud", "ApiKeys", "V2"]
    parent_config = while namespace.any?
                      parent_name = namespace.join "::"
                      parent_const = const_get parent_name
                      break parent_const.configure if parent_const.respond_to? :configure
                      namespace.pop
                    end
    default_config = Client::Configuration.new parent_config

    default_config.timeout = 10.0

    default_config
  end
  yield @configure if block_given?
  @configure
end

Instance Method Details

#configure {|config| ... } ⇒ Client::Configuration

Configure the ApiKeys Client instance.

The configuration is set to the derived mode, meaning that values can be changed, but structural changes (adding new fields, etc.) are not allowed. Structural changes should be made on configure.

See Configuration for a description of the configuration fields.

Yields:

  • (config)

    Configure the Client client.

Yield Parameters:

Returns:



90
91
92
93
# File 'lib/google/cloud/api_keys/v2/api_keys/client.rb', line 90

def configure
  yield @config if block_given?
  @config
end

#create_key(request, options = nil) ⇒ ::Gapic::Operation #create_key(parent: nil, key: nil, key_id: nil) ⇒ ::Gapic::Operation

Creates a new API key.

NOTE: Key is a global resource; hence the only supported value for location is global.

Examples:

Basic example

require "google/cloud/api_keys/v2"

# Create a client object. The client can be reused for multiple calls.
client = Google::Cloud::ApiKeys::V2::ApiKeys::Client.new

# Create a request. To set request fields, pass in keyword arguments.
request = Google::Cloud::ApiKeys::V2::CreateKeyRequest.new

# Call the create_key method.
result = client.create_key request

# The returned object is of type Gapic::Operation. You can use this
# object to check the status of an operation, cancel it, or wait
# for results. Here is how to block until completion:
result.wait_until_done! timeout: 60
if result.response?
  p result.response
else
  puts "Error!"
end

Overloads:

  • #create_key(request, options = nil) ⇒ ::Gapic::Operation

    Pass arguments to create_key via a request object, either of type CreateKeyRequest or an equivalent Hash.

    Parameters:

    • request (::Google::Cloud::ApiKeys::V2::CreateKeyRequest, ::Hash)

      A request object representing the call parameters. Required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash.

    • options (::Gapic::CallOptions, ::Hash) (defaults to: nil)

      Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.

  • #create_key(parent: nil, key: nil, key_id: nil) ⇒ ::Gapic::Operation

    Pass arguments to create_key via keyword arguments. Note that at least one keyword argument is required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash as a request object (see above).

    Parameters:

    • parent (::String) (defaults to: nil)

      Required. The project in which the API key is created.

    • key (::Google::Cloud::ApiKeys::V2::Key, ::Hash) (defaults to: nil)

      Required. The API key fields to set at creation time. You can configure only the display_name, restrictions, and annotations fields.

    • key_id (::String) (defaults to: nil)

      User specified key id (optional). If specified, it will become the final component of the key resource name.

      The id must be unique within the project, must conform with RFC-1034, is restricted to lower-cased letters, and has a maximum length of 63 characters. In another word, the id must match the regular expression: [a-z]([a-z0-9-]{0,61}[a-z0-9])?.

      The id must NOT be a UUID-like string.

Yields:

  • (response, operation)

    Access the result along with the RPC operation

Yield Parameters:

  • response (::Gapic::Operation)
  • operation (::GRPC::ActiveCall::Operation)

Returns:

  • (::Gapic::Operation)

Raises:

  • (::Google::Cloud::Error)

    if the RPC is aborted.



230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
# File 'lib/google/cloud/api_keys/v2/api_keys/client.rb', line 230

def create_key request, options = nil
  raise ::ArgumentError, "request must be provided" if request.nil?

  request = ::Gapic::Protobuf.coerce request, to: ::Google::Cloud::ApiKeys::V2::CreateKeyRequest

  # Converts hash and nil to an options object
  options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h

  # Customize the options with defaults
   = @config.rpcs.create_key..to_h

  # Set x-goog-api-client and x-goog-user-project headers
  [:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \
    lib_name: @config.lib_name, lib_version: @config.lib_version,
    gapic_version: ::Google::Cloud::ApiKeys::V2::VERSION
  [:"x-goog-user-project"] = @quota_project_id if @quota_project_id

  header_params = {}
  if request.parent
    header_params["parent"] = request.parent
  end

  request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&")
  [:"x-goog-request-params"] ||= request_params_header

  options.apply_defaults timeout:      @config.rpcs.create_key.timeout,
                         metadata:     ,
                         retry_policy: @config.rpcs.create_key.retry_policy

  options.apply_defaults timeout:      @config.timeout,
                         metadata:     @config.,
                         retry_policy: @config.retry_policy

  @api_keys_stub.call_rpc :create_key, request, options: options do |response, operation|
    response = ::Gapic::Operation.new response, @operations_client, options: options
    yield response, operation if block_given?
    return response
  end
rescue ::GRPC::BadStatus => e
  raise ::Google::Cloud::Error.from_error(e)
end

#delete_key(request, options = nil) ⇒ ::Gapic::Operation #delete_key(name: nil, etag: nil) ⇒ ::Gapic::Operation

Deletes an API key. Deleted key can be retrieved within 30 days of deletion. Afterward, key will be purged from the project.

NOTE: Key is a global resource; hence the only supported value for location is global.

Examples:

Basic example

require "google/cloud/api_keys/v2"

# Create a client object. The client can be reused for multiple calls.
client = Google::Cloud::ApiKeys::V2::ApiKeys::Client.new

# Create a request. To set request fields, pass in keyword arguments.
request = Google::Cloud::ApiKeys::V2::DeleteKeyRequest.new

# Call the delete_key method.
result = client.delete_key request

# The returned object is of type Gapic::Operation. You can use this
# object to check the status of an operation, cancel it, or wait
# for results. Here is how to block until completion:
result.wait_until_done! timeout: 60
if result.response?
  p result.response
else
  puts "Error!"
end

Overloads:

  • #delete_key(request, options = nil) ⇒ ::Gapic::Operation

    Pass arguments to delete_key via a request object, either of type DeleteKeyRequest or an equivalent Hash.

    Parameters:

    • request (::Google::Cloud::ApiKeys::V2::DeleteKeyRequest, ::Hash)

      A request object representing the call parameters. Required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash.

    • options (::Gapic::CallOptions, ::Hash) (defaults to: nil)

      Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.

  • #delete_key(name: nil, etag: nil) ⇒ ::Gapic::Operation

    Pass arguments to delete_key via keyword arguments. Note that at least one keyword argument is required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash as a request object (see above).

    Parameters:

    • name (::String) (defaults to: nil)

      Required. The resource name of the API key to be deleted.

    • etag (::String) (defaults to: nil)

      Optional. The etag known to the client for the expected state of the key. This is to be used for optimistic concurrency.

Yields:

  • (response, operation)

    Access the result along with the RPC operation

Yield Parameters:

  • response (::Gapic::Operation)
  • operation (::GRPC::ActiveCall::Operation)

Returns:

  • (::Gapic::Operation)

Raises:

  • (::Google::Cloud::Error)

    if the RPC is aborted.



717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
# File 'lib/google/cloud/api_keys/v2/api_keys/client.rb', line 717

def delete_key request, options = nil
  raise ::ArgumentError, "request must be provided" if request.nil?

  request = ::Gapic::Protobuf.coerce request, to: ::Google::Cloud::ApiKeys::V2::DeleteKeyRequest

  # Converts hash and nil to an options object
  options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h

  # Customize the options with defaults
   = @config.rpcs.delete_key..to_h

  # Set x-goog-api-client and x-goog-user-project headers
  [:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \
    lib_name: @config.lib_name, lib_version: @config.lib_version,
    gapic_version: ::Google::Cloud::ApiKeys::V2::VERSION
  [:"x-goog-user-project"] = @quota_project_id if @quota_project_id

  header_params = {}
  if request.name
    header_params["name"] = request.name
  end

  request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&")
  [:"x-goog-request-params"] ||= request_params_header

  options.apply_defaults timeout:      @config.rpcs.delete_key.timeout,
                         metadata:     ,
                         retry_policy: @config.rpcs.delete_key.retry_policy

  options.apply_defaults timeout:      @config.timeout,
                         metadata:     @config.,
                         retry_policy: @config.retry_policy

  @api_keys_stub.call_rpc :delete_key, request, options: options do |response, operation|
    response = ::Gapic::Operation.new response, @operations_client, options: options
    yield response, operation if block_given?
    return response
  end
rescue ::GRPC::BadStatus => e
  raise ::Google::Cloud::Error.from_error(e)
end

#get_key(request, options = nil) ⇒ ::Google::Cloud::ApiKeys::V2::Key #get_key(name: nil) ⇒ ::Google::Cloud::ApiKeys::V2::Key

Gets the metadata for an API key. The key string of the API key isn't included in the response.

NOTE: Key is a global resource; hence the only supported value for location is global.

Examples:

Basic example

require "google/cloud/api_keys/v2"

# Create a client object. The client can be reused for multiple calls.
client = Google::Cloud::ApiKeys::V2::ApiKeys::Client.new

# Create a request. To set request fields, pass in keyword arguments.
request = Google::Cloud::ApiKeys::V2::GetKeyRequest.new

# Call the get_key method.
result = client.get_key request

# The returned object is of type Google::Cloud::ApiKeys::V2::Key.
p result

Overloads:

  • #get_key(request, options = nil) ⇒ ::Google::Cloud::ApiKeys::V2::Key

    Pass arguments to get_key via a request object, either of type GetKeyRequest or an equivalent Hash.

    Parameters:

    • request (::Google::Cloud::ApiKeys::V2::GetKeyRequest, ::Hash)

      A request object representing the call parameters. Required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash.

    • options (::Gapic::CallOptions, ::Hash) (defaults to: nil)

      Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.

  • #get_key(name: nil) ⇒ ::Google::Cloud::ApiKeys::V2::Key

    Pass arguments to get_key via keyword arguments. Note that at least one keyword argument is required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash as a request object (see above).

    Parameters:

    • name (::String) (defaults to: nil)

      Required. The resource name of the API key to get.

Yields:

  • (response, operation)

    Access the result along with the RPC operation

Yield Parameters:

Returns:

Raises:

  • (::Google::Cloud::Error)

    if the RPC is aborted.



423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
# File 'lib/google/cloud/api_keys/v2/api_keys/client.rb', line 423

def get_key request, options = nil
  raise ::ArgumentError, "request must be provided" if request.nil?

  request = ::Gapic::Protobuf.coerce request, to: ::Google::Cloud::ApiKeys::V2::GetKeyRequest

  # Converts hash and nil to an options object
  options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h

  # Customize the options with defaults
   = @config.rpcs.get_key..to_h

  # Set x-goog-api-client and x-goog-user-project headers
  [:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \
    lib_name: @config.lib_name, lib_version: @config.lib_version,
    gapic_version: ::Google::Cloud::ApiKeys::V2::VERSION
  [:"x-goog-user-project"] = @quota_project_id if @quota_project_id

  header_params = {}
  if request.name
    header_params["name"] = request.name
  end

  request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&")
  [:"x-goog-request-params"] ||= request_params_header

  options.apply_defaults timeout:      @config.rpcs.get_key.timeout,
                         metadata:     ,
                         retry_policy: @config.rpcs.get_key.retry_policy

  options.apply_defaults timeout:      @config.timeout,
                         metadata:     @config.,
                         retry_policy: @config.retry_policy

  @api_keys_stub.call_rpc :get_key, request, options: options do |response, operation|
    yield response, operation if block_given?
    return response
  end
rescue ::GRPC::BadStatus => e
  raise ::Google::Cloud::Error.from_error(e)
end

#get_key_string(request, options = nil) ⇒ ::Google::Cloud::ApiKeys::V2::GetKeyStringResponse #get_key_string(name: nil) ⇒ ::Google::Cloud::ApiKeys::V2::GetKeyStringResponse

Get the key string for an API key.

NOTE: Key is a global resource; hence the only supported value for location is global.

Examples:

Basic example

require "google/cloud/api_keys/v2"

# Create a client object. The client can be reused for multiple calls.
client = Google::Cloud::ApiKeys::V2::ApiKeys::Client.new

# Create a request. To set request fields, pass in keyword arguments.
request = Google::Cloud::ApiKeys::V2::GetKeyStringRequest.new

# Call the get_key_string method.
result = client.get_key_string request

# The returned object is of type Google::Cloud::ApiKeys::V2::GetKeyStringResponse.
p result

Overloads:

  • #get_key_string(request, options = nil) ⇒ ::Google::Cloud::ApiKeys::V2::GetKeyStringResponse

    Pass arguments to get_key_string via a request object, either of type GetKeyStringRequest or an equivalent Hash.

    Parameters:

    • request (::Google::Cloud::ApiKeys::V2::GetKeyStringRequest, ::Hash)

      A request object representing the call parameters. Required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash.

    • options (::Gapic::CallOptions, ::Hash) (defaults to: nil)

      Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.

  • #get_key_string(name: nil) ⇒ ::Google::Cloud::ApiKeys::V2::GetKeyStringResponse

    Pass arguments to get_key_string via keyword arguments. Note that at least one keyword argument is required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash as a request object (see above).

    Parameters:

    • name (::String) (defaults to: nil)

      Required. The resource name of the API key to be retrieved.

Yields:

  • (response, operation)

    Access the result along with the RPC operation

Yield Parameters:

Returns:

Raises:

  • (::Google::Cloud::Error)

    if the RPC is aborted.



511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
# File 'lib/google/cloud/api_keys/v2/api_keys/client.rb', line 511

def get_key_string request, options = nil
  raise ::ArgumentError, "request must be provided" if request.nil?

  request = ::Gapic::Protobuf.coerce request, to: ::Google::Cloud::ApiKeys::V2::GetKeyStringRequest

  # Converts hash and nil to an options object
  options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h

  # Customize the options with defaults
   = @config.rpcs.get_key_string..to_h

  # Set x-goog-api-client and x-goog-user-project headers
  [:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \
    lib_name: @config.lib_name, lib_version: @config.lib_version,
    gapic_version: ::Google::Cloud::ApiKeys::V2::VERSION
  [:"x-goog-user-project"] = @quota_project_id if @quota_project_id

  header_params = {}
  if request.name
    header_params["name"] = request.name
  end

  request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&")
  [:"x-goog-request-params"] ||= request_params_header

  options.apply_defaults timeout:      @config.rpcs.get_key_string.timeout,
                         metadata:     ,
                         retry_policy: @config.rpcs.get_key_string.retry_policy

  options.apply_defaults timeout:      @config.timeout,
                         metadata:     @config.,
                         retry_policy: @config.retry_policy

  @api_keys_stub.call_rpc :get_key_string, request, options: options do |response, operation|
    yield response, operation if block_given?
    return response
  end
rescue ::GRPC::BadStatus => e
  raise ::Google::Cloud::Error.from_error(e)
end

#list_keys(request, options = nil) ⇒ ::Gapic::PagedEnumerable<::Google::Cloud::ApiKeys::V2::Key> #list_keys(parent: nil, page_size: nil, page_token: nil, show_deleted: nil) ⇒ ::Gapic::PagedEnumerable<::Google::Cloud::ApiKeys::V2::Key>

Lists the API keys owned by a project. The key string of the API key isn't included in the response.

NOTE: Key is a global resource; hence the only supported value for location is global.

Examples:

Basic example

require "google/cloud/api_keys/v2"

# Create a client object. The client can be reused for multiple calls.
client = Google::Cloud::ApiKeys::V2::ApiKeys::Client.new

# Create a request. To set request fields, pass in keyword arguments.
request = Google::Cloud::ApiKeys::V2::ListKeysRequest.new

# Call the list_keys method.
result = client.list_keys request

# The returned object is of type Gapic::PagedEnumerable. You can
# iterate over all elements by calling #each, and the enumerable
# will lazily make API calls to fetch subsequent pages. Other
# methods are also available for managing paging directly.
result.each do |response|
  # Each element is of type ::Google::Cloud::ApiKeys::V2::Key.
  p response
end

Overloads:

  • #list_keys(request, options = nil) ⇒ ::Gapic::PagedEnumerable<::Google::Cloud::ApiKeys::V2::Key>

    Pass arguments to list_keys via a request object, either of type ListKeysRequest or an equivalent Hash.

    Parameters:

    • request (::Google::Cloud::ApiKeys::V2::ListKeysRequest, ::Hash)

      A request object representing the call parameters. Required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash.

    • options (::Gapic::CallOptions, ::Hash) (defaults to: nil)

      Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.

  • #list_keys(parent: nil, page_size: nil, page_token: nil, show_deleted: nil) ⇒ ::Gapic::PagedEnumerable<::Google::Cloud::ApiKeys::V2::Key>

    Pass arguments to list_keys via keyword arguments. Note that at least one keyword argument is required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash as a request object (see above).

    Parameters:

    • parent (::String) (defaults to: nil)

      Required. Lists all API keys associated with this project.

    • page_size (::Integer) (defaults to: nil)

      Optional. Specifies the maximum number of results to be returned at a time.

    • page_token (::String) (defaults to: nil)

      Optional. Requests a specific page of results.

    • show_deleted (::Boolean) (defaults to: nil)

      Optional. Indicate that keys deleted in the past 30 days should also be returned.

Yields:

  • (response, operation)

    Access the result along with the RPC operation

Yield Parameters:

Returns:

Raises:

  • (::Google::Cloud::Error)

    if the RPC is aborted.



333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
# File 'lib/google/cloud/api_keys/v2/api_keys/client.rb', line 333

def list_keys request, options = nil
  raise ::ArgumentError, "request must be provided" if request.nil?

  request = ::Gapic::Protobuf.coerce request, to: ::Google::Cloud::ApiKeys::V2::ListKeysRequest

  # Converts hash and nil to an options object
  options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h

  # Customize the options with defaults
   = @config.rpcs.list_keys..to_h

  # Set x-goog-api-client and x-goog-user-project headers
  [:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \
    lib_name: @config.lib_name, lib_version: @config.lib_version,
    gapic_version: ::Google::Cloud::ApiKeys::V2::VERSION
  [:"x-goog-user-project"] = @quota_project_id if @quota_project_id

  header_params = {}
  if request.parent
    header_params["parent"] = request.parent
  end

  request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&")
  [:"x-goog-request-params"] ||= request_params_header

  options.apply_defaults timeout:      @config.rpcs.list_keys.timeout,
                         metadata:     ,
                         retry_policy: @config.rpcs.list_keys.retry_policy

  options.apply_defaults timeout:      @config.timeout,
                         metadata:     @config.,
                         retry_policy: @config.retry_policy

  @api_keys_stub.call_rpc :list_keys, request, options: options do |response, operation|
    response = ::Gapic::PagedEnumerable.new @api_keys_stub, :list_keys, request, response, operation, options
    yield response, operation if block_given?
    return response
  end
rescue ::GRPC::BadStatus => e
  raise ::Google::Cloud::Error.from_error(e)
end

#lookup_key(request, options = nil) ⇒ ::Google::Cloud::ApiKeys::V2::LookupKeyResponse #lookup_key(key_string: nil) ⇒ ::Google::Cloud::ApiKeys::V2::LookupKeyResponse

Find the parent project and resource name of the API key that matches the key string in the request. If the API key has been purged, resource name will not be set. The service account must have the apikeys.keys.lookup permission on the parent project.

Examples:

Basic example

require "google/cloud/api_keys/v2"

# Create a client object. The client can be reused for multiple calls.
client = Google::Cloud::ApiKeys::V2::ApiKeys::Client.new

# Create a request. To set request fields, pass in keyword arguments.
request = Google::Cloud::ApiKeys::V2::LookupKeyRequest.new

# Call the lookup_key method.
result = client.lookup_key request

# The returned object is of type Google::Cloud::ApiKeys::V2::LookupKeyResponse.
p result

Overloads:

  • #lookup_key(request, options = nil) ⇒ ::Google::Cloud::ApiKeys::V2::LookupKeyResponse

    Pass arguments to lookup_key via a request object, either of type LookupKeyRequest or an equivalent Hash.

    Parameters:

    • request (::Google::Cloud::ApiKeys::V2::LookupKeyRequest, ::Hash)

      A request object representing the call parameters. Required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash.

    • options (::Gapic::CallOptions, ::Hash) (defaults to: nil)

      Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.

  • #lookup_key(key_string: nil) ⇒ ::Google::Cloud::ApiKeys::V2::LookupKeyResponse

    Pass arguments to lookup_key via keyword arguments. Note that at least one keyword argument is required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash as a request object (see above).

    Parameters:

    • key_string (::String) (defaults to: nil)

      Required. Finds the project that owns the key string value.

Yields:

  • (response, operation)

    Access the result along with the RPC operation

Yield Parameters:

Returns:

Raises:

  • (::Google::Cloud::Error)

    if the RPC is aborted.



903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
# File 'lib/google/cloud/api_keys/v2/api_keys/client.rb', line 903

def lookup_key request, options = nil
  raise ::ArgumentError, "request must be provided" if request.nil?

  request = ::Gapic::Protobuf.coerce request, to: ::Google::Cloud::ApiKeys::V2::LookupKeyRequest

  # Converts hash and nil to an options object
  options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h

  # Customize the options with defaults
   = @config.rpcs.lookup_key..to_h

  # Set x-goog-api-client and x-goog-user-project headers
  [:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \
    lib_name: @config.lib_name, lib_version: @config.lib_version,
    gapic_version: ::Google::Cloud::ApiKeys::V2::VERSION
  [:"x-goog-user-project"] = @quota_project_id if @quota_project_id

  options.apply_defaults timeout:      @config.rpcs.lookup_key.timeout,
                         metadata:     ,
                         retry_policy: @config.rpcs.lookup_key.retry_policy

  options.apply_defaults timeout:      @config.timeout,
                         metadata:     @config.,
                         retry_policy: @config.retry_policy

  @api_keys_stub.call_rpc :lookup_key, request, options: options do |response, operation|
    yield response, operation if block_given?
    return response
  end
rescue ::GRPC::BadStatus => e
  raise ::Google::Cloud::Error.from_error(e)
end

#undelete_key(request, options = nil) ⇒ ::Gapic::Operation #undelete_key(name: nil) ⇒ ::Gapic::Operation

Undeletes an API key which was deleted within 30 days.

NOTE: Key is a global resource; hence the only supported value for location is global.

Examples:

Basic example

require "google/cloud/api_keys/v2"

# Create a client object. The client can be reused for multiple calls.
client = Google::Cloud::ApiKeys::V2::ApiKeys::Client.new

# Create a request. To set request fields, pass in keyword arguments.
request = Google::Cloud::ApiKeys::V2::UndeleteKeyRequest.new

# Call the undelete_key method.
result = client.undelete_key request

# The returned object is of type Gapic::Operation. You can use this
# object to check the status of an operation, cancel it, or wait
# for results. Here is how to block until completion:
result.wait_until_done! timeout: 60
if result.response?
  p result.response
else
  puts "Error!"
end

Overloads:

  • #undelete_key(request, options = nil) ⇒ ::Gapic::Operation

    Pass arguments to undelete_key via a request object, either of type UndeleteKeyRequest or an equivalent Hash.

    Parameters:

    • request (::Google::Cloud::ApiKeys::V2::UndeleteKeyRequest, ::Hash)

      A request object representing the call parameters. Required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash.

    • options (::Gapic::CallOptions, ::Hash) (defaults to: nil)

      Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.

  • #undelete_key(name: nil) ⇒ ::Gapic::Operation

    Pass arguments to undelete_key via keyword arguments. Note that at least one keyword argument is required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash as a request object (see above).

    Parameters:

    • name (::String) (defaults to: nil)

      Required. The resource name of the API key to be undeleted.

Yields:

  • (response, operation)

    Access the result along with the RPC operation

Yield Parameters:

  • response (::Gapic::Operation)
  • operation (::GRPC::ActiveCall::Operation)

Returns:

  • (::Gapic::Operation)

Raises:

  • (::Google::Cloud::Error)

    if the RPC is aborted.



813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
# File 'lib/google/cloud/api_keys/v2/api_keys/client.rb', line 813

def undelete_key request, options = nil
  raise ::ArgumentError, "request must be provided" if request.nil?

  request = ::Gapic::Protobuf.coerce request, to: ::Google::Cloud::ApiKeys::V2::UndeleteKeyRequest

  # Converts hash and nil to an options object
  options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h

  # Customize the options with defaults
   = @config.rpcs.undelete_key..to_h

  # Set x-goog-api-client and x-goog-user-project headers
  [:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \
    lib_name: @config.lib_name, lib_version: @config.lib_version,
    gapic_version: ::Google::Cloud::ApiKeys::V2::VERSION
  [:"x-goog-user-project"] = @quota_project_id if @quota_project_id

  header_params = {}
  if request.name
    header_params["name"] = request.name
  end

  request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&")
  [:"x-goog-request-params"] ||= request_params_header

  options.apply_defaults timeout:      @config.rpcs.undelete_key.timeout,
                         metadata:     ,
                         retry_policy: @config.rpcs.undelete_key.retry_policy

  options.apply_defaults timeout:      @config.timeout,
                         metadata:     @config.,
                         retry_policy: @config.retry_policy

  @api_keys_stub.call_rpc :undelete_key, request, options: options do |response, operation|
    response = ::Gapic::Operation.new response, @operations_client, options: options
    yield response, operation if block_given?
    return response
  end
rescue ::GRPC::BadStatus => e
  raise ::Google::Cloud::Error.from_error(e)
end

#update_key(request, options = nil) ⇒ ::Gapic::Operation #update_key(key: nil, update_mask: nil) ⇒ ::Gapic::Operation

Patches the modifiable fields of an API key. The key string of the API key isn't included in the response.

NOTE: Key is a global resource; hence the only supported value for location is global.

Examples:

Basic example

require "google/cloud/api_keys/v2"

# Create a client object. The client can be reused for multiple calls.
client = Google::Cloud::ApiKeys::V2::ApiKeys::Client.new

# Create a request. To set request fields, pass in keyword arguments.
request = Google::Cloud::ApiKeys::V2::UpdateKeyRequest.new

# Call the update_key method.
result = client.update_key request

# The returned object is of type Gapic::Operation. You can use this
# object to check the status of an operation, cancel it, or wait
# for results. Here is how to block until completion:
result.wait_until_done! timeout: 60
if result.response?
  p result.response
else
  puts "Error!"
end

Overloads:

  • #update_key(request, options = nil) ⇒ ::Gapic::Operation

    Pass arguments to update_key via a request object, either of type UpdateKeyRequest or an equivalent Hash.

    Parameters:

    • request (::Google::Cloud::ApiKeys::V2::UpdateKeyRequest, ::Hash)

      A request object representing the call parameters. Required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash.

    • options (::Gapic::CallOptions, ::Hash) (defaults to: nil)

      Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.

  • #update_key(key: nil, update_mask: nil) ⇒ ::Gapic::Operation

    Pass arguments to update_key via keyword arguments. Note that at least one keyword argument is required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash as a request object (see above).

    Parameters:

    • key (::Google::Cloud::ApiKeys::V2::Key, ::Hash) (defaults to: nil)

      Required. Set the name field to the resource name of the API key to be updated. You can update only the display_name, restrictions, and annotations fields.

    • update_mask (::Google::Protobuf::FieldMask, ::Hash) (defaults to: nil)

      The field mask specifies which fields to be updated as part of this request. All other fields are ignored. Mutable fields are: display_name, restrictions, and annotations. If an update mask is not provided, the service treats it as an implied mask equivalent to all allowed fields that are set on the wire. If the field mask has a special value "*", the service treats it equivalent to replace all allowed mutable fields.

Yields:

  • (response, operation)

    Access the result along with the RPC operation

Yield Parameters:

  • response (::Gapic::Operation)
  • operation (::GRPC::ActiveCall::Operation)

Returns:

  • (::Gapic::Operation)

Raises:

  • (::Google::Cloud::Error)

    if the RPC is aborted.



617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
# File 'lib/google/cloud/api_keys/v2/api_keys/client.rb', line 617

def update_key request, options = nil
  raise ::ArgumentError, "request must be provided" if request.nil?

  request = ::Gapic::Protobuf.coerce request, to: ::Google::Cloud::ApiKeys::V2::UpdateKeyRequest

  # Converts hash and nil to an options object
  options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h

  # Customize the options with defaults
   = @config.rpcs.update_key..to_h

  # Set x-goog-api-client and x-goog-user-project headers
  [:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \
    lib_name: @config.lib_name, lib_version: @config.lib_version,
    gapic_version: ::Google::Cloud::ApiKeys::V2::VERSION
  [:"x-goog-user-project"] = @quota_project_id if @quota_project_id

  header_params = {}
  if request.key&.name
    header_params["key.name"] = request.key.name
  end

  request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&")
  [:"x-goog-request-params"] ||= request_params_header

  options.apply_defaults timeout:      @config.rpcs.update_key.timeout,
                         metadata:     ,
                         retry_policy: @config.rpcs.update_key.retry_policy

  options.apply_defaults timeout:      @config.timeout,
                         metadata:     @config.,
                         retry_policy: @config.retry_policy

  @api_keys_stub.call_rpc :update_key, request, options: options do |response, operation|
    response = ::Gapic::Operation.new response, @operations_client, options: options
    yield response, operation if block_given?
    return response
  end
rescue ::GRPC::BadStatus => e
  raise ::Google::Cloud::Error.from_error(e)
end