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 ClusterID string `json:"-"`
72 ManagementToken string
73 SystemRootToken string
75 InstanceTypes InstanceTypeMap
76 Containers ContainersConfig
77 RemoteClusters map[string]RemoteCluster
81 AsyncPermissionsUpdateInterval Duration
82 DisabledAPIs StringSet
83 MaxIndexDatabaseRead int
84 MaxItemsPerResponse int
85 MaxConcurrentRequests int
86 MaxKeepBlobBuffers int
87 MaxRequestAmplification int
89 RequestTimeout Duration
91 WebsocketClientEventQueue int
92 WebsocketServerEventQueue int
93 KeepServiceRequestTimeout Duration
98 UnloggedAttributes StringSet
102 BlobSigningKey string
103 BlobSigningTTL Duration
105 BlobTrashLifetime Duration
106 BlobTrashCheckInterval Duration
107 BlobTrashConcurrency int
108 BlobDeleteConcurrency int
109 BlobReplicateConcurrency int
110 CollectionVersioning bool
111 DefaultTrashLifetime Duration
112 DefaultReplication int
113 ManagedProperties map[string]struct {
118 PreserveVersionIfIdle Duration
119 TrashSweepInterval Duration
121 ForwardSlashNameSubstitution string
124 BlobMissingReport string
125 BalancePeriod Duration
126 BalanceCollectionBatch int
127 BalanceCollectionBuffers int
128 BalanceTimeout Duration
130 WebDAVCache WebDAVCacheConfig
145 SearchAttribute string
146 SearchBindUser string
147 SearchBindPassword string
150 EmailAttribute string
151 UsernameAttribute string
157 AlternateEmailAddresses bool
159 OpenIDConnect struct {
165 EmailVerifiedClaim string
171 DefaultEmailDomain string
176 ProviderAppSecret string
180 Users map[string]TestUser
183 RemoteTokenRefresh Duration
184 TokenLifetime Duration
185 TrustedClients map[string]struct{}
188 MailchimpAPIKey string
189 MailchimpListID string
190 SendUserSetupNotificationEmail bool
191 IssueReporterEmailFrom string
192 IssueReporterEmailTo string
193 SupportEmailAddress string
199 MaxRequestLogParamsSize int
207 AnonymousUserToken string
208 AdminNotifierEmailFrom string
209 AutoAdminFirstUser bool
210 AutoAdminUserWithEmail string
211 AutoSetupNewUsers bool
212 AutoSetupNewUsersWithRepository bool
213 AutoSetupNewUsersWithVmUUID string
214 AutoSetupUsernameBlacklist StringSet
215 EmailSubjectPrefix string
216 NewInactiveUserNotificationRecipients StringSet
217 NewUserNotificationRecipients StringSet
218 NewUsersAreActive bool
219 UserNotifierEmailFrom string
220 UserProfileNotificationAddress string
221 PreferDomainForUsername string
222 UserSetupMailText string
224 Volumes map[string]Volume
226 ActivationContactLink string
227 APIClientConnectTimeout Duration
228 APIClientReceiveTimeout Duration
229 APIResponseCompression bool
230 ApplicationMimetypesWithViewIcon StringSet
231 ArvadosDocsite string
232 ArvadosPublicDataDocURL string
233 DefaultOpenIdPrefix string
234 EnableGettingStartedPopup bool
235 EnablePublicProjectsPage bool
236 FileViewersConfigURL string
237 LogViewerMaxBytes ByteSize
238 MultiSiteSearch string
239 ProfilingEnabled bool
241 RepositoryCache string
242 RunningJobLogRecordsToFetch int
244 ShowRecentCollectionsOnDashboard bool
245 ShowUserAgreementInline bool
246 ShowUserNotifications bool
249 UserProfileFormFields map[string]struct {
251 FormFieldTitle string
252 FormFieldDescription string
255 Options map[string]struct{}
257 UserProfileFormMessage string
259 WelcomePageHTML string
260 InactivePageHTML string
261 SSHHelpPageHTML string
262 SSHHelpHostSuffix string
266 ForceLegacyAPI14 bool
270 AccessViaHosts map[URL]VolumeAccess
273 StorageClasses map[string]bool
275 DriverParameters json.RawMessage
278 type S3VolumeDriverParameters struct {
285 LocationConstraint bool
287 UseAWSS3v2Driver bool
289 ConnectTimeout Duration
295 type AzureVolumeDriverParameters struct {
296 StorageAccountName string
297 StorageAccountKey string
298 StorageBaseURL string
300 RequestTimeout Duration
301 ListBlobsRetryDelay Duration
302 ListBlobsMaxAttempts int
305 type DirectoryVolumeDriverParameters struct {
310 type VolumeAccess struct {
314 type Services struct {
317 DispatchCloud Service
326 WebDAVDownload Service
334 type Service struct {
335 InternalURLs map[URL]ServiceInstance
339 type TestUser struct {
344 // URL is a url.URL that is also usable as a JSON key/value.
347 // UnmarshalText implements encoding.TextUnmarshaler so URL can be
348 // used as a JSON key/value.
349 func (su *URL) UnmarshalText(text []byte) error {
350 u, err := url.Parse(string(text))
353 if su.Path == "" && su.Host != "" {
354 // http://example really means http://example/
361 func (su URL) MarshalText() ([]byte, error) {
362 return []byte(fmt.Sprintf("%s", (*url.URL)(&su).String())), nil
365 func (su URL) String() string {
366 return (*url.URL)(&su).String()
369 type ServiceInstance struct {
370 Rendezvous string `json:",omitempty"`
373 type PostgreSQL struct {
374 Connection PostgreSQLConnection
378 type PostgreSQLConnection map[string]string
380 type RemoteCluster struct {
388 type InstanceType struct {
394 IncludedScratch ByteSize
395 AddedScratch ByteSize
400 type ContainersConfig struct {
401 CloudVMs CloudVMsConfig
402 CrunchRunCommand string
403 CrunchRunArgumentsList []string
404 DefaultKeepCacheRAM ByteSize
405 DispatchPrivateKey string
406 LogReuseDecisions bool
408 MaxDispatchAttempts int
410 MinRetryPeriod Duration
411 ReserveExtraRAM ByteSize
412 StaleLockTimeout Duration
413 SupportedDockerImageFormats StringSet
414 UsePreemptibleInstances bool
418 GitInternalDir string
423 LogSecondsBetweenEvents Duration
424 LogThrottlePeriod Duration
427 LimitLogBytesPerJob int
428 LogPartialLineThrottlePeriod Duration
429 LogUpdatePeriod Duration
430 LogUpdateSize ByteSize
434 SbatchArgumentsList []string
435 SbatchEnvironmentVariables map[string]string
437 DNSServerConfDir string
438 DNSServerConfTemplate string
439 DNSServerReloadCommand string
440 DNSServerUpdateCommand string
441 ComputeNodeDomain string
442 ComputeNodeNameservers StringSet
443 AssignNodeHostname string
448 type CloudVMsConfig struct {
451 BootProbeCommand string
452 DeployRunnerBinary string
454 MaxCloudOpsPerSecond int
455 MaxProbesPerSecond int
456 MaxConcurrentInstanceCreateOps int
457 PollInterval Duration
458 ProbeInterval Duration
460 SyncInterval Duration
461 TimeoutBooting Duration
463 TimeoutProbe Duration
464 TimeoutShutdown Duration
465 TimeoutSignal Duration
466 TimeoutStaleRunLock Duration
468 ResourceTags map[string]string
472 DriverParameters json.RawMessage
475 type InstanceTypeMap map[string]InstanceType
477 var errDuplicateInstanceTypeName = errors.New("duplicate instance type name")
479 // UnmarshalJSON handles old config files that provide an array of
480 // instance types instead of a hash.
481 func (it *InstanceTypeMap) UnmarshalJSON(data []byte) error {
482 fixup := func(t InstanceType) (InstanceType, error) {
483 if t.ProviderType == "" {
484 t.ProviderType = t.Name
487 t.Scratch = t.IncludedScratch + t.AddedScratch
488 } else if t.AddedScratch == 0 {
489 t.AddedScratch = t.Scratch - t.IncludedScratch
490 } else if t.IncludedScratch == 0 {
491 t.IncludedScratch = t.Scratch - t.AddedScratch
494 if t.Scratch != (t.IncludedScratch + t.AddedScratch) {
495 return t, fmt.Errorf("InstanceType %q: Scratch != (IncludedScratch + AddedScratch)", t.Name)
500 if len(data) > 0 && data[0] == '[' {
501 var arr []InstanceType
502 err := json.Unmarshal(data, &arr)
510 *it = make(map[string]InstanceType, len(arr))
511 for _, t := range arr {
512 if _, ok := (*it)[t.Name]; ok {
513 return errDuplicateInstanceTypeName
523 var hash map[string]InstanceType
524 err := json.Unmarshal(data, &hash)
528 // Fill in Name field (and ProviderType field, if not
529 // specified) using hash key.
530 *it = InstanceTypeMap(hash)
531 for name, t := range *it {
542 type StringSet map[string]struct{}
544 // UnmarshalJSON handles old config files that provide an array of
545 // instance types instead of a hash.
546 func (ss *StringSet) UnmarshalJSON(data []byte) error {
547 if len(data) > 0 && data[0] == '[' {
549 err := json.Unmarshal(data, &arr)
557 *ss = make(map[string]struct{}, len(arr))
558 for _, t := range arr {
559 (*ss)[t] = struct{}{}
563 var hash map[string]struct{}
564 err := json.Unmarshal(data, &hash)
568 *ss = make(map[string]struct{}, len(hash))
569 for t := range hash {
570 (*ss)[t] = struct{}{}
576 type ServiceName string
579 ServiceNameRailsAPI ServiceName = "arvados-api-server"
580 ServiceNameController ServiceName = "arvados-controller"
581 ServiceNameDispatchCloud ServiceName = "arvados-dispatch-cloud"
582 ServiceNameHealth ServiceName = "arvados-health"
583 ServiceNameWorkbench1 ServiceName = "arvados-workbench1"
584 ServiceNameWorkbench2 ServiceName = "arvados-workbench2"
585 ServiceNameWebsocket ServiceName = "arvados-ws"
586 ServiceNameKeepbalance ServiceName = "keep-balance"
587 ServiceNameKeepweb ServiceName = "keep-web"
588 ServiceNameKeepproxy ServiceName = "keepproxy"
589 ServiceNameKeepstore ServiceName = "keepstore"
592 // Map returns all services as a map, suitable for iterating over all
593 // services or looking up a service by name.
594 func (svcs Services) Map() map[ServiceName]Service {
595 return map[ServiceName]Service{
596 ServiceNameRailsAPI: svcs.RailsAPI,
597 ServiceNameController: svcs.Controller,
598 ServiceNameDispatchCloud: svcs.DispatchCloud,
599 ServiceNameHealth: svcs.Health,
600 ServiceNameWorkbench1: svcs.Workbench1,
601 ServiceNameWorkbench2: svcs.Workbench2,
602 ServiceNameWebsocket: svcs.Websocket,
603 ServiceNameKeepbalance: svcs.Keepbalance,
604 ServiceNameKeepweb: svcs.WebDAV,
605 ServiceNameKeepproxy: svcs.Keepproxy,
606 ServiceNameKeepstore: svcs.Keepstore,