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
144 ProfilingEnabled bool
146 RepositoryCache string
147 RunningJobLogRecordsToFetch int
149 ShowRecentCollectionsOnDashboard bool
150 ShowUserAgreementInline bool
151 ShowUserNotifications bool
155 UserProfileFormFields map[string]struct {
157 FormFieldTitle string
158 FormFieldDescription string
161 Options map[string]struct{}
163 UserProfileFormMessage string
167 EnableBetaController14287 bool
170 type Services struct {
173 DispatchCloud Service
183 WebDAVDownload Service
191 type Service struct {
192 InternalURLs map[URL]ServiceInstance
196 // URL is a url.URL that is also usable as a JSON key/value.
199 // UnmarshalText implements encoding.TextUnmarshaler so URL can be
200 // used as a JSON key/value.
201 func (su *URL) UnmarshalText(text []byte) error {
202 u, err := url.Parse(string(text))
209 func (su URL) MarshalText() ([]byte, error) {
210 return []byte(fmt.Sprintf("%s", (*url.URL)(&su).String())), nil
213 type ServiceInstance struct{}
215 type PostgreSQL struct {
216 Connection PostgreSQLConnection
220 type PostgreSQLConnection map[string]string
222 type RemoteCluster struct {
230 type InstanceType struct {
236 IncludedScratch ByteSize
237 AddedScratch ByteSize
242 type ContainersConfig struct {
243 CloudVMs CloudVMsConfig
244 DefaultKeepCacheRAM ByteSize
245 DispatchPrivateKey string
246 LogReuseDecisions bool
248 MaxDispatchAttempts int
250 StaleLockTimeout Duration
251 SupportedDockerImageFormats []string
252 UsePreemptibleInstances bool
256 GitInternalDir string
257 DefaultDockerImage string
258 CrunchJobWrapper string
260 CrunchRefreshTrigger string
261 ReuseJobIfOutputsDiffer bool
266 LogSecondsBetweenEvents int
267 LogThrottlePeriod Duration
270 LimitLogBytesPerJob int
271 LogPartialLineThrottlePeriod Duration
272 LogUpdatePeriod Duration
273 LogUpdateSize ByteSize
277 DNSServerConfDir string
278 DNSServerConfTemplate string
279 DNSServerReloadCommand string
280 DNSServerUpdateCommand string
281 ComputeNodeDomain string
282 ComputeNodeNameservers []string
283 AssignNodeHostname string
288 type CloudVMsConfig struct {
291 BootProbeCommand string
293 MaxCloudOpsPerSecond int
294 MaxProbesPerSecond int
295 PollInterval Duration
296 ProbeInterval Duration
298 SyncInterval Duration
299 TimeoutBooting Duration
301 TimeoutProbe Duration
302 TimeoutShutdown Duration
303 TimeoutSignal Duration
305 ResourceTags map[string]string
309 DriverParameters json.RawMessage
312 type InstanceTypeMap map[string]InstanceType
314 var errDuplicateInstanceTypeName = errors.New("duplicate instance type name")
316 // UnmarshalJSON handles old config files that provide an array of
317 // instance types instead of a hash.
318 func (it *InstanceTypeMap) UnmarshalJSON(data []byte) error {
319 if len(data) > 0 && data[0] == '[' {
320 var arr []InstanceType
321 err := json.Unmarshal(data, &arr)
329 *it = make(map[string]InstanceType, len(arr))
330 for _, t := range arr {
331 if _, ok := (*it)[t.Name]; ok {
332 return errDuplicateInstanceTypeName
334 if t.ProviderType == "" {
335 t.ProviderType = t.Name
338 t.Scratch = t.IncludedScratch + t.AddedScratch
339 } else if t.AddedScratch == 0 {
340 t.AddedScratch = t.Scratch - t.IncludedScratch
341 } else if t.IncludedScratch == 0 {
342 t.IncludedScratch = t.Scratch - t.AddedScratch
345 if t.Scratch != (t.IncludedScratch + t.AddedScratch) {
346 return fmt.Errorf("%v: Scratch != (IncludedScratch + AddedScratch)", t.Name)
352 var hash map[string]InstanceType
353 err := json.Unmarshal(data, &hash)
357 // Fill in Name field (and ProviderType field, if not
358 // specified) using hash key.
359 *it = InstanceTypeMap(hash)
360 for name, t := range *it {
362 if t.ProviderType == "" {
363 t.ProviderType = name
370 type ServiceName string
373 ServiceNameRailsAPI ServiceName = "arvados-api-server"
374 ServiceNameController ServiceName = "arvados-controller"
375 ServiceNameDispatchCloud ServiceName = "arvados-dispatch-cloud"
376 ServiceNameHealth ServiceName = "arvados-health"
377 ServiceNameNodemanager ServiceName = "arvados-node-manager"
378 ServiceNameWorkbench1 ServiceName = "arvados-workbench1"
379 ServiceNameWorkbench2 ServiceName = "arvados-workbench2"
380 ServiceNameWebsocket ServiceName = "arvados-ws"
381 ServiceNameKeepbalance ServiceName = "keep-balance"
382 ServiceNameKeepweb ServiceName = "keep-web"
383 ServiceNameKeepproxy ServiceName = "keepproxy"
384 ServiceNameKeepstore ServiceName = "keepstore"
387 // Map returns all services as a map, suitable for iterating over all
388 // services or looking up a service by name.
389 func (svcs Services) Map() map[ServiceName]Service {
390 return map[ServiceName]Service{
391 ServiceNameRailsAPI: svcs.RailsAPI,
392 ServiceNameController: svcs.Controller,
393 ServiceNameDispatchCloud: svcs.DispatchCloud,
394 ServiceNameHealth: svcs.Health,
395 ServiceNameNodemanager: svcs.Nodemanager,
396 ServiceNameWorkbench1: svcs.Workbench1,
397 ServiceNameWorkbench2: svcs.Workbench2,
398 ServiceNameWebsocket: svcs.Websocket,
399 ServiceNameKeepbalance: svcs.Keepbalance,
400 ServiceNameKeepweb: svcs.WebDAV,
401 ServiceNameKeepproxy: svcs.Keepproxy,
402 ServiceNameKeepstore: svcs.Keepstore,