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
72 DisabledAPIs StringSet
73 MaxIndexDatabaseRead int
74 MaxItemsPerResponse int
75 MaxRequestAmplification int
77 RailsSessionSecretToken string
78 RequestTimeout Duration
80 WebsocketClientEventQueue int
81 WebsocketServerEventQueue int
86 UnloggedAttributes StringSet
91 BlobSigningTTL Duration
92 CollectionVersioning bool
93 DefaultTrashLifetime Duration
94 DefaultReplication int
95 ManagedProperties map[string]struct {
100 PreserveVersionIfIdle Duration
101 TrashSweepInterval Duration
107 MaxCollectionEntries int
108 MaxCollectionBytes int64
109 MaxPermissionEntries int
117 ProviderAppSecret string
121 MailchimpAPIKey string
122 MailchimpListID string
123 SendUserSetupNotificationEmail bool
124 IssueReporterEmailFrom string
125 IssueReporterEmailTo string
126 SupportEmailAddress string
132 MaxRequestLogParamsSize int
140 AnonymousUserToken string
141 AdminNotifierEmailFrom string
142 AutoAdminFirstUser bool
143 AutoAdminUserWithEmail string
144 AnonymousUserToken string
145 AutoSetupNewUsers bool
146 AutoSetupNewUsersWithRepository bool
147 AutoSetupNewUsersWithVmUUID string
148 AutoSetupUsernameBlacklist StringSet
149 EmailSubjectPrefix string
150 NewInactiveUserNotificationRecipients StringSet
151 NewUserNotificationRecipients StringSet
152 NewUsersAreActive bool
153 UserNotifierEmailFrom string
154 UserProfileNotificationAddress string
157 ActivationContactLink string
158 APIClientConnectTimeout Duration
159 APIClientReceiveTimeout Duration
160 APIResponseCompression bool
161 ApplicationMimetypesWithViewIcon StringSet
162 ArvadosDocsite string
163 ArvadosPublicDataDocURL string
164 DefaultOpenIdPrefix string
165 EnableGettingStartedPopup bool
166 EnablePublicProjectsPage bool
167 FileViewersConfigURL string
168 LogViewerMaxBytes ByteSize
169 MultiSiteSearch string
170 ProfilingEnabled bool
172 RepositoryCache string
173 RunningJobLogRecordsToFetch int
175 ShowRecentCollectionsOnDashboard bool
176 ShowUserAgreementInline bool
177 ShowUserNotifications bool
180 UserProfileFormFields map[string]struct {
182 FormFieldTitle string
183 FormFieldDescription string
186 Options map[string]struct{}
188 UserProfileFormMessage string
192 EnableBetaController14287 bool
195 type Services struct {
198 DispatchCloud Service
208 WebDAVDownload Service
216 type Service struct {
217 InternalURLs map[URL]ServiceInstance
221 // URL is a url.URL that is also usable as a JSON key/value.
224 // UnmarshalText implements encoding.TextUnmarshaler so URL can be
225 // used as a JSON key/value.
226 func (su *URL) UnmarshalText(text []byte) error {
227 u, err := url.Parse(string(text))
234 func (su URL) MarshalText() ([]byte, error) {
235 return []byte(fmt.Sprintf("%s", (*url.URL)(&su).String())), nil
238 type ServiceInstance struct{}
240 type PostgreSQL struct {
241 Connection PostgreSQLConnection
245 type PostgreSQLConnection map[string]string
247 type RemoteCluster struct {
255 type InstanceType struct {
261 IncludedScratch ByteSize
262 AddedScratch ByteSize
267 type ContainersConfig struct {
268 CloudVMs CloudVMsConfig
269 CrunchRunCommand string
270 CrunchRunArgumentsList []string
271 DefaultKeepCacheRAM ByteSize
272 DispatchPrivateKey string
273 LogReuseDecisions bool
275 MaxDispatchAttempts int
277 MinRetryPeriod Duration
278 ReserveExtraRAM ByteSize
279 StaleLockTimeout Duration
280 SupportedDockerImageFormats StringSet
281 UsePreemptibleInstances bool
285 GitInternalDir string
286 DefaultDockerImage string
287 CrunchJobWrapper string
289 CrunchRefreshTrigger string
290 ReuseJobIfOutputsDiffer bool
295 LogSecondsBetweenEvents int
296 LogThrottlePeriod Duration
299 LimitLogBytesPerJob int
300 LogPartialLineThrottlePeriod Duration
301 LogUpdatePeriod Duration
302 LogUpdateSize ByteSize
306 SbatchArgumentsList []string
308 DNSServerConfDir string
309 DNSServerConfTemplate string
310 DNSServerReloadCommand string
311 DNSServerUpdateCommand string
312 ComputeNodeDomain string
313 ComputeNodeNameservers StringSet
314 AssignNodeHostname string
319 type CloudVMsConfig struct {
322 BootProbeCommand string
324 MaxCloudOpsPerSecond int
325 MaxProbesPerSecond int
326 PollInterval Duration
327 ProbeInterval Duration
329 SyncInterval Duration
330 TimeoutBooting Duration
332 TimeoutProbe Duration
333 TimeoutShutdown Duration
334 TimeoutSignal Duration
336 ResourceTags map[string]string
340 DriverParameters json.RawMessage
343 type InstanceTypeMap map[string]InstanceType
345 var errDuplicateInstanceTypeName = errors.New("duplicate instance type name")
347 // UnmarshalJSON handles old config files that provide an array of
348 // instance types instead of a hash.
349 func (it *InstanceTypeMap) UnmarshalJSON(data []byte) error {
350 if len(data) > 0 && data[0] == '[' {
351 var arr []InstanceType
352 err := json.Unmarshal(data, &arr)
360 *it = make(map[string]InstanceType, len(arr))
361 for _, t := range arr {
362 if _, ok := (*it)[t.Name]; ok {
363 return errDuplicateInstanceTypeName
365 if t.ProviderType == "" {
366 t.ProviderType = t.Name
369 t.Scratch = t.IncludedScratch + t.AddedScratch
370 } else if t.AddedScratch == 0 {
371 t.AddedScratch = t.Scratch - t.IncludedScratch
372 } else if t.IncludedScratch == 0 {
373 t.IncludedScratch = t.Scratch - t.AddedScratch
376 if t.Scratch != (t.IncludedScratch + t.AddedScratch) {
377 return fmt.Errorf("%v: Scratch != (IncludedScratch + AddedScratch)", t.Name)
383 var hash map[string]InstanceType
384 err := json.Unmarshal(data, &hash)
388 // Fill in Name field (and ProviderType field, if not
389 // specified) using hash key.
390 *it = InstanceTypeMap(hash)
391 for name, t := range *it {
393 if t.ProviderType == "" {
394 t.ProviderType = name
401 type StringSet map[string]struct{}
403 // UnmarshalJSON handles old config files that provide an array of
404 // instance types instead of a hash.
405 func (ss *StringSet) UnmarshalJSON(data []byte) error {
406 if len(data) > 0 && data[0] == '[' {
408 err := json.Unmarshal(data, &arr)
416 *ss = make(map[string]struct{}, len(arr))
417 for _, t := range arr {
418 (*ss)[t] = struct{}{}
422 var hash map[string]struct{}
423 err := json.Unmarshal(data, &hash)
427 *ss = make(map[string]struct{}, len(hash))
428 for t, _ := range hash {
429 (*ss)[t] = struct{}{}
435 type ServiceName string
438 ServiceNameRailsAPI ServiceName = "arvados-api-server"
439 ServiceNameController ServiceName = "arvados-controller"
440 ServiceNameDispatchCloud ServiceName = "arvados-dispatch-cloud"
441 ServiceNameHealth ServiceName = "arvados-health"
442 ServiceNameNodemanager ServiceName = "arvados-node-manager"
443 ServiceNameWorkbench1 ServiceName = "arvados-workbench1"
444 ServiceNameWorkbench2 ServiceName = "arvados-workbench2"
445 ServiceNameWebsocket ServiceName = "arvados-ws"
446 ServiceNameKeepbalance ServiceName = "keep-balance"
447 ServiceNameKeepweb ServiceName = "keep-web"
448 ServiceNameKeepproxy ServiceName = "keepproxy"
449 ServiceNameKeepstore ServiceName = "keepstore"
452 // Map returns all services as a map, suitable for iterating over all
453 // services or looking up a service by name.
454 func (svcs Services) Map() map[ServiceName]Service {
455 return map[ServiceName]Service{
456 ServiceNameRailsAPI: svcs.RailsAPI,
457 ServiceNameController: svcs.Controller,
458 ServiceNameDispatchCloud: svcs.DispatchCloud,
459 ServiceNameHealth: svcs.Health,
460 ServiceNameNodemanager: svcs.Nodemanager,
461 ServiceNameWorkbench1: svcs.Workbench1,
462 ServiceNameWorkbench2: svcs.Workbench2,
463 ServiceNameWebsocket: svcs.Websocket,
464 ServiceNameKeepbalance: svcs.Keepbalance,
465 ServiceNameKeepweb: svcs.WebDAV,
466 ServiceNameKeepproxy: svcs.Keepproxy,
467 ServiceNameKeepstore: svcs.Keepstore,