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
82 KeepServiceRequestTimeout Duration
87 UnloggedAttributes StringSet
92 BlobSigningTTL Duration
93 CollectionVersioning bool
94 DefaultTrashLifetime Duration
95 DefaultReplication int
96 ManagedProperties map[string]struct {
101 PreserveVersionIfIdle Duration
102 TrashSweepInterval Duration
109 ProviderAppSecret string
113 MailchimpAPIKey string
114 MailchimpListID string
115 SendUserSetupNotificationEmail bool
116 IssueReporterEmailFrom string
117 IssueReporterEmailTo string
118 SupportEmailAddress string
124 MaxRequestLogParamsSize int
132 AnonymousUserToken string
133 AdminNotifierEmailFrom string
134 AutoAdminFirstUser bool
135 AutoAdminUserWithEmail string
136 AutoSetupNewUsers bool
137 AutoSetupNewUsersWithRepository bool
138 AutoSetupNewUsersWithVmUUID string
139 AutoSetupUsernameBlacklist StringSet
140 EmailSubjectPrefix string
141 NewInactiveUserNotificationRecipients StringSet
142 NewUserNotificationRecipients StringSet
143 NewUsersAreActive bool
144 UserNotifierEmailFrom string
145 UserProfileNotificationAddress string
148 ActivationContactLink string
149 APIClientConnectTimeout Duration
150 APIClientReceiveTimeout Duration
151 APIResponseCompression bool
152 ApplicationMimetypesWithViewIcon StringSet
153 ArvadosDocsite string
154 ArvadosPublicDataDocURL string
155 DefaultOpenIdPrefix string
156 EnableGettingStartedPopup bool
157 EnablePublicProjectsPage bool
158 FileViewersConfigURL string
159 LogViewerMaxBytes ByteSize
160 MultiSiteSearch string
161 ProfilingEnabled bool
163 RepositoryCache string
164 RunningJobLogRecordsToFetch int
166 ShowRecentCollectionsOnDashboard bool
167 ShowUserAgreementInline bool
168 ShowUserNotifications bool
171 UserProfileFormFields map[string]struct {
173 FormFieldTitle string
174 FormFieldDescription string
177 Options map[string]struct{}
179 UserProfileFormMessage string
183 EnableBetaController14287 bool
186 type Services struct {
189 DispatchCloud Service
199 WebDAVDownload Service
207 type Service struct {
208 InternalURLs map[URL]ServiceInstance
212 // URL is a url.URL that is also usable as a JSON key/value.
215 // UnmarshalText implements encoding.TextUnmarshaler so URL can be
216 // used as a JSON key/value.
217 func (su *URL) UnmarshalText(text []byte) error {
218 u, err := url.Parse(string(text))
225 func (su URL) MarshalText() ([]byte, error) {
226 return []byte(fmt.Sprintf("%s", (*url.URL)(&su).String())), nil
229 type ServiceInstance struct{}
231 type PostgreSQL struct {
232 Connection PostgreSQLConnection
236 type PostgreSQLConnection map[string]string
238 type RemoteCluster struct {
246 type InstanceType struct {
252 IncludedScratch ByteSize
253 AddedScratch ByteSize
258 type ContainersConfig struct {
259 CloudVMs CloudVMsConfig
260 CrunchRunCommand string
261 CrunchRunArgumentsList []string
262 DefaultKeepCacheRAM ByteSize
263 DispatchPrivateKey string
264 LogReuseDecisions bool
266 MaxDispatchAttempts int
268 MinRetryPeriod Duration
269 ReserveExtraRAM ByteSize
270 StaleLockTimeout Duration
271 SupportedDockerImageFormats StringSet
272 UsePreemptibleInstances bool
276 GitInternalDir string
277 DefaultDockerImage string
278 CrunchJobWrapper string
280 CrunchRefreshTrigger string
281 ReuseJobIfOutputsDiffer bool
286 LogSecondsBetweenEvents int
287 LogThrottlePeriod Duration
290 LimitLogBytesPerJob int
291 LogPartialLineThrottlePeriod Duration
292 LogUpdatePeriod Duration
293 LogUpdateSize ByteSize
297 SbatchArgumentsList []string
298 SbatchEnvironmentVariables map[string]string
300 DNSServerConfDir string
301 DNSServerConfTemplate string
302 DNSServerReloadCommand string
303 DNSServerUpdateCommand string
304 ComputeNodeDomain string
305 ComputeNodeNameservers StringSet
306 AssignNodeHostname string
311 type CloudVMsConfig struct {
314 BootProbeCommand string
316 MaxCloudOpsPerSecond int
317 MaxProbesPerSecond int
318 PollInterval Duration
319 ProbeInterval Duration
321 SyncInterval Duration
322 TimeoutBooting Duration
324 TimeoutProbe Duration
325 TimeoutShutdown Duration
326 TimeoutSignal Duration
328 ResourceTags map[string]string
332 DriverParameters json.RawMessage
335 type InstanceTypeMap map[string]InstanceType
337 var errDuplicateInstanceTypeName = errors.New("duplicate instance type name")
339 // UnmarshalJSON handles old config files that provide an array of
340 // instance types instead of a hash.
341 func (it *InstanceTypeMap) UnmarshalJSON(data []byte) error {
342 if len(data) > 0 && data[0] == '[' {
343 var arr []InstanceType
344 err := json.Unmarshal(data, &arr)
352 *it = make(map[string]InstanceType, len(arr))
353 for _, t := range arr {
354 if _, ok := (*it)[t.Name]; ok {
355 return errDuplicateInstanceTypeName
357 if t.ProviderType == "" {
358 t.ProviderType = t.Name
361 t.Scratch = t.IncludedScratch + t.AddedScratch
362 } else if t.AddedScratch == 0 {
363 t.AddedScratch = t.Scratch - t.IncludedScratch
364 } else if t.IncludedScratch == 0 {
365 t.IncludedScratch = t.Scratch - t.AddedScratch
368 if t.Scratch != (t.IncludedScratch + t.AddedScratch) {
369 return fmt.Errorf("%v: Scratch != (IncludedScratch + AddedScratch)", t.Name)
375 var hash map[string]InstanceType
376 err := json.Unmarshal(data, &hash)
380 // Fill in Name field (and ProviderType field, if not
381 // specified) using hash key.
382 *it = InstanceTypeMap(hash)
383 for name, t := range *it {
385 if t.ProviderType == "" {
386 t.ProviderType = name
393 type StringSet map[string]struct{}
395 // UnmarshalJSON handles old config files that provide an array of
396 // instance types instead of a hash.
397 func (ss *StringSet) UnmarshalJSON(data []byte) error {
398 if len(data) > 0 && data[0] == '[' {
400 err := json.Unmarshal(data, &arr)
408 *ss = make(map[string]struct{}, len(arr))
409 for _, t := range arr {
410 (*ss)[t] = struct{}{}
414 var hash map[string]struct{}
415 err := json.Unmarshal(data, &hash)
419 *ss = make(map[string]struct{}, len(hash))
420 for t, _ := range hash {
421 (*ss)[t] = struct{}{}
427 type ServiceName string
430 ServiceNameRailsAPI ServiceName = "arvados-api-server"
431 ServiceNameController ServiceName = "arvados-controller"
432 ServiceNameDispatchCloud ServiceName = "arvados-dispatch-cloud"
433 ServiceNameHealth ServiceName = "arvados-health"
434 ServiceNameNodemanager ServiceName = "arvados-node-manager"
435 ServiceNameWorkbench1 ServiceName = "arvados-workbench1"
436 ServiceNameWorkbench2 ServiceName = "arvados-workbench2"
437 ServiceNameWebsocket ServiceName = "arvados-ws"
438 ServiceNameKeepbalance ServiceName = "keep-balance"
439 ServiceNameKeepweb ServiceName = "keep-web"
440 ServiceNameKeepproxy ServiceName = "keepproxy"
441 ServiceNameKeepstore ServiceName = "keepstore"
444 // Map returns all services as a map, suitable for iterating over all
445 // services or looking up a service by name.
446 func (svcs Services) Map() map[ServiceName]Service {
447 return map[ServiceName]Service{
448 ServiceNameRailsAPI: svcs.RailsAPI,
449 ServiceNameController: svcs.Controller,
450 ServiceNameDispatchCloud: svcs.DispatchCloud,
451 ServiceNameHealth: svcs.Health,
452 ServiceNameNodemanager: svcs.Nodemanager,
453 ServiceNameWorkbench1: svcs.Workbench1,
454 ServiceNameWorkbench2: svcs.Workbench2,
455 ServiceNameWebsocket: svcs.Websocket,
456 ServiceNameKeepbalance: svcs.Keepbalance,
457 ServiceNameKeepweb: svcs.WebDAV,
458 ServiceNameKeepproxy: svcs.Keepproxy,
459 ServiceNameKeepstore: svcs.Keepstore,