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 {
313 SecretAccessKey string
317 LocationConstraint bool
320 ConnectTimeout Duration
327 type AzureVolumeDriverParameters struct {
328 StorageAccountName string
329 StorageAccountKey string
330 StorageBaseURL string
332 RequestTimeout Duration
333 ListBlobsRetryDelay Duration
334 ListBlobsMaxAttempts int
337 type DirectoryVolumeDriverParameters struct {
342 type VolumeAccess struct {
346 type Services struct {
349 DispatchCloud Service
351 DispatchSLURM Service
357 WebDAVDownload Service
365 type Service struct {
366 InternalURLs map[URL]ServiceInstance
370 type TestUser struct {
375 // URL is a url.URL that is also usable as a JSON key/value.
378 // UnmarshalText implements encoding.TextUnmarshaler so URL can be
379 // used as a JSON key/value.
380 func (su *URL) UnmarshalText(text []byte) error {
381 u, err := url.Parse(string(text))
384 if su.Path == "" && su.Host != "" {
385 // http://example really means http://example/
392 func (su URL) MarshalText() ([]byte, error) {
393 return []byte(su.String()), nil
396 func (su URL) String() string {
397 return (*url.URL)(&su).String()
400 type TLSVersion uint16
402 func (v TLSVersion) MarshalText() ([]byte, error) {
406 case tls.VersionTLS10:
407 return []byte("1.0"), nil
408 case tls.VersionTLS11:
409 return []byte("1.1"), nil
410 case tls.VersionTLS12:
411 return []byte("1.2"), nil
412 case tls.VersionTLS13:
413 return []byte("1.3"), nil
415 return nil, fmt.Errorf("unsupported TLSVersion %x", v)
419 func (v *TLSVersion) UnmarshalJSON(text []byte) error {
420 if len(text) > 0 && text[0] == '"' {
422 err := json.Unmarshal(text, &s)
428 switch string(text) {
432 *v = tls.VersionTLS10
434 *v = tls.VersionTLS11
436 *v = tls.VersionTLS12
438 *v = tls.VersionTLS13
440 return fmt.Errorf("unsupported TLSVersion %q", text)
445 type ServiceInstance struct {
447 Rendezvous string `json:",omitempty"`
450 type PostgreSQL struct {
451 Connection PostgreSQLConnection
455 type PostgreSQLConnection map[string]string
457 type RemoteCluster struct {
465 type CUDAFeatures struct {
467 HardwareCapability string
471 type InstanceType struct {
472 Name string `json:"-"`
476 Scratch ByteSize `json:"-"`
477 IncludedScratch ByteSize
478 AddedScratch ByteSize
484 type ContainersConfig struct {
485 CloudVMs CloudVMsConfig
486 CrunchRunCommand string
487 CrunchRunArgumentsList []string
488 DefaultKeepCacheRAM ByteSize
489 DispatchPrivateKey string
490 LogReuseDecisions bool
491 MaxDispatchAttempts int
493 MinRetryPeriod Duration
494 ReserveExtraRAM ByteSize
495 StaleLockTimeout Duration
496 SupportedDockerImageFormats StringSet
497 AlwaysUsePreemptibleInstances bool
498 PreemptiblePriceFactor float64
499 MaximumPriceFactor float64
501 LocalKeepBlobBuffersPerVCPU int
502 LocalKeepLogsToContainerLog string
508 LogUpdatePeriod Duration
509 LogUpdateSize ByteSize
517 SbatchArgumentsList []string
518 SbatchEnvironmentVariables map[string]string
522 BsubArgumentsList []string
523 BsubCUDAArguments []string
524 MaxRunTimeOverhead Duration
525 MaxRunTimeDefault Duration
529 type CloudVMsConfig struct {
532 BootProbeCommand string
533 InstanceInitCommand string
534 DeployRunnerBinary string
537 MaxCloudOpsPerSecond int
538 MaxProbesPerSecond int
539 MaxConcurrentInstanceCreateOps int
541 InitialQuotaEstimate int
542 SupervisorFraction float64
543 PollInterval Duration
544 ProbeInterval Duration
546 SyncInterval Duration
547 TimeoutBooting Duration
549 TimeoutProbe Duration
550 TimeoutShutdown Duration
551 TimeoutSignal Duration
552 TimeoutStaleRunLock Duration
554 ResourceTags map[string]string
558 DriverParameters json.RawMessage
561 type InstanceTypeMap map[string]InstanceType
563 var errDuplicateInstanceTypeName = errors.New("duplicate instance type name")
565 // UnmarshalJSON does special handling of InstanceTypes:
567 // - populate computed fields (Name and Scratch)
569 // - error out if InstancesTypes are populated as an array, which was
570 // deprecated in Arvados 1.2.0
571 func (it *InstanceTypeMap) UnmarshalJSON(data []byte) error {
572 fixup := func(t InstanceType) (InstanceType, error) {
573 if t.ProviderType == "" {
574 t.ProviderType = t.Name
576 // If t.Scratch is set in the configuration file, it will be ignored and overwritten.
577 // It will also generate a "deprecated or unknown config entry" warning.
578 t.Scratch = t.IncludedScratch + t.AddedScratch
582 if len(data) > 0 && data[0] == '[' {
583 return fmt.Errorf("InstanceTypes must be specified as a map, not an array, see https://doc.arvados.org/admin/config.html")
585 var hash map[string]InstanceType
586 err := json.Unmarshal(data, &hash)
590 // Fill in Name field (and ProviderType field, if not
591 // specified) using hash key.
592 *it = InstanceTypeMap(hash)
593 for name, t := range *it {
604 type StringSet map[string]struct{}
606 // UnmarshalJSON handles old config files that provide an array of
607 // instance types instead of a hash.
608 func (ss *StringSet) UnmarshalJSON(data []byte) error {
609 if len(data) > 0 && data[0] == '[' {
611 err := json.Unmarshal(data, &arr)
619 *ss = make(map[string]struct{}, len(arr))
620 for _, t := range arr {
621 (*ss)[t] = struct{}{}
625 var hash map[string]struct{}
626 err := json.Unmarshal(data, &hash)
630 *ss = make(map[string]struct{}, len(hash))
631 for t := range hash {
632 (*ss)[t] = struct{}{}
638 type ServiceName string
641 ServiceNameController ServiceName = "arvados-controller"
642 ServiceNameDispatchCloud ServiceName = "arvados-dispatch-cloud"
643 ServiceNameDispatchLSF ServiceName = "arvados-dispatch-lsf"
644 ServiceNameDispatchSLURM ServiceName = "crunch-dispatch-slurm"
645 ServiceNameHealth ServiceName = "arvados-health"
646 ServiceNameKeepbalance ServiceName = "keep-balance"
647 ServiceNameKeepproxy ServiceName = "keepproxy"
648 ServiceNameKeepstore ServiceName = "keepstore"
649 ServiceNameKeepweb ServiceName = "keep-web"
650 ServiceNameRailsAPI ServiceName = "arvados-api-server"
651 ServiceNameWebsocket ServiceName = "arvados-ws"
652 ServiceNameWorkbench1 ServiceName = "arvados-workbench1"
653 ServiceNameWorkbench2 ServiceName = "arvados-workbench2"
656 // Map returns all services as a map, suitable for iterating over all
657 // services or looking up a service by name.
658 func (svcs Services) Map() map[ServiceName]Service {
659 return map[ServiceName]Service{
660 ServiceNameController: svcs.Controller,
661 ServiceNameDispatchCloud: svcs.DispatchCloud,
662 ServiceNameDispatchLSF: svcs.DispatchLSF,
663 ServiceNameDispatchSLURM: svcs.DispatchSLURM,
664 ServiceNameHealth: svcs.Health,
665 ServiceNameKeepbalance: svcs.Keepbalance,
666 ServiceNameKeepproxy: svcs.Keepproxy,
667 ServiceNameKeepstore: svcs.Keepstore,
668 ServiceNameKeepweb: svcs.WebDAV,
669 ServiceNameRailsAPI: svcs.RailsAPI,
670 ServiceNameWebsocket: svcs.Websocket,
671 ServiceNameWorkbench1: svcs.Workbench1,
672 ServiceNameWorkbench2: svcs.Workbench2,