Class: EasyCrypt::SecretsProvider::Base Abstract
- Inherits:
-
Object
- Object
- EasyCrypt::SecretsProvider::Base
- Defined in:
- lib/easy_crypt/secrets_provider/base.rb
Overview
Base class for all secret providers. Implements the interface that concrete providers must follow.
This abstract base class defines the structure for secrets providers, including required methods for retrieving encryption configuration values such as ‘salt`, `secret`, and `cipher`. Subclasses are expected to implement these methods based on their respective sources (e.g., environment variables, Rails credentials).
Direct Known Subclasses
Instance Attribute Summary collapse
-
#purpose ⇒ Symbol
readonly
The purpose of the credential being accessed.
Instance Method Summary collapse
-
#cipher ⇒ String?
abstract
Returns the encryption cipher.
-
#initialize(purpose) ⇒ Base
constructor
Initialize a new secrets provider.
-
#salt ⇒ String
abstract
Returns the salt value for key generation.
-
#secret ⇒ String
abstract
Returns the secret key for encryption.
-
#validate_attributes! ⇒ Object
Validates the presence of required attributes for the secrets provider.
Constructor Details
#initialize(purpose) ⇒ Base
Initialize a new secrets provider
22 23 24 |
# File 'lib/easy_crypt/secrets_provider/base.rb', line 22 def initialize(purpose) @purpose = purpose end |
Instance Attribute Details
#purpose ⇒ Symbol (readonly)
Returns The purpose of the credential being accessed.
17 18 19 |
# File 'lib/easy_crypt/secrets_provider/base.rb', line 17 def purpose @purpose end |
Instance Method Details
#cipher ⇒ String?
Returns the encryption cipher.
42 43 44 |
# File 'lib/easy_crypt/secrets_provider/base.rb', line 42 def cipher raise NotImplementedError, 'Subclasses must implement #cipher' end |
#salt ⇒ String
Returns the salt value for key generation
51 52 53 |
# File 'lib/easy_crypt/secrets_provider/base.rb', line 51 def salt raise NotImplementedError, 'Subclasses must implement #salt' end |
#secret ⇒ String
Returns the secret key for encryption
60 61 62 |
# File 'lib/easy_crypt/secrets_provider/base.rb', line 60 def secret raise NotImplementedError, 'Subclasses must implement #secret' end |
#validate_attributes! ⇒ Object
Validates the presence of required attributes for the secrets provider.
Checks if the attributes ‘salt`, and `secret` are defined. Raises a `MissingSecretsConfigurationError` error if any of these attributes are missing.
32 33 34 35 |
# File 'lib/easy_crypt/secrets_provider/base.rb', line 32 def validate_attributes! missing_attributes = %w[salt secret].reject { |attr| send(attr) } raise MissingSecretsConfigurationError.new(purpose, missing_attributes) if missing_attributes.any? end |