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'
19 require 'config_validators'
22 # Load the defaults, used by config:migrate and fallback loading
23 # legacy application.yml
24 defaultYAML, stderr, status = Open3.capture3("arvados-server", "config-dump", "-config=-", "-skip-legacy", stdin_data: "Clusters: {xxxxx: {}}")
27 raise "error loading config: #{status}"
29 confs = YAML.load(defaultYAML, deserialize_symbols: false)
30 clusterID, clusterConfig = confs["Clusters"].first
31 $arvados_config_defaults = clusterConfig
32 $arvados_config_defaults["ClusterID"] = clusterID
34 if ENV["ARVADOS_CONFIG"] == "none"
35 # Don't load config. This magic value is set by packaging scripts so
36 # they can run "rake assets:precompile" without a real config.
37 $arvados_config_global = $arvados_config_defaults.deep_dup
39 # Load the global config file
40 Open3.popen2("arvados-server", "config-dump", "-skip-legacy") do |stdin, stdout, status_thread|
41 confs = YAML.load(stdout, deserialize_symbols: false)
42 if confs && !confs.empty?
43 # config-dump merges defaults with user configuration, so every
45 clusterID, clusterConfig = confs["Clusters"].first
46 $arvados_config_global = clusterConfig
47 $arvados_config_global["ClusterID"] = clusterID
49 # config-dump failed, assume we will be loading from legacy
50 # application.yml, initialize with defaults.
51 $arvados_config_global = $arvados_config_defaults.deep_dup
57 $arvados_config = $arvados_config_global.deep_dup
59 # Declare all our configuration items.
60 arvcfg = ConfigLoader.new
62 arvcfg.declare_config "ManagementToken", String, :ManagementToken
63 arvcfg.declare_config "TLS.Insecure", Boolean, :arvados_insecure_https
64 arvcfg.declare_config "Collections.TrustAllContent", Boolean, :trust_all_content
66 arvcfg.declare_config "Services.Controller.ExternalURL", URI, :arvados_v1_base, ->(cfg, k, v) {
69 ConfigLoader.set_cfg cfg, "Services.Controller.ExternalURL", u
72 arvcfg.declare_config "Services.WebShell.ExternalURL", URI, :shell_in_a_box_url, ->(cfg, k, v) {
74 u = URI(v.sub("%{hostname}", "*"))
76 ConfigLoader.set_cfg cfg, "Services.WebShell.ExternalURL", u
79 arvcfg.declare_config "Services.WebDAV.ExternalURL", URI, :keep_web_url, ->(cfg, k, v) {
81 u = URI(v.sub("%{uuid_or_pdh}", "*"))
83 ConfigLoader.set_cfg cfg, "Services.WebDAV.ExternalURL", u
86 arvcfg.declare_config "Services.WebDAVDownload.ExternalURL", URI, :keep_web_download_url, ->(cfg, k, v) {
88 u = URI(v.sub("%{uuid_or_pdh}", "*"))
90 ConfigLoader.set_cfg cfg, "Services.WebDAVDownload.ExternalURL", u
93 arvcfg.declare_config "Services.Composer.ExternalURL", URI, :composer_url
94 arvcfg.declare_config "Services.Workbench2.ExternalURL", URI, :workbench2_url
96 arvcfg.declare_config "Users.AnonymousUserToken", String, :anonymous_user_token
98 arvcfg.declare_config "Workbench.SecretKeyBase", String, :secret_key_base
100 arvcfg.declare_config "Workbench.ApplicationMimetypesWithViewIcon", Hash, :application_mimetypes_with_view_icon, ->(cfg, k, v) {
105 ConfigLoader.set_cfg cfg, "Workbench.ApplicationMimetypesWithViewIcon", mimetypes
108 arvcfg.declare_config "Workbench.RunningJobLogRecordsToFetch", Integer, :running_job_log_records_to_fetch
109 arvcfg.declare_config "Workbench.LogViewerMaxBytes", Integer, :log_viewer_max_bytes
110 arvcfg.declare_config "Workbench.ProfilingEnabled", Boolean, :profiling_enabled
111 arvcfg.declare_config "Workbench.APIResponseCompression", Boolean, :api_response_compression
112 arvcfg.declare_config "Workbench.UserProfileFormFields", Hash, :user_profile_form_fields, ->(cfg, k, v) {
117 v.each_with_index do |s,i|
118 entries[s["key"]] = {
120 "FormFieldTitle" => s["form_field_title"],
121 "FormFieldDescription" => s["form_field_description"],
122 "Required" => s["required"],
126 entries[s["key"]]["Options"] = {}
127 s["options"].each do |o|
128 entries[s["key"]]["Options"][o] = {}
132 ConfigLoader.set_cfg cfg, "Workbench.UserProfileFormFields", entries
134 arvcfg.declare_config "Workbench.UserProfileFormMessage", String, :user_profile_form_message
135 arvcfg.declare_config "Workbench.Theme", String, :arvados_theme
136 arvcfg.declare_config "Workbench.ShowUserNotifications", Boolean, :show_user_notifications
137 arvcfg.declare_config "Workbench.ShowUserAgreementInline", Boolean, :show_user_agreement_inline
138 arvcfg.declare_config "Workbench.RepositoryCache", String, :repository_cache
139 arvcfg.declare_config "Workbench.Repositories", Boolean, :repositories
140 arvcfg.declare_config "Workbench.APIClientConnectTimeout", ActiveSupport::Duration, :api_client_connect_timeout
141 arvcfg.declare_config "Workbench.APIClientReceiveTimeout", ActiveSupport::Duration, :api_client_receive_timeout
142 arvcfg.declare_config "Workbench.APIResponseCompression", Boolean, :api_response_compression
143 arvcfg.declare_config "Workbench.SiteName", String, :site_name
144 arvcfg.declare_config "Workbench.MultiSiteSearch", String, :multi_site_search, ->(cfg, k, v) {
148 ConfigLoader.set_cfg cfg, "Workbench.MultiSiteSearch", v.to_s
150 arvcfg.declare_config "Workbench.EnablePublicProjectsPage", Boolean, :enable_public_projects_page
151 arvcfg.declare_config "Workbench.EnableGettingStartedPopup", Boolean, :enable_getting_started_popup
152 arvcfg.declare_config "Workbench.ArvadosPublicDataDocURL", String, :arvados_public_data_doc_url
153 arvcfg.declare_config "Workbench.ArvadosDocsite", String, :arvados_docsite
154 arvcfg.declare_config "Workbench.ShowRecentCollectionsOnDashboard", Boolean, :show_recent_collections_on_dashboard
155 arvcfg.declare_config "Workbench.ActivationContactLink", String, :activation_contact_link
156 arvcfg.declare_config "Workbench.DefaultOpenIdPrefix", String, :default_openid_prefix
158 arvcfg.declare_config "Mail.SendUserSetupNotificationEmail", Boolean, :send_user_setup_notification_email
159 arvcfg.declare_config "Mail.IssueReporterEmailFrom", String, :issue_reporter_email_from
160 arvcfg.declare_config "Mail.IssueReporterEmailTo", String, :issue_reporter_email_to
161 arvcfg.declare_config "Mail.SupportEmailAddress", String, :support_email_address
162 arvcfg.declare_config "Mail.EmailFrom", String, :email_from
164 application_config = {}
165 %w(application.default application).each do |cfgfile|
166 path = "#{::Rails.root.to_s}/config/#{cfgfile}.yml"
167 confs = ConfigLoader.load(path, erb: true)
168 # Ignore empty YAML file:
169 next if confs == false
170 application_config.deep_merge!(confs['common'] || {})
171 application_config.deep_merge!(confs[::Rails.env.to_s] || {})
174 $remaining_config = arvcfg.migrate_config(application_config, $arvados_config)
176 # Checks for wrongly typed configuration items, coerces properties
177 # into correct types (such as Duration), and optionally raise error
178 # for essential configuration that can't be empty.
179 arvcfg.coercion_and_check $arvados_config_defaults, check_nonempty: false
180 arvcfg.coercion_and_check $arvados_config_global, check_nonempty: false
181 arvcfg.coercion_and_check $arvados_config, check_nonempty: true
183 # * $arvados_config_defaults is the defaults
184 # * $arvados_config_global is $arvados_config_defaults merged with the contents of /etc/arvados/config.yml
185 # These are used by the rake config: tasks
187 # * $arvados_config is $arvados_config_global merged with the migrated contents of application.yml
188 # This is what actually gets copied into the Rails configuration object.
190 ArvadosWorkbench::Application.configure do
191 # Copy into the Rails config object. This also turns Hash into
192 # OrderedOptions so that application code can use
193 # Rails.configuration.API.Blah instead of
194 # Rails.configuration.API["Blah"]
195 ConfigLoader.copy_into_config $arvados_config, config
196 ConfigLoader.copy_into_config $remaining_config, config
197 secrets.secret_key_base = $arvados_config["Workbench"]["SecretKeyBase"]
198 if ENV["ARVADOS_CONFIG"] != "none"
199 ConfigValidators.validate_wb2_url_config()
200 ConfigValidators.validate_download_config()