Class: HatiConfig::Encryption::FileKeyProvider

Inherits:
KeyProvider
  • Object
show all
Defined in:
lib/hati_config/encryption.rb

Overview

FileKeyProvider gets the encryption key from a file.

Instance Method Summary collapse

Methods inherited from KeyProvider

create

Constructor Details

#initialize(options = {}) ⇒ FileKeyProvider

Returns a new instance of FileKeyProvider.

Raises:



204
205
206
207
208
# File 'lib/hati_config/encryption.rb', line 204

def initialize(options = {})
  super()
  @file_path = options[:file_path]
  raise EncryptionError, 'File path not provided' unless @file_path
end

Instance Method Details

#key ⇒ Object



210
211
212
213
214
215
216
# File 'lib/hati_config/encryption.rb', line 210

def key
  raise EncryptionError, "Key file not found: #{@file_path}" unless File.exist?(@file_path)

  File.read(@file_path).strip
rescue SystemCallError => e
  raise EncryptionError, "Failed to read key file: #{e.message}"
end