You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openwhisk.apache.org by ho...@apache.org on 2017/07/17 01:30:08 UTC
[incubator-openwhisk-client-go] 01/04: Get Action URL from CLI
(#2461)
This is an automated email from the ASF dual-hosted git repository.
houshengbo pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-openwhisk-client-go.git
commit 9bbb68791a595120ce19a5728a1d19fa9edabe58
Author: James Dubee <jw...@us.ibm.com>
AuthorDate: Wed Jul 12 13:20:40 2017 -0400
Get Action URL from CLI (#2461)
---
whisk/action.go | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
whisk/shared.go | 21 +++++++++++++++++++--
2 files changed, 67 insertions(+), 2 deletions(-)
diff --git a/whisk/action.go b/whisk/action.go
index 985eb52..394e59b 100644
--- a/whisk/action.go
+++ b/whisk/action.go
@@ -23,6 +23,7 @@ import (
"errors"
"net/url"
"github.com/apache/incubator-openwhisk-client-go/wski18n"
+ "strings"
)
type ActionService struct {
@@ -57,6 +58,53 @@ type ActionListOptions struct {
Docs bool `url:"docs,omitempty"`
}
+/*
+Determines if an action is a web action by examining the action's annotations. A value of true is returned if the
+action's annotations contains a "web-export" key and its associated value is a boolean value of "true". Otherwise, false
+is returned.
+ */
+func (action Action) WebAction() (webExportValue bool) {
+ webExport := action.Annotations.GetValue("web-export")
+ webExportValue, _ = webExport.(bool)
+
+ Debug(DbgInfo, "Web export value is '%t'\n", webExportValue)
+
+ return webExportValue
+}
+
+/*
+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"
+ 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)
+
+ if action.WebAction() {
+ if len(pkg) == 0 {
+ pkg = "default"
+ }
+
+ actionURL = fmt.Sprintf(webActionPath, apiHost, apiPath, 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)
+ Debug(DbgInfo, "Packaged action URL: %s\n", actionURL)
+ } else {
+ actionURL = fmt.Sprintf(packagedActionPath, apiHost, apiPath, apiVersion, namespace, pkg, name)
+ Debug(DbgInfo, "Action URL: %s\n", actionURL)
+ }
+ }
+
+ return actionURL
+}
+
////////////////////
// Action Methods //
////////////////////
diff --git a/whisk/shared.go b/whisk/shared.go
index a39722f..f91787d 100644
--- a/whisk/shared.go
+++ b/whisk/shared.go
@@ -20,12 +20,29 @@ package whisk
import "encoding/json"
type KeyValue struct {
- Key string `json:"key"`
- Value interface{} `json:"value"`
+ Key string `json:"key"`
+ Value interface{} `json:"value"`
}
type KeyValueArr []KeyValue
+/*
+Retrieves a value associated with a given key from a KeyValueArr. A key of type string must be passed to the method.
+An interface will be returned containing the found value. If a key could not be found, a nil value will be returned.
+ */
+func (keyValueArr KeyValueArr) GetValue(key string) (res interface{}) {
+ for i := 0; i < len(keyValueArr); i++ {
+ if keyValueArr[i].Key == key {
+ res = keyValueArr[i].Value
+ break;
+ }
+ }
+
+ Debug(DbgInfo, "Got value '%v' for key '%s' from '%v'\n", res, key, keyValueArr)
+
+ return res
+}
+
type Annotations []map[string]interface{}
type Parameters *json.RawMessage
--
To stop receiving notification emails like this one, please contact
"commits@openwhisk.apache.org" <co...@openwhisk.apache.org>.