Class: Mongo::Crypt::DataKeyContext Private

Inherits:
Context
  • Object
show all
Defined in:
build/ruby-driver-master/lib/mongo/crypt/data_key_context.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.

A Context object initialized specifically for the purpose of creating a data key in the key managemenet system.

Instance Attribute Summary

Attributes inherited from Context

#ctx_p

Instance Method Summary collapse

Methods inherited from Context

#run_state_machine, #state

Constructor Details

#initialize(mongocrypt, io, kms_provider, options = {}) ⇒ DataKeyContext

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.

Create a new DataKeyContext object

Parameters:

  • mongocrypt (Mongo::Crypt::Handle)

    a Handle that wraps a mongocrypt_t object used to create a new mongocrypt_ctx_t

  • io (Mongo::Crypt::EncryptionIO)

    An object that performs all driver I/O on behalf of libmongocrypt

  • kms_provider (String)

    The KMS provider to use. Options are “aws” and “local”.

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

    Data key creation options.

Options Hash (options):

  • :master_key (Hash)

    A Hash of options related to the AWS KMS provider option. Required if kms_provider is “aws”.

    • :region [ String ] The The AWS region of the master key (required).

    • :key [ String ] The Amazon Resource Name (ARN) of the master key (required).

    • :endpoint [ String ] An alternate host to send KMS requests to (optional).

  • :key_alt_names (Array<String>)

    An optional array of strings specifying alternate names for the new data key.



44
45
46
47
48
49
50
51
52
53
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
# File 'build/ruby-driver-master/lib/mongo/crypt/data_key_context.rb', line 44

def initialize(mongocrypt, io, kms_provider, options={})
  super(mongocrypt, io)

  case kms_provider
  when 'local'
    Binding.ctx_setopt_master_key_local(self)
  when 'aws'
    unless options
      raise ArgumentError.new(
        'When "aws" is specified as the KMS provider, options cannot be nil'
      )
    end

    unless options.key?(:master_key)
      raise ArgumentError.new(
        'When "aws" is specified as the KMS provider, the options Hash ' +
        'must contain a key named :master_key with a Hash value in the ' +
        '{ region: "AWS-REGION", key: "AWS-KEY-ARN" }'
      )
    end

    master_key_opts = options[:master_key]

    set_aws_master_key(master_key_opts)
    set_aws_endpoint(master_key_opts[:endpoint]) if master_key_opts[:endpoint]
  else
    raise ArgumentError.new(
      "#{kms_provider} is an invalid kms provider. " +
      "Valid options are 'aws' and 'local'"
    )
  end

  set_key_alt_names(options[:key_alt_names]) if options[:key_alt_names]
  initialize_ctx
end