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-cli.git
commit 5b466804c18c68cae594f8126698bfe9244d8974 Author: James Dubee <[email protected]> AuthorDate: Wed Jul 12 13:20:40 2017 -0400 Get Action URL from CLI (#2461) --- commands/action.go | 58 +++++++++++++++++++++++----------------- commands/api.go | 6 ++--- commands/flags.go | 1 + commands/util.go | 19 ++----------- wski18n/resources/en_US.all.json | 4 +++ 5 files changed, 44 insertions(+), 44 deletions(-) diff --git a/commands/action.go b/commands/action.go index b4926d9..786e6f1 100644 --- a/commands/action.go +++ b/commands/action.go @@ -33,13 +33,13 @@ import ( "github.com/mattn/go-colorable" ) -const MEMORY_LIMIT = 256 -const TIMEOUT_LIMIT = 60000 -const LOGSIZE_LIMIT = 10 -const ACTIVATION_ID = "activationId" -const WEB_EXPORT_ANNOT = "web-export" -const RAW_HTTP_ANNOT = "raw-http" -const FINAL_ANNOT = "final" +const MEMORY_LIMIT = 256 +const TIMEOUT_LIMIT = 60000 +const LOGSIZE_LIMIT = 10 +const ACTIVATION_ID = "activationId" +const WEB_EXPORT_ANNOT = "web-export" +const RAW_HTTP_ANNOT = "raw-http" +const FINAL_ANNOT = "final" var actionCmd = &cobra.Command{ Use: "action", @@ -196,7 +196,7 @@ func handleInvocationResponse( } var actionGetCmd = &cobra.Command{ - Use: "get ACTION_NAME [FIELD_FILTER]", + Use: "get ACTION_NAME [FIELD_FILTER | --summary | --url]", Short: wski18n.T("get action"), SilenceUsage: true, SilenceErrors: true, @@ -211,7 +211,7 @@ var actionGetCmd = &cobra.Command{ return whiskErr } - if len(args) > 1 { + if !Flags.action.url && !Flags.common.summary && len(args) > 1 { field = args[1] if !fieldExists(&whisk.Action{}, field) { @@ -229,7 +229,13 @@ var actionGetCmd = &cobra.Command{ return actionGetError(qualifiedName.entityName, err) } - if Flags.common.summary { + if Flags.action.url { + actionURL := action.ActionURL(Properties.APIHost, + DefaultOpenWhiskApiPath, + Properties.APIVersion, + qualifiedName.packageName) + printActionGetWithURL(qualifiedName.entity, actionURL) + } else if Flags.common.summary { printSummary(action) } else { if len(field) > 0 { @@ -823,6 +829,17 @@ func printActionGetWithField(entityName string, field string, action *whisk.Acti printField(action, field) } +func printActionGetWithURL(entityName string, actionURL string) { + fmt.Fprintf( + color.Output, + wski18n.T("{{.ok}} got action {{.name}}\n", + map[string]interface{}{ + "ok": color.GreenString("ok:"), + "name": boldString(entityName), + })) + fmt.Println(actionURL) +} + func printActionGet(entityName string, action *whisk.Action) { fmt.Fprintf( color.Output, @@ -847,7 +864,7 @@ func printActionDeleted(entityName string) { } // Check if the specified action is a web-action -func isWebAction(client *whisk.Client, qname QualifiedName) error { +func isWebAction(client *whisk.Client, qname QualifiedName) (error) { var err error = nil savedNs := client.Namespace @@ -855,6 +872,7 @@ func isWebAction(client *whisk.Client, qname QualifiedName) error { fullActionName := "/" + qname.namespace + "/" + qname.entityName action, _, err := client.Actions.Get(qname.entityName) + if err != nil { whisk.Debug(whisk.DbgError, "client.Actions.Get(%s) error: %s\n", fullActionName, err) whisk.Debug(whisk.DbgError, "Unable to obtain action '%s' for web action validation\n", fullActionName) @@ -865,23 +883,14 @@ func isWebAction(client *whisk.Client, qname QualifiedName) error { } else { err = errors.New(wski18n.T("Action '{{.name}}' is not a web action. Issue 'wsk action update {{.name}} --web true' to convert the action to a web action.", map[string]interface{}{"name": fullActionName})) - weVal := getValue(action.Annotations, "web-export") - if (weVal == nil) { - whisk.Debug(whisk.DbgError, "getValue(annotations, web-export) for action %s found no value\n", fullActionName) - } else { - var webExport bool - var ok bool - if webExport, ok = weVal.(bool); !ok { - whisk.Debug(whisk.DbgError, "web-export annotation value (%v) is not a boolean\n", weVal) - } else if !webExport { - whisk.Debug(whisk.DbgError, "web-export annotation value is false\n", weVal) - } else { - err = nil - } + + if action.WebAction() { + err = nil } } client.Namespace = savedNs + return err } @@ -922,6 +931,7 @@ func init() { actionInvokeCmd.Flags().BoolVarP(&Flags.action.result, "result", "r", false, wski18n.T("blocking invoke; show only activation result (unless there is a failure)")) actionGetCmd.Flags().BoolVarP(&Flags.common.summary, "summary", "s", false, wski18n.T("summarize action details")) + actionGetCmd.Flags().BoolVarP(&Flags.action.url, "url", "r", false, wski18n.T("get action url")) actionListCmd.Flags().IntVarP(&Flags.common.skip, "skip", "s", 0, wski18n.T("exclude the first `SKIP` number of actions from the result")) actionListCmd.Flags().IntVarP(&Flags.common.limit, "limit", "l", 30, wski18n.T("only return `LIMIT` number of actions from the collection")) diff --git a/commands/api.go b/commands/api.go index 968c8b7..b58b4ed 100644 --- a/commands/api.go +++ b/commands/api.go @@ -1567,9 +1567,9 @@ func getUserContextId() (string, error) { func init() { apiCreateCmd.Flags().StringVarP(&Flags.api.apiname, "apiname", "n", "", wski18n.T("Friendly name of the API; ignored when CFG_FILE is specified (default BASE_PATH)")) apiCreateCmd.Flags().StringVarP(&Flags.api.configfile, "config-file", "c", "", wski18n.T("`CFG_FILE` containing API configuration in swagger JSON format")) - //apiUpdateCmd.Flags().StringVarP(&flags.api.action, "action", "a", "", wski18n.T("`ACTION` to invoke when API is called")) - //apiUpdateCmd.Flags().StringVarP(&flags.api.path, "path", "p", "", wski18n.T("relative `PATH` of API")) - //apiUpdateCmd.Flags().StringVarP(&flags.api.verb, "method", "m", "", wski18n.T("API `VERB`")) + //apiUpdateCmd.Flags().StringVarP(&Flags.api.action, "action", "a", "", wski18n.T("`ACTION` to invoke when API is called")) + //apiUpdateCmd.Flags().StringVarP(&Flags.api.path, "path", "p", "", wski18n.T("relative `PATH` of API")) + //apiUpdateCmd.Flags().StringVarP(&Flags.api.verb, "method", "m", "", wski18n.T("API `VERB`")) apiGetCmd.Flags().BoolVarP(&Flags.common.detail, "full", "f", false, wski18n.T("display full API configuration details")) apiListCmd.Flags().IntVarP(&Flags.common.skip, "skip", "s", 0, wski18n.T("exclude the first `SKIP` number of actions from the result")) apiListCmd.Flags().IntVarP(&Flags.common.limit, "limit", "l", 30, wski18n.T("only return `LIMIT` number of actions from the collection")) diff --git a/commands/flags.go b/commands/flags.go index 5695be8..4dbf12a 100644 --- a/commands/flags.go +++ b/commands/flags.go @@ -126,6 +126,7 @@ type ActionFlags struct { result bool kind string main string + url bool } func IsVerbose() bool { diff --git a/commands/util.go b/commands/util.go index 96e205a..e010914 100644 --- a/commands/util.go +++ b/commands/util.go @@ -488,26 +488,11 @@ func getKeys(keyValueArr whisk.KeyValueArr) ([]string) { return res } -func getValue(keyValueArr whisk.KeyValueArr, key string) (interface{}) { - var res interface{} - - for i := 0; i < len(keyValueArr); i++ { - if keyValueArr[i].Key == key { - res = keyValueArr[i].Value - break; - } - } - - whisk.Debug(whisk.DbgInfo, "Got value '%v' from '%v' for key '%s'\n", res, keyValueArr, key) - - return res -} - func getValueString(keyValueArr whisk.KeyValueArr, key string) (string) { var value interface{} var res string - value = getValue(keyValueArr, key) + value = keyValueArr.GetValue(key) castedValue, canCast := value.(string) if (canCast) { @@ -523,7 +508,7 @@ func getChildValues(keyValueArr whisk.KeyValueArr, key string, childKey string) var value interface{} var res []interface{} - value = getValue(keyValueArr, key) + value = keyValueArr.GetValue(key) castedValue, canCast := value.([]interface{}) if canCast { diff --git a/wski18n/resources/en_US.all.json b/wski18n/resources/en_US.all.json index ec409ad..bcc776d 100644 --- a/wski18n/resources/en_US.all.json +++ b/wski18n/resources/en_US.all.json @@ -1466,5 +1466,9 @@ { "id": "An entity name, '{{.name}}', was provided instead of a namespace. Valid namespaces are of the following format: /NAMESPACE.", "translation": "An entity name, '{{.name}}', was provided instead of a namespace. Valid namespaces are of the following format: /NAMESPACE." + }, + { + "id": "get action url", + "translation": "get action url" } ] -- To stop receiving notification emails like this one, please contact "[email protected]" <[email protected]>.
