Commit 08395cc8 authored by Jonne Haß's avatar Jonne Haß
Browse files

Migrate configuration to TOML

YAML is just too easy to get wrong

closes #8132
parent 9dff9642
......@@ -9,6 +9,7 @@ app/views/terms/terms.*
app/assets/images/custom/
# Configuration files
config/diaspora.toml
config/diaspora.yml
config/initializers/secret_token.rb
.bundle
......
......@@ -5,6 +5,7 @@
## Bug fixes
## Features
* Support and recommend TOML as configuration format [#8132](https://github.com/diaspora/diaspora/pull/8132)
# 0.7.14.0
......
......@@ -50,7 +50,8 @@ gem "uglifier", "4.2.0"
# Configuration
gem "configurate", "0.3.1"
gem "configurate", "0.4.0"
gem "tomlrb", "1.3.0"
# Cross-origin resource sharing
......
......@@ -132,7 +132,7 @@ GEM
sass-rails (< 5.1)
sprockets (< 4.0)
concurrent-ruby (1.1.6)
configurate (0.3.1)
configurate (0.4.0)
connection_pool (2.2.2)
coveralls (0.8.23)
json (>= 1.8, < 3)
......@@ -733,6 +733,7 @@ GEM
tins (1.24.1)
sync
to_regexp (0.2.1)
tomlrb (1.3.0)
turbo_dev_assets (0.0.2)
twitter (7.0.0)
addressable (~> 2.3)
......@@ -809,7 +810,7 @@ DEPENDENCIES
capybara (= 3.15.0)
carrierwave (= 1.3.1)
compass-rails (= 3.1.0)
configurate (= 0.3.1)
configurate (= 0.4.0)
coveralls (= 0.8.23)
cucumber-api-steps (= 0.14)
cucumber-rails (= 2.0.0)
......@@ -928,6 +929,7 @@ DEPENDENCIES
sprockets-rails (= 3.2.1)
string-direction (= 1.2.2)
timecop (= 0.9.1)
tomlrb (= 1.3.0)
turbo_dev_assets (= 0.0.2)
twitter (= 7.0.0)
twitter-text (= 1.14.7)
......
(function() {
app.helpers.locations = {
getTiles: function() {
// If the mapbox option is enabled in the diaspora.yml, the mapbox tiles with the podmin's credentials are used.
// If the mapbox option is enabled in the diaspora.toml, the mapbox tiles with the podmin's credentials are used.
if (gon.appConfig.map.mapbox.enabled) {
return L.tileLayer("https://api.mapbox.com/styles/v1/{style}/tiles/256/{z}/{x}/{y}?access_token={accessToken}", {
accessToken: gon.appConfig.map.mapbox.access_token,
......
......@@ -15,7 +15,7 @@
= t(".configure_your_pod")
!= t(".configuration_info",
database_path: content_tag(:code, "config/database.yml"),
diaspora_path: content_tag(:code, "config/diaspora.yml"))
diaspora_path: content_tag(:code, "config/diaspora.toml"))
.col-md-4
.landing-info-card
......
......@@ -5,22 +5,31 @@ require "yaml"
module BundlerHelper
def self.rails_env
@rails_env ||= ENV["RAILS_ENV"] ||
parse_value_from_file("diaspora.yml", "configuration", "server", "rails_environment") ||
parse_value_from_file("defaults.yml", "defaults", "server", "rails_environment")
parse_value_from_toml_file("diaspora.toml", "rails_environment") ||
parse_value_from_yaml_file("diaspora.yml", "configuration", "server", "rails_environment") ||
parse_value_from_yaml_file("defaults.yml", "defaults", "server", "rails_environment")
end
def self.database
@adapter ||= parse_value_from_file("database.yml", rails_env, "adapter")
@adapter ||= parse_value_from_yaml_file("database.yml", rails_env, "adapter")
raise "No database adapter found, please fix your config/database.yml!" unless @adapter
abort "No database adapter found, please fix your config/database.yml!" unless @adapter
@adapter.sub("mysql2", "mysql")
end
private_class_method def self.parse_value_from_file(file, *keys)
private_class_method def self.parse_value_from_yaml_file(file, *keys)
path = File.join(__dir__, file)
YAML.load_file(path).dig(*keys) if File.file?(path)
end
private_class_method def self.parse_value_from_toml_file(file, key)
path = File.join(__dir__, file)
return YAML.load_file(path).dig(*keys) if File.file?(path)
puts "Configuration file #{path} not found, ensure it's present" # rubocop:disable Rails/Output
if File.file?(path)
File.read(path)[/^\s*#{Regexp.escape(key)}\s*=\s*["']([^"']+)["']\s*$/, 1]
elsif !File.file? File.join(__dir__, "diaspora.yml")
warn "WARNING: Configuration file #{path} not found, ensure it's present" # rubocop:disable Rails/Output
end
end
end
This diff is collapsed.
This diff is collapsed.
......@@ -31,7 +31,7 @@ Devise.setup do |config|
Rails.logger.warn("No smtp sender address set, mail may fail.")
warn "WARNING: No smtp sender address set, mail may fail."
end
config.mailer_sender = "please-change-me@config-diaspora-yml.com"
config.mailer_sender = "please-change-me@config-diaspora-toml.com"
end
# Configure the class responsible to send e-mails.
......
......@@ -6,9 +6,9 @@ require 'sidekiq/middleware/i18n'
# Single process-mode
if AppConfig.environment.single_process_mode? && Rails.env != "test"
if Rails.env == 'production'
puts "WARNING: You are running Diaspora in production without Sidekiq"
puts " workers turned on. Please set single_process_mode to false in"
puts " config/diaspora.yml."
warn "WARNING: You are running Diaspora in production without Sidekiq"
warn " workers turned on. Please set single_process_mode to false in"
warn " config/diaspora.toml."
end
require 'sidekiq/testing/inline'
end
......
......@@ -3,6 +3,7 @@
require "pathname"
require "bundler/setup"
require "configurate"
require "configurate/provider/toml"
rails_env = ENV["RAILS_ENV"] || ENV["RACK_ENV"] || "development"
......@@ -20,18 +21,35 @@ AppConfig ||= Configurate::Settings.create do
add_provider Configurate::Provider::Dynamic
add_provider Configurate::Provider::Env
unless heroku? || rails_env == "test" || File.exist?(File.join(config_dir, "diaspora.yml"))
warn "FATAL: Configuration not found. Copy over diaspora.yml.example"
warn " to diaspora.yml and edit it to your needs."
unless heroku? ||
rails_env == "test" ||
File.exist?(File.join(config_dir, "diaspora.toml")) ||
File.exist?(File.join(config_dir, "diaspora.yml"))
warn "FATAL: Configuration not found. Copy over diaspora.toml.example"
warn " to diaspora.toml and edit it to your needs."
exit!
end
add_provider Configurate::Provider::YAML,
File.join(config_dir, "diaspora.yml"),
namespace: rails_env, required: false
add_provider Configurate::Provider::YAML,
File.join(config_dir, "diaspora.yml"),
namespace: "configuration", required: false
if File.exist?(File.join(config_dir, "diaspora.toml"))
if File.exist?(File.join(config_dir, "diaspora.yml"))
warn "WARNING: diaspora.toml found, ignoring diaspora.yml. Move or delete diaspora.yml to remove this warning."
end
add_provider Configurate::Provider::TOML,
File.join(config_dir, "diaspora.toml"),
namespace: rails_env, required: false
add_provider Configurate::Provider::TOML,
File.join(config_dir, "diaspora.toml"),
namespace: "configuration", required: false
else
add_provider Configurate::Provider::YAML,
File.join(config_dir, "diaspora.yml"),
namespace: rails_env, required: false
add_provider Configurate::Provider::YAML,
File.join(config_dir, "diaspora.yml"),
namespace: "configuration", required: false
end
add_provider Configurate::Provider::YAML,
File.join(config_dir, "defaults.yml"),
namespace: rails_env
......
......@@ -86,7 +86,7 @@ Logging::Rails.configure do |config|
# Default log-level (development=debug, production=info)
Logging.logger.root.level = config.log_level
# log-levels from the diaspora.yml for SQL and federation debug-logging
# log-levels from the diaspora.toml for SQL and federation debug-logging
Logging.logger[ActionView::Base].level = Rails.env.development? ? :debug : :warn
Logging.logger[ActiveRecord::Base].level = AppConfig.environment.logging.debug.sql? ? :debug : :info
Logging.logger[DiasporaFederation::Salmon::MagicEnvelope].level =
......
......@@ -257,7 +257,7 @@ dia_config() {
if [ ! -z $dia_config_delete ]; then
rm "$DIASPORA_CONFIG_DIA" "$DIASPORA_CONFIG_DB"
fi
# Create new diaspora.yml if none exists
# Create new diaspora.toml if none exists
if [ ! -f "$DIASPORA_CONFIG_DIA" ]; then
cp "$DIASPORA_CONFIG_DIA".example "$DIASPORA_CONFIG_DIA"
fi
......@@ -477,7 +477,7 @@ export SCRIPT_ROOT=$(cd $(dirname "${BASH_SOURCE[0]}") && pwd)
export DIASPORA_ROOT=$(dirname "$SCRIPT_ROOT")
export DIASPORA_ROOT_UID=1001
export DIASPORA_ROOT_GID=1001
export DIASPORA_CONFIG_DIA=$DIASPORA_ROOT/config/diaspora.yml
export DIASPORA_CONFIG_DIA=$DIASPORA_ROOT/config/diaspora.toml
export DIASPORA_CONFIG_DB=$DIASPORA_ROOT/config/database.yml
export DIASPORA_DOCKER_DB=$(dia_get_db)
......
......@@ -55,10 +55,15 @@ then
fatal "config/database.yml is missing! Copy over config/database.yml.example to config/database.yml and edit it properly!"
fi
# Check if diaspora.yml exists
if [ ! -e "config/diaspora.yml" ]
# Check if diaspora.toml exists
if [ -e "config/diaspora.toml" ]
then
fatal "config/diaspora.yml is missing! Copy over config/diaspora.yml.example to config/diaspora.yml and edit it properly!"
CONFIG_FILE="config/diaspora.toml"
elif [ -e "config/diaspora.yml" ]
then
CONFIG_FILE="config/diaspora.yml"
else
fatal "config/diaspora.toml is missing! Copy over config/diaspora.toml.example to config/diaspora.toml and edit it properly!"
fi
command -v git > /dev/null 2>&1
......@@ -100,7 +105,7 @@ fi
if [ -z "$RAILS_ENV" ]
then
RAILS_ENV=$(bin/bundle exec ruby ./script/get_config.rb server.rails_environment | grep -vE "is not writable|as your home directory temporarily" )
on_failure "Couldn't parse config/diaspora.yml!"
on_failure "Couldn't parse $CONFIG_FILE!"
export RAILS_ENV
fi
......@@ -116,7 +121,7 @@ vars=$(bin/bundle exec ruby ./script/get_config.rb \
redis_url=environment.redis \
| grep -vE "is not writable|as your home directory temporarily"
)
on_failure "Couldn't parse config/diaspora.yml!"
on_failure "Couldn't parse $CONFIG_FILE!"
eval "$vars"
args="$@"
......@@ -170,10 +175,10 @@ then
if [ -n "$redis_url" ]
then
redis_param="url: '$redis_url'"
fi
fi
if [ "$(bin/bundle exec ruby -e "require 'redis'; puts Redis.new($redis_param).ping" 2> /dev/null | grep -vE "is not writable|as your home directory temporarily" )" != "PONG" ]
then
fatal "Can't connect to redis. Please check if it's running and if environment.redis is configured correctly in config/diaspora.yml."
fatal "Can't connect to redis. Please check if it's running and if environment.redis is configured correctly in $CONFIG_FILE."
fi
fi
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment