Class: HatiConfig::Encryption::AwsKmsKeyProvider
- Inherits:
-
KeyProvider
- Object
- KeyProvider
- HatiConfig::Encryption::AwsKmsKeyProvider
- Defined in:
- lib/hati_config/encryption.rb
Overview
AwsKmsKeyProvider gets the encryption key from AWS KMS.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ AwsKmsKeyProvider
constructor
A new instance of AwsKmsKeyProvider.
- #key ⇒ Object
Methods inherited from KeyProvider
Constructor Details
#initialize(options = {}) ⇒ AwsKmsKeyProvider
Returns a new instance of AwsKmsKeyProvider.
221 222 223 224 225 226 227 228 |
# File 'lib/hati_config/encryption.rb', line 221 def initialize( = {}) super() require 'aws-sdk-kms' @key_id = [:key_id] @region = [:region] @client = nil raise EncryptionError, 'KMS key ID not provided' unless @key_id end |
Instance Method Details
#key ⇒ Object
230 231 232 233 234 235 236 237 238 239 240 241 |
# File 'lib/hati_config/encryption.rb', line 230 def key @key ||= begin client = Aws::KMS::Client.new(region: @region) response = client.generate_data_key( key_id: @key_id, key_spec: 'AES_256' ) response.plaintext rescue Aws::KMS::Errors::ServiceError => e raise EncryptionError, "Failed to get key from KMS: #{e.}" end end |