17353: Don't show config-dump warnings for empty config.
[arvados.git] / apps / workbench / config / arvados_config.rb
index a3a01cabfa6b9be67a10283c3ff1d914accda053..007e8d0687c6b290633ca809b2bf4396ca657a2d 100644 (file)
 # /etc/arvados/config.yml, you will be able to delete application.yml.
 
 require 'config_loader'
-
-begin
-  # If secret_token.rb exists here, we need to load it first.
-  require_relative 'secret_token.rb'
-rescue LoadError
-  # Normally secret_token.rb is missing and the secret token is
-  # configured by application.yml (i.e., here!) instead.
-end
-
-# Load the defaults
-$arvados_config_defaults = ConfigLoader.load "#{::Rails.root.to_s}/config/config.default.yml"
-if $arvados_config_defaults.empty?
-  raise "Missing #{::Rails.root.to_s}/config/config.default.yml"
-end
-
-def remove_sample_entries(h)
-  return unless h.is_a? Hash
-  h.delete("SAMPLE")
-  h.each { |k, v| remove_sample_entries(v) }
+require 'config_validators'
+require 'open3'
+
+# Load the defaults, used by config:migrate and fallback loading
+# legacy application.yml
+defaultYAML, stderr, status = Open3.capture3("arvados-server", "config-dump", "-config=-", "-skip-legacy", stdin_data: "Clusters: {xxxxx: {}}")
+if !status.success?
+  puts stderr
+  raise "error loading config: #{status}"
 end
-remove_sample_entries($arvados_config_defaults)
-
-clusterID, clusterConfig = $arvados_config_defaults["Clusters"].first
+confs = YAML.load(defaultYAML, deserialize_symbols: false)
+clusterID, clusterConfig = confs["Clusters"].first
 $arvados_config_defaults = clusterConfig
 $arvados_config_defaults["ClusterID"] = clusterID
 
-# Initialize the global config with the defaults
-$arvados_config_global = $arvados_config_defaults.deep_dup
-
 # Load the global config file
-confs = ConfigLoader.load "/etc/arvados/config.yml"
-if !confs.empty?
-  clusterID, clusterConfig = confs["Clusters"].first
-  $arvados_config_global["ClusterID"] = clusterID
-
-  # Copy the cluster config over the defaults
-  $arvados_config_global.deep_merge!(clusterConfig)
+Open3.popen2("arvados-server", "config-dump", "-skip-legacy") do |stdin, stdout, status_thread|
+  confs = YAML.load(stdout, deserialize_symbols: false)
+  if confs && !confs.empty?
+    # config-dump merges defaults with user configuration, so every
+    # key should be set.
+    clusterID, clusterConfig = confs["Clusters"].first
+    $arvados_config_global = clusterConfig
+    $arvados_config_global["ClusterID"] = clusterID
+  else
+    # config-dump failed, assume we will be loading from legacy
+    # application.yml, initialize with defaults.
+    $arvados_config_global = $arvados_config_defaults.deep_dup
+  end
 end
 
 # Now make a copy
@@ -63,6 +55,7 @@ arvcfg = ConfigLoader.new
 
 arvcfg.declare_config "ManagementToken", String, :ManagementToken
 arvcfg.declare_config "TLS.Insecure", Boolean, :arvados_insecure_https
+arvcfg.declare_config "Collections.TrustAllContent", Boolean, :trust_all_content
 
 arvcfg.declare_config "Services.Controller.ExternalURL", URI, :arvados_v1_base, ->(cfg, k, v) {
   u = URI(v)
@@ -96,6 +89,8 @@ arvcfg.declare_config "Services.Workbench2.ExternalURL", URI, :workbench2_url
 
 arvcfg.declare_config "Users.AnonymousUserToken", String, :anonymous_user_token
 
+arvcfg.declare_config "Workbench.SecretKeyBase", String, :secret_key_base
+
 arvcfg.declare_config "Workbench.ApplicationMimetypesWithViewIcon", Hash, :application_mimetypes_with_view_icon, ->(cfg, k, v) {
   mimetypes = {}
   v.each do |m|
@@ -106,13 +101,35 @@ arvcfg.declare_config "Workbench.ApplicationMimetypesWithViewIcon", Hash, :appli
 
 arvcfg.declare_config "Workbench.RunningJobLogRecordsToFetch", Integer, :running_job_log_records_to_fetch
 arvcfg.declare_config "Workbench.LogViewerMaxBytes", Integer, :log_viewer_max_bytes
-arvcfg.declare_config "Workbench.TrustAllContent", Boolean, :trust_all_content
-arvcfg.declare_config "Workbench.UserProfileFormFields", Hash, :user_profile_form_fields
+arvcfg.declare_config "Workbench.ProfilingEnabled", Boolean, :profiling_enabled
+arvcfg.declare_config "Workbench.APIResponseCompression", Boolean, :api_response_compression
+arvcfg.declare_config "Workbench.UserProfileFormFields", Hash, :user_profile_form_fields, ->(cfg, k, v) {
+  if !v
+    v = []
+  end
+  entries = {}
+  v.each_with_index do |s,i|
+    entries[s["key"]] = {
+      "Type" => s["type"],
+      "FormFieldTitle" => s["form_field_title"],
+      "FormFieldDescription" => s["form_field_description"],
+      "Required" => s["required"],
+      "Position": i
+    }
+    if s["options"]
+      entries[s["key"]]["Options"] = {}
+      s["options"].each do |o|
+        entries[s["key"]]["Options"][o] = {}
+      end
+    end
+  end
+  ConfigLoader.set_cfg cfg, "Workbench.UserProfileFormFields", entries
+}
 arvcfg.declare_config "Workbench.UserProfileFormMessage", String, :user_profile_form_message
 arvcfg.declare_config "Workbench.Theme", String, :arvados_theme
 arvcfg.declare_config "Workbench.ShowUserNotifications", Boolean, :show_user_notifications
 arvcfg.declare_config "Workbench.ShowUserAgreementInline", Boolean, :show_user_agreement_inline
-arvcfg.declare_config "Workbench.RepositoryCache", Boolean, :repository_cache
+arvcfg.declare_config "Workbench.RepositoryCache", String, :repository_cache
 arvcfg.declare_config "Workbench.Repositories", Boolean, :repositories
 arvcfg.declare_config "Workbench.APIClientConnectTimeout", ActiveSupport::Duration, :api_client_connect_timeout
 arvcfg.declare_config "Workbench.APIClientReceiveTimeout", ActiveSupport::Duration, :api_client_receive_timeout
@@ -171,5 +188,8 @@ ArvadosWorkbench::Application.configure do
   # Rails.configuration.API["Blah"]
   ConfigLoader.copy_into_config $arvados_config, config
   ConfigLoader.copy_into_config $remaining_config, config
-  secrets.secret_key_base = $arvados_config["Workbench"]["SecretToken"]
+  secrets.secret_key_base = $arvados_config["Workbench"]["SecretKeyBase"]
+  ConfigValidators.validate_wb2_url_config()
+  ConfigValidators.validate_download_config()
+
 end