Class: EasyCrypt::SecretsProvider::EnvProvider

Inherits:
Base
  • Object
show all
Defined in:
lib/easy_crypt/secrets_provider/env_provider.rb

Overview

Provider that fetches encryption configuration from environment variables

Multiple credential purposes can be configured using environment variables. Each credential purpose requires three environment variables following this pattern:

EASY_CRYPT__CIPHER - (optional) Cipher to use for the encryption

falls back to EasyCrypt.default_cipher is not set

EASY_CRYPT__SALT - Salt value for the encryption EASY_CRYPT__SECRET - Secret key for the encryption

Where [PURPOSE] is the uppercase version of the credential purpose

You can set these variables in your .env file:

echo "EASY_CRYPT_AUTHENTICATION_CIPHER=aes128" >> .env
echo "EASY_CRYPT_AUTHENTICATION_SALT=your-salt" >> .env
echo "EASY_CRYPT_AUTHENTICATION_SECRET=your-secret" >> .env

Or export them directly in your environment:

export EASY_CRYPT_AUTHENTICATION_CIPHER=aes128
export EASY_CRYPT_AUTHENTICATION_SALT=your-salt
export EASY_CRYPT_AUTHENTICATION_SECRET=your-secret

Examples:

Using authentication credentials

# In .env file or environment:
EASY_CRYPT_AUTHENTICATION_CIPHER=aes128
EASY_CRYPT_AUTHENTICATION_SALT=your-salt-value
EASY_CRYPT_AUTHENTICATION_SECRET=your-secret-key

provider = EnvProvider.new(:authentication)
provider.cipher  #=> "aes128"
provider.salt    #=> "your-salt-value"
provider.secret  #=> "your-secret-key"

Using user_data credentials

# In .env file or environment:
EASY_CRYPT_USER_DATA_SALT=different-salt
EASY_CRYPT_USER_DATA_SECRET=different-secret

provider = EnvProvider.new(:user_data)
provider.cipher  #=> nil
provider.salt    #=> "different-salt"
provider.secret  #=> "different-secret"

Instance Attribute Summary

Attributes inherited from Base

#purpose

Instance Method Summary collapse

Methods inherited from Base

#initialize, #validate_attributes!

Constructor Details

This class inherits a constructor from EasyCrypt::SecretsProvider::Base

Instance Method Details

#cipherString?

Returns The encryption cipher from environment variable.

Returns:

  • (String, nil)

    The encryption cipher from environment variable



49
50
51
# File 'lib/easy_crypt/secrets_provider/env_provider.rb', line 49

def cipher
  credentials('CIPHER')
end

#saltString?

Returns The salt value from environment variable.

Returns:

  • (String, nil)

    The salt value from environment variable



54
55
56
# File 'lib/easy_crypt/secrets_provider/env_provider.rb', line 54

def salt
  credentials('SALT')
end

#secretString?

Returns The secret key from environment variable.

Returns:

  • (String, nil)

    The secret key from environment variable



59
60
61
# File 'lib/easy_crypt/secrets_provider/env_provider.rb', line 59

def secret
  credentials('SECRET')
end