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 MaxKeepBlobBuffers int
108 MaxRequestAmplification int
110 MaxTokenLifetime Duration
111 RequestTimeout Duration
113 WebsocketClientEventQueue int
114 WebsocketServerEventQueue int
115 KeepServiceRequestTimeout Duration
116 VocabularyPath string
117 FreezeProjectRequiresDescription bool
118 FreezeProjectRequiresProperties StringSet
119 UnfreezeProjectRequiresAdmin bool
120 LockBeforeUpdate bool
125 UnloggedAttributes StringSet
129 BlobSigningKey string
130 BlobSigningTTL Duration
132 BlobTrashLifetime Duration
133 BlobTrashCheckInterval Duration
134 BlobTrashConcurrency int
135 BlobDeleteConcurrency int
136 BlobReplicateConcurrency int
137 CollectionVersioning bool
138 DefaultTrashLifetime Duration
139 DefaultReplication int
140 ManagedProperties ManagedProperties
141 PreserveVersionIfIdle Duration
142 TrashSweepInterval Duration
144 ForwardSlashNameSubstitution string
147 BlobMissingReport string
148 BalancePeriod Duration
149 BalanceCollectionBatch int
150 BalanceCollectionBuffers int
151 BalanceTimeout Duration
152 BalanceUpdateLimit int
154 BalanceTrashLimit int
156 WebDAVCache WebDAVCacheConfig
158 KeepproxyPermission UploadDownloadRolePermissions
159 WebDAVPermission UploadDownloadRolePermissions
161 WebDAVLogDownloadInterval Duration
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
219 MaxRequestLogParamsSize int
220 RequestQueueDumpDirectory string
231 ActivatedUsersAreVisibleToOthers bool
232 AnonymousUserToken string
233 AdminNotifierEmailFrom string
234 AutoAdminFirstUser bool
235 AutoAdminUserWithEmail string
236 AutoSetupNewUsers bool
237 AutoSetupNewUsersWithVmUUID string
238 AutoSetupUsernameBlacklist StringSet
239 EmailSubjectPrefix string
240 NewInactiveUserNotificationRecipients StringSet
241 NewUserNotificationRecipients StringSet
242 NewUsersAreActive bool
243 SendUserSetupNotificationEmail bool
244 SupportEmailAddress string
245 UserNotifierEmailFrom string
246 UserNotifierEmailBcc StringSet
247 UserProfileNotificationAddress string
248 PreferDomainForUsername string
249 UserSetupMailText string
250 RoleGroupsVisibleToAll bool
251 CanCreateRoleGroups bool
252 ActivityLoggingPeriod Duration
253 SyncIgnoredGroups []string
254 SyncRequiredGroups []string
255 SyncUserAccounts bool
256 SyncUserAPITokens bool
260 StorageClasses map[string]StorageClassConfig
261 Volumes map[string]Volume
263 ActivationContactLink string
264 ArvadosDocsite string
265 ArvadosPublicDataDocURL string
266 DisableSharingURLsUI bool
267 FileViewersConfigURL string
268 ShowUserAgreementInline bool
271 UserProfileFormFields map[string]struct {
273 FormFieldTitle string
274 FormFieldDescription string
277 Options map[string]struct{}
279 UserProfileFormMessage string
280 WelcomePageHTML string
281 InactivePageHTML string
282 SSHHelpPageHTML string
283 SSHHelpHostSuffix string
289 type StorageClassConfig struct {
295 AccessViaHosts map[URL]VolumeAccess
297 AllowTrashWhenReadOnly bool
299 StorageClasses map[string]bool
301 DriverParameters json.RawMessage
304 type S3VolumeDriverParameters struct {
306 SecretAccessKey string
310 LocationConstraint bool
313 ConnectTimeout Duration
321 type AzureVolumeDriverParameters struct {
322 StorageAccountName string
323 StorageAccountKey string
324 StorageBaseURL string
326 RequestTimeout Duration
327 ListBlobsRetryDelay Duration
328 ListBlobsMaxAttempts int
331 type DirectoryVolumeDriverParameters struct {
336 type VolumeAccess struct {
340 type Services struct {
343 DispatchCloud Service
345 DispatchSLURM Service
351 WebDAVDownload Service
359 type Service struct {
360 InternalURLs map[URL]ServiceInstance
364 type TestUser struct {
369 // URL is a url.URL that is also usable as a JSON key/value.
372 // UnmarshalText implements encoding.TextUnmarshaler so URL can be
373 // used as a JSON key/value.
374 func (su *URL) UnmarshalText(text []byte) error {
375 u, err := url.Parse(string(text))
378 if su.Path == "" && su.Host != "" {
379 // http://example really means http://example/
386 func (su URL) MarshalText() ([]byte, error) {
387 return []byte(su.String()), nil
390 func (su URL) String() string {
391 return (*url.URL)(&su).String()
394 type TLSVersion uint16
396 func (v TLSVersion) MarshalText() ([]byte, error) {
400 case tls.VersionTLS10:
401 return []byte("1.0"), nil
402 case tls.VersionTLS11:
403 return []byte("1.1"), nil
404 case tls.VersionTLS12:
405 return []byte("1.2"), nil
406 case tls.VersionTLS13:
407 return []byte("1.3"), nil
409 return nil, fmt.Errorf("unsupported TLSVersion %x", v)
413 func (v *TLSVersion) UnmarshalJSON(text []byte) error {
414 if len(text) > 0 && text[0] == '"' {
416 err := json.Unmarshal(text, &s)
422 switch string(text) {
426 *v = tls.VersionTLS10
428 *v = tls.VersionTLS11
430 *v = tls.VersionTLS12
432 *v = tls.VersionTLS13
434 return fmt.Errorf("unsupported TLSVersion %q", text)
439 type ServiceInstance struct {
441 Rendezvous string `json:",omitempty"`
444 type PostgreSQL struct {
445 Connection PostgreSQLConnection
449 type PostgreSQLConnection map[string]string
451 type RemoteCluster struct {
459 type CUDAFeatures struct {
461 HardwareCapability string
465 type InstanceType struct {
466 Name string `json:"-"`
470 Scratch ByteSize `json:"-"`
471 IncludedScratch ByteSize
472 AddedScratch ByteSize
478 type ContainersConfig struct {
479 CloudVMs CloudVMsConfig
480 CrunchRunCommand string
481 CrunchRunArgumentsList []string
482 DefaultKeepCacheRAM ByteSize
483 DispatchPrivateKey string
484 LogReuseDecisions bool
485 MaxDispatchAttempts int
487 MinRetryPeriod Duration
488 ReserveExtraRAM ByteSize
489 StaleLockTimeout Duration
490 SupportedDockerImageFormats StringSet
491 AlwaysUsePreemptibleInstances bool
492 PreemptiblePriceFactor float64
493 MaximumPriceFactor float64
495 LocalKeepBlobBuffersPerVCPU int
496 LocalKeepLogsToContainerLog string
499 LogUpdatePeriod Duration
500 LogUpdateSize ByteSize
508 SbatchArgumentsList []string
509 SbatchEnvironmentVariables map[string]string
513 BsubArgumentsList []string
514 BsubCUDAArguments []string
515 MaxRunTimeOverhead Duration
516 MaxRunTimeDefault Duration
520 type CloudVMsConfig struct {
523 BootProbeCommand string
524 InstanceInitCommand string
525 DeployRunnerBinary string
528 MaxCloudOpsPerSecond int
529 MaxProbesPerSecond int
530 MaxConcurrentInstanceCreateOps int
532 InitialQuotaEstimate int
533 SupervisorFraction float64
534 PollInterval Duration
535 ProbeInterval Duration
537 SyncInterval Duration
538 TimeoutBooting Duration
540 TimeoutProbe Duration
541 TimeoutShutdown Duration
542 TimeoutSignal Duration
543 TimeoutStaleRunLock Duration
545 ResourceTags map[string]string
549 DriverParameters json.RawMessage
552 type InstanceTypeMap map[string]InstanceType
554 var errDuplicateInstanceTypeName = errors.New("duplicate instance type name")
556 // UnmarshalJSON does special handling of InstanceTypes:
558 // - populate computed fields (Name and Scratch)
560 // - error out if InstancesTypes are populated as an array, which was
561 // deprecated in Arvados 1.2.0
562 func (it *InstanceTypeMap) UnmarshalJSON(data []byte) error {
563 fixup := func(t InstanceType) (InstanceType, error) {
564 if t.ProviderType == "" {
565 t.ProviderType = t.Name
567 // If t.Scratch is set in the configuration file, it will be ignored and overwritten.
568 // It will also generate a "deprecated or unknown config entry" warning.
569 t.Scratch = t.IncludedScratch + t.AddedScratch
573 if len(data) > 0 && data[0] == '[' {
574 return fmt.Errorf("InstanceTypes must be specified as a map, not an array, see https://doc.arvados.org/admin/config.html")
576 var hash map[string]InstanceType
577 err := json.Unmarshal(data, &hash)
581 // Fill in Name field (and ProviderType field, if not
582 // specified) using hash key.
583 *it = InstanceTypeMap(hash)
584 for name, t := range *it {
595 type StringSet map[string]struct{}
597 // UnmarshalJSON handles old config files that provide an array of
598 // instance types instead of a hash.
599 func (ss *StringSet) UnmarshalJSON(data []byte) error {
600 if len(data) > 0 && data[0] == '[' {
602 err := json.Unmarshal(data, &arr)
610 *ss = make(map[string]struct{}, len(arr))
611 for _, t := range arr {
612 (*ss)[t] = struct{}{}
616 var hash map[string]struct{}
617 err := json.Unmarshal(data, &hash)
621 *ss = make(map[string]struct{}, len(hash))
622 for t := range hash {
623 (*ss)[t] = struct{}{}
629 type ServiceName string
632 ServiceNameController ServiceName = "arvados-controller"
633 ServiceNameDispatchCloud ServiceName = "arvados-dispatch-cloud"
634 ServiceNameDispatchLSF ServiceName = "arvados-dispatch-lsf"
635 ServiceNameDispatchSLURM ServiceName = "crunch-dispatch-slurm"
636 ServiceNameHealth ServiceName = "arvados-health"
637 ServiceNameKeepbalance ServiceName = "keep-balance"
638 ServiceNameKeepproxy ServiceName = "keepproxy"
639 ServiceNameKeepstore ServiceName = "keepstore"
640 ServiceNameKeepweb ServiceName = "keep-web"
641 ServiceNameRailsAPI ServiceName = "arvados-api-server"
642 ServiceNameWebsocket ServiceName = "arvados-ws"
643 ServiceNameWorkbench1 ServiceName = "arvados-workbench1"
644 ServiceNameWorkbench2 ServiceName = "arvados-workbench2"
647 // Map returns all services as a map, suitable for iterating over all
648 // services or looking up a service by name.
649 func (svcs Services) Map() map[ServiceName]Service {
650 return map[ServiceName]Service{
651 ServiceNameController: svcs.Controller,
652 ServiceNameDispatchCloud: svcs.DispatchCloud,
653 ServiceNameDispatchLSF: svcs.DispatchLSF,
654 ServiceNameDispatchSLURM: svcs.DispatchSLURM,
655 ServiceNameHealth: svcs.Health,
656 ServiceNameKeepbalance: svcs.Keepbalance,
657 ServiceNameKeepproxy: svcs.Keepproxy,
658 ServiceNameKeepstore: svcs.Keepstore,
659 ServiceNameKeepweb: svcs.WebDAV,
660 ServiceNameRailsAPI: svcs.RailsAPI,
661 ServiceNameWebsocket: svcs.Websocket,
662 ServiceNameWorkbench1: svcs.Workbench1,
663 ServiceNameWorkbench2: svcs.Workbench2,