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
186 TokenLifetime Duration
189 MailchimpAPIKey string
190 MailchimpListID string
191 SendUserSetupNotificationEmail bool
192 IssueReporterEmailFrom string
193 IssueReporterEmailTo string
194 SupportEmailAddress string
200 MaxRequestLogParamsSize int
208 AnonymousUserToken string
209 AdminNotifierEmailFrom string
210 AutoAdminFirstUser bool
211 AutoAdminUserWithEmail string
212 AutoSetupNewUsers bool
213 AutoSetupNewUsersWithRepository bool
214 AutoSetupNewUsersWithVmUUID string
215 AutoSetupUsernameBlacklist StringSet
216 EmailSubjectPrefix string
217 NewInactiveUserNotificationRecipients StringSet
218 NewUserNotificationRecipients StringSet
219 NewUsersAreActive bool
220 UserNotifierEmailFrom string
221 UserProfileNotificationAddress string
222 PreferDomainForUsername string
224 Volumes map[string]Volume
226 ActivationContactLink string
227 APIClientConnectTimeout Duration
228 APIClientReceiveTimeout Duration
229 APIResponseCompression bool
230 ApplicationMimetypesWithViewIcon StringSet
231 ArvadosDocsite string
232 ArvadosPublicDataDocURL string
233 DefaultOpenIdPrefix string
234 EnableGettingStartedPopup bool
235 EnablePublicProjectsPage bool
236 FileViewersConfigURL string
237 LogViewerMaxBytes ByteSize
238 MultiSiteSearch string
239 ProfilingEnabled bool
241 RepositoryCache string
242 RunningJobLogRecordsToFetch int
244 ShowRecentCollectionsOnDashboard bool
245 ShowUserAgreementInline bool
246 ShowUserNotifications bool
249 UserProfileFormFields map[string]struct {
251 FormFieldTitle string
252 FormFieldDescription string
255 Options map[string]struct{}
257 UserProfileFormMessage string
259 WelcomePageHTML string
260 InactivePageHTML string
261 SSHHelpPageHTML string
262 SSHHelpHostSuffix string
265 ForceLegacyAPI14 bool
269 AccessViaHosts map[URL]VolumeAccess
272 StorageClasses map[string]bool
274 DriverParameters json.RawMessage
277 type S3VolumeDriverParameters struct {
284 LocationConstraint bool
286 UseAWSS3v2Driver bool
288 ConnectTimeout Duration
294 type AzureVolumeDriverParameters struct {
295 StorageAccountName string
296 StorageAccountKey string
297 StorageBaseURL string
299 RequestTimeout Duration
300 ListBlobsRetryDelay Duration
301 ListBlobsMaxAttempts int
304 type DirectoryVolumeDriverParameters struct {
309 type VolumeAccess struct {
313 type Services struct {
316 DispatchCloud Service
325 WebDAVDownload Service
333 type Service struct {
334 InternalURLs map[URL]ServiceInstance
338 type TestUser struct {
343 // URL is a url.URL that is also usable as a JSON key/value.
346 // UnmarshalText implements encoding.TextUnmarshaler so URL can be
347 // used as a JSON key/value.
348 func (su *URL) UnmarshalText(text []byte) error {
349 u, err := url.Parse(string(text))
352 if su.Path == "" && su.Host != "" {
353 // http://example really means http://example/
360 func (su URL) MarshalText() ([]byte, error) {
361 return []byte(fmt.Sprintf("%s", (*url.URL)(&su).String())), nil
364 func (su URL) String() string {
365 return (*url.URL)(&su).String()
368 type ServiceInstance struct {
369 Rendezvous string `json:",omitempty"`
372 type PostgreSQL struct {
373 Connection PostgreSQLConnection
377 type PostgreSQLConnection map[string]string
379 type RemoteCluster struct {
387 type InstanceType struct {
393 IncludedScratch ByteSize
394 AddedScratch ByteSize
399 type ContainersConfig struct {
400 CloudVMs CloudVMsConfig
401 CrunchRunCommand string
402 CrunchRunArgumentsList []string
403 DefaultKeepCacheRAM ByteSize
404 DispatchPrivateKey string
405 LogReuseDecisions bool
407 MaxDispatchAttempts int
409 MinRetryPeriod Duration
410 ReserveExtraRAM ByteSize
411 StaleLockTimeout Duration
412 SupportedDockerImageFormats StringSet
413 UsePreemptibleInstances bool
417 GitInternalDir string
422 LogSecondsBetweenEvents Duration
423 LogThrottlePeriod Duration
426 LimitLogBytesPerJob int
427 LogPartialLineThrottlePeriod Duration
428 LogUpdatePeriod Duration
429 LogUpdateSize ByteSize
433 SbatchArgumentsList []string
434 SbatchEnvironmentVariables map[string]string
436 DNSServerConfDir string
437 DNSServerConfTemplate string
438 DNSServerReloadCommand string
439 DNSServerUpdateCommand string
440 ComputeNodeDomain string
441 ComputeNodeNameservers StringSet
442 AssignNodeHostname string
447 type CloudVMsConfig struct {
450 BootProbeCommand string
451 DeployRunnerBinary string
453 MaxCloudOpsPerSecond int
454 MaxProbesPerSecond int
455 PollInterval Duration
456 ProbeInterval Duration
458 SyncInterval Duration
459 TimeoutBooting Duration
461 TimeoutProbe Duration
462 TimeoutShutdown Duration
463 TimeoutSignal Duration
465 ResourceTags map[string]string
469 DriverParameters json.RawMessage
472 type InstanceTypeMap map[string]InstanceType
474 var errDuplicateInstanceTypeName = errors.New("duplicate instance type name")
476 // UnmarshalJSON handles old config files that provide an array of
477 // instance types instead of a hash.
478 func (it *InstanceTypeMap) UnmarshalJSON(data []byte) error {
479 fixup := func(t InstanceType) (InstanceType, error) {
480 if t.ProviderType == "" {
481 t.ProviderType = t.Name
484 t.Scratch = t.IncludedScratch + t.AddedScratch
485 } else if t.AddedScratch == 0 {
486 t.AddedScratch = t.Scratch - t.IncludedScratch
487 } else if t.IncludedScratch == 0 {
488 t.IncludedScratch = t.Scratch - t.AddedScratch
491 if t.Scratch != (t.IncludedScratch + t.AddedScratch) {
492 return t, fmt.Errorf("InstanceType %q: Scratch != (IncludedScratch + AddedScratch)", t.Name)
497 if len(data) > 0 && data[0] == '[' {
498 var arr []InstanceType
499 err := json.Unmarshal(data, &arr)
507 *it = make(map[string]InstanceType, len(arr))
508 for _, t := range arr {
509 if _, ok := (*it)[t.Name]; ok {
510 return errDuplicateInstanceTypeName
520 var hash map[string]InstanceType
521 err := json.Unmarshal(data, &hash)
525 // Fill in Name field (and ProviderType field, if not
526 // specified) using hash key.
527 *it = InstanceTypeMap(hash)
528 for name, t := range *it {
539 type StringSet map[string]struct{}
541 // UnmarshalJSON handles old config files that provide an array of
542 // instance types instead of a hash.
543 func (ss *StringSet) UnmarshalJSON(data []byte) error {
544 if len(data) > 0 && data[0] == '[' {
546 err := json.Unmarshal(data, &arr)
554 *ss = make(map[string]struct{}, len(arr))
555 for _, t := range arr {
556 (*ss)[t] = struct{}{}
560 var hash map[string]struct{}
561 err := json.Unmarshal(data, &hash)
565 *ss = make(map[string]struct{}, len(hash))
566 for t := range hash {
567 (*ss)[t] = struct{}{}
573 type ServiceName string
576 ServiceNameRailsAPI ServiceName = "arvados-api-server"
577 ServiceNameController ServiceName = "arvados-controller"
578 ServiceNameDispatchCloud ServiceName = "arvados-dispatch-cloud"
579 ServiceNameHealth ServiceName = "arvados-health"
580 ServiceNameWorkbench1 ServiceName = "arvados-workbench1"
581 ServiceNameWorkbench2 ServiceName = "arvados-workbench2"
582 ServiceNameWebsocket ServiceName = "arvados-ws"
583 ServiceNameKeepbalance ServiceName = "keep-balance"
584 ServiceNameKeepweb ServiceName = "keep-web"
585 ServiceNameKeepproxy ServiceName = "keepproxy"
586 ServiceNameKeepstore ServiceName = "keepstore"
589 // Map returns all services as a map, suitable for iterating over all
590 // services or looking up a service by name.
591 func (svcs Services) Map() map[ServiceName]Service {
592 return map[ServiceName]Service{
593 ServiceNameRailsAPI: svcs.RailsAPI,
594 ServiceNameController: svcs.Controller,
595 ServiceNameDispatchCloud: svcs.DispatchCloud,
596 ServiceNameHealth: svcs.Health,
597 ServiceNameWorkbench1: svcs.Workbench1,
598 ServiceNameWorkbench2: svcs.Workbench2,
599 ServiceNameWebsocket: svcs.Websocket,
600 ServiceNameKeepbalance: svcs.Keepbalance,
601 ServiceNameKeepweb: svcs.WebDAV,
602 ServiceNameKeepproxy: svcs.Keepproxy,
603 ServiceNameKeepstore: svcs.Keepstore,