Method: Mongo::Crypt::KMS::Credentials#initialize

Defined in:
lib/mongo/crypt/kms/credentials.rb

#initialize(kms_providers) ⇒ Credentials

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.

Note:

There may be more than one KMS provider specified.

Creates a KMS credentials object form a parameters hash.

Parameters:

  • kms_providers (Hash)

    A hash that contains credential for KMS providers. The hash should have KMS provider names as keys, and required parameters for every provider as values. Required parameters for KMS providers are described in corresponding classes inside Mongo::Crypt::KMS module.

Raises:

  • (ArgumentError)

    If required options are missing or incorrectly formatted.



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/mongo/crypt/kms/credentials.rb', line 54

def initialize(kms_providers)
  if kms_providers.nil?
    raise ArgumentError.new("KMS providers options must not be nil")
  end
  if kms_providers.key?(:aws)
    @aws = AWS::Credentials.new(kms_providers[:aws])
  end
  if kms_providers.key?(:azure)
    @azure = Azure::Credentials.new(kms_providers[:azure])
  end
  if kms_providers.key?(:gcp)
    @gcp = GCP::Credentials.new(kms_providers[:gcp])
  end
  if kms_providers.key?(:kmip)
    @kmip = KMIP::Credentials.new(kms_providers[:kmip])
  end
  if kms_providers.key?(:local)
    @local = Local::Credentials.new(kms_providers[:local])
  end
  if @aws.nil? && @azure.nil? && @gcp.nil? && @kmip.nil? && @local.nil?
    raise ArgumentError.new(
      "KMS providers options must have one of the following keys: " +
      ":aws, :azure, :gcp, :kmip, :local"
    )
  end
end