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 |
# 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) 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
77 78 79 80 81 82 83 84 85 |
# File 'lib/leml/core.rb', line 77 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
72 73 74 75 |
# File 'lib/leml/core.rb', line 72 def merge_secrets return unless @key.present? && File.exists?(SECRETS) Rails.application.secrets.merge!(decrypt(@secrets)[Rails.env].deep_symbolize_keys) if @secrets end |
#show ⇒ Object
87 88 89 90 |
# File 'lib/leml/core.rb', line 87 def show return unless @secrets print(decrypt(@secrets).to_yaml) end |