class Hiera::Backend::Eyaml::Encryptors::GcpKms

Constants

Cloudkms
VERSION

Public Class Methods

decrypt(ciphertext) click to toggle source
# File lib/hiera/backend/eyaml/encryptors/gcpkms.rb, line 48
def self.decrypt(ciphertext)
  self.init()
  decrypt_request = Cloudkms::DecryptRequest.new(:ciphertext => Base64.decode64(ciphertext))
  response = @kms_client.decrypt_crypto_key(@key_id, decrypt_request)
  return response.plaintext
end
encrypt(plaintext) click to toggle source
# File lib/hiera/backend/eyaml/encryptors/gcpkms.rb, line 40
def self.encrypt(plaintext)
  self.init()
  encrypt_request = Cloudkms::EncryptRequest.new(:plaintext => plaintext)
  response = @kms_client.encrypt_crypto_key(@key_id, encrypt_request)
  return Base64.encode64(response.ciphertext.chomp)
end
init() click to toggle source
# File lib/hiera/backend/eyaml/encryptors/gcpkms.rb, line 28
def self.init
  # Instantiate the client
  @kms_client = Cloudkms::CloudKMSService.new

  # Set the required scopes to access the Key Management Service API
  # @see https://developers.google.com/identity/protocols/application-default-credentials#callingruby
  @kms_client.authorization = Google::Auth.get_application_default(
    "https://www.googleapis.com/auth/cloud-platform"
  )
  @key_id = self.option :key_id
end