14812: First pass migrating tests.
[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
20 begin
21   # If secret_token.rb exists here, we need to load it first.
22   require_relative 'secret_token.rb'
23 rescue LoadError
24   # Normally secret_token.rb is missing and the secret token is
25   # configured by application.yml (i.e., here!) instead.
26 end
27
28 # Load the defaults
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"
32 end
33
34 def remove_sample_entries(h)
35   return unless h.is_a? Hash
36   h.delete("SAMPLE")
37   h.each { |k, v| remove_sample_entries(v) }
38 end
39 remove_sample_entries($arvados_config_defaults)
40
41 clusterID, clusterConfig = $arvados_config_defaults["Clusters"].first
42 $arvados_config_defaults = clusterConfig
43 $arvados_config_defaults["ClusterID"] = clusterID
44
45 # Initialize the global config with the defaults
46 $arvados_config_global = $arvados_config_defaults.deep_dup
47
48 # Load the global config file
49 confs = ConfigLoader.load "/etc/arvados/config.yml"
50 if !confs.empty?
51   clusterID, clusterConfig = confs["Clusters"].first
52   $arvados_config_global["ClusterID"] = clusterID
53
54   # Copy the cluster config over the defaults
55   $arvados_config_global.deep_merge!(clusterConfig)
56 end
57
58 # Now make a copy
59 $arvados_config = $arvados_config_global.deep_dup
60
61 # Declare all our configuration items.
62 arvcfg = ConfigLoader.new
63
64 arvcfg.declare_config "ManagementToken", String, :ManagementToken
65 arvcfg.declare_config "TLS.Insecure", Boolean, :arvados_insecure_https
66
67 arvcfg.declare_config "Services.Controller.ExternalURL", URI, :arvados_v1_base, ->(cfg, k, v) {
68   u = URI(v)
69   u.path = ""
70   ConfigLoader.set_cfg cfg, "Services.Controller.ExternalURL", u
71 }
72
73 arvcfg.declare_config "Services.WebShell.ExternalURL", URI, :shell_in_a_box_url, ->(cfg, k, v) {
74   v ||= ""
75   u = URI(v.sub("%{hostname}", "*"))
76   u.path = ""
77   ConfigLoader.set_cfg cfg, "Services.WebShell.ExternalURL", u
78 }
79
80 arvcfg.declare_config "Services.WebDAV.ExternalURL", URI, :keep_web_url, ->(cfg, k, v) {
81   v ||= ""
82   u = URI(v.sub("%{uuid_or_pdh}", "*"))
83   u.path = ""
84   ConfigLoader.set_cfg cfg, "Services.WebDAV.ExternalURL", u
85 }
86
87 arvcfg.declare_config "Services.WebDAVDownload.ExternalURL", URI, :keep_web_download_url, ->(cfg, k, v) {
88   v ||= ""
89   u = URI(v.sub("%{uuid_or_pdh}", "*"))
90   u.path = ""
91   ConfigLoader.set_cfg cfg, "Services.WebDAVDownload.ExternalURL", u
92 }
93
94 arvcfg.declare_config "Services.Composer.ExternalURL", URI, :composer_url
95 arvcfg.declare_config "Services.Workbench2.ExternalURL", URI, :workbench2_url
96
97 arvcfg.declare_config "Users.AnonymousUserToken", String, :anonymous_user_token
98
99 arvcfg.declare_config "Workbench.SecretToken", String, :secret_token
100 arvcfg.declare_config "Workbench.SecretKeyBase", String, :secret_key_base
101
102 arvcfg.declare_config "Workbench.ApplicationMimetypesWithViewIcon", Hash, :application_mimetypes_with_view_icon, ->(cfg, k, v) {
103   mimetypes = {}
104   v.each do |m|
105     mimetypes[m] = {}
106   end
107   ConfigLoader.set_cfg cfg, "Workbench.ApplicationMimetypesWithViewIcon", mimetypes
108 }
109
110 arvcfg.declare_config "Workbench.RunningJobLogRecordsToFetch", Integer, :running_job_log_records_to_fetch
111 arvcfg.declare_config "Workbench.LogViewerMaxBytes", Integer, :log_viewer_max_bytes
112 arvcfg.declare_config "Workbench.TrustAllContent", Boolean, :trust_all_content
113 arvcfg.declare_config "Workbench.UserProfileFormFields", Array, :user_profile_form_fields, ->(cfg, k, v) {
114   if !v
115     v = []
116   end
117   ConfigLoader.set_cfg cfg, "Workbench.UserProfileFormFields", v
118 }
119 arvcfg.declare_config "Workbench.UserProfileFormMessage", String, :user_profile_form_message
120 arvcfg.declare_config "Workbench.Theme", String, :arvados_theme
121 arvcfg.declare_config "Workbench.ShowUserNotifications", Boolean, :show_user_notifications
122 arvcfg.declare_config "Workbench.ShowUserAgreementInline", Boolean, :show_user_agreement_inline
123 arvcfg.declare_config "Workbench.RepositoryCache", String, :repository_cache
124 arvcfg.declare_config "Workbench.Repositories", Boolean, :repositories
125 arvcfg.declare_config "Workbench.APIClientConnectTimeout", ActiveSupport::Duration, :api_client_connect_timeout
126 arvcfg.declare_config "Workbench.APIClientReceiveTimeout", ActiveSupport::Duration, :api_client_receive_timeout
127 arvcfg.declare_config "Workbench.APIResponseCompression", Boolean, :api_response_compression
128 arvcfg.declare_config "Workbench.SiteName", String, :site_name
129 arvcfg.declare_config "Workbench.MultiSiteSearch", String, :multi_site_search, ->(cfg, k, v) {
130   if !v
131     v = ""
132   end
133   ConfigLoader.set_cfg cfg, "Workbench.MultiSiteSearch", v.to_s
134 }
135 arvcfg.declare_config "Workbench.EnablePublicProjectsPage", Boolean, :enable_public_projects_page
136 arvcfg.declare_config "Workbench.EnableGettingStartedPopup", Boolean, :enable_getting_started_popup
137 arvcfg.declare_config "Workbench.ArvadosPublicDataDocURL", String, :arvados_public_data_doc_url
138 arvcfg.declare_config "Workbench.ArvadosDocsite", String, :arvados_docsite
139 arvcfg.declare_config "Workbench.ShowRecentCollectionsOnDashboard", Boolean, :show_recent_collections_on_dashboard
140 arvcfg.declare_config "Workbench.ActivationContactLink", String, :activation_contact_link
141 arvcfg.declare_config "Workbench.DefaultOpenIdPrefix", String, :default_openid_prefix
142
143 arvcfg.declare_config "Mail.SendUserSetupNotificationEmail", Boolean, :send_user_setup_notification_email
144 arvcfg.declare_config "Mail.IssueReporterEmailFrom", String, :issue_reporter_email_from
145 arvcfg.declare_config "Mail.IssueReporterEmailTo", String, :issue_reporter_email_to
146 arvcfg.declare_config "Mail.SupportEmailAddress", String, :support_email_address
147 arvcfg.declare_config "Mail.EmailFrom", String, :email_from
148
149 application_config = {}
150 %w(application.default application).each do |cfgfile|
151   path = "#{::Rails.root.to_s}/config/#{cfgfile}.yml"
152   confs = ConfigLoader.load(path, erb: true)
153   # Ignore empty YAML file:
154   next if confs == false
155   application_config.deep_merge!(confs['common'] || {})
156   application_config.deep_merge!(confs[::Rails.env.to_s] || {})
157 end
158
159 $remaining_config = arvcfg.migrate_config(application_config, $arvados_config)
160
161 # Checks for wrongly typed configuration items, coerces properties
162 # into correct types (such as Duration), and optionally raise error
163 # for essential configuration that can't be empty.
164 arvcfg.coercion_and_check $arvados_config_defaults, check_nonempty: false
165 arvcfg.coercion_and_check $arvados_config_global, check_nonempty: false
166 arvcfg.coercion_and_check $arvados_config, check_nonempty: true
167
168 # * $arvados_config_defaults is the defaults
169 # * $arvados_config_global is $arvados_config_defaults merged with the contents of /etc/arvados/config.yml
170 # These are used by the rake config: tasks
171 #
172 # * $arvados_config is $arvados_config_global merged with the migrated contents of application.yml
173 # This is what actually gets copied into the Rails configuration object.
174
175 ArvadosWorkbench::Application.configure do
176   # Copy into the Rails config object.  This also turns Hash into
177   # OrderedOptions so that application code can use
178   # Rails.configuration.API.Blah instead of
179   # Rails.configuration.API["Blah"]
180   ConfigLoader.copy_into_config $arvados_config, config
181   ConfigLoader.copy_into_config $remaining_config, config
182   secrets.secret_key_base = $arvados_config["Workbench"]["SecretKeyBase"]
183 end