13996: Migrate tests to new config
[arvados.git] / services / api / config / initializers / load_config.rb
1 # Copyright (C) The Arvados Authors. All rights reserved.
2 #
3 # SPDX-License-Identifier: AGPL-3.0
4
5 require 'config_loader'
6
7 begin
8   # If secret_token.rb exists here, we need to load it first.
9   require_relative 'secret_token.rb'
10 rescue LoadError
11   # Normally secret_token.rb is missing and the secret token is
12   # configured by application.yml (i.e., here!) instead.
13 end
14
15 if (File.exist?(File.expand_path '../omniauth.rb', __FILE__) and
16     not defined? WARNED_OMNIAUTH_CONFIG)
17   Rails.logger.warn <<-EOS
18 DEPRECATED CONFIGURATION:
19  Please move your SSO provider config into config/application.yml
20  and delete config/initializers/omniauth.rb.
21 EOS
22   # Real values will be copied from globals by omniauth_init.rb. For
23   # now, assign some strings so the generic *.yml config loader
24   # doesn't overwrite them or complain that they're missing.
25   Rails.configuration.Login["ProviderAppID"] = 'xxx'
26   Rails.configuration.Login["ProviderAppSecret"] = 'xxx'
27   Rails.configuration.Services["SSO"]["ExternalURL"] = '//xxx'
28   WARNED_OMNIAUTH_CONFIG = true
29 end
30
31 $arvados_config = {}
32
33 ["#{::Rails.root.to_s}/config/config.defaults.yml", "/etc/arvados/config.yml"].each do |path|
34   if File.exist? path
35     confs = YAML.load(IO.read(path), deserialize_symbols: false)
36     if confs
37       clusters = confs["Clusters"].first
38       $arvados_config["ClusterID"] = clusters[0]
39       $arvados_config.merge!(clusters[1])
40     end
41   end
42 end
43
44 declare_config "ClusterID", NonemptyString, :uuid_prefix
45 declare_config "ManagementToken", NonemptyString, :ManagementToken
46 declare_config "Git.Repositories", String, :git_repositories_dir
47 declare_config "API.DisabledAPIs", Array, :disable_api_methods
48 declare_config "API.MaxRequestSize", Integer, :max_request_size
49 declare_config "API.MaxIndexDatabaseRead", Integer, :max_index_database_read
50 declare_config "API.MaxItemsPerResponse", Integer, :max_items_per_response
51 declare_config "API.AsyncPermissionsUpdateInterval", ActiveSupport::Duration, :async_permissions_update_interval
52 declare_config "Users.AutoSetupNewUsers", Boolean, :auto_setup_new_users
53 declare_config "Users.AutoSetupNewUsersWithVmUUID", String, :auto_setup_new_users_with_vm_uuid
54 declare_config "Users.AutoSetupNewUsersWithRepository", Boolean, :auto_setup_new_users_with_repository
55 declare_config "Users.AutoSetupUsernameBlacklist", Array, :auto_setup_name_blacklist
56 declare_config "Users.NewUsersAreActive", Boolean, :new_users_are_active
57 declare_config "Users.AutoAdminUserWithEmail", String, :auto_admin_user
58 declare_config "Users.AutoAdminFirstUser", Boolean, :auto_admin_first_user
59 declare_config "Users.UserProfileNotificationAddress", String, :user_profile_notification_address
60 declare_config "Users.AdminNotifierEmailFrom", String, :admin_notifier_email_from
61 declare_config "Users.EmailSubjectPrefix", String, :email_subject_prefix
62 declare_config "Users.UserNotifierEmailFrom", String, :user_notifier_email_from
63 declare_config "Users.NewUserNotificationRecipients", Array, :new_user_notification_recipients
64 declare_config "Users.NewInactiveUserNotificationRecipients", Array, :new_inactive_user_notification_recipients
65 declare_config "Login.ProviderAppSecret", NonemptyString, :sso_app_secret
66 declare_config "Login.ProviderAppID", NonemptyString, :sso_app_id
67 declare_config "TLS.Insecure", Boolean, :sso_insecure
68 declare_config "Services.SSO.ExternalURL", NonemptyString, :sso_provider_url
69 declare_config "AuditLogs.MaxAge", ActiveSupport::Duration, :max_audit_log_age
70 declare_config "AuditLogs.MaxDeleteBatch", Integer, :max_audit_log_delete_batch
71 declare_config "AuditLogs.UnloggedAttributes", Array, :unlogged_attributes
72 declare_config "SystemLogs.MaxRequestLogParamsSize", Integer, :max_request_log_params_size
73 declare_config "Collections.DefaultReplication", Integer, :default_collection_replication
74 declare_config "Collections.DefaultTrashLifetime", ActiveSupport::Duration, :default_trash_lifetime
75 declare_config "Collections.CollectionVersioning", Boolean, :collection_versioning
76 declare_config "Collections.PreserveVersionIfIdle", ActiveSupport::Duration, :preserve_version_if_idle
77 declare_config "Collections.TrashSweepInterval", ActiveSupport::Duration, :trash_sweep_interval
78 declare_config "Collections.BlobSigningKey", NonemptyString, :blob_signing_key
79 declare_config "Collections.BlobSigningTTL", Integer, :blob_signature_ttl
80 declare_config "Collections.BlobSigning", Boolean, :permit_create_collection_with_unsigned_manifest
81 declare_config "Containers.SupportedDockerImageFormats", Array, :docker_image_formats
82 declare_config "Containers.LogReuseDecisions", Boolean, :log_reuse_decisions
83 declare_config "Containers.DefaultKeepCacheRAM", Integer, :container_default_keep_cache_ram
84 declare_config "Containers.MaxDispatchAttempts", Integer, :max_container_dispatch_attempts
85 declare_config "Containers.MaxRetryAttempts", Integer, :container_count_max
86 declare_config "Containers.UsePreemptibleInstances", Boolean, :preemptible_instances
87 declare_config "Containers.MaxComputeVMs", Integer, :max_compute_nodes
88 declare_config "Containers.Logging.LogBytesPerEvent", Integer, :crunch_log_bytes_per_event
89 declare_config "Containers.Logging.LogSecondsBetweenEvents", ActiveSupport::Duration, :crunch_log_seconds_between_events
90 declare_config "Containers.Logging.LogThrottlePeriod", ActiveSupport::Duration, :crunch_log_throttle_period
91 declare_config "Containers.Logging.LogThrottleBytes", Integer, :crunch_log_throttle_bytes
92 declare_config "Containers.Logging.LogThrottleLines", Integer, :crunch_log_throttle_lines
93 declare_config "Containers.Logging.LimitLogBytesPerJob", Integer, :crunch_limit_log_bytes_per_job
94 declare_config "Containers.Logging.LogPartialLineThrottlePeriod", ActiveSupport::Duration, :crunch_log_partial_line_throttle_period
95 declare_config "Containers.Logging.LogUpdatePeriod", ActiveSupport::Duration, :crunch_log_update_period
96 declare_config "Containers.Logging.LogUpdateSize", Integer, :crunch_log_update_size
97 declare_config "Containers.Logging.MaxAge", ActiveSupport::Duration, :clean_container_log_rows_after
98 declare_config "Containers.SLURM.Managed.DNSServerConfDir", String, :dns_server_conf_dir
99 declare_config "Containers.SLURM.Managed.DNSServerConfTemplate", String, :dns_server_conf_template
100 declare_config "Containers.SLURM.Managed.DNSServerReloadCommand", String, :dns_server_reload_command
101 declare_config "Containers.SLURM.Managed.DNSServerUpdateCommand", String, :dns_server_update_command
102 declare_config "Containers.SLURM.Managed.ComputeNodeDomain", String, :compute_node_domain
103 declare_config "Containers.SLURM.Managed.ComputeNodeNameservers", Array, :compute_node_nameservers
104 declare_config "Containers.SLURM.Managed.AssignNodeHostname", String, :assign_node_hostname
105 declare_config "Containers.JobsAPI.Enable", String, :enable_legacy_jobs_api, ->(cfg, k, v) { set_cfg cfg, "Containers.JobsAPI.Enable", v.to_s }
106 declare_config "Containers.JobsAPI.CrunchJobWrapper", String, :crunch_job_wrapper
107 declare_config "Containers.JobsAPI.CrunchJobUser", String, :crunch_job_user
108 declare_config "Containers.JobsAPI.CrunchRefreshTrigger", String, :crunch_refresh_trigger
109 declare_config "Containers.JobsAPI.GitInternalDir", String, :git_internal_dir
110 declare_config "Containers.JobsAPI.ReuseJobIfOutputsDiffer", Boolean, :reuse_job_if_outputs_differ
111 declare_config "Containers.JobsAPI.DefaultDockerImage", String, :default_docker_image_for_jobs
112 declare_config "Mail.MailchimpAPIKey", String, :mailchimp_api_key
113 declare_config "Mail.MailchimpListID", String, :mailchimp_list_id
114 declare_config "Services.Workbench1.ExternalURL", URI, :workbench_address
115 declare_config "Services.Websocket.ExternalURL", URI, :websocket_address
116 declare_config "Services.WebDAV.ExternalURL", URI, :keep_web_service_url
117 declare_config "Services.GitHTTP.ExternalURL", URI, :git_repo_https_base
118 declare_config "Services.GitSSH.ExternalURL", URI, :git_repo_ssh_base
119 declare_config "RemoteClusters", Hash, :remote_hosts, ->(cfg, k, v) {
120   h = {}
121   v.each do |clusterid, host|
122     h[clusterid] = {
123       "Host" => host,
124       "Proxy" => true,
125       "Scheme" => "https",
126       "Insecure" => false,
127       "ActivateUsers" => false
128     }
129   end
130   set_cfg cfg, "RemoteClusters", h
131 }
132 declare_config "RemoteClusters.*.Proxy", Boolean, :remote_hosts_via_dns
133
134 application_config = {}
135 %w(application.default application).each do |cfgfile|
136   path = "#{::Rails.root.to_s}/config/#{cfgfile}.yml"
137   if File.exist? path
138     yaml = ERB.new(IO.read path).result(binding)
139     confs = YAML.load(yaml, deserialize_symbols: true)
140     # Ignore empty YAML file:
141     next if confs == false
142     application_config.merge!(confs['common'] || {})
143     application_config.merge!(confs[::Rails.env.to_s] || {})
144   end
145 end
146
147 $remaining_config = migrate_config application_config, $arvados_config
148
149 if application_config[:auto_activate_users_from]
150   application_config[:auto_activate_users_from].each do |cluster|
151     if $arvados_config.RemoteClusters[cluster]
152       $arvados_config.RemoteClusters[cluster]["ActivateUsers"] = true
153     end
154   end
155 end
156
157 # Checks for wrongly typed configuration items, and essential items
158 # that can't be empty
159 coercion_and_check $arvados_config
160
161 Server::Application.configure do
162   nils = []
163   copy_into_config $arvados_config, config
164   copy_into_config $remaining_config, config
165   config.secret_key_base = config.secret_token
166 end