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
This commit is contained in:
kannappanr
2019-02-07 21:10:38 -08:00
committed by GitHub
parent 7bc792e745
commit da3e027145
3 changed files with 8 additions and 2 deletions
+1 -1
View File
@@ -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")
+6
View File
@@ -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) != "" {
+1 -1
View File
@@ -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