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
145 SearchAttribute string
146 SearchBindUser string
147 SearchBindPassword string
150 EmailAttribute string
151 UsernameAttribute string
153 GoogleClientID string
154 GoogleClientSecret string
155 GoogleAlternateEmailAddresses bool
158 PAMDefaultEmailDomain string
160 ProviderAppSecret string
162 RemoteTokenRefresh Duration
165 MailchimpAPIKey string
166 MailchimpListID string
167 SendUserSetupNotificationEmail bool
168 IssueReporterEmailFrom string
169 IssueReporterEmailTo string
170 SupportEmailAddress string
176 MaxRequestLogParamsSize int
184 AnonymousUserToken string
185 AdminNotifierEmailFrom string
186 AutoAdminFirstUser bool
187 AutoAdminUserWithEmail string
188 AutoSetupNewUsers bool
189 AutoSetupNewUsersWithRepository bool
190 AutoSetupNewUsersWithVmUUID string
191 AutoSetupUsernameBlacklist StringSet
192 EmailSubjectPrefix string
193 NewInactiveUserNotificationRecipients StringSet
194 NewUserNotificationRecipients StringSet
195 NewUsersAreActive bool
196 UserNotifierEmailFrom string
197 UserProfileNotificationAddress string
198 PreferDomainForUsername string
200 Volumes map[string]Volume
202 ActivationContactLink string
203 APIClientConnectTimeout Duration
204 APIClientReceiveTimeout Duration
205 APIResponseCompression bool
206 ApplicationMimetypesWithViewIcon StringSet
207 ArvadosDocsite string
208 ArvadosPublicDataDocURL string
209 DefaultOpenIdPrefix string
210 EnableGettingStartedPopup bool
211 EnablePublicProjectsPage bool
212 FileViewersConfigURL string
213 LogViewerMaxBytes ByteSize
214 MultiSiteSearch string
215 ProfilingEnabled bool
217 RepositoryCache string
218 RunningJobLogRecordsToFetch int
220 ShowRecentCollectionsOnDashboard bool
221 ShowUserAgreementInline bool
222 ShowUserNotifications bool
225 UserProfileFormFields map[string]struct {
227 FormFieldTitle string
228 FormFieldDescription string
231 Options map[string]struct{}
233 UserProfileFormMessage string
235 WelcomePageHTML string
236 InactivePageHTML string
237 SSHHelpPageHTML string
238 SSHHelpHostSuffix string
241 ForceLegacyAPI14 bool
245 AccessViaHosts map[URL]VolumeAccess
248 StorageClasses map[string]bool
250 DriverParameters json.RawMessage
253 type S3VolumeDriverParameters struct {
259 LocationConstraint bool
261 ConnectTimeout Duration
267 type AzureVolumeDriverParameters struct {
268 StorageAccountName string
269 StorageAccountKey string
270 StorageBaseURL string
272 RequestTimeout Duration
273 ListBlobsRetryDelay Duration
274 ListBlobsMaxAttempts int
277 type DirectoryVolumeDriverParameters struct {
282 type VolumeAccess struct {
286 type Services struct {
289 DispatchCloud Service
299 WebDAVDownload Service
307 type Service struct {
308 InternalURLs map[URL]ServiceInstance
312 // URL is a url.URL that is also usable as a JSON key/value.
315 // UnmarshalText implements encoding.TextUnmarshaler so URL can be
316 // used as a JSON key/value.
317 func (su *URL) UnmarshalText(text []byte) error {
318 u, err := url.Parse(string(text))
325 func (su URL) MarshalText() ([]byte, error) {
326 return []byte(fmt.Sprintf("%s", (*url.URL)(&su).String())), nil
329 func (su URL) String() string {
330 return (*url.URL)(&su).String()
333 type ServiceInstance struct {
334 Rendezvous string `json:",omitempty"`
337 type PostgreSQL struct {
338 Connection PostgreSQLConnection
342 type PostgreSQLConnection map[string]string
344 type RemoteCluster struct {
352 type InstanceType struct {
358 IncludedScratch ByteSize
359 AddedScratch ByteSize
364 type ContainersConfig struct {
365 CloudVMs CloudVMsConfig
366 CrunchRunCommand string
367 CrunchRunArgumentsList []string
368 DefaultKeepCacheRAM ByteSize
369 DispatchPrivateKey string
370 LogReuseDecisions bool
372 MaxDispatchAttempts int
374 MinRetryPeriod Duration
375 ReserveExtraRAM ByteSize
376 StaleLockTimeout Duration
377 SupportedDockerImageFormats StringSet
378 UsePreemptibleInstances bool
382 GitInternalDir string
387 LogSecondsBetweenEvents Duration
388 LogThrottlePeriod Duration
391 LimitLogBytesPerJob int
392 LogPartialLineThrottlePeriod Duration
393 LogUpdatePeriod Duration
394 LogUpdateSize ByteSize
398 SbatchArgumentsList []string
399 SbatchEnvironmentVariables map[string]string
401 DNSServerConfDir string
402 DNSServerConfTemplate string
403 DNSServerReloadCommand string
404 DNSServerUpdateCommand string
405 ComputeNodeDomain string
406 ComputeNodeNameservers StringSet
407 AssignNodeHostname string
412 type CloudVMsConfig struct {
415 BootProbeCommand string
416 DeployRunnerBinary string
418 MaxCloudOpsPerSecond int
419 MaxProbesPerSecond int
420 PollInterval Duration
421 ProbeInterval Duration
423 SyncInterval Duration
424 TimeoutBooting Duration
426 TimeoutProbe Duration
427 TimeoutShutdown Duration
428 TimeoutSignal Duration
430 ResourceTags map[string]string
434 DriverParameters json.RawMessage
437 type InstanceTypeMap map[string]InstanceType
439 var errDuplicateInstanceTypeName = errors.New("duplicate instance type name")
441 // UnmarshalJSON handles old config files that provide an array of
442 // instance types instead of a hash.
443 func (it *InstanceTypeMap) UnmarshalJSON(data []byte) error {
444 fixup := func(t InstanceType) (InstanceType, error) {
445 if t.ProviderType == "" {
446 t.ProviderType = t.Name
449 t.Scratch = t.IncludedScratch + t.AddedScratch
450 } else if t.AddedScratch == 0 {
451 t.AddedScratch = t.Scratch - t.IncludedScratch
452 } else if t.IncludedScratch == 0 {
453 t.IncludedScratch = t.Scratch - t.AddedScratch
456 if t.Scratch != (t.IncludedScratch + t.AddedScratch) {
457 return t, fmt.Errorf("InstanceType %q: Scratch != (IncludedScratch + AddedScratch)", t.Name)
462 if len(data) > 0 && data[0] == '[' {
463 var arr []InstanceType
464 err := json.Unmarshal(data, &arr)
472 *it = make(map[string]InstanceType, len(arr))
473 for _, t := range arr {
474 if _, ok := (*it)[t.Name]; ok {
475 return errDuplicateInstanceTypeName
485 var hash map[string]InstanceType
486 err := json.Unmarshal(data, &hash)
490 // Fill in Name field (and ProviderType field, if not
491 // specified) using hash key.
492 *it = InstanceTypeMap(hash)
493 for name, t := range *it {
504 type StringSet map[string]struct{}
506 // UnmarshalJSON handles old config files that provide an array of
507 // instance types instead of a hash.
508 func (ss *StringSet) UnmarshalJSON(data []byte) error {
509 if len(data) > 0 && data[0] == '[' {
511 err := json.Unmarshal(data, &arr)
519 *ss = make(map[string]struct{}, len(arr))
520 for _, t := range arr {
521 (*ss)[t] = struct{}{}
525 var hash map[string]struct{}
526 err := json.Unmarshal(data, &hash)
530 *ss = make(map[string]struct{}, len(hash))
531 for t, _ := range hash {
532 (*ss)[t] = struct{}{}
538 type ServiceName string
541 ServiceNameRailsAPI ServiceName = "arvados-api-server"
542 ServiceNameController ServiceName = "arvados-controller"
543 ServiceNameDispatchCloud ServiceName = "arvados-dispatch-cloud"
544 ServiceNameHealth ServiceName = "arvados-health"
545 ServiceNameNodemanager ServiceName = "arvados-node-manager"
546 ServiceNameWorkbench1 ServiceName = "arvados-workbench1"
547 ServiceNameWorkbench2 ServiceName = "arvados-workbench2"
548 ServiceNameWebsocket ServiceName = "arvados-ws"
549 ServiceNameKeepbalance ServiceName = "keep-balance"
550 ServiceNameKeepweb ServiceName = "keep-web"
551 ServiceNameKeepproxy ServiceName = "keepproxy"
552 ServiceNameKeepstore ServiceName = "keepstore"
555 // Map returns all services as a map, suitable for iterating over all
556 // services or looking up a service by name.
557 func (svcs Services) Map() map[ServiceName]Service {
558 return map[ServiceName]Service{
559 ServiceNameRailsAPI: svcs.RailsAPI,
560 ServiceNameController: svcs.Controller,
561 ServiceNameDispatchCloud: svcs.DispatchCloud,
562 ServiceNameHealth: svcs.Health,
563 ServiceNameNodemanager: svcs.Nodemanager,
564 ServiceNameWorkbench1: svcs.Workbench1,
565 ServiceNameWorkbench2: svcs.Workbench2,
566 ServiceNameWebsocket: svcs.Websocket,
567 ServiceNameKeepbalance: svcs.Keepbalance,
568 ServiceNameKeepweb: svcs.WebDAV,
569 ServiceNameKeepproxy: svcs.Keepproxy,
570 ServiceNameKeepstore: svcs.Keepstore,