ahoward / sekrets

sekrets is a command line tool and library used to securely manage encrypted files and settings in your rails' applications and git repositories.
BSD 2-Clause "Simplified" License
268 stars 28 forks source link

Please add Sekrets.key_provided? #11

Closed kwerle closed 6 months ago

kwerle commented 7 years ago

I would like to be able to load secrets if the key was provided or do nothing if not. To this end, I would like to

def load_sekrets
  <do stuff with Sekrets.settings_for>
end

load_sekrets if Sekrets.key_provided?

Where Sekrets.key_provided? will return true if it is able to find the key in one of the usual places without resorting to Sekrets.ask.

I'm happy to PR this if you think this is a worthwhile feature.

Specific background: My rails 4.2 sekrets.rb initializer looks like:

def merge_sekrets(sekrets)
  secrets = sekrets['shared'] || {}
  secrets.merge!(sekrets[Rails.env] || {})
  Rails.application.secrets.merge!(secrets).symbolize_keys!
end

settings = Sekrets.settings_for('./config/sekrets.yml.enc')
merge_sekrets(settings)

I don't really want to have to provide the secret key to make the dev/test environments work. But I probably do for staging, production.

ahoward commented 6 months ago

you may use, instead:


key = Sekrets.key_for('./config/sekrets.yml.enc', prompt: false)

if key
  settings = Sekrets.settings_for('./config/sekrets.yml.enc', key: key)
  merge_sekrets(settings)
end