From 69e81a0dc303d688afef0be8c3b34945057f5074 Mon Sep 17 00:00:00 2001 From: Maxwell Salzberg Date: Wed, 18 Jan 2012 17:57:26 -0800 Subject: [PATCH] move loading rack ssl to an initializer, so we have EnviromentConfiguration and AppConfig. also, circumvent ssl requirement option is now back" --- config/application.yml.example | 1 + config/initializers/enforce_ssl.rb | 1 + lib/enviroment_configuration.rb | 9 ++++++++- 3 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 config/initializers/enforce_ssl.rb diff --git a/config/application.yml.example b/config/application.yml.example index 4eadcf13c..1f2d69eeb 100644 --- a/config/application.yml.example +++ b/config/application.yml.example @@ -196,6 +196,7 @@ defaults: &defaults # is running on the default Redis port. redis_location: '' + circumvent_ssl_requirement: false # Web tracking diff --git a/config/initializers/enforce_ssl.rb b/config/initializers/enforce_ssl.rb new file mode 100644 index 000000000..4f5306955 --- /dev/null +++ b/config/initializers/enforce_ssl.rb @@ -0,0 +1 @@ +Rails.application.config.middleware.insert_before(Rack::Runtime, Rack::SSL) if EnviromentConfiguration.enforce_ssl? diff --git a/lib/enviroment_configuration.rb b/lib/enviroment_configuration.rb index 43fcd4b83..a48289221 100644 --- a/lib/enviroment_configuration.rb +++ b/lib/enviroment_configuration.rb @@ -1,5 +1,5 @@ module EnviromentConfiguration - ARRAY_SEPERATOR = '%|%' + def self.heroku? ENV['HEROKU'] end @@ -29,6 +29,13 @@ module EnviromentConfiguration end end + def self.enforce_ssl? + return false unless Rails.env == 'production' + return false if ENV['NO_SSL'] + return false if AppConfig[:circumvent_ssl_requirement].present? + true + end + def self.ca_cert_file_location if self.heroku? "/usr/lib/ssl/certs/ca-certificates.crt"