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"
25 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 cc, ok := sc.Clusters[clusterID]
54 return nil, fmt.Errorf("cluster %q is not configured", clusterID)
56 cc.ClusterID = clusterID
60 type WebDAVCacheConfig struct {
64 MaxCollectionEntries int
65 MaxCollectionBytes int64
66 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 MaxTokenLifetime Duration
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
126 BlobMissingReport string
127 BalancePeriod Duration
128 BalanceCollectionBatch int
129 BalanceCollectionBuffers int
130 BalanceTimeout Duration
132 WebDAVCache WebDAVCacheConfig
147 SearchAttribute string
148 SearchBindUser string
149 SearchBindPassword string
152 EmailAttribute string
153 UsernameAttribute string
159 AlternateEmailAddresses bool
160 AuthenticationRequestParameters map[string]string
162 OpenIDConnect struct {
168 EmailVerifiedClaim string
170 AcceptAccessToken bool
171 AcceptAccessTokenScope string
172 AuthenticationRequestParameters map[string]string
177 DefaultEmailDomain string
182 ProviderAppSecret string
186 Users map[string]TestUser
189 RemoteTokenRefresh Duration
190 TokenLifetime Duration
191 TrustedClients map[string]struct{}
192 IssueTrustedTokens bool
195 MailchimpAPIKey string
196 MailchimpListID string
197 SendUserSetupNotificationEmail bool
198 IssueReporterEmailFrom string
199 IssueReporterEmailTo string
200 SupportEmailAddress string
206 MaxRequestLogParamsSize int
214 AnonymousUserToken string
215 AdminNotifierEmailFrom string
216 AutoAdminFirstUser bool
217 AutoAdminUserWithEmail string
218 AutoSetupNewUsers bool
219 AutoSetupNewUsersWithRepository bool
220 AutoSetupNewUsersWithVmUUID string
221 AutoSetupUsernameBlacklist StringSet
222 EmailSubjectPrefix string
223 NewInactiveUserNotificationRecipients StringSet
224 NewUserNotificationRecipients StringSet
225 NewUsersAreActive bool
226 UserNotifierEmailFrom string
227 UserProfileNotificationAddress string
228 PreferDomainForUsername string
229 UserSetupMailText string
231 Volumes map[string]Volume
233 ActivationContactLink string
234 APIClientConnectTimeout Duration
235 APIClientReceiveTimeout Duration
236 APIResponseCompression bool
237 ApplicationMimetypesWithViewIcon StringSet
238 ArvadosDocsite string
239 ArvadosPublicDataDocURL string
240 DefaultOpenIdPrefix string
241 EnableGettingStartedPopup bool
242 EnablePublicProjectsPage bool
243 FileViewersConfigURL string
244 LogViewerMaxBytes ByteSize
245 MultiSiteSearch string
246 ProfilingEnabled bool
248 RepositoryCache string
249 RunningJobLogRecordsToFetch int
251 ShowRecentCollectionsOnDashboard bool
252 ShowUserAgreementInline bool
253 ShowUserNotifications bool
256 UserProfileFormFields map[string]struct {
258 FormFieldTitle string
259 FormFieldDescription string
262 Options map[string]struct{}
264 UserProfileFormMessage string
266 WelcomePageHTML string
267 InactivePageHTML string
268 SSHHelpPageHTML string
269 SSHHelpHostSuffix string
275 AccessViaHosts map[URL]VolumeAccess
278 StorageClasses map[string]bool
280 DriverParameters json.RawMessage
283 type S3VolumeDriverParameters struct {
286 SecretAccessKey string
290 LocationConstraint bool
292 UseAWSS3v2Driver bool
294 ConnectTimeout Duration
300 type AzureVolumeDriverParameters struct {
301 StorageAccountName string
302 StorageAccountKey string
303 StorageBaseURL string
305 RequestTimeout Duration
306 ListBlobsRetryDelay Duration
307 ListBlobsMaxAttempts int
310 type DirectoryVolumeDriverParameters struct {
315 type VolumeAccess struct {
319 type Services struct {
322 DispatchCloud Service
331 WebDAVDownload Service
339 type Service struct {
340 InternalURLs map[URL]ServiceInstance
344 type TestUser struct {
349 // URL is a url.URL that is also usable as a JSON key/value.
352 // UnmarshalText implements encoding.TextUnmarshaler so URL can be
353 // used as a JSON key/value.
354 func (su *URL) UnmarshalText(text []byte) error {
355 u, err := url.Parse(string(text))
358 if su.Path == "" && su.Host != "" {
359 // http://example really means http://example/
366 func (su URL) MarshalText() ([]byte, error) {
367 return []byte(fmt.Sprintf("%s", (*url.URL)(&su).String())), nil
370 func (su URL) String() string {
371 return (*url.URL)(&su).String()
374 type ServiceInstance struct {
375 Rendezvous string `json:",omitempty"`
378 type PostgreSQL struct {
379 Connection PostgreSQLConnection
383 type PostgreSQLConnection map[string]string
385 type RemoteCluster struct {
393 type InstanceType struct {
399 IncludedScratch ByteSize
400 AddedScratch ByteSize
405 type ContainersConfig struct {
406 CloudVMs CloudVMsConfig
407 CrunchRunCommand string
408 CrunchRunArgumentsList []string
409 DefaultKeepCacheRAM ByteSize
410 DispatchPrivateKey string
411 LogReuseDecisions bool
413 MaxDispatchAttempts int
415 MinRetryPeriod Duration
416 ReserveExtraRAM ByteSize
417 StaleLockTimeout Duration
418 SupportedDockerImageFormats StringSet
419 UsePreemptibleInstances bool
423 GitInternalDir string
428 LogSecondsBetweenEvents Duration
429 LogThrottlePeriod Duration
432 LimitLogBytesPerJob int
433 LogPartialLineThrottlePeriod Duration
434 LogUpdatePeriod Duration
435 LogUpdateSize ByteSize
443 SbatchArgumentsList []string
444 SbatchEnvironmentVariables map[string]string
446 DNSServerConfDir string
447 DNSServerConfTemplate string
448 DNSServerReloadCommand string
449 DNSServerUpdateCommand string
450 ComputeNodeDomain string
451 ComputeNodeNameservers StringSet
452 AssignNodeHostname string
457 type CloudVMsConfig struct {
460 BootProbeCommand string
461 DeployRunnerBinary string
463 MaxCloudOpsPerSecond int
464 MaxProbesPerSecond int
465 MaxConcurrentInstanceCreateOps int
466 PollInterval Duration
467 ProbeInterval Duration
469 SyncInterval Duration
470 TimeoutBooting Duration
472 TimeoutProbe Duration
473 TimeoutShutdown Duration
474 TimeoutSignal Duration
475 TimeoutStaleRunLock Duration
477 ResourceTags map[string]string
481 DriverParameters json.RawMessage
484 type InstanceTypeMap map[string]InstanceType
486 var errDuplicateInstanceTypeName = errors.New("duplicate instance type name")
488 // UnmarshalJSON handles old config files that provide an array of
489 // instance types instead of a hash.
490 func (it *InstanceTypeMap) UnmarshalJSON(data []byte) error {
491 fixup := func(t InstanceType) (InstanceType, error) {
492 if t.ProviderType == "" {
493 t.ProviderType = t.Name
496 t.Scratch = t.IncludedScratch + t.AddedScratch
497 } else if t.AddedScratch == 0 {
498 t.AddedScratch = t.Scratch - t.IncludedScratch
499 } else if t.IncludedScratch == 0 {
500 t.IncludedScratch = t.Scratch - t.AddedScratch
503 if t.Scratch != (t.IncludedScratch + t.AddedScratch) {
504 return t, fmt.Errorf("InstanceType %q: Scratch != (IncludedScratch + AddedScratch)", t.Name)
509 if len(data) > 0 && data[0] == '[' {
510 var arr []InstanceType
511 err := json.Unmarshal(data, &arr)
519 *it = make(map[string]InstanceType, len(arr))
520 for _, t := range arr {
521 if _, ok := (*it)[t.Name]; ok {
522 return errDuplicateInstanceTypeName
532 var hash map[string]InstanceType
533 err := json.Unmarshal(data, &hash)
537 // Fill in Name field (and ProviderType field, if not
538 // specified) using hash key.
539 *it = InstanceTypeMap(hash)
540 for name, t := range *it {
551 type StringSet map[string]struct{}
553 // UnmarshalJSON handles old config files that provide an array of
554 // instance types instead of a hash.
555 func (ss *StringSet) UnmarshalJSON(data []byte) error {
556 if len(data) > 0 && data[0] == '[' {
558 err := json.Unmarshal(data, &arr)
566 *ss = make(map[string]struct{}, len(arr))
567 for _, t := range arr {
568 (*ss)[t] = struct{}{}
572 var hash map[string]struct{}
573 err := json.Unmarshal(data, &hash)
577 *ss = make(map[string]struct{}, len(hash))
578 for t := range hash {
579 (*ss)[t] = struct{}{}
585 type ServiceName string
588 ServiceNameRailsAPI ServiceName = "arvados-api-server"
589 ServiceNameController ServiceName = "arvados-controller"
590 ServiceNameDispatchCloud ServiceName = "arvados-dispatch-cloud"
591 ServiceNameHealth ServiceName = "arvados-health"
592 ServiceNameWorkbench1 ServiceName = "arvados-workbench1"
593 ServiceNameWorkbench2 ServiceName = "arvados-workbench2"
594 ServiceNameWebsocket ServiceName = "arvados-ws"
595 ServiceNameKeepbalance ServiceName = "keep-balance"
596 ServiceNameKeepweb ServiceName = "keep-web"
597 ServiceNameKeepproxy ServiceName = "keepproxy"
598 ServiceNameKeepstore ServiceName = "keepstore"
601 // Map returns all services as a map, suitable for iterating over all
602 // services or looking up a service by name.
603 func (svcs Services) Map() map[ServiceName]Service {
604 return map[ServiceName]Service{
605 ServiceNameRailsAPI: svcs.RailsAPI,
606 ServiceNameController: svcs.Controller,
607 ServiceNameDispatchCloud: svcs.DispatchCloud,
608 ServiceNameHealth: svcs.Health,
609 ServiceNameWorkbench1: svcs.Workbench1,
610 ServiceNameWorkbench2: svcs.Workbench2,
611 ServiceNameWebsocket: svcs.Websocket,
612 ServiceNameKeepbalance: svcs.Keepbalance,
613 ServiceNameKeepweb: svcs.WebDAV,
614 ServiceNameKeepproxy: svcs.Keepproxy,
615 ServiceNameKeepstore: svcs.Keepstore,