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
157 AlternateEmailAddresses bool
159 OpenIDConnect struct {
168 DefaultEmailDomain string
173 ProviderAppSecret string
176 RemoteTokenRefresh Duration
179 MailchimpAPIKey string
180 MailchimpListID string
181 SendUserSetupNotificationEmail bool
182 IssueReporterEmailFrom string
183 IssueReporterEmailTo string
184 SupportEmailAddress string
190 MaxRequestLogParamsSize int
198 AnonymousUserToken string
199 AdminNotifierEmailFrom string
200 AutoAdminFirstUser bool
201 AutoAdminUserWithEmail string
202 AutoSetupNewUsers bool
203 AutoSetupNewUsersWithRepository bool
204 AutoSetupNewUsersWithVmUUID string
205 AutoSetupUsernameBlacklist StringSet
206 EmailSubjectPrefix string
207 NewInactiveUserNotificationRecipients StringSet
208 NewUserNotificationRecipients StringSet
209 NewUsersAreActive bool
210 UserNotifierEmailFrom string
211 UserProfileNotificationAddress string
212 PreferDomainForUsername string
214 Volumes map[string]Volume
216 ActivationContactLink string
217 APIClientConnectTimeout Duration
218 APIClientReceiveTimeout Duration
219 APIResponseCompression bool
220 ApplicationMimetypesWithViewIcon StringSet
221 ArvadosDocsite string
222 ArvadosPublicDataDocURL string
223 DefaultOpenIdPrefix string
224 EnableGettingStartedPopup bool
225 EnablePublicProjectsPage bool
226 FileViewersConfigURL string
227 LogViewerMaxBytes ByteSize
228 MultiSiteSearch string
229 ProfilingEnabled bool
231 RepositoryCache string
232 RunningJobLogRecordsToFetch int
234 ShowRecentCollectionsOnDashboard bool
235 ShowUserAgreementInline bool
236 ShowUserNotifications bool
239 UserProfileFormFields map[string]struct {
241 FormFieldTitle string
242 FormFieldDescription string
245 Options map[string]struct{}
247 UserProfileFormMessage string
249 WelcomePageHTML string
250 InactivePageHTML string
251 SSHHelpPageHTML string
252 SSHHelpHostSuffix string
255 ForceLegacyAPI14 bool
259 AccessViaHosts map[URL]VolumeAccess
262 StorageClasses map[string]bool
264 DriverParameters json.RawMessage
267 type S3VolumeDriverParameters struct {
274 LocationConstraint bool
277 ConnectTimeout Duration
283 type AzureVolumeDriverParameters struct {
284 StorageAccountName string
285 StorageAccountKey string
286 StorageBaseURL string
288 RequestTimeout Duration
289 ListBlobsRetryDelay Duration
290 ListBlobsMaxAttempts int
293 type DirectoryVolumeDriverParameters struct {
298 type VolumeAccess struct {
302 type Services struct {
305 DispatchCloud Service
315 WebDAVDownload Service
323 type Service struct {
324 InternalURLs map[URL]ServiceInstance
328 // URL is a url.URL that is also usable as a JSON key/value.
331 // UnmarshalText implements encoding.TextUnmarshaler so URL can be
332 // used as a JSON key/value.
333 func (su *URL) UnmarshalText(text []byte) error {
334 u, err := url.Parse(string(text))
337 if su.Path == "" && su.Host != "" {
338 // http://example really means http://example/
345 func (su URL) MarshalText() ([]byte, error) {
346 return []byte(fmt.Sprintf("%s", (*url.URL)(&su).String())), nil
349 func (su URL) String() string {
350 return (*url.URL)(&su).String()
353 type ServiceInstance struct {
354 Rendezvous string `json:",omitempty"`
357 type PostgreSQL struct {
358 Connection PostgreSQLConnection
362 type PostgreSQLConnection map[string]string
364 type RemoteCluster struct {
372 type InstanceType struct {
378 IncludedScratch ByteSize
379 AddedScratch ByteSize
384 type ContainersConfig struct {
385 CloudVMs CloudVMsConfig
386 CrunchRunCommand string
387 CrunchRunArgumentsList []string
388 DefaultKeepCacheRAM ByteSize
389 DispatchPrivateKey string
390 LogReuseDecisions bool
392 MaxDispatchAttempts int
394 MinRetryPeriod Duration
395 ReserveExtraRAM ByteSize
396 StaleLockTimeout Duration
397 SupportedDockerImageFormats StringSet
398 UsePreemptibleInstances bool
402 GitInternalDir string
407 LogSecondsBetweenEvents Duration
408 LogThrottlePeriod Duration
411 LimitLogBytesPerJob int
412 LogPartialLineThrottlePeriod Duration
413 LogUpdatePeriod Duration
414 LogUpdateSize ByteSize
418 SbatchArgumentsList []string
419 SbatchEnvironmentVariables map[string]string
421 DNSServerConfDir string
422 DNSServerConfTemplate string
423 DNSServerReloadCommand string
424 DNSServerUpdateCommand string
425 ComputeNodeDomain string
426 ComputeNodeNameservers StringSet
427 AssignNodeHostname string
432 type CloudVMsConfig struct {
435 BootProbeCommand string
436 DeployRunnerBinary string
438 MaxCloudOpsPerSecond int
439 MaxProbesPerSecond int
440 PollInterval Duration
441 ProbeInterval Duration
443 SyncInterval Duration
444 TimeoutBooting Duration
446 TimeoutProbe Duration
447 TimeoutShutdown Duration
448 TimeoutSignal Duration
450 ResourceTags map[string]string
454 DriverParameters json.RawMessage
457 type InstanceTypeMap map[string]InstanceType
459 var errDuplicateInstanceTypeName = errors.New("duplicate instance type name")
461 // UnmarshalJSON handles old config files that provide an array of
462 // instance types instead of a hash.
463 func (it *InstanceTypeMap) UnmarshalJSON(data []byte) error {
464 fixup := func(t InstanceType) (InstanceType, error) {
465 if t.ProviderType == "" {
466 t.ProviderType = t.Name
469 t.Scratch = t.IncludedScratch + t.AddedScratch
470 } else if t.AddedScratch == 0 {
471 t.AddedScratch = t.Scratch - t.IncludedScratch
472 } else if t.IncludedScratch == 0 {
473 t.IncludedScratch = t.Scratch - t.AddedScratch
476 if t.Scratch != (t.IncludedScratch + t.AddedScratch) {
477 return t, fmt.Errorf("InstanceType %q: Scratch != (IncludedScratch + AddedScratch)", t.Name)
482 if len(data) > 0 && data[0] == '[' {
483 var arr []InstanceType
484 err := json.Unmarshal(data, &arr)
492 *it = make(map[string]InstanceType, len(arr))
493 for _, t := range arr {
494 if _, ok := (*it)[t.Name]; ok {
495 return errDuplicateInstanceTypeName
505 var hash map[string]InstanceType
506 err := json.Unmarshal(data, &hash)
510 // Fill in Name field (and ProviderType field, if not
511 // specified) using hash key.
512 *it = InstanceTypeMap(hash)
513 for name, t := range *it {
524 type StringSet map[string]struct{}
526 // UnmarshalJSON handles old config files that provide an array of
527 // instance types instead of a hash.
528 func (ss *StringSet) UnmarshalJSON(data []byte) error {
529 if len(data) > 0 && data[0] == '[' {
531 err := json.Unmarshal(data, &arr)
539 *ss = make(map[string]struct{}, len(arr))
540 for _, t := range arr {
541 (*ss)[t] = struct{}{}
545 var hash map[string]struct{}
546 err := json.Unmarshal(data, &hash)
550 *ss = make(map[string]struct{}, len(hash))
551 for t, _ := range hash {
552 (*ss)[t] = struct{}{}
558 type ServiceName string
561 ServiceNameRailsAPI ServiceName = "arvados-api-server"
562 ServiceNameController ServiceName = "arvados-controller"
563 ServiceNameDispatchCloud ServiceName = "arvados-dispatch-cloud"
564 ServiceNameHealth ServiceName = "arvados-health"
565 ServiceNameNodemanager ServiceName = "arvados-node-manager"
566 ServiceNameWorkbench1 ServiceName = "arvados-workbench1"
567 ServiceNameWorkbench2 ServiceName = "arvados-workbench2"
568 ServiceNameWebsocket ServiceName = "arvados-ws"
569 ServiceNameKeepbalance ServiceName = "keep-balance"
570 ServiceNameKeepweb ServiceName = "keep-web"
571 ServiceNameKeepproxy ServiceName = "keepproxy"
572 ServiceNameKeepstore ServiceName = "keepstore"
575 // Map returns all services as a map, suitable for iterating over all
576 // services or looking up a service by name.
577 func (svcs Services) Map() map[ServiceName]Service {
578 return map[ServiceName]Service{
579 ServiceNameRailsAPI: svcs.RailsAPI,
580 ServiceNameController: svcs.Controller,
581 ServiceNameDispatchCloud: svcs.DispatchCloud,
582 ServiceNameHealth: svcs.Health,
583 ServiceNameNodemanager: svcs.Nodemanager,
584 ServiceNameWorkbench1: svcs.Workbench1,
585 ServiceNameWorkbench2: svcs.Workbench2,
586 ServiceNameWebsocket: svcs.Websocket,
587 ServiceNameKeepbalance: svcs.Keepbalance,
588 ServiceNameKeepweb: svcs.WebDAV,
589 ServiceNameKeepproxy: svcs.Keepproxy,
590 ServiceNameKeepstore: svcs.Keepstore,