Class: Mongo::Crypt::KMS::GCP::MasterKeyDocument Private

Inherits:
Object
  • Object
show all
Includes:
Validations
Defined in:
build/ruby-driver-v2.18/lib/mongo/crypt/kms/gcp.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

GCP KMS master key document object contains KMS master key parameters.

Constant Summary collapse

FORMAT_HINT =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

"GCP key document  must be in the format: " +
"{ project_id: 'PROJECT_ID', location: 'LOCATION', " +
"key_ring: 'KEY-RING', key_name: 'KEY-NAME' }"

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Validations

#validate_param, validate_tls_options

Constructor Details

#initialize(opts) ⇒ MasterKeyDocument

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Creates a master key document object form a parameters hash.

Parameters:

  • opts (Hash)

    A hash that contains master key options for the GCP KMS provider.

Options Hash (opts):

  • :project_id (String)

    GCP project id.

  • :location (String)

    GCP location.

  • :key_ring (String)

    GCP KMS key ring.

  • :key_name (String)

    GCP KMS key name.

  • :key_version (String | nil)

    GCP KMS key version, optional.

  • :endpoint (String | nil)

    GCP KMS key endpoint, optional.

Raises:

  • (ArgumentError)

    If required options are missing or incorrectly.



152
153
154
155
156
157
158
159
160
161
162
163
# File 'build/ruby-driver-v2.18/lib/mongo/crypt/kms/gcp.rb', line 152

def initialize(opts)
  if opts.empty?
    @empty = true
    return
  end
  @project_id = validate_param(:project_id, opts, FORMAT_HINT)
  @location = validate_param(:location, opts, FORMAT_HINT)
  @key_ring = validate_param(:key_ring, opts, FORMAT_HINT)
  @key_name = validate_param(:key_name, opts, FORMAT_HINT)
  @key_version = validate_param(:key_version, opts, FORMAT_HINT, required: false)
  @endpoint = validate_param(:endpoint, opts, FORMAT_HINT, required: false)
end

Instance Attribute Details

#endpointString | nil (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns GCP KMS endpoint.

Returns:

  • (String | nil)

    GCP KMS endpoint.



134
135
136
# File 'build/ruby-driver-v2.18/lib/mongo/crypt/kms/gcp.rb', line 134

def endpoint
  @endpoint
end

#key_nameString (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns GCP KMS key name.

Returns:

  • (String)

    GCP KMS key name.



128
129
130
# File 'build/ruby-driver-v2.18/lib/mongo/crypt/kms/gcp.rb', line 128

def key_name
  @key_name
end

#key_ringString (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns GCP KMS key ring.

Returns:

  • (String)

    GCP KMS key ring.



125
126
127
# File 'build/ruby-driver-v2.18/lib/mongo/crypt/kms/gcp.rb', line 125

def key_ring
  @key_ring
end

#key_versionString | nil (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns GCP KMS key version.

Returns:

  • (String | nil)

    GCP KMS key version.



131
132
133
# File 'build/ruby-driver-v2.18/lib/mongo/crypt/kms/gcp.rb', line 131

def key_version
  @key_version
end

#locationString (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns GCP location.

Returns:

  • (String)

    GCP location.



122
123
124
# File 'build/ruby-driver-v2.18/lib/mongo/crypt/kms/gcp.rb', line 122

def location
  @location
end

#project_idString (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns GCP project id.

Returns:

  • (String)

    GCP project id.



119
120
121
# File 'build/ruby-driver-v2.18/lib/mongo/crypt/kms/gcp.rb', line 119

def project_id
  @project_id
end

Instance Method Details

#to_documentBSON::Document

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Convert master key document object to a BSON document in libmongocrypt format.

Returns:

  • (BSON::Document)

    GCP KMS credentials in libmongocrypt format.



168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
# File 'build/ruby-driver-v2.18/lib/mongo/crypt/kms/gcp.rb', line 168

def to_document
  return BSON::Document.new({}) if @empty
  BSON::Document.new({
    provider: 'gcp',
    projectId: project_id,
    location: location,
    keyRing: key_ring,
    keyName: key_name
  }).tap do |bson|
    unless key_version.nil?
      bson.update({ keyVersion: key_version })
    end
    unless endpoint.nil?
      bson.update({ endpoint: endpoint })
    end
  end
end