Secretive is a way to configure your application's ENV variables using a .yml file.
It includes Rails integration, including a generator and a task for sharing secrets with Heroku.
Add this line to your application's Gemfile:
gem 'secretive'
And then execute:
$ bundle
Or install it yourself as:
$ gem install secretive
Simply run rails g secrets
to create and automatically .gitignore the required .yml files.
When starting your Rails application, top-level variables and any variables in a group with the same name as your Rails environment will become ENV variables.
For example, take following YAML file:
TOP_SECRET: "This will self-destruct."
development:
SUPER_SECRET: "Jeremiah was a bullfrog."`
production:
SUPER_SECRET: "He was a good friend of mine."
In development:
$ rails console -e development
> ENV["SUPER_SECRET"]
=> "Jeremiah was a bullfrog."
> ENV["TOP_SECRET"]
=> "This will self-destruct."
In production:
$ rails console -e production
> ENV["SUPER_SECRET"]
=> "He was a good friend of mine."
> ENV["TOP_SECRET"]
=> "This will self-destruct."
If not using Rails, create a config/secrets.yml
file (or whatever you want to call it) and call Secretive.environmentalize!
somewhere in your application.
You can choose which file to use as your secrets file by setting Secretive.file = "../path/to/myfile"
before calling Secretive.environmentalize!
.
You can also pass Secretive.environmentalize!
a scope. Top-level variables will always be loaded.
For example, take following YAML file:
TOP_SECRET: "This will self-destruct."
superheroes:
BEST_HERO: "Harvey Birdman"`
supervillains:
BEST_VILLAIN: "Mentok, Mind-Taker"
After calling Secretive.environmentalize!("superheroes")
:
$ irb
> ENV["BEST_HERO"]
=> "Harvey Birdman"
> ENV["TOP_SECRET"]
=> "This will self-destruct."
> ENV["BEST_VILLAIN"]
=> nil
Secretive comes with a rake task for sharing secrets with Heroku.
Run rake secretive:share_with[yourapp]
to convert all values in the production
scope of your .yml file into ENV variables in the Heroku app.
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Added some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request