class EcsDeployer::Util::Cipher
Constants
- ENCRYPT_VARIABLE_PATTERN
Public Class Methods
new(aws_options = {})
click to toggle source
@param [Hash] aws_options @return [EcsDeployer::Util::Cipher]
# File lib/ecs_deployer/util/cipher.rb, line 10 def initialize(aws_options = {}) @kms = Aws::KMS::Client.new(aws_options) end
Public Instance Methods
decrypt(value)
click to toggle source
@param [String] value @return [String]
# File lib/ecs_deployer/util/cipher.rb, line 26 def decrypt(value) match = value.match(ENCRYPT_VARIABLE_PATTERN) raise KmsDecryptError, 'Encrypted string is invalid.' unless match begin @kms.decrypt(ciphertext_blob: Base64.strict_decode64(match[1])).plaintext rescue => e raise KmsDecryptError, e.to_s end end
encrypt(master_key, value)
click to toggle source
@param [String] mater_key @param [String] value @return [String]
# File lib/ecs_deployer/util/cipher.rb, line 17 def encrypt(master_key, value) encode = @kms.encrypt(key_id: "alias/#{master_key}", plaintext: value) "${#{Base64.strict_encode64(encode.ciphertext_blob)}}" rescue => e raise KmsEncryptError, e.to_s end
encrypt_value?(value)
click to toggle source
@param [String] value @return [Bool]
# File lib/ecs_deployer/util/cipher.rb, line 39 def encrypt_value?(value) value.to_s.match(ENCRYPT_VARIABLE_PATTERN) ? true : false end