Pin jssha to 2.4.2
[arvados.git] / apps / workbench / config / arvados_config.rb
1 # Copyright (C) The Arvados Authors. All rights reserved.
2 #
3 # SPDX-License-Identifier: AGPL-3.0
4
5 #
6 # Load Arvados configuration from /etc/arvados/config.yml, using defaults
7 # from config.default.yml
8 #
9 # Existing application.yml is migrated into the new config structure.
10 # Keys in the legacy application.yml take precedence.
11 #
12 # Use "bundle exec config:dump" to get the complete active configuration
13 #
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.
17
18 require 'config_loader'
19 require 'config_validators'
20 require 'open3'
21
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: {}}")
26   stdin.close
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
31 end
32
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
38     # key should be set.
39     clusterID, clusterConfig = confs["Clusters"].first
40     $arvados_config_global = clusterConfig
41     $arvados_config_global["ClusterID"] = clusterID
42   else
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
46   end
47 end
48
49 # Now make a copy
50 $arvados_config = $arvados_config_global.deep_dup
51
52 # Declare all our configuration items.
53 arvcfg = ConfigLoader.new
54
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
58
59 arvcfg.declare_config "Services.Controller.ExternalURL", URI, :arvados_v1_base, ->(cfg, k, v) {
60   u = URI(v)
61   u.path = ""
62   ConfigLoader.set_cfg cfg, "Services.Controller.ExternalURL", u
63 }
64
65 arvcfg.declare_config "Services.WebShell.ExternalURL", URI, :shell_in_a_box_url, ->(cfg, k, v) {
66   v ||= ""
67   u = URI(v.sub("%{hostname}", "*"))
68   u.path = ""
69   ConfigLoader.set_cfg cfg, "Services.WebShell.ExternalURL", u
70 }
71
72 arvcfg.declare_config "Services.WebDAV.ExternalURL", URI, :keep_web_url, ->(cfg, k, v) {
73   v ||= ""
74   u = URI(v.sub("%{uuid_or_pdh}", "*"))
75   u.path = ""
76   ConfigLoader.set_cfg cfg, "Services.WebDAV.ExternalURL", u
77 }
78
79 arvcfg.declare_config "Services.WebDAVDownload.ExternalURL", URI, :keep_web_download_url, ->(cfg, k, v) {
80   v ||= ""
81   u = URI(v.sub("%{uuid_or_pdh}", "*"))
82   u.path = ""
83   ConfigLoader.set_cfg cfg, "Services.WebDAVDownload.ExternalURL", u
84 }
85
86 arvcfg.declare_config "Services.Composer.ExternalURL", URI, :composer_url
87 arvcfg.declare_config "Services.Workbench2.ExternalURL", URI, :workbench2_url
88
89 arvcfg.declare_config "Users.AnonymousUserToken", String, :anonymous_user_token
90
91 arvcfg.declare_config "Workbench.SecretKeyBase", String, :secret_key_base
92
93 arvcfg.declare_config "Workbench.ApplicationMimetypesWithViewIcon", Hash, :application_mimetypes_with_view_icon, ->(cfg, k, v) {
94   mimetypes = {}
95   v.each do |m|
96     mimetypes[m] = {}
97   end
98   ConfigLoader.set_cfg cfg, "Workbench.ApplicationMimetypesWithViewIcon", mimetypes
99 }
100
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) {
106   if !v
107     v = []
108   end
109   entries = {}
110   v.each_with_index do |s,i|
111     entries[s["key"]] = {
112       "Type" => s["type"],
113       "FormFieldTitle" => s["form_field_title"],
114       "FormFieldDescription" => s["form_field_description"],
115       "Required" => s["required"],
116       "Position": i
117     }
118     if s["options"]
119       entries[s["key"]]["Options"] = {}
120       s["options"].each do |o|
121         entries[s["key"]]["Options"][o] = {}
122       end
123     end
124   end
125   ConfigLoader.set_cfg cfg, "Workbench.UserProfileFormFields", entries
126 }
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) {
138   if !v
139     v = ""
140   end
141   ConfigLoader.set_cfg cfg, "Workbench.MultiSiteSearch", v.to_s
142 }
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
150
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
156
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] || {})
165 end
166
167 $remaining_config = arvcfg.migrate_config(application_config, $arvados_config)
168
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
175
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
179 #
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.
182
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()
193
194 end