1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: Apache-2.0
14 "git.curoverse.com/arvados.git/sdk/go/config"
17 var DefaultConfigFile = func() string {
18 if path := os.Getenv("ARVADOS_CONFIG"); path != "" {
21 return "/etc/arvados/config.yml"
26 Clusters map[string]Cluster
29 // GetConfig returns the current system config, loading it from
30 // configFile if needed.
31 func GetConfig(configFile string) (*Config, error) {
33 err := config.LoadFile(&cfg, configFile)
37 // GetCluster returns the cluster ID and config for the given
38 // cluster, or the default/only configured cluster if clusterID is "".
39 func (sc *Config) GetCluster(clusterID string) (*Cluster, error) {
41 if len(sc.Clusters) == 0 {
42 return nil, fmt.Errorf("no clusters configured")
43 } else if len(sc.Clusters) > 1 {
44 return nil, fmt.Errorf("multiple clusters configured, cannot choose")
46 for id, cc := range sc.Clusters {
52 if cc, ok := sc.Clusters[clusterID]; !ok {
53 return nil, fmt.Errorf("cluster %q is not configured", clusterID)
55 cc.ClusterID = clusterID
60 type WebDAVCacheConfig struct {
64 MaxCollectionEntries int
65 MaxCollectionBytes int64
66 MaxPermissionEntries int
70 ClusterID string `json:"-"`
71 ManagementToken string
72 SystemRootToken string
74 InstanceTypes InstanceTypeMap
75 Containers ContainersConfig
76 RemoteClusters map[string]RemoteCluster
80 AsyncPermissionsUpdateInterval Duration
81 DisabledAPIs StringSet
82 MaxIndexDatabaseRead int
83 MaxItemsPerResponse int
84 MaxRequestAmplification int
86 RailsSessionSecretToken string
87 RequestTimeout Duration
89 WebsocketClientEventQueue int
90 WebsocketServerEventQueue int
91 KeepServiceRequestTimeout Duration
96 UnloggedAttributes StringSet
100 BlobSigningKey string
101 BlobSigningTTL Duration
102 CollectionVersioning bool
103 DefaultTrashLifetime Duration
104 DefaultReplication int
105 ManagedProperties map[string]struct {
110 PreserveVersionIfIdle Duration
111 TrashSweepInterval Duration
114 WebDAVCache WebDAVCacheConfig
122 ProviderAppSecret string
125 RemoteTokenRefresh Duration
128 MailchimpAPIKey string
129 MailchimpListID string
130 SendUserSetupNotificationEmail bool
131 IssueReporterEmailFrom string
132 IssueReporterEmailTo string
133 SupportEmailAddress string
139 MaxRequestLogParamsSize int
147 AnonymousUserToken string
148 AdminNotifierEmailFrom string
149 AutoAdminFirstUser bool
150 AutoAdminUserWithEmail string
151 AutoSetupNewUsers bool
152 AutoSetupNewUsersWithRepository bool
153 AutoSetupNewUsersWithVmUUID string
154 AutoSetupUsernameBlacklist StringSet
155 EmailSubjectPrefix string
156 NewInactiveUserNotificationRecipients StringSet
157 NewUserNotificationRecipients StringSet
158 NewUsersAreActive bool
159 UserNotifierEmailFrom string
160 UserProfileNotificationAddress string
163 ActivationContactLink string
164 APIClientConnectTimeout Duration
165 APIClientReceiveTimeout Duration
166 APIResponseCompression bool
167 ApplicationMimetypesWithViewIcon StringSet
168 ArvadosDocsite string
169 ArvadosPublicDataDocURL string
170 DefaultOpenIdPrefix string
171 EnableGettingStartedPopup bool
172 EnablePublicProjectsPage bool
173 FileViewersConfigURL string
174 LogViewerMaxBytes ByteSize
175 MultiSiteSearch string
176 ProfilingEnabled bool
178 RepositoryCache string
179 RunningJobLogRecordsToFetch int
181 ShowRecentCollectionsOnDashboard bool
182 ShowUserAgreementInline bool
183 ShowUserNotifications bool
186 UserProfileFormFields map[string]struct {
188 FormFieldTitle string
189 FormFieldDescription string
192 Options map[string]struct{}
194 UserProfileFormMessage string
198 EnableBetaController14287 bool
201 type Services struct {
204 DispatchCloud Service
214 WebDAVDownload Service
222 type Service struct {
223 InternalURLs map[URL]ServiceInstance
227 // URL is a url.URL that is also usable as a JSON key/value.
230 // UnmarshalText implements encoding.TextUnmarshaler so URL can be
231 // used as a JSON key/value.
232 func (su *URL) UnmarshalText(text []byte) error {
233 u, err := url.Parse(string(text))
240 func (su URL) MarshalText() ([]byte, error) {
241 return []byte(fmt.Sprintf("%s", (*url.URL)(&su).String())), nil
244 type ServiceInstance struct{}
246 type PostgreSQL struct {
247 Connection PostgreSQLConnection
251 type PostgreSQLConnection map[string]string
253 type RemoteCluster struct {
261 type InstanceType struct {
267 IncludedScratch ByteSize
268 AddedScratch ByteSize
273 type ContainersConfig struct {
274 CloudVMs CloudVMsConfig
275 CrunchRunCommand string
276 CrunchRunArgumentsList []string
277 DefaultKeepCacheRAM ByteSize
278 DispatchPrivateKey string
279 LogReuseDecisions bool
281 MaxDispatchAttempts int
283 MinRetryPeriod Duration
284 ReserveExtraRAM ByteSize
285 StaleLockTimeout Duration
286 SupportedDockerImageFormats StringSet
287 UsePreemptibleInstances bool
291 GitInternalDir string
296 LogSecondsBetweenEvents int
297 LogThrottlePeriod Duration
300 LimitLogBytesPerJob int
301 LogPartialLineThrottlePeriod Duration
302 LogUpdatePeriod Duration
303 LogUpdateSize ByteSize
307 SbatchArgumentsList []string
308 SbatchEnvironmentVariables map[string]string
310 DNSServerConfDir string
311 DNSServerConfTemplate string
312 DNSServerReloadCommand string
313 DNSServerUpdateCommand string
314 ComputeNodeDomain string
315 ComputeNodeNameservers StringSet
316 AssignNodeHostname string
321 type CloudVMsConfig struct {
324 BootProbeCommand string
326 MaxCloudOpsPerSecond int
327 MaxProbesPerSecond int
328 PollInterval Duration
329 ProbeInterval Duration
331 SyncInterval Duration
332 TimeoutBooting Duration
334 TimeoutProbe Duration
335 TimeoutShutdown Duration
336 TimeoutSignal Duration
338 ResourceTags map[string]string
342 DriverParameters json.RawMessage
345 type InstanceTypeMap map[string]InstanceType
347 var errDuplicateInstanceTypeName = errors.New("duplicate instance type name")
349 // UnmarshalJSON handles old config files that provide an array of
350 // instance types instead of a hash.
351 func (it *InstanceTypeMap) UnmarshalJSON(data []byte) error {
352 if len(data) > 0 && data[0] == '[' {
353 var arr []InstanceType
354 err := json.Unmarshal(data, &arr)
362 *it = make(map[string]InstanceType, len(arr))
363 for _, t := range arr {
364 if _, ok := (*it)[t.Name]; ok {
365 return errDuplicateInstanceTypeName
367 if t.ProviderType == "" {
368 t.ProviderType = t.Name
371 t.Scratch = t.IncludedScratch + t.AddedScratch
372 } else if t.AddedScratch == 0 {
373 t.AddedScratch = t.Scratch - t.IncludedScratch
374 } else if t.IncludedScratch == 0 {
375 t.IncludedScratch = t.Scratch - t.AddedScratch
378 if t.Scratch != (t.IncludedScratch + t.AddedScratch) {
379 return fmt.Errorf("%v: Scratch != (IncludedScratch + AddedScratch)", t.Name)
385 var hash map[string]InstanceType
386 err := json.Unmarshal(data, &hash)
390 // Fill in Name field (and ProviderType field, if not
391 // specified) using hash key.
392 *it = InstanceTypeMap(hash)
393 for name, t := range *it {
395 if t.ProviderType == "" {
396 t.ProviderType = name
403 type StringSet map[string]struct{}
405 // UnmarshalJSON handles old config files that provide an array of
406 // instance types instead of a hash.
407 func (ss *StringSet) UnmarshalJSON(data []byte) error {
408 if len(data) > 0 && data[0] == '[' {
410 err := json.Unmarshal(data, &arr)
418 *ss = make(map[string]struct{}, len(arr))
419 for _, t := range arr {
420 (*ss)[t] = struct{}{}
424 var hash map[string]struct{}
425 err := json.Unmarshal(data, &hash)
429 *ss = make(map[string]struct{}, len(hash))
430 for t, _ := range hash {
431 (*ss)[t] = struct{}{}
437 type ServiceName string
440 ServiceNameRailsAPI ServiceName = "arvados-api-server"
441 ServiceNameController ServiceName = "arvados-controller"
442 ServiceNameDispatchCloud ServiceName = "arvados-dispatch-cloud"
443 ServiceNameHealth ServiceName = "arvados-health"
444 ServiceNameNodemanager ServiceName = "arvados-node-manager"
445 ServiceNameWorkbench1 ServiceName = "arvados-workbench1"
446 ServiceNameWorkbench2 ServiceName = "arvados-workbench2"
447 ServiceNameWebsocket ServiceName = "arvados-ws"
448 ServiceNameKeepbalance ServiceName = "keep-balance"
449 ServiceNameKeepweb ServiceName = "keep-web"
450 ServiceNameKeepproxy ServiceName = "keepproxy"
451 ServiceNameKeepstore ServiceName = "keepstore"
454 // Map returns all services as a map, suitable for iterating over all
455 // services or looking up a service by name.
456 func (svcs Services) Map() map[ServiceName]Service {
457 return map[ServiceName]Service{
458 ServiceNameRailsAPI: svcs.RailsAPI,
459 ServiceNameController: svcs.Controller,
460 ServiceNameDispatchCloud: svcs.DispatchCloud,
461 ServiceNameHealth: svcs.Health,
462 ServiceNameNodemanager: svcs.Nodemanager,
463 ServiceNameWorkbench1: svcs.Workbench1,
464 ServiceNameWorkbench2: svcs.Workbench2,
465 ServiceNameWebsocket: svcs.Websocket,
466 ServiceNameKeepbalance: svcs.Keepbalance,
467 ServiceNameKeepweb: svcs.WebDAV,
468 ServiceNameKeepproxy: svcs.Keepproxy,
469 ServiceNameKeepstore: svcs.Keepstore,