From ee5d48d4940a136283c1d7b2be47af93888edf10 Mon Sep 17 00:00:00 2001 From: Henne Vogelsang Date: Mon, 12 May 2014 18:32:26 +0200 Subject: [PATCH] Migrate all secrets to config/secrets.yml --- .gitignore | 1 + .travis.yml | 1 + config/config.yml.example | 7 +------ config/environment.rb | 1 - config/initializers/devise.rb | 2 +- config/initializers/hoptoad.rb | 10 +++++----- config/initializers/secret_token.rb | 7 ------- config/secrets.yml.example | 20 ++++++++++++++++++++ 8 files changed, 29 insertions(+), 20 deletions(-) delete mode 100644 config/initializers/secret_token.rb create mode 100644 config/secrets.yml.example diff --git a/.gitignore b/.gitignore index 69669e6c..a9ebd7f2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ config/application.rb config/config.yml +config/secrets.yml config/database.yml /vendor/cache /vendor/cache-old diff --git a/.travis.yml b/.travis.yml index bb77e858..94148e6d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -14,6 +14,7 @@ before_install: before_script: - cp config/database.yml.example config/database.yml - cp config/config.yml.example config/config.yml + - cp config/secrets.yml.example config/secrets.yml - RAILS_ENV=test bundle exec rake db:migrate --trace script: - bundle exec rspec --color --format documentation diff --git a/config/config.yml.example b/config/config.yml.example index f2e72703..c0c98b6d 100644 --- a/config/config.yml.example +++ b/config/config.yml.example @@ -5,14 +5,9 @@ defaults: &defaults devise_mail_sender: "no-reply@localhost" # The hostname to be used when building the URL in the emails url_for_emails: "localhost:3000" - # A secret key for your rails app. You can generate one with 'rake secret' - secret_key: 12345 - # A secret key. You can generate one with 'rake secret' - devise_secret_key: '12345' # errbit configuration, get your own instance: https://github.com/errbit/errbit - #errbit_key: 123456789101112131415 + #errbit_key: See config/secrets.yml #errbit_host: errbit.exmaple.com - cookies_secret_token: 'secretstringwhichshouldbechanged' development: <<: *defaults diff --git a/config/environment.rb b/config/environment.rb index 2a233acc..6b0a63d2 100644 --- a/config/environment.rb +++ b/config/environment.rb @@ -12,4 +12,3 @@ end # Initialize the rails application Osem::Application.initialize! -Osem::Application.config.secret_keybase = CONFIG['secret_key'] diff --git a/config/initializers/devise.rb b/config/initializers/devise.rb index 77208236..2dc7d680 100644 --- a/config/initializers/devise.rb +++ b/config/initializers/devise.rb @@ -2,7 +2,7 @@ # Many of these configuration options can be set straight in your model. Devise.setup do |config| # ==> Secret key, generate one with `rake secret` - config.secret_key = CONFIG['devise_secret_key'] + config.secret_key = Rails.application.secrets.devise_secret_key # ==> Mailer Configuration # Configure the e-mail address which will be shown in Devise::Mailer, diff --git a/config/initializers/hoptoad.rb b/config/initializers/hoptoad.rb index 970310a8..14780578 100644 --- a/config/initializers/hoptoad.rb +++ b/config/initializers/hoptoad.rb @@ -1,11 +1,11 @@ HoptoadNotifier.configure do |config| # Change this to some sensible data for your errbit instance - config.api_key = CONFIG["errbit_key"] || "" - config.host = CONFIG["errbit_host"] || "" + config.api_key = Rails.application.secrets.errbit_key || '' + config.host = CONFIG['errbit_host'] || '' if config.api_key.blank? || config.host.blank? - config.development_environments = "production development test" + config.development_environments = 'production development test' else - config.development_environments = "development test" + config.development_environments = 'development test' end config.ignore_only = %w{ @@ -14,7 +14,7 @@ HoptoadNotifier.configure do |config| config.ignore_by_filter do |exception_data| ret=false - if exception_data[:error_class] == "ActionController::RoutingError" + if exception_data[:error_class] == 'ActionController::RoutingError' message = exception_data[:error_message] ret=true if message =~ %r{\[GET\]} end diff --git a/config/initializers/secret_token.rb b/config/initializers/secret_token.rb deleted file mode 100644 index 98825f4a..00000000 --- a/config/initializers/secret_token.rb +++ /dev/null @@ -1,7 +0,0 @@ -# Be sure to restart your server when you modify this file. - -# Your secret key for verifying the integrity of signed cookies. -# If you change this key, all old signed cookies will become invalid! -# Make sure the secret is at least 30 characters and all random, -# no regular words or you'll be exposed to dictionary attacks. -Osem::Application.config.secret_token = CONFIG['cookies_secret_token'] diff --git a/config/secrets.yml.example b/config/secrets.yml.example new file mode 100644 index 00000000..d88180d4 --- /dev/null +++ b/config/secrets.yml.example @@ -0,0 +1,20 @@ +defaults: &defaults + # You can generate secret keys with 'rake secret' + + # For rails cookies + secret_key_base: '12345' + + # For devise login tokens + devise_secret_key: '12345' + + # Your errbit API key + # errbit_key: '12345' + +development: + <<: *defaults + +test: + <<: *defaults + +production: + <<: *defaults