Skip to content

Commit 7fcb604

Browse files
rainestrandmonkey
andauthored
chore(gen) use modern plugin schema API (#3116)
Remove the controller's plugin default population in favor of equivalent functionality now provided by go-kong. The go-kong functionality uses the modern GetFullSchema instead of the deprecated GetSchema. Remove helpers and tests associated with the old KIC functionality. Co-authored-by: Yi Tao <[email protected]>
1 parent c2cba5f commit 7fcb604

File tree

5 files changed

+3
-731
lines changed

5 files changed

+3
-731
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ require (
2727
github.com/spf13/cobra v1.6.1
2828
github.com/spf13/pflag v1.0.5
2929
github.com/stretchr/testify v1.8.1
30-
github.com/tidwall/gjson v1.14.3
3130
golang.org/x/net v0.0.0-20221014081412-f15817d10f9b
3231
google.golang.org/api v0.101.0
3332
google.golang.org/genproto v0.0.0-20221018160656-63c7b68cfc55
@@ -140,6 +139,7 @@ require (
140139
github.com/sergi/go-diff v1.2.0 // indirect
141140
github.com/shirou/gopsutil/v3 v3.22.8 // indirect
142141
github.com/ssgelm/cookiejarparser v1.0.1 // indirect
142+
github.com/tidwall/gjson v1.14.3 // indirect
143143
github.com/tidwall/match v1.1.1 // indirect
144144
github.com/tidwall/pretty v1.2.0 // indirect
145145
github.com/tklauser/go-sysconf v0.3.10 // indirect

internal/dataplane/deckgen/deckgen.go

Lines changed: 0 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88

99
"github.com/kong/deck/file"
1010
"github.com/kong/go-kong/kong"
11-
"github.com/tidwall/gjson"
1211
)
1312

1413
// GenerateSHA generates a SHA256 checksum of the (targetContent, customEntities) tuple, with the purpose of change
@@ -117,63 +116,3 @@ func PluginString(plugin file.FPlugin) string {
117116
}
118117
return result
119118
}
120-
121-
// FillPluginConfig returns a copy of `config` that has default values filled in from `schema`.
122-
func FillPluginConfig(schema map[string]interface{},
123-
config kong.Configuration,
124-
) (kong.Configuration, error) {
125-
jsonb, err := json.Marshal(&schema)
126-
if err != nil {
127-
return nil, err
128-
}
129-
// Get all in the schema
130-
value := gjson.ParseBytes((jsonb))
131-
return fillRecord(value, config)
132-
}
133-
134-
func fillRecord(schema gjson.Result, config kong.Configuration) (kong.Configuration, error) {
135-
if config == nil {
136-
return nil, nil
137-
}
138-
res := config.DeepCopy()
139-
value := schema.Get("fields")
140-
141-
value.ForEach(func(key, value gjson.Result) bool {
142-
// get the key name
143-
ms := value.Map()
144-
fname := ""
145-
for k := range ms {
146-
fname = k
147-
break
148-
}
149-
ftype := value.Get(fname + ".type")
150-
if ftype.String() == "record" {
151-
subConfig := config[fname]
152-
if subConfig == nil {
153-
subConfig = make(map[string]interface{})
154-
}
155-
newSubConfig, err := fillRecord(value.Get(fname), subConfig.(map[string]interface{}))
156-
if err != nil {
157-
panic(err)
158-
}
159-
res[fname] = map[string]interface{}(newSubConfig)
160-
return true
161-
}
162-
// check if key is already set in the config
163-
if _, ok := config[fname]; ok {
164-
// yes, don't set it
165-
return true
166-
}
167-
// no, set it
168-
value = value.Get(fname + ".default")
169-
if value.Exists() {
170-
res[fname] = value.Value()
171-
} else {
172-
// if no default exists, set an explicit nil
173-
res[fname] = nil
174-
}
175-
return true
176-
})
177-
178-
return res, nil
179-
}

0 commit comments

Comments
 (0)