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