From 8a754183862bfc1a5841b4cee1a0574cc891fec1 Mon Sep 17 00:00:00 2001 From: Matthias Hanel Date: Mon, 30 Mar 2020 11:49:19 -0400 Subject: [PATCH] Using AccountResolver url from operator jwt. If resolver is specified separately, it takes precedence. nsc push automatically adds /accounts. That's why its added here too. Operator jwt reload is not supported and is not taken into account. On startup the AccountResolver url is checked and exits if it can't be reached. Signed-off-by: Matthias Hanel --- server/opts.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/server/opts.go b/server/opts.go index e1ae3893..facfabb1 100644 --- a/server/opts.go +++ b/server/opts.go @@ -697,7 +697,21 @@ func (o *Options) processConfigFileLine(k string, v interface{}, errors *[]error } o.TrustedOperators = append(o.TrustedOperators, opc) } + // In case "resolver" is defined as well, it takes precedence + if o.AccountResolver == nil && len(o.TrustedOperators) == 1 { + if accUrl, err := parseURL(o.TrustedOperators[0].AccountServerURL, "account resolver"); err == nil { + // accommodate nsc which appends "/accounts" during nsc push + suffix := "" + if accUrl.Path == "/jwt/v1/" || accUrl.Path == "/jwt/v1" { + suffix = "/accounts" + } + o.AccountResolver, _ = NewURLAccResolver(accUrl.String() + suffix) + } + } case "resolver", "account_resolver", "accounts_resolver": + // "resolver" takes precedence over value obtained from "operator". + // Clear so that parsing errors are not silently ignored. + o.AccountResolver = nil var memResolverRe = regexp.MustCompile(`(MEM|MEMORY|mem|memory)\s*`) var resolverRe = regexp.MustCompile(`(?:URL|url){1}(?:\({1}\s*"?([^\s"]*)"?\s*\){1})?\s*`) str, ok := v.(string)