1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: Apache-2.0
14 "git.arvados.org/arvados.git/sdk/go/config"
17 var DefaultConfigFile = func() string {
18 if path := os.Getenv("ARVADOS_CONFIG"); path != "" {
21 return "/etc/arvados/config.yml"
26 Clusters map[string]Cluster
30 // GetConfig returns the current system config, loading it from
31 // configFile if needed.
32 func GetConfig(configFile string) (*Config, error) {
34 err := config.LoadFile(&cfg, configFile)
38 // GetCluster returns the cluster ID and config for the given
39 // cluster, or the default/only configured cluster if clusterID is "".
40 func (sc *Config) GetCluster(clusterID string) (*Cluster, error) {
42 if len(sc.Clusters) == 0 {
43 return nil, fmt.Errorf("no clusters configured")
44 } else if len(sc.Clusters) > 1 {
45 return nil, fmt.Errorf("multiple clusters configured, cannot choose")
47 for id, cc := range sc.Clusters {
53 if cc, ok := sc.Clusters[clusterID]; !ok {
54 return nil, fmt.Errorf("cluster %q is not configured", clusterID)
56 cc.ClusterID = clusterID
61 type WebDAVCacheConfig struct {
65 MaxCollectionEntries int
66 MaxCollectionBytes int64
67 MaxPermissionEntries int
72 ClusterID string `json:"-"`
73 ManagementToken string
74 SystemRootToken string
76 InstanceTypes InstanceTypeMap
77 Containers ContainersConfig
78 RemoteClusters map[string]RemoteCluster
82 AsyncPermissionsUpdateInterval Duration
83 DisabledAPIs StringSet
84 MaxIndexDatabaseRead int
85 MaxItemsPerResponse int
86 MaxConcurrentRequests int
87 MaxKeepBlobBuffers int
88 MaxRequestAmplification int
90 RailsSessionSecretToken string
91 RequestTimeout Duration
93 WebsocketClientEventQueue int
94 WebsocketServerEventQueue int
95 KeepServiceRequestTimeout Duration
100 UnloggedAttributes StringSet
104 BlobSigningKey string
105 BlobSigningTTL Duration
107 BlobTrashLifetime Duration
108 BlobTrashCheckInterval Duration
109 BlobTrashConcurrency int
110 BlobDeleteConcurrency int
111 BlobReplicateConcurrency int
112 CollectionVersioning bool
113 DefaultTrashLifetime Duration
114 DefaultReplication int
115 ManagedProperties map[string]struct {
120 PreserveVersionIfIdle Duration
121 TrashSweepInterval Duration
123 ForwardSlashNameSubstitution string
125 BlobMissingReport string
126 BalancePeriod Duration
127 BalanceCollectionBatch int
128 BalanceCollectionBuffers int
129 BalanceTimeout Duration
131 WebDAVCache WebDAVCacheConfig
146 SearchAttribute string
147 SearchBindUser string
148 SearchBindPassword string
151 EmailAttribute string
152 UsernameAttribute string
158 AlternateEmailAddresses bool
160 OpenIDConnect struct {
166 EmailVerifiedClaim string
172 DefaultEmailDomain string
177 ProviderAppSecret string
180 RemoteTokenRefresh Duration
181 TokenLifetime Duration
184 MailchimpAPIKey string
185 MailchimpListID string
186 SendUserSetupNotificationEmail bool
187 IssueReporterEmailFrom string
188 IssueReporterEmailTo string
189 SupportEmailAddress string
195 MaxRequestLogParamsSize int
203 AnonymousUserToken string
204 AdminNotifierEmailFrom string
205 AutoAdminFirstUser bool
206 AutoAdminUserWithEmail string
207 AutoSetupNewUsers bool
208 AutoSetupNewUsersWithRepository bool
209 AutoSetupNewUsersWithVmUUID string
210 AutoSetupUsernameBlacklist StringSet
211 EmailSubjectPrefix string
212 NewInactiveUserNotificationRecipients StringSet
213 NewUserNotificationRecipients StringSet
214 NewUsersAreActive bool
215 UserNotifierEmailFrom string
216 UserProfileNotificationAddress string
217 PreferDomainForUsername string
219 Volumes map[string]Volume
221 ActivationContactLink string
222 APIClientConnectTimeout Duration
223 APIClientReceiveTimeout Duration
224 APIResponseCompression bool
225 ApplicationMimetypesWithViewIcon StringSet
226 ArvadosDocsite string
227 ArvadosPublicDataDocURL string
228 DefaultOpenIdPrefix string
229 EnableGettingStartedPopup bool
230 EnablePublicProjectsPage bool
231 FileViewersConfigURL string
232 LogViewerMaxBytes ByteSize
233 MultiSiteSearch string
234 ProfilingEnabled bool
236 RepositoryCache string
237 RunningJobLogRecordsToFetch int
239 ShowRecentCollectionsOnDashboard bool
240 ShowUserAgreementInline bool
241 ShowUserNotifications bool
244 UserProfileFormFields map[string]struct {
246 FormFieldTitle string
247 FormFieldDescription string
250 Options map[string]struct{}
252 UserProfileFormMessage string
254 WelcomePageHTML string
255 InactivePageHTML string
256 SSHHelpPageHTML string
257 SSHHelpHostSuffix string
260 ForceLegacyAPI14 bool
264 AccessViaHosts map[URL]VolumeAccess
267 StorageClasses map[string]bool
269 DriverParameters json.RawMessage
272 type S3VolumeDriverParameters struct {
279 LocationConstraint bool
281 UseAWSS3v2Driver bool
283 ConnectTimeout Duration
289 type AzureVolumeDriverParameters struct {
290 StorageAccountName string
291 StorageAccountKey string
292 StorageBaseURL string
294 RequestTimeout Duration
295 ListBlobsRetryDelay Duration
296 ListBlobsMaxAttempts int
299 type DirectoryVolumeDriverParameters struct {
304 type VolumeAccess struct {
308 type Services struct {
311 DispatchCloud Service
321 WebDAVDownload Service
329 type Service struct {
330 InternalURLs map[URL]ServiceInstance
334 // URL is a url.URL that is also usable as a JSON key/value.
337 // UnmarshalText implements encoding.TextUnmarshaler so URL can be
338 // used as a JSON key/value.
339 func (su *URL) UnmarshalText(text []byte) error {
340 u, err := url.Parse(string(text))
343 if su.Path == "" && su.Host != "" {
344 // http://example really means http://example/
351 func (su URL) MarshalText() ([]byte, error) {
352 return []byte(fmt.Sprintf("%s", (*url.URL)(&su).String())), nil
355 func (su URL) String() string {
356 return (*url.URL)(&su).String()
359 type ServiceInstance struct {
360 Rendezvous string `json:",omitempty"`
363 type PostgreSQL struct {
364 Connection PostgreSQLConnection
368 type PostgreSQLConnection map[string]string
370 type RemoteCluster struct {
378 type InstanceType struct {
384 IncludedScratch ByteSize
385 AddedScratch ByteSize
390 type ContainersConfig struct {
391 CloudVMs CloudVMsConfig
392 CrunchRunCommand string
393 CrunchRunArgumentsList []string
394 DefaultKeepCacheRAM ByteSize
395 DispatchPrivateKey string
396 LogReuseDecisions bool
398 MaxDispatchAttempts int
400 MinRetryPeriod Duration
401 ReserveExtraRAM ByteSize
402 StaleLockTimeout Duration
403 SupportedDockerImageFormats StringSet
404 UsePreemptibleInstances bool
408 GitInternalDir string
413 LogSecondsBetweenEvents Duration
414 LogThrottlePeriod Duration
417 LimitLogBytesPerJob int
418 LogPartialLineThrottlePeriod Duration
419 LogUpdatePeriod Duration
420 LogUpdateSize ByteSize
424 SbatchArgumentsList []string
425 SbatchEnvironmentVariables map[string]string
427 DNSServerConfDir string
428 DNSServerConfTemplate string
429 DNSServerReloadCommand string
430 DNSServerUpdateCommand string
431 ComputeNodeDomain string
432 ComputeNodeNameservers StringSet
433 AssignNodeHostname string
438 type CloudVMsConfig struct {
441 BootProbeCommand string
442 DeployRunnerBinary string
444 MaxCloudOpsPerSecond int
445 MaxProbesPerSecond int
446 PollInterval Duration
447 ProbeInterval Duration
449 SyncInterval Duration
450 TimeoutBooting Duration
452 TimeoutProbe Duration
453 TimeoutShutdown Duration
454 TimeoutSignal Duration
456 ResourceTags map[string]string
460 DriverParameters json.RawMessage
463 type InstanceTypeMap map[string]InstanceType
465 var errDuplicateInstanceTypeName = errors.New("duplicate instance type name")
467 // UnmarshalJSON handles old config files that provide an array of
468 // instance types instead of a hash.
469 func (it *InstanceTypeMap) UnmarshalJSON(data []byte) error {
470 fixup := func(t InstanceType) (InstanceType, error) {
471 if t.ProviderType == "" {
472 t.ProviderType = t.Name
475 t.Scratch = t.IncludedScratch + t.AddedScratch
476 } else if t.AddedScratch == 0 {
477 t.AddedScratch = t.Scratch - t.IncludedScratch
478 } else if t.IncludedScratch == 0 {
479 t.IncludedScratch = t.Scratch - t.AddedScratch
482 if t.Scratch != (t.IncludedScratch + t.AddedScratch) {
483 return t, fmt.Errorf("InstanceType %q: Scratch != (IncludedScratch + AddedScratch)", t.Name)
488 if len(data) > 0 && data[0] == '[' {
489 var arr []InstanceType
490 err := json.Unmarshal(data, &arr)
498 *it = make(map[string]InstanceType, len(arr))
499 for _, t := range arr {
500 if _, ok := (*it)[t.Name]; ok {
501 return errDuplicateInstanceTypeName
511 var hash map[string]InstanceType
512 err := json.Unmarshal(data, &hash)
516 // Fill in Name field (and ProviderType field, if not
517 // specified) using hash key.
518 *it = InstanceTypeMap(hash)
519 for name, t := range *it {
530 type StringSet map[string]struct{}
532 // UnmarshalJSON handles old config files that provide an array of
533 // instance types instead of a hash.
534 func (ss *StringSet) UnmarshalJSON(data []byte) error {
535 if len(data) > 0 && data[0] == '[' {
537 err := json.Unmarshal(data, &arr)
545 *ss = make(map[string]struct{}, len(arr))
546 for _, t := range arr {
547 (*ss)[t] = struct{}{}
551 var hash map[string]struct{}
552 err := json.Unmarshal(data, &hash)
556 *ss = make(map[string]struct{}, len(hash))
557 for t := range hash {
558 (*ss)[t] = struct{}{}
564 type ServiceName string
567 ServiceNameRailsAPI ServiceName = "arvados-api-server"
568 ServiceNameController ServiceName = "arvados-controller"
569 ServiceNameDispatchCloud ServiceName = "arvados-dispatch-cloud"
570 ServiceNameHealth ServiceName = "arvados-health"
571 ServiceNameNodemanager ServiceName = "arvados-node-manager"
572 ServiceNameWorkbench1 ServiceName = "arvados-workbench1"
573 ServiceNameWorkbench2 ServiceName = "arvados-workbench2"
574 ServiceNameWebsocket ServiceName = "arvados-ws"
575 ServiceNameKeepbalance ServiceName = "keep-balance"
576 ServiceNameKeepweb ServiceName = "keep-web"
577 ServiceNameKeepproxy ServiceName = "keepproxy"
578 ServiceNameKeepstore ServiceName = "keepstore"
581 // Map returns all services as a map, suitable for iterating over all
582 // services or looking up a service by name.
583 func (svcs Services) Map() map[ServiceName]Service {
584 return map[ServiceName]Service{
585 ServiceNameRailsAPI: svcs.RailsAPI,
586 ServiceNameController: svcs.Controller,
587 ServiceNameDispatchCloud: svcs.DispatchCloud,
588 ServiceNameHealth: svcs.Health,
589 ServiceNameNodemanager: svcs.Nodemanager,
590 ServiceNameWorkbench1: svcs.Workbench1,
591 ServiceNameWorkbench2: svcs.Workbench2,
592 ServiceNameWebsocket: svcs.Websocket,
593 ServiceNameKeepbalance: svcs.Keepbalance,
594 ServiceNameKeepweb: svcs.WebDAV,
595 ServiceNameKeepproxy: svcs.Keepproxy,
596 ServiceNameKeepstore: svcs.Keepstore,