Backport Rails 6 per-environment credentials to Rails 5.2
September 17, 2019 ยท View on GitHub
Rails PR: https://github.com/rails/rails/pull/33521
This patch makes it possible to use per-environment credentials (i.e., config/credentials/staging.yml.enc) in Rails 5.2.
Installation
- Drop
backport_rails_six_credentials.rbandbackport_rails_six_credentials_command.rbsomewhere, for example, into thelib/folder - Add this line to
config/application.rb:
# Right after `require "rails"`
require_relative "../lib/backport_rails_six_credentials"
- Add this line to
config/boot.rb:
# Right after `require 'bundler/setup'`
require_relative "../lib/backport_rails_six_credentials_command"
Usage
Now you can call:
$ bundle exec rails credentials:edit -e staging
create config/credentials/staging.key
...
And Rails.application.credentials now uses env-specific credentials if they're present and master/root credentials otherwise.