Merge branch '18051-blob-signing'
[arvados.git] / lib / config / deprecated.go
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 package config
6
7 import (
8         "encoding/json"
9         "fmt"
10         "io/ioutil"
11         "net/url"
12         "os"
13         "strings"
14
15         "git.arvados.org/arvados.git/sdk/go/arvados"
16         "github.com/ghodss/yaml"
17 )
18
19 type deprRequestLimits struct {
20         MaxItemsPerResponse            *int
21         MultiClusterRequestConcurrency *int
22 }
23
24 type deprCluster struct {
25         RequestLimits deprRequestLimits
26         NodeProfiles  map[string]nodeProfile
27         Login         struct {
28                 GoogleClientID                *string
29                 GoogleClientSecret            *string
30                 GoogleAlternateEmailAddresses *bool
31                 ProviderAppID                 *string
32                 ProviderAppSecret             *string
33         }
34 }
35
36 type deprecatedConfig struct {
37         Clusters map[string]deprCluster
38 }
39
40 type nodeProfile struct {
41         Controller    systemServiceInstance `json:"arvados-controller"`
42         Health        systemServiceInstance `json:"arvados-health"`
43         Keepbalance   systemServiceInstance `json:"keep-balance"`
44         Keepproxy     systemServiceInstance `json:"keepproxy"`
45         Keepstore     systemServiceInstance `json:"keepstore"`
46         Keepweb       systemServiceInstance `json:"keep-web"`
47         DispatchCloud systemServiceInstance `json:"arvados-dispatch-cloud"`
48         RailsAPI      systemServiceInstance `json:"arvados-api-server"`
49         Websocket     systemServiceInstance `json:"arvados-ws"`
50         Workbench1    systemServiceInstance `json:"arvados-workbench"`
51 }
52
53 type systemServiceInstance struct {
54         Listen   string
55         TLS      bool
56         Insecure bool
57 }
58
59 func (ldr *Loader) applyDeprecatedConfig(cfg *arvados.Config) error {
60         var dc deprecatedConfig
61         err := yaml.Unmarshal(ldr.configdata, &dc)
62         if err != nil {
63                 return err
64         }
65         hostname, err := os.Hostname()
66         if err != nil {
67                 return err
68         }
69         for id, dcluster := range dc.Clusters {
70                 cluster, ok := cfg.Clusters[id]
71                 if !ok {
72                         return fmt.Errorf("can't load legacy config %q that is not present in current config", id)
73                 }
74                 for name, np := range dcluster.NodeProfiles {
75                         if name == "*" || name == os.Getenv("ARVADOS_NODE_PROFILE") || name == hostname {
76                                 name = "localhost"
77                         } else if ldr.Logger != nil {
78                                 ldr.Logger.Warnf("overriding Clusters.%s.Services using Clusters.%s.NodeProfiles.%s (guessing %q is a hostname)", id, id, name, name)
79                         }
80                         applyDeprecatedNodeProfile(name, np.RailsAPI, &cluster.Services.RailsAPI)
81                         applyDeprecatedNodeProfile(name, np.Controller, &cluster.Services.Controller)
82                         applyDeprecatedNodeProfile(name, np.DispatchCloud, &cluster.Services.DispatchCloud)
83                 }
84                 if dst, n := &cluster.API.MaxItemsPerResponse, dcluster.RequestLimits.MaxItemsPerResponse; n != nil && *n != *dst {
85                         *dst = *n
86                 }
87                 if dst, n := &cluster.API.MaxRequestAmplification, dcluster.RequestLimits.MultiClusterRequestConcurrency; n != nil && *n != *dst {
88                         *dst = *n
89                 }
90
91                 // Google* moved to Google.*
92                 if dst, n := &cluster.Login.Google.ClientID, dcluster.Login.GoogleClientID; n != nil && *n != *dst {
93                         *dst = *n
94                         if *n != "" {
95                                 // In old config, non-empty ClientID meant enable
96                                 cluster.Login.Google.Enable = true
97                         }
98                 }
99                 if dst, n := &cluster.Login.Google.ClientSecret, dcluster.Login.GoogleClientSecret; n != nil && *n != *dst {
100                         *dst = *n
101                 }
102                 if dst, n := &cluster.Login.Google.AlternateEmailAddresses, dcluster.Login.GoogleAlternateEmailAddresses; n != nil && *n != *dst {
103                         *dst = *n
104                 }
105
106                 cfg.Clusters[id] = cluster
107         }
108         return nil
109 }
110
111 func (ldr *Loader) applyDeprecatedVolumeDriverParameters(cfg *arvados.Config) error {
112         for clusterID, cluster := range cfg.Clusters {
113                 for volID, vol := range cluster.Volumes {
114                         if vol.Driver == "S3" {
115                                 var params struct {
116                                         AccessKey       string `json:",omitempty"`
117                                         SecretKey       string `json:",omitempty"`
118                                         AccessKeyID     string
119                                         SecretAccessKey string
120                                 }
121                                 err := json.Unmarshal(vol.DriverParameters, &params)
122                                 if err != nil {
123                                         return fmt.Errorf("error loading %s.Volumes.%s.DriverParameters: %w", clusterID, volID, err)
124                                 }
125                                 if params.AccessKey != "" || params.SecretKey != "" {
126                                         if params.AccessKeyID != "" || params.SecretAccessKey != "" {
127                                                 return fmt.Errorf("cannot use old keys (AccessKey/SecretKey) and new keys (AccessKeyID/SecretAccessKey) at the same time in %s.Volumes.%s.DriverParameters -- you must remove the old config keys", clusterID, volID)
128                                                 continue
129                                         }
130                                         var allparams map[string]interface{}
131                                         err = json.Unmarshal(vol.DriverParameters, &allparams)
132                                         if err != nil {
133                                                 return fmt.Errorf("error loading %s.Volumes.%s.DriverParameters: %w", clusterID, volID, err)
134                                         }
135                                         for k := range allparams {
136                                                 if lk := strings.ToLower(k); lk == "accesskey" || lk == "secretkey" {
137                                                         delete(allparams, k)
138                                                 }
139                                         }
140                                         ldr.Logger.Warnf("using your old config keys %s.Volumes.%s.DriverParameters.AccessKey/SecretKey -- but you should rename them to AccessKeyID/SecretAccessKey", clusterID, volID)
141                                         allparams["AccessKeyID"] = params.AccessKey
142                                         allparams["SecretAccessKey"] = params.SecretKey
143                                         vol.DriverParameters, err = json.Marshal(allparams)
144                                         if err != nil {
145                                                 return err
146                                         }
147                                         cluster.Volumes[volID] = vol
148                                 }
149                         }
150                 }
151         }
152         return nil
153 }
154
155 func applyDeprecatedNodeProfile(hostname string, ssi systemServiceInstance, svc *arvados.Service) {
156         scheme := "https"
157         if !ssi.TLS {
158                 scheme = "http"
159         }
160         if svc.InternalURLs == nil {
161                 svc.InternalURLs = map[arvados.URL]arvados.ServiceInstance{}
162         }
163         host := ssi.Listen
164         if host == "" {
165                 return
166         }
167         if strings.HasPrefix(host, ":") {
168                 host = hostname + host
169         }
170         svc.InternalURLs[arvados.URL{Scheme: scheme, Host: host, Path: "/"}] = arvados.ServiceInstance{}
171 }
172
173 func (ldr *Loader) loadOldConfigHelper(component, path string, target interface{}) error {
174         if path == "" {
175                 return nil
176         }
177         buf, err := ioutil.ReadFile(path)
178         if err != nil {
179                 return err
180         }
181
182         ldr.Logger.Warnf("you should remove the legacy %v config file (%s) after migrating all config keys to the cluster configuration file (%s)", component, path, ldr.Path)
183
184         err = yaml.Unmarshal(buf, target)
185         if err != nil {
186                 return fmt.Errorf("%s: %s", path, err)
187         }
188         return nil
189 }
190
191 type oldCrunchDispatchSlurmConfig struct {
192         Client *arvados.Client
193
194         SbatchArguments *[]string
195         PollPeriod      *arvados.Duration
196         PrioritySpread  *int64
197
198         // crunch-run command to invoke. The container UUID will be
199         // appended. If nil, []string{"crunch-run"} will be used.
200         //
201         // Example: []string{"crunch-run", "--cgroup-parent-subsystem=memory"}
202         CrunchRunCommand *[]string
203
204         // Extra RAM to reserve (in Bytes) for SLURM job, in addition
205         // to the amount specified in the container's RuntimeConstraints
206         ReserveExtraRAM *int64
207
208         // Minimum time between two attempts to run the same container
209         MinRetryPeriod *arvados.Duration
210
211         // Batch size for container queries
212         BatchSize *int64
213 }
214
215 const defaultCrunchDispatchSlurmConfigPath = "/etc/arvados/crunch-dispatch-slurm/crunch-dispatch-slurm.yml"
216
217 func loadOldClientConfig(cluster *arvados.Cluster, client *arvados.Client) {
218         if client == nil {
219                 return
220         }
221         if client.APIHost != "" {
222                 cluster.Services.Controller.ExternalURL.Host = client.APIHost
223                 cluster.Services.Controller.ExternalURL.Path = "/"
224         }
225         if client.Scheme != "" {
226                 cluster.Services.Controller.ExternalURL.Scheme = client.Scheme
227         } else {
228                 cluster.Services.Controller.ExternalURL.Scheme = "https"
229         }
230         if client.AuthToken != "" {
231                 cluster.SystemRootToken = client.AuthToken
232         }
233         cluster.TLS.Insecure = client.Insecure
234         ks := ""
235         for i, u := range client.KeepServiceURIs {
236                 if i > 0 {
237                         ks += " "
238                 }
239                 ks += u
240         }
241         cluster.Containers.SLURM.SbatchEnvironmentVariables = map[string]string{"ARVADOS_KEEP_SERVICES": ks}
242 }
243
244 // update config using values from an crunch-dispatch-slurm config file.
245 func (ldr *Loader) loadOldCrunchDispatchSlurmConfig(cfg *arvados.Config) error {
246         if ldr.CrunchDispatchSlurmPath == "" {
247                 return nil
248         }
249         var oc oldCrunchDispatchSlurmConfig
250         err := ldr.loadOldConfigHelper("crunch-dispatch-slurm", ldr.CrunchDispatchSlurmPath, &oc)
251         if os.IsNotExist(err) && (ldr.CrunchDispatchSlurmPath == defaultCrunchDispatchSlurmConfigPath) {
252                 return nil
253         } else if err != nil {
254                 return err
255         }
256
257         cluster, err := cfg.GetCluster("")
258         if err != nil {
259                 return err
260         }
261
262         loadOldClientConfig(cluster, oc.Client)
263
264         if oc.SbatchArguments != nil {
265                 cluster.Containers.SLURM.SbatchArgumentsList = *oc.SbatchArguments
266         }
267         if oc.PollPeriod != nil {
268                 cluster.Containers.CloudVMs.PollInterval = *oc.PollPeriod
269         }
270         if oc.PrioritySpread != nil {
271                 cluster.Containers.SLURM.PrioritySpread = *oc.PrioritySpread
272         }
273         if oc.CrunchRunCommand != nil {
274                 if len(*oc.CrunchRunCommand) >= 1 {
275                         cluster.Containers.CrunchRunCommand = (*oc.CrunchRunCommand)[0]
276                 }
277                 if len(*oc.CrunchRunCommand) >= 2 {
278                         cluster.Containers.CrunchRunArgumentsList = (*oc.CrunchRunCommand)[1:]
279                 }
280         }
281         if oc.ReserveExtraRAM != nil {
282                 cluster.Containers.ReserveExtraRAM = arvados.ByteSize(*oc.ReserveExtraRAM)
283         }
284         if oc.MinRetryPeriod != nil {
285                 cluster.Containers.MinRetryPeriod = *oc.MinRetryPeriod
286         }
287         if oc.BatchSize != nil {
288                 cluster.API.MaxItemsPerResponse = int(*oc.BatchSize)
289         }
290
291         cfg.Clusters[cluster.ClusterID] = *cluster
292         return nil
293 }
294
295 type oldWsConfig struct {
296         Client       *arvados.Client
297         Postgres     *arvados.PostgreSQLConnection
298         PostgresPool *int
299         Listen       *string
300         LogLevel     *string
301         LogFormat    *string
302
303         PingTimeout      *arvados.Duration
304         ClientEventQueue *int
305         ServerEventQueue *int
306
307         ManagementToken *string
308 }
309
310 const defaultWebsocketConfigPath = "/etc/arvados/ws/ws.yml"
311
312 // update config using values from an crunch-dispatch-slurm config file.
313 func (ldr *Loader) loadOldWebsocketConfig(cfg *arvados.Config) error {
314         if ldr.WebsocketPath == "" {
315                 return nil
316         }
317         var oc oldWsConfig
318         err := ldr.loadOldConfigHelper("arvados-ws", ldr.WebsocketPath, &oc)
319         if os.IsNotExist(err) && ldr.WebsocketPath == defaultWebsocketConfigPath {
320                 return nil
321         } else if err != nil {
322                 return err
323         }
324
325         cluster, err := cfg.GetCluster("")
326         if err != nil {
327                 return err
328         }
329
330         loadOldClientConfig(cluster, oc.Client)
331
332         if oc.Postgres != nil {
333                 cluster.PostgreSQL.Connection = *oc.Postgres
334         }
335         if oc.PostgresPool != nil {
336                 cluster.PostgreSQL.ConnectionPool = *oc.PostgresPool
337         }
338         if oc.Listen != nil {
339                 cluster.Services.Websocket.InternalURLs[arvados.URL{Host: *oc.Listen, Path: "/"}] = arvados.ServiceInstance{}
340         }
341         if oc.LogLevel != nil {
342                 cluster.SystemLogs.LogLevel = *oc.LogLevel
343         }
344         if oc.LogFormat != nil {
345                 cluster.SystemLogs.Format = *oc.LogFormat
346         }
347         if oc.PingTimeout != nil {
348                 cluster.API.SendTimeout = *oc.PingTimeout
349         }
350         if oc.ClientEventQueue != nil {
351                 cluster.API.WebsocketClientEventQueue = *oc.ClientEventQueue
352         }
353         if oc.ServerEventQueue != nil {
354                 cluster.API.WebsocketServerEventQueue = *oc.ServerEventQueue
355         }
356         if oc.ManagementToken != nil {
357                 cluster.ManagementToken = *oc.ManagementToken
358         }
359
360         cfg.Clusters[cluster.ClusterID] = *cluster
361         return nil
362 }
363
364 type oldKeepProxyConfig struct {
365         Client          *arvados.Client
366         Listen          *string
367         DisableGet      *bool
368         DisablePut      *bool
369         DefaultReplicas *int
370         Timeout         *arvados.Duration
371         PIDFile         *string
372         Debug           *bool
373         ManagementToken *string
374 }
375
376 const defaultKeepproxyConfigPath = "/etc/arvados/keepproxy/keepproxy.yml"
377
378 func (ldr *Loader) loadOldKeepproxyConfig(cfg *arvados.Config) error {
379         if ldr.KeepproxyPath == "" {
380                 return nil
381         }
382         var oc oldKeepProxyConfig
383         err := ldr.loadOldConfigHelper("keepproxy", ldr.KeepproxyPath, &oc)
384         if os.IsNotExist(err) && ldr.KeepproxyPath == defaultKeepproxyConfigPath {
385                 return nil
386         } else if err != nil {
387                 return err
388         }
389
390         cluster, err := cfg.GetCluster("")
391         if err != nil {
392                 return err
393         }
394
395         loadOldClientConfig(cluster, oc.Client)
396
397         if oc.Listen != nil {
398                 cluster.Services.Keepproxy.InternalURLs[arvados.URL{Host: *oc.Listen, Path: "/"}] = arvados.ServiceInstance{}
399         }
400         if oc.DefaultReplicas != nil {
401                 cluster.Collections.DefaultReplication = *oc.DefaultReplicas
402         }
403         if oc.Timeout != nil {
404                 cluster.API.KeepServiceRequestTimeout = *oc.Timeout
405         }
406         if oc.Debug != nil {
407                 if *oc.Debug && cluster.SystemLogs.LogLevel != "debug" {
408                         cluster.SystemLogs.LogLevel = "debug"
409                 } else if !*oc.Debug && cluster.SystemLogs.LogLevel != "info" {
410                         cluster.SystemLogs.LogLevel = "info"
411                 }
412         }
413         if oc.ManagementToken != nil {
414                 cluster.ManagementToken = *oc.ManagementToken
415         }
416
417         // The following legacy options are no longer supported. If they are set to
418         // true or PIDFile has a value, error out and notify the user
419         unsupportedEntry := func(cfgEntry string) error {
420                 return fmt.Errorf("the keepproxy %s configuration option is no longer supported, please remove it from your configuration file", cfgEntry)
421         }
422         if oc.DisableGet != nil && *oc.DisableGet {
423                 return unsupportedEntry("DisableGet")
424         }
425         if oc.DisablePut != nil && *oc.DisablePut {
426                 return unsupportedEntry("DisablePut")
427         }
428         if oc.PIDFile != nil && *oc.PIDFile != "" {
429                 return unsupportedEntry("PIDFile")
430         }
431
432         cfg.Clusters[cluster.ClusterID] = *cluster
433         return nil
434 }
435
436 const defaultKeepWebConfigPath = "/etc/arvados/keep-web/keep-web.yml"
437
438 type oldKeepWebConfig struct {
439         Client *arvados.Client
440
441         Listen *string
442
443         AnonymousTokens    *[]string
444         AttachmentOnlyHost *string
445         TrustAllContent    *bool
446
447         Cache struct {
448                 TTL                  *arvados.Duration
449                 UUIDTTL              *arvados.Duration
450                 MaxCollectionEntries *int
451                 MaxCollectionBytes   *int64
452                 MaxUUIDEntries       *int
453         }
454
455         // Hack to support old command line flag, which is a bool
456         // meaning "get actual token from environment".
457         deprecatedAllowAnonymous *bool
458
459         // Authorization token to be included in all health check requests.
460         ManagementToken *string
461 }
462
463 func (ldr *Loader) loadOldKeepWebConfig(cfg *arvados.Config) error {
464         if ldr.KeepWebPath == "" {
465                 return nil
466         }
467         var oc oldKeepWebConfig
468         err := ldr.loadOldConfigHelper("keep-web", ldr.KeepWebPath, &oc)
469         if os.IsNotExist(err) && ldr.KeepWebPath == defaultKeepWebConfigPath {
470                 return nil
471         } else if err != nil {
472                 return err
473         }
474
475         cluster, err := cfg.GetCluster("")
476         if err != nil {
477                 return err
478         }
479
480         loadOldClientConfig(cluster, oc.Client)
481
482         if oc.Listen != nil {
483                 cluster.Services.WebDAV.InternalURLs[arvados.URL{Host: *oc.Listen, Path: "/"}] = arvados.ServiceInstance{}
484                 cluster.Services.WebDAVDownload.InternalURLs[arvados.URL{Host: *oc.Listen, Path: "/"}] = arvados.ServiceInstance{}
485         }
486         if oc.AttachmentOnlyHost != nil {
487                 cluster.Services.WebDAVDownload.ExternalURL = arvados.URL{Host: *oc.AttachmentOnlyHost, Path: "/"}
488         }
489         if oc.ManagementToken != nil {
490                 cluster.ManagementToken = *oc.ManagementToken
491         }
492         if oc.TrustAllContent != nil {
493                 cluster.Collections.TrustAllContent = *oc.TrustAllContent
494         }
495         if oc.Cache.TTL != nil {
496                 cluster.Collections.WebDAVCache.TTL = *oc.Cache.TTL
497         }
498         if oc.Cache.UUIDTTL != nil {
499                 cluster.Collections.WebDAVCache.UUIDTTL = *oc.Cache.UUIDTTL
500         }
501         if oc.Cache.MaxCollectionEntries != nil {
502                 cluster.Collections.WebDAVCache.MaxCollectionEntries = *oc.Cache.MaxCollectionEntries
503         }
504         if oc.Cache.MaxCollectionBytes != nil {
505                 cluster.Collections.WebDAVCache.MaxCollectionBytes = *oc.Cache.MaxCollectionBytes
506         }
507         if oc.Cache.MaxUUIDEntries != nil {
508                 cluster.Collections.WebDAVCache.MaxUUIDEntries = *oc.Cache.MaxUUIDEntries
509         }
510         if oc.AnonymousTokens != nil {
511                 if len(*oc.AnonymousTokens) > 0 {
512                         cluster.Users.AnonymousUserToken = (*oc.AnonymousTokens)[0]
513                         if len(*oc.AnonymousTokens) > 1 {
514                                 ldr.Logger.Warn("More than 1 anonymous tokens configured, using only the first and discarding the rest.")
515                         }
516                 }
517         }
518
519         cfg.Clusters[cluster.ClusterID] = *cluster
520         return nil
521 }
522
523 const defaultGitHttpdConfigPath = "/etc/arvados/git-httpd/git-httpd.yml"
524
525 type oldGitHttpdConfig struct {
526         Client          *arvados.Client
527         Listen          *string
528         GitCommand      *string
529         GitoliteHome    *string
530         RepoRoot        *string
531         ManagementToken *string
532 }
533
534 func (ldr *Loader) loadOldGitHttpdConfig(cfg *arvados.Config) error {
535         if ldr.GitHttpdPath == "" {
536                 return nil
537         }
538         var oc oldGitHttpdConfig
539         err := ldr.loadOldConfigHelper("arv-git-httpd", ldr.GitHttpdPath, &oc)
540         if os.IsNotExist(err) && ldr.GitHttpdPath == defaultGitHttpdConfigPath {
541                 return nil
542         } else if err != nil {
543                 return err
544         }
545
546         cluster, err := cfg.GetCluster("")
547         if err != nil {
548                 return err
549         }
550
551         loadOldClientConfig(cluster, oc.Client)
552
553         if oc.Listen != nil {
554                 cluster.Services.GitHTTP.InternalURLs[arvados.URL{Host: *oc.Listen}] = arvados.ServiceInstance{}
555         }
556         if oc.ManagementToken != nil {
557                 cluster.ManagementToken = *oc.ManagementToken
558         }
559         if oc.GitCommand != nil {
560                 cluster.Git.GitCommand = *oc.GitCommand
561         }
562         if oc.GitoliteHome != nil {
563                 cluster.Git.GitoliteHome = *oc.GitoliteHome
564         }
565         if oc.RepoRoot != nil {
566                 cluster.Git.Repositories = *oc.RepoRoot
567         }
568
569         cfg.Clusters[cluster.ClusterID] = *cluster
570         return nil
571 }
572
573 const defaultKeepBalanceConfigPath = "/etc/arvados/keep-balance/keep-balance.yml"
574
575 type oldKeepBalanceConfig struct {
576         Client              *arvados.Client
577         Listen              *string
578         KeepServiceTypes    *[]string
579         KeepServiceList     *arvados.KeepServiceList
580         RunPeriod           *arvados.Duration
581         CollectionBatchSize *int
582         CollectionBuffers   *int
583         RequestTimeout      *arvados.Duration
584         LostBlocksFile      *string
585         ManagementToken     *string
586 }
587
588 func (ldr *Loader) loadOldKeepBalanceConfig(cfg *arvados.Config) error {
589         if ldr.KeepBalancePath == "" {
590                 return nil
591         }
592         var oc oldKeepBalanceConfig
593         err := ldr.loadOldConfigHelper("keep-balance", ldr.KeepBalancePath, &oc)
594         if os.IsNotExist(err) && ldr.KeepBalancePath == defaultKeepBalanceConfigPath {
595                 return nil
596         } else if err != nil {
597                 return err
598         }
599
600         cluster, err := cfg.GetCluster("")
601         if err != nil {
602                 return err
603         }
604
605         loadOldClientConfig(cluster, oc.Client)
606
607         if oc.Listen != nil {
608                 cluster.Services.Keepbalance.InternalURLs[arvados.URL{Host: *oc.Listen}] = arvados.ServiceInstance{}
609         }
610         if oc.ManagementToken != nil {
611                 cluster.ManagementToken = *oc.ManagementToken
612         }
613         if oc.RunPeriod != nil {
614                 cluster.Collections.BalancePeriod = *oc.RunPeriod
615         }
616         if oc.LostBlocksFile != nil {
617                 cluster.Collections.BlobMissingReport = *oc.LostBlocksFile
618         }
619         if oc.CollectionBatchSize != nil {
620                 cluster.Collections.BalanceCollectionBatch = *oc.CollectionBatchSize
621         }
622         if oc.CollectionBuffers != nil {
623                 cluster.Collections.BalanceCollectionBuffers = *oc.CollectionBuffers
624         }
625         if oc.RequestTimeout != nil {
626                 cluster.API.KeepServiceRequestTimeout = *oc.RequestTimeout
627         }
628
629         msg := "The %s configuration option is no longer supported. Please remove it from your configuration file. See the keep-balance upgrade notes at https://doc.arvados.org/admin/upgrading.html for more details."
630
631         // If the keep service type provided is "disk" silently ignore it, since
632         // this is what ends up being done anyway.
633         if oc.KeepServiceTypes != nil {
634                 numTypes := len(*oc.KeepServiceTypes)
635                 if numTypes != 0 && !(numTypes == 1 && (*oc.KeepServiceTypes)[0] == "disk") {
636                         return fmt.Errorf(msg, "KeepServiceTypes")
637                 }
638         }
639
640         if oc.KeepServiceList != nil {
641                 return fmt.Errorf(msg, "KeepServiceList")
642         }
643
644         cfg.Clusters[cluster.ClusterID] = *cluster
645         return nil
646 }
647
648 func (ldr *Loader) loadOldEnvironmentVariables(cfg *arvados.Config) error {
649         if os.Getenv("ARVADOS_API_TOKEN") == "" && os.Getenv("ARVADOS_API_HOST") == "" {
650                 return nil
651         }
652         cluster, err := cfg.GetCluster("")
653         if err != nil {
654                 return err
655         }
656         if tok := os.Getenv("ARVADOS_API_TOKEN"); tok != "" && cluster.SystemRootToken == "" {
657                 ldr.Logger.Warn("SystemRootToken missing from cluster config, falling back to ARVADOS_API_TOKEN environment variable")
658                 cluster.SystemRootToken = tok
659         }
660         if apihost := os.Getenv("ARVADOS_API_HOST"); apihost != "" && cluster.Services.Controller.ExternalURL.Host == "" {
661                 ldr.Logger.Warn("Services.Controller.ExternalURL missing from cluster config, falling back to ARVADOS_API_HOST(_INSECURE) environment variables")
662                 u, err := url.Parse("https://" + apihost)
663                 if err != nil {
664                         return fmt.Errorf("cannot parse ARVADOS_API_HOST: %s", err)
665                 }
666                 cluster.Services.Controller.ExternalURL = arvados.URL(*u)
667                 if i := os.Getenv("ARVADOS_API_HOST_INSECURE"); i != "" && i != "0" {
668                         cluster.TLS.Insecure = true
669                 }
670         }
671         cfg.Clusters[cluster.ClusterID] = *cluster
672         return nil
673 }