1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: Apache-2.0
14 "git.curoverse.com/arvados.git/sdk/go/config"
17 var DefaultConfigFile = func() string {
18 if path := os.Getenv("ARVADOS_CONFIG"); path != "" {
21 return "/etc/arvados/config.yml"
26 Clusters map[string]Cluster
29 // GetConfig returns the current system config, loading it from
30 // configFile if needed.
31 func GetConfig(configFile string) (*Config, error) {
33 err := config.LoadFile(&cfg, configFile)
37 // GetCluster returns the cluster ID and config for the given
38 // cluster, or the default/only configured cluster if clusterID is "".
39 func (sc *Config) GetCluster(clusterID string) (*Cluster, error) {
41 if len(sc.Clusters) == 0 {
42 return nil, fmt.Errorf("no clusters configured")
43 } else if len(sc.Clusters) > 1 {
44 return nil, fmt.Errorf("multiple clusters configured, cannot choose")
46 for id, cc := range sc.Clusters {
52 if cc, ok := sc.Clusters[clusterID]; !ok {
53 return nil, fmt.Errorf("cluster %q is not configured", clusterID)
55 cc.ClusterID = clusterID
61 ClusterID string `json:"-"`
62 ManagementToken string
63 SystemRootToken string
65 InstanceTypes InstanceTypeMap
66 Containers ContainersConfig
67 RemoteClusters map[string]RemoteCluster
71 AsyncPermissionsUpdateInterval Duration
73 MaxIndexDatabaseRead int
74 MaxItemsPerResponse int
75 MaxRequestAmplification int
77 RailsSessionSecretToken string
78 RequestTimeout Duration
83 UnloggedAttributes []string
88 BlobSigningTTL Duration
89 CollectionVersioning bool
90 DefaultTrashLifetime Duration
91 DefaultReplication int
92 ManagedProperties map[string]struct {
97 PreserveVersionIfIdle Duration
98 TrashSweepInterval Duration
105 ProviderAppSecret string
109 MailchimpAPIKey string
110 MailchimpListID string
111 SendUserSetupNotificationEmail bool
112 IssueReporterEmailFrom string
113 IssueReporterEmailTo string
114 SupportEmailAddress string
120 MaxRequestLogParamsSize int
128 AnonymousUserToken string
129 AdminNotifierEmailFrom string
130 AutoAdminFirstUser bool
131 AutoAdminUserWithEmail string
132 AutoSetupNewUsers bool
133 AutoSetupNewUsersWithRepository bool
134 AutoSetupNewUsersWithVmUUID string
135 AutoSetupUsernameBlacklist []string
136 EmailSubjectPrefix string
137 NewInactiveUserNotificationRecipients []string
138 NewUserNotificationRecipients []string
139 NewUsersAreActive bool
140 UserNotifierEmailFrom string
141 UserProfileNotificationAddress string
144 ActivationContactLink string
145 APIClientConnectTimeout Duration
146 APIClientReceiveTimeout Duration
147 APIResponseCompression bool
148 ApplicationMimetypesWithViewIcon map[string]struct{}
149 ArvadosDocsite string
150 ArvadosPublicDataDocURL string
151 DefaultOpenIdPrefix string
152 EnableGettingStartedPopup bool
153 EnablePublicProjectsPage bool
154 FileViewersConfigURL string
155 LogViewerMaxBytes ByteSize
156 MultiSiteSearch string
157 ProfilingEnabled bool
159 RepositoryCache string
160 RunningJobLogRecordsToFetch int
162 ShowRecentCollectionsOnDashboard bool
163 ShowUserAgreementInline bool
164 ShowUserNotifications bool
167 UserProfileFormFields map[string]struct {
169 FormFieldTitle string
170 FormFieldDescription string
173 Options map[string]struct{}
175 UserProfileFormMessage string
179 EnableBetaController14287 bool
182 type Services struct {
185 DispatchCloud Service
195 WebDAVDownload Service
203 type Service struct {
204 InternalURLs map[URL]ServiceInstance
208 // URL is a url.URL that is also usable as a JSON key/value.
211 // UnmarshalText implements encoding.TextUnmarshaler so URL can be
212 // used as a JSON key/value.
213 func (su *URL) UnmarshalText(text []byte) error {
214 u, err := url.Parse(string(text))
221 func (su URL) MarshalText() ([]byte, error) {
222 return []byte(fmt.Sprintf("%s", (*url.URL)(&su).String())), nil
225 type ServiceInstance struct{}
227 type PostgreSQL struct {
228 Connection PostgreSQLConnection
232 type PostgreSQLConnection map[string]string
234 type RemoteCluster struct {
242 type InstanceType struct {
248 IncludedScratch ByteSize
249 AddedScratch ByteSize
254 type ContainersConfig struct {
255 CloudVMs CloudVMsConfig
256 DefaultKeepCacheRAM ByteSize
257 DispatchPrivateKey string
258 LogReuseDecisions bool
260 MaxDispatchAttempts int
262 StaleLockTimeout Duration
263 SupportedDockerImageFormats []string
264 UsePreemptibleInstances bool
268 GitInternalDir string
269 DefaultDockerImage string
270 CrunchJobWrapper string
272 CrunchRefreshTrigger string
273 ReuseJobIfOutputsDiffer bool
278 LogSecondsBetweenEvents int
279 LogThrottlePeriod Duration
282 LimitLogBytesPerJob int
283 LogPartialLineThrottlePeriod Duration
284 LogUpdatePeriod Duration
285 LogUpdateSize ByteSize
289 DNSServerConfDir string
290 DNSServerConfTemplate string
291 DNSServerReloadCommand string
292 DNSServerUpdateCommand string
293 ComputeNodeDomain string
294 ComputeNodeNameservers []string
295 AssignNodeHostname string
300 type CloudVMsConfig struct {
303 BootProbeCommand string
305 MaxCloudOpsPerSecond int
306 MaxProbesPerSecond int
307 PollInterval Duration
308 ProbeInterval Duration
310 SyncInterval Duration
311 TimeoutBooting Duration
313 TimeoutProbe Duration
314 TimeoutShutdown Duration
315 TimeoutSignal Duration
317 ResourceTags map[string]string
321 DriverParameters json.RawMessage
324 type InstanceTypeMap map[string]InstanceType
326 var errDuplicateInstanceTypeName = errors.New("duplicate instance type name")
328 // UnmarshalJSON handles old config files that provide an array of
329 // instance types instead of a hash.
330 func (it *InstanceTypeMap) UnmarshalJSON(data []byte) error {
331 if len(data) > 0 && data[0] == '[' {
332 var arr []InstanceType
333 err := json.Unmarshal(data, &arr)
341 *it = make(map[string]InstanceType, len(arr))
342 for _, t := range arr {
343 if _, ok := (*it)[t.Name]; ok {
344 return errDuplicateInstanceTypeName
346 if t.ProviderType == "" {
347 t.ProviderType = t.Name
350 t.Scratch = t.IncludedScratch + t.AddedScratch
351 } else if t.AddedScratch == 0 {
352 t.AddedScratch = t.Scratch - t.IncludedScratch
353 } else if t.IncludedScratch == 0 {
354 t.IncludedScratch = t.Scratch - t.AddedScratch
357 if t.Scratch != (t.IncludedScratch + t.AddedScratch) {
358 return fmt.Errorf("%v: Scratch != (IncludedScratch + AddedScratch)", t.Name)
364 var hash map[string]InstanceType
365 err := json.Unmarshal(data, &hash)
369 // Fill in Name field (and ProviderType field, if not
370 // specified) using hash key.
371 *it = InstanceTypeMap(hash)
372 for name, t := range *it {
374 if t.ProviderType == "" {
375 t.ProviderType = name
382 type ServiceName string
385 ServiceNameRailsAPI ServiceName = "arvados-api-server"
386 ServiceNameController ServiceName = "arvados-controller"
387 ServiceNameDispatchCloud ServiceName = "arvados-dispatch-cloud"
388 ServiceNameHealth ServiceName = "arvados-health"
389 ServiceNameNodemanager ServiceName = "arvados-node-manager"
390 ServiceNameWorkbench1 ServiceName = "arvados-workbench1"
391 ServiceNameWorkbench2 ServiceName = "arvados-workbench2"
392 ServiceNameWebsocket ServiceName = "arvados-ws"
393 ServiceNameKeepbalance ServiceName = "keep-balance"
394 ServiceNameKeepweb ServiceName = "keep-web"
395 ServiceNameKeepproxy ServiceName = "keepproxy"
396 ServiceNameKeepstore ServiceName = "keepstore"
399 // Map returns all services as a map, suitable for iterating over all
400 // services or looking up a service by name.
401 func (svcs Services) Map() map[ServiceName]Service {
402 return map[ServiceName]Service{
403 ServiceNameRailsAPI: svcs.RailsAPI,
404 ServiceNameController: svcs.Controller,
405 ServiceNameDispatchCloud: svcs.DispatchCloud,
406 ServiceNameHealth: svcs.Health,
407 ServiceNameNodemanager: svcs.Nodemanager,
408 ServiceNameWorkbench1: svcs.Workbench1,
409 ServiceNameWorkbench2: svcs.Workbench2,
410 ServiceNameWebsocket: svcs.Websocket,
411 ServiceNameKeepbalance: svcs.Keepbalance,
412 ServiceNameKeepweb: svcs.WebDAV,
413 ServiceNameKeepproxy: svcs.Keepproxy,
414 ServiceNameKeepstore: svcs.Keepstore,