diff --git a/Gemfile b/Gemfile index 93b2ca4..43ed208 100644 --- a/Gemfile +++ b/Gemfile @@ -17,7 +17,7 @@ gem 'strong_parameters' gem 'SystemTimer', :platform => :ruby_18 gem 'actionmailer_inline_css' gem 'kaminari', '>= 0.14.1' -gem 'rack-ssl-enforcer' +gem 'rack-ssl-enforcer', :require => false # fabrication 1.3.0 is last supporting ruby 1.8. Update when stop supporting this version too gem 'fabrication', "~> 1.3.0" # Used for both tests and demo data gem 'rails_autolink' diff --git a/config/initializers/_load_config.rb b/config/initializers/_load_config.rb index 6086b11..64f8396 100644 --- a/config/initializers/_load_config.rb +++ b/config/initializers/_load_config.rb @@ -4,15 +4,17 @@ default_config_file = Rails.root.join("config", "config.example.yml") # Allow a Rails Engine to override config by defining it earlier unless defined?(Errbit::Config) Errbit::Config = OpenStruct.new + use_env = ENV['HEROKU'] || ENV['USE_ENV'] # If Errbit is running on Heroku, config can be set from environment variables. - if ENV['HEROKU'] + if use_env Errbit::Config.host = ENV['ERRBIT_HOST'] Errbit::Config.email_from = ENV['ERRBIT_EMAIL_FROM'] - Errbit::Config.email_at_notices = ENV['ERRBIT_EMAIL_AT_NOTICES'] - Errbit::Config.confirm_resolve_err = ENV['ERRBIT_CONFIRM_RESOLVE_ERR'] - Errbit::Config.user_has_username = ENV['ERRBIT_USER_HAS_USERNAME'] - Errbit::Config.allow_comments_with_issue_tracker = ENV['ERRBIT_ALLOW_COMMENTS_WITH_ISSUE_TRACKER'] + # Not really easy to use like an env because need an array and ENV return a string :( + # Errbit::Config.email_at_notices = ENV['ERRBIT_EMAIL_AT_NOTICES'] + Errbit::Config.confirm_resolve_err = ENV['ERRBIT_CONFIRM_RESOLVE_ERR'].to_i == 0 + Errbit::Config.user_has_username = ENV['ERRBIT_USER_HAS_USERNAME'].to_i == 1 + Errbit::Config.allow_comments_with_issue_tracker = ENV['ERRBIT_ALLOW_COMMENTS_WITH_ISSUE_TRACKER'].to_i == 0 Errbit::Config.enforce_ssl = ENV['ERRBIT_ENFORCE_SSL'] Errbit::Config.use_gravatar = ENV['ERRBIT_USE_GRAVATAR'] @@ -29,7 +31,7 @@ unless defined?(Errbit::Config) :authentication => :plain, :user_name => ENV['SMTP_USERNAME'] || ENV['SENDGRID_USERNAME'], :password => ENV['SMTP_PASSWORD'] || ENV['SENDGRID_PASSWORD'], - :domain => ENV['SENDGRID_DOMAIN'] || ENV['ERRBIT_EMAIL_FROM'].split('@').last + :domain => ENV['SMTP_DOMAIN'] || ENV['SENDGRID_DOMAIN'] || ENV['ERRBIT_EMAIL_FROM'].split('@').last } end @@ -44,7 +46,7 @@ unless defined?(Errbit::Config) Errbit::Config.send("#{k}=", v) end # Show message if we are not running tests, not running on Heroku, and config.yml doesn't exist. - elsif not ENV['HEROKU'] + elsif not use_env puts "Please copy 'config/config.example.yml' to 'config/config.yml' and configure your settings. Using default settings." end @@ -76,4 +78,4 @@ end if Rails.env.production? Rails.application.config.consider_all_requests_local = Errbit::Config.display_internal_errors -end \ No newline at end of file +end diff --git a/config/initializers/mongo.rb b/config/initializers/mongo.rb index 30b1377..0a91121 100644 --- a/config/initializers/mongo.rb +++ b/config/initializers/mongo.rb @@ -1,12 +1,33 @@ -if mongo = ENV['MONGOLAB_URI'] || ENV['MONGOHQ_URL'] - settings = URI.parse(mongo) - database_name = settings.path.gsub(/^\//, '') +# Some code extract from Mongoid gem +config_file = Rails.root.join("config", "mongoid.yml") +if config_file.file? && + YAML.load(ERB.new(File.read(config_file)).result)[Rails.env].values.flatten.any? + ::Mongoid.load!(config_file) +else + # No mongoid.yml file. Use ENV variable to define your MongoDB + # configuration + if mongo = ENV['MONGOLAB_URI'] || ENV['MONGOHQ_URL'] + settings = URI.parse(mongo) + database_name = settings.path.gsub(/^\//, '') + else + settings = OpenStruct.new({ + :host => ENV['MONGOID_HOST'], + :port => ENV['MONGOID_PORT'], + :user => ENV['MONGOID_USERNAME'], + :password => ENV['MONGOID_PASSWORD'] + }) + database_name = ENV['MONGOID_DATABASE'] + end Mongoid.configure do |config| - config.master = Mongo::Connection.new(settings.host, settings.port).db(database_name) + config.master = Mongo::Connection.new( + settings.host, + settings.port + ).db(database_name) config.master.authenticate(settings.user, settings.password) if settings.user - config.allow_dynamic_fields = false - config.use_activesupport_time_zone = true end end +Mongoid.allow_dynamic_fields = false +Mongoid.use_activesupport_time_zone = true +Mongoid.identity_map_enabled = true diff --git a/config/initializers/ssl_enforcer.rb b/config/initializers/ssl_enforcer.rb index 106f347..03c8ed8 100755 --- a/config/initializers/ssl_enforcer.rb +++ b/config/initializers/ssl_enforcer.rb @@ -1,5 +1,6 @@ # Enforce SSL connections, if configured if Errbit::Config.enforce_ssl + require 'rack/ssl-enforcer' ActionMailer::Base.default_url_options.merge!(:protocol => 'https://') Errbit::Application.configure do config.middleware.use Rack::SslEnforcer, :except => /^\/deploys/ diff --git a/docs/ENV-VARIABLES.md b/docs/ENV-VARIABLES.md new file mode 100644 index 0000000..0463e0a --- /dev/null +++ b/docs/ENV-VARIABLES.md @@ -0,0 +1,59 @@ +# Which env variable you can use ? + +Errbit can be almost configured by some ENVIRONMENT variables. If you +use this variable, you don't need copy all of you configuration file + +To activate this env variable you need activate it by a Variable env. +You can do that with HEROKU or USE_ENV variable + +If you activate it you can use all of this env variable : + +## Errbit base configuration + +* ERRBIT_HOST : the host of your errbit instance (not define by default) +* ERRBIT_EMAIL_FROM : the email sending all of your notification (not + define by default ) +* ERRBIT_CONFIRM_RESOLVE_ERR : define if you need confirm when you mark + a problem resolve. ( true by default, fill it and you not need +confirm ) +* ERRBIT_USER_HAS_USERNAME : allow identify your user by username + instead of email. ( false by default, set to '1' to activate it) +* ERRBIT_ALLOW_COMMENTS_WITH_ISSUE_TRACKER : define if you activate the + comment or not. By default comment are +* ERRBIT_ENFORCE_SSL : allow force the ssl on all the application. By + default is false +* ERRBIT_USE_GRAVATAR : allow use gravatar to see user gravatar in user + comment and page + +## Authentification configuration + +Environement variable allow define how you can auth on your errbit + +### Github authentification + +You can allow the GITHUB auth + +* GITHUB_AUTHENTIFICATION : define if you allow the github auth. By + default false +* GITHUB_CLIENT_ID : you github app client id to use in your github auth +* GITHUB_SECRET : your github app secret to use in your github auth +* GITHUB_ACCESS_SCOPE : The scope to ask to access on github account + +## Email sending configuration + +* SMTP_SERVER +* SMTP_PORT +* SMTP_USERNAME +* SMTP_PASSWORD +* SMTP_DOMAIN + +## MongoDB + +* MONGOLAB_URI +* MONGOHQ_URL +* MONGOID_HOST +* MONGOID_PORT +* MONGOID_USERNAME +* MONGOID_PASSWORD +* MONGOID_DATABASE + -- libgit2 0.21.2