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 AnonymousUserToken string
146 AutoSetupNewUsers bool
147 AutoSetupNewUsersWithRepository bool
148 AutoSetupNewUsersWithVmUUID string
149 AutoSetupUsernameBlacklist StringSet
150 EmailSubjectPrefix string
151 NewInactiveUserNotificationRecipients StringSet
152 NewUserNotificationRecipients StringSet
153 NewUsersAreActive bool
154 UserNotifierEmailFrom string
155 UserProfileNotificationAddress string
158 ActivationContactLink string
159 APIClientConnectTimeout Duration
160 APIClientReceiveTimeout Duration
161 APIResponseCompression bool
162 ApplicationMimetypesWithViewIcon StringSet
163 ArvadosDocsite string
164 ArvadosPublicDataDocURL string
165 DefaultOpenIdPrefix string
166 EnableGettingStartedPopup bool
167 EnablePublicProjectsPage bool
168 FileViewersConfigURL string
169 LogViewerMaxBytes ByteSize
170 MultiSiteSearch string
171 ProfilingEnabled bool
173 RepositoryCache string
174 RunningJobLogRecordsToFetch int
176 ShowRecentCollectionsOnDashboard bool
177 ShowUserAgreementInline bool
178 ShowUserNotifications bool
181 UserProfileFormFields map[string]struct {
183 FormFieldTitle string
184 FormFieldDescription string
187 Options map[string]struct{}
189 UserProfileFormMessage string
193 EnableBetaController14287 bool
196 type Services struct {
199 DispatchCloud Service
209 WebDAVDownload Service
217 type Service struct {
218 InternalURLs map[URL]ServiceInstance
222 // URL is a url.URL that is also usable as a JSON key/value.
225 // UnmarshalText implements encoding.TextUnmarshaler so URL can be
226 // used as a JSON key/value.
227 func (su *URL) UnmarshalText(text []byte) error {
228 u, err := url.Parse(string(text))
235 func (su URL) MarshalText() ([]byte, error) {
236 return []byte(fmt.Sprintf("%s", (*url.URL)(&su).String())), nil
239 type ServiceInstance struct{}
241 type PostgreSQL struct {
242 Connection PostgreSQLConnection
246 type PostgreSQLConnection map[string]string
248 type RemoteCluster struct {
256 type InstanceType struct {
262 IncludedScratch ByteSize
263 AddedScratch ByteSize
268 type ContainersConfig struct {
269 CloudVMs CloudVMsConfig
270 CrunchRunCommand string
271 CrunchRunArgumentsList []string
272 DefaultKeepCacheRAM ByteSize
273 DispatchPrivateKey string
274 LogReuseDecisions bool
276 MaxDispatchAttempts int
278 MinRetryPeriod Duration
279 ReserveExtraRAM ByteSize
280 StaleLockTimeout Duration
281 SupportedDockerImageFormats StringSet
282 UsePreemptibleInstances bool
286 GitInternalDir string
287 DefaultDockerImage string
288 CrunchJobWrapper string
290 CrunchRefreshTrigger string
291 ReuseJobIfOutputsDiffer bool
296 LogSecondsBetweenEvents int
297 LogThrottlePeriod Duration
300 LimitLogBytesPerJob int
301 LogPartialLineThrottlePeriod Duration
302 LogUpdatePeriod Duration
303 LogUpdateSize ByteSize
307 SbatchArgumentsList []string
309 DNSServerConfDir string
310 DNSServerConfTemplate string
311 DNSServerReloadCommand string
312 DNSServerUpdateCommand string
313 ComputeNodeDomain string
314 ComputeNodeNameservers StringSet
315 AssignNodeHostname string
320 type CloudVMsConfig struct {
323 BootProbeCommand string
325 MaxCloudOpsPerSecond int
326 MaxProbesPerSecond int
327 PollInterval Duration
328 ProbeInterval Duration
330 SyncInterval Duration
331 TimeoutBooting Duration
333 TimeoutProbe Duration
334 TimeoutShutdown Duration
335 TimeoutSignal Duration
337 ResourceTags map[string]string
341 DriverParameters json.RawMessage
344 type InstanceTypeMap map[string]InstanceType
346 var errDuplicateInstanceTypeName = errors.New("duplicate instance type name")
348 // UnmarshalJSON handles old config files that provide an array of
349 // instance types instead of a hash.
350 func (it *InstanceTypeMap) UnmarshalJSON(data []byte) error {
351 if len(data) > 0 && data[0] == '[' {
352 var arr []InstanceType
353 err := json.Unmarshal(data, &arr)
361 *it = make(map[string]InstanceType, len(arr))
362 for _, t := range arr {
363 if _, ok := (*it)[t.Name]; ok {
364 return errDuplicateInstanceTypeName
366 if t.ProviderType == "" {
367 t.ProviderType = t.Name
370 t.Scratch = t.IncludedScratch + t.AddedScratch
371 } else if t.AddedScratch == 0 {
372 t.AddedScratch = t.Scratch - t.IncludedScratch
373 } else if t.IncludedScratch == 0 {
374 t.IncludedScratch = t.Scratch - t.AddedScratch
377 if t.Scratch != (t.IncludedScratch + t.AddedScratch) {
378 return fmt.Errorf("%v: Scratch != (IncludedScratch + AddedScratch)", t.Name)
384 var hash map[string]InstanceType
385 err := json.Unmarshal(data, &hash)
389 // Fill in Name field (and ProviderType field, if not
390 // specified) using hash key.
391 *it = InstanceTypeMap(hash)
392 for name, t := range *it {
394 if t.ProviderType == "" {
395 t.ProviderType = name
402 type StringSet map[string]struct{}
404 // UnmarshalJSON handles old config files that provide an array of
405 // instance types instead of a hash.
406 func (ss *StringSet) UnmarshalJSON(data []byte) error {
407 if len(data) > 0 && data[0] == '[' {
409 err := json.Unmarshal(data, &arr)
417 *ss = make(map[string]struct{}, len(arr))
418 for _, t := range arr {
419 (*ss)[t] = struct{}{}
423 var hash map[string]struct{}
424 err := json.Unmarshal(data, &hash)
428 *ss = make(map[string]struct{}, len(hash))
429 for t, _ := range hash {
430 (*ss)[t] = struct{}{}
436 type ServiceName string
439 ServiceNameRailsAPI ServiceName = "arvados-api-server"
440 ServiceNameController ServiceName = "arvados-controller"
441 ServiceNameDispatchCloud ServiceName = "arvados-dispatch-cloud"
442 ServiceNameHealth ServiceName = "arvados-health"
443 ServiceNameNodemanager ServiceName = "arvados-node-manager"
444 ServiceNameWorkbench1 ServiceName = "arvados-workbench1"
445 ServiceNameWorkbench2 ServiceName = "arvados-workbench2"
446 ServiceNameWebsocket ServiceName = "arvados-ws"
447 ServiceNameKeepbalance ServiceName = "keep-balance"
448 ServiceNameKeepweb ServiceName = "keep-web"
449 ServiceNameKeepproxy ServiceName = "keepproxy"
450 ServiceNameKeepstore ServiceName = "keepstore"
453 // Map returns all services as a map, suitable for iterating over all
454 // services or looking up a service by name.
455 func (svcs Services) Map() map[ServiceName]Service {
456 return map[ServiceName]Service{
457 ServiceNameRailsAPI: svcs.RailsAPI,
458 ServiceNameController: svcs.Controller,
459 ServiceNameDispatchCloud: svcs.DispatchCloud,
460 ServiceNameHealth: svcs.Health,
461 ServiceNameNodemanager: svcs.Nodemanager,
462 ServiceNameWorkbench1: svcs.Workbench1,
463 ServiceNameWorkbench2: svcs.Workbench2,
464 ServiceNameWebsocket: svcs.Websocket,
465 ServiceNameKeepbalance: svcs.Keepbalance,
466 ServiceNameKeepweb: svcs.WebDAV,
467 ServiceNameKeepproxy: svcs.Keepproxy,
468 ServiceNameKeepstore: svcs.Keepstore,