load_config.rb 1.71 KB
Newer Older
1 2
# frozen_string_literal: true

3 4 5
require "pathname"
require "bundler/setup"
require "configurate"
Jonne Haß's avatar
Jonne Haß committed
6

7
rails_env = ENV["RAILS_ENV"] || ENV["RACK_ENV"] || "development"
8

9 10
module Rails
  def self.root
11
    @__root ||= Pathname.new File.expand_path("../../", __FILE__)
12 13
  end
end
14

15
require Rails.root.join "lib", "configuration_methods"
Jonne Haß's avatar
Jonne Haß committed
16

17
config_dir = Rails.root.join("config").to_s
Jonne Haß's avatar
Jonne Haß committed
18

19 20 21
AppConfig ||= Configurate::Settings.create do
  add_provider Configurate::Provider::Dynamic
  add_provider Configurate::Provider::Env
22 23 24 25

  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."
Jonne Haß's avatar
Jonne Haß committed
26
    exit!
Jonne Haß's avatar
Jonne Haß committed
27
  end
28

29
  add_provider Configurate::Provider::YAML,
30
               File.join(config_dir, "diaspora.yml"),
31
               namespace: rails_env, required: false
32
  add_provider Configurate::Provider::YAML,
33
               File.join(config_dir, "diaspora.yml"),
Jonne Haß's avatar
Jonne Haß committed
34
               namespace: "configuration", required: false
35
  add_provider Configurate::Provider::YAML,
36
               File.join(config_dir, "defaults.yml"),
37
               namespace: rails_env
38
  add_provider Configurate::Provider::YAML,
39 40
               File.join(config_dir, "defaults.yml"),
               namespace: "defaults", raise_on_missing: true
41

Jonne Haß's avatar
Jonne Haß committed
42
  extend Configuration::Methods
43

Jonne Haß's avatar
Jonne Haß committed
44
  if rails_env == "production"  &&
45
     (environment.certificate_authorities.nil? ||
46 47
     environment.certificate_authorities.empty? ||
     !File.file?(environment.certificate_authorities.get))
48 49
    warn "FATAL: Diaspora doesn't know where your certificate authorities are." \
         " Please ensure they are set to a valid path in diaspora.yml"
Jonne Haß's avatar
Jonne Haß committed
50
    exit!
Jonne Haß's avatar
Jonne Haß committed
51 52
  end
end