Add 'sdk/java-v2/' from commit '55f103e336ca9fb8bf1720d2ef4ee8dd4e221118'
[arvados.git] / apps / workbench / config / load_config.rb
1 # Copyright (C) The Arvados Authors. All rights reserved.
2 #
3 # SPDX-License-Identifier: AGPL-3.0
4
5 # This file must be loaded _after_ secret_token.rb if secret_token is
6 # defined there instead of in config/application.yml.
7
8 $application_config = {}
9
10 %w(application.default application).each do |cfgfile|
11   path = "#{::Rails.root.to_s}/config/#{cfgfile}.yml"
12   if File.exists? path
13     yaml = ERB.new(IO.read path).result(binding)
14     confs = YAML.load(yaml, deserialize_symbols: true)
15     $application_config.merge!(confs['common'] || {})
16     $application_config.merge!(confs[::Rails.env.to_s] || {})
17   end
18 end
19
20 ArvadosWorkbench::Application.configure do
21   nils = []
22   $application_config.each do |k, v|
23     # "foo.bar: baz" --> { config.foo.bar = baz }
24     cfg = config
25     ks = k.split '.'
26     k = ks.pop
27     ks.each do |kk|
28       cfg = cfg.send(kk)
29     end
30     if v.nil? and cfg.respond_to?(k) and !cfg.send(k).nil?
31       # Config is nil in *.yml, but has been set already in
32       # environments/*.rb (or has a Rails default). Don't overwrite
33       # the default/upstream config with nil.
34       #
35       # After config files have been migrated, this mechanism should
36       # be removed.
37       Rails.logger.warn <<EOS
38 DEPRECATED: Inheriting config.#{ks.join '.'} from Rails config.
39             Please move this config into config/application.yml.
40 EOS
41     elsif v.nil?
42       # Config variables are not allowed to be nil. Make a "naughty"
43       # list, and present it below.
44       nils << k
45     else
46       cfg.send "#{k}=", v
47     end
48   end
49   if !nils.empty? and not ::Rails.groups.include?('assets')
50     raise <<EOS
51 #{::Rails.groups.include?('assets')}
52 Refusing to start in #{::Rails.env.to_s} mode with missing configuration.
53
54 The following configuration settings must be specified in
55 config/application.yml:
56 * #{nils.join "\n* "}
57
58 EOS
59   end
60   # Refuse to start if keep-web isn't configured
61   if not (config.keep_web_url or config.keep_web_download_url) and not ::Rails.groups.include?('assets')
62     raise <<EOS
63 Refusing to start in #{::Rails.env.to_s} mode with missing configuration.
64
65 Keep-web service must be configured in config/application.yml:
66 * keep_web_url
67 * keep_web_download_url
68
69 EOS
70   end
71 end