This repository has been archived by the owner on Jul 11, 2023. It is now read-only.
/
model_sdwan_application_list_policy_object.go
73 lines (65 loc) · 2.13 KB
/
model_sdwan_application_list_policy_object.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// Code generated by "gen/generator.go"; DO NOT EDIT.
package provider
import (
"context"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/tidwall/gjson"
"github.com/tidwall/sjson"
)
type ApplicationList struct {
Id types.String `tfsdk:"id"`
Version types.Int64 `tfsdk:"version"`
Name types.String `tfsdk:"name"`
Entries []ApplicationListEntries `tfsdk:"entries"`
}
type ApplicationListEntries struct {
Application types.String `tfsdk:"application"`
ApplicationFamily types.String `tfsdk:"application_family"`
}
func (data ApplicationList) getType() string {
return "app"
}
func (data ApplicationList) toBody(ctx context.Context) string {
body, _ := sjson.Set("", "description", "Desc Not Required")
body, _ = sjson.Set(body, "name", data.Name.ValueString())
body, _ = sjson.Set(body, "type", "app")
if len(data.Entries) > 0 {
body, _ = sjson.Set(body, "entries", []interface{}{})
for _, item := range data.Entries {
itemBody := ""
if !item.Application.IsNull() {
itemBody, _ = sjson.Set(itemBody, "app", item.Application.ValueString())
}
if !item.ApplicationFamily.IsNull() {
itemBody, _ = sjson.Set(itemBody, "appFamily", item.ApplicationFamily.ValueString())
}
body, _ = sjson.SetRaw(body, "entries.-1", itemBody)
}
}
return body
}
func (data *ApplicationList) fromBody(ctx context.Context, res gjson.Result) {
if value := res.Get("name"); value.Exists() {
data.Name = types.StringValue(value.String())
} else {
data.Name = types.StringNull()
}
if value := res.Get("entries"); value.Exists() {
data.Entries = make([]ApplicationListEntries, 0)
value.ForEach(func(k, v gjson.Result) bool {
item := ApplicationListEntries{}
if cValue := v.Get("app"); cValue.Exists() {
item.Application = types.StringValue(cValue.String())
} else {
item.Application = types.StringNull()
}
if cValue := v.Get("appFamily"); cValue.Exists() {
item.ApplicationFamily = types.StringValue(cValue.String())
} else {
item.ApplicationFamily = types.StringNull()
}
data.Entries = append(data.Entries, item)
return true
})
}
}