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 {
67 MaxCollectionBytes int64
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 MaxQueueTimeForLockRequests Duration
106 LogCreateRequestFraction float64
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
173 MinTLSVersion TLSVersion
176 SearchAttribute string
177 SearchBindUser string
178 SearchBindPassword string
181 EmailAttribute string
182 UsernameAttribute string
188 AlternateEmailAddresses bool
189 AuthenticationRequestParameters map[string]string
191 OpenIDConnect struct {
197 EmailVerifiedClaim string
199 AcceptAccessToken bool
200 AcceptAccessTokenScope string
201 AuthenticationRequestParameters map[string]string
206 DefaultEmailDomain string
210 Users map[string]TestUser
213 RemoteTokenRefresh Duration
214 TokenLifetime Duration
215 TrustedClients map[URL]struct{}
216 TrustPrivateNetworks bool
217 IssueTrustedTokens bool
220 MailchimpAPIKey string
221 MailchimpListID string
222 SendUserSetupNotificationEmail bool
223 IssueReporterEmailFrom string
224 IssueReporterEmailTo string
225 SupportEmailAddress string
231 MaxRequestLogParamsSize int
232 RequestQueueDumpDirectory string
243 ActivatedUsersAreVisibleToOthers bool
244 AnonymousUserToken string
245 AdminNotifierEmailFrom string
246 AutoAdminFirstUser bool
247 AutoAdminUserWithEmail string
248 AutoSetupNewUsers bool
249 AutoSetupNewUsersWithRepository bool
250 AutoSetupNewUsersWithVmUUID string
251 AutoSetupUsernameBlacklist StringSet
252 EmailSubjectPrefix string
253 NewInactiveUserNotificationRecipients StringSet
254 NewUserNotificationRecipients StringSet
255 NewUsersAreActive bool
256 UserNotifierEmailFrom string
257 UserNotifierEmailBcc StringSet
258 UserProfileNotificationAddress string
259 PreferDomainForUsername string
260 UserSetupMailText string
261 RoleGroupsVisibleToAll bool
262 CanCreateRoleGroups bool
263 ActivityLoggingPeriod Duration
264 SyncIgnoredGroups []string
265 SyncRequiredGroups []string
266 SyncUserAccounts bool
267 SyncUserAPITokens bool
271 StorageClasses map[string]StorageClassConfig
272 Volumes map[string]Volume
274 ActivationContactLink string
275 ArvadosDocsite string
276 ArvadosPublicDataDocURL string
277 DisableSharingURLsUI bool
278 FileViewersConfigURL string
279 ShowUserAgreementInline bool
282 UserProfileFormFields map[string]struct {
284 FormFieldTitle string
285 FormFieldDescription string
288 Options map[string]struct{}
290 UserProfileFormMessage string
291 WelcomePageHTML string
292 InactivePageHTML string
293 SSHHelpPageHTML string
294 SSHHelpHostSuffix string
300 type StorageClassConfig struct {
306 AccessViaHosts map[URL]VolumeAccess
308 AllowTrashWhenReadOnly bool
310 StorageClasses map[string]bool
312 DriverParameters json.RawMessage
315 type S3VolumeDriverParameters struct {
318 SecretAccessKey string
322 LocationConstraint bool
325 ConnectTimeout Duration
332 type AzureVolumeDriverParameters struct {
333 StorageAccountName string
334 StorageAccountKey string
335 StorageBaseURL string
337 RequestTimeout Duration
338 ListBlobsRetryDelay Duration
339 ListBlobsMaxAttempts int
342 type DirectoryVolumeDriverParameters struct {
347 type VolumeAccess struct {
351 type Services struct {
354 DispatchCloud Service
356 DispatchSLURM Service
364 WebDAVDownload Service
372 type Service struct {
373 InternalURLs map[URL]ServiceInstance
377 type TestUser struct {
382 // URL is a url.URL that is also usable as a JSON key/value.
385 // UnmarshalText implements encoding.TextUnmarshaler so URL can be
386 // used as a JSON key/value.
387 func (su *URL) UnmarshalText(text []byte) error {
388 u, err := url.Parse(string(text))
391 if su.Path == "" && su.Host != "" {
392 // http://example really means http://example/
399 func (su URL) MarshalText() ([]byte, error) {
400 return []byte(su.String()), nil
403 func (su URL) String() string {
404 return (*url.URL)(&su).String()
407 type TLSVersion uint16
409 func (v TLSVersion) MarshalText() ([]byte, error) {
413 case tls.VersionTLS10:
414 return []byte("1.0"), nil
415 case tls.VersionTLS11:
416 return []byte("1.1"), nil
417 case tls.VersionTLS12:
418 return []byte("1.2"), nil
419 case tls.VersionTLS13:
420 return []byte("1.3"), nil
422 return nil, fmt.Errorf("unsupported TLSVersion %x", v)
426 func (v *TLSVersion) UnmarshalJSON(text []byte) error {
427 if len(text) > 0 && text[0] == '"' {
429 err := json.Unmarshal(text, &s)
435 switch string(text) {
439 *v = tls.VersionTLS10
441 *v = tls.VersionTLS11
443 *v = tls.VersionTLS12
445 *v = tls.VersionTLS13
447 return fmt.Errorf("unsupported TLSVersion %q", text)
452 type ServiceInstance struct {
454 Rendezvous string `json:",omitempty"`
457 type PostgreSQL struct {
458 Connection PostgreSQLConnection
462 type PostgreSQLConnection map[string]string
464 type RemoteCluster struct {
472 type CUDAFeatures struct {
474 HardwareCapability string
478 type InstanceType struct {
479 Name string `json:"-"`
483 Scratch ByteSize `json:"-"`
484 IncludedScratch ByteSize
485 AddedScratch ByteSize
491 type ContainersConfig struct {
492 CloudVMs CloudVMsConfig
493 CrunchRunCommand string
494 CrunchRunArgumentsList []string
495 DefaultKeepCacheRAM ByteSize
496 DispatchPrivateKey string
497 LogReuseDecisions bool
498 MaxDispatchAttempts int
500 MinRetryPeriod Duration
501 ReserveExtraRAM ByteSize
502 StaleLockTimeout Duration
503 SupportedDockerImageFormats StringSet
504 AlwaysUsePreemptibleInstances bool
505 PreemptiblePriceFactor float64
506 MaximumPriceFactor float64
508 LocalKeepBlobBuffersPerVCPU int
509 LocalKeepLogsToContainerLog string
513 GitInternalDir string
517 SweepInterval Duration
519 LogSecondsBetweenEvents Duration
520 LogThrottlePeriod Duration
523 LimitLogBytesPerJob int
524 LogPartialLineThrottlePeriod Duration
525 LogUpdatePeriod Duration
526 LogUpdateSize ByteSize
534 SbatchArgumentsList []string
535 SbatchEnvironmentVariables map[string]string
537 DNSServerConfDir string
538 DNSServerConfTemplate string
539 DNSServerReloadCommand string
540 DNSServerUpdateCommand string
541 ComputeNodeDomain string
542 ComputeNodeNameservers StringSet
543 AssignNodeHostname string
548 BsubArgumentsList []string
549 BsubCUDAArguments []string
553 type CloudVMsConfig struct {
556 BootProbeCommand string
557 InstanceInitCommand string
558 DeployRunnerBinary string
561 MaxCloudOpsPerSecond int
562 MaxProbesPerSecond int
563 MaxConcurrentInstanceCreateOps int
565 InitialQuotaEstimate int
566 SupervisorFraction float64
567 PollInterval Duration
568 ProbeInterval Duration
570 SyncInterval Duration
571 TimeoutBooting Duration
573 TimeoutProbe Duration
574 TimeoutShutdown Duration
575 TimeoutSignal Duration
576 TimeoutStaleRunLock Duration
578 ResourceTags map[string]string
582 DriverParameters json.RawMessage
585 type InstanceTypeMap map[string]InstanceType
587 var errDuplicateInstanceTypeName = errors.New("duplicate instance type name")
589 // UnmarshalJSON does special handling of InstanceTypes:
591 // - populate computed fields (Name and Scratch)
593 // - error out if InstancesTypes are populated as an array, which was
594 // deprecated in Arvados 1.2.0
595 func (it *InstanceTypeMap) UnmarshalJSON(data []byte) error {
596 fixup := func(t InstanceType) (InstanceType, error) {
597 if t.ProviderType == "" {
598 t.ProviderType = t.Name
600 // If t.Scratch is set in the configuration file, it will be ignored and overwritten.
601 // It will also generate a "deprecated or unknown config entry" warning.
602 t.Scratch = t.IncludedScratch + t.AddedScratch
606 if len(data) > 0 && data[0] == '[' {
607 return fmt.Errorf("InstanceTypes must be specified as a map, not an array, see https://doc.arvados.org/admin/config.html")
609 var hash map[string]InstanceType
610 err := json.Unmarshal(data, &hash)
614 // Fill in Name field (and ProviderType field, if not
615 // specified) using hash key.
616 *it = InstanceTypeMap(hash)
617 for name, t := range *it {
628 type StringSet map[string]struct{}
630 // UnmarshalJSON handles old config files that provide an array of
631 // instance types instead of a hash.
632 func (ss *StringSet) UnmarshalJSON(data []byte) error {
633 if len(data) > 0 && data[0] == '[' {
635 err := json.Unmarshal(data, &arr)
643 *ss = make(map[string]struct{}, len(arr))
644 for _, t := range arr {
645 (*ss)[t] = struct{}{}
649 var hash map[string]struct{}
650 err := json.Unmarshal(data, &hash)
654 *ss = make(map[string]struct{}, len(hash))
655 for t := range hash {
656 (*ss)[t] = struct{}{}
662 type ServiceName string
665 ServiceNameController ServiceName = "arvados-controller"
666 ServiceNameDispatchCloud ServiceName = "arvados-dispatch-cloud"
667 ServiceNameDispatchLSF ServiceName = "arvados-dispatch-lsf"
668 ServiceNameDispatchSLURM ServiceName = "crunch-dispatch-slurm"
669 ServiceNameGitHTTP ServiceName = "arvados-git-httpd"
670 ServiceNameHealth ServiceName = "arvados-health"
671 ServiceNameKeepbalance ServiceName = "keep-balance"
672 ServiceNameKeepproxy ServiceName = "keepproxy"
673 ServiceNameKeepstore ServiceName = "keepstore"
674 ServiceNameKeepweb ServiceName = "keep-web"
675 ServiceNameRailsAPI ServiceName = "arvados-api-server"
676 ServiceNameWebsocket ServiceName = "arvados-ws"
677 ServiceNameWorkbench1 ServiceName = "arvados-workbench1"
678 ServiceNameWorkbench2 ServiceName = "arvados-workbench2"
681 // Map returns all services as a map, suitable for iterating over all
682 // services or looking up a service by name.
683 func (svcs Services) Map() map[ServiceName]Service {
684 return map[ServiceName]Service{
685 ServiceNameController: svcs.Controller,
686 ServiceNameDispatchCloud: svcs.DispatchCloud,
687 ServiceNameDispatchLSF: svcs.DispatchLSF,
688 ServiceNameDispatchSLURM: svcs.DispatchSLURM,
689 ServiceNameGitHTTP: svcs.GitHTTP,
690 ServiceNameHealth: svcs.Health,
691 ServiceNameKeepbalance: svcs.Keepbalance,
692 ServiceNameKeepproxy: svcs.Keepproxy,
693 ServiceNameKeepstore: svcs.Keepstore,
694 ServiceNameKeepweb: svcs.WebDAV,
695 ServiceNameRailsAPI: svcs.RailsAPI,
696 ServiceNameWebsocket: svcs.Websocket,
697 ServiceNameWorkbench1: svcs.Workbench1,
698 ServiceNameWorkbench2: svcs.Workbench2,