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

Modules: ENV Classes: Cli

Constant Summary collapse

VERSION =
"0.0.1"

Class Method Summary collapse

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,options={})
  decoded_value = Base64.decode64 env[key]

  Encryptor.decrypt(self.default_options.merge(options).merge(:value => decoded_value))
end

.default_optionsObject

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
  @default_options || ::Encryptor.default_options
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=(options={})
  @default_options = default_options.merge(options)
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,options={})
  encrypted_value = Encryptor.encrypt(self.default_options.merge(options).merge(:value => value.to_s))

  Base64.strict_encode64 encrypted_value.to_s
end

.envObject

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