Module: EncryptedEnv
- Defined in:
- lib/encrypted_env.rb,
lib/encrypted_env/cli.rb,
lib/encrypted_env/env.rb,
lib/encrypted_env/version.rb
Defined Under Namespace
Constant Summary collapse
- VERSION =
"0.0.1"
Class Method Summary collapse
-
.decrypt(key, options = {}) ⇒ Object
Decrypt a value already stored in the ENV.
-
.default_options ⇒ Object
The default options used when called encrypt and decrypt.
-
.default_options=(options = {}) ⇒ Object
Sets some default options that are globally used.
-
.encrypt(value, options = {}) ⇒ Object
Encrypts a value and base64 encodes it into the ENV.
-
.env ⇒ Object
Returns a hash like structure that should be the ENV.
-
.env=(env) ⇒ Object
Allows the setting of the environment to something other then ::ENV.
Class Method Details
.decrypt(key, options = {}) ⇒ Object
Decrypt a value already stored in the ENV. The value is assumed be Base64 encoded
35 36 37 38 39 |
# File 'lib/encrypted_env.rb', line 35 def self.decrypt(key,={}) decoded_value = Base64.decode64 env[key] Encryptor.decrypt(self..merge().merge(:value => decoded_value)) end |
.default_options ⇒ Object
The default options used when called encrypt and decrypt
Defaults to Encryptor.default_options, or { :algorithm => ‘aes-256-cbc’ }
13 14 15 |
# File 'lib/encrypted_env.rb', line 13 def self. @default_options || ::Encryptor. end |
.default_options=(options = {}) ⇒ Object
Sets some default options that are globally used
Valid keys are
:key -> The encryption key
:algorithm -> run 'openssl list-cipher-commands' to see what can be used
22 23 24 |
# File 'lib/encrypted_env.rb', line 22 def self.(={}) @default_options = .merge() end |
.encrypt(value, options = {}) ⇒ Object
Encrypts a value and base64 encodes it into the ENV
28 29 30 31 32 |
# File 'lib/encrypted_env.rb', line 28 def self.encrypt(value,={}) encrypted_value = Encryptor.encrypt(self..merge().merge(:value => value.to_s)) Base64.strict_encode64 encrypted_value.to_s end |
.env ⇒ Object
Returns a hash like structure that should be the ENV. It defaults to ::ENV
42 43 44 |
# File 'lib/encrypted_env.rb', line 42 def self.env @env || ::ENV end |
.env=(env) ⇒ Object
Allows the setting of the environment to something other then ::ENV. Good for testing or if you are serializing to something. The items passed should behave like a Hash
48 49 50 |
# File 'lib/encrypted_env.rb', line 48 def self.env=(env) @env = env end |