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
94 ProviderAppSecret string
98 MailchimpAPIKey string
99 MailchimpListID string
100 SendUserSetupNotificationEmail bool
101 IssueReporterEmailFrom string
102 IssueReporterEmailTo string
103 SupportEmailAddress string
109 MaxRequestLogParamsSize int
117 AnonymousUserToken string
118 AdminNotifierEmailFrom string
119 AutoAdminFirstUser bool
120 AutoAdminUserWithEmail string
121 AutoSetupNewUsers bool
122 AutoSetupNewUsersWithRepository bool
123 AutoSetupNewUsersWithVmUUID string
124 AutoSetupUsernameBlacklist []string
125 EmailSubjectPrefix string
126 NewInactiveUserNotificationRecipients []string
127 NewUserNotificationRecipients []string
128 NewUsersAreActive bool
129 UserNotifierEmailFrom string
130 UserProfileNotificationAddress string
133 ActivationContactLink string
134 APIClientConnectTimeout Duration
135 APIClientReceiveTimeout Duration
136 APIResponseCompression bool
137 ApplicationMimetypesWithViewIcon map[string]struct{}
138 ArvadosDocsite string
139 ArvadosPublicDataDocURL string
140 DefaultOpenIdPrefix string
141 EnableGettingStartedPopup bool
142 EnablePublicProjectsPage bool
143 FileViewersConfigURL string
144 LogViewerMaxBytes ByteSize
145 MultiSiteSearch string
146 ProfilingEnabled bool
148 RepositoryCache string
149 RunningJobLogRecordsToFetch int
151 ShowRecentCollectionsOnDashboard bool
152 ShowUserAgreementInline bool
153 ShowUserNotifications bool
156 UserProfileFormFields map[string]struct {
158 FormFieldTitle string
159 FormFieldDescription string
162 Options map[string]struct{}
164 UserProfileFormMessage string
168 EnableBetaController14287 bool
171 type Services struct {
174 DispatchCloud Service
184 WebDAVDownload Service
192 type Service struct {
193 InternalURLs map[URL]ServiceInstance
197 // URL is a url.URL that is also usable as a JSON key/value.
200 // UnmarshalText implements encoding.TextUnmarshaler so URL can be
201 // used as a JSON key/value.
202 func (su *URL) UnmarshalText(text []byte) error {
203 u, err := url.Parse(string(text))
210 func (su URL) MarshalText() ([]byte, error) {
211 return []byte(fmt.Sprintf("%s", (*url.URL)(&su).String())), nil
214 type ServiceInstance struct{}
216 type PostgreSQL struct {
217 Connection PostgreSQLConnection
221 type PostgreSQLConnection map[string]string
223 type RemoteCluster struct {
231 type InstanceType struct {
237 IncludedScratch ByteSize
238 AddedScratch ByteSize
243 type ContainersConfig struct {
244 CloudVMs CloudVMsConfig
245 DefaultKeepCacheRAM ByteSize
246 DispatchPrivateKey string
247 LogReuseDecisions bool
249 MaxDispatchAttempts int
251 StaleLockTimeout Duration
252 SupportedDockerImageFormats []string
253 UsePreemptibleInstances bool
257 GitInternalDir string
258 DefaultDockerImage string
259 CrunchJobWrapper string
261 CrunchRefreshTrigger string
262 ReuseJobIfOutputsDiffer bool
267 LogSecondsBetweenEvents int
268 LogThrottlePeriod Duration
271 LimitLogBytesPerJob int
272 LogPartialLineThrottlePeriod Duration
273 LogUpdatePeriod Duration
274 LogUpdateSize ByteSize
278 DNSServerConfDir string
279 DNSServerConfTemplate string
280 DNSServerReloadCommand string
281 DNSServerUpdateCommand string
282 ComputeNodeDomain string
283 ComputeNodeNameservers []string
284 AssignNodeHostname string
289 type CloudVMsConfig struct {
292 BootProbeCommand string
294 MaxCloudOpsPerSecond int
295 MaxProbesPerSecond int
296 PollInterval Duration
297 ProbeInterval Duration
299 SyncInterval Duration
300 TimeoutBooting Duration
302 TimeoutProbe Duration
303 TimeoutShutdown Duration
304 TimeoutSignal Duration
306 ResourceTags map[string]string
310 DriverParameters json.RawMessage
313 type InstanceTypeMap map[string]InstanceType
315 var errDuplicateInstanceTypeName = errors.New("duplicate instance type name")
317 // UnmarshalJSON handles old config files that provide an array of
318 // instance types instead of a hash.
319 func (it *InstanceTypeMap) UnmarshalJSON(data []byte) error {
320 if len(data) > 0 && data[0] == '[' {
321 var arr []InstanceType
322 err := json.Unmarshal(data, &arr)
330 *it = make(map[string]InstanceType, len(arr))
331 for _, t := range arr {
332 if _, ok := (*it)[t.Name]; ok {
333 return errDuplicateInstanceTypeName
335 if t.ProviderType == "" {
336 t.ProviderType = t.Name
339 t.Scratch = t.IncludedScratch + t.AddedScratch
340 } else if t.AddedScratch == 0 {
341 t.AddedScratch = t.Scratch - t.IncludedScratch
342 } else if t.IncludedScratch == 0 {
343 t.IncludedScratch = t.Scratch - t.AddedScratch
346 if t.Scratch != (t.IncludedScratch + t.AddedScratch) {
347 return fmt.Errorf("%v: Scratch != (IncludedScratch + AddedScratch)", t.Name)
353 var hash map[string]InstanceType
354 err := json.Unmarshal(data, &hash)
358 // Fill in Name field (and ProviderType field, if not
359 // specified) using hash key.
360 *it = InstanceTypeMap(hash)
361 for name, t := range *it {
363 if t.ProviderType == "" {
364 t.ProviderType = name
371 type ServiceName string
374 ServiceNameRailsAPI ServiceName = "arvados-api-server"
375 ServiceNameController ServiceName = "arvados-controller"
376 ServiceNameDispatchCloud ServiceName = "arvados-dispatch-cloud"
377 ServiceNameHealth ServiceName = "arvados-health"
378 ServiceNameNodemanager ServiceName = "arvados-node-manager"
379 ServiceNameWorkbench1 ServiceName = "arvados-workbench1"
380 ServiceNameWorkbench2 ServiceName = "arvados-workbench2"
381 ServiceNameWebsocket ServiceName = "arvados-ws"
382 ServiceNameKeepbalance ServiceName = "keep-balance"
383 ServiceNameKeepweb ServiceName = "keep-web"
384 ServiceNameKeepproxy ServiceName = "keepproxy"
385 ServiceNameKeepstore ServiceName = "keepstore"
388 // Map returns all services as a map, suitable for iterating over all
389 // services or looking up a service by name.
390 func (svcs Services) Map() map[ServiceName]Service {
391 return map[ServiceName]Service{
392 ServiceNameRailsAPI: svcs.RailsAPI,
393 ServiceNameController: svcs.Controller,
394 ServiceNameDispatchCloud: svcs.DispatchCloud,
395 ServiceNameHealth: svcs.Health,
396 ServiceNameNodemanager: svcs.Nodemanager,
397 ServiceNameWorkbench1: svcs.Workbench1,
398 ServiceNameWorkbench2: svcs.Workbench2,
399 ServiceNameWebsocket: svcs.Websocket,
400 ServiceNameKeepbalance: svcs.Keepbalance,
401 ServiceNameKeepweb: svcs.WebDAV,
402 ServiceNameKeepproxy: svcs.Keepproxy,
403 ServiceNameKeepstore: svcs.Keepstore,