You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openwhisk.apache.org by mr...@apache.org on 2017/08/29 18:19:42 UTC
[incubator-openwhisk-client-go] branch master updated: Remove
bluemix URL as the default URL for client go (#33)
This is an automated email from the ASF dual-hosted git repository.
mrutkowski 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 6572868 Remove bluemix URL as the default URL for client go (#33)
6572868 is described below
commit 6572868460e856f5658a57fb64f98236b73aaee0
Author: Vincent <sh...@us.ibm.com>
AuthorDate: Tue Aug 29 14:19:41 2017 -0400
Remove bluemix URL as the default URL for client go (#33)
This PR makes sure the base URL is generated from the host in config
Closes-Bug: #25
---
whisk/client.go | 21 +++++---
whisk/client_test.go | 107 +++++++++++++++++++++++++++++++++++++++
wski18n/i18n_resources.go | 4 +-
wski18n/resources/en_US.all.json | 8 +++
4 files changed, 130 insertions(+), 10 deletions(-)
diff --git a/whisk/client.go b/whisk/client.go
index 8b9339f..985bc75 100644
--- a/whisk/client.go
+++ b/whisk/client.go
@@ -34,7 +34,6 @@ import (
)
const (
- defaultBaseURL = "openwhisk.ng.bluemix.net"
AuthRequired = true
NoAuth = false
IncludeNamespaceInUrl = true
@@ -119,17 +118,23 @@ func NewClient(httpClient *http.Client, config_input *Config) (*Client, error) {
}
var err error
- if config.BaseURL == nil {
- config.BaseURL, err = url.Parse(defaultBaseURL)
+ var errStr = ""
+ 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)
if err != nil {
- Debug(DbgError, "url.Parse(%s) error: %s\n", defaultBaseURL, err)
- errStr := wski18n.T("Unable to create request URL '{{.url}}': {{.err}}",
- map[string]interface{}{"url": defaultBaseURL, "err": err})
- werr := MakeWskError(errors.New(errStr), EXIT_CODE_ERR_GENERAL, DISPLAY_MSG, NO_DISPLAY_USAGE)
- return nil, werr
+ 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}}",
+ map[string]interface{}{"host": config.Host, "err": err})
}
}
+ if len(errStr) != 0 {
+ werr := MakeWskError(errors.New(errStr), EXIT_CODE_ERR_GENERAL, DISPLAY_MSG, NO_DISPLAY_USAGE)
+ return nil, werr
+ }
+
if len(config.Namespace) == 0 {
config.Namespace = "_"
}
diff --git a/whisk/client_test.go b/whisk/client_test.go
new file mode 100644
index 0000000..1b3e748
--- /dev/null
+++ b/whisk/client_test.go
@@ -0,0 +1,107 @@
+// +build unit
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package whisk
+
+import (
+ "testing"
+ "github.com/stretchr/testify/assert"
+ "net/http"
+ "fmt"
+ "net/url"
+)
+
+const (
+ FakeHost = "myUrl.com"
+ FakeHostDiff = "myUrlTest.com"
+ FakeBaseURL = "https://" + FakeHost + "/api"
+ FakeBaseURLDiff = "https://" + FakeHostDiff + "/api"
+ FakeNamespace = "my_namespace"
+ FakeAuthKey = "dhajfhshfs:hjhfsjfdjfjsgfjs"
+)
+
+func GetValidConfigTest() *Config {
+ var config Config
+ config.Host = FakeHost
+ config.Namespace = FakeNamespace
+ config.AuthToken = FakeAuthKey
+ return &config
+}
+
+func GetInvalidConfigMissingApiHostTest() *Config {
+ var config Config
+ config.Namespace = FakeNamespace
+ config.AuthToken = FakeAuthKey
+ return &config
+}
+
+func GetInvalidConfigMissingApiHostWithBaseURLTest() *Config {
+ var config Config
+ urlBase := fmt.Sprintf("https://%s/api", FakeHostDiff)
+ config.BaseURL, _ = url.Parse(urlBase)
+ config.Namespace = FakeNamespace
+ config.AuthToken = FakeAuthKey
+ return &config
+}
+
+func GetValidConfigDiffApiHostAndBaseURLTest() *Config {
+ var config Config
+ urlBase := fmt.Sprintf("https://%s/api", FakeHostDiff)
+ config.BaseURL, _ = url.Parse(urlBase)
+ config.Host = FakeHost
+ config.Namespace = FakeNamespace
+ config.AuthToken = FakeAuthKey
+ return &config
+}
+
+func TestNewClient(t *testing.T) {
+ // Test the use case to pass a valid config.
+ config := GetValidConfigTest()
+ client, err := NewClient(http.DefaultClient, config)
+ assert.Nil(t, err)
+ assert.NotNil(t, client)
+ assert.Equal(t, FakeNamespace, client.Config.Namespace)
+ assert.Equal(t, FakeHost, client.Config.Host)
+ assert.Equal(t, FakeBaseURL, client.Config.BaseURL.String())
+ assert.Equal(t, FakeAuthKey, client.Config.AuthToken)
+
+ // Test the use case to pass an invalid config with a missing api host.
+ config = GetInvalidConfigMissingApiHostTest()
+ client, err = NewClient(http.DefaultClient, config)
+ assert.NotNil(t, err)
+ assert.Contains(t, err.Error(), "Unable to create request URL, because OpenWhisk API host is missing")
+ assert.Nil(t, client)
+
+ // Test the use case to pass a valid config with the base url but without api host.
+ config = GetInvalidConfigMissingApiHostWithBaseURLTest()
+ client, err = NewClient(http.DefaultClient, config)
+ assert.NotNil(t, err)
+ assert.Contains(t, err.Error(), "Unable to create request URL, because OpenWhisk API host is missing")
+ assert.Nil(t, client)
+
+ // Test the use case to pass a valid config with both the base and api host of different values.
+ config = GetValidConfigDiffApiHostAndBaseURLTest()
+ client, err = NewClient(http.DefaultClient, config)
+ assert.Nil(t, err)
+ assert.NotNil(t, client)
+ assert.Equal(t, FakeNamespace, client.Config.Namespace)
+ assert.Equal(t, FakeHost, client.Config.Host)
+ assert.Equal(t, FakeBaseURLDiff, client.Config.BaseURL.String())
+ assert.Equal(t, FakeAuthKey, client.Config.AuthToken)
+}
diff --git a/wski18n/i18n_resources.go b/wski18n/i18n_resources.go
index 4050101..9f839e3 100644
--- a/wski18n/i18n_resources.go
+++ b/wski18n/i18n_resources.go
@@ -114,7 +114,7 @@ func wski18nResourcesDe_deAllJson() (*asset, error) {
return a, nil
}
-var _wski18nResourcesEn_usAllJson = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xcc\x97\xdf\x6f\xe2\x38\x10\xc7\xdf\xf9\x2b\x46\x79\x81\x93\x68\xfe\x80\xde\x13\xba\x43\x07\xba\x5e\x41\x57\xd8\x3e\x6c\x57\x2b\x37\x1e\x88\xd5\x60\xa7\x63\x07\x96\xa2\xfc\xef\x2b\x3b\xd0\xb2\x6d\x42\x7e\x90\x76\xfb\x44\x64\x3c\xdf\xf9\x78\x3c\xf6\x8c\xbf\x76\x00\x76\x1d\x00\x00\x4f\x70\xef\x12\xbc\xb9\x64\xf7\x11\x82\x51\xc0\x38\x07\x52\x89\x41\x50\xb1\x11\x4a\x6a\xe8\xee\x76\xfe\xfe\x3b\x4d\xbb\x5e\x3f [...]
+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 [...]
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: 5913, mode: os.FileMode(420), modTime: time.Unix(1503698750, 0)}
+ info := bindataFileInfo{name: "wski18n/resources/en_US.all.json", size: 6303, mode: os.FileMode(420), modTime: time.Unix(1503937683, 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 b09d382..8a8e83d 100644
--- a/wski18n/resources/en_US.all.json
+++ b/wski18n/resources/en_US.all.json
@@ -124,6 +124,14 @@
"translation": "The connection failed, or timed out. (HTTP status code {{.code}})"
},
{
+ "id": "Unable to create request URL, because OpenWhisk API host is missing",
+ "translation": "Unable to create request URL, because OpenWhisk API host is missing"
+ },
+ {
+ "id": "Unable to create request URL, because the api host '{{.host}}' is invalid: {{.err}}",
+ "translation": "Unable to create request URL, because the api host '{{.host}}' is invalid: {{.err}}"
+ },
+ {
"id": "OpenWhisk API host is missing (Please configure WHISK_APIHOST in .wskprops under the system HOME directory.)",
"translation": "OpenWhisk API host is missing (Please configure WHISK_APIHOST in .wskprops under the system HOME directory.)"
},
--
To stop receiving notification emails like this one, please contact
['"commits@openwhisk.apache.org" <co...@openwhisk.apache.org>'].