1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: Apache-2.0
14 "git.arvados.org/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
30 // GetConfig returns the current system config, loading it from
31 // configFile if needed.
32 func GetConfig(configFile string) (*Config, error) {
34 err := config.LoadFile(&cfg, configFile)
38 // GetCluster returns the cluster ID and config for the given
39 // cluster, or the default/only configured cluster if clusterID is "".
40 func (sc *Config) GetCluster(clusterID string) (*Cluster, error) {
42 if len(sc.Clusters) == 0 {
43 return nil, fmt.Errorf("no clusters configured")
44 } else if len(sc.Clusters) > 1 {
45 return nil, fmt.Errorf("multiple clusters configured, cannot choose")
47 for id, cc := range sc.Clusters {
53 if cc, ok := sc.Clusters[clusterID]; !ok {
54 return nil, fmt.Errorf("cluster %q is not configured", clusterID)
56 cc.ClusterID = clusterID
61 type WebDAVCacheConfig struct {
65 MaxCollectionEntries int
66 MaxCollectionBytes int64
67 MaxPermissionEntries int
72 ClusterID string `json:"-"`
73 ManagementToken string
74 SystemRootToken string
76 InstanceTypes InstanceTypeMap
77 Containers ContainersConfig
78 RemoteClusters map[string]RemoteCluster
82 AsyncPermissionsUpdateInterval Duration
83 DisabledAPIs StringSet
84 MaxIndexDatabaseRead int
85 MaxItemsPerResponse int
86 MaxConcurrentRequests int
87 MaxKeepBlobBuffers int
88 MaxRequestAmplification int
90 RailsSessionSecretToken string
91 RequestTimeout Duration
93 WebsocketClientEventQueue int
94 WebsocketServerEventQueue int
95 KeepServiceRequestTimeout Duration
100 UnloggedAttributes StringSet
104 BlobSigningKey string
105 BlobSigningTTL Duration
107 BlobTrashLifetime Duration
108 BlobTrashCheckInterval Duration
109 BlobTrashConcurrency int
110 BlobDeleteConcurrency int
111 BlobReplicateConcurrency int
112 CollectionVersioning bool
113 DefaultTrashLifetime Duration
114 DefaultReplication int
115 ManagedProperties map[string]struct {
120 PreserveVersionIfIdle Duration
121 TrashSweepInterval Duration
123 ForwardSlashNameSubstitution string
125 BlobMissingReport string
126 BalancePeriod Duration
127 BalanceCollectionBatch int
128 BalanceCollectionBuffers int
129 BalanceTimeout Duration
131 WebDAVCache WebDAVCacheConfig
146 SearchAttribute string
147 SearchBindUser string
148 SearchBindPassword string
151 EmailAttribute string
152 UsernameAttribute string
158 AlternateEmailAddresses bool
160 OpenIDConnect struct {
169 DefaultEmailDomain string
174 ProviderAppSecret string
177 RemoteTokenRefresh Duration
180 MailchimpAPIKey string
181 MailchimpListID string
182 SendUserSetupNotificationEmail bool
183 IssueReporterEmailFrom string
184 IssueReporterEmailTo string
185 SupportEmailAddress string
191 MaxRequestLogParamsSize int
199 AnonymousUserToken string
200 AdminNotifierEmailFrom string
201 AutoAdminFirstUser bool
202 AutoAdminUserWithEmail string
203 AutoSetupNewUsers bool
204 AutoSetupNewUsersWithRepository bool
205 AutoSetupNewUsersWithVmUUID string
206 AutoSetupUsernameBlacklist StringSet
207 EmailSubjectPrefix string
208 NewInactiveUserNotificationRecipients StringSet
209 NewUserNotificationRecipients StringSet
210 NewUsersAreActive bool
211 UserNotifierEmailFrom string
212 UserProfileNotificationAddress string
213 PreferDomainForUsername string
215 Volumes map[string]Volume
217 ActivationContactLink string
218 APIClientConnectTimeout Duration
219 APIClientReceiveTimeout Duration
220 APIResponseCompression bool
221 ApplicationMimetypesWithViewIcon StringSet
222 ArvadosDocsite string
223 ArvadosPublicDataDocURL string
224 DefaultOpenIdPrefix string
225 EnableGettingStartedPopup bool
226 EnablePublicProjectsPage bool
227 FileViewersConfigURL string
228 LogViewerMaxBytes ByteSize
229 MultiSiteSearch string
230 ProfilingEnabled bool
232 RepositoryCache string
233 RunningJobLogRecordsToFetch int
235 ShowRecentCollectionsOnDashboard bool
236 ShowUserAgreementInline bool
237 ShowUserNotifications bool
240 UserProfileFormFields map[string]struct {
242 FormFieldTitle string
243 FormFieldDescription string
246 Options map[string]struct{}
248 UserProfileFormMessage string
250 WelcomePageHTML string
251 InactivePageHTML string
252 SSHHelpPageHTML string
253 SSHHelpHostSuffix string
256 ForceLegacyAPI14 bool
260 AccessViaHosts map[URL]VolumeAccess
263 StorageClasses map[string]bool
265 DriverParameters json.RawMessage
268 type S3VolumeDriverParameters struct {
275 LocationConstraint bool
278 ConnectTimeout Duration
284 type AzureVolumeDriverParameters struct {
285 StorageAccountName string
286 StorageAccountKey string
287 StorageBaseURL string
289 RequestTimeout Duration
290 ListBlobsRetryDelay Duration
291 ListBlobsMaxAttempts int
294 type DirectoryVolumeDriverParameters struct {
299 type VolumeAccess struct {
303 type Services struct {
306 DispatchCloud Service
316 WebDAVDownload Service
324 type Service struct {
325 InternalURLs map[URL]ServiceInstance
329 // URL is a url.URL that is also usable as a JSON key/value.
332 // UnmarshalText implements encoding.TextUnmarshaler so URL can be
333 // used as a JSON key/value.
334 func (su *URL) UnmarshalText(text []byte) error {
335 u, err := url.Parse(string(text))
338 if su.Path == "" && su.Host != "" {
339 // http://example really means http://example/
346 func (su URL) MarshalText() ([]byte, error) {
347 return []byte(fmt.Sprintf("%s", (*url.URL)(&su).String())), nil
350 func (su URL) String() string {
351 return (*url.URL)(&su).String()
354 type ServiceInstance struct {
355 Rendezvous string `json:",omitempty"`
358 type PostgreSQL struct {
359 Connection PostgreSQLConnection
363 type PostgreSQLConnection map[string]string
365 type RemoteCluster struct {
373 type InstanceType struct {
379 IncludedScratch ByteSize
380 AddedScratch ByteSize
385 type ContainersConfig struct {
386 CloudVMs CloudVMsConfig
387 CrunchRunCommand string
388 CrunchRunArgumentsList []string
389 DefaultKeepCacheRAM ByteSize
390 DispatchPrivateKey string
391 LogReuseDecisions bool
393 MaxDispatchAttempts int
395 MinRetryPeriod Duration
396 ReserveExtraRAM ByteSize
397 StaleLockTimeout Duration
398 SupportedDockerImageFormats StringSet
399 UsePreemptibleInstances bool
403 GitInternalDir string
408 LogSecondsBetweenEvents Duration
409 LogThrottlePeriod Duration
412 LimitLogBytesPerJob int
413 LogPartialLineThrottlePeriod Duration
414 LogUpdatePeriod Duration
415 LogUpdateSize ByteSize
419 SbatchArgumentsList []string
420 SbatchEnvironmentVariables map[string]string
422 DNSServerConfDir string
423 DNSServerConfTemplate string
424 DNSServerReloadCommand string
425 DNSServerUpdateCommand string
426 ComputeNodeDomain string
427 ComputeNodeNameservers StringSet
428 AssignNodeHostname string
433 type CloudVMsConfig struct {
436 BootProbeCommand string
437 DeployRunnerBinary string
439 MaxCloudOpsPerSecond int
440 MaxProbesPerSecond int
441 PollInterval Duration
442 ProbeInterval Duration
444 SyncInterval Duration
445 TimeoutBooting Duration
447 TimeoutProbe Duration
448 TimeoutShutdown Duration
449 TimeoutSignal Duration
451 ResourceTags map[string]string
455 DriverParameters json.RawMessage
458 type InstanceTypeMap map[string]InstanceType
460 var errDuplicateInstanceTypeName = errors.New("duplicate instance type name")
462 // UnmarshalJSON handles old config files that provide an array of
463 // instance types instead of a hash.
464 func (it *InstanceTypeMap) UnmarshalJSON(data []byte) error {
465 fixup := func(t InstanceType) (InstanceType, error) {
466 if t.ProviderType == "" {
467 t.ProviderType = t.Name
470 t.Scratch = t.IncludedScratch + t.AddedScratch
471 } else if t.AddedScratch == 0 {
472 t.AddedScratch = t.Scratch - t.IncludedScratch
473 } else if t.IncludedScratch == 0 {
474 t.IncludedScratch = t.Scratch - t.AddedScratch
477 if t.Scratch != (t.IncludedScratch + t.AddedScratch) {
478 return t, fmt.Errorf("InstanceType %q: Scratch != (IncludedScratch + AddedScratch)", t.Name)
483 if len(data) > 0 && data[0] == '[' {
484 var arr []InstanceType
485 err := json.Unmarshal(data, &arr)
493 *it = make(map[string]InstanceType, len(arr))
494 for _, t := range arr {
495 if _, ok := (*it)[t.Name]; ok {
496 return errDuplicateInstanceTypeName
506 var hash map[string]InstanceType
507 err := json.Unmarshal(data, &hash)
511 // Fill in Name field (and ProviderType field, if not
512 // specified) using hash key.
513 *it = InstanceTypeMap(hash)
514 for name, t := range *it {
525 type StringSet map[string]struct{}
527 // UnmarshalJSON handles old config files that provide an array of
528 // instance types instead of a hash.
529 func (ss *StringSet) UnmarshalJSON(data []byte) error {
530 if len(data) > 0 && data[0] == '[' {
532 err := json.Unmarshal(data, &arr)
540 *ss = make(map[string]struct{}, len(arr))
541 for _, t := range arr {
542 (*ss)[t] = struct{}{}
546 var hash map[string]struct{}
547 err := json.Unmarshal(data, &hash)
551 *ss = make(map[string]struct{}, len(hash))
552 for t, _ := range hash {
553 (*ss)[t] = struct{}{}
559 type ServiceName string
562 ServiceNameRailsAPI ServiceName = "arvados-api-server"
563 ServiceNameController ServiceName = "arvados-controller"
564 ServiceNameDispatchCloud ServiceName = "arvados-dispatch-cloud"
565 ServiceNameHealth ServiceName = "arvados-health"
566 ServiceNameNodemanager ServiceName = "arvados-node-manager"
567 ServiceNameWorkbench1 ServiceName = "arvados-workbench1"
568 ServiceNameWorkbench2 ServiceName = "arvados-workbench2"
569 ServiceNameWebsocket ServiceName = "arvados-ws"
570 ServiceNameKeepbalance ServiceName = "keep-balance"
571 ServiceNameKeepweb ServiceName = "keep-web"
572 ServiceNameKeepproxy ServiceName = "keepproxy"
573 ServiceNameKeepstore ServiceName = "keepstore"
576 // Map returns all services as a map, suitable for iterating over all
577 // services or looking up a service by name.
578 func (svcs Services) Map() map[ServiceName]Service {
579 return map[ServiceName]Service{
580 ServiceNameRailsAPI: svcs.RailsAPI,
581 ServiceNameController: svcs.Controller,
582 ServiceNameDispatchCloud: svcs.DispatchCloud,
583 ServiceNameHealth: svcs.Health,
584 ServiceNameNodemanager: svcs.Nodemanager,
585 ServiceNameWorkbench1: svcs.Workbench1,
586 ServiceNameWorkbench2: svcs.Workbench2,
587 ServiceNameWebsocket: svcs.Websocket,
588 ServiceNameKeepbalance: svcs.Keepbalance,
589 ServiceNameKeepweb: svcs.WebDAV,
590 ServiceNameKeepproxy: svcs.Keepproxy,
591 ServiceNameKeepstore: svcs.Keepstore,