From 68f6929a58bf9aab7df691a0db1567e27bc942b8 Mon Sep 17 00:00:00 2001 From: Tom Clegg Date: Tue, 13 Jul 2021 17:18:02 -0400 Subject: [PATCH] 16561: Detect ambiguous uses of ListenAddress. Arvados-DCO-1.1-Signed-off-by: Tom Clegg --- lib/service/cmd.go | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/lib/service/cmd.go b/lib/service/cmd.go index a9d5731eac..92c554ce53 100644 --- a/lib/service/cmd.go +++ b/lib/service/cmd.go @@ -245,11 +245,34 @@ func getListenAddr(svcs arvados.Services, prog arvados.ServiceName, log logrus.F } if svc.ListenAddress != "" { + scheme := "" for internalURL := range svc.InternalURLs { - listenURL := internalURL - listenURL.Host = svc.ListenAddress - return listenURL, internalURL, nil + if internalURL.Host == svc.ListenAddress { + if len(svc.InternalURLs) > 1 { + log.Warnf("possible configuration error: multiple InternalURLs entries exist for %s but only %q will ever be used because it matches ListenAddress", prog, internalURL.String()) + } + return internalURL, internalURL, nil + } + switch scheme { + case "": + scheme = internalURL.Scheme + case internalURL.Scheme: + default: + scheme = "-" // different InternalURLs have different schemes + } + } + if scheme == "-" { + return arvados.URL{}, arvados.URL{}, fmt.Errorf("cannot use ListenAddress %q: InternalURLs use multiple schemes and none have host %q", svc.ListenAddress, svc.ListenAddress) + } + if scheme == "" { + // No entries at all in InternalURLs + scheme = "http" } + listenURL := arvados.URL{} + listenURL.Host = svc.ListenAddress + listenURL.Scheme = scheme + listenURL.Path = "/" + return listenURL, listenURL, nil } errors := []string{} -- 2.30.2