Ruby on Rails - storing authentication keys with figaro in ruby on rails- ruby on rails tutorial - rails guides - rails tutorial - ruby rails
- Add gem 'figaro' to our Gemfile and run bundle install. Then run bundle exec figaro install; this will create config/application.yml and add it to our .gitignore file, preventing it from being added to version control.
We can store your keys in application.yml in this format:
SECRET_NAME: secret_value
Clicking "Copy Code" button will copy the code into the clipboard - memory. Please paste(Ctrl+V) it in your destination. The code will get pasted. Happy coding from Wikitechy - ruby on rails tutorial - rails guides - ruby rails - rubyonrails - learn ruby on rails - team
- where SECRET_NAME and secret_value are the name and value of our API key.
- We also need to name these secrets in config/secrets.yml.
- We can have different secrets in each environment.
File look like:
development:
secret_name: <%= ENV["SECRET_NAME"] %>
test:
secret_name: <%= ENV["SECRET_NAME"] %>
production:
secret_name: <%= ENV["SECRET_NAME"] %>
Clicking "Copy Code" button will copy the code into the clipboard - memory. Please paste(Ctrl+V) it in your destination. The code will get pasted. Happy coding from Wikitechy - ruby on rails tutorial - rails guides - ruby rails - rubyonrails - learn ruby on rails - team
How you use these keys varies, but say for example some_component in the development environment needs access to secret_name. In config/environments/development.rb, we'd put:
Rails.application.configure do
config.some_component.configuration_hash = {
:secret => Rails.application.secrets.secret_name
}
end
Clicking "Copy Code" button will copy the code into the clipboard - memory. Please paste(Ctrl+V) it in your destination. The code will get pasted. Happy coding from Wikitechy - ruby on rails tutorial - rails guides - ruby rails - rubyonrails - learn ruby on rails - team
Finally, let's say you want to spin up a production environment on Heroku. This command will upload the values in config/environments/production.rb to Heroku:
$ figaro heroku:set -e production