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
61 ClusterID string `json:"-"`
62 ManagementToken string
63 SystemRootToken string
65 InstanceTypes InstanceTypeMap
66 Containers ContainersConfig
67 RemoteClusters map[string]RemoteCluster
71 AsyncPermissionsUpdateInterval Duration
72 DisabledAPIs StringSet
73 MaxIndexDatabaseRead int
74 MaxItemsPerResponse int
75 MaxRequestAmplification int
77 RailsSessionSecretToken string
78 RequestTimeout Duration
80 WebsocketClientEventQueue int
81 WebsocketServerEventQueue int
86 UnloggedAttributes StringSet
91 BlobSigningTTL Duration
92 CollectionVersioning bool
93 DefaultTrashLifetime Duration
94 DefaultReplication int
95 ManagedProperties map[string]struct {
100 PreserveVersionIfIdle Duration
101 TrashSweepInterval Duration
108 ProviderAppSecret string
112 MailchimpAPIKey string
113 MailchimpListID string
114 SendUserSetupNotificationEmail bool
115 IssueReporterEmailFrom string
116 IssueReporterEmailTo string
117 SupportEmailAddress string
123 MaxRequestLogParamsSize int
131 AnonymousUserToken string
132 AdminNotifierEmailFrom string
133 AutoAdminFirstUser bool
134 AutoAdminUserWithEmail string
135 AutoSetupNewUsers bool
136 AutoSetupNewUsersWithRepository bool
137 AutoSetupNewUsersWithVmUUID string
138 AutoSetupUsernameBlacklist StringSet
139 EmailSubjectPrefix string
140 NewInactiveUserNotificationRecipients StringSet
141 NewUserNotificationRecipients StringSet
142 NewUsersAreActive bool
143 UserNotifierEmailFrom string
144 UserProfileNotificationAddress string
147 ActivationContactLink string
148 APIClientConnectTimeout Duration
149 APIClientReceiveTimeout Duration
150 APIResponseCompression bool
151 ApplicationMimetypesWithViewIcon StringSet
152 ArvadosDocsite string
153 ArvadosPublicDataDocURL string
154 DefaultOpenIdPrefix string
155 EnableGettingStartedPopup bool
156 EnablePublicProjectsPage bool
157 FileViewersConfigURL string
158 LogViewerMaxBytes ByteSize
159 MultiSiteSearch string
160 ProfilingEnabled bool
162 RepositoryCache string
163 RunningJobLogRecordsToFetch int
165 ShowRecentCollectionsOnDashboard bool
166 ShowUserAgreementInline bool
167 ShowUserNotifications bool
170 UserProfileFormFields map[string]struct {
172 FormFieldTitle string
173 FormFieldDescription string
176 Options map[string]struct{}
178 UserProfileFormMessage string
182 EnableBetaController14287 bool
185 type Services struct {
188 DispatchCloud Service
198 WebDAVDownload Service
206 type Service struct {
207 InternalURLs map[URL]ServiceInstance
211 // URL is a url.URL that is also usable as a JSON key/value.
214 // UnmarshalText implements encoding.TextUnmarshaler so URL can be
215 // used as a JSON key/value.
216 func (su *URL) UnmarshalText(text []byte) error {
217 u, err := url.Parse(string(text))
224 func (su URL) MarshalText() ([]byte, error) {
225 return []byte(fmt.Sprintf("%s", (*url.URL)(&su).String())), nil
228 type ServiceInstance struct{}
230 type PostgreSQL struct {
231 Connection PostgreSQLConnection
235 type PostgreSQLConnection map[string]string
237 type RemoteCluster struct {
245 type InstanceType struct {
251 IncludedScratch ByteSize
252 AddedScratch ByteSize
257 type ContainersConfig struct {
258 CloudVMs CloudVMsConfig
259 CrunchRunCommand string
260 CrunchRunArgumentsList []string
261 DefaultKeepCacheRAM ByteSize
262 DispatchPrivateKey string
263 LogReuseDecisions bool
265 MaxDispatchAttempts int
267 MinRetryPeriod Duration
268 ReserveExtraRAM ByteSize
269 StaleLockTimeout Duration
270 SupportedDockerImageFormats StringSet
271 UsePreemptibleInstances bool
275 GitInternalDir string
276 DefaultDockerImage string
277 CrunchJobWrapper string
279 CrunchRefreshTrigger string
280 ReuseJobIfOutputsDiffer bool
285 LogSecondsBetweenEvents int
286 LogThrottlePeriod Duration
289 LimitLogBytesPerJob int
290 LogPartialLineThrottlePeriod Duration
291 LogUpdatePeriod Duration
292 LogUpdateSize ByteSize
296 SbatchArgumentsList []string
298 DNSServerConfDir string
299 DNSServerConfTemplate string
300 DNSServerReloadCommand string
301 DNSServerUpdateCommand string
302 ComputeNodeDomain string
303 ComputeNodeNameservers StringSet
304 AssignNodeHostname string
309 type CloudVMsConfig struct {
312 BootProbeCommand string
314 MaxCloudOpsPerSecond int
315 MaxProbesPerSecond int
316 PollInterval Duration
317 ProbeInterval Duration
319 SyncInterval Duration
320 TimeoutBooting Duration
322 TimeoutProbe Duration
323 TimeoutShutdown Duration
324 TimeoutSignal Duration
326 ResourceTags map[string]string
330 DriverParameters json.RawMessage
333 type InstanceTypeMap map[string]InstanceType
335 var errDuplicateInstanceTypeName = errors.New("duplicate instance type name")
337 // UnmarshalJSON handles old config files that provide an array of
338 // instance types instead of a hash.
339 func (it *InstanceTypeMap) UnmarshalJSON(data []byte) error {
340 if len(data) > 0 && data[0] == '[' {
341 var arr []InstanceType
342 err := json.Unmarshal(data, &arr)
350 *it = make(map[string]InstanceType, len(arr))
351 for _, t := range arr {
352 if _, ok := (*it)[t.Name]; ok {
353 return errDuplicateInstanceTypeName
355 if t.ProviderType == "" {
356 t.ProviderType = t.Name
359 t.Scratch = t.IncludedScratch + t.AddedScratch
360 } else if t.AddedScratch == 0 {
361 t.AddedScratch = t.Scratch - t.IncludedScratch
362 } else if t.IncludedScratch == 0 {
363 t.IncludedScratch = t.Scratch - t.AddedScratch
366 if t.Scratch != (t.IncludedScratch + t.AddedScratch) {
367 return fmt.Errorf("%v: Scratch != (IncludedScratch + AddedScratch)", t.Name)
373 var hash map[string]InstanceType
374 err := json.Unmarshal(data, &hash)
378 // Fill in Name field (and ProviderType field, if not
379 // specified) using hash key.
380 *it = InstanceTypeMap(hash)
381 for name, t := range *it {
383 if t.ProviderType == "" {
384 t.ProviderType = name
391 type StringSet map[string]struct{}
393 // UnmarshalJSON handles old config files that provide an array of
394 // instance types instead of a hash.
395 func (ss *StringSet) UnmarshalJSON(data []byte) error {
396 if len(data) > 0 && data[0] == '[' {
398 err := json.Unmarshal(data, &arr)
406 *ss = make(map[string]struct{}, len(arr))
407 for _, t := range arr {
408 (*ss)[t] = struct{}{}
412 var hash map[string]struct{}
413 err := json.Unmarshal(data, &hash)
417 *ss = make(map[string]struct{}, len(hash))
418 for t, _ := range hash {
419 (*ss)[t] = struct{}{}
425 type ServiceName string
428 ServiceNameRailsAPI ServiceName = "arvados-api-server"
429 ServiceNameController ServiceName = "arvados-controller"
430 ServiceNameDispatchCloud ServiceName = "arvados-dispatch-cloud"
431 ServiceNameHealth ServiceName = "arvados-health"
432 ServiceNameNodemanager ServiceName = "arvados-node-manager"
433 ServiceNameWorkbench1 ServiceName = "arvados-workbench1"
434 ServiceNameWorkbench2 ServiceName = "arvados-workbench2"
435 ServiceNameWebsocket ServiceName = "arvados-ws"
436 ServiceNameKeepbalance ServiceName = "keep-balance"
437 ServiceNameKeepweb ServiceName = "keep-web"
438 ServiceNameKeepproxy ServiceName = "keepproxy"
439 ServiceNameKeepstore ServiceName = "keepstore"
442 // Map returns all services as a map, suitable for iterating over all
443 // services or looking up a service by name.
444 func (svcs Services) Map() map[ServiceName]Service {
445 return map[ServiceName]Service{
446 ServiceNameRailsAPI: svcs.RailsAPI,
447 ServiceNameController: svcs.Controller,
448 ServiceNameDispatchCloud: svcs.DispatchCloud,
449 ServiceNameHealth: svcs.Health,
450 ServiceNameNodemanager: svcs.Nodemanager,
451 ServiceNameWorkbench1: svcs.Workbench1,
452 ServiceNameWorkbench2: svcs.Workbench2,
453 ServiceNameWebsocket: svcs.Websocket,
454 ServiceNameKeepbalance: svcs.Keepbalance,
455 ServiceNameKeepweb: svcs.WebDAV,
456 ServiceNameKeepproxy: svcs.Keepproxy,
457 ServiceNameKeepstore: svcs.Keepstore,