Class: Rails::Secrets
Overview
Greatly inspired by Ara T. Howard’s magnificent sekrets gem. 😘
Defined Under Namespace
Classes: MissingKeyError
Class Attribute Summary collapse
-
.root ⇒ Object
writeonly
Sets the attribute root.
Class Method Summary collapse
- .decrypt(data) ⇒ Object
- .encrypt(data) ⇒ Object
- .key ⇒ Object
- .parse(paths, env:) ⇒ Object
- .read ⇒ Object
- .read_for_editing(&block) ⇒ Object
- .write(contents) ⇒ Object
Class Attribute Details
.root=(value) ⇒ Object (writeonly)
Sets the attribute root
22 23 24 |
# File 'railties/lib/rails/secrets.rb', line 22 def root=(value) @root = value end |
Class Method Details
.decrypt(data) ⇒ Object
42 43 44 |
# File 'railties/lib/rails/secrets.rb', line 42 def decrypt(data) encryptor.decrypt_and_verify(data) end |
.encrypt(data) ⇒ Object
38 39 40 |
# File 'railties/lib/rails/secrets.rb', line 38 def encrypt(data) encryptor.encrypt_and_sign(data) end |
.key ⇒ Object
34 35 36 |
# File 'railties/lib/rails/secrets.rb', line 34 def key ENV["RAILS_MASTER_KEY"] || read_key_file || handle_missing_key end |
.parse(paths, env:) ⇒ Object
24 25 26 27 28 29 30 31 32 |
# File 'railties/lib/rails/secrets.rb', line 24 def parse(paths, env:) paths.each_with_object(Hash.new) do |path, all_secrets| require "erb" secrets = YAML.load(ERB.new(preprocess(path)).result) || {} all_secrets.merge!(secrets["shared"].deep_symbolize_keys) if secrets["shared"] all_secrets.merge!(secrets[env].deep_symbolize_keys) if secrets[env] end end |
.read ⇒ Object
46 47 48 |
# File 'railties/lib/rails/secrets.rb', line 46 def read decrypt(IO.binread(path)) end |
.read_for_editing(&block) ⇒ Object
55 56 57 |
# File 'railties/lib/rails/secrets.rb', line 55 def read_for_editing(&block) writing(read, &block) end |