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 {
165 EmailVerifiedClaim string
171 DefaultEmailDomain string
176 ProviderAppSecret string
179 RemoteTokenRefresh Duration
182 MailchimpAPIKey string
183 MailchimpListID string
184 SendUserSetupNotificationEmail bool
185 IssueReporterEmailFrom string
186 IssueReporterEmailTo string
187 SupportEmailAddress string
193 MaxRequestLogParamsSize int
201 AnonymousUserToken string
202 AdminNotifierEmailFrom string
203 AutoAdminFirstUser bool
204 AutoAdminUserWithEmail string
205 AutoSetupNewUsers bool
206 AutoSetupNewUsersWithRepository bool
207 AutoSetupNewUsersWithVmUUID string
208 AutoSetupUsernameBlacklist StringSet
209 EmailSubjectPrefix string
210 NewInactiveUserNotificationRecipients StringSet
211 NewUserNotificationRecipients StringSet
212 NewUsersAreActive bool
213 UserNotifierEmailFrom string
214 UserProfileNotificationAddress string
215 PreferDomainForUsername string
217 Volumes map[string]Volume
219 ActivationContactLink string
220 APIClientConnectTimeout Duration
221 APIClientReceiveTimeout Duration
222 APIResponseCompression bool
223 ApplicationMimetypesWithViewIcon StringSet
224 ArvadosDocsite string
225 ArvadosPublicDataDocURL string
226 DefaultOpenIdPrefix string
227 EnableGettingStartedPopup bool
228 EnablePublicProjectsPage bool
229 FileViewersConfigURL string
230 LogViewerMaxBytes ByteSize
231 MultiSiteSearch string
232 ProfilingEnabled bool
234 RepositoryCache string
235 RunningJobLogRecordsToFetch int
237 ShowRecentCollectionsOnDashboard bool
238 ShowUserAgreementInline bool
239 ShowUserNotifications bool
242 UserProfileFormFields map[string]struct {
244 FormFieldTitle string
245 FormFieldDescription string
248 Options map[string]struct{}
250 UserProfileFormMessage string
252 WelcomePageHTML string
253 InactivePageHTML string
254 SSHHelpPageHTML string
255 SSHHelpHostSuffix string
258 ForceLegacyAPI14 bool
262 AccessViaHosts map[URL]VolumeAccess
265 StorageClasses map[string]bool
267 DriverParameters json.RawMessage
270 type S3VolumeDriverParameters struct {
277 LocationConstraint bool
280 ConnectTimeout Duration
286 type AzureVolumeDriverParameters struct {
287 StorageAccountName string
288 StorageAccountKey string
289 StorageBaseURL string
291 RequestTimeout Duration
292 ListBlobsRetryDelay Duration
293 ListBlobsMaxAttempts int
296 type DirectoryVolumeDriverParameters struct {
301 type VolumeAccess struct {
305 type Services struct {
308 DispatchCloud Service
318 WebDAVDownload Service
326 type Service struct {
327 InternalURLs map[URL]ServiceInstance
331 // URL is a url.URL that is also usable as a JSON key/value.
334 // UnmarshalText implements encoding.TextUnmarshaler so URL can be
335 // used as a JSON key/value.
336 func (su *URL) UnmarshalText(text []byte) error {
337 u, err := url.Parse(string(text))
340 if su.Path == "" && su.Host != "" {
341 // http://example really means http://example/
348 func (su URL) MarshalText() ([]byte, error) {
349 return []byte(fmt.Sprintf("%s", (*url.URL)(&su).String())), nil
352 func (su URL) String() string {
353 return (*url.URL)(&su).String()
356 type ServiceInstance struct {
357 Rendezvous string `json:",omitempty"`
360 type PostgreSQL struct {
361 Connection PostgreSQLConnection
365 type PostgreSQLConnection map[string]string
367 type RemoteCluster struct {
375 type InstanceType struct {
381 IncludedScratch ByteSize
382 AddedScratch ByteSize
387 type ContainersConfig struct {
388 CloudVMs CloudVMsConfig
389 CrunchRunCommand string
390 CrunchRunArgumentsList []string
391 DefaultKeepCacheRAM ByteSize
392 DispatchPrivateKey string
393 LogReuseDecisions bool
395 MaxDispatchAttempts int
397 MinRetryPeriod Duration
398 ReserveExtraRAM ByteSize
399 StaleLockTimeout Duration
400 SupportedDockerImageFormats StringSet
401 UsePreemptibleInstances bool
405 GitInternalDir string
410 LogSecondsBetweenEvents Duration
411 LogThrottlePeriod Duration
414 LimitLogBytesPerJob int
415 LogPartialLineThrottlePeriod Duration
416 LogUpdatePeriod Duration
417 LogUpdateSize ByteSize
421 SbatchArgumentsList []string
422 SbatchEnvironmentVariables map[string]string
424 DNSServerConfDir string
425 DNSServerConfTemplate string
426 DNSServerReloadCommand string
427 DNSServerUpdateCommand string
428 ComputeNodeDomain string
429 ComputeNodeNameservers StringSet
430 AssignNodeHostname string
435 type CloudVMsConfig struct {
438 BootProbeCommand string
439 DeployRunnerBinary string
441 MaxCloudOpsPerSecond int
442 MaxProbesPerSecond int
443 PollInterval Duration
444 ProbeInterval Duration
446 SyncInterval Duration
447 TimeoutBooting Duration
449 TimeoutProbe Duration
450 TimeoutShutdown Duration
451 TimeoutSignal Duration
453 ResourceTags map[string]string
457 DriverParameters json.RawMessage
460 type InstanceTypeMap map[string]InstanceType
462 var errDuplicateInstanceTypeName = errors.New("duplicate instance type name")
464 // UnmarshalJSON handles old config files that provide an array of
465 // instance types instead of a hash.
466 func (it *InstanceTypeMap) UnmarshalJSON(data []byte) error {
467 fixup := func(t InstanceType) (InstanceType, error) {
468 if t.ProviderType == "" {
469 t.ProviderType = t.Name
472 t.Scratch = t.IncludedScratch + t.AddedScratch
473 } else if t.AddedScratch == 0 {
474 t.AddedScratch = t.Scratch - t.IncludedScratch
475 } else if t.IncludedScratch == 0 {
476 t.IncludedScratch = t.Scratch - t.AddedScratch
479 if t.Scratch != (t.IncludedScratch + t.AddedScratch) {
480 return t, fmt.Errorf("InstanceType %q: Scratch != (IncludedScratch + AddedScratch)", t.Name)
485 if len(data) > 0 && data[0] == '[' {
486 var arr []InstanceType
487 err := json.Unmarshal(data, &arr)
495 *it = make(map[string]InstanceType, len(arr))
496 for _, t := range arr {
497 if _, ok := (*it)[t.Name]; ok {
498 return errDuplicateInstanceTypeName
508 var hash map[string]InstanceType
509 err := json.Unmarshal(data, &hash)
513 // Fill in Name field (and ProviderType field, if not
514 // specified) using hash key.
515 *it = InstanceTypeMap(hash)
516 for name, t := range *it {
527 type StringSet map[string]struct{}
529 // UnmarshalJSON handles old config files that provide an array of
530 // instance types instead of a hash.
531 func (ss *StringSet) UnmarshalJSON(data []byte) error {
532 if len(data) > 0 && data[0] == '[' {
534 err := json.Unmarshal(data, &arr)
542 *ss = make(map[string]struct{}, len(arr))
543 for _, t := range arr {
544 (*ss)[t] = struct{}{}
548 var hash map[string]struct{}
549 err := json.Unmarshal(data, &hash)
553 *ss = make(map[string]struct{}, len(hash))
554 for t, _ := range hash {
555 (*ss)[t] = struct{}{}
561 type ServiceName string
564 ServiceNameRailsAPI ServiceName = "arvados-api-server"
565 ServiceNameController ServiceName = "arvados-controller"
566 ServiceNameDispatchCloud ServiceName = "arvados-dispatch-cloud"
567 ServiceNameHealth ServiceName = "arvados-health"
568 ServiceNameNodemanager ServiceName = "arvados-node-manager"
569 ServiceNameWorkbench1 ServiceName = "arvados-workbench1"
570 ServiceNameWorkbench2 ServiceName = "arvados-workbench2"
571 ServiceNameWebsocket ServiceName = "arvados-ws"
572 ServiceNameKeepbalance ServiceName = "keep-balance"
573 ServiceNameKeepweb ServiceName = "keep-web"
574 ServiceNameKeepproxy ServiceName = "keepproxy"
575 ServiceNameKeepstore ServiceName = "keepstore"
578 // Map returns all services as a map, suitable for iterating over all
579 // services or looking up a service by name.
580 func (svcs Services) Map() map[ServiceName]Service {
581 return map[ServiceName]Service{
582 ServiceNameRailsAPI: svcs.RailsAPI,
583 ServiceNameController: svcs.Controller,
584 ServiceNameDispatchCloud: svcs.DispatchCloud,
585 ServiceNameHealth: svcs.Health,
586 ServiceNameNodemanager: svcs.Nodemanager,
587 ServiceNameWorkbench1: svcs.Workbench1,
588 ServiceNameWorkbench2: svcs.Workbench2,
589 ServiceNameWebsocket: svcs.Websocket,
590 ServiceNameKeepbalance: svcs.Keepbalance,
591 ServiceNameKeepweb: svcs.WebDAV,
592 ServiceNameKeepproxy: svcs.Keepproxy,
593 ServiceNameKeepstore: svcs.Keepstore,