-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add ext plugin, replace _ into - in plugin names
- Loading branch information
1 parent
6044a4f
commit 9e25bf4
Showing
3 changed files
with
208 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
package model | ||
|
||
import ( | ||
"github.com/hashicorp/terraform-plugin-framework/tfsdk" | ||
"github.com/hashicorp/terraform-plugin-framework/types" | ||
"github.com/webbankir/terraform-provider-apisix/apisix/plan_modifier" | ||
"github.com/webbankir/terraform-provider-apisix/apisix/utils" | ||
) | ||
|
||
type PluginExtPluginPostReqType struct { | ||
Disable types.Bool `tfsdk:"disable"` | ||
Config []PluginExtPluginPostReqConfType `tfsdk:"conf"` | ||
} | ||
|
||
type PluginExtPluginPostReqConfType struct { | ||
Name types.String `tfsdk:"name"` | ||
Value types.String `tfsdk:"value"` | ||
} | ||
|
||
var PluginExtPluginPostReqSchemaAttribute = tfsdk.Attribute{ | ||
Optional: true, | ||
Attributes: tfsdk.SingleNestedAttributes(map[string]tfsdk.Attribute{ | ||
"disable": { | ||
Optional: true, | ||
Computed: true, | ||
Type: types.BoolType, | ||
PlanModifiers: []tfsdk.AttributePlanModifier{ | ||
plan_modifier.DefaultBool(false), | ||
}, | ||
}, | ||
"conf": { | ||
Required: true, | ||
Attributes: tfsdk.ListNestedAttributes(map[string]tfsdk.Attribute{ | ||
"name": { | ||
Required: true, | ||
Type: types.StringType, | ||
}, | ||
"value": { | ||
Required: true, | ||
Type: types.StringType, | ||
}, | ||
}, tfsdk.ListNestedAttributesOptions{MinItems: 1}), | ||
}, | ||
}), | ||
} | ||
|
||
func (s PluginExtPluginPostReqType) Name() string { return "ext-plugin-pre-req" } | ||
|
||
func (s PluginExtPluginPostReqType) MapToState(data map[string]interface{}, pluginsType *PluginsType) { | ||
v := data[s.Name()] | ||
if v == nil { | ||
return | ||
} | ||
jsonData := v.(map[string]interface{}) | ||
item := PluginExtPluginPostReqType{} | ||
|
||
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) | ||
} | ||
|
||
item.Config = subItems | ||
pluginsType.ExtPluginPostReqType = &item | ||
} | ||
|
||
func (s PluginExtPluginPostReqType) StateToMap(m map[string]interface{}) { | ||
pluginValue := map[string]interface{}{} | ||
|
||
utils.BoolTypeValueToMap(s.Disable, pluginValue, "disable") | ||
|
||
var subItems []map[string]interface{} | ||
for _, vv := range s.Config { | ||
subItem := make(map[string]interface{}) | ||
utils.StringTypeValueToMap(vv.Name, subItem, "name") | ||
utils.StringTypeValueToMap(vv.Value, subItem, "value") | ||
} | ||
|
||
pluginValue["config"] = subItems | ||
|
||
m[s.Name()] = pluginValue | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
package model | ||
|
||
import ( | ||
"github.com/hashicorp/terraform-plugin-framework/tfsdk" | ||
"github.com/hashicorp/terraform-plugin-framework/types" | ||
"github.com/webbankir/terraform-provider-apisix/apisix/plan_modifier" | ||
"github.com/webbankir/terraform-provider-apisix/apisix/utils" | ||
) | ||
|
||
type PluginExtPluginPreReqType struct { | ||
Disable types.Bool `tfsdk:"disable"` | ||
Config []PluginExtPluginPreReqConfType `tfsdk:"conf"` | ||
} | ||
|
||
type PluginExtPluginPreReqConfType struct { | ||
Name types.String `tfsdk:"name"` | ||
Value types.String `tfsdk:"value"` | ||
} | ||
|
||
var PluginExtPluginPreReqSchemaAttribute = tfsdk.Attribute{ | ||
Optional: true, | ||
Attributes: tfsdk.SingleNestedAttributes(map[string]tfsdk.Attribute{ | ||
"disable": { | ||
Optional: true, | ||
Computed: true, | ||
Type: types.BoolType, | ||
PlanModifiers: []tfsdk.AttributePlanModifier{ | ||
plan_modifier.DefaultBool(false), | ||
}, | ||
}, | ||
"conf": { | ||
Required: true, | ||
Attributes: tfsdk.ListNestedAttributes(map[string]tfsdk.Attribute{ | ||
"name": { | ||
Required: true, | ||
Type: types.StringType, | ||
}, | ||
"value": { | ||
Required: true, | ||
Type: types.StringType, | ||
}, | ||
}, tfsdk.ListNestedAttributesOptions{MinItems: 1}), | ||
}, | ||
}), | ||
} | ||
|
||
func (s PluginExtPluginPreReqType) Name() string { return "ext-plugin-pre-req" } | ||
|
||
func (s PluginExtPluginPreReqType) MapToState(data map[string]interface{}, pluginsType *PluginsType) { | ||
v := data[s.Name()] | ||
if v == nil { | ||
return | ||
} | ||
jsonData := v.(map[string]interface{}) | ||
item := PluginExtPluginPreReqType{} | ||
|
||
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) | ||
} | ||
|
||
item.Config = subItems | ||
pluginsType.ExtPluginPreReqType = &item | ||
} | ||
|
||
func (s PluginExtPluginPreReqType) StateToMap(m map[string]interface{}) { | ||
pluginValue := map[string]interface{}{} | ||
|
||
utils.BoolTypeValueToMap(s.Disable, pluginValue, "disable") | ||
|
||
var subItems []map[string]interface{} | ||
for _, vv := range s.Config { | ||
subItem := make(map[string]interface{}) | ||
utils.StringTypeValueToMap(vv.Name, subItem, "name") | ||
utils.StringTypeValueToMap(vv.Value, subItem, "value") | ||
} | ||
|
||
pluginValue["config"] = subItems | ||
|
||
m[s.Name()] = pluginValue | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters