sec_config
it's a tool which should help you to maintain various key-value based data for your rails project:
- often we use some kind of external APIs which require keys or tokens
- we don't want to save such data directly in the repo, however we would like to use it
- we would like to have different key values for different environments
this flow is used in netguru and we're happy to recommend it to everybody!
installation
add this line to your application's gemfile:
gem 'sec_config'
and then execute:
$ bundle
or install it yourself as:
$ gem install sec_config
usage
generate the structure and you're ready to go.
sc install
ok, what now? you have your config.yml
file which is stored in repo.
# config/config.yml
defaults: &defaults
not_important_key: "abcdef"
important_key: "123456"
development:
<<: *defaults
not_important_key: "fedcba"
production:
<<: *defaults
you have also a sec_config.yml.sample
file which you should rename on the target environment to sec_config.yml
and put the data you want overvrite the defaults with.
# config/sec_config.yml
production:
important_key: "abc123"
usage within your app
# on development
AppConfig.not_important_key
# => fedcba
AppConfig.important_key
# => 123456
# on production
AppConfig.not_important_key
# => abcdef
AppConfig.important_key
# => abc123
tips
- don't forget that
sec_config.yml
has to be edited directly on the environment which you want to be overwriting the data (staging
,production
, etc.) *_secret
,*_token
,*_password
variables seem to be a good example of keys which should not be stored in the repo
contributing
- fork it
- create your feature branch (
git checkout -b my-new-feature
) - commit your changes (
git commit -am 'add some feature'
) - push to the branch (
git push origin my-new-feature
) - create new pull request