Class: Google::Cloud::Kms::V1::KeyManagementServiceClient

Inherits:
Object
  • Object
show all
Defined in:
lib/google/cloud/kms/v1/key_management_service_client.rb,
lib/google/cloud/kms/v1/helpers.rb

Overview

Google Cloud Key Management Service

Manages cryptographic keys and operations using those keys. Implements a REST model with the following objects:

If you are using manual gRPC libraries, see Using gRPC with Cloud KMS.

Constant Summary collapse

SERVICE_ADDRESS =

The default address of the service.

"cloudkms.googleapis.com".freeze
DEFAULT_SERVICE_PORT =

The default port of the service.

443
GRPC_INTERCEPTORS =

The default set of gRPC interceptors.

[]
DEFAULT_TIMEOUT =
30
ALL_SCOPES =

The scopes needed to make gRPC calls to all of the methods defined in this service.

[
  "https://www.googleapis.com/auth/cloud-platform",
  "https://www.googleapis.com/auth/cloudkms"
].freeze

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(credentials: nil, scopes: ALL_SCOPES, client_config: {}, timeout: DEFAULT_TIMEOUT, metadata: nil, service_address: nil, service_port: nil, exception_transformer: nil, lib_name: nil, lib_version: "") ⇒ KeyManagementServiceClient

Returns a new instance of KeyManagementServiceClient.

Parameters:

  • credentials (Google::Auth::Credentials, String, Hash, GRPC::Core::Channel, GRPC::Core::ChannelCredentials, Proc) (defaults to: nil)

    Provides the means for authenticating requests made by the client. This parameter can be many types. A Google::Auth::Credentials uses a the properties of its represented keyfile for authenticating requests made by this client. A String will be treated as the path to the keyfile to be used for the construction of credentials for this client. A Hash will be treated as the contents of a keyfile to be used for the construction of credentials for this client. A GRPC::Core::Channel will be used to make calls through. A GRPC::Core::ChannelCredentials for the setting up the RPC client. The channel credentials should already be composed with a GRPC::Core::CallCredentials object. A Proc will be used as an updater_proc for the Grpc channel. The proc transforms the metadata for requests, generally, to give OAuth credentials.

  • scopes (Array<String>) (defaults to: ALL_SCOPES)

    The OAuth scopes for this service. This parameter is ignored if an updater_proc is supplied.

  • client_config (Hash) (defaults to: {})

    A Hash for call options for each method. See Google::Gax#construct_settings for the structure of this data. Falls back to the default config if not specified or the specified config is missing data points.

  • timeout (Numeric) (defaults to: DEFAULT_TIMEOUT)

    The default timeout, in seconds, for calls made through this client.

  • metadata (Hash) (defaults to: nil)

    Default metadata to be sent with each request. This can be overridden on a per call basis.

  • service_address (String) (defaults to: nil)

    Override for the service hostname, or nil to leave as the default.

  • service_port (Integer) (defaults to: nil)

    Override for the service port, or nil to leave as the default.

  • exception_transformer (Proc) (defaults to: nil)

    An optional proc that intercepts any exceptions raised during an API call to inject custom error handling.



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
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
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
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
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
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
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
# File 'lib/google/cloud/kms/v1/key_management_service_client.rb', line 237

def initialize \
    credentials: nil,
    scopes: ALL_SCOPES,
    client_config: {},
    timeout: DEFAULT_TIMEOUT,
    metadata: nil,
    service_address: nil,
    service_port: nil,
    exception_transformer: nil,
    lib_name: nil,
    lib_version: ""
  # 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 "google/gax/grpc"
  require "google/cloud/kms/v1/service_services_pb"
  require "google/iam/v1/iam_policy_services_pb"

  credentials ||= Google::Cloud::Kms::V1::Credentials.default

  if credentials.is_a?(String) || credentials.is_a?(Hash)
    updater_proc = Google::Cloud::Kms::V1::Credentials.new(credentials).updater_proc
  end
  if credentials.is_a?(GRPC::Core::Channel)
    channel = credentials
  end
  if credentials.is_a?(GRPC::Core::ChannelCredentials)
    chan_creds = credentials
  end
  if credentials.is_a?(Proc)
    updater_proc = credentials
  end
  if credentials.is_a?(Google::Auth::Credentials)
    updater_proc = credentials.updater_proc
  end

  package_version = Google::Cloud::Kms::VERSION

  google_api_client = "gl-ruby/#{RUBY_VERSION}"
  google_api_client << " #{lib_name}/#{lib_version}" if lib_name
  google_api_client << " gapic/#{package_version} gax/#{Google::Gax::VERSION}"
  google_api_client << " grpc/#{GRPC::VERSION}"
  google_api_client.freeze

  headers = { :"x-goog-api-client" => google_api_client }
  if credentials.respond_to?(:quota_project_id) && credentials.quota_project_id
    headers[:"x-goog-user-project"] = credentials.quota_project_id
  end
  headers.merge!() unless .nil?
  client_config_file = Pathname.new(__dir__).join(
    "key_management_service_client_config.json"
  )
  defaults = client_config_file.open do |f|
    Google::Gax.construct_settings(
      "google.cloud.kms.v1.KeyManagementService",
      JSON.parse(f.read),
      client_config,
      Google::Gax::Grpc::STATUS_CODE_NAMES,
      timeout,
      page_descriptors: PAGE_DESCRIPTORS,
      errors: Google::Gax::Grpc::API_ERRORS,
      metadata: headers
    )
  end

  # Allow overriding the service path/port in subclasses.
  service_path = service_address || self.class::SERVICE_ADDRESS
  port = service_port || self.class::DEFAULT_SERVICE_PORT
  interceptors = self.class::GRPC_INTERCEPTORS
  @key_management_service_stub = Google::Gax::Grpc.create_stub(
    service_path,
    port,
    chan_creds: chan_creds,
    channel: channel,
    updater_proc: updater_proc,
    scopes: scopes,
    interceptors: interceptors,
    &Google::Cloud::Kms::V1::KeyManagementService::Stub.method(:new)
  )
  @iam_policy_stub = Google::Gax::Grpc.create_stub(
    service_path,
    port,
    chan_creds: chan_creds,
    channel: channel,
    updater_proc: updater_proc,
    scopes: scopes,
    interceptors: interceptors,
    &Google::Iam::V1::IAMPolicy::Stub.method(:new)
  )

  @list_key_rings = Google::Gax.create_api_call(
    @key_management_service_stub.method(:list_key_rings),
    defaults["list_key_rings"],
    exception_transformer: exception_transformer,
    params_extractor: proc do |request|
      {'parent' => request.parent}
    end
  )
  @list_import_jobs = Google::Gax.create_api_call(
    @key_management_service_stub.method(:list_import_jobs),
    defaults["list_import_jobs"],
    exception_transformer: exception_transformer,
    params_extractor: proc do |request|
      {'parent' => request.parent}
    end
  )
  @list_crypto_keys = Google::Gax.create_api_call(
    @key_management_service_stub.method(:list_crypto_keys),
    defaults["list_crypto_keys"],
    exception_transformer: exception_transformer,
    params_extractor: proc do |request|
      {'parent' => request.parent}
    end
  )
  @list_crypto_key_versions = Google::Gax.create_api_call(
    @key_management_service_stub.method(:list_crypto_key_versions),
    defaults["list_crypto_key_versions"],
    exception_transformer: exception_transformer,
    params_extractor: proc do |request|
      {'parent' => request.parent}
    end
  )
  @get_key_ring = Google::Gax.create_api_call(
    @key_management_service_stub.method(:get_key_ring),
    defaults["get_key_ring"],
    exception_transformer: exception_transformer,
    params_extractor: proc do |request|
      {'name' => request.name}
    end
  )
  @get_import_job = Google::Gax.create_api_call(
    @key_management_service_stub.method(:get_import_job),
    defaults["get_import_job"],
    exception_transformer: exception_transformer,
    params_extractor: proc do |request|
      {'name' => request.name}
    end
  )
  @get_crypto_key = Google::Gax.create_api_call(
    @key_management_service_stub.method(:get_crypto_key),
    defaults["get_crypto_key"],
    exception_transformer: exception_transformer,
    params_extractor: proc do |request|
      {'name' => request.name}
    end
  )
  @get_crypto_key_version = Google::Gax.create_api_call(
    @key_management_service_stub.method(:get_crypto_key_version),
    defaults["get_crypto_key_version"],
    exception_transformer: exception_transformer,
    params_extractor: proc do |request|
      {'name' => request.name}
    end
  )
  @create_key_ring = Google::Gax.create_api_call(
    @key_management_service_stub.method(:create_key_ring),
    defaults["create_key_ring"],
    exception_transformer: exception_transformer,
    params_extractor: proc do |request|
      {'parent' => request.parent}
    end
  )
  @create_import_job = Google::Gax.create_api_call(
    @key_management_service_stub.method(:create_import_job),
    defaults["create_import_job"],
    exception_transformer: exception_transformer,
    params_extractor: proc do |request|
      {'parent' => request.parent}
    end
  )
  @create_crypto_key = Google::Gax.create_api_call(
    @key_management_service_stub.method(:create_crypto_key),
    defaults["create_crypto_key"],
    exception_transformer: exception_transformer,
    params_extractor: proc do |request|
      {'parent' => request.parent}
    end
  )
  @create_crypto_key_version = Google::Gax.create_api_call(
    @key_management_service_stub.method(:create_crypto_key_version),
    defaults["create_crypto_key_version"],
    exception_transformer: exception_transformer,
    params_extractor: proc do |request|
      {'parent' => request.parent}
    end
  )
  @import_crypto_key_version = Google::Gax.create_api_call(
    @key_management_service_stub.method(:import_crypto_key_version),
    defaults["import_crypto_key_version"],
    exception_transformer: exception_transformer,
    params_extractor: proc do |request|
      {'parent' => request.parent}
    end
  )
  @update_crypto_key = Google::Gax.create_api_call(
    @key_management_service_stub.method(:update_crypto_key),
    defaults["update_crypto_key"],
    exception_transformer: exception_transformer,
    params_extractor: proc do |request|
      {'crypto_key.name' => request.crypto_key.name}
    end
  )
  @update_crypto_key_version = Google::Gax.create_api_call(
    @key_management_service_stub.method(:update_crypto_key_version),
    defaults["update_crypto_key_version"],
    exception_transformer: exception_transformer,
    params_extractor: proc do |request|
      {'crypto_key_version.name' => request.crypto_key_version.name}
    end
  )
  @encrypt = Google::Gax.create_api_call(
    @key_management_service_stub.method(:encrypt),
    defaults["encrypt"],
    exception_transformer: exception_transformer,
    params_extractor: proc do |request|
      {'name' => request.name}
    end
  )
  @decrypt = Google::Gax.create_api_call(
    @key_management_service_stub.method(:decrypt),
    defaults["decrypt"],
    exception_transformer: exception_transformer,
    params_extractor: proc do |request|
      {'name' => request.name}
    end
  )
  @update_crypto_key_primary_version = Google::Gax.create_api_call(
    @key_management_service_stub.method(:update_crypto_key_primary_version),
    defaults["update_crypto_key_primary_version"],
    exception_transformer: exception_transformer,
    params_extractor: proc do |request|
      {'name' => request.name}
    end
  )
  @destroy_crypto_key_version = Google::Gax.create_api_call(
    @key_management_service_stub.method(:destroy_crypto_key_version),
    defaults["destroy_crypto_key_version"],
    exception_transformer: exception_transformer,
    params_extractor: proc do |request|
      {'name' => request.name}
    end
  )
  @restore_crypto_key_version = Google::Gax.create_api_call(
    @key_management_service_stub.method(:restore_crypto_key_version),
    defaults["restore_crypto_key_version"],
    exception_transformer: exception_transformer,
    params_extractor: proc do |request|
      {'name' => request.name}
    end
  )
  @get_public_key = Google::Gax.create_api_call(
    @key_management_service_stub.method(:get_public_key),
    defaults["get_public_key"],
    exception_transformer: exception_transformer,
    params_extractor: proc do |request|
      {'name' => request.name}
    end
  )
  @asymmetric_decrypt = Google::Gax.create_api_call(
    @key_management_service_stub.method(:asymmetric_decrypt),
    defaults["asymmetric_decrypt"],
    exception_transformer: exception_transformer,
    params_extractor: proc do |request|
      {'name' => request.name}
    end
  )
  @asymmetric_sign = Google::Gax.create_api_call(
    @key_management_service_stub.method(:asymmetric_sign),
    defaults["asymmetric_sign"],
    exception_transformer: exception_transformer,
    params_extractor: proc do |request|
      {'name' => request.name}
    end
  )
  @set_iam_policy = Google::Gax.create_api_call(
    @iam_policy_stub.method(:set_iam_policy),
    defaults["set_iam_policy"],
    exception_transformer: exception_transformer,
    params_extractor: proc do |request|
      {'resource' => request.resource}
    end
  )
  @get_iam_policy = Google::Gax.create_api_call(
    @iam_policy_stub.method(:get_iam_policy),
    defaults["get_iam_policy"],
    exception_transformer: exception_transformer,
    params_extractor: proc do |request|
      {'resource' => request.resource}
    end
  )
  @test_iam_permissions = Google::Gax.create_api_call(
    @iam_policy_stub.method(:test_iam_permissions),
    defaults["test_iam_permissions"],
    exception_transformer: exception_transformer,
    params_extractor: proc do |request|
      {'resource' => request.resource}
    end
  )
end

Class Method Details

.crypto_key_path(project, location, key_ring, crypto_key) ⇒ String

Returns a fully-qualified crypto_key resource name string.

Parameters:

  • project (String)
  • location (String)
  • key_ring (String)
  • crypto_key (String)

Returns:

  • (String)


134
135
136
137
138
139
140
141
# File 'lib/google/cloud/kms/v1/key_management_service_client.rb', line 134

def self.crypto_key_path project, location, key_ring, crypto_key
  CRYPTO_KEY_PATH_TEMPLATE.render(
    :"project" => project,
    :"location" => location,
    :"key_ring" => key_ring,
    :"crypto_key" => crypto_key
  )
end

.crypto_key_path_path(project, location, key_ring, crypto_key_path) ⇒ Object

Returns a fully-qualified crypto_key_path resource name string.



144
145
146
# File 'lib/google/cloud/kms/v1/key_management_service_client.rb', line 144

def self.crypto_key_path_path project, location, key_ring, crypto_key_path
  "projects/#{project}/locations/#{location}/keyRings/#{key_ring}/cryptoKeys/#{crypto_key_path}"
end

.crypto_key_version_path(project, location, key_ring, crypto_key, crypto_key_version) ⇒ String

Returns a fully-qualified crypto_key_version resource name string.

Parameters:

  • project (String)
  • location (String)
  • key_ring (String)
  • crypto_key (String)
  • crypto_key_version (String)

Returns:

  • (String)


155
156
157
158
159
160
161
162
163
# File 'lib/google/cloud/kms/v1/key_management_service_client.rb', line 155

def self.crypto_key_version_path project, location, key_ring, crypto_key, crypto_key_version
  CRYPTO_KEY_VERSION_PATH_TEMPLATE.render(
    :"project" => project,
    :"location" => location,
    :"key_ring" => key_ring,
    :"crypto_key" => crypto_key,
    :"crypto_key_version" => crypto_key_version
  )
end

.import_job_path(project, location, key_ring, import_job) ⇒ String

Returns a fully-qualified import_job resource name string.

Parameters:

  • project (String)
  • location (String)
  • key_ring (String)
  • import_job (String)

Returns:

  • (String)


171
172
173
174
175
176
177
178
# File 'lib/google/cloud/kms/v1/key_management_service_client.rb', line 171

def self.import_job_path project, location, key_ring, import_job
  IMPORT_JOB_PATH_TEMPLATE.render(
    :"project" => project,
    :"location" => location,
    :"key_ring" => key_ring,
    :"import_job" => import_job
  )
end

.key_ring_path(project, location, key_ring) ⇒ String

Returns a fully-qualified key_ring resource name string.

Parameters:

  • project (String)
  • location (String)
  • key_ring (String)

Returns:

  • (String)


185
186
187
188
189
190
191
# File 'lib/google/cloud/kms/v1/key_management_service_client.rb', line 185

def self.key_ring_path project, location, key_ring
  KEY_RING_PATH_TEMPLATE.render(
    :"project" => project,
    :"location" => location,
    :"key_ring" => key_ring
  )
end

.location_path(project, location) ⇒ String

Returns a fully-qualified location resource name string.

Parameters:

  • project (String)
  • location (String)

Returns:

  • (String)


197
198
199
200
201
202
# File 'lib/google/cloud/kms/v1/key_management_service_client.rb', line 197

def self.location_path project, location
  LOCATION_PATH_TEMPLATE.render(
    :"project" => project,
    :"location" => location
  )
end

Instance Method Details

#asymmetric_decrypt(name, ciphertext, options: nil) {|result, operation| ... } ⇒ Google::Cloud::Kms::V1::AsymmetricDecryptResponse

Decrypts data that was encrypted with a public key retrieved from GetPublicKey corresponding to a CryptoKeyVersion with CryptoKey#purpose ASYMMETRIC_DECRYPT.

Examples:

require "google/cloud/kms"

key_management_client = Google::Cloud::Kms.new(version: :v1)
formatted_name = Google::Cloud::Kms::V1::KeyManagementServiceClient.crypto_key_version_path("[PROJECT]", "[LOCATION]", "[KEY_RING]", "[CRYPTO_KEY]", "[CRYPTO_KEY_VERSION]")

# TODO: Initialize `ciphertext`:
ciphertext = ''
response = key_management_client.asymmetric_decrypt(formatted_name, ciphertext)

Parameters:

  • name (String)

    Required. The resource name of the CryptoKeyVersion to use for decryption.

  • ciphertext (String)

    Required. The data encrypted with the named CryptoKeyVersion's public key using OAEP.

  • options (Google::Gax::CallOptions) (defaults to: nil)

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

Yields:

  • (result, operation)

    Access the result along with the RPC operation

Yield Parameters:

Returns:

Raises:

  • (Google::Gax::GaxError)

    if the RPC is aborted.



1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
# File 'lib/google/cloud/kms/v1/key_management_service_client.rb', line 1607

def asymmetric_decrypt \
    name,
    ciphertext,
    options: nil,
    &block
  req = {
    name: name,
    ciphertext: ciphertext
  }.delete_if { |_, v| v.nil? }
  req = Google::Gax::to_proto(req, Google::Cloud::Kms::V1::AsymmetricDecryptRequest)
  @asymmetric_decrypt.call(req, options, &block)
end

#asymmetric_sign(name, digest, options: nil) {|result, operation| ... } ⇒ Google::Cloud::Kms::V1::AsymmetricSignResponse

Signs data using a CryptoKeyVersion with CryptoKey#purpose ASYMMETRIC_SIGN, producing a signature that can be verified with the public key retrieved from GetPublicKey.

Examples:

require "google/cloud/kms"

key_management_client = Google::Cloud::Kms.new(version: :v1)
formatted_name = Google::Cloud::Kms::V1::KeyManagementServiceClient.crypto_key_version_path("[PROJECT]", "[LOCATION]", "[KEY_RING]", "[CRYPTO_KEY]", "[CRYPTO_KEY_VERSION]")

# TODO: Initialize `digest`:
digest = {}
response = key_management_client.asymmetric_sign(formatted_name, digest)

Parameters:

  • name (String)

    Required. The resource name of the CryptoKeyVersion to use for signing.

  • digest (Google::Cloud::Kms::V1::Digest | Hash)

    Required. The digest of the data to sign. The digest must be produced with the same digest algorithm as specified by the key version's algorithm. A hash of the same form as Google::Cloud::Kms::V1::Digest can also be provided.

  • options (Google::Gax::CallOptions) (defaults to: nil)

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

Yields:

  • (result, operation)

    Access the result along with the RPC operation

Yield Parameters:

Returns:

Raises:

  • (Google::Gax::GaxError)

    if the RPC is aborted.



1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
# File 'lib/google/cloud/kms/v1/key_management_service_client.rb', line 1650

def asymmetric_sign \
    name,
    digest,
    options: nil,
    &block
  req = {
    name: name,
    digest: digest
  }.delete_if { |_, v| v.nil? }
  req = Google::Gax::to_proto(req, Google::Cloud::Kms::V1::AsymmetricSignRequest)
  @asymmetric_sign.call(req, options, &block)
end

#create_crypto_key(parent, crypto_key_id, crypto_key, skip_initial_version_creation: nil, options: nil) {|result, operation| ... } ⇒ Google::Cloud::Kms::V1::CryptoKey

Create a new CryptoKey within a KeyRing.

CryptoKey#purpose and CryptoKey#version_template#algorithm are required.

Examples:

require "google/cloud/kms"

key_management_client = Google::Cloud::Kms.new(version: :v1)
formatted_parent = Google::Cloud::Kms::V1::KeyManagementServiceClient.key_ring_path("[PROJECT]", "[LOCATION]", "[KEY_RING]")
crypto_key_id = "my-app-key"
purpose = :ENCRYPT_DECRYPT
seconds = 2147483647
next_rotation_time = { seconds: seconds }
seconds_2 = 604800
rotation_period = { seconds: seconds_2 }
crypto_key = {
  purpose: purpose,
  next_rotation_time: next_rotation_time,
  rotation_period: rotation_period
}
response = key_management_client.create_crypto_key(formatted_parent, crypto_key_id, crypto_key)

Parameters:

  • parent (String)

    Required. The name of the KeyRing associated with the CryptoKeys.

  • crypto_key_id (String)

    Required. It must be unique within a KeyRing and match the regular expression [a-zA-Z0-9_-]{1,63}

  • crypto_key (Google::Cloud::Kms::V1::CryptoKey | Hash)

    Required. A CryptoKey with initial field values. A hash of the same form as Google::Cloud::Kms::V1::CryptoKey can also be provided.

  • skip_initial_version_creation (true, false) (defaults to: nil)

    If set to true, the request will create a CryptoKey without any CryptoKeyVersions. You must manually call CreateCryptoKeyVersion or ImportCryptoKeyVersion before you can use this CryptoKey.

  • options (Google::Gax::CallOptions) (defaults to: nil)

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

Yields:

  • (result, operation)

    Access the result along with the RPC operation

Yield Parameters:

Returns:

Raises:

  • (Google::Gax::GaxError)

    if the RPC is aborted.



1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
# File 'lib/google/cloud/kms/v1/key_management_service_client.rb', line 1088

def create_crypto_key \
    parent,
    crypto_key_id,
    crypto_key,
    skip_initial_version_creation: nil,
    options: nil,
    &block
  req = {
    parent: parent,
    crypto_key_id: crypto_key_id,
    crypto_key: crypto_key,
    skip_initial_version_creation: skip_initial_version_creation
  }.delete_if { |_, v| v.nil? }
  req = Google::Gax::to_proto(req, Google::Cloud::Kms::V1::CreateCryptoKeyRequest)
  @create_crypto_key.call(req, options, &block)
end

#create_crypto_key_version(parent, crypto_key_version, options: nil) {|result, operation| ... } ⇒ Google::Cloud::Kms::V1::CryptoKeyVersion

Create a new CryptoKeyVersion in a CryptoKey.

The server will assign the next sequential id. If unset, state will be set to ENABLED.

Examples:

require "google/cloud/kms"

key_management_client = Google::Cloud::Kms.new(version: :v1)
formatted_parent = Google::Cloud::Kms::V1::KeyManagementServiceClient.crypto_key_path("[PROJECT]", "[LOCATION]", "[KEY_RING]", "[CRYPTO_KEY]")

# TODO: Initialize `crypto_key_version`:
crypto_key_version = {}
response = key_management_client.create_crypto_key_version(formatted_parent, crypto_key_version)

Parameters:

  • parent (String)

    Required. The name of the CryptoKey associated with the CryptoKeyVersions.

  • crypto_key_version (Google::Cloud::Kms::V1::CryptoKeyVersion | Hash)

    Required. A CryptoKeyVersion with initial field values. A hash of the same form as Google::Cloud::Kms::V1::CryptoKeyVersion can also be provided.

  • options (Google::Gax::CallOptions) (defaults to: nil)

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

Yields:

  • (result, operation)

    Access the result along with the RPC operation

Yield Parameters:

Returns:

Raises:

  • (Google::Gax::GaxError)

    if the RPC is aborted.



1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
# File 'lib/google/cloud/kms/v1/key_management_service_client.rb', line 1136

def create_crypto_key_version \
    parent,
    crypto_key_version,
    options: nil,
    &block
  req = {
    parent: parent,
    crypto_key_version: crypto_key_version
  }.delete_if { |_, v| v.nil? }
  req = Google::Gax::to_proto(req, Google::Cloud::Kms::V1::CreateCryptoKeyVersionRequest)
  @create_crypto_key_version.call(req, options, &block)
end

#create_import_job(parent, import_job_id, import_job, options: nil) {|result, operation| ... } ⇒ Google::Cloud::Kms::V1::ImportJob

Create a new ImportJob within a KeyRing.

ImportJob#import_method is required.

Examples:

require "google/cloud/kms"

key_management_client = Google::Cloud::Kms.new(version: :v1)
formatted_parent = Google::Cloud::Kms::V1::KeyManagementServiceClient.key_ring_path("[PROJECT]", "[LOCATION]", "[KEY_RING]")
import_job_id = "my-import-job"
import_method = :RSA_OAEP_3072_SHA1_AES_256
protection_level = :HSM
import_job = { import_method: import_method, protection_level: protection_level }
response = key_management_client.create_import_job(formatted_parent, import_job_id, import_job)

Parameters:

  • parent (String)

    Required. The name of the KeyRing associated with the ImportJobs.

  • import_job_id (String)

    Required. It must be unique within a KeyRing and match the regular expression [a-zA-Z0-9_-]{1,63}

  • import_job (Google::Cloud::Kms::V1::ImportJob | Hash)

    Required. An ImportJob with initial field values. A hash of the same form as Google::Cloud::Kms::V1::ImportJob can also be provided.

  • options (Google::Gax::CallOptions) (defaults to: nil)

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

Yields:

  • (result, operation)

    Access the result along with the RPC operation

Yield Parameters:

Returns:

Raises:

  • (Google::Gax::GaxError)

    if the RPC is aborted.



1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
# File 'lib/google/cloud/kms/v1/key_management_service_client.rb', line 1025

def create_import_job \
    parent,
    import_job_id,
    import_job,
    options: nil,
    &block
  req = {
    parent: parent,
    import_job_id: import_job_id,
    import_job: import_job
  }.delete_if { |_, v| v.nil? }
  req = Google::Gax::to_proto(req, Google::Cloud::Kms::V1::CreateImportJobRequest)
  @create_import_job.call(req, options, &block)
end

#create_key_ring(parent, key_ring_id, key_ring, options: nil) {|result, operation| ... } ⇒ Google::Cloud::Kms::V1::KeyRing

Create a new KeyRing in a given Project and Location.

Examples:

require "google/cloud/kms"

key_management_client = Google::Cloud::Kms.new(version: :v1)
formatted_parent = Google::Cloud::Kms::V1::KeyManagementServiceClient.location_path("[PROJECT]", "[LOCATION]")

# TODO: Initialize `key_ring_id`:
key_ring_id = ''

# TODO: Initialize `key_ring`:
key_ring = {}
response = key_management_client.create_key_ring(formatted_parent, key_ring_id, key_ring)

Parameters:

  • parent (String)

    Required. The resource name of the location associated with the KeyRings, in the format projects/*/locations/*.

  • key_ring_id (String)

    Required. It must be unique within a location and match the regular expression [a-zA-Z0-9_-]{1,63}

  • key_ring (Google::Cloud::Kms::V1::KeyRing | Hash)

    Required. A KeyRing with initial field values. A hash of the same form as Google::Cloud::Kms::V1::KeyRing can also be provided.

  • options (Google::Gax::CallOptions) (defaults to: nil)

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

Yields:

  • (result, operation)

    Access the result along with the RPC operation

Yield Parameters:

Returns:

Raises:

  • (Google::Gax::GaxError)

    if the RPC is aborted.



977
978
979
980
981
982
983
984
985
986
987
988
989
990
# File 'lib/google/cloud/kms/v1/key_management_service_client.rb', line 977

def create_key_ring \
    parent,
    key_ring_id,
    key_ring,
    options: nil,
    &block
  req = {
    parent: parent,
    key_ring_id: key_ring_id,
    key_ring: key_ring
  }.delete_if { |_, v| v.nil? }
  req = Google::Gax::to_proto(req, Google::Cloud::Kms::V1::CreateKeyRingRequest)
  @create_key_ring.call(req, options, &block)
end

#crypto_key_path(project, location, key_ring, crypto_key) ⇒ String

Alias for Google::Cloud::Kms::V1::KeyManagementServiceClient.crypto_key_path.

Parameters:

  • project (String)
  • location (String)
  • key_ring (String)
  • crypto_key (String)

Returns:

  • (String)


25
26
27
# File 'lib/google/cloud/kms/v1/helpers.rb', line 25

def crypto_key_path project, location, key_ring, crypto_key
  self.class.crypto_key_path project, location, key_ring, crypto_key
end

#crypto_key_path_path(project, location, key_ring, crypto_key_path) ⇒ String

Alias for Google::Cloud::Kms::V1::KeyManagementServiceClient.crypto_key_path_path.

Parameters:

  • project (String)
  • location (String)
  • key_ring (String)
  • crypto_key_path (String)

Returns:

  • (String)


35
36
37
# File 'lib/google/cloud/kms/v1/helpers.rb', line 35

def crypto_key_path_path project, location, key_ring, crypto_key_path
  self.class.crypto_key_path_path project, location, key_ring, crypto_key_path
end

#crypto_key_version_path(project, location, key_ring, crypto_key, crypto_key_version) ⇒ String

Alias for Google::Cloud::Kms::V1::KeyManagementServiceClient.crypto_key_version_path.

Parameters:

  • project (String)
  • location (String)
  • key_ring (String)
  • crypto_key (String)
  • crypto_key_version (String)

Returns:

  • (String)


46
47
48
# File 'lib/google/cloud/kms/v1/helpers.rb', line 46

def crypto_key_version_path project, location, key_ring, crypto_key, crypto_key_version
  self.class.crypto_key_version_path project, location, key_ring, crypto_key, crypto_key_version
end

#decrypt(name, ciphertext, additional_authenticated_data: nil, options: nil) {|result, operation| ... } ⇒ Google::Cloud::Kms::V1::DecryptResponse

Decrypts data that was protected by Encrypt. The CryptoKey#purpose must be ENCRYPT_DECRYPT.

Examples:

require "google/cloud/kms"

key_management_client = Google::Cloud::Kms.new(version: :v1)
formatted_name = Google::Cloud::Kms::V1::KeyManagementServiceClient.crypto_key_path("[PROJECT]", "[LOCATION]", "[KEY_RING]", "[CRYPTO_KEY]")

# TODO: Initialize `ciphertext`:
ciphertext = ''
response = key_management_client.decrypt(formatted_name, ciphertext)

Parameters:

  • name (String)

    Required. The resource name of the CryptoKey to use for decryption. The server will choose the appropriate version.

  • ciphertext (String)

    Required. The encrypted data originally returned in EncryptResponse#ciphertext.

  • additional_authenticated_data (String) (defaults to: nil)

    Optional. Optional data that must match the data originally supplied in EncryptRequest#additional_authenticated_data.

  • options (Google::Gax::CallOptions) (defaults to: nil)

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

Yields:

  • (result, operation)

    Access the result along with the RPC operation

Yield Parameters:

Returns:

Raises:

  • (Google::Gax::GaxError)

    if the RPC is aborted.



1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
# File 'lib/google/cloud/kms/v1/key_management_service_client.rb', line 1414

def decrypt \
    name,
    ciphertext,
    additional_authenticated_data: nil,
    options: nil,
    &block
  req = {
    name: name,
    ciphertext: ciphertext,
    additional_authenticated_data: additional_authenticated_data
  }.delete_if { |_, v| v.nil? }
  req = Google::Gax::to_proto(req, Google::Cloud::Kms::V1::DecryptRequest)
  @decrypt.call(req, options, &block)
end

#destroy_crypto_key_version(name, options: nil) {|result, operation| ... } ⇒ Google::Cloud::Kms::V1::CryptoKeyVersion

Schedule a CryptoKeyVersion for destruction.

Upon calling this method, CryptoKeyVersion#state will be set to DESTROY_SCHEDULED and destroy_time will be set to a time 24 hours in the future, at which point the state will be changed to DESTROYED, and the key material will be irrevocably destroyed.

Before the destroy_time is reached, RestoreCryptoKeyVersion may be called to reverse the process.

Examples:

require "google/cloud/kms"

key_management_client = Google::Cloud::Kms.new(version: :v1)
formatted_name = Google::Cloud::Kms::V1::KeyManagementServiceClient.crypto_key_version_path("[PROJECT]", "[LOCATION]", "[KEY_RING]", "[CRYPTO_KEY]", "[CRYPTO_KEY_VERSION]")
response = key_management_client.destroy_crypto_key_version(formatted_name)

Parameters:

  • name (String)

    Required. The resource name of the CryptoKeyVersion to destroy.

  • options (Google::Gax::CallOptions) (defaults to: nil)

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

Yields:

  • (result, operation)

    Access the result along with the RPC operation

Yield Parameters:

Returns:

Raises:

  • (Google::Gax::GaxError)

    if the RPC is aborted.



1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
# File 'lib/google/cloud/kms/v1/key_management_service_client.rb', line 1498

def destroy_crypto_key_version \
    name,
    options: nil,
    &block
  req = {
    name: name
  }.delete_if { |_, v| v.nil? }
  req = Google::Gax::to_proto(req, Google::Cloud::Kms::V1::DestroyCryptoKeyVersionRequest)
  @destroy_crypto_key_version.call(req, options, &block)
end

#encrypt(name, plaintext, additional_authenticated_data: nil, options: nil) {|result, operation| ... } ⇒ Google::Cloud::Kms::V1::EncryptResponse

Encrypts data, so that it can only be recovered by a call to Decrypt. The CryptoKey#purpose must be ENCRYPT_DECRYPT.

Examples:

require "google/cloud/kms"

key_management_client = Google::Cloud::Kms.new(version: :v1)

# TODO: Initialize `name`:
name = ''

# TODO: Initialize `plaintext`:
plaintext = ''
response = key_management_client.encrypt(name, plaintext)

Parameters:

  • name (String)

    Required. The resource name of the CryptoKey or CryptoKeyVersion to use for encryption.

    If a CryptoKey is specified, the server will use its primary version.

  • plaintext (String)

    Required. The data to encrypt. Must be no larger than 64KiB.

    The maximum size depends on the key version's protection_level. For SOFTWARE keys, the plaintext must be no larger than 64KiB. For HSM keys, the combined length of the plaintext and additional_authenticated_data fields must be no larger than 8KiB.

  • additional_authenticated_data (String) (defaults to: nil)

    Optional. Optional data that, if specified, must also be provided during decryption through DecryptRequest#additional_authenticated_data.

    The maximum size depends on the key version's protection_level. For SOFTWARE keys, the AAD must be no larger than 64KiB. For HSM keys, the combined length of the plaintext and additional_authenticated_data fields must be no larger than 8KiB.

  • options (Google::Gax::CallOptions) (defaults to: nil)

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

Yields:

  • (result, operation)

    Access the result along with the RPC operation

Yield Parameters:

Returns:

Raises:

  • (Google::Gax::GaxError)

    if the RPC is aborted.



1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
# File 'lib/google/cloud/kms/v1/key_management_service_client.rb', line 1369

def encrypt \
    name,
    plaintext,
    additional_authenticated_data: nil,
    options: nil,
    &block
  req = {
    name: name,
    plaintext: plaintext,
    additional_authenticated_data: additional_authenticated_data
  }.delete_if { |_, v| v.nil? }
  req = Google::Gax::to_proto(req, Google::Cloud::Kms::V1::EncryptRequest)
  @encrypt.call(req, options, &block)
end

#get_crypto_key(name, options: nil) {|result, operation| ... } ⇒ Google::Cloud::Kms::V1::CryptoKey

Returns metadata for a given CryptoKey, as well as its primary CryptoKeyVersion.

Examples:

require "google/cloud/kms"

key_management_client = Google::Cloud::Kms.new(version: :v1)
formatted_name = Google::Cloud::Kms::V1::KeyManagementServiceClient.crypto_key_path("[PROJECT]", "[LOCATION]", "[KEY_RING]", "[CRYPTO_KEY]")
response = key_management_client.get_crypto_key(formatted_name)

Parameters:

  • name (String)

    Required. The name of the CryptoKey to get.

  • options (Google::Gax::CallOptions) (defaults to: nil)

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

Yields:

  • (result, operation)

    Access the result along with the RPC operation

Yield Parameters:

Returns:

Raises:

  • (Google::Gax::GaxError)

    if the RPC is aborted.



903
904
905
906
907
908
909
910
911
912
# File 'lib/google/cloud/kms/v1/key_management_service_client.rb', line 903

def get_crypto_key \
    name,
    options: nil,
    &block
  req = {
    name: name
  }.delete_if { |_, v| v.nil? }
  req = Google::Gax::to_proto(req, Google::Cloud::Kms::V1::GetCryptoKeyRequest)
  @get_crypto_key.call(req, options, &block)
end

#get_crypto_key_version(name, options: nil) {|result, operation| ... } ⇒ Google::Cloud::Kms::V1::CryptoKeyVersion

Returns metadata for a given CryptoKeyVersion.

Examples:

require "google/cloud/kms"

key_management_client = Google::Cloud::Kms.new(version: :v1)
formatted_name = Google::Cloud::Kms::V1::KeyManagementServiceClient.crypto_key_version_path("[PROJECT]", "[LOCATION]", "[KEY_RING]", "[CRYPTO_KEY]", "[CRYPTO_KEY_VERSION]")
response = key_management_client.get_crypto_key_version(formatted_name)

Parameters:

  • name (String)

    Required. The name of the CryptoKeyVersion to get.

  • options (Google::Gax::CallOptions) (defaults to: nil)

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

Yields:

  • (result, operation)

    Access the result along with the RPC operation

Yield Parameters:

Returns:

Raises:

  • (Google::Gax::GaxError)

    if the RPC is aborted.



933
934
935
936
937
938
939
940
941
942
# File 'lib/google/cloud/kms/v1/key_management_service_client.rb', line 933

def get_crypto_key_version \
    name,
    options: nil,
    &block
  req = {
    name: name
  }.delete_if { |_, v| v.nil? }
  req = Google::Gax::to_proto(req, Google::Cloud::Kms::V1::GetCryptoKeyVersionRequest)
  @get_crypto_key_version.call(req, options, &block)
end

#get_iam_policy(resource, options_: nil, options: nil) {|result, operation| ... } ⇒ Google::Iam::V1::Policy

Gets the access control policy for a resource. Returns an empty policy if the resource exists and does not have a policy set.

Examples:

require "google/cloud/kms"

key_management_client = Google::Cloud::Kms.new(version: :v1)

# TODO: Initialize `resource`:
resource = ''
response = key_management_client.get_iam_policy(resource)

Parameters:

  • resource (String)

    REQUIRED: The resource for which the policy is being requested. See the operation documentation for the appropriate value for this field.

  • options_ (Google::Iam::V1::GetPolicyOptions | Hash) (defaults to: nil)

    OPTIONAL: A GetPolicyOptions object for specifying options to GetIamPolicy. This field is only used by Cloud IAM. A hash of the same form as Google::Iam::V1::GetPolicyOptions can also be provided.

  • options (Google::Gax::CallOptions) (defaults to: nil)

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

Yields:

  • (result, operation)

    Access the result along with the RPC operation

Yield Parameters:

  • result (Google::Iam::V1::Policy)
  • operation (GRPC::ActiveCall::Operation)

Returns:

  • (Google::Iam::V1::Policy)

Raises:

  • (Google::Gax::GaxError)

    if the RPC is aborted.



1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
# File 'lib/google/cloud/kms/v1/key_management_service_client.rb', line 1740

def get_iam_policy \
    resource,
    options_: nil,
    options: nil,
    &block
  req = {
    resource: resource,
    options: options_
  }.delete_if { |_, v| v.nil? }
  req = Google::Gax::to_proto(req, Google::Iam::V1::GetIamPolicyRequest)
  @get_iam_policy.call(req, options, &block)
end

#get_import_job(name, options: nil) {|result, operation| ... } ⇒ Google::Cloud::Kms::V1::ImportJob

Returns metadata for a given ImportJob.

Examples:

require "google/cloud/kms"

key_management_client = Google::Cloud::Kms.new(version: :v1)
formatted_name = Google::Cloud::Kms::V1::KeyManagementServiceClient.import_job_path("[PROJECT]", "[LOCATION]", "[KEY_RING]", "[IMPORT_JOB]")
response = key_management_client.get_import_job(formatted_name)

Parameters:

  • name (String)

    Required. The name of the ImportJob to get.

  • options (Google::Gax::CallOptions) (defaults to: nil)

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

Yields:

  • (result, operation)

    Access the result along with the RPC operation

Yield Parameters:

Returns:

Raises:

  • (Google::Gax::GaxError)

    if the RPC is aborted.



872
873
874
875
876
877
878
879
880
881
# File 'lib/google/cloud/kms/v1/key_management_service_client.rb', line 872

def get_import_job \
    name,
    options: nil,
    &block
  req = {
    name: name
  }.delete_if { |_, v| v.nil? }
  req = Google::Gax::to_proto(req, Google::Cloud::Kms::V1::GetImportJobRequest)
  @get_import_job.call(req, options, &block)
end

#get_key_ring(name, options: nil) {|result, operation| ... } ⇒ Google::Cloud::Kms::V1::KeyRing

Returns metadata for a given KeyRing.

Examples:

require "google/cloud/kms"

key_management_client = Google::Cloud::Kms.new(version: :v1)
formatted_name = Google::Cloud::Kms::V1::KeyManagementServiceClient.key_ring_path("[PROJECT]", "[LOCATION]", "[KEY_RING]")
response = key_management_client.get_key_ring(formatted_name)

Parameters:

  • name (String)

    Required. The name of the KeyRing to get.

  • options (Google::Gax::CallOptions) (defaults to: nil)

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

Yields:

  • (result, operation)

    Access the result along with the RPC operation

Yield Parameters:

Returns:

Raises:

  • (Google::Gax::GaxError)

    if the RPC is aborted.



842
843
844
845
846
847
848
849
850
851
# File 'lib/google/cloud/kms/v1/key_management_service_client.rb', line 842

def get_key_ring \
    name,
    options: nil,
    &block
  req = {
    name: name
  }.delete_if { |_, v| v.nil? }
  req = Google::Gax::to_proto(req, Google::Cloud::Kms::V1::GetKeyRingRequest)
  @get_key_ring.call(req, options, &block)
end

#get_public_key(name, options: nil) {|result, operation| ... } ⇒ Google::Cloud::Kms::V1::PublicKey

Returns the public key for the given CryptoKeyVersion. The CryptoKey#purpose must be ASYMMETRIC_SIGN or ASYMMETRIC_DECRYPT.

Examples:

require "google/cloud/kms"

key_management_client = Google::Cloud::Kms.new(version: :v1)
formatted_name = Google::Cloud::Kms::V1::KeyManagementServiceClient.crypto_key_version_path("[PROJECT]", "[LOCATION]", "[KEY_RING]", "[CRYPTO_KEY]", "[CRYPTO_KEY_VERSION]")
response = key_management_client.get_public_key(formatted_name)

Parameters:

  • name (String)

    Required. The name of the CryptoKeyVersion public key to get.

  • options (Google::Gax::CallOptions) (defaults to: nil)

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

Yields:

  • (result, operation)

    Access the result along with the RPC operation

Yield Parameters:

Returns:

Raises:

  • (Google::Gax::GaxError)

    if the RPC is aborted.



1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
# File 'lib/google/cloud/kms/v1/key_management_service_client.rb', line 1568

def get_public_key \
    name,
    options: nil,
    &block
  req = {
    name: name
  }.delete_if { |_, v| v.nil? }
  req = Google::Gax::to_proto(req, Google::Cloud::Kms::V1::GetPublicKeyRequest)
  @get_public_key.call(req, options, &block)
end

#import_crypto_key_version(parent, algorithm, import_job, rsa_aes_wrapped_key: nil, options: nil) {|result, operation| ... } ⇒ Google::Cloud::Kms::V1::CryptoKeyVersion

Imports a new CryptoKeyVersion into an existing CryptoKey using the wrapped key material provided in the request.

The version ID will be assigned the next sequential id within the CryptoKey.

Examples:

require "google/cloud/kms"

key_management_client = Google::Cloud::Kms.new(version: :v1)
formatted_parent = Google::Cloud::Kms::V1::KeyManagementServiceClient.crypto_key_path("[PROJECT]", "[LOCATION]", "[KEY_RING]", "[CRYPTO_KEY]")

# TODO: Initialize `algorithm`:
algorithm = :CRYPTO_KEY_VERSION_ALGORITHM_UNSPECIFIED

# TODO: Initialize `import_job`:
import_job = ''
response = key_management_client.import_crypto_key_version(formatted_parent, algorithm, import_job)

Parameters:

  • parent (String)

    Required. The name of the CryptoKey to be imported into.

  • algorithm (Google::Cloud::Kms::V1::CryptoKeyVersion::CryptoKeyVersionAlgorithm)

    Required. The algorithm of the key being imported. This does not need to match the version_template of the CryptoKey this version imports into.

  • import_job (String)

    Required. The name of the ImportJob that was used to wrap this key material.

  • rsa_aes_wrapped_key (String) (defaults to: nil)

    Wrapped key material produced with RSA_OAEP_3072_SHA1_AES_256 or RSA_OAEP_4096_SHA1_AES_256.

    This field contains the concatenation of two wrapped keys:

    1. An ephemeral AES-256 wrapping key wrapped with the public_key using RSAES-OAEP with SHA-1, MGF1 with SHA-1, and an empty label.
    2. The key to be imported, wrapped with the ephemeral AES-256 key using AES-KWP (RFC 5649).

    If importing symmetric key material, it is expected that the unwrapped key contains plain bytes. If importing asymmetric key material, it is expected that the unwrapped key is in PKCS#8-encoded DER format (the PrivateKeyInfo structure from RFC 5208).

    This format is the same as the format produced by PKCS#11 mechanism CKM_RSA_AES_KEY_WRAP.

  • options (Google::Gax::CallOptions) (defaults to: nil)

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

Yields:

  • (result, operation)

    Access the result along with the RPC operation

Yield Parameters:

Returns:

Raises:

  • (Google::Gax::GaxError)

    if the RPC is aborted.



1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
# File 'lib/google/cloud/kms/v1/key_management_service_client.rb', line 1211

def import_crypto_key_version \
    parent,
    algorithm,
    import_job,
    rsa_aes_wrapped_key: nil,
    options: nil,
    &block
  req = {
    parent: parent,
    algorithm: algorithm,
    import_job: import_job,
    rsa_aes_wrapped_key: rsa_aes_wrapped_key
  }.delete_if { |_, v| v.nil? }
  req = Google::Gax::to_proto(req, Google::Cloud::Kms::V1::ImportCryptoKeyVersionRequest)
  @import_crypto_key_version.call(req, options, &block)
end

#import_job_path(project, location, key_ring, import_job) ⇒ String

Alias for Google::Cloud::Kms::V1::KeyManagementServiceClient.import_job_path.

Parameters:

  • project (String)
  • location (String)
  • key_ring (String)
  • import_job (String)

Returns:

  • (String)


56
57
58
# File 'lib/google/cloud/kms/v1/helpers.rb', line 56

def import_job_path project, location, key_ring, import_job
  self.class.import_job_path project, location, key_ring, import_job
end

#key_ring_path(project, location, key_ring) ⇒ String

Alias for Google::Cloud::Kms::V1::KeyManagementServiceClient.key_ring_path.

Parameters:

  • project (String)
  • location (String)
  • key_ring (String)

Returns:

  • (String)


65
66
67
# File 'lib/google/cloud/kms/v1/helpers.rb', line 65

def key_ring_path project, location, key_ring
  self.class.key_ring_path project, location, key_ring
end

#list_crypto_key_versions(parent, page_size: nil, view: nil, filter: nil, order_by: nil, options: nil) {|result, operation| ... } ⇒ Google::Gax::PagedEnumerable<Google::Cloud::Kms::V1::CryptoKeyVersion>

Examples:

require "google/cloud/kms"

key_management_client = Google::Cloud::Kms.new(version: :v1)
formatted_parent = Google::Cloud::Kms::V1::KeyManagementServiceClient.crypto_key_path("[PROJECT]", "[LOCATION]", "[KEY_RING]", "[CRYPTO_KEY]")

# Iterate over all results.
key_management_client.list_crypto_key_versions(formatted_parent).each do |element|
  # Process element.
end

# Or iterate over results one page at a time.
key_management_client.list_crypto_key_versions(formatted_parent).each_page do |page|
  # Process each page at a time.
  page.each do |element|
    # Process element.
  end
end

Parameters:

  • parent (String)

    Required. The resource name of the CryptoKey to list, in the format projects/*/locations/*/keyRings/*/cryptoKeys/*.

  • page_size (Integer) (defaults to: nil)

    The maximum number of resources contained in the underlying API response. If page streaming is performed per-resource, this parameter does not affect the return value. If page streaming is performed per-page, this determines the maximum number of resources in a page.

  • view (Google::Cloud::Kms::V1::CryptoKeyVersion::CryptoKeyVersionView) (defaults to: nil)

    The fields to include in the response.

  • filter (String) (defaults to: nil)

    Optional. Only include resources that match the filter in the response. For more information, see Sorting and filtering list results.

  • order_by (String) (defaults to: nil)

    Optional. Specify how the results should be sorted. If not specified, the results will be sorted in the default order. For more information, see Sorting and filtering list results.

  • options (Google::Gax::CallOptions) (defaults to: nil)

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

Yields:

  • (result, operation)

    Access the result along with the RPC operation

Yield Parameters:

Returns:

  • (Google::Gax::PagedEnumerable<Google::Cloud::Kms::V1::CryptoKeyVersion>)

    An enumerable of Google::Cloud::Kms::V1::CryptoKeyVersion instances. See Google::Gax::PagedEnumerable documentation for other operations such as per-page iteration or access to the response object.

Raises:

  • (Google::Gax::GaxError)

    if the RPC is aborted.



804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
# File 'lib/google/cloud/kms/v1/key_management_service_client.rb', line 804

def list_crypto_key_versions \
    parent,
    page_size: nil,
    view: nil,
    filter: nil,
    order_by: nil,
    options: nil,
    &block
  req = {
    parent: parent,
    page_size: page_size,
    view: view,
    filter: filter,
    order_by: order_by
  }.delete_if { |_, v| v.nil? }
  req = Google::Gax::to_proto(req, Google::Cloud::Kms::V1::ListCryptoKeyVersionsRequest)
  @list_crypto_key_versions.call(req, options, &block)
end

#list_crypto_keys(parent, page_size: nil, version_view: nil, filter: nil, order_by: nil, options: nil) {|result, operation| ... } ⇒ Google::Gax::PagedEnumerable<Google::Cloud::Kms::V1::CryptoKey>

Lists CryptoKeys.

Examples:

require "google/cloud/kms"

key_management_client = Google::Cloud::Kms.new(version: :v1)
formatted_parent = Google::Cloud::Kms::V1::KeyManagementServiceClient.key_ring_path("[PROJECT]", "[LOCATION]", "[KEY_RING]")

# Iterate over all results.
key_management_client.list_crypto_keys(formatted_parent).each do |element|
  # Process element.
end

# Or iterate over results one page at a time.
key_management_client.list_crypto_keys(formatted_parent).each_page do |page|
  # Process each page at a time.
  page.each do |element|
    # Process element.
  end
end

Parameters:

  • parent (String)

    Required. The resource name of the KeyRing to list, in the format projects/*/locations/*/keyRings/*.

  • page_size (Integer) (defaults to: nil)

    The maximum number of resources contained in the underlying API response. If page streaming is performed per-resource, this parameter does not affect the return value. If page streaming is performed per-page, this determines the maximum number of resources in a page.

  • version_view (Google::Cloud::Kms::V1::CryptoKeyVersion::CryptoKeyVersionView) (defaults to: nil)

    The fields of the primary version to include in the response.

  • filter (String) (defaults to: nil)

    Optional. Only include resources that match the filter in the response. For more information, see Sorting and filtering list results.

  • order_by (String) (defaults to: nil)

    Optional. Specify how the results should be sorted. If not specified, the results will be sorted in the default order. For more information, see Sorting and filtering list results.

  • options (Google::Gax::CallOptions) (defaults to: nil)

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

Yields:

  • (result, operation)

    Access the result along with the RPC operation

Yield Parameters:

Returns:

  • (Google::Gax::PagedEnumerable<Google::Cloud::Kms::V1::CryptoKey>)

    An enumerable of Google::Cloud::Kms::V1::CryptoKey instances. See Google::Gax::PagedEnumerable documentation for other operations such as per-page iteration or access to the response object.

Raises:

  • (Google::Gax::GaxError)

    if the RPC is aborted.



731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
# File 'lib/google/cloud/kms/v1/key_management_service_client.rb', line 731

def list_crypto_keys \
    parent,
    page_size: nil,
    version_view: nil,
    filter: nil,
    order_by: nil,
    options: nil,
    &block
  req = {
    parent: parent,
    page_size: page_size,
    version_view: version_view,
    filter: filter,
    order_by: order_by
  }.delete_if { |_, v| v.nil? }
  req = Google::Gax::to_proto(req, Google::Cloud::Kms::V1::ListCryptoKeysRequest)
  @list_crypto_keys.call(req, options, &block)
end

#list_import_jobs(parent, page_size: nil, filter: nil, order_by: nil, options: nil) {|result, operation| ... } ⇒ Google::Gax::PagedEnumerable<Google::Cloud::Kms::V1::ImportJob>

Lists ImportJobs.

Examples:

require "google/cloud/kms"

key_management_client = Google::Cloud::Kms.new(version: :v1)
formatted_parent = Google::Cloud::Kms::V1::KeyManagementServiceClient.key_ring_path("[PROJECT]", "[LOCATION]", "[KEY_RING]")

# Iterate over all results.
key_management_client.list_import_jobs(formatted_parent).each do |element|
  # Process element.
end

# Or iterate over results one page at a time.
key_management_client.list_import_jobs(formatted_parent).each_page do |page|
  # Process each page at a time.
  page.each do |element|
    # Process element.
  end
end

Parameters:

  • parent (String)

    Required. The resource name of the KeyRing to list, in the format projects/*/locations/*/keyRings/*.

  • page_size (Integer) (defaults to: nil)

    The maximum number of resources contained in the underlying API response. If page streaming is performed per-resource, this parameter does not affect the return value. If page streaming is performed per-page, this determines the maximum number of resources in a page.

  • filter (String) (defaults to: nil)

    Optional. Only include resources that match the filter in the response. For more information, see Sorting and filtering list results.

  • order_by (String) (defaults to: nil)

    Optional. Specify how the results should be sorted. If not specified, the results will be sorted in the default order. For more information, see Sorting and filtering list results.

  • options (Google::Gax::CallOptions) (defaults to: nil)

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

Yields:

  • (result, operation)

    Access the result along with the RPC operation

Yield Parameters:

Returns:

  • (Google::Gax::PagedEnumerable<Google::Cloud::Kms::V1::ImportJob>)

    An enumerable of Google::Cloud::Kms::V1::ImportJob instances. See Google::Gax::PagedEnumerable documentation for other operations such as per-page iteration or access to the response object.

Raises:

  • (Google::Gax::GaxError)

    if the RPC is aborted.



660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
# File 'lib/google/cloud/kms/v1/key_management_service_client.rb', line 660

def list_import_jobs \
    parent,
    page_size: nil,
    filter: nil,
    order_by: nil,
    options: nil,
    &block
  req = {
    parent: parent,
    page_size: page_size,
    filter: filter,
    order_by: order_by
  }.delete_if { |_, v| v.nil? }
  req = Google::Gax::to_proto(req, Google::Cloud::Kms::V1::ListImportJobsRequest)
  @list_import_jobs.call(req, options, &block)
end

#list_key_rings(parent, page_size: nil, filter: nil, order_by: nil, options: nil) {|result, operation| ... } ⇒ Google::Gax::PagedEnumerable<Google::Cloud::Kms::V1::KeyRing>

Lists KeyRings.

Examples:

require "google/cloud/kms"

key_management_client = Google::Cloud::Kms.new(version: :v1)
formatted_parent = Google::Cloud::Kms::V1::KeyManagementServiceClient.location_path("[PROJECT]", "[LOCATION]")

# Iterate over all results.
key_management_client.list_key_rings(formatted_parent).each do |element|
  # Process element.
end

# Or iterate over results one page at a time.
key_management_client.list_key_rings(formatted_parent).each_page do |page|
  # Process each page at a time.
  page.each do |element|
    # Process element.
  end
end

Parameters:

  • parent (String)

    Required. The resource name of the location associated with the KeyRings, in the format projects/*/locations/*.

  • page_size (Integer) (defaults to: nil)

    The maximum number of resources contained in the underlying API response. If page streaming is performed per-resource, this parameter does not affect the return value. If page streaming is performed per-page, this determines the maximum number of resources in a page.

  • filter (String) (defaults to: nil)

    Optional. Only include resources that match the filter in the response. For more information, see Sorting and filtering list results.

  • order_by (String) (defaults to: nil)

    Optional. Specify how the results should be sorted. If not specified, the results will be sorted in the default order. For more information, see Sorting and filtering list results.

  • options (Google::Gax::CallOptions) (defaults to: nil)

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

Yields:

  • (result, operation)

    Access the result along with the RPC operation

Yield Parameters:

Returns:

  • (Google::Gax::PagedEnumerable<Google::Cloud::Kms::V1::KeyRing>)

    An enumerable of Google::Cloud::Kms::V1::KeyRing instances. See Google::Gax::PagedEnumerable documentation for other operations such as per-page iteration or access to the response object.

Raises:

  • (Google::Gax::GaxError)

    if the RPC is aborted.



591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
# File 'lib/google/cloud/kms/v1/key_management_service_client.rb', line 591

def list_key_rings \
    parent,
    page_size: nil,
    filter: nil,
    order_by: nil,
    options: nil,
    &block
  req = {
    parent: parent,
    page_size: page_size,
    filter: filter,
    order_by: order_by
  }.delete_if { |_, v| v.nil? }
  req = Google::Gax::to_proto(req, Google::Cloud::Kms::V1::ListKeyRingsRequest)
  @list_key_rings.call(req, options, &block)
end

#location_path(project, location) ⇒ String

Alias for Google::Cloud::Kms::V1::KeyManagementServiceClient.location_path.

Parameters:

  • project (String)
  • location (String)

Returns:

  • (String)


73
74
75
# File 'lib/google/cloud/kms/v1/helpers.rb', line 73

def location_path project, location
  self.class.location_path project, location
end

#restore_crypto_key_version(name, options: nil) {|result, operation| ... } ⇒ Google::Cloud::Kms::V1::CryptoKeyVersion

Restore a CryptoKeyVersion in the DESTROY_SCHEDULED state.

Upon restoration of the CryptoKeyVersion, state will be set to DISABLED, and destroy_time will be cleared.

Examples:

require "google/cloud/kms"

key_management_client = Google::Cloud::Kms.new(version: :v1)
formatted_name = Google::Cloud::Kms::V1::KeyManagementServiceClient.crypto_key_version_path("[PROJECT]", "[LOCATION]", "[KEY_RING]", "[CRYPTO_KEY]", "[CRYPTO_KEY_VERSION]")
response = key_management_client.restore_crypto_key_version(formatted_name)

Parameters:

  • name (String)

    Required. The resource name of the CryptoKeyVersion to restore.

  • options (Google::Gax::CallOptions) (defaults to: nil)

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

Yields:

  • (result, operation)

    Access the result along with the RPC operation

Yield Parameters:

Returns:

Raises:

  • (Google::Gax::GaxError)

    if the RPC is aborted.



1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
# File 'lib/google/cloud/kms/v1/key_management_service_client.rb', line 1534

def restore_crypto_key_version \
    name,
    options: nil,
    &block
  req = {
    name: name
  }.delete_if { |_, v| v.nil? }
  req = Google::Gax::to_proto(req, Google::Cloud::Kms::V1::RestoreCryptoKeyVersionRequest)
  @restore_crypto_key_version.call(req, options, &block)
end

#set_iam_policy(resource, policy, options: nil) {|result, operation| ... } ⇒ Google::Iam::V1::Policy

Sets the access control policy on the specified resource. Replaces any existing policy.

Can return Public Errors: NOT_FOUND, INVALID_ARGUMENT and PERMISSION_DENIED

Examples:

require "google/cloud/kms"

key_management_client = Google::Cloud::Kms.new(version: :v1)

# TODO: Initialize `resource`:
resource = ''

# TODO: Initialize `policy`:
policy = {}
response = key_management_client.set_iam_policy(resource, policy)

Parameters:

  • resource (String)

    REQUIRED: The resource for which the policy is being specified. See the operation documentation for the appropriate value for this field.

  • policy (Google::Iam::V1::Policy | Hash)

    REQUIRED: The complete policy to be applied to the resource. The size of the policy is limited to a few 10s of KB. An empty policy is a valid policy but certain Cloud Platform services (such as Projects) might reject them. A hash of the same form as Google::Iam::V1::Policy can also be provided.

  • options (Google::Gax::CallOptions) (defaults to: nil)

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

Yields:

  • (result, operation)

    Access the result along with the RPC operation

Yield Parameters:

  • result (Google::Iam::V1::Policy)
  • operation (GRPC::ActiveCall::Operation)

Returns:

  • (Google::Iam::V1::Policy)

Raises:

  • (Google::Gax::GaxError)

    if the RPC is aborted.



1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
# File 'lib/google/cloud/kms/v1/key_management_service_client.rb', line 1699

def set_iam_policy \
    resource,
    policy,
    options: nil,
    &block
  req = {
    resource: resource,
    policy: policy
  }.delete_if { |_, v| v.nil? }
  req = Google::Gax::to_proto(req, Google::Iam::V1::SetIamPolicyRequest)
  @set_iam_policy.call(req, options, &block)
end

#test_iam_permissions(resource, permissions, options: nil) {|result, operation| ... } ⇒ Google::Iam::V1::TestIamPermissionsResponse

Returns permissions that a caller has on the specified resource. If the resource does not exist, this will return an empty set of permissions, not a NOT_FOUND error.

Note: This operation is designed to be used for building permission-aware UIs and command-line tools, not for authorization checking. This operation may "fail open" without warning.

Examples:

require "google/cloud/kms"

key_management_client = Google::Cloud::Kms.new(version: :v1)

# TODO: Initialize `resource`:
resource = ''

# TODO: Initialize `permissions`:
permissions = []
response = key_management_client.test_iam_permissions(resource, permissions)

Parameters:

  • resource (String)

    REQUIRED: The resource for which the policy detail is being requested. See the operation documentation for the appropriate value for this field.

  • permissions (Array<String>)

    The set of permissions to check for the resource. Permissions with wildcards (such as '' or 'storage.') are not allowed. For more information see IAM Overview.

  • options (Google::Gax::CallOptions) (defaults to: nil)

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

Yields:

  • (result, operation)

    Access the result along with the RPC operation

Yield Parameters:

  • result (Google::Iam::V1::TestIamPermissionsResponse)
  • operation (GRPC::ActiveCall::Operation)

Returns:

  • (Google::Iam::V1::TestIamPermissionsResponse)

Raises:

  • (Google::Gax::GaxError)

    if the RPC is aborted.



1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
# File 'lib/google/cloud/kms/v1/key_management_service_client.rb', line 1789

def test_iam_permissions \
    resource,
    permissions,
    options: nil,
    &block
  req = {
    resource: resource,
    permissions: permissions
  }.delete_if { |_, v| v.nil? }
  req = Google::Gax::to_proto(req, Google::Iam::V1::TestIamPermissionsRequest)
  @test_iam_permissions.call(req, options, &block)
end

#update_crypto_key(crypto_key, update_mask, options: nil) {|result, operation| ... } ⇒ Google::Cloud::Kms::V1::CryptoKey

Update a CryptoKey.

Examples:

require "google/cloud/kms"

key_management_client = Google::Cloud::Kms.new(version: :v1)

# TODO: Initialize `crypto_key`:
crypto_key = {}

# TODO: Initialize `update_mask`:
update_mask = {}
response = key_management_client.update_crypto_key(crypto_key, update_mask)

Parameters:

  • crypto_key (Google::Cloud::Kms::V1::CryptoKey | Hash)

    Required. CryptoKey with updated values. A hash of the same form as Google::Cloud::Kms::V1::CryptoKey can also be provided.

  • update_mask (Google::Protobuf::FieldMask | Hash)

    Required. List of fields to be updated in this request. A hash of the same form as Google::Protobuf::FieldMask can also be provided.

  • options (Google::Gax::CallOptions) (defaults to: nil)

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

Yields:

  • (result, operation)

    Access the result along with the RPC operation

Yield Parameters:

Returns:

Raises:

  • (Google::Gax::GaxError)

    if the RPC is aborted.



1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
# File 'lib/google/cloud/kms/v1/key_management_service_client.rb', line 1258

def update_crypto_key \
    crypto_key,
    update_mask,
    options: nil,
    &block
  req = {
    crypto_key: crypto_key,
    update_mask: update_mask
  }.delete_if { |_, v| v.nil? }
  req = Google::Gax::to_proto(req, Google::Cloud::Kms::V1::UpdateCryptoKeyRequest)
  @update_crypto_key.call(req, options, &block)
end

#update_crypto_key_primary_version(name, crypto_key_version_id, options: nil) {|result, operation| ... } ⇒ Google::Cloud::Kms::V1::CryptoKey

Update the version of a CryptoKey that will be used in Encrypt.

Returns an error if called on an asymmetric key.

Examples:

require "google/cloud/kms"

key_management_client = Google::Cloud::Kms.new(version: :v1)
formatted_name = Google::Cloud::Kms::V1::KeyManagementServiceClient.crypto_key_path("[PROJECT]", "[LOCATION]", "[KEY_RING]", "[CRYPTO_KEY]")

# TODO: Initialize `crypto_key_version_id`:
crypto_key_version_id = ''
response = key_management_client.update_crypto_key_primary_version(formatted_name, crypto_key_version_id)

Parameters:

  • name (String)

    Required. The resource name of the CryptoKey to update.

  • crypto_key_version_id (String)

    Required. The id of the child CryptoKeyVersion to use as primary.

  • options (Google::Gax::CallOptions) (defaults to: nil)

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

Yields:

  • (result, operation)

    Access the result along with the RPC operation

Yield Parameters:

Returns:

Raises:

  • (Google::Gax::GaxError)

    if the RPC is aborted.



1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
# File 'lib/google/cloud/kms/v1/key_management_service_client.rb', line 1455

def update_crypto_key_primary_version \
    name,
    crypto_key_version_id,
    options: nil,
    &block
  req = {
    name: name,
    crypto_key_version_id: crypto_key_version_id
  }.delete_if { |_, v| v.nil? }
  req = Google::Gax::to_proto(req, Google::Cloud::Kms::V1::UpdateCryptoKeyPrimaryVersionRequest)
  @update_crypto_key_primary_version.call(req, options, &block)
end

#update_crypto_key_version(crypto_key_version, update_mask, options: nil) {|result, operation| ... } ⇒ Google::Cloud::Kms::V1::CryptoKeyVersion

Update a CryptoKeyVersion's metadata.

state may be changed between ENABLED and DISABLED using this method. See DestroyCryptoKeyVersion and RestoreCryptoKeyVersion to move between other states.

Examples:

require "google/cloud/kms"

key_management_client = Google::Cloud::Kms.new(version: :v1)

# TODO: Initialize `crypto_key_version`:
crypto_key_version = {}

# TODO: Initialize `update_mask`:
update_mask = {}
response = key_management_client.update_crypto_key_version(crypto_key_version, update_mask)

Parameters:

  • crypto_key_version (Google::Cloud::Kms::V1::CryptoKeyVersion | Hash)

    Required. CryptoKeyVersion with updated values. A hash of the same form as Google::Cloud::Kms::V1::CryptoKeyVersion can also be provided.

  • update_mask (Google::Protobuf::FieldMask | Hash)

    Required. List of fields to be updated in this request. A hash of the same form as Google::Protobuf::FieldMask can also be provided.

  • options (Google::Gax::CallOptions) (defaults to: nil)

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

Yields:

  • (result, operation)

    Access the result along with the RPC operation

Yield Parameters:

Returns:

Raises:

  • (Google::Gax::GaxError)

    if the RPC is aborted.



1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
# File 'lib/google/cloud/kms/v1/key_management_service_client.rb', line 1307

def update_crypto_key_version \
    crypto_key_version,
    update_mask,
    options: nil,
    &block
  req = {
    crypto_key_version: crypto_key_version,
    update_mask: update_mask
  }.delete_if { |_, v| v.nil? }
  req = Google::Gax::to_proto(req, Google::Cloud::Kms::V1::UpdateCryptoKeyVersionRequest)
  @update_crypto_key_version.call(req, options, &block)
end