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))
306 if su.Path == "" && su.Host != "" {
307 // http://example really means http://example/
314 func (su URL) MarshalText() ([]byte, error) {
315 return []byte(fmt.Sprintf("%s", (*url.URL)(&su).String())), nil
318 func (su URL) String() string {
319 return (*url.URL)(&su).String()
322 type ServiceInstance struct {
323 Rendezvous string `json:",omitempty"`
326 type PostgreSQL struct {
327 Connection PostgreSQLConnection
331 type PostgreSQLConnection map[string]string
333 type RemoteCluster struct {
341 type InstanceType struct {
347 IncludedScratch ByteSize
348 AddedScratch ByteSize
353 type ContainersConfig struct {
354 CloudVMs CloudVMsConfig
355 CrunchRunCommand string
356 CrunchRunArgumentsList []string
357 DefaultKeepCacheRAM ByteSize
358 DispatchPrivateKey string
359 LogReuseDecisions bool
361 MaxDispatchAttempts int
363 MinRetryPeriod Duration
364 ReserveExtraRAM ByteSize
365 StaleLockTimeout Duration
366 SupportedDockerImageFormats StringSet
367 UsePreemptibleInstances bool
371 GitInternalDir string
376 LogSecondsBetweenEvents Duration
377 LogThrottlePeriod Duration
380 LimitLogBytesPerJob int
381 LogPartialLineThrottlePeriod Duration
382 LogUpdatePeriod Duration
383 LogUpdateSize ByteSize
387 SbatchArgumentsList []string
388 SbatchEnvironmentVariables map[string]string
390 DNSServerConfDir string
391 DNSServerConfTemplate string
392 DNSServerReloadCommand string
393 DNSServerUpdateCommand string
394 ComputeNodeDomain string
395 ComputeNodeNameservers StringSet
396 AssignNodeHostname string
401 type CloudVMsConfig struct {
404 BootProbeCommand string
405 DeployRunnerBinary string
407 MaxCloudOpsPerSecond int
408 MaxProbesPerSecond int
409 PollInterval Duration
410 ProbeInterval Duration
412 SyncInterval Duration
413 TimeoutBooting Duration
415 TimeoutProbe Duration
416 TimeoutShutdown Duration
417 TimeoutSignal Duration
419 ResourceTags map[string]string
423 DriverParameters json.RawMessage
426 type InstanceTypeMap map[string]InstanceType
428 var errDuplicateInstanceTypeName = errors.New("duplicate instance type name")
430 // UnmarshalJSON handles old config files that provide an array of
431 // instance types instead of a hash.
432 func (it *InstanceTypeMap) UnmarshalJSON(data []byte) error {
433 fixup := func(t InstanceType) (InstanceType, error) {
434 if t.ProviderType == "" {
435 t.ProviderType = t.Name
438 t.Scratch = t.IncludedScratch + t.AddedScratch
439 } else if t.AddedScratch == 0 {
440 t.AddedScratch = t.Scratch - t.IncludedScratch
441 } else if t.IncludedScratch == 0 {
442 t.IncludedScratch = t.Scratch - t.AddedScratch
445 if t.Scratch != (t.IncludedScratch + t.AddedScratch) {
446 return t, fmt.Errorf("InstanceType %q: Scratch != (IncludedScratch + AddedScratch)", t.Name)
451 if len(data) > 0 && data[0] == '[' {
452 var arr []InstanceType
453 err := json.Unmarshal(data, &arr)
461 *it = make(map[string]InstanceType, len(arr))
462 for _, t := range arr {
463 if _, ok := (*it)[t.Name]; ok {
464 return errDuplicateInstanceTypeName
474 var hash map[string]InstanceType
475 err := json.Unmarshal(data, &hash)
479 // Fill in Name field (and ProviderType field, if not
480 // specified) using hash key.
481 *it = InstanceTypeMap(hash)
482 for name, t := range *it {
493 type StringSet map[string]struct{}
495 // UnmarshalJSON handles old config files that provide an array of
496 // instance types instead of a hash.
497 func (ss *StringSet) UnmarshalJSON(data []byte) error {
498 if len(data) > 0 && data[0] == '[' {
500 err := json.Unmarshal(data, &arr)
508 *ss = make(map[string]struct{}, len(arr))
509 for _, t := range arr {
510 (*ss)[t] = struct{}{}
514 var hash map[string]struct{}
515 err := json.Unmarshal(data, &hash)
519 *ss = make(map[string]struct{}, len(hash))
520 for t, _ := range hash {
521 (*ss)[t] = struct{}{}
527 type ServiceName string
530 ServiceNameRailsAPI ServiceName = "arvados-api-server"
531 ServiceNameController ServiceName = "arvados-controller"
532 ServiceNameDispatchCloud ServiceName = "arvados-dispatch-cloud"
533 ServiceNameHealth ServiceName = "arvados-health"
534 ServiceNameNodemanager ServiceName = "arvados-node-manager"
535 ServiceNameWorkbench1 ServiceName = "arvados-workbench1"
536 ServiceNameWorkbench2 ServiceName = "arvados-workbench2"
537 ServiceNameWebsocket ServiceName = "arvados-ws"
538 ServiceNameKeepbalance ServiceName = "keep-balance"
539 ServiceNameKeepweb ServiceName = "keep-web"
540 ServiceNameKeepproxy ServiceName = "keepproxy"
541 ServiceNameKeepstore ServiceName = "keepstore"
544 // Map returns all services as a map, suitable for iterating over all
545 // services or looking up a service by name.
546 func (svcs Services) Map() map[ServiceName]Service {
547 return map[ServiceName]Service{
548 ServiceNameRailsAPI: svcs.RailsAPI,
549 ServiceNameController: svcs.Controller,
550 ServiceNameDispatchCloud: svcs.DispatchCloud,
551 ServiceNameHealth: svcs.Health,
552 ServiceNameNodemanager: svcs.Nodemanager,
553 ServiceNameWorkbench1: svcs.Workbench1,
554 ServiceNameWorkbench2: svcs.Workbench2,
555 ServiceNameWebsocket: svcs.Websocket,
556 ServiceNameKeepbalance: svcs.Keepbalance,
557 ServiceNameKeepweb: svcs.WebDAV,
558 ServiceNameKeepproxy: svcs.Keepproxy,
559 ServiceNameKeepstore: svcs.Keepstore,