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
71 type UploadDownloadPermission struct {
76 type UploadDownloadRolePermissions struct {
77 User UploadDownloadPermission
78 Admin UploadDownloadPermission
82 ClusterID string `json:"-"`
83 ManagementToken string
84 SystemRootToken string
86 InstanceTypes InstanceTypeMap
87 Containers ContainersConfig
88 RemoteClusters map[string]RemoteCluster
92 AsyncPermissionsUpdateInterval Duration
93 DisabledAPIs StringSet
94 MaxIndexDatabaseRead int
95 MaxItemsPerResponse int
96 MaxConcurrentRequests int
97 MaxKeepBlobBuffers int
98 MaxRequestAmplification int
100 MaxTokenLifetime Duration
101 RequestTimeout Duration
103 WebsocketClientEventQueue int
104 WebsocketServerEventQueue int
105 KeepServiceRequestTimeout Duration
110 UnloggedAttributes StringSet
114 BlobSigningKey string
115 BlobSigningTTL Duration
117 BlobTrashLifetime Duration
118 BlobTrashCheckInterval Duration
119 BlobTrashConcurrency int
120 BlobDeleteConcurrency int
121 BlobReplicateConcurrency int
122 CollectionVersioning bool
123 DefaultTrashLifetime Duration
124 DefaultReplication int
125 ManagedProperties map[string]struct {
130 PreserveVersionIfIdle Duration
131 TrashSweepInterval Duration
133 ForwardSlashNameSubstitution string
136 BlobMissingReport string
137 BalancePeriod Duration
138 BalanceCollectionBatch int
139 BalanceCollectionBuffers int
140 BalanceTimeout Duration
142 WebDAVCache WebDAVCacheConfig
144 KeepproxyPermission UploadDownloadRolePermissions
145 WebDAVPermission UploadDownloadRolePermissions
161 SearchAttribute string
162 SearchBindUser string
163 SearchBindPassword string
166 EmailAttribute string
167 UsernameAttribute string
173 AlternateEmailAddresses bool
174 AuthenticationRequestParameters map[string]string
176 OpenIDConnect struct {
182 EmailVerifiedClaim string
184 AcceptAccessToken bool
185 AcceptAccessTokenScope string
186 AuthenticationRequestParameters map[string]string
191 DefaultEmailDomain string
196 ProviderAppSecret string
200 Users map[string]TestUser
203 RemoteTokenRefresh Duration
204 TokenLifetime Duration
205 TrustedClients map[string]struct{}
206 IssueTrustedTokens bool
209 MailchimpAPIKey string
210 MailchimpListID string
211 SendUserSetupNotificationEmail bool
212 IssueReporterEmailFrom string
213 IssueReporterEmailTo string
214 SupportEmailAddress string
220 MaxRequestLogParamsSize int
228 AnonymousUserToken string
229 AdminNotifierEmailFrom string
230 AutoAdminFirstUser bool
231 AutoAdminUserWithEmail string
232 AutoSetupNewUsers bool
233 AutoSetupNewUsersWithRepository bool
234 AutoSetupNewUsersWithVmUUID string
235 AutoSetupUsernameBlacklist StringSet
236 EmailSubjectPrefix string
237 NewInactiveUserNotificationRecipients StringSet
238 NewUserNotificationRecipients StringSet
239 NewUsersAreActive bool
240 UserNotifierEmailFrom string
241 UserProfileNotificationAddress string
242 PreferDomainForUsername string
243 UserSetupMailText string
245 Volumes map[string]Volume
247 ActivationContactLink string
248 APIClientConnectTimeout Duration
249 APIClientReceiveTimeout Duration
250 APIResponseCompression bool
251 ApplicationMimetypesWithViewIcon StringSet
252 ArvadosDocsite string
253 ArvadosPublicDataDocURL string
254 DefaultOpenIdPrefix string
255 EnableGettingStartedPopup bool
256 EnablePublicProjectsPage bool
257 FileViewersConfigURL string
258 LogViewerMaxBytes ByteSize
259 MultiSiteSearch string
260 ProfilingEnabled bool
262 RepositoryCache string
263 RunningJobLogRecordsToFetch int
265 ShowRecentCollectionsOnDashboard bool
266 ShowUserAgreementInline bool
267 ShowUserNotifications bool
270 UserProfileFormFields map[string]struct {
272 FormFieldTitle string
273 FormFieldDescription string
276 Options map[string]struct{}
278 UserProfileFormMessage string
280 WelcomePageHTML string
281 InactivePageHTML string
282 SSHHelpPageHTML string
283 SSHHelpHostSuffix string
289 AccessViaHosts map[URL]VolumeAccess
292 StorageClasses map[string]bool
294 DriverParameters json.RawMessage
297 type S3VolumeDriverParameters struct {
300 SecretAccessKey string
304 LocationConstraint bool
306 UseAWSS3v2Driver bool
308 ConnectTimeout Duration
314 type AzureVolumeDriverParameters struct {
315 StorageAccountName string
316 StorageAccountKey string
317 StorageBaseURL string
319 RequestTimeout Duration
320 ListBlobsRetryDelay Duration
321 ListBlobsMaxAttempts int
324 type DirectoryVolumeDriverParameters struct {
329 type VolumeAccess struct {
333 type Services struct {
336 DispatchCloud Service
345 WebDAVDownload Service
353 type Service struct {
354 InternalURLs map[URL]ServiceInstance
358 type TestUser struct {
363 // URL is a url.URL that is also usable as a JSON key/value.
366 // UnmarshalText implements encoding.TextUnmarshaler so URL can be
367 // used as a JSON key/value.
368 func (su *URL) UnmarshalText(text []byte) error {
369 u, err := url.Parse(string(text))
372 if su.Path == "" && su.Host != "" {
373 // http://example really means http://example/
380 func (su URL) MarshalText() ([]byte, error) {
381 return []byte(fmt.Sprintf("%s", (*url.URL)(&su).String())), nil
384 func (su URL) String() string {
385 return (*url.URL)(&su).String()
388 type ServiceInstance struct {
389 Rendezvous string `json:",omitempty"`
392 type PostgreSQL struct {
393 Connection PostgreSQLConnection
397 type PostgreSQLConnection map[string]string
399 type RemoteCluster struct {
407 type InstanceType struct {
413 IncludedScratch ByteSize
414 AddedScratch ByteSize
419 type ContainersConfig struct {
420 CloudVMs CloudVMsConfig
421 CrunchRunCommand string
422 CrunchRunArgumentsList []string
423 DefaultKeepCacheRAM ByteSize
424 DispatchPrivateKey string
425 LogReuseDecisions bool
427 MaxDispatchAttempts int
429 MinRetryPeriod Duration
430 ReserveExtraRAM ByteSize
431 StaleLockTimeout Duration
432 SupportedDockerImageFormats StringSet
433 UsePreemptibleInstances bool
437 GitInternalDir string
442 LogSecondsBetweenEvents Duration
443 LogThrottlePeriod Duration
446 LimitLogBytesPerJob int
447 LogPartialLineThrottlePeriod Duration
448 LogUpdatePeriod Duration
449 LogUpdateSize ByteSize
457 SbatchArgumentsList []string
458 SbatchEnvironmentVariables map[string]string
460 DNSServerConfDir string
461 DNSServerConfTemplate string
462 DNSServerReloadCommand string
463 DNSServerUpdateCommand string
464 ComputeNodeDomain string
465 ComputeNodeNameservers StringSet
466 AssignNodeHostname string
471 type CloudVMsConfig struct {
474 BootProbeCommand string
475 DeployRunnerBinary string
477 MaxCloudOpsPerSecond int
478 MaxProbesPerSecond int
479 MaxConcurrentInstanceCreateOps int
480 PollInterval Duration
481 ProbeInterval Duration
483 SyncInterval Duration
484 TimeoutBooting Duration
486 TimeoutProbe Duration
487 TimeoutShutdown Duration
488 TimeoutSignal Duration
489 TimeoutStaleRunLock Duration
491 ResourceTags map[string]string
495 DriverParameters json.RawMessage
498 type InstanceTypeMap map[string]InstanceType
500 var errDuplicateInstanceTypeName = errors.New("duplicate instance type name")
502 // UnmarshalJSON handles old config files that provide an array of
503 // instance types instead of a hash.
504 func (it *InstanceTypeMap) UnmarshalJSON(data []byte) error {
505 fixup := func(t InstanceType) (InstanceType, error) {
506 if t.ProviderType == "" {
507 t.ProviderType = t.Name
510 t.Scratch = t.IncludedScratch + t.AddedScratch
511 } else if t.AddedScratch == 0 {
512 t.AddedScratch = t.Scratch - t.IncludedScratch
513 } else if t.IncludedScratch == 0 {
514 t.IncludedScratch = t.Scratch - t.AddedScratch
517 if t.Scratch != (t.IncludedScratch + t.AddedScratch) {
518 return t, fmt.Errorf("InstanceType %q: Scratch != (IncludedScratch + AddedScratch)", t.Name)
523 if len(data) > 0 && data[0] == '[' {
524 var arr []InstanceType
525 err := json.Unmarshal(data, &arr)
533 *it = make(map[string]InstanceType, len(arr))
534 for _, t := range arr {
535 if _, ok := (*it)[t.Name]; ok {
536 return errDuplicateInstanceTypeName
546 var hash map[string]InstanceType
547 err := json.Unmarshal(data, &hash)
551 // Fill in Name field (and ProviderType field, if not
552 // specified) using hash key.
553 *it = InstanceTypeMap(hash)
554 for name, t := range *it {
565 type StringSet map[string]struct{}
567 // UnmarshalJSON handles old config files that provide an array of
568 // instance types instead of a hash.
569 func (ss *StringSet) UnmarshalJSON(data []byte) error {
570 if len(data) > 0 && data[0] == '[' {
572 err := json.Unmarshal(data, &arr)
580 *ss = make(map[string]struct{}, len(arr))
581 for _, t := range arr {
582 (*ss)[t] = struct{}{}
586 var hash map[string]struct{}
587 err := json.Unmarshal(data, &hash)
591 *ss = make(map[string]struct{}, len(hash))
592 for t := range hash {
593 (*ss)[t] = struct{}{}
599 type ServiceName string
602 ServiceNameRailsAPI ServiceName = "arvados-api-server"
603 ServiceNameController ServiceName = "arvados-controller"
604 ServiceNameDispatchCloud ServiceName = "arvados-dispatch-cloud"
605 ServiceNameHealth ServiceName = "arvados-health"
606 ServiceNameWorkbench1 ServiceName = "arvados-workbench1"
607 ServiceNameWorkbench2 ServiceName = "arvados-workbench2"
608 ServiceNameWebsocket ServiceName = "arvados-ws"
609 ServiceNameKeepbalance ServiceName = "keep-balance"
610 ServiceNameKeepweb ServiceName = "keep-web"
611 ServiceNameKeepproxy ServiceName = "keepproxy"
612 ServiceNameKeepstore ServiceName = "keepstore"
615 // Map returns all services as a map, suitable for iterating over all
616 // services or looking up a service by name.
617 func (svcs Services) Map() map[ServiceName]Service {
618 return map[ServiceName]Service{
619 ServiceNameRailsAPI: svcs.RailsAPI,
620 ServiceNameController: svcs.Controller,
621 ServiceNameDispatchCloud: svcs.DispatchCloud,
622 ServiceNameHealth: svcs.Health,
623 ServiceNameWorkbench1: svcs.Workbench1,
624 ServiceNameWorkbench2: svcs.Workbench2,
625 ServiceNameWebsocket: svcs.Websocket,
626 ServiceNameKeepbalance: svcs.Keepbalance,
627 ServiceNameKeepweb: svcs.WebDAV,
628 ServiceNameKeepproxy: svcs.Keepproxy,
629 ServiceNameKeepstore: svcs.Keepstore,