123456789_123456789_123456789_123456789_123456789_

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

Relationships & Source Files
Super Chains via Extension / Inclusion / Inheritance
Instance Chain:
Inherits: Object
Defined in: lib/mongo/crypt/kms/gcp/master_document.rb

Overview

::Mongo::Crypt::KMS::GCP KMS master key document object contains ::Mongo::Crypt::KMS master key parameters.

Constant Summary

Class Method Summary

Instance Attribute Summary

Instance Method Summary

::Mongo::Crypt::KMS::Validations - Included

#validate_param

Validate if a ::Mongo::Crypt::KMS parameter is valid.

#validate_tls_options

Validate KMS TLS options.

Constructor Details

.new(opts) ⇒ MasterKeyDocument

Creates a master key document object form a parameters hash.

Parameters:

Options Hash (opts):

Raises:

  • (ArgumentError)

    If required options are missing or incorrectly.

[ GitHub ]

  
# File 'lib/mongo/crypt/kms/gcp/master_document.rb', line 61

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)

Returns:

[ GitHub ]

  
# File 'lib/mongo/crypt/kms/gcp/master_document.rb', line 43

attr_reader :endpoint

#key_nameString (readonly)

Returns:

[ GitHub ]

  
# File 'lib/mongo/crypt/kms/gcp/master_document.rb', line 37

attr_reader :key_name

#key_ringString (readonly)

Returns:

[ GitHub ]

  
# File 'lib/mongo/crypt/kms/gcp/master_document.rb', line 34

attr_reader :key_ring

#key_versionString | nil (readonly)

Returns:

[ GitHub ]

  
# File 'lib/mongo/crypt/kms/gcp/master_document.rb', line 40

attr_reader :key_version

#locationString (readonly)

Returns:

[ GitHub ]

  
# File 'lib/mongo/crypt/kms/gcp/master_document.rb', line 31

attr_reader :location

#project_idString (readonly)

Returns:

[ GitHub ]

  
# File 'lib/mongo/crypt/kms/gcp/master_document.rb', line 28

attr_reader :project_id

Instance Method Details

#to_documentBSON::Document

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

Returns:

[ GitHub ]

  
# File 'lib/mongo/crypt/kms/gcp/master_document.rb', line 77

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|
    bson.update({ keyVersion: key_version }) unless key_version.nil?
    bson.update({ endpoint: endpoint }) unless endpoint.nil?
  end
end