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
130 WebDAVCache WebDAVCacheConfig
138 GoogleClientID string
139 GoogleClientSecret string
140 GoogleAlternateEmailAddresses bool
143 PAMDefaultEmailDomain string
145 ProviderAppSecret string
147 RemoteTokenRefresh Duration
150 MailchimpAPIKey string
151 MailchimpListID string
152 SendUserSetupNotificationEmail bool
153 IssueReporterEmailFrom string
154 IssueReporterEmailTo string
155 SupportEmailAddress string
161 MaxRequestLogParamsSize int
169 AnonymousUserToken string
170 AdminNotifierEmailFrom string
171 AutoAdminFirstUser bool
172 AutoAdminUserWithEmail string
173 AutoSetupNewUsers bool
174 AutoSetupNewUsersWithRepository bool
175 AutoSetupNewUsersWithVmUUID string
176 AutoSetupUsernameBlacklist StringSet
177 EmailSubjectPrefix string
178 NewInactiveUserNotificationRecipients StringSet
179 NewUserNotificationRecipients StringSet
180 NewUsersAreActive bool
181 UserNotifierEmailFrom string
182 UserProfileNotificationAddress string
183 PreferDomainForUsername string
185 Volumes map[string]Volume
187 ActivationContactLink string
188 APIClientConnectTimeout Duration
189 APIClientReceiveTimeout Duration
190 APIResponseCompression bool
191 ApplicationMimetypesWithViewIcon StringSet
192 ArvadosDocsite string
193 ArvadosPublicDataDocURL string
194 DefaultOpenIdPrefix string
195 EnableGettingStartedPopup bool
196 EnablePublicProjectsPage bool
197 FileViewersConfigURL string
198 LogViewerMaxBytes ByteSize
199 MultiSiteSearch string
200 ProfilingEnabled bool
202 RepositoryCache string
203 RunningJobLogRecordsToFetch int
205 ShowRecentCollectionsOnDashboard bool
206 ShowUserAgreementInline bool
207 ShowUserNotifications bool
210 UserProfileFormFields map[string]struct {
212 FormFieldTitle string
213 FormFieldDescription string
216 Options map[string]struct{}
218 UserProfileFormMessage string
220 WelcomePageHTML string
221 InactivePageHTML string
222 SSHHelpPageHTML string
223 SSHHelpHostSuffix string
226 ForceLegacyAPI14 bool
230 AccessViaHosts map[URL]VolumeAccess
233 StorageClasses map[string]bool
235 DriverParameters json.RawMessage
238 type S3VolumeDriverParameters struct {
244 LocationConstraint bool
246 ConnectTimeout Duration
252 type AzureVolumeDriverParameters struct {
253 StorageAccountName string
254 StorageAccountKey string
255 StorageBaseURL string
257 RequestTimeout Duration
258 ListBlobsRetryDelay Duration
259 ListBlobsMaxAttempts int
262 type DirectoryVolumeDriverParameters struct {
267 type VolumeAccess struct {
271 type Services struct {
274 DispatchCloud Service
284 WebDAVDownload Service
292 type Service struct {
293 InternalURLs map[URL]ServiceInstance
297 // URL is a url.URL that is also usable as a JSON key/value.
300 // UnmarshalText implements encoding.TextUnmarshaler so URL can be
301 // used as a JSON key/value.
302 func (su *URL) UnmarshalText(text []byte) error {
303 u, err := url.Parse(string(text))
310 func (su URL) MarshalText() ([]byte, error) {
311 return []byte(fmt.Sprintf("%s", (*url.URL)(&su).String())), nil
314 func (su URL) String() string {
315 return (*url.URL)(&su).String()
318 type ServiceInstance struct {
319 Rendezvous string `json:",omitempty"`
322 type PostgreSQL struct {
323 Connection PostgreSQLConnection
327 type PostgreSQLConnection map[string]string
329 type RemoteCluster struct {
337 type InstanceType struct {
343 IncludedScratch ByteSize
344 AddedScratch ByteSize
349 type ContainersConfig struct {
350 CloudVMs CloudVMsConfig
351 CrunchRunCommand string
352 CrunchRunArgumentsList []string
353 DefaultKeepCacheRAM ByteSize
354 DispatchPrivateKey string
355 LogReuseDecisions bool
357 MaxDispatchAttempts int
359 MinRetryPeriod Duration
360 ReserveExtraRAM ByteSize
361 StaleLockTimeout Duration
362 SupportedDockerImageFormats StringSet
363 UsePreemptibleInstances bool
367 GitInternalDir string
372 LogSecondsBetweenEvents Duration
373 LogThrottlePeriod Duration
376 LimitLogBytesPerJob int
377 LogPartialLineThrottlePeriod Duration
378 LogUpdatePeriod Duration
379 LogUpdateSize ByteSize
383 SbatchArgumentsList []string
384 SbatchEnvironmentVariables map[string]string
386 DNSServerConfDir string
387 DNSServerConfTemplate string
388 DNSServerReloadCommand string
389 DNSServerUpdateCommand string
390 ComputeNodeDomain string
391 ComputeNodeNameservers StringSet
392 AssignNodeHostname string
397 type CloudVMsConfig struct {
400 BootProbeCommand string
401 DeployRunnerBinary string
403 MaxCloudOpsPerSecond int
404 MaxProbesPerSecond int
405 PollInterval Duration
406 ProbeInterval Duration
408 SyncInterval Duration
409 TimeoutBooting Duration
411 TimeoutProbe Duration
412 TimeoutShutdown Duration
413 TimeoutSignal Duration
415 ResourceTags map[string]string
419 DriverParameters json.RawMessage
422 type InstanceTypeMap map[string]InstanceType
424 var errDuplicateInstanceTypeName = errors.New("duplicate instance type name")
426 // UnmarshalJSON handles old config files that provide an array of
427 // instance types instead of a hash.
428 func (it *InstanceTypeMap) UnmarshalJSON(data []byte) error {
429 fixup := func(t InstanceType) (InstanceType, error) {
430 if t.ProviderType == "" {
431 t.ProviderType = t.Name
434 t.Scratch = t.IncludedScratch + t.AddedScratch
435 } else if t.AddedScratch == 0 {
436 t.AddedScratch = t.Scratch - t.IncludedScratch
437 } else if t.IncludedScratch == 0 {
438 t.IncludedScratch = t.Scratch - t.AddedScratch
441 if t.Scratch != (t.IncludedScratch + t.AddedScratch) {
442 return t, fmt.Errorf("InstanceType %q: Scratch != (IncludedScratch + AddedScratch)", t.Name)
447 if len(data) > 0 && data[0] == '[' {
448 var arr []InstanceType
449 err := json.Unmarshal(data, &arr)
457 *it = make(map[string]InstanceType, len(arr))
458 for _, t := range arr {
459 if _, ok := (*it)[t.Name]; ok {
460 return errDuplicateInstanceTypeName
470 var hash map[string]InstanceType
471 err := json.Unmarshal(data, &hash)
475 // Fill in Name field (and ProviderType field, if not
476 // specified) using hash key.
477 *it = InstanceTypeMap(hash)
478 for name, t := range *it {
489 type StringSet map[string]struct{}
491 // UnmarshalJSON handles old config files that provide an array of
492 // instance types instead of a hash.
493 func (ss *StringSet) UnmarshalJSON(data []byte) error {
494 if len(data) > 0 && data[0] == '[' {
496 err := json.Unmarshal(data, &arr)
504 *ss = make(map[string]struct{}, len(arr))
505 for _, t := range arr {
506 (*ss)[t] = struct{}{}
510 var hash map[string]struct{}
511 err := json.Unmarshal(data, &hash)
515 *ss = make(map[string]struct{}, len(hash))
516 for t, _ := range hash {
517 (*ss)[t] = struct{}{}
523 type ServiceName string
526 ServiceNameRailsAPI ServiceName = "arvados-api-server"
527 ServiceNameController ServiceName = "arvados-controller"
528 ServiceNameDispatchCloud ServiceName = "arvados-dispatch-cloud"
529 ServiceNameHealth ServiceName = "arvados-health"
530 ServiceNameNodemanager ServiceName = "arvados-node-manager"
531 ServiceNameWorkbench1 ServiceName = "arvados-workbench1"
532 ServiceNameWorkbench2 ServiceName = "arvados-workbench2"
533 ServiceNameWebsocket ServiceName = "arvados-ws"
534 ServiceNameKeepbalance ServiceName = "keep-balance"
535 ServiceNameKeepweb ServiceName = "keep-web"
536 ServiceNameKeepproxy ServiceName = "keepproxy"
537 ServiceNameKeepstore ServiceName = "keepstore"
540 // Map returns all services as a map, suitable for iterating over all
541 // services or looking up a service by name.
542 func (svcs Services) Map() map[ServiceName]Service {
543 return map[ServiceName]Service{
544 ServiceNameRailsAPI: svcs.RailsAPI,
545 ServiceNameController: svcs.Controller,
546 ServiceNameDispatchCloud: svcs.DispatchCloud,
547 ServiceNameHealth: svcs.Health,
548 ServiceNameNodemanager: svcs.Nodemanager,
549 ServiceNameWorkbench1: svcs.Workbench1,
550 ServiceNameWorkbench2: svcs.Workbench2,
551 ServiceNameWebsocket: svcs.Websocket,
552 ServiceNameKeepbalance: svcs.Keepbalance,
553 ServiceNameKeepweb: svcs.WebDAV,
554 ServiceNameKeepproxy: svcs.Keepproxy,
555 ServiceNameKeepstore: svcs.Keepstore,