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.
This commit is contained in:
parent
4e5c6f0c97
commit
31a5ef19de
14 changed files with 364 additions and 298 deletions
4
.gitignore
vendored
4
.gitignore
vendored
|
|
@ -6,6 +6,8 @@ public/images/ball.png
|
||||||
# Configuration files
|
# Configuration files
|
||||||
config/app_config.yml
|
config/app_config.yml
|
||||||
config/app.yml
|
config/app.yml
|
||||||
|
config/application.yml
|
||||||
|
config/script_server_config.yml
|
||||||
config/fb_config.yml
|
config/fb_config.yml
|
||||||
config/oauth_keys.yml
|
config/oauth_keys.yml
|
||||||
config/initializers/secret_token.rb
|
config/initializers/secret_token.rb
|
||||||
|
|
@ -31,12 +33,12 @@ public/source.tar*
|
||||||
tmp/**/*
|
tmp/**/*
|
||||||
tmp/*
|
tmp/*
|
||||||
db/*.sqlite3
|
db/*.sqlite3
|
||||||
.redcar
|
|
||||||
|
|
||||||
# Temporary files of every sort
|
# Temporary files of every sort
|
||||||
.sass-cache/*
|
.sass-cache/*
|
||||||
.DS_Store
|
.DS_Store
|
||||||
.idea
|
.idea
|
||||||
|
.redcar
|
||||||
.rvmrc
|
.rvmrc
|
||||||
.stgit*
|
.stgit*
|
||||||
*.swap
|
*.swap
|
||||||
|
|
|
||||||
1
Gemfile
1
Gemfile
|
|
@ -9,6 +9,7 @@ gem 'chef', '0.9.12', :require => false
|
||||||
gem 'ohai', '0.5.8', :require => false #Chef dependency
|
gem 'ohai', '0.5.8', :require => false #Chef dependency
|
||||||
|
|
||||||
gem 'nokogiri'
|
gem 'nokogiri'
|
||||||
|
gem 'settingslogic', '2.0.6'
|
||||||
|
|
||||||
#Security
|
#Security
|
||||||
gem 'devise', '~> 1.3.1'
|
gem 'devise', '~> 1.3.1'
|
||||||
|
|
|
||||||
24
Gemfile.lock
24
Gemfile.lock
|
|
@ -129,14 +129,14 @@ GEM
|
||||||
erubis
|
erubis
|
||||||
extlib
|
extlib
|
||||||
highline
|
highline
|
||||||
json (>= 1.4.4, <= 1.4.6)
|
json (<= 1.4.6, >= 1.4.4)
|
||||||
mixlib-authentication (>= 1.1.0)
|
mixlib-authentication (>= 1.1.0)
|
||||||
mixlib-cli (>= 1.1.0)
|
mixlib-cli (>= 1.1.0)
|
||||||
mixlib-config (>= 1.1.2)
|
mixlib-config (>= 1.1.2)
|
||||||
mixlib-log (>= 1.2.0)
|
mixlib-log (>= 1.2.0)
|
||||||
moneta
|
moneta
|
||||||
ohai (>= 0.5.7)
|
ohai (>= 0.5.7)
|
||||||
rest-client (>= 1.0.4, < 1.7.0)
|
rest-client (< 1.7.0, >= 1.0.4)
|
||||||
uuidtools
|
uuidtools
|
||||||
childprocess (0.1.7)
|
childprocess (0.1.7)
|
||||||
ffi (~> 0.6.3)
|
ffi (~> 0.6.3)
|
||||||
|
|
@ -146,10 +146,10 @@ GEM
|
||||||
columnize (0.3.2)
|
columnize (0.3.2)
|
||||||
configuration (1.2.0)
|
configuration (1.2.0)
|
||||||
crack (0.1.8)
|
crack (0.1.8)
|
||||||
cucumber (0.10.2)
|
cucumber (0.10.3)
|
||||||
builder (>= 2.1.2)
|
builder (>= 2.1.2)
|
||||||
diff-lcs (>= 1.1.2)
|
diff-lcs (>= 1.1.2)
|
||||||
gherkin (>= 2.3.5)
|
gherkin (>= 2.3.8)
|
||||||
json (>= 1.4.6)
|
json (>= 1.4.6)
|
||||||
term-ansicolor (>= 1.0.5)
|
term-ansicolor (>= 1.0.5)
|
||||||
cucumber-rails (0.3.2)
|
cucumber-rails (0.3.2)
|
||||||
|
|
@ -163,7 +163,7 @@ GEM
|
||||||
warden (~> 1.0.3)
|
warden (~> 1.0.3)
|
||||||
devise_invitable (0.5.0)
|
devise_invitable (0.5.0)
|
||||||
devise (~> 1.3.1)
|
devise (~> 1.3.1)
|
||||||
rails (>= 3.0.0, <= 3.2)
|
rails (<= 3.2, >= 3.0.0)
|
||||||
diff-lcs (1.1.2)
|
diff-lcs (1.1.2)
|
||||||
erubis (2.6.6)
|
erubis (2.6.6)
|
||||||
abstract (>= 1.0.0)
|
abstract (>= 1.0.0)
|
||||||
|
|
@ -177,7 +177,7 @@ GEM
|
||||||
faraday (0.5.4)
|
faraday (0.5.4)
|
||||||
addressable (~> 2.2.2)
|
addressable (~> 2.2.2)
|
||||||
multipart-post (~> 1.1.0)
|
multipart-post (~> 1.1.0)
|
||||||
rack (>= 1.1.0, < 2)
|
rack (< 2, >= 1.1.0)
|
||||||
faraday_middleware (0.3.2)
|
faraday_middleware (0.3.2)
|
||||||
faraday (~> 0.5.4)
|
faraday (~> 0.5.4)
|
||||||
fastercsv (1.5.4)
|
fastercsv (1.5.4)
|
||||||
|
|
@ -201,7 +201,7 @@ GEM
|
||||||
rspec-instafail (~> 0.1.4)
|
rspec-instafail (~> 0.1.4)
|
||||||
ruby-progressbar (~> 0.0.10)
|
ruby-progressbar (~> 0.0.10)
|
||||||
gem_plugin (0.2.3)
|
gem_plugin (0.2.3)
|
||||||
gherkin (2.3.8)
|
gherkin (2.3.9)
|
||||||
json (>= 1.4.6)
|
json (>= 1.4.6)
|
||||||
haml (3.0.25)
|
haml (3.0.25)
|
||||||
hashie (0.4.0)
|
hashie (0.4.0)
|
||||||
|
|
@ -244,7 +244,7 @@ GEM
|
||||||
gem_plugin (>= 0.2.3)
|
gem_plugin (>= 0.2.3)
|
||||||
multi_json (0.0.5)
|
multi_json (0.0.5)
|
||||||
multi_xml (0.2.2)
|
multi_xml (0.2.2)
|
||||||
multipart-post (1.1.1)
|
multipart-post (1.1.2)
|
||||||
mysql2 (0.2.6)
|
mysql2 (0.2.6)
|
||||||
net-ldap (0.1.1)
|
net-ldap (0.1.1)
|
||||||
net-scp (1.0.4)
|
net-scp (1.0.4)
|
||||||
|
|
@ -284,7 +284,7 @@ GEM
|
||||||
multi_json (~> 0.0.4)
|
multi_json (~> 0.0.4)
|
||||||
ohai (0.5.8)
|
ohai (0.5.8)
|
||||||
extlib
|
extlib
|
||||||
json (>= 1.4.4, <= 1.4.6)
|
json (<= 1.4.6, >= 1.4.4)
|
||||||
mixlib-cli
|
mixlib-cli
|
||||||
mixlib-config
|
mixlib-config
|
||||||
mixlib-log
|
mixlib-log
|
||||||
|
|
@ -299,7 +299,7 @@ GEM
|
||||||
orm_adapter (0.0.5)
|
orm_adapter (0.0.5)
|
||||||
polyglot (0.3.1)
|
polyglot (0.3.1)
|
||||||
pyu-ruby-sasl (0.0.3.2)
|
pyu-ruby-sasl (0.0.3.2)
|
||||||
rack (1.2.2)
|
rack (1.2.3)
|
||||||
rack-mount (0.6.14)
|
rack-mount (0.6.14)
|
||||||
rack (>= 1.0.0)
|
rack (>= 1.0.0)
|
||||||
rack-openid (1.2.0)
|
rack-openid (1.2.0)
|
||||||
|
|
@ -366,10 +366,11 @@ GEM
|
||||||
ffi (~> 0.6.3)
|
ffi (~> 0.6.3)
|
||||||
json_pure
|
json_pure
|
||||||
rubyzip
|
rubyzip
|
||||||
|
settingslogic (2.0.6)
|
||||||
simple_oauth (0.1.5)
|
simple_oauth (0.1.5)
|
||||||
sinatra (1.2.6)
|
sinatra (1.2.6)
|
||||||
rack (~> 1.1)
|
rack (~> 1.1)
|
||||||
tilt (>= 1.2.2, < 2.0)
|
tilt (< 2.0, >= 1.2.2)
|
||||||
subexec (0.0.4)
|
subexec (0.0.4)
|
||||||
systemu (2.2.0)
|
systemu (2.2.0)
|
||||||
term-ansicolor (1.0.5)
|
term-ansicolor (1.0.5)
|
||||||
|
|
@ -449,6 +450,7 @@ DEPENDENCIES
|
||||||
rspec-rails (>= 2.0.0)
|
rspec-rails (>= 2.0.0)
|
||||||
ruby-debug
|
ruby-debug
|
||||||
selenium-webdriver (= 0.1.3)
|
selenium-webdriver (= 0.1.3)
|
||||||
|
settingslogic (= 2.0.6)
|
||||||
sod!
|
sod!
|
||||||
thin (= 1.2.11)
|
thin (= 1.2.11)
|
||||||
twitter!
|
twitter!
|
||||||
|
|
|
||||||
94
app/models/app_config.rb
Normal file
94
app/models/app_config.rb
Normal file
|
|
@ -0,0 +1,94 @@
|
||||||
|
# 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
|
||||||
|
|
@ -2,42 +2,64 @@
|
||||||
# licensed under the Affero General Public License version 3 or later. See
|
# licensed under the Affero General Public License version 3 or later. See
|
||||||
# the COPYRIGHT file.
|
# 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"
|
pod_url: "http://localhost:3000"
|
||||||
|
|
||||||
# Set this to true in order to close signups. Users will still be
|
# Set this to true to prevent people from signing up for your pod without an invitation.
|
||||||
# able to invite other people to join.
|
|
||||||
registrations_closed: false
|
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
|
# Enable extensive logging to log/{development,test,production}.log
|
||||||
debug: false
|
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.
|
# Enable extensive logging to websocket server.
|
||||||
socket_debug : false
|
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
|
socket_host: 0.0.0.0
|
||||||
|
|
||||||
# File containing pid of running script/websocket_server.rb
|
# File containing pid of running script/websocket_server.rb
|
||||||
socket_pidfile: "log/diaspora-wsd.pid"
|
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_port: 8080
|
||||||
socket_collection_name: 'websocket'
|
socket_collection_name: 'websocket'
|
||||||
|
|
||||||
# Secure websocket confguration (wss://)
|
# Secure websocket confguration (wss://).
|
||||||
# requires SSL cert and key
|
# Requires SSL cert and key
|
||||||
socket_secure: false
|
socket_secure: false
|
||||||
socket_cert_chain_location: '/full/path/to/cert_chain.crt'
|
socket_cert_chain_location: '/full/path/to/cert_chain.crt'
|
||||||
socket_private_key_location: '/full/path/to/file.key'
|
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/'
|
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
|
# requiring meaningful smtp_* settings. These are options for RoR's
|
||||||
# ActionMailer class.
|
# ActionMailer class.
|
||||||
mailer_on: false
|
mailer_on: false
|
||||||
|
|
@ -46,85 +68,78 @@ default:
|
||||||
# connection or 'sendmail' to use the sendmail binary.
|
# connection or 'sendmail' to use the sendmail binary.
|
||||||
mailer_method: 'smtp'
|
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_address: 'smtp.example.com'
|
||||||
smtp_port: '587'
|
smtp_port: '587'
|
||||||
|
|
||||||
# Domain administered of smtp server.
|
# Domain of smtp server.
|
||||||
smtp_domain: 'example.com'
|
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'
|
smtp_sender_address: 'no-reply@joindiaspora.com'
|
||||||
|
|
||||||
# Authentication required to send mail. Use one of 'one', 'plain',
|
# Authentication required to send mail. Use one of 'one', 'plain',
|
||||||
# 'login' or 'cram-md5'. Use 'none' if server do not support
|
# 'login' or 'cram-md5'. Use 'none' if server does not support
|
||||||
# authentication
|
# authentication
|
||||||
smtp_authentication: 'plain'
|
smtp_authentication: 'plain'
|
||||||
|
|
||||||
# Automatically enable TLS? Ignored if smtp_authentication is set to none
|
# Automatically enable TLS? Ignored if smtp_authentication is set to none
|
||||||
smtp_starttls_auto: true
|
smtp_starttls_auto: true
|
||||||
|
|
||||||
# Credentails possibly required to log in to SMTP server if
|
# Credentials to log in to the SMTP server - may be necessary if
|
||||||
# smtp_authentication != 'none'
|
# smtp_authentication is not 'none'
|
||||||
smtp_username: 'smtp_username'
|
smtp_username: 'smtp_username'
|
||||||
smtp_password: 'secret'
|
smtp_password: 'secret'
|
||||||
|
|
||||||
# The path to the sendmail binary.
|
# The path to the sendmail binary.
|
||||||
sendmail_location: '/usr/sbin/sendmail'
|
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
|
google_a_site: false
|
||||||
|
|
||||||
#piwik integration if not set, no javascript included
|
# piwik integration - if not set, no javascript included
|
||||||
piwik_id:
|
piwik_id:
|
||||||
# the site url in raw format (e.g. pikwik.examplehost.com)
|
# the site url in raw format (e.g. pikwik.examplehost.com)
|
||||||
piwik_url:
|
piwik_url:
|
||||||
|
|
||||||
|
#
|
||||||
|
# Miscellaneous setup
|
||||||
|
#
|
||||||
|
|
||||||
#cloudfiles username and api-key, used for backups
|
# cloudfiles username and api-key - used for backups
|
||||||
cloudfiles_username: 'example'
|
cloudfiles_username: 'example'
|
||||||
cloudfiles_api_key: 'abc123'
|
cloudfiles_api_key: 'abc123'
|
||||||
invites_off: false
|
|
||||||
|
|
||||||
#list of users who have admin privilages
|
# List of users who have admin privileges
|
||||||
admins:
|
admins:
|
||||||
- 'example_user1dsioaioedfhgoiesajdigtoearogjaidofgjo'
|
- '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_key: 'key'
|
||||||
#s3_secret: 'secret'
|
#s3_secret: 'secret'
|
||||||
#s3_bucket: 'my_photos'
|
#s3_bucket: 'my_photos'
|
||||||
s3_region: 'us-east-1'
|
s3_region: 'us-east-1'
|
||||||
|
|
||||||
# If you want normal Rails logs, set this to false in the appropriate environment.
|
# Set this to true if you want to do everything synchronously instead of using resque, our redis-backed queue system.
|
||||||
# It is false by default in development and test.
|
|
||||||
enable_splunk_logging: true
|
|
||||||
|
|
||||||
# Process jobs in process?
|
|
||||||
single_process_mode: true
|
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:
|
development:
|
||||||
|
<<: *defaults
|
||||||
enable_splunk_logging: false
|
enable_splunk_logging: false
|
||||||
|
|
||||||
production:
|
production:
|
||||||
|
<<: *defaults
|
||||||
single_process_mode: false
|
single_process_mode: false
|
||||||
|
|
||||||
# Do not touch unless you know what you're doing
|
# Do not touch unless you know what you're doing
|
||||||
test:
|
test:
|
||||||
pod_url: "http://example.org/"
|
<<: *defaults
|
||||||
|
pod_url: "http://example.org"
|
||||||
socket_port: 8081
|
socket_port: 8081
|
||||||
enable_splunk_logging: false
|
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"
|
|
||||||
|
|
||||||
|
|
@ -1,14 +1,5 @@
|
||||||
# Copyright (c) 2010, Diaspora Inc. This file is
|
# Copyright (c) 2010, Diaspora Inc. This file is
|
||||||
# licensed under the Affero General Public License version 3 or later. See
|
# licensed under the Affero General Public License version 3 or later. See
|
||||||
# the COPYRIGHT file.
|
# 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')
|
require File.join(Rails.root, 'app', 'models', 'app_config')
|
||||||
|
|
||||||
AppConfig.configure_for_environment(Rails.env)
|
|
||||||
9
config/script_server_config.yml.example
Normal file
9
config/script_server_config.yml.example
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
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"
|
||||||
|
|
@ -1,107 +0,0 @@
|
||||||
# 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,15 +4,10 @@
|
||||||
# the COPYRIGHT file.
|
# the COPYRIGHT file.
|
||||||
|
|
||||||
require 'rubygems'
|
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
|
class Rails
|
||||||
def self.root
|
def self.root
|
||||||
File.join(File.dirname(__FILE__), "..")
|
File.expand_path(File.join(File.dirname(__FILE__), ".."))
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.env
|
def self.env
|
||||||
|
|
@ -23,21 +18,33 @@ class Rails
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
require File.join(Rails.root, 'lib', 'app_config')
|
|
||||||
|
|
||||||
|
|
||||||
if ARGV.length >= 1
|
if ARGV.length >= 1
|
||||||
key = ARGV[0].to_sym
|
setting_name = ARGV[0]
|
||||||
AppConfig.configure_for_environment(Rails.env)
|
if Rails.env == 'script_server' # load from the special script_server_config.yml file
|
||||||
if AppConfig.has_key?(key)
|
require 'yaml'
|
||||||
print AppConfig[key]
|
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
|
else
|
||||||
puts "Invalid option #{ARGV[0]}"
|
print AppConfig[setting_name]
|
||||||
exit 2
|
end
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
puts "Usage: ./script/get_config.rb option [section]"
|
$stderr.puts "Usage: ./script/get_config.rb option [section]"
|
||||||
puts ""
|
$stderr.puts ""
|
||||||
puts "section defaults to development"
|
$stderr.puts "section defaults to development"
|
||||||
exit 1
|
Process.exit(1)
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -137,12 +137,7 @@ if [ ! -e public/source.tar.gz ]; then
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
# Check if config files exists
|
# Check if database.yml 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
|
|
||||||
|
|
||||||
if [ ! -e 'config/database.yml' ]; then
|
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
|
echo 'FATAL: config/database.yml is missing! Copy over config/database.yml.example to config/database.yml and edit it properly!' >&2
|
||||||
exit 68
|
exit 68
|
||||||
|
|
|
||||||
|
|
@ -1,18 +0,0 @@
|
||||||
# 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
|
|
||||||
AppConfig[:pod_url].should == 'http://example.org/'
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
describe 'terse_pod_url'
|
|
||||||
it 'should be correctly parsed' do
|
|
||||||
AppConfig[:pod_uri].host.should == 'example.org'
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
@ -127,4 +127,3 @@ script_server:
|
||||||
|
|
||||||
# Possibilties are development, production
|
# Possibilties are development, production
|
||||||
rails_env: "development"
|
rails_env: "development"
|
||||||
|
|
||||||
|
|
@ -1,79 +0,0 @@
|
||||||
# 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 AppConfig do
|
|
||||||
before do
|
|
||||||
@environment_vars = AppConfig.config_vars
|
|
||||||
AppConfig.config_vars = {}
|
|
||||||
end
|
|
||||||
after do
|
|
||||||
AppConfig.config_vars = @environment_vars
|
|
||||||
end
|
|
||||||
describe ".base_file_path" do
|
|
||||||
it "allows you to set the base file path" do
|
|
||||||
AppConfig.base_file_path = "foo"
|
|
||||||
AppConfig.base_file_path.should == "foo"
|
|
||||||
end
|
|
||||||
it "defaults to config/app_base.yml" do
|
|
||||||
AppConfig.base_file_path = nil
|
|
||||||
AppConfig.base_file_path.should == "#{Rails.root}/config/app_base.yml"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
describe ".load_config_for_environment" do
|
|
||||||
before do
|
|
||||||
@original_stderr = $stderr
|
|
||||||
$stderr = StringIO.new
|
|
||||||
end
|
|
||||||
after do
|
|
||||||
$stderr = @original_stderr
|
|
||||||
end
|
|
||||||
it "prints error if base file is missing" do
|
|
||||||
AppConfig.base_file_path = "/no/such/file"
|
|
||||||
AppConfig.file_path = File.join(Rails.root, "config", "app_base.yml")
|
|
||||||
|
|
||||||
AppConfig.load_config_for_environment(:test)
|
|
||||||
$stderr.rewind
|
|
||||||
$stderr.string.chomp.should_not be_blank
|
|
||||||
end
|
|
||||||
it "prints error and exits if there's no config at all" do
|
|
||||||
AppConfig.base_file_path = "/no/such/file"
|
|
||||||
AppConfig.file_path = "/no/such/file"
|
|
||||||
|
|
||||||
lambda {
|
|
||||||
AppConfig.load_config_for_environment(:test)
|
|
||||||
}.should raise_error SystemExit
|
|
||||||
|
|
||||||
$stderr.rewind
|
|
||||||
$stderr.string.chomp.should_not be_blank
|
|
||||||
end
|
|
||||||
end
|
|
||||||
describe ".generate_pod_uri" do
|
|
||||||
describe "when pod_url is prefixed with protocol" do
|
|
||||||
it "generates a URI with a host for http" do
|
|
||||||
AppConfig[:pod_url] = "http://oscar.joindiaspora.com"
|
|
||||||
AppConfig.generate_pod_uri
|
|
||||||
AppConfig[:pod_uri].host.should == "oscar.joindiaspora.com"
|
|
||||||
end
|
|
||||||
it "generates a URI with a host for https" do
|
|
||||||
AppConfig[:pod_url] = "https://oscar.joindiaspora.com"
|
|
||||||
AppConfig.generate_pod_uri
|
|
||||||
AppConfig[:pod_uri].host.should == "oscar.joindiaspora.com"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
describe "when pod_url is not prefixed with protocol" do
|
|
||||||
it "generates a URI with a host" do
|
|
||||||
AppConfig[:pod_url] = "oscar.joindiaspora.com"
|
|
||||||
AppConfig.generate_pod_uri
|
|
||||||
AppConfig[:pod_uri].host.should == "oscar.joindiaspora.com"
|
|
||||||
end
|
|
||||||
it "adds http:// to the front of the pod_url" do
|
|
||||||
AppConfig[:pod_url] = "oscar.joindiaspora.com"
|
|
||||||
AppConfig.generate_pod_uri
|
|
||||||
AppConfig[:pod_url].should == "http://oscar.joindiaspora.com"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
155
spec/models/app_config_spec.rb
Normal file
155
spec/models/app_config_spec.rb
Normal file
|
|
@ -0,0 +1,155 @@
|
||||||
|
# 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 AppConfig do
|
||||||
|
|
||||||
|
after do
|
||||||
|
AppConfig.reload!
|
||||||
|
end
|
||||||
|
|
||||||
|
describe ".load!" do
|
||||||
|
context "error conditions" do
|
||||||
|
before do
|
||||||
|
@original_stderr = $stderr
|
||||||
|
$stderr = StringIO.new
|
||||||
|
end
|
||||||
|
after do
|
||||||
|
$stderr = @original_stderr
|
||||||
|
end
|
||||||
|
|
||||||
|
context "with old-style application.yml" do
|
||||||
|
before do
|
||||||
|
@original_source = AppConfig.source
|
||||||
|
AppConfig.source(File.join(Rails.root, "spec", "fixtures", "config", "old_style_app.yml"))
|
||||||
|
end
|
||||||
|
after do
|
||||||
|
AppConfig.source(@original_source)
|
||||||
|
end
|
||||||
|
it "prints an error message and exits" do
|
||||||
|
expect {
|
||||||
|
AppConfig.load!
|
||||||
|
}.should raise_error SystemExit
|
||||||
|
|
||||||
|
$stderr.rewind
|
||||||
|
$stderr.string.chomp.should_not be_blank
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "when source config file (i.e. config/application.yml) does not exist" do
|
||||||
|
before do
|
||||||
|
application_yml = File.join(Rails.root, "config", "application.yml")
|
||||||
|
@app_yml = File.join(Rails.root, "config", "app.yml")
|
||||||
|
@app_config_yml = File.join(Rails.root, "config", "app_config.yml")
|
||||||
|
File.should_receive(:exists?).with(application_yml).at_least(:once).and_return(false)
|
||||||
|
end
|
||||||
|
after do
|
||||||
|
File.instance_eval { alias :exists? :obfuscated_by_rspec_mocks__exists? } # unmock exists? so that the AppConfig.reload! in the top-level after block can run
|
||||||
|
end
|
||||||
|
context "and there are no old-style config files around" do
|
||||||
|
it "prints an error message with instructions for setting up application.yml and exits" do
|
||||||
|
File.should_receive(:exists?).with(@app_yml).at_least(:once).and_return(false)
|
||||||
|
File.should_receive(:exists?).with(@app_config_yml).at_least(:once).and_return(false)
|
||||||
|
|
||||||
|
expect {
|
||||||
|
AppConfig.load!
|
||||||
|
}.should raise_error SystemExit
|
||||||
|
|
||||||
|
$stderr.rewind
|
||||||
|
$stderr.string.should include("haven't set up")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
context "and there is an old-style app.yml" do
|
||||||
|
it "prints an error message with instructions for converting an old-style file and exits" do
|
||||||
|
File.should_receive(:exists?).with(@app_yml).at_least(:once).and_return(true)
|
||||||
|
|
||||||
|
expect {
|
||||||
|
AppConfig.load!
|
||||||
|
}.should raise_error SystemExit
|
||||||
|
|
||||||
|
$stderr.rewind
|
||||||
|
$stderr.string.should include("file format has changed")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
context "and there is an old-style app_config.yml" do
|
||||||
|
it "prints an error message with instructions for converting an old-style file and exits" do
|
||||||
|
File.should_receive(:exists?).with(@app_yml).at_least(:once).and_return(false)
|
||||||
|
File.should_receive(:exists?).with(@app_config_yml).at_least(:once).and_return(true)
|
||||||
|
|
||||||
|
expect {
|
||||||
|
AppConfig.load!
|
||||||
|
}.should raise_error SystemExit
|
||||||
|
|
||||||
|
$stderr.rewind
|
||||||
|
$stderr.string.should include("file format has changed")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
it "calls normalize_pod_url" do
|
||||||
|
AppConfig.should_receive(:normalize_pod_url).twice # apparently should_receive counts stuff in after blocks...WTF?
|
||||||
|
AppConfig.load!
|
||||||
|
end
|
||||||
|
it "calls normalize_admins" do
|
||||||
|
AppConfig.should_receive(:normalize_admins).twice
|
||||||
|
AppConfig.load!
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe ".normalize_admins" do
|
||||||
|
it "downcases the user names that are set as admins" do
|
||||||
|
AppConfig[:admins] = ["UPPERCASE", "MiXeDCaSe", "lowercase"]
|
||||||
|
AppConfig.normalize_admins
|
||||||
|
AppConfig[:admins].should == ["uppercase", "mixedcase", "lowercase"]
|
||||||
|
end
|
||||||
|
it "sets admins to an empty array if no admins were specified" do
|
||||||
|
AppConfig[:admins] = nil
|
||||||
|
AppConfig.normalize_admins
|
||||||
|
AppConfig[:admins].should == []
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe ".normalize_pod_url" do
|
||||||
|
it "adds a trailing slash if there isn't one" do
|
||||||
|
AppConfig[:pod_url] = "http://example.org"
|
||||||
|
AppConfig.normalize_pod_url
|
||||||
|
AppConfig[:pod_url].should == "http://example.org/"
|
||||||
|
end
|
||||||
|
it "does not add an extra trailing slash" do
|
||||||
|
AppConfig[:pod_url] = "http://example.org/"
|
||||||
|
AppConfig.normalize_pod_url
|
||||||
|
AppConfig[:pod_url].should == "http://example.org/"
|
||||||
|
end
|
||||||
|
it "adds http:// on the front if it's missing" do
|
||||||
|
AppConfig[:pod_url] = "example.org/"
|
||||||
|
AppConfig.normalize_pod_url
|
||||||
|
AppConfig[:pod_url].should == "http://example.org/"
|
||||||
|
end
|
||||||
|
it "does not add a prefix if there already is http:// on the front" do
|
||||||
|
AppConfig[:pod_url] = "http://example.org/"
|
||||||
|
AppConfig.normalize_pod_url
|
||||||
|
AppConfig[:pod_url].should == "http://example.org/"
|
||||||
|
end
|
||||||
|
it "does not add a prefix if there already is https:// on the front" do
|
||||||
|
AppConfig[:pod_url] = "https://example.org/"
|
||||||
|
AppConfig.normalize_pod_url
|
||||||
|
AppConfig[:pod_url].should == "https://example.org/"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe ".pod_uri" do
|
||||||
|
it "properly parses the pod_url" do
|
||||||
|
pod_uri = AppConfig[:pod_uri]
|
||||||
|
pod_uri.scheme.should == "http"
|
||||||
|
pod_uri.host.should == "example.org"
|
||||||
|
end
|
||||||
|
it "clears the cached pod_uri when you set pod_url" do
|
||||||
|
AppConfig[:pod_uri].host.should == "example.org"
|
||||||
|
AppConfig[:pod_url] = "http://joindiaspora.com"
|
||||||
|
AppConfig[:pod_uri].host.should == "joindiaspora.com"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
Loading…
Reference in a new issue