When I started to publish code on GitHub I began searching for the best way to share my code without accidentially giving away my keys, passcodes or usernames. I tried to fork a version for publishing but branch history will still allow the public to see what was in previous versions. After trying a few methods, I opted to store all my passcodes in a *.yml file in config folder and just add it to the .gitignore. This required a few notes to let cloners know what to do with the code in the case they were to use their own keys directly.
Create a file under the ‘/config’ folder ‘ app_passwords.yml’
defaults: &defaults app_key: my_app_key app_secret: my_app_secret development: <<: *defaults test: <<: *defaults production: <<: *defaults
In ‘config/initializers/01_app_passwords.rb’
MY_PASSWORDS = YAML.load_file("#{Rails.root}/config/app_passwords.yml")[Rails.env]
In ‘my_controller.rb’
APP_KEY = MY_PASSWORDS['app_key'] APP_SECRET = MY_PASSWORDS['app_secret']
- Change ‘MY_PASSWORDS['app_key’]‘ and 'MY_PASSWORDS['app_secret’] with their own keys and passwords. or….
- Add their own ‘app_passwords.yml’ to the ‘/config’ folder.
No comments:
Post a Comment