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 MaxConcurrentRequests int
103 MaxKeepBlobBuffers int
104 MaxRequestAmplification int
106 MaxTokenLifetime Duration
107 RequestTimeout Duration
109 WebsocketClientEventQueue int
110 WebsocketServerEventQueue int
111 KeepServiceRequestTimeout Duration
112 VocabularyPath string
113 FreezeProjectRequiresDescription bool
114 FreezeProjectRequiresProperties StringSet
115 UnfreezeProjectRequiresAdmin bool
116 LockBeforeUpdate bool
121 UnloggedAttributes StringSet
125 BlobSigningKey string
126 BlobSigningTTL Duration
128 BlobTrashLifetime Duration
129 BlobTrashCheckInterval Duration
130 BlobTrashConcurrency int
131 BlobDeleteConcurrency int
132 BlobReplicateConcurrency int
133 CollectionVersioning bool
134 DefaultTrashLifetime Duration
135 DefaultReplication int
136 ManagedProperties ManagedProperties
137 PreserveVersionIfIdle Duration
138 TrashSweepInterval Duration
140 ForwardSlashNameSubstitution string
143 BlobMissingReport string
144 BalancePeriod Duration
145 BalanceCollectionBatch int
146 BalanceCollectionBuffers int
147 BalanceTimeout Duration
148 BalanceUpdateLimit int
150 WebDAVCache WebDAVCacheConfig
152 KeepproxyPermission UploadDownloadRolePermissions
153 WebDAVPermission UploadDownloadRolePermissions
167 MinTLSVersion TLSVersion
170 SearchAttribute string
171 SearchBindUser string
172 SearchBindPassword string
175 EmailAttribute string
176 UsernameAttribute string
182 AlternateEmailAddresses bool
183 AuthenticationRequestParameters map[string]string
185 OpenIDConnect struct {
191 EmailVerifiedClaim string
193 AcceptAccessToken bool
194 AcceptAccessTokenScope string
195 AuthenticationRequestParameters map[string]string
200 DefaultEmailDomain string
204 Users map[string]TestUser
207 RemoteTokenRefresh Duration
208 TokenLifetime Duration
209 TrustedClients map[URL]struct{}
210 TrustPrivateNetworks bool
211 IssueTrustedTokens bool
214 MailchimpAPIKey string
215 MailchimpListID string
216 SendUserSetupNotificationEmail bool
217 IssueReporterEmailFrom string
218 IssueReporterEmailTo string
219 SupportEmailAddress string
225 MaxRequestLogParamsSize int
236 ActivatedUsersAreVisibleToOthers bool
237 AnonymousUserToken string
238 AdminNotifierEmailFrom string
239 AutoAdminFirstUser bool
240 AutoAdminUserWithEmail string
241 AutoSetupNewUsers bool
242 AutoSetupNewUsersWithRepository bool
243 AutoSetupNewUsersWithVmUUID string
244 AutoSetupUsernameBlacklist StringSet
245 EmailSubjectPrefix string
246 NewInactiveUserNotificationRecipients StringSet
247 NewUserNotificationRecipients StringSet
248 NewUsersAreActive bool
249 UserNotifierEmailFrom string
250 UserNotifierEmailBcc StringSet
251 UserProfileNotificationAddress string
252 PreferDomainForUsername string
253 UserSetupMailText string
254 RoleGroupsVisibleToAll bool
255 CanCreateRoleGroups bool
256 ActivityLoggingPeriod Duration
258 StorageClasses map[string]StorageClassConfig
259 Volumes map[string]Volume
261 ActivationContactLink string
262 APIClientConnectTimeout Duration
263 APIClientReceiveTimeout Duration
264 APIResponseCompression bool
265 ApplicationMimetypesWithViewIcon StringSet
266 ArvadosDocsite string
267 ArvadosPublicDataDocURL string
268 DefaultOpenIdPrefix string
269 DisableSharingURLsUI bool
270 EnableGettingStartedPopup bool
271 EnablePublicProjectsPage bool
272 FileViewersConfigURL string
273 LogViewerMaxBytes ByteSize
274 MultiSiteSearch string
275 ProfilingEnabled bool
277 RepositoryCache string
278 RunningJobLogRecordsToFetch int
280 ShowRecentCollectionsOnDashboard bool
281 ShowUserAgreementInline bool
282 ShowUserNotifications bool
285 UserProfileFormFields map[string]struct {
287 FormFieldTitle string
288 FormFieldDescription string
291 Options map[string]struct{}
293 UserProfileFormMessage string
294 WelcomePageHTML string
295 InactivePageHTML string
296 SSHHelpPageHTML string
297 SSHHelpHostSuffix string
303 type StorageClassConfig struct {
309 AccessViaHosts map[URL]VolumeAccess
312 StorageClasses map[string]bool
314 DriverParameters json.RawMessage
317 type S3VolumeDriverParameters struct {
320 SecretAccessKey string
324 LocationConstraint bool
326 UseAWSS3v2Driver bool
328 ConnectTimeout Duration
335 type AzureVolumeDriverParameters struct {
336 StorageAccountName string
337 StorageAccountKey string
338 StorageBaseURL string
340 RequestTimeout Duration
341 ListBlobsRetryDelay Duration
342 ListBlobsMaxAttempts int
345 type DirectoryVolumeDriverParameters struct {
350 type VolumeAccess struct {
354 type Services struct {
357 DispatchCloud Service
359 DispatchSLURM Service
367 WebDAVDownload Service
375 type Service struct {
376 InternalURLs map[URL]ServiceInstance
380 type TestUser struct {
385 // URL is a url.URL that is also usable as a JSON key/value.
388 // UnmarshalText implements encoding.TextUnmarshaler so URL can be
389 // used as a JSON key/value.
390 func (su *URL) UnmarshalText(text []byte) error {
391 u, err := url.Parse(string(text))
394 if su.Path == "" && su.Host != "" {
395 // http://example really means http://example/
402 func (su URL) MarshalText() ([]byte, error) {
403 return []byte(su.String()), nil
406 func (su URL) String() string {
407 return (*url.URL)(&su).String()
410 type TLSVersion uint16
412 func (v TLSVersion) MarshalText() ([]byte, error) {
416 case tls.VersionTLS10:
417 return []byte("1.0"), nil
418 case tls.VersionTLS11:
419 return []byte("1.1"), nil
420 case tls.VersionTLS12:
421 return []byte("1.2"), nil
422 case tls.VersionTLS13:
423 return []byte("1.3"), nil
425 return nil, fmt.Errorf("unsupported TLSVersion %x", v)
429 func (v *TLSVersion) UnmarshalJSON(text []byte) error {
430 if len(text) > 0 && text[0] == '"' {
432 err := json.Unmarshal(text, &s)
438 switch string(text) {
442 *v = tls.VersionTLS10
444 *v = tls.VersionTLS11
446 *v = tls.VersionTLS12
448 *v = tls.VersionTLS13
450 return fmt.Errorf("unsupported TLSVersion %q", text)
455 type ServiceInstance struct {
457 Rendezvous string `json:",omitempty"`
460 type PostgreSQL struct {
461 Connection PostgreSQLConnection
465 type PostgreSQLConnection map[string]string
467 type RemoteCluster struct {
475 type CUDAFeatures struct {
477 HardwareCapability string
481 type InstanceType struct {
482 Name string `json:"-"`
486 Scratch ByteSize `json:"-"`
487 IncludedScratch ByteSize
488 AddedScratch ByteSize
494 type ContainersConfig struct {
495 CloudVMs CloudVMsConfig
496 CrunchRunCommand string
497 CrunchRunArgumentsList []string
498 DefaultKeepCacheRAM ByteSize
499 DispatchPrivateKey string
500 LogReuseDecisions bool
501 MaxDispatchAttempts int
503 MinRetryPeriod Duration
504 ReserveExtraRAM ByteSize
505 StaleLockTimeout Duration
506 SupportedDockerImageFormats StringSet
507 AlwaysUsePreemptibleInstances bool
508 PreemptiblePriceFactor float64
510 LocalKeepBlobBuffersPerVCPU int
511 LocalKeepLogsToContainerLog string
515 GitInternalDir string
519 SweepInterval Duration
521 LogSecondsBetweenEvents Duration
522 LogThrottlePeriod Duration
525 LimitLogBytesPerJob int
526 LogPartialLineThrottlePeriod Duration
527 LogUpdatePeriod Duration
528 LogUpdateSize ByteSize
536 SbatchArgumentsList []string
537 SbatchEnvironmentVariables map[string]string
539 DNSServerConfDir string
540 DNSServerConfTemplate string
541 DNSServerReloadCommand string
542 DNSServerUpdateCommand string
543 ComputeNodeDomain string
544 ComputeNodeNameservers StringSet
545 AssignNodeHostname string
550 BsubArgumentsList []string
551 BsubCUDAArguments []string
555 type CloudVMsConfig struct {
558 BootProbeCommand string
559 DeployRunnerBinary string
561 MaxCloudOpsPerSecond int
562 MaxProbesPerSecond int
563 MaxConcurrentInstanceCreateOps int
565 PollInterval Duration
566 ProbeInterval Duration
568 SyncInterval Duration
569 TimeoutBooting Duration
571 TimeoutProbe Duration
572 TimeoutShutdown Duration
573 TimeoutSignal Duration
574 TimeoutStaleRunLock Duration
576 ResourceTags map[string]string
580 DriverParameters json.RawMessage
583 type InstanceTypeMap map[string]InstanceType
585 var errDuplicateInstanceTypeName = errors.New("duplicate instance type name")
587 // UnmarshalJSON does special handling of InstanceTypes:
589 // - populate computed fields (Name and Scratch)
591 // - error out if InstancesTypes are populated as an array, which was
592 // deprecated in Arvados 1.2.0
593 func (it *InstanceTypeMap) UnmarshalJSON(data []byte) error {
594 fixup := func(t InstanceType) (InstanceType, error) {
595 if t.ProviderType == "" {
596 t.ProviderType = t.Name
598 // If t.Scratch is set in the configuration file, it will be ignored and overwritten.
599 // It will also generate a "deprecated or unknown config entry" warning.
600 t.Scratch = t.IncludedScratch + t.AddedScratch
604 if len(data) > 0 && data[0] == '[' {
605 return fmt.Errorf("InstanceTypes must be specified as a map, not an array, see https://doc.arvados.org/admin/config.html")
607 var hash map[string]InstanceType
608 err := json.Unmarshal(data, &hash)
612 // Fill in Name field (and ProviderType field, if not
613 // specified) using hash key.
614 *it = InstanceTypeMap(hash)
615 for name, t := range *it {
626 type StringSet map[string]struct{}
628 // UnmarshalJSON handles old config files that provide an array of
629 // instance types instead of a hash.
630 func (ss *StringSet) UnmarshalJSON(data []byte) error {
631 if len(data) > 0 && data[0] == '[' {
633 err := json.Unmarshal(data, &arr)
641 *ss = make(map[string]struct{}, len(arr))
642 for _, t := range arr {
643 (*ss)[t] = struct{}{}
647 var hash map[string]struct{}
648 err := json.Unmarshal(data, &hash)
652 *ss = make(map[string]struct{}, len(hash))
653 for t := range hash {
654 (*ss)[t] = struct{}{}
660 type ServiceName string
663 ServiceNameController ServiceName = "arvados-controller"
664 ServiceNameDispatchCloud ServiceName = "arvados-dispatch-cloud"
665 ServiceNameDispatchLSF ServiceName = "arvados-dispatch-lsf"
666 ServiceNameDispatchSLURM ServiceName = "crunch-dispatch-slurm"
667 ServiceNameGitHTTP ServiceName = "arvados-git-httpd"
668 ServiceNameHealth ServiceName = "arvados-health"
669 ServiceNameKeepbalance ServiceName = "keep-balance"
670 ServiceNameKeepproxy ServiceName = "keepproxy"
671 ServiceNameKeepstore ServiceName = "keepstore"
672 ServiceNameKeepweb ServiceName = "keep-web"
673 ServiceNameRailsAPI ServiceName = "arvados-api-server"
674 ServiceNameWebsocket ServiceName = "arvados-ws"
675 ServiceNameWorkbench1 ServiceName = "arvados-workbench1"
676 ServiceNameWorkbench2 ServiceName = "arvados-workbench2"
679 // Map returns all services as a map, suitable for iterating over all
680 // services or looking up a service by name.
681 func (svcs Services) Map() map[ServiceName]Service {
682 return map[ServiceName]Service{
683 ServiceNameController: svcs.Controller,
684 ServiceNameDispatchCloud: svcs.DispatchCloud,
685 ServiceNameDispatchLSF: svcs.DispatchLSF,
686 ServiceNameDispatchSLURM: svcs.DispatchSLURM,
687 ServiceNameGitHTTP: svcs.GitHTTP,
688 ServiceNameHealth: svcs.Health,
689 ServiceNameKeepbalance: svcs.Keepbalance,
690 ServiceNameKeepproxy: svcs.Keepproxy,
691 ServiceNameKeepstore: svcs.Keepstore,
692 ServiceNameKeepweb: svcs.WebDAV,
693 ServiceNameRailsAPI: svcs.RailsAPI,
694 ServiceNameWebsocket: svcs.Websocket,
695 ServiceNameWorkbench1: svcs.Workbench1,
696 ServiceNameWorkbench2: svcs.Workbench2,