You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openwhisk.apache.org by pd...@apache.org on 2018/09/13 18:36:13 UTC

[incubator-openwhisk-wskdeploy] branch master updated: adding recursive call to interpolate JSON (#980)

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

pdesai pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-openwhisk-wskdeploy.git


The following commit(s) were added to refs/heads/master by this push:
     new 785d887  adding recursive call to interpolate JSON (#980)
785d887 is described below

commit 785d8871f313b033fa322de1d3a8fc56e0be6abd
Author: Priti Desai <pd...@us.ibm.com>
AuthorDate: Thu Sep 13 11:36:08 2018 -0700

    adding recursive call to interpolate JSON (#980)
---
 parsers/manifest_parser_test.go              | 30 +++++++++++++++++++++++-
 parsers/parameters.go                        | 14 +++++++++---
 tests/dat/manifest_validate_json_params.yaml | 31 +++++++++++++++++++++++++
 wski18n/i18n_resources.go                    | 34 ++++++++++++++--------------
 4 files changed, 88 insertions(+), 21 deletions(-)

diff --git a/parsers/manifest_parser_test.go b/parsers/manifest_parser_test.go
index ec7dc24..87bda54 100644
--- a/parsers/manifest_parser_test.go
+++ b/parsers/manifest_parser_test.go
@@ -1254,7 +1254,7 @@ func TestParseManifestForJSONParams(t *testing.T) {
 		assert.Equal(t, expectedResult, actualResult, TEST_MSG_ACTION_FUNCTION_RUNTIME_MISMATCH)
 
 		// validate the number of inputs to this action
-		expectedResult = strconv.FormatInt(8, 10)
+		expectedResult = strconv.FormatInt(15, 10)
 		actualResult = strconv.FormatInt(int64(len(action.Inputs)), 10)
 		assert.Equal(t, expectedResult, actualResult, TEST_MSG_PARAMETER_NUMBER_MISMATCH)
 
@@ -1295,6 +1295,34 @@ func TestParseManifestForJSONParams(t *testing.T) {
 				actualResult8 := param.Value.(map[interface{}]interface{})
 				expectedResult8 := map[interface{}]interface{}{"name": "$${USERNAME}", "password": "$${PASSWORD}"}
 				assert.Equal(t, expectedResult8, actualResult8, fmt.Sprintf(TEST_MSG_ACTION_PARAMETER_VALUE_MISMATCH, input))
+			case "member9":
+				actualResult9 := param.Value.(map[interface{}]interface{})
+				expectedResult9 := map[interface{}]interface{}{"data": map[interface{}]interface{}{"name": "$USERNAME"}}
+				assert.Equal(t, expectedResult9, actualResult9, fmt.Sprintf(TEST_MSG_ACTION_PARAMETER_VALUE_MISMATCH, input))
+			case "member10":
+				actualResult10 := param.Value.(map[interface{}]interface{})
+				expectedResult10 := map[interface{}]interface{}{"data": map[interface{}]interface{}{"auth": map[interface{}]interface{}{"username": "$USERNAME", "password": "$PASSWORD"}}}
+				assert.Equal(t, expectedResult10, actualResult10, fmt.Sprintf(TEST_MSG_ACTION_PARAMETER_VALUE_MISMATCH, input))
+			case "member11":
+				actualResult11 := param.Value.(map[interface{}]interface{})
+				expectedResult11 := map[interface{}]interface{}{"data": map[interface{}]interface{}{"auth": map[interface{}]interface{}{"username": "$${USERNAME}", "password": "$${PASSWORD}"}}}
+				assert.Equal(t, expectedResult11, actualResult11, fmt.Sprintf(TEST_MSG_ACTION_PARAMETER_VALUE_MISMATCH, input))
+			case "member12":
+				actualResult12 := param.Value.(map[interface{}]interface{})
+				expectedResult12 := map[interface{}]interface{}{"name": "${USERNAME}", "password": "${PASSWORD}"}
+				assert.Equal(t, expectedResult12, actualResult12, fmt.Sprintf(TEST_MSG_ACTION_PARAMETER_VALUE_MISMATCH, input))
+			case "member13":
+				actualResult13 := param.Value.(map[interface{}]interface{})
+				expectedResult13 := map[interface{}]interface{}{"data": map[interface{}]interface{}{"name": "$USERNAME"}}
+				assert.Equal(t, expectedResult13, actualResult13, fmt.Sprintf(TEST_MSG_ACTION_PARAMETER_VALUE_MISMATCH, input))
+			case "member14":
+				actualResult14 := param.Value.(map[interface{}]interface{})
+				expectedResult14 := map[interface{}]interface{}{"data": map[interface{}]interface{}{"name": map[interface{}]interface{}{"username": "$USERNAME"}}}
+				assert.Equal(t, expectedResult14, actualResult14, fmt.Sprintf(TEST_MSG_ACTION_PARAMETER_VALUE_MISMATCH, input))
+			case "member15":
+				actualResult15 := param.Value.(map[interface{}]interface{})
+				expectedResult15 := map[interface{}]interface{}{"data": map[interface{}]interface{}{"name": map[interface{}]interface{}{"username": "$${USERNAME}"}}}
+				assert.Equal(t, expectedResult15, actualResult15, fmt.Sprintf(TEST_MSG_ACTION_PARAMETER_VALUE_MISMATCH, input))
 			}
 		}
 
diff --git a/parsers/parameters.go b/parsers/parameters.go
index cbf7a4d..c9d9f85 100644
--- a/parsers/parameters.go
+++ b/parsers/parameters.go
@@ -230,6 +230,16 @@ func resolveMultiLineParameter(filePath string, paramName string, param *Paramet
 
 	return param.Value, errorParser
 }
+func interpolateJSON(data map[string]interface{}) map[string]interface{} {
+	for key, value := range data {
+		if reflect.TypeOf(value).Kind() == reflect.String {
+			data[key] = wskenv.InterpolateStringWithEnvVar(value)
+		} else if reflect.TypeOf(value).Kind() == reflect.Map {
+			data[key] = interpolateJSON(value.(map[string]interface{}))
+		}
+	}
+	return data
+}
 
 /*
    resolveJSONParameter assure JSON data is converted to a map[string]{interface*} type.
@@ -268,9 +278,7 @@ func resolveJSONParameter(filePath string, paramName string, param *Parameter, v
 		if param.Value != nil && reflect.TypeOf(param.Value).Kind() == reflect.Map {
 			if _, ok := param.Value.(map[interface{}]interface{}); ok {
 				var temp map[string]interface{} = utils.ConvertInterfaceMap(param.Value.(map[interface{}]interface{}))
-				for name, val := range temp {
-					temp[name] = wskenv.InterpolateStringWithEnvVar(val)
-				}
+				temp = interpolateJSON(temp)
 				//fmt.Printf("EXIT: Parameter [%s] type=[%v] value=[%v]\n", paramName, param.Type, temp)
 				return temp, errorParser
 			}
diff --git a/tests/dat/manifest_validate_json_params.yaml b/tests/dat/manifest_validate_json_params.yaml
index 2fecfd7..1fcc3df 100644
--- a/tests/dat/manifest_validate_json_params.yaml
+++ b/tests/dat/manifest_validate_json_params.yaml
@@ -37,6 +37,37 @@ packages:
           member8:
             type: json
             value: { "name": "$${USERNAME}", "password": "$${PASSWORD}" }
+          member9:
+            type: json
+            value: {
+              "data": {
+                "name": "$USERNAME",
+              }
+            }
+          member10:
+            type: json
+            value: {
+              "data": {
+                "auth": {
+                  "username": "$USERNAME",
+                  "password": "$PASSWORD"
+                }
+              }
+            }
+          member11:
+            type: json
+            value: {
+              "data": {
+                "auth": {
+                  "username": "$${USERNAME}",
+                  "password": "$${PASSWORD}"
+                }
+              }
+            }
+          member12: { "name": "${USERNAME}", "password": "${PASSWORD}" }
+          member13: { "data": { "name": "$USERNAME" } }
+          member14: { "data": { "name": { "username": "$USERNAME" } } }
+          member15: { "data": { "name": { "username": "$${USERNAME}" } } }
         outputs:
             fellowship:
               type: json
diff --git a/wski18n/i18n_resources.go b/wski18n/i18n_resources.go
index 2a1c643..e397a0b 100644
--- a/wski18n/i18n_resources.go
+++ b/wski18n/i18n_resources.go
@@ -329,14 +329,14 @@ func AssetNames() []string {
 
 // _bindata is a table, holding each asset generator, mapped to its name.
 var _bindata = map[string]func() (*asset, error){
-	"wski18n/resources/de_DE.all.json": wski18nResourcesDe_deAllJson,
-	"wski18n/resources/en_US.all.json": wski18nResourcesEn_usAllJson,
-	"wski18n/resources/es_ES.all.json": wski18nResourcesEs_esAllJson,
-	"wski18n/resources/fr_FR.all.json": wski18nResourcesFr_frAllJson,
-	"wski18n/resources/it_IT.all.json": wski18nResourcesIt_itAllJson,
-	"wski18n/resources/ja_JA.all.json": wski18nResourcesJa_jaAllJson,
-	"wski18n/resources/ko_KR.all.json": wski18nResourcesKo_krAllJson,
-	"wski18n/resources/pt_BR.all.json": wski18nResourcesPt_brAllJson,
+	"wski18n/resources/de_DE.all.json":   wski18nResourcesDe_deAllJson,
+	"wski18n/resources/en_US.all.json":   wski18nResourcesEn_usAllJson,
+	"wski18n/resources/es_ES.all.json":   wski18nResourcesEs_esAllJson,
+	"wski18n/resources/fr_FR.all.json":   wski18nResourcesFr_frAllJson,
+	"wski18n/resources/it_IT.all.json":   wski18nResourcesIt_itAllJson,
+	"wski18n/resources/ja_JA.all.json":   wski18nResourcesJa_jaAllJson,
+	"wski18n/resources/ko_KR.all.json":   wski18nResourcesKo_krAllJson,
+	"wski18n/resources/pt_BR.all.json":   wski18nResourcesPt_brAllJson,
 	"wski18n/resources/zh_Hans.all.json": wski18nResourcesZh_hansAllJson,
 	"wski18n/resources/zh_Hant.all.json": wski18nResourcesZh_hantAllJson,
 }
@@ -380,17 +380,18 @@ type bintree struct {
 	Func     func() (*asset, error)
 	Children map[string]*bintree
 }
+
 var _bintree = &bintree{nil, map[string]*bintree{
 	"wski18n": &bintree{nil, map[string]*bintree{
 		"resources": &bintree{nil, map[string]*bintree{
-			"de_DE.all.json": &bintree{wski18nResourcesDe_deAllJson, map[string]*bintree{}},
-			"en_US.all.json": &bintree{wski18nResourcesEn_usAllJson, map[string]*bintree{}},
-			"es_ES.all.json": &bintree{wski18nResourcesEs_esAllJson, map[string]*bintree{}},
-			"fr_FR.all.json": &bintree{wski18nResourcesFr_frAllJson, map[string]*bintree{}},
-			"it_IT.all.json": &bintree{wski18nResourcesIt_itAllJson, map[string]*bintree{}},
-			"ja_JA.all.json": &bintree{wski18nResourcesJa_jaAllJson, map[string]*bintree{}},
-			"ko_KR.all.json": &bintree{wski18nResourcesKo_krAllJson, map[string]*bintree{}},
-			"pt_BR.all.json": &bintree{wski18nResourcesPt_brAllJson, map[string]*bintree{}},
+			"de_DE.all.json":   &bintree{wski18nResourcesDe_deAllJson, map[string]*bintree{}},
+			"en_US.all.json":   &bintree{wski18nResourcesEn_usAllJson, map[string]*bintree{}},
+			"es_ES.all.json":   &bintree{wski18nResourcesEs_esAllJson, map[string]*bintree{}},
+			"fr_FR.all.json":   &bintree{wski18nResourcesFr_frAllJson, map[string]*bintree{}},
+			"it_IT.all.json":   &bintree{wski18nResourcesIt_itAllJson, map[string]*bintree{}},
+			"ja_JA.all.json":   &bintree{wski18nResourcesJa_jaAllJson, map[string]*bintree{}},
+			"ko_KR.all.json":   &bintree{wski18nResourcesKo_krAllJson, map[string]*bintree{}},
+			"pt_BR.all.json":   &bintree{wski18nResourcesPt_brAllJson, map[string]*bintree{}},
 			"zh_Hans.all.json": &bintree{wski18nResourcesZh_hansAllJson, map[string]*bintree{}},
 			"zh_Hant.all.json": &bintree{wski18nResourcesZh_hantAllJson, map[string]*bintree{}},
 		}},
@@ -443,4 +444,3 @@ func _filePath(dir, name string) string {
 	cannonicalName := strings.Replace(name, "\\", "/", -1)
 	return filepath.Join(append([]string{dir}, strings.Split(cannonicalName, "/")...)...)
 }
-