From da3e0271451dbdaaa8455c37505c644678bfcf1c Mon Sep 17 00:00:00 2001 From: kannappanr <30541348+kannappanr@users.noreply.github.com> Date: Thu, 7 Feb 2019 21:10:38 -0800 Subject: [PATCH] Strip trailing separator in URL in config host add (#2680) Also, in the case of find command for existing configs that has a trailing separator in the URL, trim the separator from the URL. Fixes #2645 --- cmd/config-host-add.go | 2 +- cmd/config-utils.go | 6 ++++++ cmd/find.go | 2 +- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/cmd/config-host-add.go b/cmd/config-host-add.go index e7df44f2..a0ccbff1 100644 --- a/cmd/config-host-add.go +++ b/cmd/config-host-add.go @@ -227,7 +227,7 @@ func mainConfigHostAdd(ctx *cli.Context) error { console.SetColor("HostMessage", color.New(color.FgGreen)) var ( args = ctx.Args() - url = args.Get(1) + url = trimTrailingSeparator(args.Get(1)) accessKey = args.Get(2) secretKey = args.Get(3) api = ctx.String("api") diff --git a/cmd/config-utils.go b/cmd/config-utils.go index 01d53f1f..285ed196 100644 --- a/cmd/config-utils.go +++ b/cmd/config-utils.go @@ -41,6 +41,12 @@ func isValidSecretKey(secretKey string) bool { return len(secretKey) >= secretKeyMinLen } +// trimTrailingSeparator - Remove trailing separator. +func trimTrailingSeparator(hostURL string) string { + separator := string(newClientURL(hostURL).Separator) + return strings.TrimSuffix(hostURL, separator) +} + // isValidHostURL - validate input host url. func isValidHostURL(hostURL string) (ok bool) { if strings.TrimSpace(hostURL) != "" { diff --git a/cmd/find.go b/cmd/find.go index ab7a5bf1..8c84467a 100644 --- a/cmd/find.go +++ b/cmd/find.go @@ -209,7 +209,7 @@ func getAliasedPath(ctx *findContext, path string) string { prefixPath := ctx.clnt.GetURL().String() var aliasedPath string if ctx.targetAlias != "" { - aliasedPath = ctx.targetAlias + strings.TrimPrefix(path, ctx.targetFullURL) + aliasedPath = ctx.targetAlias + strings.TrimPrefix(path, strings.TrimSuffix(ctx.targetFullURL, separator)) } else { aliasedPath = path // look for prefix path, if found filter at that, Watch calls