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
174 MinTLSVersion TLSVersion
177 SearchAttribute string
178 SearchBindUser string
179 SearchBindPassword string
182 EmailAttribute string
183 UsernameAttribute string
189 AlternateEmailAddresses bool
190 AuthenticationRequestParameters map[string]string
192 OpenIDConnect struct {
198 EmailVerifiedClaim string
200 AcceptAccessToken bool
201 AcceptAccessTokenScope string
202 AuthenticationRequestParameters map[string]string
207 DefaultEmailDomain string
211 Users map[string]TestUser
214 RemoteTokenRefresh Duration
215 TokenLifetime Duration
216 TrustedClients map[URL]struct{}
217 TrustPrivateNetworks bool
218 IssueTrustedTokens bool
221 MailchimpAPIKey string
222 MailchimpListID string
223 SendUserSetupNotificationEmail bool
224 IssueReporterEmailFrom string
225 IssueReporterEmailTo string
226 SupportEmailAddress string
232 MaxRequestLogParamsSize int
233 RequestQueueDumpDirectory string
244 ActivatedUsersAreVisibleToOthers bool
245 AnonymousUserToken string
246 AdminNotifierEmailFrom string
247 AutoAdminFirstUser bool
248 AutoAdminUserWithEmail string
249 AutoSetupNewUsers bool
250 AutoSetupNewUsersWithRepository bool
251 AutoSetupNewUsersWithVmUUID string
252 AutoSetupUsernameBlacklist StringSet
253 EmailSubjectPrefix string
254 NewInactiveUserNotificationRecipients StringSet
255 NewUserNotificationRecipients StringSet
256 NewUsersAreActive bool
257 UserNotifierEmailFrom string
258 UserNotifierEmailBcc StringSet
259 UserProfileNotificationAddress string
260 PreferDomainForUsername string
261 UserSetupMailText string
262 RoleGroupsVisibleToAll bool
263 CanCreateRoleGroups bool
264 ActivityLoggingPeriod Duration
265 SyncIgnoredGroups []string
266 SyncRequiredGroups []string
267 SyncUserAccounts bool
268 SyncUserAPITokens bool
272 StorageClasses map[string]StorageClassConfig
273 Volumes map[string]Volume
275 ActivationContactLink string
276 ArvadosDocsite string
277 ArvadosPublicDataDocURL string
278 DisableSharingURLsUI bool
279 FileViewersConfigURL string
280 ShowUserAgreementInline bool
283 UserProfileFormFields map[string]struct {
285 FormFieldTitle string
286 FormFieldDescription string
289 Options map[string]struct{}
291 UserProfileFormMessage string
292 WelcomePageHTML string
293 InactivePageHTML string
294 SSHHelpPageHTML string
295 SSHHelpHostSuffix string
301 type StorageClassConfig struct {
307 AccessViaHosts map[URL]VolumeAccess
309 AllowTrashWhenReadOnly bool
311 StorageClasses map[string]bool
313 DriverParameters json.RawMessage
316 type S3VolumeDriverParameters struct {
319 SecretAccessKey string
323 LocationConstraint bool
326 ConnectTimeout Duration
333 type AzureVolumeDriverParameters struct {
334 StorageAccountName string
335 StorageAccountKey string
336 StorageBaseURL string
338 RequestTimeout Duration
339 ListBlobsRetryDelay Duration
340 ListBlobsMaxAttempts int
343 type DirectoryVolumeDriverParameters struct {
348 type VolumeAccess struct {
352 type Services struct {
355 DispatchCloud Service
357 DispatchSLURM Service
365 WebDAVDownload Service
373 type Service struct {
374 InternalURLs map[URL]ServiceInstance
378 type TestUser struct {
383 // URL is a url.URL that is also usable as a JSON key/value.
386 // UnmarshalText implements encoding.TextUnmarshaler so URL can be
387 // used as a JSON key/value.
388 func (su *URL) UnmarshalText(text []byte) error {
389 u, err := url.Parse(string(text))
392 if su.Path == "" && su.Host != "" {
393 // http://example really means http://example/
400 func (su URL) MarshalText() ([]byte, error) {
401 return []byte(su.String()), nil
404 func (su URL) String() string {
405 return (*url.URL)(&su).String()
408 type TLSVersion uint16
410 func (v TLSVersion) MarshalText() ([]byte, error) {
414 case tls.VersionTLS10:
415 return []byte("1.0"), nil
416 case tls.VersionTLS11:
417 return []byte("1.1"), nil
418 case tls.VersionTLS12:
419 return []byte("1.2"), nil
420 case tls.VersionTLS13:
421 return []byte("1.3"), nil
423 return nil, fmt.Errorf("unsupported TLSVersion %x", v)
427 func (v *TLSVersion) UnmarshalJSON(text []byte) error {
428 if len(text) > 0 && text[0] == '"' {
430 err := json.Unmarshal(text, &s)
436 switch string(text) {
440 *v = tls.VersionTLS10
442 *v = tls.VersionTLS11
444 *v = tls.VersionTLS12
446 *v = tls.VersionTLS13
448 return fmt.Errorf("unsupported TLSVersion %q", text)
453 type ServiceInstance struct {
455 Rendezvous string `json:",omitempty"`
458 type PostgreSQL struct {
459 Connection PostgreSQLConnection
463 type PostgreSQLConnection map[string]string
465 type RemoteCluster struct {
473 type CUDAFeatures struct {
475 HardwareCapability string
479 type InstanceType struct {
480 Name string `json:"-"`
484 Scratch ByteSize `json:"-"`
485 IncludedScratch ByteSize
486 AddedScratch ByteSize
492 type ContainersConfig struct {
493 CloudVMs CloudVMsConfig
494 CrunchRunCommand string
495 CrunchRunArgumentsList []string
496 DefaultKeepCacheRAM ByteSize
497 DispatchPrivateKey string
498 LogReuseDecisions bool
499 MaxDispatchAttempts int
501 MinRetryPeriod Duration
502 ReserveExtraRAM ByteSize
503 StaleLockTimeout Duration
504 SupportedDockerImageFormats StringSet
505 AlwaysUsePreemptibleInstances bool
506 PreemptiblePriceFactor float64
507 MaximumPriceFactor float64
509 LocalKeepBlobBuffersPerVCPU int
510 LocalKeepLogsToContainerLog string
514 GitInternalDir string
518 SweepInterval Duration
520 LogSecondsBetweenEvents Duration
521 LogThrottlePeriod Duration
524 LimitLogBytesPerJob int
525 LogPartialLineThrottlePeriod Duration
526 LogUpdatePeriod Duration
527 LogUpdateSize ByteSize
535 SbatchArgumentsList []string
536 SbatchEnvironmentVariables map[string]string
538 DNSServerConfDir string
539 DNSServerConfTemplate string
540 DNSServerReloadCommand string
541 DNSServerUpdateCommand string
542 ComputeNodeDomain string
543 ComputeNodeNameservers StringSet
544 AssignNodeHostname string
549 BsubArgumentsList []string
550 BsubCUDAArguments []string
554 type CloudVMsConfig struct {
557 BootProbeCommand string
558 InstanceInitCommand string
559 DeployRunnerBinary string
562 MaxCloudOpsPerSecond int
563 MaxProbesPerSecond int
564 MaxConcurrentInstanceCreateOps int
566 InitialQuotaEstimate int
567 SupervisorFraction float64
568 PollInterval Duration
569 ProbeInterval Duration
571 SyncInterval Duration
572 TimeoutBooting Duration
574 TimeoutProbe Duration
575 TimeoutShutdown Duration
576 TimeoutSignal Duration
577 TimeoutStaleRunLock Duration
579 ResourceTags map[string]string
583 DriverParameters json.RawMessage
586 type InstanceTypeMap map[string]InstanceType
588 var errDuplicateInstanceTypeName = errors.New("duplicate instance type name")
590 // UnmarshalJSON does special handling of InstanceTypes:
592 // - populate computed fields (Name and Scratch)
594 // - error out if InstancesTypes are populated as an array, which was
595 // deprecated in Arvados 1.2.0
596 func (it *InstanceTypeMap) UnmarshalJSON(data []byte) error {
597 fixup := func(t InstanceType) (InstanceType, error) {
598 if t.ProviderType == "" {
599 t.ProviderType = t.Name
601 // If t.Scratch is set in the configuration file, it will be ignored and overwritten.
602 // It will also generate a "deprecated or unknown config entry" warning.
603 t.Scratch = t.IncludedScratch + t.AddedScratch
607 if len(data) > 0 && data[0] == '[' {
608 return fmt.Errorf("InstanceTypes must be specified as a map, not an array, see https://doc.arvados.org/admin/config.html")
610 var hash map[string]InstanceType
611 err := json.Unmarshal(data, &hash)
615 // Fill in Name field (and ProviderType field, if not
616 // specified) using hash key.
617 *it = InstanceTypeMap(hash)
618 for name, t := range *it {
629 type StringSet map[string]struct{}
631 // UnmarshalJSON handles old config files that provide an array of
632 // instance types instead of a hash.
633 func (ss *StringSet) UnmarshalJSON(data []byte) error {
634 if len(data) > 0 && data[0] == '[' {
636 err := json.Unmarshal(data, &arr)
644 *ss = make(map[string]struct{}, len(arr))
645 for _, t := range arr {
646 (*ss)[t] = struct{}{}
650 var hash map[string]struct{}
651 err := json.Unmarshal(data, &hash)
655 *ss = make(map[string]struct{}, len(hash))
656 for t := range hash {
657 (*ss)[t] = struct{}{}
663 type ServiceName string
666 ServiceNameController ServiceName = "arvados-controller"
667 ServiceNameDispatchCloud ServiceName = "arvados-dispatch-cloud"
668 ServiceNameDispatchLSF ServiceName = "arvados-dispatch-lsf"
669 ServiceNameDispatchSLURM ServiceName = "crunch-dispatch-slurm"
670 ServiceNameGitHTTP ServiceName = "arvados-git-httpd"
671 ServiceNameHealth ServiceName = "arvados-health"
672 ServiceNameKeepbalance ServiceName = "keep-balance"
673 ServiceNameKeepproxy ServiceName = "keepproxy"
674 ServiceNameKeepstore ServiceName = "keepstore"
675 ServiceNameKeepweb ServiceName = "keep-web"
676 ServiceNameRailsAPI ServiceName = "arvados-api-server"
677 ServiceNameWebsocket ServiceName = "arvados-ws"
678 ServiceNameWorkbench1 ServiceName = "arvados-workbench1"
679 ServiceNameWorkbench2 ServiceName = "arvados-workbench2"
682 // Map returns all services as a map, suitable for iterating over all
683 // services or looking up a service by name.
684 func (svcs Services) Map() map[ServiceName]Service {
685 return map[ServiceName]Service{
686 ServiceNameController: svcs.Controller,
687 ServiceNameDispatchCloud: svcs.DispatchCloud,
688 ServiceNameDispatchLSF: svcs.DispatchLSF,
689 ServiceNameDispatchSLURM: svcs.DispatchSLURM,
690 ServiceNameGitHTTP: svcs.GitHTTP,
691 ServiceNameHealth: svcs.Health,
692 ServiceNameKeepbalance: svcs.Keepbalance,
693 ServiceNameKeepproxy: svcs.Keepproxy,
694 ServiceNameKeepstore: svcs.Keepstore,
695 ServiceNameKeepweb: svcs.WebDAV,
696 ServiceNameRailsAPI: svcs.RailsAPI,
697 ServiceNameWebsocket: svcs.Websocket,
698 ServiceNameWorkbench1: svcs.Workbench1,
699 ServiceNameWorkbench2: svcs.Workbench2,