1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: Apache-2.0
14 "git.curoverse.com/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
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 if cc, ok := sc.Clusters[clusterID]; !ok {
53 return nil, fmt.Errorf("cluster %q is not configured", clusterID)
55 cc.ClusterID = clusterID
60 type WebDAVCacheConfig struct {
64 MaxCollectionEntries int
65 MaxCollectionBytes int64
66 MaxPermissionEntries int
70 ClusterID string `json:"-"`
71 ManagementToken string
72 SystemRootToken string
74 InstanceTypes InstanceTypeMap
75 Containers ContainersConfig
76 RemoteClusters map[string]RemoteCluster
80 AsyncPermissionsUpdateInterval Duration
81 DisabledAPIs StringSet
82 MaxIndexDatabaseRead int
83 MaxItemsPerResponse int
84 MaxRequestAmplification int
86 RailsSessionSecretToken string
87 RequestTimeout Duration
89 WebsocketClientEventQueue int
90 WebsocketServerEventQueue int
95 UnloggedAttributes StringSet
100 BlobSigningTTL Duration
101 CollectionVersioning bool
102 DefaultTrashLifetime Duration
103 DefaultReplication int
104 ManagedProperties map[string]struct {
109 PreserveVersionIfIdle Duration
110 TrashSweepInterval Duration
113 WebDAVCache WebDAVCacheConfig
119 ProviderAppSecret string
123 MailchimpAPIKey string
124 MailchimpListID string
125 SendUserSetupNotificationEmail bool
126 IssueReporterEmailFrom string
127 IssueReporterEmailTo string
128 SupportEmailAddress string
134 MaxRequestLogParamsSize int
142 AnonymousUserToken string
143 AdminNotifierEmailFrom string
144 AutoAdminFirstUser bool
145 AutoAdminUserWithEmail string
146 AutoSetupNewUsers bool
147 AutoSetupNewUsersWithRepository bool
148 AutoSetupNewUsersWithVmUUID string
149 AutoSetupUsernameBlacklist StringSet
150 EmailSubjectPrefix string
151 NewInactiveUserNotificationRecipients StringSet
152 NewUserNotificationRecipients StringSet
153 NewUsersAreActive bool
154 UserNotifierEmailFrom string
155 UserProfileNotificationAddress string
158 ActivationContactLink string
159 APIClientConnectTimeout Duration
160 APIClientReceiveTimeout Duration
161 APIResponseCompression bool
162 ApplicationMimetypesWithViewIcon StringSet
163 ArvadosDocsite string
164 ArvadosPublicDataDocURL string
165 DefaultOpenIdPrefix string
166 EnableGettingStartedPopup bool
167 EnablePublicProjectsPage bool
168 FileViewersConfigURL string
169 LogViewerMaxBytes ByteSize
170 MultiSiteSearch string
171 ProfilingEnabled bool
173 RepositoryCache string
174 RunningJobLogRecordsToFetch int
176 ShowRecentCollectionsOnDashboard bool
177 ShowUserAgreementInline bool
178 ShowUserNotifications bool
181 UserProfileFormFields map[string]struct {
183 FormFieldTitle string
184 FormFieldDescription string
187 Options map[string]struct{}
189 UserProfileFormMessage string
193 EnableBetaController14287 bool
196 type Services struct {
199 DispatchCloud Service
209 WebDAVDownload Service
217 type Service struct {
218 InternalURLs map[URL]ServiceInstance
222 // URL is a url.URL that is also usable as a JSON key/value.
225 // UnmarshalText implements encoding.TextUnmarshaler so URL can be
226 // used as a JSON key/value.
227 func (su *URL) UnmarshalText(text []byte) error {
228 u, err := url.Parse(string(text))
235 func (su URL) MarshalText() ([]byte, error) {
236 return []byte(fmt.Sprintf("%s", (*url.URL)(&su).String())), nil
239 type ServiceInstance struct{}
241 type PostgreSQL struct {
242 Connection PostgreSQLConnection
246 type PostgreSQLConnection map[string]string
248 type RemoteCluster struct {
256 type InstanceType struct {
262 IncludedScratch ByteSize
263 AddedScratch ByteSize
268 type ContainersConfig struct {
269 CloudVMs CloudVMsConfig
270 CrunchRunCommand string
271 CrunchRunArgumentsList []string
272 DefaultKeepCacheRAM ByteSize
273 DispatchPrivateKey string
274 LogReuseDecisions bool
276 MaxDispatchAttempts int
278 MinRetryPeriod Duration
279 ReserveExtraRAM ByteSize
280 StaleLockTimeout Duration
281 SupportedDockerImageFormats StringSet
282 UsePreemptibleInstances bool
286 GitInternalDir string
291 LogSecondsBetweenEvents int
292 LogThrottlePeriod Duration
295 LimitLogBytesPerJob int
296 LogPartialLineThrottlePeriod Duration
297 LogUpdatePeriod Duration
298 LogUpdateSize ByteSize
302 SbatchArgumentsList []string
303 SbatchEnvironmentVariables map[string]string
305 DNSServerConfDir string
306 DNSServerConfTemplate string
307 DNSServerReloadCommand string
308 DNSServerUpdateCommand string
309 ComputeNodeDomain string
310 ComputeNodeNameservers StringSet
311 AssignNodeHostname string
316 type CloudVMsConfig struct {
319 BootProbeCommand string
321 MaxCloudOpsPerSecond int
322 MaxProbesPerSecond int
323 PollInterval Duration
324 ProbeInterval Duration
326 SyncInterval Duration
327 TimeoutBooting Duration
329 TimeoutProbe Duration
330 TimeoutShutdown Duration
331 TimeoutSignal Duration
333 ResourceTags map[string]string
337 DriverParameters json.RawMessage
340 type InstanceTypeMap map[string]InstanceType
342 var errDuplicateInstanceTypeName = errors.New("duplicate instance type name")
344 // UnmarshalJSON handles old config files that provide an array of
345 // instance types instead of a hash.
346 func (it *InstanceTypeMap) UnmarshalJSON(data []byte) error {
347 if len(data) > 0 && data[0] == '[' {
348 var arr []InstanceType
349 err := json.Unmarshal(data, &arr)
357 *it = make(map[string]InstanceType, len(arr))
358 for _, t := range arr {
359 if _, ok := (*it)[t.Name]; ok {
360 return errDuplicateInstanceTypeName
362 if t.ProviderType == "" {
363 t.ProviderType = t.Name
366 t.Scratch = t.IncludedScratch + t.AddedScratch
367 } else if t.AddedScratch == 0 {
368 t.AddedScratch = t.Scratch - t.IncludedScratch
369 } else if t.IncludedScratch == 0 {
370 t.IncludedScratch = t.Scratch - t.AddedScratch
373 if t.Scratch != (t.IncludedScratch + t.AddedScratch) {
374 return fmt.Errorf("%v: Scratch != (IncludedScratch + AddedScratch)", t.Name)
380 var hash map[string]InstanceType
381 err := json.Unmarshal(data, &hash)
385 // Fill in Name field (and ProviderType field, if not
386 // specified) using hash key.
387 *it = InstanceTypeMap(hash)
388 for name, t := range *it {
390 if t.ProviderType == "" {
391 t.ProviderType = name
398 type StringSet map[string]struct{}
400 // UnmarshalJSON handles old config files that provide an array of
401 // instance types instead of a hash.
402 func (ss *StringSet) UnmarshalJSON(data []byte) error {
403 if len(data) > 0 && data[0] == '[' {
405 err := json.Unmarshal(data, &arr)
413 *ss = make(map[string]struct{}, len(arr))
414 for _, t := range arr {
415 (*ss)[t] = struct{}{}
419 var hash map[string]struct{}
420 err := json.Unmarshal(data, &hash)
424 *ss = make(map[string]struct{}, len(hash))
425 for t, _ := range hash {
426 (*ss)[t] = struct{}{}
432 type ServiceName string
435 ServiceNameRailsAPI ServiceName = "arvados-api-server"
436 ServiceNameController ServiceName = "arvados-controller"
437 ServiceNameDispatchCloud ServiceName = "arvados-dispatch-cloud"
438 ServiceNameHealth ServiceName = "arvados-health"
439 ServiceNameNodemanager ServiceName = "arvados-node-manager"
440 ServiceNameWorkbench1 ServiceName = "arvados-workbench1"
441 ServiceNameWorkbench2 ServiceName = "arvados-workbench2"
442 ServiceNameWebsocket ServiceName = "arvados-ws"
443 ServiceNameKeepbalance ServiceName = "keep-balance"
444 ServiceNameKeepweb ServiceName = "keep-web"
445 ServiceNameKeepproxy ServiceName = "keepproxy"
446 ServiceNameKeepstore ServiceName = "keepstore"
449 // Map returns all services as a map, suitable for iterating over all
450 // services or looking up a service by name.
451 func (svcs Services) Map() map[ServiceName]Service {
452 return map[ServiceName]Service{
453 ServiceNameRailsAPI: svcs.RailsAPI,
454 ServiceNameController: svcs.Controller,
455 ServiceNameDispatchCloud: svcs.DispatchCloud,
456 ServiceNameHealth: svcs.Health,
457 ServiceNameNodemanager: svcs.Nodemanager,
458 ServiceNameWorkbench1: svcs.Workbench1,
459 ServiceNameWorkbench2: svcs.Workbench2,
460 ServiceNameWebsocket: svcs.Websocket,
461 ServiceNameKeepbalance: svcs.Keepbalance,
462 ServiceNameKeepweb: svcs.WebDAV,
463 ServiceNameKeepproxy: svcs.Keepproxy,
464 ServiceNameKeepstore: svcs.Keepstore,