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
29 // GetConfig returns the current system config, loading it from
30 // configFile if needed.
31 func GetConfig(configFile string) (*Config, error) {
33 err := config.LoadFile(&cfg, configFile)
37 // GetCluster returns the cluster ID and config for the given
38 // cluster, or the default/only configured cluster if clusterID is "".
39 func (sc *Config) GetCluster(clusterID string) (*Cluster, error) {
41 if len(sc.Clusters) == 0 {
42 return nil, fmt.Errorf("no clusters configured")
43 } else if len(sc.Clusters) > 1 {
44 return nil, fmt.Errorf("multiple clusters configured, cannot choose")
46 for id, cc := range sc.Clusters {
52 if cc, ok := sc.Clusters[clusterID]; !ok {
53 return nil, fmt.Errorf("cluster %q is not configured", clusterID)
55 cc.ClusterID = clusterID
60 type WebDAVCacheConfig struct {
64 MaxCollectionEntries int
65 MaxCollectionBytes int64
66 MaxPermissionEntries int
70 ClusterID string `json:"-"`
71 ManagementToken string
72 SystemRootToken string
74 InstanceTypes InstanceTypeMap
75 Containers ContainersConfig
76 RemoteClusters map[string]RemoteCluster
80 AsyncPermissionsUpdateInterval Duration
81 DisabledAPIs StringSet
82 MaxIndexDatabaseRead int
83 MaxItemsPerResponse int
84 MaxConcurrentRequests int
85 MaxKeepBlobBuffers int
86 MaxRequestAmplification int
88 RailsSessionSecretToken string
89 RequestTimeout Duration
91 WebsocketClientEventQueue int
92 WebsocketServerEventQueue int
93 KeepServiceRequestTimeout Duration
98 UnloggedAttributes StringSet
102 BlobSigningKey string
103 BlobSigningTTL Duration
105 BlobTrashLifetime Duration
106 BlobTrashCheckInterval Duration
107 BlobTrashConcurrency int
108 BlobDeleteConcurrency int
109 BlobReplicateConcurrency int
110 CollectionVersioning bool
111 DefaultTrashLifetime Duration
112 DefaultReplication int
113 ManagedProperties map[string]struct {
118 PreserveVersionIfIdle Duration
119 TrashSweepInterval Duration
121 ForwardSlashNameSubstitution string
123 BlobMissingReport string
124 BalancePeriod Duration
125 BalanceCollectionBatch int
126 BalanceCollectionBuffers int
128 WebDAVCache WebDAVCacheConfig
136 GoogleClientID string
137 GoogleClientSecret string
138 GoogleAlternateEmailAddresses bool
141 PAMDefaultEmailDomain string
143 ProviderAppSecret string
145 RemoteTokenRefresh Duration
148 MailchimpAPIKey string
149 MailchimpListID string
150 SendUserSetupNotificationEmail bool
151 IssueReporterEmailFrom string
152 IssueReporterEmailTo string
153 SupportEmailAddress string
159 MaxRequestLogParamsSize int
167 AnonymousUserToken string
168 AdminNotifierEmailFrom string
169 AutoAdminFirstUser bool
170 AutoAdminUserWithEmail string
171 AutoSetupNewUsers bool
172 AutoSetupNewUsersWithRepository bool
173 AutoSetupNewUsersWithVmUUID string
174 AutoSetupUsernameBlacklist StringSet
175 EmailSubjectPrefix string
176 NewInactiveUserNotificationRecipients StringSet
177 NewUserNotificationRecipients StringSet
178 NewUsersAreActive bool
179 UserNotifierEmailFrom string
180 UserProfileNotificationAddress string
181 PreferDomainForUsername string
183 Volumes map[string]Volume
185 ActivationContactLink string
186 APIClientConnectTimeout Duration
187 APIClientReceiveTimeout Duration
188 APIResponseCompression bool
189 ApplicationMimetypesWithViewIcon StringSet
190 ArvadosDocsite string
191 ArvadosPublicDataDocURL string
192 DefaultOpenIdPrefix string
193 EnableGettingStartedPopup bool
194 EnablePublicProjectsPage bool
195 FileViewersConfigURL string
196 LogViewerMaxBytes ByteSize
197 MultiSiteSearch string
198 ProfilingEnabled bool
200 RepositoryCache string
201 RunningJobLogRecordsToFetch int
203 ShowRecentCollectionsOnDashboard bool
204 ShowUserAgreementInline bool
205 ShowUserNotifications bool
208 UserProfileFormFields map[string]struct {
210 FormFieldTitle string
211 FormFieldDescription string
214 Options map[string]struct{}
216 UserProfileFormMessage string
218 WelcomePageHTML string
219 InactivePageHTML string
220 SSHHelpPageHTML string
221 SSHHelpHostSuffix string
224 ForceLegacyAPI14 bool
228 AccessViaHosts map[URL]VolumeAccess
231 StorageClasses map[string]bool
233 DriverParameters json.RawMessage
236 type S3VolumeDriverParameters struct {
242 LocationConstraint bool
244 ConnectTimeout Duration
250 type AzureVolumeDriverParameters struct {
251 StorageAccountName string
252 StorageAccountKey string
253 StorageBaseURL string
255 RequestTimeout Duration
256 ListBlobsRetryDelay Duration
257 ListBlobsMaxAttempts int
260 type DirectoryVolumeDriverParameters struct {
265 type VolumeAccess struct {
269 type Services struct {
272 DispatchCloud Service
282 WebDAVDownload Service
290 type Service struct {
291 InternalURLs map[URL]ServiceInstance
295 // URL is a url.URL that is also usable as a JSON key/value.
298 // UnmarshalText implements encoding.TextUnmarshaler so URL can be
299 // used as a JSON key/value.
300 func (su *URL) UnmarshalText(text []byte) error {
301 u, err := url.Parse(string(text))
308 func (su URL) MarshalText() ([]byte, error) {
309 return []byte(fmt.Sprintf("%s", (*url.URL)(&su).String())), nil
312 func (su URL) String() string {
313 return (*url.URL)(&su).String()
316 type ServiceInstance struct {
317 Rendezvous string `json:",omitempty"`
320 type PostgreSQL struct {
321 Connection PostgreSQLConnection
325 type PostgreSQLConnection map[string]string
327 type RemoteCluster struct {
335 type InstanceType struct {
341 IncludedScratch ByteSize
342 AddedScratch ByteSize
347 type ContainersConfig struct {
348 CloudVMs CloudVMsConfig
349 CrunchRunCommand string
350 CrunchRunArgumentsList []string
351 DefaultKeepCacheRAM ByteSize
352 DispatchPrivateKey string
353 LogReuseDecisions bool
355 MaxDispatchAttempts int
357 MinRetryPeriod Duration
358 ReserveExtraRAM ByteSize
359 StaleLockTimeout Duration
360 SupportedDockerImageFormats StringSet
361 UsePreemptibleInstances bool
365 GitInternalDir string
370 LogSecondsBetweenEvents Duration
371 LogThrottlePeriod Duration
374 LimitLogBytesPerJob int
375 LogPartialLineThrottlePeriod Duration
376 LogUpdatePeriod Duration
377 LogUpdateSize ByteSize
381 SbatchArgumentsList []string
382 SbatchEnvironmentVariables map[string]string
384 DNSServerConfDir string
385 DNSServerConfTemplate string
386 DNSServerReloadCommand string
387 DNSServerUpdateCommand string
388 ComputeNodeDomain string
389 ComputeNodeNameservers StringSet
390 AssignNodeHostname string
395 type CloudVMsConfig struct {
398 BootProbeCommand string
399 DeployRunnerBinary string
401 MaxCloudOpsPerSecond int
402 MaxProbesPerSecond int
403 PollInterval Duration
404 ProbeInterval Duration
406 SyncInterval Duration
407 TimeoutBooting Duration
409 TimeoutProbe Duration
410 TimeoutShutdown Duration
411 TimeoutSignal Duration
413 ResourceTags map[string]string
417 DriverParameters json.RawMessage
420 type InstanceTypeMap map[string]InstanceType
422 var errDuplicateInstanceTypeName = errors.New("duplicate instance type name")
424 // UnmarshalJSON handles old config files that provide an array of
425 // instance types instead of a hash.
426 func (it *InstanceTypeMap) UnmarshalJSON(data []byte) error {
427 fixup := func(t InstanceType) (InstanceType, error) {
428 if t.ProviderType == "" {
429 t.ProviderType = t.Name
432 t.Scratch = t.IncludedScratch + t.AddedScratch
433 } else if t.AddedScratch == 0 {
434 t.AddedScratch = t.Scratch - t.IncludedScratch
435 } else if t.IncludedScratch == 0 {
436 t.IncludedScratch = t.Scratch - t.AddedScratch
439 if t.Scratch != (t.IncludedScratch + t.AddedScratch) {
440 return t, fmt.Errorf("InstanceType %q: Scratch != (IncludedScratch + AddedScratch)", t.Name)
445 if len(data) > 0 && data[0] == '[' {
446 var arr []InstanceType
447 err := json.Unmarshal(data, &arr)
455 *it = make(map[string]InstanceType, len(arr))
456 for _, t := range arr {
457 if _, ok := (*it)[t.Name]; ok {
458 return errDuplicateInstanceTypeName
468 var hash map[string]InstanceType
469 err := json.Unmarshal(data, &hash)
473 // Fill in Name field (and ProviderType field, if not
474 // specified) using hash key.
475 *it = InstanceTypeMap(hash)
476 for name, t := range *it {
487 type StringSet map[string]struct{}
489 // UnmarshalJSON handles old config files that provide an array of
490 // instance types instead of a hash.
491 func (ss *StringSet) UnmarshalJSON(data []byte) error {
492 if len(data) > 0 && data[0] == '[' {
494 err := json.Unmarshal(data, &arr)
502 *ss = make(map[string]struct{}, len(arr))
503 for _, t := range arr {
504 (*ss)[t] = struct{}{}
508 var hash map[string]struct{}
509 err := json.Unmarshal(data, &hash)
513 *ss = make(map[string]struct{}, len(hash))
514 for t, _ := range hash {
515 (*ss)[t] = struct{}{}
521 type ServiceName string
524 ServiceNameRailsAPI ServiceName = "arvados-api-server"
525 ServiceNameController ServiceName = "arvados-controller"
526 ServiceNameDispatchCloud ServiceName = "arvados-dispatch-cloud"
527 ServiceNameHealth ServiceName = "arvados-health"
528 ServiceNameNodemanager ServiceName = "arvados-node-manager"
529 ServiceNameWorkbench1 ServiceName = "arvados-workbench1"
530 ServiceNameWorkbench2 ServiceName = "arvados-workbench2"
531 ServiceNameWebsocket ServiceName = "arvados-ws"
532 ServiceNameKeepbalance ServiceName = "keep-balance"
533 ServiceNameKeepweb ServiceName = "keep-web"
534 ServiceNameKeepproxy ServiceName = "keepproxy"
535 ServiceNameKeepstore ServiceName = "keepstore"
538 // Map returns all services as a map, suitable for iterating over all
539 // services or looking up a service by name.
540 func (svcs Services) Map() map[ServiceName]Service {
541 return map[ServiceName]Service{
542 ServiceNameRailsAPI: svcs.RailsAPI,
543 ServiceNameController: svcs.Controller,
544 ServiceNameDispatchCloud: svcs.DispatchCloud,
545 ServiceNameHealth: svcs.Health,
546 ServiceNameNodemanager: svcs.Nodemanager,
547 ServiceNameWorkbench1: svcs.Workbench1,
548 ServiceNameWorkbench2: svcs.Workbench2,
549 ServiceNameWebsocket: svcs.Websocket,
550 ServiceNameKeepbalance: svcs.Keepbalance,
551 ServiceNameKeepweb: svcs.WebDAV,
552 ServiceNameKeepproxy: svcs.Keepproxy,
553 ServiceNameKeepstore: svcs.Keepstore,