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
181 Users map[string]TestUser
184 RemoteTokenRefresh Duration
187 MailchimpAPIKey string
188 MailchimpListID string
189 SendUserSetupNotificationEmail bool
190 IssueReporterEmailFrom string
191 IssueReporterEmailTo string
192 SupportEmailAddress string
198 MaxRequestLogParamsSize int
206 AnonymousUserToken string
207 AdminNotifierEmailFrom string
208 AutoAdminFirstUser bool
209 AutoAdminUserWithEmail string
210 AutoSetupNewUsers bool
211 AutoSetupNewUsersWithRepository bool
212 AutoSetupNewUsersWithVmUUID string
213 AutoSetupUsernameBlacklist StringSet
214 EmailSubjectPrefix string
215 NewInactiveUserNotificationRecipients StringSet
216 NewUserNotificationRecipients StringSet
217 NewUsersAreActive bool
218 UserNotifierEmailFrom string
219 UserProfileNotificationAddress string
220 PreferDomainForUsername string
222 Volumes map[string]Volume
224 ActivationContactLink string
225 APIClientConnectTimeout Duration
226 APIClientReceiveTimeout Duration
227 APIResponseCompression bool
228 ApplicationMimetypesWithViewIcon StringSet
229 ArvadosDocsite string
230 ArvadosPublicDataDocURL string
231 DefaultOpenIdPrefix string
232 EnableGettingStartedPopup bool
233 EnablePublicProjectsPage bool
234 FileViewersConfigURL string
235 LogViewerMaxBytes ByteSize
236 MultiSiteSearch string
237 ProfilingEnabled bool
239 RepositoryCache string
240 RunningJobLogRecordsToFetch int
242 ShowRecentCollectionsOnDashboard bool
243 ShowUserAgreementInline bool
244 ShowUserNotifications bool
247 UserProfileFormFields map[string]struct {
249 FormFieldTitle string
250 FormFieldDescription string
253 Options map[string]struct{}
255 UserProfileFormMessage string
257 WelcomePageHTML string
258 InactivePageHTML string
259 SSHHelpPageHTML string
260 SSHHelpHostSuffix string
263 ForceLegacyAPI14 bool
267 AccessViaHosts map[URL]VolumeAccess
270 StorageClasses map[string]bool
272 DriverParameters json.RawMessage
275 type S3VolumeDriverParameters struct {
282 LocationConstraint bool
284 UseAWSS3v2Driver bool
286 ConnectTimeout Duration
292 type AzureVolumeDriverParameters struct {
293 StorageAccountName string
294 StorageAccountKey string
295 StorageBaseURL string
297 RequestTimeout Duration
298 ListBlobsRetryDelay Duration
299 ListBlobsMaxAttempts int
302 type DirectoryVolumeDriverParameters struct {
307 type VolumeAccess struct {
311 type Services struct {
314 DispatchCloud Service
323 WebDAVDownload Service
331 type Service struct {
332 InternalURLs map[URL]ServiceInstance
336 type TestUser struct {
341 // URL is a url.URL that is also usable as a JSON key/value.
344 // UnmarshalText implements encoding.TextUnmarshaler so URL can be
345 // used as a JSON key/value.
346 func (su *URL) UnmarshalText(text []byte) error {
347 u, err := url.Parse(string(text))
350 if su.Path == "" && su.Host != "" {
351 // http://example really means http://example/
358 func (su URL) MarshalText() ([]byte, error) {
359 return []byte(fmt.Sprintf("%s", (*url.URL)(&su).String())), nil
362 func (su URL) String() string {
363 return (*url.URL)(&su).String()
366 type ServiceInstance struct {
367 Rendezvous string `json:",omitempty"`
370 type PostgreSQL struct {
371 Connection PostgreSQLConnection
375 type PostgreSQLConnection map[string]string
377 type RemoteCluster struct {
385 type InstanceType struct {
391 IncludedScratch ByteSize
392 AddedScratch ByteSize
397 type ContainersConfig struct {
398 CloudVMs CloudVMsConfig
399 CrunchRunCommand string
400 CrunchRunArgumentsList []string
401 DefaultKeepCacheRAM ByteSize
402 DispatchPrivateKey string
403 LogReuseDecisions bool
405 MaxDispatchAttempts int
407 MinRetryPeriod Duration
408 ReserveExtraRAM ByteSize
409 StaleLockTimeout Duration
410 SupportedDockerImageFormats StringSet
411 UsePreemptibleInstances bool
415 GitInternalDir string
420 LogSecondsBetweenEvents Duration
421 LogThrottlePeriod Duration
424 LimitLogBytesPerJob int
425 LogPartialLineThrottlePeriod Duration
426 LogUpdatePeriod Duration
427 LogUpdateSize ByteSize
431 SbatchArgumentsList []string
432 SbatchEnvironmentVariables map[string]string
434 DNSServerConfDir string
435 DNSServerConfTemplate string
436 DNSServerReloadCommand string
437 DNSServerUpdateCommand string
438 ComputeNodeDomain string
439 ComputeNodeNameservers StringSet
440 AssignNodeHostname string
445 type CloudVMsConfig struct {
448 BootProbeCommand string
449 DeployRunnerBinary string
451 MaxCloudOpsPerSecond int
452 MaxProbesPerSecond int
453 PollInterval Duration
454 ProbeInterval Duration
456 SyncInterval Duration
457 TimeoutBooting Duration
459 TimeoutProbe Duration
460 TimeoutShutdown Duration
461 TimeoutSignal Duration
463 ResourceTags map[string]string
467 DriverParameters json.RawMessage
470 type InstanceTypeMap map[string]InstanceType
472 var errDuplicateInstanceTypeName = errors.New("duplicate instance type name")
474 // UnmarshalJSON handles old config files that provide an array of
475 // instance types instead of a hash.
476 func (it *InstanceTypeMap) UnmarshalJSON(data []byte) error {
477 fixup := func(t InstanceType) (InstanceType, error) {
478 if t.ProviderType == "" {
479 t.ProviderType = t.Name
482 t.Scratch = t.IncludedScratch + t.AddedScratch
483 } else if t.AddedScratch == 0 {
484 t.AddedScratch = t.Scratch - t.IncludedScratch
485 } else if t.IncludedScratch == 0 {
486 t.IncludedScratch = t.Scratch - t.AddedScratch
489 if t.Scratch != (t.IncludedScratch + t.AddedScratch) {
490 return t, fmt.Errorf("InstanceType %q: Scratch != (IncludedScratch + AddedScratch)", t.Name)
495 if len(data) > 0 && data[0] == '[' {
496 var arr []InstanceType
497 err := json.Unmarshal(data, &arr)
505 *it = make(map[string]InstanceType, len(arr))
506 for _, t := range arr {
507 if _, ok := (*it)[t.Name]; ok {
508 return errDuplicateInstanceTypeName
518 var hash map[string]InstanceType
519 err := json.Unmarshal(data, &hash)
523 // Fill in Name field (and ProviderType field, if not
524 // specified) using hash key.
525 *it = InstanceTypeMap(hash)
526 for name, t := range *it {
537 type StringSet map[string]struct{}
539 // UnmarshalJSON handles old config files that provide an array of
540 // instance types instead of a hash.
541 func (ss *StringSet) UnmarshalJSON(data []byte) error {
542 if len(data) > 0 && data[0] == '[' {
544 err := json.Unmarshal(data, &arr)
552 *ss = make(map[string]struct{}, len(arr))
553 for _, t := range arr {
554 (*ss)[t] = struct{}{}
558 var hash map[string]struct{}
559 err := json.Unmarshal(data, &hash)
563 *ss = make(map[string]struct{}, len(hash))
564 for t := range hash {
565 (*ss)[t] = struct{}{}
571 type ServiceName string
574 ServiceNameRailsAPI ServiceName = "arvados-api-server"
575 ServiceNameController ServiceName = "arvados-controller"
576 ServiceNameDispatchCloud ServiceName = "arvados-dispatch-cloud"
577 ServiceNameHealth ServiceName = "arvados-health"
578 ServiceNameWorkbench1 ServiceName = "arvados-workbench1"
579 ServiceNameWorkbench2 ServiceName = "arvados-workbench2"
580 ServiceNameWebsocket ServiceName = "arvados-ws"
581 ServiceNameKeepbalance ServiceName = "keep-balance"
582 ServiceNameKeepweb ServiceName = "keep-web"
583 ServiceNameKeepproxy ServiceName = "keepproxy"
584 ServiceNameKeepstore ServiceName = "keepstore"
587 // Map returns all services as a map, suitable for iterating over all
588 // services or looking up a service by name.
589 func (svcs Services) Map() map[ServiceName]Service {
590 return map[ServiceName]Service{
591 ServiceNameRailsAPI: svcs.RailsAPI,
592 ServiceNameController: svcs.Controller,
593 ServiceNameDispatchCloud: svcs.DispatchCloud,
594 ServiceNameHealth: svcs.Health,
595 ServiceNameWorkbench1: svcs.Workbench1,
596 ServiceNameWorkbench2: svcs.Workbench2,
597 ServiceNameWebsocket: svcs.Websocket,
598 ServiceNameKeepbalance: svcs.Keepbalance,
599 ServiceNameKeepweb: svcs.WebDAV,
600 ServiceNameKeepproxy: svcs.Keepproxy,
601 ServiceNameKeepstore: svcs.Keepstore,