From 8bdd04d49be368bd9cc04f4038ac6a0aa65065ad Mon Sep 17 00:00:00 2001 From: Sergey Suslov Date: Wed, 9 Feb 2022 15:10:05 +0300 Subject: [PATCH] fixes --- apisix/model/plugin_ext_plugin_post_req.go | 19 +++++++++++-------- apisix/model/plugin_ext_plugin_pre_req.go | 18 ++++++++++-------- 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/apisix/model/plugin_ext_plugin_post_req.go b/apisix/model/plugin_ext_plugin_post_req.go index 2da5d07..901e71d 100644 --- a/apisix/model/plugin_ext_plugin_post_req.go +++ b/apisix/model/plugin_ext_plugin_post_req.go @@ -44,7 +44,7 @@ var PluginExtPluginPostReqSchemaAttribute = tfsdk.Attribute{ }), } -func (s PluginExtPluginPostReqType) Name() string { return "ext-plugin-pre-req" } +func (s PluginExtPluginPostReqType) Name() string { return "ext-plugin-post-req" } func (s PluginExtPluginPostReqType) MapToState(data map[string]interface{}, pluginsType *PluginsType) { v := data[s.Name()] @@ -57,12 +57,14 @@ func (s PluginExtPluginPostReqType) MapToState(data map[string]interface{}, plug utils.MapValueToBoolTypeValue(jsonData, "disable", &item.Disable) var subItems []PluginExtPluginPostReqConfType - for _, vv := range jsonData["conf"].([]interface{}) { - subItem := PluginExtPluginPostReqConfType{} - subV := vv.(map[string]interface{}) - utils.MapValueToStringTypeValue(subV, "name", &subItem.Name) - utils.MapValueToStringTypeValue(subV, "value", &subItem.Value) - subItems = append(subItems, subItem) + if v := jsonData["conf"]; v != nil { + for _, vv := range v.([]interface{}) { + subItem := PluginExtPluginPostReqConfType{} + subV := vv.(map[string]interface{}) + utils.MapValueToStringTypeValue(subV, "name", &subItem.Name) + utils.MapValueToStringTypeValue(subV, "value", &subItem.Value) + subItems = append(subItems, subItem) + } } item.Config = subItems @@ -79,9 +81,10 @@ func (s PluginExtPluginPostReqType) StateToMap(m map[string]interface{}) { subItem := make(map[string]interface{}) utils.StringTypeValueToMap(vv.Name, subItem, "name") utils.StringTypeValueToMap(vv.Value, subItem, "value") + subItems = append(subItems, subItem) } - pluginValue["config"] = subItems + pluginValue["conf"] = subItems m[s.Name()] = pluginValue } diff --git a/apisix/model/plugin_ext_plugin_pre_req.go b/apisix/model/plugin_ext_plugin_pre_req.go index 8e1e355..1abb5ae 100644 --- a/apisix/model/plugin_ext_plugin_pre_req.go +++ b/apisix/model/plugin_ext_plugin_pre_req.go @@ -57,12 +57,14 @@ func (s PluginExtPluginPreReqType) MapToState(data map[string]interface{}, plugi utils.MapValueToBoolTypeValue(jsonData, "disable", &item.Disable) var subItems []PluginExtPluginPreReqConfType - for _, vv := range jsonData["conf"].([]interface{}) { - subItem := PluginExtPluginPreReqConfType{} - subV := vv.(map[string]interface{}) - utils.MapValueToStringTypeValue(subV, "name", &subItem.Name) - utils.MapValueToStringTypeValue(subV, "value", &subItem.Value) - subItems = append(subItems, subItem) + if v := jsonData["conf"]; v != nil { + for _, vv := range v.([]interface{}) { + subItem := PluginExtPluginPreReqConfType{} + subV := vv.(map[string]interface{}) + utils.MapValueToStringTypeValue(subV, "name", &subItem.Name) + utils.MapValueToStringTypeValue(subV, "value", &subItem.Value) + subItems = append(subItems, subItem) + } } item.Config = subItems @@ -79,9 +81,9 @@ func (s PluginExtPluginPreReqType) StateToMap(m map[string]interface{}) { subItem := make(map[string]interface{}) utils.StringTypeValueToMap(vv.Name, subItem, "name") utils.StringTypeValueToMap(vv.Value, subItem, "value") + subItems = append(subItems, subItem) } - pluginValue["config"] = subItems - + pluginValue["conf"] = subItems m[s.Name()] = pluginValue }