This is an automated email from the ASF dual-hosted git repository. csantanapr pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/incubator-openwhisk-cli.git
commit 0792cc89b106682326ea55d15b6334be190512e1 Author: Ben Browning <[email protected]> AuthorDate: Wed Sep 20 15:21:51 2017 -0400 Don't assume apihost is https for sdk and action urls (#2748) * Don't assume apihost is https for sdk and action urls Reuse the getURLBase utility method when computing the URL for sdk downloads and action URLs. This fixes #2720 and fixes #2719. * Cleanup some trailing whitespace I missed * Missed this import in last-second rebase * Update debug messages to match `GetURLBase` method name --- commands/action.go | 8 +++++++- commands/commands.go | 4 ++-- commands/property.go | 8 ++++---- commands/util.go | 24 ------------------------ 4 files changed, 13 insertions(+), 31 deletions(-) diff --git a/commands/action.go b/commands/action.go index 1546602..82312f6 100644 --- a/commands/action.go +++ b/commands/action.go @@ -230,10 +230,16 @@ var actionGetCmd = &cobra.Command{ } if Flags.action.url { - actionURL := action.ActionURL(Properties.APIHost, + actionURL, err := action.ActionURL(Properties.APIHost, DefaultOpenWhiskApiPath, Properties.APIVersion, qualifiedName.GetPackageName()) + if err != nil { + errStr := wski18n.T("Invalid host address '{{.host}}': {{.err}}", + map[string]interface{}{"host": Properties.APIHost, "err": err}) + werr := whisk.MakeWskError(errors.New(errStr), whisk.EXIT_CODE_ERR_GENERAL, whisk.DISPLAY_MSG, whisk.NO_DISPLAY_USAGE) + return werr + } printActionGetWithURL(qualifiedName.GetEntity(), actionURL) } else if Flags.common.summary { printSummary(action) diff --git a/commands/commands.go b/commands/commands.go index 0914a73..9d79ad0 100644 --- a/commands/commands.go +++ b/commands/commands.go @@ -33,7 +33,7 @@ const DefaultOpenWhiskApiPath string = "/api" var UserAgent string = "OpenWhisk-CLI" func setupClientConfig(cmd *cobra.Command, args []string) (error){ - baseURL, err := GetURLBase(Properties.APIHost, DefaultOpenWhiskApiPath) + baseURL, err := whisk.GetURLBase(Properties.APIHost, DefaultOpenWhiskApiPath) // Determine if the parent command will require the API host to be set apiHostRequired := (cmd.Parent().Name() == "property" && cmd.Name() == "get" && (Flags.property.auth || @@ -45,7 +45,7 @@ func setupClientConfig(cmd *cobra.Command, args []string) (error){ // Display an error if the parent command requires an API host to be set, and the current API host is not valid if err != nil && !apiHostRequired { - whisk.Debug(whisk.DbgError, "getURLBase(%s, %s) error: %s\n", Properties.APIHost, DefaultOpenWhiskApiPath, err) + whisk.Debug(whisk.DbgError, "whisk.GetURLBase(%s, %s) error: %s\n", Properties.APIHost, DefaultOpenWhiskApiPath, err) errMsg := wski18n.T("The API host is not valid: {{.err}}", map[string]interface{}{"err": err}) whiskErr := whisk.MakeWskErrorFromWskError(errors.New(errMsg), err, whisk.EXIT_CODE_ERR_GENERAL, whisk.DISPLAY_MSG, whisk.NO_DISPLAY_USAGE) diff --git a/commands/property.go b/commands/property.go index d51fdeb..5153e18 100644 --- a/commands/property.go +++ b/commands/property.go @@ -106,11 +106,11 @@ var propertySetCmd = &cobra.Command{ } if apiHost := Flags.property.apihostSet; len(apiHost) > 0 { - baseURL, err := GetURLBase(apiHost, DefaultOpenWhiskApiPath) + baseURL, err := whisk.GetURLBase(apiHost, DefaultOpenWhiskApiPath) if err != nil { // Not aborting now. Subsequent commands will result in error - whisk.Debug(whisk.DbgError, "getURLBase(%s, %s) error: %s", apiHost, DefaultOpenWhiskApiPath, err) + whisk.Debug(whisk.DbgError, "whisk.GetURLBase(%s, %s) error: %s", apiHost, DefaultOpenWhiskApiPath, err) errStr := fmt.Sprintf( wski18n.T("Unable to set API host value; the API host value '{{.apihost}}' is invalid: {{.err}}", map[string]interface{}{"apihost": apiHost, "err": err})) @@ -537,10 +537,10 @@ func parseConfigFlags(cmd *cobra.Command, args []string) error { if client != nil { client.Config.Host = apiHost - baseURL, err := GetURLBase(apiHost, DefaultOpenWhiskApiPath) + baseURL, err := whisk.GetURLBase(apiHost, DefaultOpenWhiskApiPath) if err != nil { - whisk.Debug(whisk.DbgError, "getURLBase(%s, %s) failed: %s\n", apiHost, DefaultOpenWhiskApiPath, err) + whisk.Debug(whisk.DbgError, "whisk.GetURLBase(%s, %s) failed: %s\n", apiHost, DefaultOpenWhiskApiPath, err) errStr := wski18n.T("Invalid host address '{{.host}}': {{.err}}", map[string]interface{}{"host": Properties.APIHost, "err": err}) werr := whisk.MakeWskError(errors.New(errStr), whisk.EXIT_CODE_ERR_GENERAL, whisk.DISPLAY_MSG, whisk.NO_DISPLAY_USAGE) diff --git a/commands/util.go b/commands/util.go index 96511c0..7226487 100644 --- a/commands/util.go +++ b/commands/util.go @@ -35,7 +35,6 @@ import ( "compress/gzip" "archive/zip" "encoding/json" - "net/url" "io/ioutil" "sort" "reflect" @@ -816,29 +815,6 @@ func checkArgs(args []string, minimumArgNumber int, maximumArgNumber int, comman } } -func GetURLBase(host string, path string) (*url.URL, error) { - if len(host) == 0 { - errMsg := wski18n.T("An API host must be provided.") - whiskErr := whisk.MakeWskError(errors.New(errMsg), whisk.EXIT_CODE_ERR_GENERAL, - whisk.DISPLAY_MSG, whisk.DISPLAY_USAGE) - return nil, whiskErr - } - - if !strings.HasPrefix(host, "http") { - host = "https://" + host - } - - urlBase := fmt.Sprintf("%s%s", host, path) - url, err := url.Parse(urlBase) - - if len(url.Scheme) == 0 || len(url.Host) == 0 { - urlBase = fmt.Sprintf("https://%s%s", host, path) - url, err = url.Parse(urlBase) - } - - return url, err -} - func normalizeNamespace(namespace string) (string) { if (namespace == "_") { namespace = wski18n.T("default") -- To stop receiving notification emails like this one, please contact "[email protected]" <[email protected]>.
