1 # Copyright (C) The Arvados Authors. All rights reserved.
3 # SPDX-License-Identifier: AGPL-3.0
6 # Load Arvados configuration from /etc/arvados/config.yml, using defaults
7 # from config.default.yml
9 # Existing application.yml is migrated into the new config structure.
10 # Keys in the legacy application.yml take precedence.
12 # Use "bundle exec config:dump" to get the complete active configuration
14 # Use "bundle exec config:migrate" to migrate application.yml to
15 # config.yml. After adding the output of config:migrate to
16 # /etc/arvados/config.yml, you will be able to delete application.yml.
18 require 'config_loader'
21 # If secret_token.rb exists here, we need to load it first.
22 require_relative 'secret_token.rb'
24 # Normally secret_token.rb is missing and the secret token is
25 # configured by application.yml (i.e., here!) instead.
29 $arvados_config_defaults = ConfigLoader.load "#{::Rails.root.to_s}/config/config.default.yml"
30 if $arvados_config_defaults.empty?
31 raise "Missing #{::Rails.root.to_s}/config/config.default.yml"
34 def remove_sample_entries(h)
35 return unless h.is_a? Hash
37 h.each { |k, v| remove_sample_entries(v) }
39 remove_sample_entries($arvados_config_defaults)
41 clusterID, clusterConfig = $arvados_config_defaults["Clusters"].first
42 $arvados_config_defaults = clusterConfig
43 $arvados_config_defaults["ClusterID"] = clusterID
45 # Initialize the global config with the defaults
46 $arvados_config_global = $arvados_config_defaults.deep_dup
48 # Load the global config file
49 confs = ConfigLoader.load "/etc/arvados/config.yml"
51 clusterID, clusterConfig = confs["Clusters"].first
52 $arvados_config_global["ClusterID"] = clusterID
54 # Copy the cluster config over the defaults
55 $arvados_config_global.deep_merge!(clusterConfig)
59 $arvados_config = $arvados_config_global.deep_dup
61 # Declare all our configuration items.
62 arvcfg = ConfigLoader.new
64 arvcfg.declare_config "ManagementToken", String, :ManagementToken
65 arvcfg.declare_config "TLS.Insecure", Boolean, :arvados_insecure_https
67 arvcfg.declare_config "Services.Controller.ExternalURL", URI, :arvados_v1_base, ->(cfg, k, v) {
70 ConfigLoader.set_cfg cfg, "Services.Controller.ExternalURL", u
73 arvcfg.declare_config "Services.WebShell.ExternalURL", URI, :shell_in_a_box_url, ->(cfg, k, v) {
75 u = URI(v.sub("%{hostname}", "*"))
77 ConfigLoader.set_cfg cfg, "Services.WebShell.ExternalURL", u
80 arvcfg.declare_config "Services.WebDAV.ExternalURL", URI, :keep_web_service_url, ->(cfg, k, v) {
82 u = URI(v.sub("%{uuid_or_pdh}", "*"))
84 ConfigLoader.set_cfg cfg, "Services.WebDAV.ExternalURL", u
87 arvcfg.declare_config "Services.WebDAVDownload.ExternalURL", URI, :keep_web_download_url, ->(cfg, k, v) {
89 u = URI(v.sub("%{uuid_or_pdh}", "*"))
91 ConfigLoader.set_cfg cfg, "Services.WebDAVDownload.ExternalURL", u
94 arvcfg.declare_config "Services.Composer.ExternalURL", URI, :composer_url
95 arvcfg.declare_config "Services.Workbench2.ExternalURL", URI, :workbench2_url
97 arvcfg.declare_config "Workbench.ApplicationMimetypesWithViewIcon", Hash, :application_mimetypes_with_view_icon, ->(cfg, k, v) {
102 ConfigLoader.set_cfg cfg, "Workbench.ApplicationMimetypesWithViewIcon", mimetypes
105 arvcfg.declare_config "Users.AnonymousUserToken", String, :anonymous_user_token
108 application_config = {}
109 %w(application.default application).each do |cfgfile|
110 path = "#{::Rails.root.to_s}/config/#{cfgfile}.yml"
111 confs = ConfigLoader.load(path, erb: true)
112 # Ignore empty YAML file:
113 next if confs == false
114 application_config.deep_merge!(confs['common'] || {})
115 application_config.deep_merge!(confs[::Rails.env.to_s] || {})
118 $remaining_config = arvcfg.migrate_config(application_config, $arvados_config)
120 # Checks for wrongly typed configuration items, coerces properties
121 # into correct types (such as Duration), and optionally raise error
122 # for essential configuration that can't be empty.
123 arvcfg.coercion_and_check $arvados_config_defaults, check_nonempty: false
124 arvcfg.coercion_and_check $arvados_config_global, check_nonempty: false
125 arvcfg.coercion_and_check $arvados_config, check_nonempty: true
127 # * $arvados_config_defaults is the defaults
128 # * $arvados_config_global is $arvados_config_defaults merged with the contents of /etc/arvados/config.yml
129 # These are used by the rake config: tasks
131 # * $arvados_config is $arvados_config_global merged with the migrated contents of application.yml
132 # This is what actually gets copied into the Rails configuration object.
134 ArvadosWorkbench::Application.configure do
135 # Copy into the Rails config object. This also turns Hash into
136 # OrderedOptions so that application code can use
137 # Rails.configuration.API.Blah instead of
138 # Rails.configuration.API["Blah"]
139 ConfigLoader.copy_into_config $arvados_config, config
140 ConfigLoader.copy_into_config $remaining_config, config
141 secrets.secret_key_base = $arvados_config["Workbench"]["SecretToken"]