Class: Moonshot::Plugins::EncryptedParameters::ParameterEncrypter

Inherits:
Object
  • Object
show all
Defined in:
lib/plugins/encrypted_parameters/parameter_encrypter.rb

Overview

Class that can encrypt and decrypt parameters using KMS.

Instance Method Summary collapse

Constructor Details

#initialize(key_arn) ⇒ ParameterEncrypter

Returns a new instance of ParameterEncrypter.

Parameters:

  • key_arn (String)

    The ARN for the KMS key.



10
11
12
13
# File 'lib/plugins/encrypted_parameters/parameter_encrypter.rb', line 10

def initialize(key_arn)
  @kms_client = Aws::KMS::Client.new
  @key_arn = key_arn
end

Instance Method Details

#encrypt(param_value) ⇒ String

Encrypt and base64 encode the parameter value.

Parameters:

  • param_value (String)

    The parameter to encrypt.

Returns:

  • (String)

    base64 encoded encrypted ciphertext.



19
20
21
22
23
24
# File 'lib/plugins/encrypted_parameters/parameter_encrypter.rb', line 19

def encrypt(param_value)
  resp = @kms_client.encrypt(key_id: @key_arn, plaintext: param_value)

  # Use strict here to avoid newlines which cause issues with parameters.
  Base64.strict_encode64(resp.ciphertext_blob)
end