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/05/11 14:40:15 UTC

[incubator-openwhisk-cli] branch master updated (2ead5a4 -> 6af3ba1)

This is an automated email from the ASF dual-hosted git repository.

houshengbo pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-openwhisk-cli.git.

      from  2ead5a4   Run the test cases under openwhisk to ensure the quality of the binary
       new  36fd347   Add wsk cli support for importing/exporting API configuration in YAML format (#2209)
       new  6af3ba1   Update the i18n_resources to sync up with openwhisk

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "adds" were already present in the repository and have only
been added to this reference.


Summary of changes:
 Godeps/Godeps.json               | 11 +++++---
 commands/action.go               |  2 +-
 commands/api.go                  | 55 +++++++++++++++++++++++++++++++++++++++-
 commands/flags.go                |  1 +
 wski18n/i18n_resources.go        | 22 ++++++++--------
 wski18n/resources/en_US.all.json | 20 +++++++++++++--
 6 files changed, 93 insertions(+), 18 deletions(-)

-- 
To stop receiving notification emails like this one, please contact
['"commits@openwhisk.apache.org" <co...@openwhisk.apache.org>'].

[incubator-openwhisk-cli] 01/02: Add wsk cli support for importing/exporting API configuration in YAML format (#2209)

Posted by ho...@apache.org.
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 36fd34774fa8679f1708b3eaf41fc1a5ffa5a46a
Author: Mark Deuser <md...@us.ibm.com>
AuthorDate: Wed May 10 16:18:04 2017 -0400

    Add wsk cli support for importing/exporting API configuration in YAML format (#2209)
    
    * Update CLI to support YAML API configuration
    - `wsk api get --format yaml`
    - wsk api create --config-file api.yaml
    
    * YAML API configuration tests
    
    * Code review updates
    
    * Improve action throttling check
---
 Godeps/Godeps.json               | 13 +++++++---
 commands/action.go               |  2 +-
 commands/api.go                  | 55 +++++++++++++++++++++++++++++++++++++++-
 commands/flags.go                |  1 +
 wski18n/resources/en_US.all.json | 20 +++++++++++++--
 5 files changed, 83 insertions(+), 8 deletions(-)

diff --git a/Godeps/Godeps.json b/Godeps/Godeps.json
index 39b2b7a..861a221 100644
--- a/Godeps/Godeps.json
+++ b/Godeps/Godeps.json
@@ -71,15 +71,20 @@
 		},
 		{
 			"ImportPath": "gopkg.in/yaml.v2",
-			"Rev": "e4d366fc3c7938e2958e662b4258c7a89e1f0e3e"
+			"Rev": "cd8b52f8269e0feb286dfeef29f8fe4d5b397e0b"
 		},
 		{
-			"ImportPath": "github.com/apache/incubator-openwhisk-client-go/whisk",
-			"Rev": "62ddca28397566aaa46ac06484d79bd6da74011f"
+			"ImportPath": "github.com/ghodss/yaml",
+			"Comment": "v1.0.0",
+			"Rev": "0ca9ea5df5451ffdf184b4428c902747c2c11cd7"
 		},
         {
+            "ImportPath": "github.com/apache/incubator-openwhisk-client-go/whisk",
+            "Rev": "62ddca28397566aaa46ac06484d79bd6da74011f"
+        },
+        {
             "ImportPath": "github.com/apache/incubator-openwhisk-client-go/wski18n",
             "Rev": "62ddca28397566aaa46ac06484d79bd6da74011f"
-        }
+        },
 	]
 }
diff --git a/commands/action.go b/commands/action.go
index b3f543c..21373a1 100644
--- a/commands/action.go
+++ b/commands/action.go
@@ -849,7 +849,7 @@ func isWebAction(client *whisk.Client, qname QualifiedName) error {
     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)
-        err = errors.New(wski18n.T("API action does not exist"))
+        err = errors.New(wski18n.T("API action '{{.name}}' does not exist", map[string]interface{}{"name": fullActionName}))
     } else {
         err = errors.New(wski18n.T("API 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}))
diff --git a/commands/api.go b/commands/api.go
index 53a5729..8587fef 100644
--- a/commands/api.go
+++ b/commands/api.go
@@ -17,6 +17,8 @@
 package commands
 
 import (
+    "bytes"
+    "bufio"
     "errors"
     "fmt"
     "reflect"
@@ -27,10 +29,19 @@ import (
     "github.com/apache/incubator-openwhisk-cli/wski18n"
 
     "github.com/fatih/color"
+    "github.com/ghodss/yaml"
     "github.com/spf13/cobra"
     "encoding/json"
 )
 
+const (
+    yamlFileExtension = "yaml"
+    ymlFileExtension = "yml"
+
+    formatOptionYaml = "yaml"
+    formatOptionJson = "json"
+)
+
 //////////////
 // Commands //
 //////////////
@@ -897,6 +908,15 @@ var apiGetCmdV2 = &cobra.Command{
             return whiskErr
         }
 
+        if ( cmd.LocalFlags().Changed("format") &&
+             strings.ToLower(Flags.common.format) != formatOptionYaml &&
+             strings.ToLower(Flags.common.format) != formatOptionJson) {
+            errMsg := wski18n.T("Invalid format type: {{.type}}", map[string]interface{}{"type": Flags.common.format})
+            whiskErr := whisk.MakeWskError(errors.New(errMsg), whisk.EXITCODE_ERR_GENERAL,
+                whisk.DISPLAY_MSG, whisk.NO_DISPLAY_USAGE)
+            return whiskErr
+        }
+
         apiGetReq := new(whisk.ApiGetRequest)
         apiGetReqOptions := new(whisk.ApiGetRequestOptions)
         apiGetReqOptions.ApiBasePath = args[0]
@@ -948,7 +968,24 @@ var apiGetCmdV2 = &cobra.Command{
                 whisk.DISPLAY_MSG, whisk.NO_DISPLAY_USAGE)
             return whiskErr
         }
-        printJSON(displayResult)
+
+        if ( cmd.LocalFlags().Changed("format") && strings.ToLower(Flags.common.format) == formatOptionYaml ) {
+            var jsonOutputBuffer bytes.Buffer
+            var jsonOutputWriter = bufio.NewWriter(&jsonOutputBuffer)
+            printJSON(displayResult, jsonOutputWriter)
+            jsonOutputWriter.Flush()
+            yamlbytes, err := yaml.JSONToYAML(jsonOutputBuffer.Bytes())
+            if err != nil {
+                whisk.Debug(whisk.DbgError, "yaml.JSONToYAML() error: %s\n", err)
+                errMsg := wski18n.T("Unable to convert API into YAML: {{.err}}", map[string]interface{}{"err": err})
+                whiskErr := whisk.MakeWskError(errors.New(errMsg), whisk.EXITCODE_ERR_GENERAL,
+                    whisk.DISPLAY_MSG, whisk.NO_DISPLAY_USAGE)
+                return whiskErr
+            }
+            fmt.Println(string(yamlbytes))
+        } else {
+            printJSON(displayResult)
+        }
 
         return nil
     },
@@ -1421,6 +1458,21 @@ func parseSwaggerApiV2() (*whisk.Api, error) {
         return nil, whiskErr
     }
 
+    // Check if this swagger is in JSON or YAML format
+    isYaml := strings.HasSuffix(Flags.api.configfile, yamlFileExtension) || strings.HasSuffix(Flags.api.configfile, ymlFileExtension)
+    if isYaml {
+        whisk.Debug(whisk.DbgInfo, "Converting YAML formated API configuration into JSON\n")
+        jsonbytes, err := yaml.YAMLToJSON([]byte(swagger))
+        if err != nil {
+            whisk.Debug(whisk.DbgError, "yaml.YAMLToJSON() error: %s\n", err)
+            errMsg := wski18n.T("Unable to parse YAML configuration file: {{.err}}", map[string]interface{}{"err": err})
+            whiskErr := whisk.MakeWskError(errors.New(errMsg), whisk.EXITCODE_ERR_GENERAL,
+                whisk.DISPLAY_MSG, whisk.NO_DISPLAY_USAGE)
+            return nil, whiskErr
+        }
+        swagger = string(jsonbytes)
+    }
+
     // Parse the JSON into a swagger object
     swaggerObj := new(whisk.ApiSwaggerV2)
     err = json.Unmarshal([]byte(swagger), swaggerObj)
@@ -1520,6 +1572,7 @@ func init() {
     apiCreateCmdV2.Flags().StringVarP(&Flags.api.configfile, "config-file", "c", "", wski18n.T("`CFG_FILE` containing API configuration in swagger JSON format"))
     apiCreateCmdV2.Flags().StringVar(&Flags.api.resptype, "response-type", "json", wski18n.T("Set the web action response `TYPE`. Possible values are html, http, json, text, svg"))
     apiGetCmdV2.Flags().BoolVarP(&Flags.common.detail, "full", "f", false, wski18n.T("display full API configuration details"))
+    apiGetCmdV2.Flags().StringVarP(&Flags.common.format, "format", "", formatOptionJson, wski18n.T("Specify the API output `TYPE`, either json or yaml"))
     apiListCmdV2.Flags().IntVarP(&Flags.common.skip, "skip", "s", 0, wski18n.T("exclude the first `SKIP` number of actions from the result"))
     apiListCmdV2.Flags().IntVarP(&Flags.common.limit, "limit", "l", 30, wski18n.T("only return `LIMIT` number of actions from the collection"))
     apiListCmdV2.Flags().BoolVarP(&Flags.common.full, "full", "f", false, wski18n.T("display full description of each API"))
diff --git a/commands/flags.go b/commands/flags.go
index 4c2b0a9..7a7964a 100644
--- a/commands/flags.go
+++ b/commands/flags.go
@@ -55,6 +55,7 @@ var Flags struct {
         summary     bool
         feed        string  // name of feed
         detail      bool
+        format      string
     }
 
     property struct {
diff --git a/wski18n/resources/en_US.all.json b/wski18n/resources/en_US.all.json
index 92c934b..e173b42 100644
--- a/wski18n/resources/en_US.all.json
+++ b/wski18n/resources/en_US.all.json
@@ -1380,8 +1380,8 @@
     "translation": "Invalid argument '{{.arg}}' for --web flag. Valid input consist of 'yes', 'true', 'raw', 'false', or 'no'."
   },
   {
-    "id": "API action does not exist",
-    "translation": "API action does not exist"
+    "id": "API action '{{.name}}' does not exist",
+    "translation": "API action '{{.name}}' does not exist"
   },
   {
     "id": "API action '{{.name}}' is not a web action. Issue 'wsk action update {{.name}} --web true' to convert the action to a web action.",
@@ -1446,5 +1446,21 @@
   {
     "id": "Authorization key is not configured (--auth is required)",
     "translation": "Authorization key is not configured (--auth is required)"
+  },
+  {
+    "id": "Specify the API output `TYPE`, either json or yaml",
+    "translation": "Specify the API output `TYPE`, either json or yaml"
+  },
+  {
+    "id": "Unable to parse YAML configuration file: {{.err}}",
+    "translation": "Unable to parse YAML configuration file: {{.err}}"
+  },
+  {
+    "id": "Unable to convert API into YAML: {{.err}}",
+    "translation": "Unable to convert API into YAML: {{.err}}"
+  },
+  {
+    "id": "Invalid format type: {{.type}}",
+    "translation": "Invalid format type: {{.type}}"
   }
 ]

-- 
To stop receiving notification emails like this one, please contact
"commits@openwhisk.apache.org" <co...@openwhisk.apache.org>.

[incubator-openwhisk-cli] 02/02: Update the i18n_resources to sync up with openwhisk

Posted by ho...@apache.org.
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 6af3ba1c82e4a0666e9d78163c5e758c9575ebbe
Author: Vincent Hou <sh...@us.ibm.com>
AuthorDate: Thu May 11 10:37:49 2017 -0400

    Update the i18n_resources to sync up with openwhisk
---
 Godeps/Godeps.json        |  2 +-
 wski18n/i18n_resources.go | 22 +++++++++++-----------
 2 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/Godeps/Godeps.json b/Godeps/Godeps.json
index 861a221..18e62de 100644
--- a/Godeps/Godeps.json
+++ b/Godeps/Godeps.json
@@ -85,6 +85,6 @@
         {
             "ImportPath": "github.com/apache/incubator-openwhisk-client-go/wski18n",
             "Rev": "62ddca28397566aaa46ac06484d79bd6da74011f"
-        },
+        }
 	]
 }
diff --git a/wski18n/i18n_resources.go b/wski18n/i18n_resources.go
index 4d7f266..6c33e8e 100644
--- a/wski18n/i18n_resources.go
+++ b/wski18n/i18n_resources.go
@@ -92,12 +92,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(1494253819, 0)}
+	info := bindataFileInfo{name: "wski18n/resources/de_DE.all.json", size: 0, mode: os.FileMode(420), modTime: time.Unix(1494512602, 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\x5d\x5f\x73\xdb\xb6\xb2\x7f\xef\xa7\xd8\xe9\x8b\x9d\x19\xdb\x39\xe7\xe9\xce\x4d\xa7\x0f\x6a\xe2\x9e\xe8\x24\xb1\x3d\x91\xd3\x73\x3a\xb7\x77\x2a\x88\x84\x24\xd4\x14\xc0\x02\xa0\x15\x25\xc7\xdf\xfd\x0e\x00\x92\x22\x25\xfc\x25\xe5\xe6\x3e\xc5\x11\x77\x7f\xbb\xf8\xbf\x58\xec\x02\xff\xf3\x1d\xc0\xd7\xef\x00\x00\xbe\x27\xf9\xf7\xaf\xe0\xfb\x49\x59\x16\x24\x43\x92\x30\x0a\xf8\x33\x91\x38\x87\x8a\xe2\xcf\x25 [...]
+var _wski18nResourcesEn_usAllJson = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xcc\x5d\x5f\x73\xdb\x38\x92\x7f\x9f\x4f\xd1\x95\x17\x3b\x55\xb6\xb3\xfb\x74\x75\x99\x9a\x07\x4d\xe2\xd9\x78\x93\xd8\xae\xc8\x99\xdd\xa9\x9b\xab\x11\x44\x42\x12\xc6\x14\xc0\x01\x40\x2b\x8a\xd7\xdf\xfd\x0a\x00\x49\x91\x12\xfe\x92\x72\x72\x4f\x71\xc4\xee\x5f\x37\xfe\x37\x1a\xdd\xc0\xff\xfc\x00\xf0\xf8\x03\x00\xc0\x0b\x92\xbf\x78\x0d\x2f\x26\x65\x59\x90\x0c\x49\xc2\x28\xe0\x2f\x44\xe2\x1c\x2a\x8a\xbf\x94\x38 [...]
 
 func wski18nResourcesEn_usAllJsonBytes() ([]byte, error) {
 	return bindataRead(
@@ -112,7 +112,7 @@ func wski18nResourcesEn_usAllJson() (*asset, error) {
 		return nil, err
 	}
 
-	info := bindataFileInfo{name: "wski18n/resources/en_US.all.json", size: 47063, mode: os.FileMode(420), modTime: time.Unix(1494254127, 0)}
+	info := bindataFileInfo{name: "wski18n/resources/en_US.all.json", size: 47607, mode: os.FileMode(420), modTime: time.Unix(1494512852, 0)}
 	a := &asset{bytes: bytes, info: info}
 	return a, nil
 }
@@ -132,7 +132,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(1494253819, 0)}
+	info := bindataFileInfo{name: "wski18n/resources/es_ES.all.json", size: 0, mode: os.FileMode(420), modTime: time.Unix(1494512602, 0)}
 	a := &asset{bytes: bytes, info: info}
 	return a, nil
 }
@@ -152,7 +152,7 @@ func wski18nResourcesFr_frAllJson() (*asset, error) {
 		return nil, err
 	}
 
-	info := bindataFileInfo{name: "wski18n/resources/fr_FR.all.json", size: 101, mode: os.FileMode(420), modTime: time.Unix(1494253819, 0)}
+	info := bindataFileInfo{name: "wski18n/resources/fr_FR.all.json", size: 101, mode: os.FileMode(420), modTime: time.Unix(1494512602, 0)}
 	a := &asset{bytes: bytes, info: info}
 	return a, nil
 }
@@ -172,7 +172,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(1494253819, 0)}
+	info := bindataFileInfo{name: "wski18n/resources/it_IT.all.json", size: 0, mode: os.FileMode(420), modTime: time.Unix(1494512602, 0)}
 	a := &asset{bytes: bytes, info: info}
 	return a, nil
 }
@@ -192,7 +192,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(1494253819, 0)}
+	info := bindataFileInfo{name: "wski18n/resources/ja_JA.all.json", size: 0, mode: os.FileMode(420), modTime: time.Unix(1494512602, 0)}
 	a := &asset{bytes: bytes, info: info}
 	return a, nil
 }
@@ -212,7 +212,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(1494253819, 0)}
+	info := bindataFileInfo{name: "wski18n/resources/ko_KR.all.json", size: 0, mode: os.FileMode(420), modTime: time.Unix(1494512602, 0)}
 	a := &asset{bytes: bytes, info: info}
 	return a, nil
 }
@@ -232,7 +232,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(1494253819, 0)}
+	info := bindataFileInfo{name: "wski18n/resources/pt_BR.all.json", size: 0, mode: os.FileMode(420), modTime: time.Unix(1494512602, 0)}
 	a := &asset{bytes: bytes, info: info}
 	return a, nil
 }
@@ -252,7 +252,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(1494253819, 0)}
+	info := bindataFileInfo{name: "wski18n/resources/zh_Hans.all.json", size: 0, mode: os.FileMode(420), modTime: time.Unix(1494512602, 0)}
 	a := &asset{bytes: bytes, info: info}
 	return a, nil
 }
@@ -272,7 +272,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(1494253819, 0)}
+	info := bindataFileInfo{name: "wski18n/resources/zh_Hant.all.json", size: 0, mode: os.FileMode(420), modTime: time.Unix(1494512602, 0)}
 	a := &asset{bytes: bytes, info: info}
 	return a, nil
 }

-- 
To stop receiving notification emails like this one, please contact
"commits@openwhisk.apache.org" <co...@openwhisk.apache.org>.