class Mongo::Crypt::KMS::GCP::MasterKeyDocument
GCP KMS master key document object contains KMS master key parameters.
@api private
Constants
- FORMAT_HINT
Attributes
@return [ String ] GCP location.
@return [ String ] GCP project id.
Public Class Methods
Creates a master key document object form a parameters hash.
@param [ Hash ] opts A hash that contains master key options for
the GCP KMS provider.
@option opts [ String ] :project_id GCP project id. @option opts [ String ] :location GCP location. @option opts [ String ] :key_ring GCP KMS key ring. @option opts [ String ] :key_name GCP KMS key name. @option opts [ String | nil ] :key_version GCP KMS key version, optional. @option opts [ String | nil ] :endpoint GCP KMS key endpoint, optional.
@raise [ ArgumentError ] If required options are missing or incorrectly.
# 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
Public Instance Methods
Convert master key document object to a BSON document in libmongocrypt format.
@return [ BSON::Document ] GCP KMS credentials in libmongocrypt format.
# 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| unless key_version.nil? bson.update({ keyVersion: key_version }) end unless endpoint.nil? bson.update({ endpoint: endpoint }) end end end