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 Open3.popen2("arvados-server", "config-dump", "-config=-", "-skip-legacy") do |stdin, stdout, status_thread|
25 stdin.write("Clusters: {xxxxx: {}}")
27 confs = YAML.load(stdout, deserialize_symbols: false)
28 clusterID, clusterConfig = confs["Clusters"].first
29 $arvados_config_defaults = clusterConfig
30 $arvados_config_defaults["ClusterID"] = clusterID
33 # Load the global config file
34 Open3.popen2("arvados-server", "config-dump", "-skip-legacy") do |stdin, stdout, status_thread|
35 confs = YAML.load(stdout, deserialize_symbols: false)
36 if confs && !confs.empty?
37 # config-dump merges defaults with user configuration, so every
39 clusterID, clusterConfig = confs["Clusters"].first
40 $arvados_config_global = clusterConfig
41 $arvados_config_global["ClusterID"] = clusterID
43 # config-dump failed, assume we will be loading from legacy
44 # application.yml, initialize with defaults.
45 $arvados_config_global = $arvados_config_defaults.deep_dup
50 $arvados_config = $arvados_config_global.deep_dup
52 # Declare all our configuration items.
53 arvcfg = ConfigLoader.new
55 arvcfg.declare_config "ManagementToken", String, :ManagementToken
56 arvcfg.declare_config "TLS.Insecure", Boolean, :arvados_insecure_https
57 arvcfg.declare_config "Collections.TrustAllContent", Boolean, :trust_all_content
59 arvcfg.declare_config "Services.Controller.ExternalURL", URI, :arvados_v1_base, ->(cfg, k, v) {
62 ConfigLoader.set_cfg cfg, "Services.Controller.ExternalURL", u
65 arvcfg.declare_config "Services.WebShell.ExternalURL", URI, :shell_in_a_box_url, ->(cfg, k, v) {
67 u = URI(v.sub("%{hostname}", "*"))
69 ConfigLoader.set_cfg cfg, "Services.WebShell.ExternalURL", u
72 arvcfg.declare_config "Services.WebDAV.ExternalURL", URI, :keep_web_url, ->(cfg, k, v) {
74 u = URI(v.sub("%{uuid_or_pdh}", "*"))
76 ConfigLoader.set_cfg cfg, "Services.WebDAV.ExternalURL", u
79 arvcfg.declare_config "Services.WebDAVDownload.ExternalURL", URI, :keep_web_download_url, ->(cfg, k, v) {
81 u = URI(v.sub("%{uuid_or_pdh}", "*"))
83 ConfigLoader.set_cfg cfg, "Services.WebDAVDownload.ExternalURL", u
86 arvcfg.declare_config "Services.Composer.ExternalURL", URI, :composer_url
87 arvcfg.declare_config "Services.Workbench2.ExternalURL", URI, :workbench2_url
89 arvcfg.declare_config "Users.AnonymousUserToken", String, :anonymous_user_token
91 arvcfg.declare_config "Workbench.SecretKeyBase", String, :secret_key_base
93 arvcfg.declare_config "Workbench.ApplicationMimetypesWithViewIcon", Hash, :application_mimetypes_with_view_icon, ->(cfg, k, v) {
98 ConfigLoader.set_cfg cfg, "Workbench.ApplicationMimetypesWithViewIcon", mimetypes
101 arvcfg.declare_config "Workbench.RunningJobLogRecordsToFetch", Integer, :running_job_log_records_to_fetch
102 arvcfg.declare_config "Workbench.LogViewerMaxBytes", Integer, :log_viewer_max_bytes
103 arvcfg.declare_config "Workbench.ProfilingEnabled", Boolean, :profiling_enabled
104 arvcfg.declare_config "Workbench.APIResponseCompression", Boolean, :api_response_compression
105 arvcfg.declare_config "Workbench.UserProfileFormFields", Hash, :user_profile_form_fields, ->(cfg, k, v) {
110 v.each_with_index do |s,i|
111 entries[s["key"]] = {
113 "FormFieldTitle" => s["form_field_title"],
114 "FormFieldDescription" => s["form_field_description"],
115 "Required" => s["required"],
119 entries[s["key"]]["Options"] = {}
120 s["options"].each do |o|
121 entries[s["key"]]["Options"][o] = {}
125 ConfigLoader.set_cfg cfg, "Workbench.UserProfileFormFields", entries
127 arvcfg.declare_config "Workbench.UserProfileFormMessage", String, :user_profile_form_message
128 arvcfg.declare_config "Workbench.Theme", String, :arvados_theme
129 arvcfg.declare_config "Workbench.ShowUserNotifications", Boolean, :show_user_notifications
130 arvcfg.declare_config "Workbench.ShowUserAgreementInline", Boolean, :show_user_agreement_inline
131 arvcfg.declare_config "Workbench.RepositoryCache", String, :repository_cache
132 arvcfg.declare_config "Workbench.Repositories", Boolean, :repositories
133 arvcfg.declare_config "Workbench.APIClientConnectTimeout", ActiveSupport::Duration, :api_client_connect_timeout
134 arvcfg.declare_config "Workbench.APIClientReceiveTimeout", ActiveSupport::Duration, :api_client_receive_timeout
135 arvcfg.declare_config "Workbench.APIResponseCompression", Boolean, :api_response_compression
136 arvcfg.declare_config "Workbench.SiteName", String, :site_name
137 arvcfg.declare_config "Workbench.MultiSiteSearch", String, :multi_site_search, ->(cfg, k, v) {
141 ConfigLoader.set_cfg cfg, "Workbench.MultiSiteSearch", v.to_s
143 arvcfg.declare_config "Workbench.EnablePublicProjectsPage", Boolean, :enable_public_projects_page
144 arvcfg.declare_config "Workbench.EnableGettingStartedPopup", Boolean, :enable_getting_started_popup
145 arvcfg.declare_config "Workbench.ArvadosPublicDataDocURL", String, :arvados_public_data_doc_url
146 arvcfg.declare_config "Workbench.ArvadosDocsite", String, :arvados_docsite
147 arvcfg.declare_config "Workbench.ShowRecentCollectionsOnDashboard", Boolean, :show_recent_collections_on_dashboard
148 arvcfg.declare_config "Workbench.ActivationContactLink", String, :activation_contact_link
149 arvcfg.declare_config "Workbench.DefaultOpenIdPrefix", String, :default_openid_prefix
151 arvcfg.declare_config "Mail.SendUserSetupNotificationEmail", Boolean, :send_user_setup_notification_email
152 arvcfg.declare_config "Mail.IssueReporterEmailFrom", String, :issue_reporter_email_from
153 arvcfg.declare_config "Mail.IssueReporterEmailTo", String, :issue_reporter_email_to
154 arvcfg.declare_config "Mail.SupportEmailAddress", String, :support_email_address
155 arvcfg.declare_config "Mail.EmailFrom", String, :email_from
157 application_config = {}
158 %w(application.default application).each do |cfgfile|
159 path = "#{::Rails.root.to_s}/config/#{cfgfile}.yml"
160 confs = ConfigLoader.load(path, erb: true)
161 # Ignore empty YAML file:
162 next if confs == false
163 application_config.deep_merge!(confs['common'] || {})
164 application_config.deep_merge!(confs[::Rails.env.to_s] || {})
167 $remaining_config = arvcfg.migrate_config(application_config, $arvados_config)
169 # Checks for wrongly typed configuration items, coerces properties
170 # into correct types (such as Duration), and optionally raise error
171 # for essential configuration that can't be empty.
172 arvcfg.coercion_and_check $arvados_config_defaults, check_nonempty: false
173 arvcfg.coercion_and_check $arvados_config_global, check_nonempty: false
174 arvcfg.coercion_and_check $arvados_config, check_nonempty: true
176 # * $arvados_config_defaults is the defaults
177 # * $arvados_config_global is $arvados_config_defaults merged with the contents of /etc/arvados/config.yml
178 # These are used by the rake config: tasks
180 # * $arvados_config is $arvados_config_global merged with the migrated contents of application.yml
181 # This is what actually gets copied into the Rails configuration object.
183 ArvadosWorkbench::Application.configure do
184 # Copy into the Rails config object. This also turns Hash into
185 # OrderedOptions so that application code can use
186 # Rails.configuration.API.Blah instead of
187 # Rails.configuration.API["Blah"]
188 ConfigLoader.copy_into_config $arvados_config, config
189 ConfigLoader.copy_into_config $remaining_config, config
190 secrets.secret_key_base = $arvados_config["Workbench"]["SecretKeyBase"]
191 ConfigValidators.validate_wb2_url_config()
192 ConfigValidators.validate_download_config()