Merge branch '18994-cwl-basename' refs #18994
[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                                         }
129                                         var allparams map[string]interface{}
130                                         err = json.Unmarshal(vol.DriverParameters, &allparams)
131                                         if err != nil {
132                                                 return fmt.Errorf("error loading %s.Volumes.%s.DriverParameters: %w", clusterID, volID, err)
133                                         }
134                                         for k := range allparams {
135                                                 if lk := strings.ToLower(k); lk == "accesskey" || lk == "secretkey" {
136                                                         delete(allparams, k)
137                                                 }
138                                         }
139                                         ldr.Logger.Warnf("using your old config keys %s.Volumes.%s.DriverParameters.AccessKey/SecretKey -- but you should rename them to AccessKeyID/SecretAccessKey", clusterID, volID)
140                                         allparams["AccessKeyID"] = params.AccessKey
141                                         allparams["SecretAccessKey"] = params.SecretKey
142                                         vol.DriverParameters, err = json.Marshal(allparams)
143                                         if err != nil {
144                                                 return err
145                                         }
146                                         cluster.Volumes[volID] = vol
147                                 }
148                         }
149                 }
150         }
151         return nil
152 }
153
154 func applyDeprecatedNodeProfile(hostname string, ssi systemServiceInstance, svc *arvados.Service) {
155         scheme := "https"
156         if !ssi.TLS {
157                 scheme = "http"
158         }
159         if svc.InternalURLs == nil {
160                 svc.InternalURLs = map[arvados.URL]arvados.ServiceInstance{}
161         }
162         host := ssi.Listen
163         if host == "" {
164                 return
165         }
166         if strings.HasPrefix(host, ":") {
167                 host = hostname + host
168         }
169         svc.InternalURLs[arvados.URL{Scheme: scheme, Host: host, Path: "/"}] = arvados.ServiceInstance{}
170 }
171
172 func (ldr *Loader) loadOldConfigHelper(component, path string, target interface{}) error {
173         if path == "" {
174                 return nil
175         }
176         buf, err := ioutil.ReadFile(path)
177         if err != nil {
178                 return err
179         }
180
181         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)
182
183         err = yaml.Unmarshal(buf, target)
184         if err != nil {
185                 return fmt.Errorf("%s: %s", path, err)
186         }
187         return nil
188 }
189
190 type oldCrunchDispatchSlurmConfig struct {
191         Client *arvados.Client
192
193         SbatchArguments *[]string
194         PollPeriod      *arvados.Duration
195         PrioritySpread  *int64
196
197         // crunch-run command to invoke. The container UUID will be
198         // appended. If nil, []string{"crunch-run"} will be used.
199         //
200         // Example: []string{"crunch-run", "--cgroup-parent-subsystem=memory"}
201         CrunchRunCommand *[]string
202
203         // Extra RAM to reserve (in Bytes) for SLURM job, in addition
204         // to the amount specified in the container's RuntimeConstraints
205         ReserveExtraRAM *int64
206
207         // Minimum time between two attempts to run the same container
208         MinRetryPeriod *arvados.Duration
209
210         // Batch size for container queries
211         BatchSize *int64
212 }
213
214 const defaultCrunchDispatchSlurmConfigPath = "/etc/arvados/crunch-dispatch-slurm/crunch-dispatch-slurm.yml"
215
216 func loadOldClientConfig(cluster *arvados.Cluster, client *arvados.Client) {
217         if client == nil {
218                 return
219         }
220         if client.APIHost != "" {
221                 cluster.Services.Controller.ExternalURL.Host = client.APIHost
222                 cluster.Services.Controller.ExternalURL.Path = "/"
223         }
224         if client.Scheme != "" {
225                 cluster.Services.Controller.ExternalURL.Scheme = client.Scheme
226         } else {
227                 cluster.Services.Controller.ExternalURL.Scheme = "https"
228         }
229         if client.AuthToken != "" {
230                 cluster.SystemRootToken = client.AuthToken
231         }
232         cluster.TLS.Insecure = client.Insecure
233         ks := ""
234         for i, u := range client.KeepServiceURIs {
235                 if i > 0 {
236                         ks += " "
237                 }
238                 ks += u
239         }
240         cluster.Containers.SLURM.SbatchEnvironmentVariables = map[string]string{"ARVADOS_KEEP_SERVICES": ks}
241 }
242
243 // update config using values from an crunch-dispatch-slurm config file.
244 func (ldr *Loader) loadOldCrunchDispatchSlurmConfig(cfg *arvados.Config) error {
245         if ldr.CrunchDispatchSlurmPath == "" {
246                 return nil
247         }
248         var oc oldCrunchDispatchSlurmConfig
249         err := ldr.loadOldConfigHelper("crunch-dispatch-slurm", ldr.CrunchDispatchSlurmPath, &oc)
250         if os.IsNotExist(err) && (ldr.CrunchDispatchSlurmPath == defaultCrunchDispatchSlurmConfigPath) {
251                 return nil
252         } else if err != nil {
253                 return err
254         }
255
256         cluster, err := cfg.GetCluster("")
257         if err != nil {
258                 return err
259         }
260
261         loadOldClientConfig(cluster, oc.Client)
262
263         if oc.SbatchArguments != nil {
264                 cluster.Containers.SLURM.SbatchArgumentsList = *oc.SbatchArguments
265         }
266         if oc.PollPeriod != nil {
267                 cluster.Containers.CloudVMs.PollInterval = *oc.PollPeriod
268         }
269         if oc.PrioritySpread != nil {
270                 cluster.Containers.SLURM.PrioritySpread = *oc.PrioritySpread
271         }
272         if oc.CrunchRunCommand != nil {
273                 if len(*oc.CrunchRunCommand) >= 1 {
274                         cluster.Containers.CrunchRunCommand = (*oc.CrunchRunCommand)[0]
275                 }
276                 if len(*oc.CrunchRunCommand) >= 2 {
277                         cluster.Containers.CrunchRunArgumentsList = (*oc.CrunchRunCommand)[1:]
278                 }
279         }
280         if oc.ReserveExtraRAM != nil {
281                 cluster.Containers.ReserveExtraRAM = arvados.ByteSize(*oc.ReserveExtraRAM)
282         }
283         if oc.MinRetryPeriod != nil {
284                 cluster.Containers.MinRetryPeriod = *oc.MinRetryPeriod
285         }
286         if oc.BatchSize != nil {
287                 cluster.API.MaxItemsPerResponse = int(*oc.BatchSize)
288         }
289
290         cfg.Clusters[cluster.ClusterID] = *cluster
291         return nil
292 }
293
294 type oldWsConfig struct {
295         Client       *arvados.Client
296         Postgres     *arvados.PostgreSQLConnection
297         PostgresPool *int
298         Listen       *string
299         LogLevel     *string
300         LogFormat    *string
301
302         PingTimeout      *arvados.Duration
303         ClientEventQueue *int
304         ServerEventQueue *int
305
306         ManagementToken *string
307 }
308
309 const defaultWebsocketConfigPath = "/etc/arvados/ws/ws.yml"
310
311 // update config using values from an crunch-dispatch-slurm config file.
312 func (ldr *Loader) loadOldWebsocketConfig(cfg *arvados.Config) error {
313         if ldr.WebsocketPath == "" {
314                 return nil
315         }
316         var oc oldWsConfig
317         err := ldr.loadOldConfigHelper("arvados-ws", ldr.WebsocketPath, &oc)
318         if os.IsNotExist(err) && ldr.WebsocketPath == defaultWebsocketConfigPath {
319                 return nil
320         } else if err != nil {
321                 return err
322         }
323
324         cluster, err := cfg.GetCluster("")
325         if err != nil {
326                 return err
327         }
328
329         loadOldClientConfig(cluster, oc.Client)
330
331         if oc.Postgres != nil {
332                 cluster.PostgreSQL.Connection = *oc.Postgres
333         }
334         if oc.PostgresPool != nil {
335                 cluster.PostgreSQL.ConnectionPool = *oc.PostgresPool
336         }
337         if oc.Listen != nil {
338                 cluster.Services.Websocket.InternalURLs[arvados.URL{Host: *oc.Listen, Path: "/"}] = arvados.ServiceInstance{}
339         }
340         if oc.LogLevel != nil {
341                 cluster.SystemLogs.LogLevel = *oc.LogLevel
342         }
343         if oc.LogFormat != nil {
344                 cluster.SystemLogs.Format = *oc.LogFormat
345         }
346         if oc.PingTimeout != nil {
347                 cluster.API.SendTimeout = *oc.PingTimeout
348         }
349         if oc.ClientEventQueue != nil {
350                 cluster.API.WebsocketClientEventQueue = *oc.ClientEventQueue
351         }
352         if oc.ServerEventQueue != nil {
353                 cluster.API.WebsocketServerEventQueue = *oc.ServerEventQueue
354         }
355         if oc.ManagementToken != nil {
356                 cluster.ManagementToken = *oc.ManagementToken
357         }
358
359         cfg.Clusters[cluster.ClusterID] = *cluster
360         return nil
361 }
362
363 type oldKeepProxyConfig struct {
364         Client          *arvados.Client
365         Listen          *string
366         DisableGet      *bool
367         DisablePut      *bool
368         DefaultReplicas *int
369         Timeout         *arvados.Duration
370         PIDFile         *string
371         Debug           *bool
372         ManagementToken *string
373 }
374
375 const defaultKeepproxyConfigPath = "/etc/arvados/keepproxy/keepproxy.yml"
376
377 func (ldr *Loader) loadOldKeepproxyConfig(cfg *arvados.Config) error {
378         if ldr.KeepproxyPath == "" {
379                 return nil
380         }
381         var oc oldKeepProxyConfig
382         err := ldr.loadOldConfigHelper("keepproxy", ldr.KeepproxyPath, &oc)
383         if os.IsNotExist(err) && ldr.KeepproxyPath == defaultKeepproxyConfigPath {
384                 return nil
385         } else if err != nil {
386                 return err
387         }
388
389         cluster, err := cfg.GetCluster("")
390         if err != nil {
391                 return err
392         }
393
394         loadOldClientConfig(cluster, oc.Client)
395
396         if oc.Listen != nil {
397                 cluster.Services.Keepproxy.InternalURLs[arvados.URL{Host: *oc.Listen, Path: "/"}] = arvados.ServiceInstance{}
398         }
399         if oc.DefaultReplicas != nil {
400                 cluster.Collections.DefaultReplication = *oc.DefaultReplicas
401         }
402         if oc.Timeout != nil {
403                 cluster.API.KeepServiceRequestTimeout = *oc.Timeout
404         }
405         if oc.Debug != nil {
406                 if *oc.Debug && cluster.SystemLogs.LogLevel != "debug" {
407                         cluster.SystemLogs.LogLevel = "debug"
408                 } else if !*oc.Debug && cluster.SystemLogs.LogLevel != "info" {
409                         cluster.SystemLogs.LogLevel = "info"
410                 }
411         }
412         if oc.ManagementToken != nil {
413                 cluster.ManagementToken = *oc.ManagementToken
414         }
415
416         // The following legacy options are no longer supported. If they are set to
417         // true or PIDFile has a value, error out and notify the user
418         unsupportedEntry := func(cfgEntry string) error {
419                 return fmt.Errorf("the keepproxy %s configuration option is no longer supported, please remove it from your configuration file", cfgEntry)
420         }
421         if oc.DisableGet != nil && *oc.DisableGet {
422                 return unsupportedEntry("DisableGet")
423         }
424         if oc.DisablePut != nil && *oc.DisablePut {
425                 return unsupportedEntry("DisablePut")
426         }
427         if oc.PIDFile != nil && *oc.PIDFile != "" {
428                 return unsupportedEntry("PIDFile")
429         }
430
431         cfg.Clusters[cluster.ClusterID] = *cluster
432         return nil
433 }
434
435 const defaultKeepWebConfigPath = "/etc/arvados/keep-web/keep-web.yml"
436
437 type oldKeepWebConfig struct {
438         Client *arvados.Client
439
440         Listen *string
441
442         AnonymousTokens    *[]string
443         AttachmentOnlyHost *string
444         TrustAllContent    *bool
445
446         Cache struct {
447                 TTL                  *arvados.Duration
448                 UUIDTTL              *arvados.Duration
449                 MaxCollectionEntries *int
450                 MaxCollectionBytes   *int64
451                 MaxUUIDEntries       *int
452         }
453
454         // Hack to support old command line flag, which is a bool
455         // meaning "get actual token from environment".
456         deprecatedAllowAnonymous *bool
457
458         // Authorization token to be included in all health check requests.
459         ManagementToken *string
460 }
461
462 func (ldr *Loader) loadOldKeepWebConfig(cfg *arvados.Config) error {
463         if ldr.KeepWebPath == "" {
464                 return nil
465         }
466         var oc oldKeepWebConfig
467         err := ldr.loadOldConfigHelper("keep-web", ldr.KeepWebPath, &oc)
468         if os.IsNotExist(err) && ldr.KeepWebPath == defaultKeepWebConfigPath {
469                 return nil
470         } else if err != nil {
471                 return err
472         }
473
474         cluster, err := cfg.GetCluster("")
475         if err != nil {
476                 return err
477         }
478
479         loadOldClientConfig(cluster, oc.Client)
480
481         if oc.Listen != nil {
482                 cluster.Services.WebDAV.InternalURLs[arvados.URL{Host: *oc.Listen, Path: "/"}] = arvados.ServiceInstance{}
483                 cluster.Services.WebDAVDownload.InternalURLs[arvados.URL{Host: *oc.Listen, Path: "/"}] = arvados.ServiceInstance{}
484         }
485         if oc.AttachmentOnlyHost != nil {
486                 cluster.Services.WebDAVDownload.ExternalURL = arvados.URL{Host: *oc.AttachmentOnlyHost, Path: "/"}
487         }
488         if oc.ManagementToken != nil {
489                 cluster.ManagementToken = *oc.ManagementToken
490         }
491         if oc.TrustAllContent != nil {
492                 cluster.Collections.TrustAllContent = *oc.TrustAllContent
493         }
494         if oc.Cache.TTL != nil {
495                 cluster.Collections.WebDAVCache.TTL = *oc.Cache.TTL
496         }
497         if oc.Cache.UUIDTTL != nil {
498                 cluster.Collections.WebDAVCache.UUIDTTL = *oc.Cache.UUIDTTL
499         }
500         if oc.Cache.MaxCollectionEntries != nil {
501                 cluster.Collections.WebDAVCache.MaxCollectionEntries = *oc.Cache.MaxCollectionEntries
502         }
503         if oc.Cache.MaxCollectionBytes != nil {
504                 cluster.Collections.WebDAVCache.MaxCollectionBytes = *oc.Cache.MaxCollectionBytes
505         }
506         if oc.Cache.MaxUUIDEntries != nil {
507                 cluster.Collections.WebDAVCache.MaxUUIDEntries = *oc.Cache.MaxUUIDEntries
508         }
509         if oc.AnonymousTokens != nil {
510                 if len(*oc.AnonymousTokens) > 0 {
511                         cluster.Users.AnonymousUserToken = (*oc.AnonymousTokens)[0]
512                         if len(*oc.AnonymousTokens) > 1 {
513                                 ldr.Logger.Warn("More than 1 anonymous tokens configured, using only the first and discarding the rest.")
514                         }
515                 }
516         }
517
518         cfg.Clusters[cluster.ClusterID] = *cluster
519         return nil
520 }
521
522 const defaultGitHttpdConfigPath = "/etc/arvados/git-httpd/git-httpd.yml"
523
524 type oldGitHttpdConfig struct {
525         Client          *arvados.Client
526         Listen          *string
527         GitCommand      *string
528         GitoliteHome    *string
529         RepoRoot        *string
530         ManagementToken *string
531 }
532
533 func (ldr *Loader) loadOldGitHttpdConfig(cfg *arvados.Config) error {
534         if ldr.GitHttpdPath == "" {
535                 return nil
536         }
537         var oc oldGitHttpdConfig
538         err := ldr.loadOldConfigHelper("arv-git-httpd", ldr.GitHttpdPath, &oc)
539         if os.IsNotExist(err) && ldr.GitHttpdPath == defaultGitHttpdConfigPath {
540                 return nil
541         } else if err != nil {
542                 return err
543         }
544
545         cluster, err := cfg.GetCluster("")
546         if err != nil {
547                 return err
548         }
549
550         loadOldClientConfig(cluster, oc.Client)
551
552         if oc.Listen != nil {
553                 cluster.Services.GitHTTP.InternalURLs[arvados.URL{Host: *oc.Listen}] = arvados.ServiceInstance{}
554         }
555         if oc.ManagementToken != nil {
556                 cluster.ManagementToken = *oc.ManagementToken
557         }
558         if oc.GitCommand != nil {
559                 cluster.Git.GitCommand = *oc.GitCommand
560         }
561         if oc.GitoliteHome != nil {
562                 cluster.Git.GitoliteHome = *oc.GitoliteHome
563         }
564         if oc.RepoRoot != nil {
565                 cluster.Git.Repositories = *oc.RepoRoot
566         }
567
568         cfg.Clusters[cluster.ClusterID] = *cluster
569         return nil
570 }
571
572 const defaultKeepBalanceConfigPath = "/etc/arvados/keep-balance/keep-balance.yml"
573
574 type oldKeepBalanceConfig struct {
575         Client              *arvados.Client
576         Listen              *string
577         KeepServiceTypes    *[]string
578         KeepServiceList     *arvados.KeepServiceList
579         RunPeriod           *arvados.Duration
580         CollectionBatchSize *int
581         CollectionBuffers   *int
582         RequestTimeout      *arvados.Duration
583         LostBlocksFile      *string
584         ManagementToken     *string
585 }
586
587 func (ldr *Loader) loadOldKeepBalanceConfig(cfg *arvados.Config) error {
588         if ldr.KeepBalancePath == "" {
589                 return nil
590         }
591         var oc oldKeepBalanceConfig
592         err := ldr.loadOldConfigHelper("keep-balance", ldr.KeepBalancePath, &oc)
593         if os.IsNotExist(err) && ldr.KeepBalancePath == defaultKeepBalanceConfigPath {
594                 return nil
595         } else if err != nil {
596                 return err
597         }
598
599         cluster, err := cfg.GetCluster("")
600         if err != nil {
601                 return err
602         }
603
604         loadOldClientConfig(cluster, oc.Client)
605
606         if oc.Listen != nil {
607                 cluster.Services.Keepbalance.InternalURLs[arvados.URL{Host: *oc.Listen}] = arvados.ServiceInstance{}
608         }
609         if oc.ManagementToken != nil {
610                 cluster.ManagementToken = *oc.ManagementToken
611         }
612         if oc.RunPeriod != nil {
613                 cluster.Collections.BalancePeriod = *oc.RunPeriod
614         }
615         if oc.LostBlocksFile != nil {
616                 cluster.Collections.BlobMissingReport = *oc.LostBlocksFile
617         }
618         if oc.CollectionBatchSize != nil {
619                 cluster.Collections.BalanceCollectionBatch = *oc.CollectionBatchSize
620         }
621         if oc.CollectionBuffers != nil {
622                 cluster.Collections.BalanceCollectionBuffers = *oc.CollectionBuffers
623         }
624         if oc.RequestTimeout != nil {
625                 cluster.API.KeepServiceRequestTimeout = *oc.RequestTimeout
626         }
627
628         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."
629
630         // If the keep service type provided is "disk" silently ignore it, since
631         // this is what ends up being done anyway.
632         if oc.KeepServiceTypes != nil {
633                 numTypes := len(*oc.KeepServiceTypes)
634                 if numTypes != 0 && !(numTypes == 1 && (*oc.KeepServiceTypes)[0] == "disk") {
635                         return fmt.Errorf(msg, "KeepServiceTypes")
636                 }
637         }
638
639         if oc.KeepServiceList != nil {
640                 return fmt.Errorf(msg, "KeepServiceList")
641         }
642
643         cfg.Clusters[cluster.ClusterID] = *cluster
644         return nil
645 }
646
647 func (ldr *Loader) loadOldEnvironmentVariables(cfg *arvados.Config) error {
648         if os.Getenv("ARVADOS_API_TOKEN") == "" && os.Getenv("ARVADOS_API_HOST") == "" {
649                 return nil
650         }
651         cluster, err := cfg.GetCluster("")
652         if err != nil {
653                 return err
654         }
655         if tok := os.Getenv("ARVADOS_API_TOKEN"); tok != "" && cluster.SystemRootToken == "" {
656                 ldr.Logger.Warn("SystemRootToken missing from cluster config, falling back to ARVADOS_API_TOKEN environment variable")
657                 cluster.SystemRootToken = tok
658         }
659         if apihost := os.Getenv("ARVADOS_API_HOST"); apihost != "" && cluster.Services.Controller.ExternalURL.Host == "" {
660                 ldr.Logger.Warn("Services.Controller.ExternalURL missing from cluster config, falling back to ARVADOS_API_HOST(_INSECURE) environment variables")
661                 u, err := url.Parse("https://" + apihost)
662                 if err != nil {
663                         return fmt.Errorf("cannot parse ARVADOS_API_HOST: %s", err)
664                 }
665                 cluster.Services.Controller.ExternalURL = arvados.URL(*u)
666                 if i := os.Getenv("ARVADOS_API_HOST_INSECURE"); i != "" && i != "0" {
667                         cluster.TLS.Insecure = true
668                 }
669         }
670         cfg.Clusters[cluster.ClusterID] = *cluster
671         return nil
672 }