Class: Leml::Core
- Inherits:
-
Object
- Object
- Leml::Core
- Defined in:
- lib/leml/core.rb
Constant Summary collapse
- KEY_FILE =
Rails.root.join('config', 'leml.key')
- SECRETS =
Rails.root.join('config', 'leml.yml')
Class Method Summary collapse
Instance Method Summary collapse
- #edit ⇒ Object
-
#initialize ⇒ Core
constructor
A new instance of Core.
- #merge_secrets ⇒ Object
- #show ⇒ Object
Constructor Details
#initialize ⇒ Core
Returns a new instance of Core.
65 66 67 68 69 70 71 |
# File 'lib/leml/core.rb', line 65 def initialize @key = File.exist?(KEY_FILE) ? File.read(KEY_FILE).chop : ENV['LEML_KEY'] raise NoLemlKeyError if @key.blank? @encryptor = ActiveSupport::MessageEncryptor.new(@key, cipher: 'aes-256-cbc') @secrets = YAML.load_file(SECRETS) @previous_key_hash = {} end |
Class Method Details
.setup ⇒ Object
10 11 12 13 14 |
# File 'lib/leml/core.rb', line 10 def setup key_initialize yaml_initialize end |
Instance Method Details
#edit ⇒ Object
78 79 80 81 82 83 84 85 86 |
# File 'lib/leml/core.rb', line 78 def edit raise NoEditorError if ENV['EDITOR'].blank? Dir.mktmpdir do |dir| tmp_file = create_decrypted_tmp_file(dir) system("#{ENV['EDITOR']} #{tmp_file.to_s}") reload_secrets_file(tmp_file) puts 'OK, your secrets is encrypted.' end end |
#merge_secrets ⇒ Object
73 74 75 76 |
# File 'lib/leml/core.rb', line 73 def merge_secrets return unless @key.present? && File.exist?(SECRETS) Rails.application.secrets.merge!(decrypt(@secrets)[Rails.env].deep_symbolize_keys) if @secrets end |
#show ⇒ Object
88 89 90 91 |
# File 'lib/leml/core.rb', line 88 def show return unless @secrets print(decrypt(@secrets).to_yaml) end |