1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: Apache-2.0
13 "git.curoverse.com/arvados.git/sdk/go/config"
16 const DefaultConfigFile = "/etc/arvados/config.yml"
19 Clusters map[string]Cluster
22 // GetConfig returns the current system config, loading it from
23 // configFile if needed.
24 func GetConfig(configFile string) (*Config, error) {
26 err := config.LoadFile(&cfg, configFile)
30 // GetCluster returns the cluster ID and config for the given
31 // cluster, or the default/only configured cluster if clusterID is "".
32 func (sc *Config) GetCluster(clusterID string) (*Cluster, error) {
34 if len(sc.Clusters) == 0 {
35 return nil, fmt.Errorf("no clusters configured")
36 } else if len(sc.Clusters) > 1 {
37 return nil, fmt.Errorf("multiple clusters configured, cannot choose")
39 for id, cc := range sc.Clusters {
45 if cc, ok := sc.Clusters[clusterID]; !ok {
46 return nil, fmt.Errorf("cluster %q is not configured", clusterID)
48 cc.ClusterID = clusterID
54 ClusterID string `json:"-"`
55 ManagementToken string
56 SystemRootToken string
58 InstanceTypes InstanceTypeMap
59 Containers ContainersConfig
60 RemoteClusters map[string]RemoteCluster
64 AsyncPermissionsUpdateInterval Duration
66 MaxIndexDatabaseRead int
67 MaxItemsPerResponse int
68 MaxRequestAmplification int
70 RailsSessionSecretToken string
71 RequestTimeout Duration
76 UnloggedAttributes []string
81 BlobSigningTTL Duration
82 CollectionVersioning bool
83 DefaultTrashLifetime Duration
84 DefaultReplication int
85 ManagedProperties map[string]interface{}
86 PreserveVersionIfIdle Duration
87 TrashSweepInterval Duration
93 ProviderAppSecret string
97 MailchimpAPIKey string
98 MailchimpListID string
99 SendUserSetupNotificationEmail bool
100 IssueReporterEmailFrom string
101 IssueReporterEmailTo string
102 SupportEmailAddress string
108 MaxRequestLogParamsSize int
116 AnonymousUserToken string
117 AdminNotifierEmailFrom string
118 AutoAdminFirstUser bool
119 AutoAdminUserWithEmail string
120 AutoSetupNewUsers bool
121 AutoSetupNewUsersWithRepository bool
122 AutoSetupNewUsersWithVmUUID string
123 AutoSetupUsernameBlacklist []string
124 EmailSubjectPrefix string
125 NewInactiveUserNotificationRecipients []string
126 NewUserNotificationRecipients []string
127 NewUsersAreActive bool
128 UserNotifierEmailFrom string
129 UserProfileNotificationAddress string
132 ActivationContactLink string
133 APIClientConnectTimeout Duration
134 APIClientReceiveTimeout Duration
135 APIResponseCompression bool
136 ApplicationMimetypesWithViewIcon map[string]struct{}
137 ArvadosDocsite string
138 ArvadosPublicDataDocURL string
139 EnableGettingStartedPopup bool
140 EnablePublicProjectsPage bool
141 FileViewersConfigURL string
142 LogViewerMaxBytes ByteSize
143 MultiSiteSearch string
145 RepositoryCache string
146 RunningJobLogRecordsToFetch int
148 ShowRecentCollectionsOnDashboard bool
149 ShowUserAgreementInline bool
150 ShowUserNotifications bool
154 UserProfileFormFields map[string]struct {
156 FormFieldTitle string
157 FormFieldDescription string
160 Options map[string]struct{}
162 UserProfileFormMessage string
166 EnableBetaController14287 bool
169 type Services struct {
172 DispatchCloud Service
182 WebDAVDownload Service
190 type Service struct {
191 InternalURLs map[URL]ServiceInstance
195 // URL is a url.URL that is also usable as a JSON key/value.
198 // UnmarshalText implements encoding.TextUnmarshaler so URL can be
199 // used as a JSON key/value.
200 func (su *URL) UnmarshalText(text []byte) error {
201 u, err := url.Parse(string(text))
208 func (su URL) MarshalText() ([]byte, error) {
209 return []byte(fmt.Sprintf("%s", (*url.URL)(&su).String())), nil
212 type ServiceInstance struct{}
214 type PostgreSQL struct {
215 Connection PostgreSQLConnection
219 type PostgreSQLConnection map[string]string
221 type RemoteCluster struct {
229 type InstanceType struct {
235 IncludedScratch ByteSize
236 AddedScratch ByteSize
241 type ContainersConfig struct {
242 CloudVMs CloudVMsConfig
243 DefaultKeepCacheRAM ByteSize
244 DispatchPrivateKey string
245 LogReuseDecisions bool
247 MaxDispatchAttempts int
249 StaleLockTimeout Duration
250 SupportedDockerImageFormats []string
251 UsePreemptibleInstances bool
255 GitInternalDir string
256 DefaultDockerImage string
257 CrunchJobWrapper string
259 CrunchRefreshTrigger string
260 ReuseJobIfOutputsDiffer bool
265 LogSecondsBetweenEvents int
266 LogThrottlePeriod Duration
269 LimitLogBytesPerJob int
270 LogPartialLineThrottlePeriod Duration
271 LogUpdatePeriod Duration
272 LogUpdateSize ByteSize
276 DNSServerConfDir string
277 DNSServerConfTemplate string
278 DNSServerReloadCommand string
279 DNSServerUpdateCommand string
280 ComputeNodeDomain string
281 ComputeNodeNameservers []string
282 AssignNodeHostname string
287 type CloudVMsConfig struct {
290 BootProbeCommand string
292 MaxCloudOpsPerSecond int
293 MaxProbesPerSecond int
294 PollInterval Duration
295 ProbeInterval Duration
297 SyncInterval Duration
298 TimeoutBooting Duration
300 TimeoutProbe Duration
301 TimeoutShutdown Duration
302 TimeoutSignal Duration
304 ResourceTags map[string]string
308 DriverParameters json.RawMessage
311 type InstanceTypeMap map[string]InstanceType
313 var errDuplicateInstanceTypeName = errors.New("duplicate instance type name")
315 // UnmarshalJSON handles old config files that provide an array of
316 // instance types instead of a hash.
317 func (it *InstanceTypeMap) UnmarshalJSON(data []byte) error {
318 if len(data) > 0 && data[0] == '[' {
319 var arr []InstanceType
320 err := json.Unmarshal(data, &arr)
328 *it = make(map[string]InstanceType, len(arr))
329 for _, t := range arr {
330 if _, ok := (*it)[t.Name]; ok {
331 return errDuplicateInstanceTypeName
333 if t.ProviderType == "" {
334 t.ProviderType = t.Name
337 t.Scratch = t.IncludedScratch + t.AddedScratch
338 } else if t.AddedScratch == 0 {
339 t.AddedScratch = t.Scratch - t.IncludedScratch
340 } else if t.IncludedScratch == 0 {
341 t.IncludedScratch = t.Scratch - t.AddedScratch
344 if t.Scratch != (t.IncludedScratch + t.AddedScratch) {
345 return fmt.Errorf("%v: Scratch != (IncludedScratch + AddedScratch)", t.Name)
351 var hash map[string]InstanceType
352 err := json.Unmarshal(data, &hash)
356 // Fill in Name field (and ProviderType field, if not
357 // specified) using hash key.
358 *it = InstanceTypeMap(hash)
359 for name, t := range *it {
361 if t.ProviderType == "" {
362 t.ProviderType = name
369 type ServiceName string
372 ServiceNameRailsAPI ServiceName = "arvados-api-server"
373 ServiceNameController ServiceName = "arvados-controller"
374 ServiceNameDispatchCloud ServiceName = "arvados-dispatch-cloud"
375 ServiceNameHealth ServiceName = "arvados-health"
376 ServiceNameNodemanager ServiceName = "arvados-node-manager"
377 ServiceNameWorkbench1 ServiceName = "arvados-workbench1"
378 ServiceNameWorkbench2 ServiceName = "arvados-workbench2"
379 ServiceNameWebsocket ServiceName = "arvados-ws"
380 ServiceNameKeepbalance ServiceName = "keep-balance"
381 ServiceNameKeepweb ServiceName = "keep-web"
382 ServiceNameKeepproxy ServiceName = "keepproxy"
383 ServiceNameKeepstore ServiceName = "keepstore"
386 // Map returns all services as a map, suitable for iterating over all
387 // services or looking up a service by name.
388 func (svcs Services) Map() map[ServiceName]Service {
389 return map[ServiceName]Service{
390 ServiceNameRailsAPI: svcs.RailsAPI,
391 ServiceNameController: svcs.Controller,
392 ServiceNameDispatchCloud: svcs.DispatchCloud,
393 ServiceNameHealth: svcs.Health,
394 ServiceNameNodemanager: svcs.Nodemanager,
395 ServiceNameWorkbench1: svcs.Workbench1,
396 ServiceNameWorkbench2: svcs.Workbench2,
397 ServiceNameWebsocket: svcs.Websocket,
398 ServiceNameKeepbalance: svcs.Keepbalance,
399 ServiceNameKeepweb: svcs.WebDAV,
400 ServiceNameKeepproxy: svcs.Keepproxy,
401 ServiceNameKeepstore: svcs.Keepstore,