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
126 BlobMissingReport string
127 BalancePeriod Duration
128 BalanceCollectionBatch int
129 BalanceCollectionBuffers int
130 BalanceTimeout Duration
132 WebDAVCache WebDAVCacheConfig
147 SearchAttribute string
148 SearchBindUser string
149 SearchBindPassword string
152 EmailAttribute string
153 UsernameAttribute string
159 AlternateEmailAddresses bool
161 OpenIDConnect struct {
167 EmailVerifiedClaim string
173 DefaultEmailDomain string
178 ProviderAppSecret string
181 RemoteTokenRefresh Duration
182 TokenLifetime Duration
185 MailchimpAPIKey string
186 MailchimpListID string
187 SendUserSetupNotificationEmail bool
188 IssueReporterEmailFrom string
189 IssueReporterEmailTo string
190 SupportEmailAddress string
196 MaxRequestLogParamsSize int
204 AnonymousUserToken string
205 AdminNotifierEmailFrom string
206 AutoAdminFirstUser bool
207 AutoAdminUserWithEmail string
208 AutoSetupNewUsers bool
209 AutoSetupNewUsersWithRepository bool
210 AutoSetupNewUsersWithVmUUID string
211 AutoSetupUsernameBlacklist StringSet
212 EmailSubjectPrefix string
213 NewInactiveUserNotificationRecipients StringSet
214 NewUserNotificationRecipients StringSet
215 NewUsersAreActive bool
216 UserNotifierEmailFrom string
217 UserProfileNotificationAddress string
218 PreferDomainForUsername string
220 Volumes map[string]Volume
222 ActivationContactLink string
223 APIClientConnectTimeout Duration
224 APIClientReceiveTimeout Duration
225 APIResponseCompression bool
226 ApplicationMimetypesWithViewIcon StringSet
227 ArvadosDocsite string
228 ArvadosPublicDataDocURL string
229 DefaultOpenIdPrefix string
230 EnableGettingStartedPopup bool
231 EnablePublicProjectsPage bool
232 FileViewersConfigURL string
233 LogViewerMaxBytes ByteSize
234 MultiSiteSearch string
235 ProfilingEnabled bool
237 RepositoryCache string
238 RunningJobLogRecordsToFetch int
240 ShowRecentCollectionsOnDashboard bool
241 ShowUserAgreementInline bool
242 ShowUserNotifications bool
245 UserProfileFormFields map[string]struct {
247 FormFieldTitle string
248 FormFieldDescription string
251 Options map[string]struct{}
253 UserProfileFormMessage string
255 WelcomePageHTML string
256 InactivePageHTML string
257 SSHHelpPageHTML string
258 SSHHelpHostSuffix string
261 ForceLegacyAPI14 bool
265 AccessViaHosts map[URL]VolumeAccess
268 StorageClasses map[string]bool
270 DriverParameters json.RawMessage
273 type S3VolumeDriverParameters struct {
280 LocationConstraint bool
282 UseAWSS3v2Driver bool
284 ConnectTimeout Duration
290 type AzureVolumeDriverParameters struct {
291 StorageAccountName string
292 StorageAccountKey string
293 StorageBaseURL string
295 RequestTimeout Duration
296 ListBlobsRetryDelay Duration
297 ListBlobsMaxAttempts int
300 type DirectoryVolumeDriverParameters struct {
305 type VolumeAccess struct {
309 type Services struct {
312 DispatchCloud Service
321 WebDAVDownload Service
329 type Service struct {
330 InternalURLs map[URL]ServiceInstance
334 // URL is a url.URL that is also usable as a JSON key/value.
337 // UnmarshalText implements encoding.TextUnmarshaler so URL can be
338 // used as a JSON key/value.
339 func (su *URL) UnmarshalText(text []byte) error {
340 u, err := url.Parse(string(text))
343 if su.Path == "" && su.Host != "" {
344 // http://example really means http://example/
351 func (su URL) MarshalText() ([]byte, error) {
352 return []byte(fmt.Sprintf("%s", (*url.URL)(&su).String())), nil
355 func (su URL) String() string {
356 return (*url.URL)(&su).String()
359 type ServiceInstance struct {
360 Rendezvous string `json:",omitempty"`
363 type PostgreSQL struct {
364 Connection PostgreSQLConnection
368 type PostgreSQLConnection map[string]string
370 type RemoteCluster struct {
378 type InstanceType struct {
384 IncludedScratch ByteSize
385 AddedScratch ByteSize
390 type ContainersConfig struct {
391 CloudVMs CloudVMsConfig
392 CrunchRunCommand string
393 CrunchRunArgumentsList []string
394 DefaultKeepCacheRAM ByteSize
395 DispatchPrivateKey string
396 LogReuseDecisions bool
398 MaxDispatchAttempts int
400 MinRetryPeriod Duration
401 ReserveExtraRAM ByteSize
402 StaleLockTimeout Duration
403 SupportedDockerImageFormats StringSet
404 UsePreemptibleInstances bool
408 GitInternalDir string
413 LogSecondsBetweenEvents Duration
414 LogThrottlePeriod Duration
417 LimitLogBytesPerJob int
418 LogPartialLineThrottlePeriod Duration
419 LogUpdatePeriod Duration
420 LogUpdateSize ByteSize
424 SbatchArgumentsList []string
425 SbatchEnvironmentVariables map[string]string
427 DNSServerConfDir string
428 DNSServerConfTemplate string
429 DNSServerReloadCommand string
430 DNSServerUpdateCommand string
431 ComputeNodeDomain string
432 ComputeNodeNameservers StringSet
433 AssignNodeHostname string
438 type CloudVMsConfig struct {
441 BootProbeCommand string
442 DeployRunnerBinary string
444 MaxCloudOpsPerSecond int
445 MaxProbesPerSecond int
446 PollInterval Duration
447 ProbeInterval Duration
449 SyncInterval Duration
450 TimeoutBooting Duration
452 TimeoutProbe Duration
453 TimeoutShutdown Duration
454 TimeoutSignal Duration
456 ResourceTags map[string]string
460 DriverParameters json.RawMessage
463 type InstanceTypeMap map[string]InstanceType
465 var errDuplicateInstanceTypeName = errors.New("duplicate instance type name")
467 // UnmarshalJSON handles old config files that provide an array of
468 // instance types instead of a hash.
469 func (it *InstanceTypeMap) UnmarshalJSON(data []byte) error {
470 fixup := func(t InstanceType) (InstanceType, error) {
471 if t.ProviderType == "" {
472 t.ProviderType = t.Name
475 t.Scratch = t.IncludedScratch + t.AddedScratch
476 } else if t.AddedScratch == 0 {
477 t.AddedScratch = t.Scratch - t.IncludedScratch
478 } else if t.IncludedScratch == 0 {
479 t.IncludedScratch = t.Scratch - t.AddedScratch
482 if t.Scratch != (t.IncludedScratch + t.AddedScratch) {
483 return t, fmt.Errorf("InstanceType %q: Scratch != (IncludedScratch + AddedScratch)", t.Name)
488 if len(data) > 0 && data[0] == '[' {
489 var arr []InstanceType
490 err := json.Unmarshal(data, &arr)
498 *it = make(map[string]InstanceType, len(arr))
499 for _, t := range arr {
500 if _, ok := (*it)[t.Name]; ok {
501 return errDuplicateInstanceTypeName
511 var hash map[string]InstanceType
512 err := json.Unmarshal(data, &hash)
516 // Fill in Name field (and ProviderType field, if not
517 // specified) using hash key.
518 *it = InstanceTypeMap(hash)
519 for name, t := range *it {
530 type StringSet map[string]struct{}
532 // UnmarshalJSON handles old config files that provide an array of
533 // instance types instead of a hash.
534 func (ss *StringSet) UnmarshalJSON(data []byte) error {
535 if len(data) > 0 && data[0] == '[' {
537 err := json.Unmarshal(data, &arr)
545 *ss = make(map[string]struct{}, len(arr))
546 for _, t := range arr {
547 (*ss)[t] = struct{}{}
551 var hash map[string]struct{}
552 err := json.Unmarshal(data, &hash)
556 *ss = make(map[string]struct{}, len(hash))
557 for t := range hash {
558 (*ss)[t] = struct{}{}
564 type ServiceName string
567 ServiceNameRailsAPI ServiceName = "arvados-api-server"
568 ServiceNameController ServiceName = "arvados-controller"
569 ServiceNameDispatchCloud ServiceName = "arvados-dispatch-cloud"
570 ServiceNameHealth ServiceName = "arvados-health"
571 ServiceNameWorkbench1 ServiceName = "arvados-workbench1"
572 ServiceNameWorkbench2 ServiceName = "arvados-workbench2"
573 ServiceNameWebsocket ServiceName = "arvados-ws"
574 ServiceNameKeepbalance ServiceName = "keep-balance"
575 ServiceNameKeepweb ServiceName = "keep-web"
576 ServiceNameKeepproxy ServiceName = "keepproxy"
577 ServiceNameKeepstore ServiceName = "keepstore"
580 // Map returns all services as a map, suitable for iterating over all
581 // services or looking up a service by name.
582 func (svcs Services) Map() map[ServiceName]Service {
583 return map[ServiceName]Service{
584 ServiceNameRailsAPI: svcs.RailsAPI,
585 ServiceNameController: svcs.Controller,
586 ServiceNameDispatchCloud: svcs.DispatchCloud,
587 ServiceNameHealth: svcs.Health,
588 ServiceNameWorkbench1: svcs.Workbench1,
589 ServiceNameWorkbench2: svcs.Workbench2,
590 ServiceNameWebsocket: svcs.Websocket,
591 ServiceNameKeepbalance: svcs.Keepbalance,
592 ServiceNameKeepweb: svcs.WebDAV,
593 ServiceNameKeepproxy: svcs.Keepproxy,
594 ServiceNameKeepstore: svcs.Keepstore,