Module: EasyCreds::Overlay
- Defined in:
- lib/easy_creds/overlay.rb
Class Method Summary collapse
-
.apply!(creds, root, env) ⇒ void
Merge config/credentials/<env>_local.yml.enc on top of the base credentials.
Class Method Details
.apply!(creds, root, env) ⇒ void
This method returns an undefined value.
Merge config/credentials/<env>_local.yml.enc on top of the base credentials.
Call it from a Rails initializer with the credentials object, project root, and environment — the values are pulled straight off the Rails globals:
EasyCreds::Overlay.apply!(Rails.application.credentials, Rails.root, Rails.env)
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/easy_creds/overlay.rb', line 22 def self.apply!(creds, root, env) env = env.to_s enc = Pathname.new(root).join("config/credentials/#{env}_local.yml.enc") key = Pathname.new(root).join("config/credentials/#{env}_local.key") return unless enc.exist? && key.exist? = ActiveSupport::EncryptedConfiguration.new( config_path: enc.to_s, key_path: key.to_s, env_key: 'RAILS_MASTER_KEY_LOCAL_UNUSED', raise_if_missing_key: false ).config.deep_symbolize_keys .each do |top_key, value| merge_key(creds, top_key, value) end rescue StandardError => e warn "[easy_creds_overlay] skipped: #{e.class}: #{e.}" end |