X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/668a799436295a17223096392898cf257d8dfc76..d3efc21c6aa0f31988b2e7936f24e6f1941791e7:/apps/workbench/config/arvados_config.rb diff --git a/apps/workbench/config/arvados_config.rb b/apps/workbench/config/arvados_config.rb index a3a01cabfa..86b4a47539 100644 --- a/apps/workbench/config/arvados_config.rb +++ b/apps/workbench/config/arvados_config.rb @@ -16,53 +16,58 @@ # /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 +load_time = Time.now.utc +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) +$arvados_config_defaults["SourceTimestamp"] = Time.rfc3339(confs["SourceTimestamp"]) +$arvados_config_defaults["SourceSHA256"] = confs["SourceSHA256"] + +if ENV["ARVADOS_CONFIG"] == "none" + # Don't load config. This magic value is set by packaging scripts so + # they can run "rake assets:precompile" without a real config. + $arvados_config_global = $arvados_config_defaults.deep_dup +else + # Load the global config file + 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 + $arvados_config_global["SourceTimestamp"] = Time.rfc3339(confs["SourceTimestamp"]) + $arvados_config_global["SourceSHA256"] = confs["SourceSHA256"] + 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 end # Now make a copy $arvados_config = $arvados_config_global.deep_dup +$arvados_config["LoadTimestamp"] = load_time # Declare all our configuration items. 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 +101,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 +113,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 +200,13 @@ 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"] + if ENV["ARVADOS_CONFIG"] != "none" + ConfigValidators.validate_wb2_url_config() + ConfigValidators.validate_download_config() + end + if Rails.configuration.Users.AnonymousUserToken and + !Rails.configuration.Users.AnonymousUserToken.starts_with?("v2/") + Rails.configuration.Users.AnonymousUserToken = "v2/#{clusterID}-gj3su-anonymouspublic/#{Rails.configuration.Users.AnonymousUserToken}" + end end