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]struct {
90 PreserveVersionIfIdle Duration
91 TrashSweepInterval Duration
98 ProviderAppSecret string
102 MailchimpAPIKey string
103 MailchimpListID string
104 SendUserSetupNotificationEmail bool
105 IssueReporterEmailFrom string
106 IssueReporterEmailTo string
107 SupportEmailAddress string
113 MaxRequestLogParamsSize int
121 AnonymousUserToken string
122 AdminNotifierEmailFrom string
123 AutoAdminFirstUser bool
124 AutoAdminUserWithEmail string
125 AutoSetupNewUsers bool
126 AutoSetupNewUsersWithRepository bool
127 AutoSetupNewUsersWithVmUUID string
128 AutoSetupUsernameBlacklist []string
129 EmailSubjectPrefix string
130 NewInactiveUserNotificationRecipients []string
131 NewUserNotificationRecipients []string
132 NewUsersAreActive bool
133 UserNotifierEmailFrom string
134 UserProfileNotificationAddress string
137 ActivationContactLink string
138 APIClientConnectTimeout Duration
139 APIClientReceiveTimeout Duration
140 APIResponseCompression bool
141 ApplicationMimetypesWithViewIcon map[string]struct{}
142 ArvadosDocsite string
143 ArvadosPublicDataDocURL string
144 DefaultOpenIdPrefix string
145 EnableGettingStartedPopup bool
146 EnablePublicProjectsPage bool
147 FileViewersConfigURL string
148 LogViewerMaxBytes ByteSize
149 MultiSiteSearch string
150 ProfilingEnabled bool
152 RepositoryCache string
153 RunningJobLogRecordsToFetch int
155 ShowRecentCollectionsOnDashboard bool
156 ShowUserAgreementInline bool
157 ShowUserNotifications bool
160 UserProfileFormFields map[string]struct {
162 FormFieldTitle string
163 FormFieldDescription string
166 Options map[string]struct{}
168 UserProfileFormMessage string
172 EnableBetaController14287 bool
175 type Services struct {
178 DispatchCloud Service
188 WebDAVDownload Service
196 type Service struct {
197 InternalURLs map[URL]ServiceInstance
201 // URL is a url.URL that is also usable as a JSON key/value.
204 // UnmarshalText implements encoding.TextUnmarshaler so URL can be
205 // used as a JSON key/value.
206 func (su *URL) UnmarshalText(text []byte) error {
207 u, err := url.Parse(string(text))
214 func (su URL) MarshalText() ([]byte, error) {
215 return []byte(fmt.Sprintf("%s", (*url.URL)(&su).String())), nil
218 type ServiceInstance struct{}
220 type PostgreSQL struct {
221 Connection PostgreSQLConnection
225 type PostgreSQLConnection map[string]string
227 type RemoteCluster struct {
235 type InstanceType struct {
241 IncludedScratch ByteSize
242 AddedScratch ByteSize
247 type ContainersConfig struct {
248 CloudVMs CloudVMsConfig
249 DefaultKeepCacheRAM ByteSize
250 DispatchPrivateKey string
251 LogReuseDecisions bool
253 MaxDispatchAttempts int
255 StaleLockTimeout Duration
256 SupportedDockerImageFormats []string
257 UsePreemptibleInstances bool
261 GitInternalDir string
262 DefaultDockerImage string
263 CrunchJobWrapper string
265 CrunchRefreshTrigger string
266 ReuseJobIfOutputsDiffer bool
271 LogSecondsBetweenEvents int
272 LogThrottlePeriod Duration
275 LimitLogBytesPerJob int
276 LogPartialLineThrottlePeriod Duration
277 LogUpdatePeriod Duration
278 LogUpdateSize ByteSize
282 DNSServerConfDir string
283 DNSServerConfTemplate string
284 DNSServerReloadCommand string
285 DNSServerUpdateCommand string
286 ComputeNodeDomain string
287 ComputeNodeNameservers []string
288 AssignNodeHostname string
293 type CloudVMsConfig struct {
296 BootProbeCommand string
298 MaxCloudOpsPerSecond int
299 MaxProbesPerSecond int
300 PollInterval Duration
301 ProbeInterval Duration
303 SyncInterval Duration
304 TimeoutBooting Duration
306 TimeoutProbe Duration
307 TimeoutShutdown Duration
308 TimeoutSignal Duration
310 ResourceTags map[string]string
314 DriverParameters json.RawMessage
317 type InstanceTypeMap map[string]InstanceType
319 var errDuplicateInstanceTypeName = errors.New("duplicate instance type name")
321 // UnmarshalJSON handles old config files that provide an array of
322 // instance types instead of a hash.
323 func (it *InstanceTypeMap) UnmarshalJSON(data []byte) error {
324 if len(data) > 0 && data[0] == '[' {
325 var arr []InstanceType
326 err := json.Unmarshal(data, &arr)
334 *it = make(map[string]InstanceType, len(arr))
335 for _, t := range arr {
336 if _, ok := (*it)[t.Name]; ok {
337 return errDuplicateInstanceTypeName
339 if t.ProviderType == "" {
340 t.ProviderType = t.Name
343 t.Scratch = t.IncludedScratch + t.AddedScratch
344 } else if t.AddedScratch == 0 {
345 t.AddedScratch = t.Scratch - t.IncludedScratch
346 } else if t.IncludedScratch == 0 {
347 t.IncludedScratch = t.Scratch - t.AddedScratch
350 if t.Scratch != (t.IncludedScratch + t.AddedScratch) {
351 return fmt.Errorf("%v: Scratch != (IncludedScratch + AddedScratch)", t.Name)
357 var hash map[string]InstanceType
358 err := json.Unmarshal(data, &hash)
362 // Fill in Name field (and ProviderType field, if not
363 // specified) using hash key.
364 *it = InstanceTypeMap(hash)
365 for name, t := range *it {
367 if t.ProviderType == "" {
368 t.ProviderType = name
375 type ServiceName string
378 ServiceNameRailsAPI ServiceName = "arvados-api-server"
379 ServiceNameController ServiceName = "arvados-controller"
380 ServiceNameDispatchCloud ServiceName = "arvados-dispatch-cloud"
381 ServiceNameHealth ServiceName = "arvados-health"
382 ServiceNameNodemanager ServiceName = "arvados-node-manager"
383 ServiceNameWorkbench1 ServiceName = "arvados-workbench1"
384 ServiceNameWorkbench2 ServiceName = "arvados-workbench2"
385 ServiceNameWebsocket ServiceName = "arvados-ws"
386 ServiceNameKeepbalance ServiceName = "keep-balance"
387 ServiceNameKeepweb ServiceName = "keep-web"
388 ServiceNameKeepproxy ServiceName = "keepproxy"
389 ServiceNameKeepstore ServiceName = "keepstore"
392 // Map returns all services as a map, suitable for iterating over all
393 // services or looking up a service by name.
394 func (svcs Services) Map() map[ServiceName]Service {
395 return map[ServiceName]Service{
396 ServiceNameRailsAPI: svcs.RailsAPI,
397 ServiceNameController: svcs.Controller,
398 ServiceNameDispatchCloud: svcs.DispatchCloud,
399 ServiceNameHealth: svcs.Health,
400 ServiceNameNodemanager: svcs.Nodemanager,
401 ServiceNameWorkbench1: svcs.Workbench1,
402 ServiceNameWorkbench2: svcs.Workbench2,
403 ServiceNameWebsocket: svcs.Websocket,
404 ServiceNameKeepbalance: svcs.Keepbalance,
405 ServiceNameKeepweb: svcs.WebDAV,
406 ServiceNameKeepproxy: svcs.Keepproxy,
407 ServiceNameKeepstore: svcs.Keepstore,