You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openwhisk.apache.org by da...@apache.org on 2017/09/22 03:14:26 UTC
[incubator-openwhisk-client-go] branch master updated: Don't assume
apihost is https for sdk and action urls (#2748)
This is an automated email from the ASF dual-hosted git repository.
daisyguo pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-openwhisk-client-go.git
The following commit(s) were added to refs/heads/master by this push:
new c6e512b Don't assume apihost is https for sdk and action urls (#2748)
c6e512b is described below
commit c6e512b136e8c27bb144c0f8b625e833fbae878a
Author: Ben Browning <be...@gmail.com>
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
---
whisk/action.go | 20 +++++++++++++-------
whisk/client.go | 2 +-
whisk/sdk.go | 6 +++++-
whisk/util.go | 24 ++++++++++++++++++++++++
whisk/wskprops.go | 4 ++--
wski18n/i18n_resources.go | 22 +++++++++++-----------
wski18n/resources/en_US.all.json | 8 ++++++++
7 files changed, 64 insertions(+), 22 deletions(-)
diff --git a/whisk/action.go b/whisk/action.go
index e2cfed5..40dad4d 100644
--- a/whisk/action.go
+++ b/whisk/action.go
@@ -121,33 +121,39 @@ func (action Action) WebAction() (webExportValue bool) {
Returns the URL of an action as a string. A valid API host, path and version must be passed. A package that contains the
action must be passed as well. An empty string must be passed if the action is not packaged.
*/
-func (action Action) ActionURL(apiHost string, apiPath string, apiVersion string, pkg string) (actionURL string) {
- webActionPath := "https://%s%s/%s/web/%s/%s/%s"
- actionPath := "https://%s%s/%s/namespaces/%s/actions/%s"
+func (action Action) ActionURL(apiHost string, apiPath string, apiVersion string, pkg string) (string, error) {
+ baseURL, err := GetURLBase(apiHost, apiPath)
+ if err != nil {
+ Debug(DbgError, "GetURLBase(%s, %s) failed: %s\n", apiHost, apiPath, err)
+ return "", err
+ }
+ webActionPath := "%s/%s/web/%s/%s/%s"
+ actionPath := "%s/%s/namespaces/%s/actions/%s"
packagedActionPath := actionPath + "/%s"
namespace := strings.Split(action.Namespace, "/")[0]
namespace = strings.Replace(url.QueryEscape(namespace), "+", "%20", -1)
name := strings.Replace(url.QueryEscape(action.Name), "+", "%20", -1)
pkg = strings.Replace(url.QueryEscape(pkg), "+", "%20", -1)
+ var actionURL string
if action.WebAction() {
if len(pkg) == 0 {
pkg = "default"
}
- actionURL = fmt.Sprintf(webActionPath, apiHost, apiPath, apiVersion, namespace, pkg, name)
+ actionURL = fmt.Sprintf(webActionPath, baseURL, apiVersion, namespace, pkg, name)
Debug(DbgInfo, "Web action URL: %s\n", actionURL)
} else {
if len(pkg) == 0 {
- actionURL = fmt.Sprintf(actionPath, apiHost, apiPath, apiVersion, namespace, name)
+ actionURL = fmt.Sprintf(actionPath, baseURL, apiVersion, namespace, name)
Debug(DbgInfo, "Packaged action URL: %s\n", actionURL)
} else {
- actionURL = fmt.Sprintf(packagedActionPath, apiHost, apiPath, apiVersion, namespace, pkg, name)
+ actionURL = fmt.Sprintf(packagedActionPath, baseURL, apiVersion, namespace, pkg, name)
Debug(DbgInfo, "Action URL: %s\n", actionURL)
}
}
- return actionURL
+ return actionURL, nil
}
////////////////////
diff --git a/whisk/client.go b/whisk/client.go
index 5fe0b14..3d6b655 100644
--- a/whisk/client.go
+++ b/whisk/client.go
@@ -127,7 +127,7 @@ func NewClient(httpClient *http.Client, config_input *Config) (*Client, error) {
if len(config.Host) == 0 {
errStr = wski18n.T("Unable to create request URL, because OpenWhisk API host is missing")
} else if config.BaseURL == nil {
- config.BaseURL, err = GetURLBase(config.Host)
+ config.BaseURL, err = GetUrlBase(config.Host)
if err != nil {
Debug(DbgError, "Unable to create request URL, because the api host %s is invalid\n", config.Host, err)
errStr = wski18n.T("Unable to create request URL, because the api host '{{.host}}' is invalid: {{.err}}",
diff --git a/whisk/sdk.go b/whisk/sdk.go
index 9269a83..b0e8708 100644
--- a/whisk/sdk.go
+++ b/whisk/sdk.go
@@ -40,7 +40,11 @@ type SdkRequest struct {
// Install artifact {component = docker || swift || iOS}
func (s *SdkService) Install(relFileUrl string) (*http.Response, error) {
- urlStr := fmt.Sprintf("https://%s/%s", s.client.Config.BaseURL.Host, relFileUrl)
+ baseURL := s.client.Config.BaseURL
+ // Remove everything but the scheme, host, and port
+ baseURL.Path, baseURL.RawQuery, baseURL.Fragment = "", "", ""
+
+ urlStr := fmt.Sprintf("%s/%s", baseURL, relFileUrl)
req, err := http.NewRequest("GET", urlStr, nil)
if err != nil {
diff --git a/whisk/util.go b/whisk/util.go
index 329e9ea..9e1087d 100644
--- a/whisk/util.go
+++ b/whisk/util.go
@@ -22,6 +22,7 @@ import (
"fmt"
"net/url"
"reflect"
+ "strings"
"github.com/fatih/color"
"github.com/google/go-querystring/query"
@@ -80,3 +81,26 @@ func PrintJSON(v interface{}) {
output, _ := prettyjson.Marshal(v)
fmt.Fprintln(color.Output, string(output))
}
+
+func GetURLBase(host string, path string) (*url.URL, error) {
+ if len(host) == 0 {
+ errMsg := wski18n.T("An API host must be provided.\n")
+ whiskErr := MakeWskError(errors.New(errMsg), EXIT_CODE_ERR_GENERAL,
+ DISPLAY_MSG, 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
+}
diff --git a/whisk/wskprops.go b/whisk/wskprops.go
index 64f621c..c607c55 100644
--- a/whisk/wskprops.go
+++ b/whisk/wskprops.go
@@ -65,7 +65,7 @@ type Wskprops struct {
Source string
}
-func GetURLBase(host string) (*url.URL, error) {
+func GetUrlBase(host string) (*url.URL, error) {
urlBase := fmt.Sprintf("%s/api", host)
url, err := url.Parse(urlBase)
@@ -81,7 +81,7 @@ func convertWskpropsToConfig(dep *Wskprops) (*Config) {
var config Config
config.Host = dep.APIHost
if len(config.Host) != 0 {
- v, err := GetURLBase(config.Host)
+ v, err := GetUrlBase(config.Host)
if err == nil {
config.BaseURL = v
}
diff --git a/wski18n/i18n_resources.go b/wski18n/i18n_resources.go
index 9f839e3..206cd63 100644
--- a/wski18n/i18n_resources.go
+++ b/wski18n/i18n_resources.go
@@ -109,12 +109,12 @@ func wski18nResourcesDe_deAllJson() (*asset, error) {
return nil, err
}
- info := bindataFileInfo{name: "wski18n/resources/de_DE.all.json", size: 0, mode: os.FileMode(420), modTime: time.Unix(1500156160, 0)}
+ info := bindataFileInfo{name: "wski18n/resources/de_DE.all.json", size: 0, mode: os.FileMode(420), modTime: time.Unix(1506031186, 0)}
a := &asset{bytes: bytes, info: info}
return a, nil
}
-var _wski18nResourcesEn_usAllJson = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xcc\x98\x51\x8f\xe2\x36\x10\xc7\xdf\xf9\x14\xa3\xbc\x2c\x95\xb8\x7c\x80\xeb\x13\x6a\x51\x41\xbd\x1e\xa8\x07\xbd\x87\x6e\x55\x99\x78\x20\xa3\x0d\xb6\xcf\x76\xa0\x1c\xca\x77\xaf\xec\xc0\x1d\xbd\x4d\x48\x62\x72\xdb\x7d\xda\xc8\xeb\xf9\xcf\xcf\xe3\xb1\x3d\xc3\x9f\x03\x80\xd3\x00\x00\x20\x22\x1e\xbd\x85\x68\x25\xd8\x3a\x43\xb0\x12\x18\xe7\xa0\x65\x6e\x11\xa4\xb2\x24\x85\x81\x87\xd3\x29\x3e\x7f\x17\xc5\x43\x34 [...]
+var _wski18nResourcesEn_usAllJson = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xcc\x98\x51\x6f\xdb\x36\x10\xc7\xdf\xfd\x29\x0e\x7a\x71\x06\xb8\xfa\x00\xdd\x53\xb0\x19\x73\xb0\xae\x31\x56\x67\x7d\x58\x86\x81\x16\xcf\xd6\x21\x12\xc9\x92\x94\x3d\xd7\xd0\x77\x1f\x48\xd9\xb5\xd7\x48\x96\x44\x2b\x59\x9e\x62\x30\xbc\xff\xfd\x78\x3c\x1e\x8f\xfa\x73\x04\xb0\x1f\x01\x00\x44\xc4\xa3\xf7\x10\x3d\x08\xb6\xcc\x10\xac\x04\xc6\x39\x68\x59\x58\x04\xa9\x2c\x49\x61\x60\xbc\xdf\xc7\x87\xdf\x65\x39\x8e [...]
func wski18nResourcesEn_usAllJsonBytes() ([]byte, error) {
return bindataRead(
@@ -129,7 +129,7 @@ func wski18nResourcesEn_usAllJson() (*asset, error) {
return nil, err
}
- info := bindataFileInfo{name: "wski18n/resources/en_US.all.json", size: 6303, mode: os.FileMode(420), modTime: time.Unix(1503937683, 0)}
+ info := bindataFileInfo{name: "wski18n/resources/en_US.all.json", size: 6538, mode: os.FileMode(420), modTime: time.Unix(1506031828, 0)}
a := &asset{bytes: bytes, info: info}
return a, nil
}
@@ -149,7 +149,7 @@ func wski18nResourcesEs_esAllJson() (*asset, error) {
return nil, err
}
- info := bindataFileInfo{name: "wski18n/resources/es_ES.all.json", size: 0, mode: os.FileMode(420), modTime: time.Unix(1500156160, 0)}
+ info := bindataFileInfo{name: "wski18n/resources/es_ES.all.json", size: 0, mode: os.FileMode(420), modTime: time.Unix(1506031186, 0)}
a := &asset{bytes: bytes, info: info}
return a, nil
}
@@ -169,7 +169,7 @@ func wski18nResourcesFr_frAllJson() (*asset, error) {
return nil, err
}
- info := bindataFileInfo{name: "wski18n/resources/fr_FR.all.json", size: 0, mode: os.FileMode(420), modTime: time.Unix(1500156160, 0)}
+ info := bindataFileInfo{name: "wski18n/resources/fr_FR.all.json", size: 0, mode: os.FileMode(420), modTime: time.Unix(1506031186, 0)}
a := &asset{bytes: bytes, info: info}
return a, nil
}
@@ -189,7 +189,7 @@ func wski18nResourcesIt_itAllJson() (*asset, error) {
return nil, err
}
- info := bindataFileInfo{name: "wski18n/resources/it_IT.all.json", size: 0, mode: os.FileMode(420), modTime: time.Unix(1500156160, 0)}
+ info := bindataFileInfo{name: "wski18n/resources/it_IT.all.json", size: 0, mode: os.FileMode(420), modTime: time.Unix(1506031186, 0)}
a := &asset{bytes: bytes, info: info}
return a, nil
}
@@ -209,7 +209,7 @@ func wski18nResourcesJa_jaAllJson() (*asset, error) {
return nil, err
}
- info := bindataFileInfo{name: "wski18n/resources/ja_JA.all.json", size: 0, mode: os.FileMode(420), modTime: time.Unix(1500156160, 0)}
+ info := bindataFileInfo{name: "wski18n/resources/ja_JA.all.json", size: 0, mode: os.FileMode(420), modTime: time.Unix(1506031186, 0)}
a := &asset{bytes: bytes, info: info}
return a, nil
}
@@ -229,7 +229,7 @@ func wski18nResourcesKo_krAllJson() (*asset, error) {
return nil, err
}
- info := bindataFileInfo{name: "wski18n/resources/ko_KR.all.json", size: 0, mode: os.FileMode(420), modTime: time.Unix(1500156160, 0)}
+ info := bindataFileInfo{name: "wski18n/resources/ko_KR.all.json", size: 0, mode: os.FileMode(420), modTime: time.Unix(1506031186, 0)}
a := &asset{bytes: bytes, info: info}
return a, nil
}
@@ -249,7 +249,7 @@ func wski18nResourcesPt_brAllJson() (*asset, error) {
return nil, err
}
- info := bindataFileInfo{name: "wski18n/resources/pt_BR.all.json", size: 0, mode: os.FileMode(420), modTime: time.Unix(1500156160, 0)}
+ info := bindataFileInfo{name: "wski18n/resources/pt_BR.all.json", size: 0, mode: os.FileMode(420), modTime: time.Unix(1506031186, 0)}
a := &asset{bytes: bytes, info: info}
return a, nil
}
@@ -269,7 +269,7 @@ func wski18nResourcesZh_hansAllJson() (*asset, error) {
return nil, err
}
- info := bindataFileInfo{name: "wski18n/resources/zh_Hans.all.json", size: 0, mode: os.FileMode(420), modTime: time.Unix(1500156160, 0)}
+ info := bindataFileInfo{name: "wski18n/resources/zh_Hans.all.json", size: 0, mode: os.FileMode(420), modTime: time.Unix(1506031186, 0)}
a := &asset{bytes: bytes, info: info}
return a, nil
}
@@ -289,7 +289,7 @@ func wski18nResourcesZh_hantAllJson() (*asset, error) {
return nil, err
}
- info := bindataFileInfo{name: "wski18n/resources/zh_Hant.all.json", size: 0, mode: os.FileMode(420), modTime: time.Unix(1500156160, 0)}
+ info := bindataFileInfo{name: "wski18n/resources/zh_Hant.all.json", size: 0, mode: os.FileMode(420), modTime: time.Unix(1506031186, 0)}
a := &asset{bytes: bytes, info: info}
return a, nil
}
diff --git a/wski18n/resources/en_US.all.json b/wski18n/resources/en_US.all.json
index 8a8e83d..775cf4f 100644
--- a/wski18n/resources/en_US.all.json
+++ b/wski18n/resources/en_US.all.json
@@ -48,6 +48,14 @@
"translation": "Authorization key is not configured (--auth is required)"
},
{
+ "id": "An API host must be provided.\n",
+ "translation": "An API host must be provided.\n"
+ },
+ {
+ "id": "Unable to add route options '{{.options}}'",
+ "translation": "Unable to add route options: {{.options}}"
+ },
+ {
"id": "Command failed due to an HTTP failure",
"translation": "Command failed due to an HTTP failure"
},
--
To stop receiving notification emails like this one, please contact
['"commits@openwhisk.apache.org" <co...@openwhisk.apache.org>'].