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 DefaultReplication int
82 BlobSigningTTL Duration
83 DefaultTrashLifetime Duration
84 TrashSweepInterval Duration
85 CollectionVersioning bool
86 PreserveVersionIfIdle Duration
92 ProviderAppSecret string
96 MailchimpAPIKey string
97 MailchimpListID string
98 SendUserSetupNotificationEmail string
99 IssueReporterEmailFrom string
100 IssueReporterEmailTo string
101 SupportEmailAddress string
107 MaxRequestLogParamsSize int
115 AdminNotifierEmailFrom string
116 AutoAdminFirstUser bool
117 AutoAdminUserWithEmail string
118 AutoSetupNewUsers bool
119 AutoSetupNewUsersWithRepository bool
120 AutoSetupNewUsersWithVmUUID string
121 AutoSetupUsernameBlacklist []string
122 EmailSubjectPrefix string
123 NewInactiveUserNotificationRecipients []string
124 NewUserNotificationRecipients []string
125 NewUsersAreActive bool
126 UserNotifierEmailFrom string
127 UserProfileNotificationAddress string
130 ActivationContactLink string
131 APIClientConnectTimeout Duration
132 APIClientReceiveTimeout Duration
133 APIResponseCompression bool
134 ApplicationMimetypesWithViewIcon map[string]struct{}
135 ArvadosDocsite string
136 ArvadosPublicDataDocURL string
137 EnableGettingStartedPopup bool
138 EnablePublicProjectsPage bool
139 FileViewersConfigURL string
140 LogViewerMaxBytes ByteSize
143 RepositoryCache string
144 RunningJobLogRecordsToFetch int
147 ShowRecentCollectionsOnDashboard bool
148 ShowUserAgreementInline bool
149 ShowUserNotifications bool
152 UserProfileFormFields map[string]struct {
154 FormFieldTitle string
155 FormFieldDescription string
158 UserProfileFormMessage string
163 type Services struct {
166 DispatchCloud Service
176 WebDAVDownload Service
184 type Service struct {
185 InternalURLs map[URL]ServiceInstance
189 // URL is a url.URL that is also usable as a JSON key/value.
192 // UnmarshalText implements encoding.TextUnmarshaler so URL can be
193 // used as a JSON key/value.
194 func (su *URL) UnmarshalText(text []byte) error {
195 u, err := url.Parse(string(text))
202 func (su URL) MarshalText() ([]byte, error) {
203 return []byte(fmt.Sprintf("%s", (*url.URL)(&su).String())), nil
206 type ServiceInstance struct{}
208 type PostgreSQL struct {
209 Connection PostgreSQLConnection
213 type PostgreSQLConnection map[string]string
215 type RemoteCluster struct {
223 type InstanceType struct {
229 IncludedScratch ByteSize
230 AddedScratch ByteSize
235 type ContainersConfig struct {
236 CloudVMs CloudVMsConfig
237 DefaultKeepCacheRAM ByteSize
238 DispatchPrivateKey string
239 LogReuseDecisions bool
241 MaxDispatchAttempts int
243 StaleLockTimeout Duration
244 SupportedDockerImageFormats []string
245 UsePreemptibleInstances bool
249 GitInternalDir string
250 DefaultDockerImage string
251 CrunchJobWrapper string
253 CrunchRefreshTrigger string
254 ReuseJobIfOutputsDiffer bool
259 LogSecondsBetweenEvents int
260 LogThrottlePeriod Duration
263 LimitLogBytesPerJob int
264 LogPartialLineThrottlePeriod Duration
265 LogUpdatePeriod Duration
266 LogUpdateSize ByteSize
270 DNSServerConfDir string
271 DNSServerConfTemplate string
272 DNSServerReloadCommand string
273 DNSServerUpdateCommand string
274 ComputeNodeDomain string
275 ComputeNodeNameservers []string
276 AssignNodeHostname string
281 type CloudVMsConfig struct {
284 BootProbeCommand string
286 MaxCloudOpsPerSecond int
287 MaxProbesPerSecond int
288 PollInterval Duration
289 ProbeInterval Duration
291 SyncInterval Duration
292 TimeoutBooting Duration
294 TimeoutProbe Duration
295 TimeoutShutdown Duration
296 TimeoutSignal Duration
298 ResourceTags map[string]string
302 DriverParameters json.RawMessage
305 type InstanceTypeMap map[string]InstanceType
307 var errDuplicateInstanceTypeName = errors.New("duplicate instance type name")
309 // UnmarshalJSON handles old config files that provide an array of
310 // instance types instead of a hash.
311 func (it *InstanceTypeMap) UnmarshalJSON(data []byte) error {
312 if len(data) > 0 && data[0] == '[' {
313 var arr []InstanceType
314 err := json.Unmarshal(data, &arr)
322 *it = make(map[string]InstanceType, len(arr))
323 for _, t := range arr {
324 if _, ok := (*it)[t.Name]; ok {
325 return errDuplicateInstanceTypeName
327 if t.ProviderType == "" {
328 t.ProviderType = t.Name
331 t.Scratch = t.IncludedScratch + t.AddedScratch
332 } else if t.AddedScratch == 0 {
333 t.AddedScratch = t.Scratch - t.IncludedScratch
334 } else if t.IncludedScratch == 0 {
335 t.IncludedScratch = t.Scratch - t.AddedScratch
338 if t.Scratch != (t.IncludedScratch + t.AddedScratch) {
339 return fmt.Errorf("%v: Scratch != (IncludedScratch + AddedScratch)", t.Name)
345 var hash map[string]InstanceType
346 err := json.Unmarshal(data, &hash)
350 // Fill in Name field (and ProviderType field, if not
351 // specified) using hash key.
352 *it = InstanceTypeMap(hash)
353 for name, t := range *it {
355 if t.ProviderType == "" {
356 t.ProviderType = name
363 type ServiceName string
366 ServiceNameRailsAPI ServiceName = "arvados-api-server"
367 ServiceNameController ServiceName = "arvados-controller"
368 ServiceNameDispatchCloud ServiceName = "arvados-dispatch-cloud"
369 ServiceNameHealth ServiceName = "arvados-health"
370 ServiceNameNodemanager ServiceName = "arvados-node-manager"
371 ServiceNameWorkbench1 ServiceName = "arvados-workbench1"
372 ServiceNameWorkbench2 ServiceName = "arvados-workbench2"
373 ServiceNameWebsocket ServiceName = "arvados-ws"
374 ServiceNameKeepbalance ServiceName = "keep-balance"
375 ServiceNameKeepweb ServiceName = "keep-web"
376 ServiceNameKeepproxy ServiceName = "keepproxy"
377 ServiceNameKeepstore ServiceName = "keepstore"
380 // Map returns all services as a map, suitable for iterating over all
381 // services or looking up a service by name.
382 func (svcs Services) Map() map[ServiceName]Service {
383 return map[ServiceName]Service{
384 ServiceNameRailsAPI: svcs.RailsAPI,
385 ServiceNameController: svcs.Controller,
386 ServiceNameDispatchCloud: svcs.DispatchCloud,
387 ServiceNameHealth: svcs.Health,
388 ServiceNameNodemanager: svcs.Nodemanager,
389 ServiceNameWorkbench1: svcs.Workbench1,
390 ServiceNameWorkbench2: svcs.Workbench2,
391 ServiceNameWebsocket: svcs.Websocket,
392 ServiceNameKeepbalance: svcs.Keepbalance,
393 ServiceNameKeepweb: svcs.WebDAV,
394 ServiceNameKeepproxy: svcs.Keepproxy,
395 ServiceNameKeepstore: svcs.Keepstore,