Commit 31a5ef19 authored by Sarah Mei's avatar Sarah Mei

Switching to settingslogic to manage our configuration. THE FILE FORMAT HAS...

Switching to settingslogic to manage our configuration. THE FILE FORMAT HAS CHANGED. OLD APP.YML AND APP_CONFIG.YML FILES WILL NOT WORK ANYMORE.
Two important differences:
1. The app only looks in one file for settings: config/application.yml. If you want to override something, do it in that file. It is gitignore'd. If config/application.yml does not exist, or exists but is in the old format, you'll get a nice friendly set of instructions on how to convert your old file.
2. script/server settings are no longer in application.yml. They have their own settings file - copy config/script_server_config.yml.example to config/script_server_config.yml. This is also gitignore'd. script/server will print a message and exit if that file doesn't exist.
parent 4e5c6f0c
......@@ -6,6 +6,8 @@ public/images/ball.png
# Configuration files
config/app_config.yml
config/app.yml
config/application.yml
config/script_server_config.yml
config/fb_config.yml
config/oauth_keys.yml
config/initializers/secret_token.rb
......@@ -31,12 +33,12 @@ public/source.tar*
tmp/**/*
tmp/*
db/*.sqlite3
.redcar
# Temporary files of every sort
.sass-cache/*
.DS_Store
.idea
.redcar
.rvmrc
.stgit*
*.swap
......
......@@ -9,6 +9,7 @@ gem 'chef', '0.9.12', :require => false
gem 'ohai', '0.5.8', :require => false #Chef dependency
gem 'nokogiri'
gem 'settingslogic', '2.0.6'
#Security
gem 'devise', '~> 1.3.1'
......
......@@ -129,14 +129,14 @@ GEM
erubis
extlib
highline
json (>= 1.4.4, <= 1.4.6)
json (<= 1.4.6, >= 1.4.4)
mixlib-authentication (>= 1.1.0)
mixlib-cli (>= 1.1.0)
mixlib-config (>= 1.1.2)
mixlib-log (>= 1.2.0)
moneta
ohai (>= 0.5.7)
rest-client (>= 1.0.4, < 1.7.0)
rest-client (< 1.7.0, >= 1.0.4)
uuidtools
childprocess (0.1.7)
ffi (~> 0.6.3)
......@@ -146,10 +146,10 @@ GEM
columnize (0.3.2)
configuration (1.2.0)
crack (0.1.8)
cucumber (0.10.2)
cucumber (0.10.3)
builder (>= 2.1.2)
diff-lcs (>= 1.1.2)
gherkin (>= 2.3.5)
gherkin (>= 2.3.8)
json (>= 1.4.6)
term-ansicolor (>= 1.0.5)
cucumber-rails (0.3.2)
......@@ -163,7 +163,7 @@ GEM
warden (~> 1.0.3)
devise_invitable (0.5.0)
devise (~> 1.3.1)
rails (>= 3.0.0, <= 3.2)
rails (<= 3.2, >= 3.0.0)
diff-lcs (1.1.2)
erubis (2.6.6)
abstract (>= 1.0.0)
......@@ -177,7 +177,7 @@ GEM
faraday (0.5.4)
addressable (~> 2.2.2)
multipart-post (~> 1.1.0)
rack (>= 1.1.0, < 2)
rack (< 2, >= 1.1.0)
faraday_middleware (0.3.2)
faraday (~> 0.5.4)
fastercsv (1.5.4)
......@@ -201,7 +201,7 @@ GEM
rspec-instafail (~> 0.1.4)
ruby-progressbar (~> 0.0.10)
gem_plugin (0.2.3)
gherkin (2.3.8)
gherkin (2.3.9)
json (>= 1.4.6)
haml (3.0.25)
hashie (0.4.0)
......@@ -244,7 +244,7 @@ GEM
gem_plugin (>= 0.2.3)
multi_json (0.0.5)
multi_xml (0.2.2)
multipart-post (1.1.1)
multipart-post (1.1.2)
mysql2 (0.2.6)
net-ldap (0.1.1)
net-scp (1.0.4)
......@@ -284,7 +284,7 @@ GEM
multi_json (~> 0.0.4)
ohai (0.5.8)
extlib
json (>= 1.4.4, <= 1.4.6)
json (<= 1.4.6, >= 1.4.4)
mixlib-cli
mixlib-config
mixlib-log
......@@ -299,7 +299,7 @@ GEM
orm_adapter (0.0.5)
polyglot (0.3.1)
pyu-ruby-sasl (0.0.3.2)
rack (1.2.2)
rack (1.2.3)
rack-mount (0.6.14)
rack (>= 1.0.0)
rack-openid (1.2.0)
......@@ -366,10 +366,11 @@ GEM
ffi (~> 0.6.3)
json_pure
rubyzip
settingslogic (2.0.6)
simple_oauth (0.1.5)
sinatra (1.2.6)
rack (~> 1.1)
tilt (>= 1.2.2, < 2.0)
tilt (< 2.0, >= 1.2.2)
subexec (0.0.4)
systemu (2.2.0)
term-ansicolor (1.0.5)
......@@ -449,6 +450,7 @@ DEPENDENCIES
rspec-rails (>= 2.0.0)
ruby-debug
selenium-webdriver (= 0.1.3)
settingslogic (= 2.0.6)
sod!
thin (= 1.2.11)
twitter!
......
# Copyright (c) 2011, Diaspora Inc. This file is
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
require 'uri'
class AppConfig < Settingslogic
source File.join(Rails.root, "config", "application.yml")
namespace Rails.env
def self.load!
if no_config_file? && !have_old_config_file?
$stderr.puts <<-HELP
******** You haven't set up your Diaspora settings file. **********
Please do the following:
1. Copy config/application.yml.example to config/application.yml.
2. Have a look at the settings in that file. It has sensible defaults for development, which (we hope)
work without modification. However, it's always good to know what's available to change later.
3. Restart Diaspora!
******** Thanks for being an alpha tester! **********
HELP
Process.exit(1)
end
if (no_config_file? && have_old_config_file?) || config_file_is_old_style?
$stderr.puts <<-HELP
******** The Diaspora configuration file format has changed. **********
Please do the following:
1. Copy config/application.yml.example to config/application.yml.
2. Make any changes in config/application.yml that you previously made in config/app.yml or config/app_config.yml.
3. Delete config/app.yml and config/app_config.yml. Don't worry if they don't exist, though.
4. Restart Diaspora!
******** Thanks for being an alpha tester! **********
HELP
Process.exit(1)
end
super
normalize_pod_url
normalize_admins
end
def self.config_file_is_old_style?
!(File.read(@source) =~ /^defaults: &defaults/)
end
def self.no_config_file?
!File.exists?(@source)
end
def self.have_old_config_file?
File.exists?(File.join(Rails.root, "config", "app.yml")) || (File.exists?(File.join(Rails.root, "config", "app_config.yml")))
end
def self.normalize_pod_url
unless self[:pod_url] =~ /^(https?:\/\/)/ # starts with http:// or https://
self[:pod_url] = "http://#{self[:pod_url]}"
end
unless self[:pod_url] =~ /\/$/ # ends with slash
self[:pod_url] = "#{self[:pod_url]}/"
end
end
def self.normalize_admins
self[:admins] ||= []
self[:admins].collect! { |username| username.downcase }
end
load!
def self.[] (key)
return self.pod_uri if key == :pod_uri
super
end
def self.[]= (key, value)
@@pod_uri = nil if key == :pod_url
super
end
cattr_accessor :pod_uri
def self.pod_uri
if @@pod_uri.nil?
begin
@@pod_uri = URI.parse(self.pod_url)
rescue
puts "WARNING: pod url " + self.pod_url + " is not a legal URI"
end
end
return @@pod_uri
end
end
\ No newline at end of file
......@@ -2,42 +2,64 @@
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
default:
defaults: &defaults
# Hostname of this host, as seen from the internet.
# Hostname of the machine you're running Diaspora on, as seen from the internet.
# For development and testing, you can leave this as is.
pod_url: "http://localhost:3000"
# Set this to true in order to close signups. Users will still be
# able to invite other people to join.
# Set this to true to prevent people from signing up for your pod without an invitation.
registrations_closed: false
# Set this to true to prevent users from sending invitations.
invites_off: false
#
# Logging setup
#
# Enable extensive logging to log/{development,test,production}.log
debug: false
# Websocket server setup, see script/websocket_server.rb
# If you want normal Rails logs, set this to false in the appropriate environment.
# It is false by default in development and test.
enable_splunk_logging: true
#
# Websocket server setup - see script/websocket_server.rb
#
# Enable extensive logging to websocket server.
socket_debug : false
# Websocket host, leave as 0.0.0.0 unless you know what you are doing
# Websocket host - leave as 0.0.0.0 unless you know what you are doing
socket_host: 0.0.0.0
# File containing pid of running script/websocket_server.rb
socket_pidfile: "log/diaspora-wsd.pid"
# Websocket port, should normally be 8080 or 8081.
# Websocket port - should normally be 8080 or 8081.
socket_port: 8080
socket_collection_name: 'websocket'
# Secure websocket confguration (wss://)
# requires SSL cert and key
# Secure websocket confguration (wss://).
# Requires SSL cert and key
socket_secure: false
socket_cert_chain_location: '/full/path/to/cert_chain.crt'
socket_private_key_location: '/full/path/to/file.key'
# Diaspora is only tested against this default pubsub server.
#
# Federation setup
#
# Diaspora is only tested against this default pubsub server. You probably don't want to change this.
pubsub_server: 'https://pubsubhubbub.appspot.com/'
# Setting this to true enables diaspora's "send email" functionality
#
# Email setup
#
# Setting this to true enables Diaspora's "send email" functionality,
# requiring meaningful smtp_* settings. These are options for RoR's
# ActionMailer class.
mailer_on: false
......@@ -46,85 +68,78 @@ default:
# connection or 'sendmail' to use the sendmail binary.
mailer_method: 'smtp'
# Address/port to smtp server handing outgoing mail.
# Address/port to smtp server handling outgoing mail.
smtp_address: 'smtp.example.com'
smtp_port: '587'
# Domain administered of smtp server.
# Domain of smtp server.
smtp_domain: 'example.com'
# Sender address in diaspora's outgoing mail.
# Sender address in Diaspora's outgoing mail.
smtp_sender_address: 'no-reply@joindiaspora.com'
# Authentication required to send mail. Use one of 'one','plain',
# 'login' or 'cram-md5'. Use 'none' if server do not support
# Authentication required to send mail. Use one of 'one', 'plain',
# 'login' or 'cram-md5'. Use 'none' if server does not support
# authentication
smtp_authentication: 'plain'
# Automatically enable TLS? Ignored if smtp_authentication is set to none
smtp_starttls_auto: true
# Credentails possibly required to log in to SMTP server if
# smtp_authentication != 'none'
# Credentials to log in to the SMTP server - may be necessary if
# smtp_authentication is not 'none'
smtp_username: 'smtp_username'
smtp_password: 'secret'
# The path to the sendmail binary.
sendmail_location: '/usr/sbin/sendmail'
#google analytics key, if false, it won't include the javascript
#
# Web tracking setup
#
# google analytics key - if false, no javascript included
google_a_site: false
#piwik integration if not set, no javascript included
# piwik integration - if not set, no javascript included
piwik_id:
# the site url in raw format (e.g. pikwik.examplehost.com)
piwik_url:
#
# Miscellaneous setup
#
#cloudfiles username and api-key, used for backups
# cloudfiles username and api-key - used for backups
cloudfiles_username: 'example'
cloudfiles_api_key: 'abc123'
invites_off: false
#list of users who have admin privilages
# List of users who have admin privileges
admins:
- 'example_user1dsioaioedfhgoiesajdigtoearogjaidofgjo'
#s3 config, if set, carrierwave will store your photos on s3
# s3 config - if set, carrierwave will store your photos on s3. Otherwise they're on the filesystem.
#s3_key: 'key'
#s3_secret: 'secret'
#s3_bucket: 'my_photos'
s3_region: 'us-east-1'
# If you want normal Rails logs, set this to false in the appropriate environment.
# It is false by default in development and test.
enable_splunk_logging: true
# Process jobs in process?
# Set this to true if you want to do everything synchronously instead of using resque, our redis-backed queue system.
single_process_mode: true
# Use this sections to overide settings from default in the specific environments
# Use this section to override default settings in specific environments
development:
<<: *defaults
enable_splunk_logging: false
production:
<<: *defaults
single_process_mode: false
# Do not touch unless you know what you're doing
test:
pod_url: "http://example.org/"
<<: *defaults
pod_url: "http://example.org"
socket_port: 8081
enable_splunk_logging: false
# This section is special, you cannot overide settings from here in the above sections
script_server:
# Port on which thin should listen
thin_port: 3000
# customize thins startup
default_thin_args: "-p $THIN_PORT -e $RAILS_ENV"
# Possibilties are development, production
rails_env: "development"
# Copyright (c) 2010, Diaspora Inc. This file is
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
#
# Sets up AppConfig. Unless stated below, each entry is a the string in
# the file app.yml, as applicable for current environment.
#
# Specific items
# * pod_url: As in app.yml, normalized with a trailing /.
# * pod_uri: An uri object derived from pod_url.
require File.join(Rails.root, 'lib', 'app_config')
AppConfig.configure_for_environment(Rails.env)
require File.join(Rails.root, 'app', 'models', 'app_config')
\ No newline at end of file
script_server:
# Port on which thin should listen
thin_port: 3000
# Customize thin's startup
default_thin_args: "-p $THIN_PORT -e $RAILS_ENV"
# Possibilities are development, production
rails_env: "development"
\ No newline at end of file
# Copyright (c) 2011, Diaspora Inc. This file is
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
class AppConfig
cattr_accessor :config_vars
cattr_accessor :base_file_path
cattr_accessor :file_path
def self.base_file_path
@@base_file_path || File.join(Rails.root, "config", "app_base.yml")
end
def self.file_path
@@file_path || File.join(Rails.root, "config", "app.yml")
end
def self.[](key)
config_vars[key]
end
def self.[]=(key, value)
config_vars[key] = value
end
def self.has_key?(key)
config_vars.has_key?(key)
end
def self.configure_for_environment(env)
load_config_for_environment(env)
generate_pod_uri
normalize_pod_url
check_pod_uri
downcase_usernames
end
def self.load_config_for_environment(env)
if File.exist?(base_file_path)
all_envs = load_config_yaml(base_file_path)
else
$stderr.puts "OH NO! Required file #{base_file_path} doesn't exist! Did you move it?"
all_envs = {}
end
if File.exist?(file_path)
all_envs_custom = load_config_yaml(file_path)
all_envs.deep_merge!(all_envs_custom)
elsif File.exist? "#{Rails.root}/config/app_config.yml"
all_envs_custom = load_config_yaml "#{Rails.root}/config/app_config.yml"
all_envs.deep_merge!(all_envs_custom)
$stderr.puts "DEPRECATION WARNING: config/app_config.yml has been renamed to config/app.yml"
else
unless Rails.env == "development" || Rails.env == "test"
$stderr.puts "WARNING: No config/app.yml found! Look at config/app.yml.example for help."
end
end
# Is there a config at all?
unless all_envs['default']
$stderr.puts "What did you do? There's no config at all!"
Process.exit(false)
end
env = env.to_s
if all_envs[env]
self.config_vars = all_envs['default'].merge(all_envs[env]).symbolize_keys
else
self.config_vars = all_envs['default'].symbolize_keys
end
end
def self.generate_pod_uri
require 'uri'
unless self.config_vars[:pod_url] =~ /^(https?:\/\/)/
self.config_vars[:pod_url] = "http://#{self.config_vars[:pod_url]}"
end
begin
self.config_vars[:pod_uri] = URI.parse(self.config_vars[:pod_url])
rescue
puts "WARNING: pod url " + self.config_vars[:pod_url] + " is not a legal URI"
end
end
def self.normalize_pod_url
self.config_vars[:pod_url] = self.config_vars[:pod_uri].normalize.to_s
end
def self.check_pod_uri
if self.config_vars[:pod_uri].host == "example.org" && Rails.env != "test"
puts "WARNING: Please modify your app.yml to have a proper pod_url!"
end
end
def self.downcase_usernames
[:admins, :auth_tokenable].each do |key|
self.config_vars[key] ||= []
self.config_vars[key].collect! { |username| username.downcase }
end
end
def self.load_config_yaml filename
# nil values are bad for merges and have no meaning here, so lets get rid of them
YAML.load(File.read(filename)).delete_if { |k, v| v.nil? }
end
end
......@@ -4,17 +4,12 @@
# the COPYRIGHT file.
require 'rubygems'
require 'yaml'
require 'active_support/core_ext/class/attribute_accessors'
require 'active_support/core_ext/hash/keys'
require 'active_support/core_ext/hash/deep_merge'
class Rails
def self.root
File.join(File.dirname(__FILE__), "..")
File.expand_path(File.join(File.dirname(__FILE__), ".."))
end
def self.env
env = 'development'
env = ENV['RAILS_ENV'] if ENV.has_key?('RAILS_ENV')
......@@ -23,21 +18,33 @@ class Rails
end
end
require File.join(Rails.root, 'lib', 'app_config')
if ARGV.length >= 1
key = ARGV[0].to_sym
AppConfig.configure_for_environment(Rails.env)
if AppConfig.has_key?(key)
print AppConfig[key]
else
puts "Invalid option #{ARGV[0]}"
exit 2
setting_name = ARGV[0]
if Rails.env == 'script_server' # load from the special script_server_config.yml file
require 'yaml'
script_server_config_file = File.join(Rails.root, 'config', 'script_server_config.yml')
begin
print YAML.load_file(script_server_config_file)['script_server'][setting_name]
rescue
$stderr.puts "Setting '#{setting_name}' not found in file #{script_server_config_file}."
$stderr.puts "Does that file exist? If not, copy it from #{File.basename(script_server_config_file)}.example in the same directory and run this script again."
Process.exit(1)
end
else # load from the general diaspora settings file
require 'active_support/core_ext/class/attribute_accessors'
require 'settingslogic'
require File.join(Rails.root, 'app', 'models', 'app_config')
setting_name = setting_name.to_sym
if AppConfig[setting_name].nil?
$stderr.puts "Could not find setting #{ARGV[0]} for environment #{Rails.env}."
Process.exit(1)
else
print AppConfig[setting_name]
end
end
else
puts "Usage: ./script/get_config.rb option [section]"
puts ""
puts "section defaults to development"
exit 1
$stderr.puts "Usage: ./script/get_config.rb option [section]"
$stderr.puts ""
$stderr.puts "section defaults to development"
Process.exit(1)
end
......@@ -137,12 +137,7 @@ if [ ! -e public/source.tar.gz ]; then
fi
# Check if config files exists
if [ ! -e 'config/app.yml' ]; then
echo "FATAL: config/app.yml is missing! Copy over config/app.yml.example to config/app.yml and edit it properly!" >&2
exit 67
fi
# Check if database.yml exists
if [ ! -e 'config/database.yml' ]; then
echo 'FATAL: config/database.yml is missing! Copy over config/database.yml.example to config/database.yml and edit it properly!' >&2
exit 68
......
# Copyright (c) 2010, Diaspora Inc. This file is
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
require 'spec_helper'
describe 'making sure the config is parsed as should' do
describe 'pod_url' do
it 'should have a trailing slash' do