Class: EncryptEnv
- Inherits:
-
Object
- Object
- EncryptEnv
- Defined in:
- lib/encrypt_env.rb
Overview
gem ‘encrypt_env’
Class Method Summary collapse
- .edit ⇒ Object
- .secrets ⇒ Object
- .secrets_all ⇒ Object
- .secrets_development ⇒ Object
- .secrets_production ⇒ Object
- .secrets_staging ⇒ Object
- .secrets_test ⇒ Object
- .setup ⇒ Object
- .show ⇒ Object
- .show_all ⇒ Object
Class Method Details
.edit ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/encrypt_env.rb', line 65 def self.edit path_root unless @path_root secrets unless @decrypted Tempfile.create do |f| f.write(decrypt) f.flush f.rewind system("vim #{f.path}") encrypt(File.read(f.path)) @decrypted = nil end end |
.secrets ⇒ Object
84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/encrypt_env.rb', line 84 def self.secrets return @decrypted if @decrypted path_root unless @path_root @decrypted = HashWithIndifferentAccess.new(YAML.safe_load( decrypt, aliases: true )) unless defined?(Rails) env = `rails r "print Rails.env"`.to_sym return @decrypted[env] || @decrypted[:default] || @decrypted end @decrypted[Rails.env.to_sym] || @decrypted[:default] || @decrypted end |
.secrets_all ⇒ Object
78 79 80 81 82 |
# File 'lib/encrypt_env.rb', line 78 def self.secrets_all path_root unless @path_root secrets unless @decrypted @decrypted end |
.secrets_development ⇒ Object
103 104 105 106 |
# File 'lib/encrypt_env.rb', line 103 def self.secrets_development secrets unless @decrypted @decrypted[:development] end |
.secrets_production ⇒ Object
98 99 100 101 |
# File 'lib/encrypt_env.rb', line 98 def self.secrets_production secrets unless @decrypted @decrypted[:production] end |
.secrets_staging ⇒ Object
113 114 115 116 |
# File 'lib/encrypt_env.rb', line 113 def self.secrets_staging secrets unless @decrypted @decrypted[:staging] end |
.secrets_test ⇒ Object
108 109 110 111 |
# File 'lib/encrypt_env.rb', line 108 def self.secrets_test secrets unless @decrypted @decrypted[:test] end |
.setup ⇒ Object
56 57 58 59 60 61 62 63 |
# File 'lib/encrypt_env.rb', line 56 def self.setup path_root @secret_file = File.("#{@path_root}/config/secrets.yml") key = OpenSSL::Random.random_bytes(16) # save key in master.key file File.open("#{@path_root}/config/master.key", 'w') { |file| file.write(key.unpack1('H*')) } encrypt(File.read(@secret_file)) end |
.show ⇒ Object
118 119 120 |
# File 'lib/encrypt_env.rb', line 118 def self.show puts secrets.inspect end |
.show_all ⇒ Object
122 123 124 |
# File 'lib/encrypt_env.rb', line 122 def self.show_all puts secrets_all.inspect end |