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 {
64 MaxCollectionEntries int
65 MaxCollectionBytes int64
66 MaxPermissionEntries int
70 ClusterID string `json:"-"`
71 ManagementToken string
72 SystemRootToken string
74 InstanceTypes InstanceTypeMap
75 Containers ContainersConfig
76 RemoteClusters map[string]RemoteCluster
80 AsyncPermissionsUpdateInterval Duration
81 DisabledAPIs StringSet
82 MaxIndexDatabaseRead int
83 MaxItemsPerResponse int
84 MaxRequestAmplification int
86 RailsSessionSecretToken string
87 RequestTimeout Duration
89 WebsocketClientEventQueue int
90 WebsocketServerEventQueue int
91 KeepServiceRequestTimeout Duration
96 UnloggedAttributes StringSet
100 BlobSigningKey string
101 BlobSigningTTL Duration
102 CollectionVersioning bool
103 DefaultTrashLifetime Duration
104 DefaultReplication int
105 ManagedProperties map[string]struct {
110 PreserveVersionIfIdle Duration
111 TrashSweepInterval Duration
114 WebDAVCache WebDAVCacheConfig
120 ProviderAppSecret string
124 MailchimpAPIKey string
125 MailchimpListID string
126 SendUserSetupNotificationEmail bool
127 IssueReporterEmailFrom string
128 IssueReporterEmailTo string
129 SupportEmailAddress string
135 MaxRequestLogParamsSize int
143 AnonymousUserToken string
144 AdminNotifierEmailFrom string
145 AutoAdminFirstUser bool
146 AutoAdminUserWithEmail string
147 AutoSetupNewUsers bool
148 AutoSetupNewUsersWithRepository bool
149 AutoSetupNewUsersWithVmUUID string
150 AutoSetupUsernameBlacklist StringSet
151 EmailSubjectPrefix string
152 NewInactiveUserNotificationRecipients StringSet
153 NewUserNotificationRecipients StringSet
154 NewUsersAreActive bool
155 UserNotifierEmailFrom string
156 UserProfileNotificationAddress string
159 ActivationContactLink string
160 APIClientConnectTimeout Duration
161 APIClientReceiveTimeout Duration
162 APIResponseCompression bool
163 ApplicationMimetypesWithViewIcon StringSet
164 ArvadosDocsite string
165 ArvadosPublicDataDocURL string
166 DefaultOpenIdPrefix string
167 EnableGettingStartedPopup bool
168 EnablePublicProjectsPage bool
169 FileViewersConfigURL string
170 LogViewerMaxBytes ByteSize
171 MultiSiteSearch string
172 ProfilingEnabled bool
174 RepositoryCache string
175 RunningJobLogRecordsToFetch int
177 ShowRecentCollectionsOnDashboard bool
178 ShowUserAgreementInline bool
179 ShowUserNotifications bool
182 UserProfileFormFields map[string]struct {
184 FormFieldTitle string
185 FormFieldDescription string
188 Options map[string]struct{}
190 UserProfileFormMessage string
194 EnableBetaController14287 bool
197 type Services struct {
200 DispatchCloud Service
210 WebDAVDownload Service
218 type Service struct {
219 InternalURLs map[URL]ServiceInstance
223 // URL is a url.URL that is also usable as a JSON key/value.
226 // UnmarshalText implements encoding.TextUnmarshaler so URL can be
227 // used as a JSON key/value.
228 func (su *URL) UnmarshalText(text []byte) error {
229 u, err := url.Parse(string(text))
236 func (su URL) MarshalText() ([]byte, error) {
237 return []byte(fmt.Sprintf("%s", (*url.URL)(&su).String())), nil
240 type ServiceInstance struct{}
242 type PostgreSQL struct {
243 Connection PostgreSQLConnection
247 type PostgreSQLConnection map[string]string
249 type RemoteCluster struct {
257 type InstanceType struct {
263 IncludedScratch ByteSize
264 AddedScratch ByteSize
269 type ContainersConfig struct {
270 CloudVMs CloudVMsConfig
271 CrunchRunCommand string
272 CrunchRunArgumentsList []string
273 DefaultKeepCacheRAM ByteSize
274 DispatchPrivateKey string
275 LogReuseDecisions bool
277 MaxDispatchAttempts int
279 MinRetryPeriod Duration
280 ReserveExtraRAM ByteSize
281 StaleLockTimeout Duration
282 SupportedDockerImageFormats StringSet
283 UsePreemptibleInstances bool
287 GitInternalDir string
292 LogSecondsBetweenEvents int
293 LogThrottlePeriod Duration
296 LimitLogBytesPerJob int
297 LogPartialLineThrottlePeriod Duration
298 LogUpdatePeriod Duration
299 LogUpdateSize ByteSize
303 SbatchArgumentsList []string
304 SbatchEnvironmentVariables map[string]string
306 DNSServerConfDir string
307 DNSServerConfTemplate string
308 DNSServerReloadCommand string
309 DNSServerUpdateCommand string
310 ComputeNodeDomain string
311 ComputeNodeNameservers StringSet
312 AssignNodeHostname string
317 type CloudVMsConfig struct {
320 BootProbeCommand string
322 MaxCloudOpsPerSecond int
323 MaxProbesPerSecond int
324 PollInterval Duration
325 ProbeInterval Duration
327 SyncInterval Duration
328 TimeoutBooting Duration
330 TimeoutProbe Duration
331 TimeoutShutdown Duration
332 TimeoutSignal Duration
334 ResourceTags map[string]string
338 DriverParameters json.RawMessage
341 type InstanceTypeMap map[string]InstanceType
343 var errDuplicateInstanceTypeName = errors.New("duplicate instance type name")
345 // UnmarshalJSON handles old config files that provide an array of
346 // instance types instead of a hash.
347 func (it *InstanceTypeMap) UnmarshalJSON(data []byte) error {
348 if len(data) > 0 && data[0] == '[' {
349 var arr []InstanceType
350 err := json.Unmarshal(data, &arr)
358 *it = make(map[string]InstanceType, len(arr))
359 for _, t := range arr {
360 if _, ok := (*it)[t.Name]; ok {
361 return errDuplicateInstanceTypeName
363 if t.ProviderType == "" {
364 t.ProviderType = t.Name
367 t.Scratch = t.IncludedScratch + t.AddedScratch
368 } else if t.AddedScratch == 0 {
369 t.AddedScratch = t.Scratch - t.IncludedScratch
370 } else if t.IncludedScratch == 0 {
371 t.IncludedScratch = t.Scratch - t.AddedScratch
374 if t.Scratch != (t.IncludedScratch + t.AddedScratch) {
375 return fmt.Errorf("%v: Scratch != (IncludedScratch + AddedScratch)", t.Name)
381 var hash map[string]InstanceType
382 err := json.Unmarshal(data, &hash)
386 // Fill in Name field (and ProviderType field, if not
387 // specified) using hash key.
388 *it = InstanceTypeMap(hash)
389 for name, t := range *it {
391 if t.ProviderType == "" {
392 t.ProviderType = name
399 type StringSet map[string]struct{}
401 // UnmarshalJSON handles old config files that provide an array of
402 // instance types instead of a hash.
403 func (ss *StringSet) UnmarshalJSON(data []byte) error {
404 if len(data) > 0 && data[0] == '[' {
406 err := json.Unmarshal(data, &arr)
414 *ss = make(map[string]struct{}, len(arr))
415 for _, t := range arr {
416 (*ss)[t] = struct{}{}
420 var hash map[string]struct{}
421 err := json.Unmarshal(data, &hash)
425 *ss = make(map[string]struct{}, len(hash))
426 for t, _ := range hash {
427 (*ss)[t] = struct{}{}
433 type ServiceName string
436 ServiceNameRailsAPI ServiceName = "arvados-api-server"
437 ServiceNameController ServiceName = "arvados-controller"
438 ServiceNameDispatchCloud ServiceName = "arvados-dispatch-cloud"
439 ServiceNameHealth ServiceName = "arvados-health"
440 ServiceNameNodemanager ServiceName = "arvados-node-manager"
441 ServiceNameWorkbench1 ServiceName = "arvados-workbench1"
442 ServiceNameWorkbench2 ServiceName = "arvados-workbench2"
443 ServiceNameWebsocket ServiceName = "arvados-ws"
444 ServiceNameKeepbalance ServiceName = "keep-balance"
445 ServiceNameKeepweb ServiceName = "keep-web"
446 ServiceNameKeepproxy ServiceName = "keepproxy"
447 ServiceNameKeepstore ServiceName = "keepstore"
450 // Map returns all services as a map, suitable for iterating over all
451 // services or looking up a service by name.
452 func (svcs Services) Map() map[ServiceName]Service {
453 return map[ServiceName]Service{
454 ServiceNameRailsAPI: svcs.RailsAPI,
455 ServiceNameController: svcs.Controller,
456 ServiceNameDispatchCloud: svcs.DispatchCloud,
457 ServiceNameHealth: svcs.Health,
458 ServiceNameNodemanager: svcs.Nodemanager,
459 ServiceNameWorkbench1: svcs.Workbench1,
460 ServiceNameWorkbench2: svcs.Workbench2,
461 ServiceNameWebsocket: svcs.Websocket,
462 ServiceNameKeepbalance: svcs.Keepbalance,
463 ServiceNameKeepweb: svcs.WebDAV,
464 ServiceNameKeepproxy: svcs.Keepproxy,
465 ServiceNameKeepstore: svcs.Keepstore,