class Hiera::Backend::Eyaml::Encryptors::Kms

Constants

VERSION

Public Class Methods

decrypt(ciphertext) click to toggle source
# File lib/hiera/backend/eyaml/encryptors/kms.rb, line 48
def self.decrypt ciphertext
  aws_profile = self.option :aws_profile
  aws_region = self.option :aws_region

  @kms = ::Aws::KMS::Client.new(
    profile: aws_profile,
    region: aws_region,
  )

  resp = @kms.decrypt({
    ciphertext_blob: ciphertext
  })

  resp.plaintext
end
encrypt(plaintext) click to toggle source
# File lib/hiera/backend/eyaml/encryptors/kms.rb, line 29
def self.encrypt plaintext
  aws_profile = self.option :aws_profile
  aws_region = self.option :aws_region
  key_id = self.option :key_id
  raise StandardError, "key_id is not defined" unless key_id

  @kms = ::Aws::KMS::Client.new(
    profile: aws_profile,
    region: aws_region,
  )

  resp = @kms.encrypt({
    key_id: key_id,
    plaintext: plaintext
  })

  resp.ciphertext_blob
end