Welcome to mirror list, hosted at ThFree Co, Russian Federation.

load_config.rb « config - github.com/diaspora/diaspora.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: f5d5757aa0fbaadf0d3e07f51c5d0348bd99cef8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# frozen_string_literal: true

require "pathname"
require "bundler/setup"
require "configurate"
require "configurate/provider/toml"

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

module Rails
  def self.root
    @__root ||= Pathname.new File.expand_path("../../", __FILE__)
  end
end

require Rails.root.join "lib", "configuration_methods"

config_dir = Rails.root.join("config").to_s

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.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

  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
    warn "WARNING: diaspora.yml is deprecated and will no longer be read in diaspora 2.0."
    warn "         Please copy over diaspora.toml.example to diaspora.toml and migrate your settings from diaspora.yml."

    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
  add_provider Configurate::Provider::YAML,
               File.join(config_dir, "defaults.yml"),
               namespace: "defaults", raise_on_missing: true

  extend Configuration::Methods

  if rails_env == "production"  &&
     (environment.certificate_authorities.nil? ||
     environment.certificate_authorities.empty? ||
     !File.file?(environment.certificate_authorities.get))
    warn "FATAL: Diaspora doesn't know where your certificate authorities are." \
         " Please ensure they are set to a valid path in diaspora.yml"
    exit!
  end
end