1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: Apache-2.0
16 "git.arvados.org/arvados.git/sdk/go/config"
19 var DefaultConfigFile = func() string {
20 if path := os.Getenv("ARVADOS_CONFIG"); path != "" {
23 return "/etc/arvados/config.yml"
27 Clusters map[string]Cluster
29 SourceTimestamp time.Time
33 // GetConfig returns the current system config, loading it from
34 // configFile if needed.
35 func GetConfig(configFile string) (*Config, error) {
37 err := config.LoadFile(&cfg, configFile)
41 // GetCluster returns the cluster ID and config for the given
42 // cluster, or the default/only configured cluster if clusterID is "".
43 func (sc *Config) GetCluster(clusterID string) (*Cluster, error) {
45 if len(sc.Clusters) == 0 {
46 return nil, fmt.Errorf("no clusters configured")
47 } else if len(sc.Clusters) > 1 {
48 return nil, fmt.Errorf("multiple clusters configured, cannot choose")
50 for id, cc := range sc.Clusters {
56 cc, ok := sc.Clusters[clusterID]
58 return nil, fmt.Errorf("cluster %q is not configured", clusterID)
60 cc.ClusterID = clusterID
64 type WebDAVCacheConfig struct {
66 DiskCacheSize ByteSizeOrPercent
67 MaxCollectionBytes ByteSize
71 type UploadDownloadPermission struct {
76 type UploadDownloadRolePermissions struct {
77 User UploadDownloadPermission
78 Admin UploadDownloadPermission
81 type ManagedProperties map[string]struct {
88 ClusterID string `json:"-"`
89 ManagementToken string
90 SystemRootToken string
92 InstanceTypes InstanceTypeMap
93 Containers ContainersConfig
94 RemoteClusters map[string]RemoteCluster
98 AsyncPermissionsUpdateInterval Duration
99 DisabledAPIs StringSet
100 MaxIndexDatabaseRead int
101 MaxItemsPerResponse int
102 MaxConcurrentRailsRequests int
103 MaxConcurrentRequests int
104 MaxQueuedRequests int
105 MaxGatewayTunnels int
106 MaxQueueTimeForLockRequests Duration
107 LogCreateRequestFraction float64
108 MaxKeepBlobBuffers int
109 MaxRequestAmplification int
111 MaxTokenLifetime Duration
112 RequestTimeout Duration
114 WebsocketClientEventQueue int
115 WebsocketServerEventQueue int
116 KeepServiceRequestTimeout Duration
117 VocabularyPath string
118 FreezeProjectRequiresDescription bool
119 FreezeProjectRequiresProperties StringSet
120 UnfreezeProjectRequiresAdmin bool
121 LockBeforeUpdate bool
126 UnloggedAttributes StringSet
130 BlobSigningKey string
131 BlobSigningTTL Duration
133 BlobTrashLifetime Duration
134 BlobTrashCheckInterval Duration
135 BlobTrashConcurrency int
136 BlobDeleteConcurrency int
137 BlobReplicateConcurrency int
138 CollectionVersioning bool
139 DefaultTrashLifetime Duration
140 DefaultReplication int
141 ManagedProperties ManagedProperties
142 PreserveVersionIfIdle Duration
143 TrashSweepInterval Duration
145 ForwardSlashNameSubstitution string
148 BlobMissingReport string
149 BalancePeriod Duration
150 BalanceCollectionBatch int
151 BalanceCollectionBuffers int
152 BalanceTimeout Duration
153 BalanceUpdateLimit int
155 BalanceTrashLimit int
157 WebDAVCache WebDAVCacheConfig
159 KeepproxyPermission UploadDownloadRolePermissions
160 WebDAVPermission UploadDownloadRolePermissions
162 WebDAVOutputBuffer ByteSize
170 MinTLSVersion TLSVersion
173 SearchAttribute string
174 SearchBindUser string
175 SearchBindPassword string
178 EmailAttribute string
179 UsernameAttribute string
185 AlternateEmailAddresses bool
186 AuthenticationRequestParameters map[string]string
188 OpenIDConnect struct {
194 EmailVerifiedClaim string
196 AcceptAccessToken bool
197 AcceptAccessTokenScope string
198 AuthenticationRequestParameters map[string]string
203 DefaultEmailDomain string
207 Users map[string]TestUser
210 RemoteTokenRefresh Duration
211 TokenLifetime Duration
212 TrustedClients map[URL]struct{}
213 TrustPrivateNetworks bool
214 IssueTrustedTokens bool
217 MailchimpAPIKey string
218 MailchimpListID string
219 SendUserSetupNotificationEmail bool
220 IssueReporterEmailFrom string
221 IssueReporterEmailTo string
222 SupportEmailAddress string
228 MaxRequestLogParamsSize int
229 RequestQueueDumpDirectory string
240 ActivatedUsersAreVisibleToOthers bool
241 AnonymousUserToken string
242 AdminNotifierEmailFrom string
243 AutoAdminFirstUser bool
244 AutoAdminUserWithEmail string
245 AutoSetupNewUsers bool
246 AutoSetupNewUsersWithVmUUID string
247 AutoSetupUsernameBlacklist StringSet
248 EmailSubjectPrefix string
249 NewInactiveUserNotificationRecipients StringSet
250 NewUserNotificationRecipients StringSet
251 NewUsersAreActive bool
252 UserNotifierEmailFrom string
253 UserNotifierEmailBcc StringSet
254 UserProfileNotificationAddress string
255 PreferDomainForUsername string
256 UserSetupMailText string
257 RoleGroupsVisibleToAll bool
258 CanCreateRoleGroups bool
259 ActivityLoggingPeriod Duration
260 SyncIgnoredGroups []string
261 SyncRequiredGroups []string
262 SyncUserAccounts bool
263 SyncUserAPITokens bool
267 StorageClasses map[string]StorageClassConfig
268 Volumes map[string]Volume
270 ActivationContactLink string
271 ArvadosDocsite string
272 ArvadosPublicDataDocURL string
273 DisableSharingURLsUI bool
274 FileViewersConfigURL string
275 ShowUserAgreementInline bool
278 UserProfileFormFields map[string]struct {
280 FormFieldTitle string
281 FormFieldDescription string
284 Options map[string]struct{}
286 UserProfileFormMessage string
287 WelcomePageHTML string
288 InactivePageHTML string
289 SSHHelpPageHTML string
290 SSHHelpHostSuffix string
296 type StorageClassConfig struct {
302 AccessViaHosts map[URL]VolumeAccess
304 AllowTrashWhenReadOnly bool
306 StorageClasses map[string]bool
308 DriverParameters json.RawMessage
311 type S3VolumeDriverParameters struct {
314 SecretAccessKey string
318 LocationConstraint bool
321 ConnectTimeout Duration
328 type AzureVolumeDriverParameters struct {
329 StorageAccountName string
330 StorageAccountKey string
331 StorageBaseURL string
333 RequestTimeout Duration
334 ListBlobsRetryDelay Duration
335 ListBlobsMaxAttempts int
338 type DirectoryVolumeDriverParameters struct {
343 type VolumeAccess struct {
347 type Services struct {
350 DispatchCloud Service
352 DispatchSLURM Service
358 WebDAVDownload Service
366 type Service struct {
367 InternalURLs map[URL]ServiceInstance
371 type TestUser struct {
376 // URL is a url.URL that is also usable as a JSON key/value.
379 // UnmarshalText implements encoding.TextUnmarshaler so URL can be
380 // used as a JSON key/value.
381 func (su *URL) UnmarshalText(text []byte) error {
382 u, err := url.Parse(string(text))
385 if su.Path == "" && su.Host != "" {
386 // http://example really means http://example/
393 func (su URL) MarshalText() ([]byte, error) {
394 return []byte(su.String()), nil
397 func (su URL) String() string {
398 return (*url.URL)(&su).String()
401 type TLSVersion uint16
403 func (v TLSVersion) MarshalText() ([]byte, error) {
407 case tls.VersionTLS10:
408 return []byte("1.0"), nil
409 case tls.VersionTLS11:
410 return []byte("1.1"), nil
411 case tls.VersionTLS12:
412 return []byte("1.2"), nil
413 case tls.VersionTLS13:
414 return []byte("1.3"), nil
416 return nil, fmt.Errorf("unsupported TLSVersion %x", v)
420 func (v *TLSVersion) UnmarshalJSON(text []byte) error {
421 if len(text) > 0 && text[0] == '"' {
423 err := json.Unmarshal(text, &s)
429 switch string(text) {
433 *v = tls.VersionTLS10
435 *v = tls.VersionTLS11
437 *v = tls.VersionTLS12
439 *v = tls.VersionTLS13
441 return fmt.Errorf("unsupported TLSVersion %q", text)
446 type ServiceInstance struct {
448 Rendezvous string `json:",omitempty"`
451 type PostgreSQL struct {
452 Connection PostgreSQLConnection
456 type PostgreSQLConnection map[string]string
458 type RemoteCluster struct {
466 type CUDAFeatures struct {
468 HardwareCapability string
472 type InstanceType struct {
473 Name string `json:"-"`
477 Scratch ByteSize `json:"-"`
478 IncludedScratch ByteSize
479 AddedScratch ByteSize
485 type ContainersConfig struct {
486 CloudVMs CloudVMsConfig
487 CrunchRunCommand string
488 CrunchRunArgumentsList []string
489 DefaultKeepCacheRAM ByteSize
490 DispatchPrivateKey string
491 LogReuseDecisions bool
492 MaxDispatchAttempts int
494 MinRetryPeriod Duration
495 ReserveExtraRAM ByteSize
496 StaleLockTimeout Duration
497 SupportedDockerImageFormats StringSet
498 AlwaysUsePreemptibleInstances bool
499 PreemptiblePriceFactor float64
500 MaximumPriceFactor float64
502 LocalKeepBlobBuffersPerVCPU int
503 LocalKeepLogsToContainerLog string
509 LogUpdatePeriod Duration
510 LogUpdateSize ByteSize
518 SbatchArgumentsList []string
519 SbatchEnvironmentVariables map[string]string
523 BsubArgumentsList []string
524 BsubCUDAArguments []string
525 MaxRunTimeOverhead Duration
526 MaxRunTimeDefault Duration
530 type CloudVMsConfig struct {
533 BootProbeCommand string
534 InstanceInitCommand string
535 DeployRunnerBinary string
538 MaxCloudOpsPerSecond int
539 MaxProbesPerSecond int
540 MaxConcurrentInstanceCreateOps int
542 InitialQuotaEstimate int
543 SupervisorFraction float64
544 PollInterval Duration
545 ProbeInterval Duration
547 SyncInterval Duration
548 TimeoutBooting Duration
550 TimeoutProbe Duration
551 TimeoutShutdown Duration
552 TimeoutSignal Duration
553 TimeoutStaleRunLock Duration
555 ResourceTags map[string]string
559 DriverParameters json.RawMessage
562 type InstanceTypeMap map[string]InstanceType
564 var errDuplicateInstanceTypeName = errors.New("duplicate instance type name")
566 // UnmarshalJSON does special handling of InstanceTypes:
568 // - populate computed fields (Name and Scratch)
570 // - error out if InstancesTypes are populated as an array, which was
571 // deprecated in Arvados 1.2.0
572 func (it *InstanceTypeMap) UnmarshalJSON(data []byte) error {
573 fixup := func(t InstanceType) (InstanceType, error) {
574 if t.ProviderType == "" {
575 t.ProviderType = t.Name
577 // If t.Scratch is set in the configuration file, it will be ignored and overwritten.
578 // It will also generate a "deprecated or unknown config entry" warning.
579 t.Scratch = t.IncludedScratch + t.AddedScratch
583 if len(data) > 0 && data[0] == '[' {
584 return fmt.Errorf("InstanceTypes must be specified as a map, not an array, see https://doc.arvados.org/admin/config.html")
586 var hash map[string]InstanceType
587 err := json.Unmarshal(data, &hash)
591 // Fill in Name field (and ProviderType field, if not
592 // specified) using hash key.
593 *it = InstanceTypeMap(hash)
594 for name, t := range *it {
605 type StringSet map[string]struct{}
607 // UnmarshalJSON handles old config files that provide an array of
608 // instance types instead of a hash.
609 func (ss *StringSet) UnmarshalJSON(data []byte) error {
610 if len(data) > 0 && data[0] == '[' {
612 err := json.Unmarshal(data, &arr)
620 *ss = make(map[string]struct{}, len(arr))
621 for _, t := range arr {
622 (*ss)[t] = struct{}{}
626 var hash map[string]struct{}
627 err := json.Unmarshal(data, &hash)
631 *ss = make(map[string]struct{}, len(hash))
632 for t := range hash {
633 (*ss)[t] = struct{}{}
639 type ServiceName string
642 ServiceNameController ServiceName = "arvados-controller"
643 ServiceNameDispatchCloud ServiceName = "arvados-dispatch-cloud"
644 ServiceNameDispatchLSF ServiceName = "arvados-dispatch-lsf"
645 ServiceNameDispatchSLURM ServiceName = "crunch-dispatch-slurm"
646 ServiceNameHealth ServiceName = "arvados-health"
647 ServiceNameKeepbalance ServiceName = "keep-balance"
648 ServiceNameKeepproxy ServiceName = "keepproxy"
649 ServiceNameKeepstore ServiceName = "keepstore"
650 ServiceNameKeepweb ServiceName = "keep-web"
651 ServiceNameRailsAPI ServiceName = "arvados-api-server"
652 ServiceNameWebsocket ServiceName = "arvados-ws"
653 ServiceNameWorkbench1 ServiceName = "arvados-workbench1"
654 ServiceNameWorkbench2 ServiceName = "arvados-workbench2"
657 // Map returns all services as a map, suitable for iterating over all
658 // services or looking up a service by name.
659 func (svcs Services) Map() map[ServiceName]Service {
660 return map[ServiceName]Service{
661 ServiceNameController: svcs.Controller,
662 ServiceNameDispatchCloud: svcs.DispatchCloud,
663 ServiceNameDispatchLSF: svcs.DispatchLSF,
664 ServiceNameDispatchSLURM: svcs.DispatchSLURM,
665 ServiceNameHealth: svcs.Health,
666 ServiceNameKeepbalance: svcs.Keepbalance,
667 ServiceNameKeepproxy: svcs.Keepproxy,
668 ServiceNameKeepstore: svcs.Keepstore,
669 ServiceNameKeepweb: svcs.WebDAV,
670 ServiceNameRailsAPI: svcs.RailsAPI,
671 ServiceNameWebsocket: svcs.Websocket,
672 ServiceNameWorkbench1: svcs.Workbench1,
673 ServiceNameWorkbench2: svcs.Workbench2,