Class: SecureCredentials::EncryptedFile
- Inherits:
-
ActiveSupport::EncryptedFile
- Object
- ActiveSupport::EncryptedFile
- SecureCredentials::EncryptedFile
- Defined in:
- lib/secure_credentials/encrypted_file.rb
Overview
Wraps ActiveSupport::EncryptedFile and provides passing key as an argument. Automatically generates missing key filenames based on store filename.
Constant Summary
Constants inherited from ActiveSupport::EncryptedFile
ActiveSupport::EncryptedFile::CIPHER
Instance Attribute Summary
Attributes inherited from ActiveSupport::EncryptedFile
#content_path, #env_key, #key_path, #raise_if_missing_key
Class Method Summary collapse
-
.default_key_path_for(filename) ⇒ Object
Same file name but with ‘.key` extension instead of `.enc`.
Instance Method Summary collapse
-
#initialize(path, key = nil, key_path: nil, env_key: nil) ⇒ EncryptedFile
constructor
A new instance of EncryptedFile.
- #key ⇒ Object
Methods inherited from ActiveSupport::EncryptedFile
#change, generate_key, #read, #write
Constructor Details
#initialize(path, key = nil, key_path: nil, env_key: nil) ⇒ EncryptedFile
Returns a new instance of EncryptedFile.
19 20 21 22 23 24 25 26 27 |
# File 'lib/secure_credentials/encrypted_file.rb', line 19 def initialize(path, key = nil, key_path: nil, env_key: nil) @key = key super( content_path: path, key_path: key_path || self.class.default_key_path_for(path), env_key: env_key, raise_if_missing_key: true, ) end |
Class Method Details
.default_key_path_for(filename) ⇒ Object
Same file name but with ‘.key` extension instead of `.enc`.
14 15 16 |
# File 'lib/secure_credentials/encrypted_file.rb', line 14 def default_key_path_for(filename) filename.sub_ext('.key') end |
Instance Method Details
#key ⇒ Object
29 30 31 |
# File 'lib/secure_credentials/encrypted_file.rb', line 29 def key @key || read_env_key || read_key_file || SecureCredentials.master_key || handle_missing_key end |