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
126 BlobMissingReport string
127 BalancePeriod Duration
128 BalanceCollectionBatch int
129 BalanceCollectionBuffers int
130 BalanceTimeout Duration
132 WebDAVCache WebDAVCacheConfig
147 SearchAttribute string
148 SearchBindUser string
149 SearchBindPassword string
152 EmailAttribute string
153 UsernameAttribute string
159 AlternateEmailAddresses bool
161 OpenIDConnect struct {
167 EmailVerifiedClaim string
173 DefaultEmailDomain string
178 ProviderAppSecret string
182 Users map[string]TestUser
185 RemoteTokenRefresh Duration
188 MailchimpAPIKey string
189 MailchimpListID string
190 SendUserSetupNotificationEmail bool
191 IssueReporterEmailFrom string
192 IssueReporterEmailTo string
193 SupportEmailAddress string
199 MaxRequestLogParamsSize int
207 AnonymousUserToken string
208 AdminNotifierEmailFrom string
209 AutoAdminFirstUser bool
210 AutoAdminUserWithEmail string
211 AutoSetupNewUsers bool
212 AutoSetupNewUsersWithRepository bool
213 AutoSetupNewUsersWithVmUUID string
214 AutoSetupUsernameBlacklist StringSet
215 EmailSubjectPrefix string
216 NewInactiveUserNotificationRecipients StringSet
217 NewUserNotificationRecipients StringSet
218 NewUsersAreActive bool
219 UserNotifierEmailFrom string
220 UserProfileNotificationAddress string
221 PreferDomainForUsername string
223 Volumes map[string]Volume
225 ActivationContactLink string
226 APIClientConnectTimeout Duration
227 APIClientReceiveTimeout Duration
228 APIResponseCompression bool
229 ApplicationMimetypesWithViewIcon StringSet
230 ArvadosDocsite string
231 ArvadosPublicDataDocURL string
232 DefaultOpenIdPrefix string
233 EnableGettingStartedPopup bool
234 EnablePublicProjectsPage bool
235 FileViewersConfigURL string
236 LogViewerMaxBytes ByteSize
237 MultiSiteSearch string
238 ProfilingEnabled bool
240 RepositoryCache string
241 RunningJobLogRecordsToFetch int
243 ShowRecentCollectionsOnDashboard bool
244 ShowUserAgreementInline bool
245 ShowUserNotifications bool
248 UserProfileFormFields map[string]struct {
250 FormFieldTitle string
251 FormFieldDescription string
254 Options map[string]struct{}
256 UserProfileFormMessage string
258 WelcomePageHTML string
259 InactivePageHTML string
260 SSHHelpPageHTML string
261 SSHHelpHostSuffix string
264 ForceLegacyAPI14 bool
268 AccessViaHosts map[URL]VolumeAccess
271 StorageClasses map[string]bool
273 DriverParameters json.RawMessage
276 type S3VolumeDriverParameters struct {
283 LocationConstraint bool
285 UseAWSS3v2Driver bool
287 ConnectTimeout Duration
293 type AzureVolumeDriverParameters struct {
294 StorageAccountName string
295 StorageAccountKey string
296 StorageBaseURL string
298 RequestTimeout Duration
299 ListBlobsRetryDelay Duration
300 ListBlobsMaxAttempts int
303 type DirectoryVolumeDriverParameters struct {
308 type VolumeAccess struct {
312 type Services struct {
315 DispatchCloud Service
324 WebDAVDownload Service
332 type Service struct {
333 InternalURLs map[URL]ServiceInstance
337 type TestUser struct {
342 // URL is a url.URL that is also usable as a JSON key/value.
345 // UnmarshalText implements encoding.TextUnmarshaler so URL can be
346 // used as a JSON key/value.
347 func (su *URL) UnmarshalText(text []byte) error {
348 u, err := url.Parse(string(text))
351 if su.Path == "" && su.Host != "" {
352 // http://example really means http://example/
359 func (su URL) MarshalText() ([]byte, error) {
360 return []byte(fmt.Sprintf("%s", (*url.URL)(&su).String())), nil
363 func (su URL) String() string {
364 return (*url.URL)(&su).String()
367 type ServiceInstance struct {
368 Rendezvous string `json:",omitempty"`
371 type PostgreSQL struct {
372 Connection PostgreSQLConnection
376 type PostgreSQLConnection map[string]string
378 type RemoteCluster struct {
386 type InstanceType struct {
392 IncludedScratch ByteSize
393 AddedScratch ByteSize
398 type ContainersConfig struct {
399 CloudVMs CloudVMsConfig
400 CrunchRunCommand string
401 CrunchRunArgumentsList []string
402 DefaultKeepCacheRAM ByteSize
403 DispatchPrivateKey string
404 LogReuseDecisions bool
406 MaxDispatchAttempts int
408 MinRetryPeriod Duration
409 ReserveExtraRAM ByteSize
410 StaleLockTimeout Duration
411 SupportedDockerImageFormats StringSet
412 UsePreemptibleInstances bool
416 GitInternalDir string
421 LogSecondsBetweenEvents Duration
422 LogThrottlePeriod Duration
425 LimitLogBytesPerJob int
426 LogPartialLineThrottlePeriod Duration
427 LogUpdatePeriod Duration
428 LogUpdateSize ByteSize
432 SbatchArgumentsList []string
433 SbatchEnvironmentVariables map[string]string
435 DNSServerConfDir string
436 DNSServerConfTemplate string
437 DNSServerReloadCommand string
438 DNSServerUpdateCommand string
439 ComputeNodeDomain string
440 ComputeNodeNameservers StringSet
441 AssignNodeHostname string
446 type CloudVMsConfig struct {
449 BootProbeCommand string
450 DeployRunnerBinary string
452 MaxCloudOpsPerSecond int
453 MaxProbesPerSecond int
454 PollInterval Duration
455 ProbeInterval Duration
457 SyncInterval Duration
458 TimeoutBooting Duration
460 TimeoutProbe Duration
461 TimeoutShutdown Duration
462 TimeoutSignal Duration
464 ResourceTags map[string]string
468 DriverParameters json.RawMessage
471 type InstanceTypeMap map[string]InstanceType
473 var errDuplicateInstanceTypeName = errors.New("duplicate instance type name")
475 // UnmarshalJSON handles old config files that provide an array of
476 // instance types instead of a hash.
477 func (it *InstanceTypeMap) UnmarshalJSON(data []byte) error {
478 fixup := func(t InstanceType) (InstanceType, error) {
479 if t.ProviderType == "" {
480 t.ProviderType = t.Name
483 t.Scratch = t.IncludedScratch + t.AddedScratch
484 } else if t.AddedScratch == 0 {
485 t.AddedScratch = t.Scratch - t.IncludedScratch
486 } else if t.IncludedScratch == 0 {
487 t.IncludedScratch = t.Scratch - t.AddedScratch
490 if t.Scratch != (t.IncludedScratch + t.AddedScratch) {
491 return t, fmt.Errorf("InstanceType %q: Scratch != (IncludedScratch + AddedScratch)", t.Name)
496 if len(data) > 0 && data[0] == '[' {
497 var arr []InstanceType
498 err := json.Unmarshal(data, &arr)
506 *it = make(map[string]InstanceType, len(arr))
507 for _, t := range arr {
508 if _, ok := (*it)[t.Name]; ok {
509 return errDuplicateInstanceTypeName
519 var hash map[string]InstanceType
520 err := json.Unmarshal(data, &hash)
524 // Fill in Name field (and ProviderType field, if not
525 // specified) using hash key.
526 *it = InstanceTypeMap(hash)
527 for name, t := range *it {
538 type StringSet map[string]struct{}
540 // UnmarshalJSON handles old config files that provide an array of
541 // instance types instead of a hash.
542 func (ss *StringSet) UnmarshalJSON(data []byte) error {
543 if len(data) > 0 && data[0] == '[' {
545 err := json.Unmarshal(data, &arr)
553 *ss = make(map[string]struct{}, len(arr))
554 for _, t := range arr {
555 (*ss)[t] = struct{}{}
559 var hash map[string]struct{}
560 err := json.Unmarshal(data, &hash)
564 *ss = make(map[string]struct{}, len(hash))
565 for t := range hash {
566 (*ss)[t] = struct{}{}
572 type ServiceName string
575 ServiceNameRailsAPI ServiceName = "arvados-api-server"
576 ServiceNameController ServiceName = "arvados-controller"
577 ServiceNameDispatchCloud ServiceName = "arvados-dispatch-cloud"
578 ServiceNameHealth ServiceName = "arvados-health"
579 ServiceNameWorkbench1 ServiceName = "arvados-workbench1"
580 ServiceNameWorkbench2 ServiceName = "arvados-workbench2"
581 ServiceNameWebsocket ServiceName = "arvados-ws"
582 ServiceNameKeepbalance ServiceName = "keep-balance"
583 ServiceNameKeepweb ServiceName = "keep-web"
584 ServiceNameKeepproxy ServiceName = "keepproxy"
585 ServiceNameKeepstore ServiceName = "keepstore"
588 // Map returns all services as a map, suitable for iterating over all
589 // services or looking up a service by name.
590 func (svcs Services) Map() map[ServiceName]Service {
591 return map[ServiceName]Service{
592 ServiceNameRailsAPI: svcs.RailsAPI,
593 ServiceNameController: svcs.Controller,
594 ServiceNameDispatchCloud: svcs.DispatchCloud,
595 ServiceNameHealth: svcs.Health,
596 ServiceNameWorkbench1: svcs.Workbench1,
597 ServiceNameWorkbench2: svcs.Workbench2,
598 ServiceNameWebsocket: svcs.Websocket,
599 ServiceNameKeepbalance: svcs.Keepbalance,
600 ServiceNameKeepweb: svcs.WebDAV,
601 ServiceNameKeepproxy: svcs.Keepproxy,
602 ServiceNameKeepstore: svcs.Keepstore,