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
60 type WebDAVCacheConfig struct {
63 MaxCollectionEntries int
64 MaxCollectionBytes int64
65 MaxPermissionEntries int
69 ClusterID string `json:"-"`
70 ManagementToken string
71 SystemRootToken string
73 InstanceTypes InstanceTypeMap
74 Containers ContainersConfig
75 RemoteClusters map[string]RemoteCluster
79 AsyncPermissionsUpdateInterval Duration
80 DisabledAPIs StringSet
81 MaxIndexDatabaseRead int
82 MaxItemsPerResponse int
83 MaxRequestAmplification int
85 RailsSessionSecretToken string
86 RequestTimeout Duration
88 WebsocketClientEventQueue int
89 WebsocketServerEventQueue int
94 UnloggedAttributes StringSet
99 BlobSigningTTL Duration
100 CollectionVersioning bool
101 DefaultTrashLifetime Duration
102 DefaultReplication int
103 ManagedProperties map[string]struct {
108 PreserveVersionIfIdle Duration
109 TrashSweepInterval Duration
112 WebDAVCache WebDAVCacheConfig
118 ProviderAppSecret string
122 MailchimpAPIKey string
123 MailchimpListID string
124 SendUserSetupNotificationEmail bool
125 IssueReporterEmailFrom string
126 IssueReporterEmailTo string
127 SupportEmailAddress string
133 MaxRequestLogParamsSize int
141 AnonymousUserToken string
142 AdminNotifierEmailFrom string
143 AutoAdminFirstUser bool
144 AutoAdminUserWithEmail 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
290 LogSecondsBetweenEvents int
291 LogThrottlePeriod Duration
294 LimitLogBytesPerJob int
295 LogPartialLineThrottlePeriod Duration
296 LogUpdatePeriod Duration
297 LogUpdateSize ByteSize
301 SbatchArgumentsList []string
302 SbatchEnvironmentVariables map[string]string
304 DNSServerConfDir string
305 DNSServerConfTemplate string
306 DNSServerReloadCommand string
307 DNSServerUpdateCommand string
308 ComputeNodeDomain string
309 ComputeNodeNameservers StringSet
310 AssignNodeHostname string
315 type CloudVMsConfig struct {
318 BootProbeCommand string
320 MaxCloudOpsPerSecond int
321 MaxProbesPerSecond int
322 PollInterval Duration
323 ProbeInterval Duration
325 SyncInterval Duration
326 TimeoutBooting Duration
328 TimeoutProbe Duration
329 TimeoutShutdown Duration
330 TimeoutSignal Duration
332 ResourceTags map[string]string
336 DriverParameters json.RawMessage
339 type InstanceTypeMap map[string]InstanceType
341 var errDuplicateInstanceTypeName = errors.New("duplicate instance type name")
343 // UnmarshalJSON handles old config files that provide an array of
344 // instance types instead of a hash.
345 func (it *InstanceTypeMap) UnmarshalJSON(data []byte) error {
346 if len(data) > 0 && data[0] == '[' {
347 var arr []InstanceType
348 err := json.Unmarshal(data, &arr)
356 *it = make(map[string]InstanceType, len(arr))
357 for _, t := range arr {
358 if _, ok := (*it)[t.Name]; ok {
359 return errDuplicateInstanceTypeName
361 if t.ProviderType == "" {
362 t.ProviderType = t.Name
365 t.Scratch = t.IncludedScratch + t.AddedScratch
366 } else if t.AddedScratch == 0 {
367 t.AddedScratch = t.Scratch - t.IncludedScratch
368 } else if t.IncludedScratch == 0 {
369 t.IncludedScratch = t.Scratch - t.AddedScratch
372 if t.Scratch != (t.IncludedScratch + t.AddedScratch) {
373 return fmt.Errorf("%v: Scratch != (IncludedScratch + AddedScratch)", t.Name)
379 var hash map[string]InstanceType
380 err := json.Unmarshal(data, &hash)
384 // Fill in Name field (and ProviderType field, if not
385 // specified) using hash key.
386 *it = InstanceTypeMap(hash)
387 for name, t := range *it {
389 if t.ProviderType == "" {
390 t.ProviderType = name
397 type StringSet map[string]struct{}
399 // UnmarshalJSON handles old config files that provide an array of
400 // instance types instead of a hash.
401 func (ss *StringSet) UnmarshalJSON(data []byte) error {
402 if len(data) > 0 && data[0] == '[' {
404 err := json.Unmarshal(data, &arr)
412 *ss = make(map[string]struct{}, len(arr))
413 for _, t := range arr {
414 (*ss)[t] = struct{}{}
418 var hash map[string]struct{}
419 err := json.Unmarshal(data, &hash)
423 *ss = make(map[string]struct{}, len(hash))
424 for t, _ := range hash {
425 (*ss)[t] = struct{}{}
431 type ServiceName string
434 ServiceNameRailsAPI ServiceName = "arvados-api-server"
435 ServiceNameController ServiceName = "arvados-controller"
436 ServiceNameDispatchCloud ServiceName = "arvados-dispatch-cloud"
437 ServiceNameHealth ServiceName = "arvados-health"
438 ServiceNameNodemanager ServiceName = "arvados-node-manager"
439 ServiceNameWorkbench1 ServiceName = "arvados-workbench1"
440 ServiceNameWorkbench2 ServiceName = "arvados-workbench2"
441 ServiceNameWebsocket ServiceName = "arvados-ws"
442 ServiceNameKeepbalance ServiceName = "keep-balance"
443 ServiceNameKeepweb ServiceName = "keep-web"
444 ServiceNameKeepproxy ServiceName = "keepproxy"
445 ServiceNameKeepstore ServiceName = "keepstore"
448 // Map returns all services as a map, suitable for iterating over all
449 // services or looking up a service by name.
450 func (svcs Services) Map() map[ServiceName]Service {
451 return map[ServiceName]Service{
452 ServiceNameRailsAPI: svcs.RailsAPI,
453 ServiceNameController: svcs.Controller,
454 ServiceNameDispatchCloud: svcs.DispatchCloud,
455 ServiceNameHealth: svcs.Health,
456 ServiceNameNodemanager: svcs.Nodemanager,
457 ServiceNameWorkbench1: svcs.Workbench1,
458 ServiceNameWorkbench2: svcs.Workbench2,
459 ServiceNameWebsocket: svcs.Websocket,
460 ServiceNameKeepbalance: svcs.Keepbalance,
461 ServiceNameKeepweb: svcs.WebDAV,
462 ServiceNameKeepproxy: svcs.Keepproxy,
463 ServiceNameKeepstore: svcs.Keepstore,