问题
What is the safest way of storing passwords that is used to other services?
Example:
App that needs to store passwords for other sites to do a rake task for fetching data that require authentication.
回答1:
You would store this data as environment variables. For example, for one of my projects I need my app to have access to a Github login. This Github login is stored as an environment variable by adding the following line to my .bashrc file.
export GITHUB_LOGIN=myLogin
In my app's config file I refer to this environment variable like this:
:github_login: <%= ENV['GITHUB_LOGIN'] %>
This config file is then loaded by the app like this:
require 'erb'
raw_data = File.read(config_file)
erbified_data = ERB.new(raw_data).result
来源:https://stackoverflow.com/questions/15978253/rails-how-to-store-passwords-for-other-services