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 string
100 IssueReporterEmailFrom string
101 IssueReporterEmailTo string
102 SupportEmailAddress string
108 MaxRequestLogParamsSize int
116 AdminNotifierEmailFrom string
117 AutoAdminFirstUser bool
118 AutoAdminUserWithEmail string
119 AutoSetupNewUsers bool
120 AutoSetupNewUsersWithRepository bool
121 AutoSetupNewUsersWithVmUUID string
122 AutoSetupUsernameBlacklist []string
123 EmailSubjectPrefix string
124 NewInactiveUserNotificationRecipients []string
125 NewUserNotificationRecipients []string
126 NewUsersAreActive bool
127 UserNotifierEmailFrom string
128 UserProfileNotificationAddress string
131 ActivationContactLink string
132 APIClientConnectTimeout Duration
133 APIClientReceiveTimeout Duration
134 APIResponseCompression bool
135 ApplicationMimetypesWithViewIcon map[string]struct{}
136 ArvadosDocsite string
137 ArvadosPublicDataDocURL string
138 EnableGettingStartedPopup bool
139 EnablePublicProjectsPage bool
140 FileViewersConfigURL string
141 LogViewerMaxBytes ByteSize
144 RepositoryCache string
145 RunningJobLogRecordsToFetch int
148 ShowRecentCollectionsOnDashboard bool
149 ShowUserAgreementInline bool
150 ShowUserNotifications bool
153 UserProfileFormFields map[string]struct {
155 FormFieldTitle string
156 FormFieldDescription string
159 UserProfileFormMessage string
164 type Services struct {
167 DispatchCloud Service
177 WebDAVDownload Service
185 type Service struct {
186 InternalURLs map[URL]ServiceInstance
190 // URL is a url.URL that is also usable as a JSON key/value.
193 // UnmarshalText implements encoding.TextUnmarshaler so URL can be
194 // used as a JSON key/value.
195 func (su *URL) UnmarshalText(text []byte) error {
196 u, err := url.Parse(string(text))
203 func (su URL) MarshalText() ([]byte, error) {
204 return []byte(fmt.Sprintf("%s", (*url.URL)(&su).String())), nil
207 type ServiceInstance struct{}
209 type PostgreSQL struct {
210 Connection PostgreSQLConnection
214 type PostgreSQLConnection map[string]string
216 type RemoteCluster struct {
224 type InstanceType struct {
230 IncludedScratch ByteSize
231 AddedScratch ByteSize
236 type ContainersConfig struct {
237 CloudVMs CloudVMsConfig
238 DefaultKeepCacheRAM ByteSize
239 DispatchPrivateKey string
240 LogReuseDecisions bool
242 MaxDispatchAttempts int
244 StaleLockTimeout Duration
245 SupportedDockerImageFormats []string
246 UsePreemptibleInstances bool
250 GitInternalDir string
251 DefaultDockerImage string
252 CrunchJobWrapper string
254 CrunchRefreshTrigger string
255 ReuseJobIfOutputsDiffer bool
260 LogSecondsBetweenEvents int
261 LogThrottlePeriod Duration
264 LimitLogBytesPerJob int
265 LogPartialLineThrottlePeriod Duration
266 LogUpdatePeriod Duration
267 LogUpdateSize ByteSize
271 DNSServerConfDir string
272 DNSServerConfTemplate string
273 DNSServerReloadCommand string
274 DNSServerUpdateCommand string
275 ComputeNodeDomain string
276 ComputeNodeNameservers []string
277 AssignNodeHostname string
282 type CloudVMsConfig struct {
285 BootProbeCommand string
287 MaxCloudOpsPerSecond int
288 MaxProbesPerSecond int
289 PollInterval Duration
290 ProbeInterval Duration
292 SyncInterval Duration
293 TimeoutBooting Duration
295 TimeoutProbe Duration
296 TimeoutShutdown Duration
297 TimeoutSignal Duration
299 ResourceTags map[string]string
303 DriverParameters json.RawMessage
306 type InstanceTypeMap map[string]InstanceType
308 var errDuplicateInstanceTypeName = errors.New("duplicate instance type name")
310 // UnmarshalJSON handles old config files that provide an array of
311 // instance types instead of a hash.
312 func (it *InstanceTypeMap) UnmarshalJSON(data []byte) error {
313 if len(data) > 0 && data[0] == '[' {
314 var arr []InstanceType
315 err := json.Unmarshal(data, &arr)
323 *it = make(map[string]InstanceType, len(arr))
324 for _, t := range arr {
325 if _, ok := (*it)[t.Name]; ok {
326 return errDuplicateInstanceTypeName
328 if t.ProviderType == "" {
329 t.ProviderType = t.Name
332 t.Scratch = t.IncludedScratch + t.AddedScratch
333 } else if t.AddedScratch == 0 {
334 t.AddedScratch = t.Scratch - t.IncludedScratch
335 } else if t.IncludedScratch == 0 {
336 t.IncludedScratch = t.Scratch - t.AddedScratch
339 if t.Scratch != (t.IncludedScratch + t.AddedScratch) {
340 return fmt.Errorf("%v: Scratch != (IncludedScratch + AddedScratch)", t.Name)
346 var hash map[string]InstanceType
347 err := json.Unmarshal(data, &hash)
351 // Fill in Name field (and ProviderType field, if not
352 // specified) using hash key.
353 *it = InstanceTypeMap(hash)
354 for name, t := range *it {
356 if t.ProviderType == "" {
357 t.ProviderType = name
364 type ServiceName string
367 ServiceNameRailsAPI ServiceName = "arvados-api-server"
368 ServiceNameController ServiceName = "arvados-controller"
369 ServiceNameDispatchCloud ServiceName = "arvados-dispatch-cloud"
370 ServiceNameHealth ServiceName = "arvados-health"
371 ServiceNameNodemanager ServiceName = "arvados-node-manager"
372 ServiceNameWorkbench1 ServiceName = "arvados-workbench1"
373 ServiceNameWorkbench2 ServiceName = "arvados-workbench2"
374 ServiceNameWebsocket ServiceName = "arvados-ws"
375 ServiceNameKeepbalance ServiceName = "keep-balance"
376 ServiceNameKeepweb ServiceName = "keep-web"
377 ServiceNameKeepproxy ServiceName = "keepproxy"
378 ServiceNameKeepstore ServiceName = "keepstore"
381 // Map returns all services as a map, suitable for iterating over all
382 // services or looking up a service by name.
383 func (svcs Services) Map() map[ServiceName]Service {
384 return map[ServiceName]Service{
385 ServiceNameRailsAPI: svcs.RailsAPI,
386 ServiceNameController: svcs.Controller,
387 ServiceNameDispatchCloud: svcs.DispatchCloud,
388 ServiceNameHealth: svcs.Health,
389 ServiceNameNodemanager: svcs.Nodemanager,
390 ServiceNameWorkbench1: svcs.Workbench1,
391 ServiceNameWorkbench2: svcs.Workbench2,
392 ServiceNameWebsocket: svcs.Websocket,
393 ServiceNameKeepbalance: svcs.Keepbalance,
394 ServiceNameKeepweb: svcs.WebDAV,
395 ServiceNameKeepproxy: svcs.Keepproxy,
396 ServiceNameKeepstore: svcs.Keepstore,