Add missing bits from V1, slight touchup
This commit is contained in:
@@ -245,6 +245,7 @@ func (d *auxYamlDoc) unmarshal{{ .expIdent }}Node(dctx documentContext, n *yaml.
|
||||
auxOut envoyx.NodeSet
|
||||
nestedNodes envoyx.NodeSet
|
||||
scope envoyx.Scope
|
||||
envoyConfig envoyx.NodeConfig
|
||||
{{- if .rbac }}
|
||||
rbacNodes envoyx.NodeSet
|
||||
{{- end }}
|
||||
@@ -332,7 +333,7 @@ func (d *auxYamlDoc) unmarshal{{ .expIdent }}Node(dctx documentContext, n *yaml.
|
||||
auxRefs map[string]envoyx.Ref
|
||||
auxIdents envoyx.Identifiers
|
||||
)
|
||||
auxRefs, auxIdents, err = unmarshal{{ $resource.expIdent }}{{ $attr.expIdent }}Node(r, n)
|
||||
auxRefs, auxIdents, err = d.unmarshal{{ $resource.expIdent }}{{ $attr.expIdent }}Node(r, n)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -359,6 +360,8 @@ func (d *auxYamlDoc) unmarshal{{ .expIdent }}Node(dctx documentContext, n *yaml.
|
||||
rbacNodes = append(rbacNodes, auxOut...)
|
||||
auxOut = nil
|
||||
{{- end }}
|
||||
case "(envoy)":
|
||||
envoyConfig = d.decodeEnvoyConfig(n)
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -537,6 +540,7 @@ func (d *auxYamlDoc) unmarshal{{ .expIdent }}Node(dctx documentContext, n *yaml.
|
||||
{{if or .envoy.scoped}}
|
||||
Scope: scope,
|
||||
{{end}}
|
||||
Config: envoyConfig,
|
||||
}
|
||||
{{- if .rbac }}
|
||||
// Update RBAC resource nodes with references regarding the resource
|
||||
@@ -686,6 +690,25 @@ func unmarshalLocaleNode(n *yaml.Node) (out envoyx.NodeSet, err error) {
|
||||
})
|
||||
}
|
||||
|
||||
// // // // // // // // // // // // // // // // // // // // // // // // //
|
||||
// Envoy config unmarshal logic
|
||||
// // // // // // // // // // // // // // // // // // // // // // // // //
|
||||
|
||||
func (d *auxYamlDoc) decodeEnvoyConfig(n *yaml.Node) (out envoyx.NodeConfig) {
|
||||
y7s.EachMap(n, func(k, v *yaml.Node) (err error) {
|
||||
switch strings.ToLower(k.Value) {
|
||||
case "skipif", "skip":
|
||||
return y7s.DecodeScalar(v, "decode skip if", &out.SkipIf)
|
||||
case "onexisting", "mergealg":
|
||||
out.MergeAlg = envoyx.CastMergeAlg(v.Value)
|
||||
}
|
||||
|
||||
return nil
|
||||
})
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// // // // // // // // // // // // // // // // // // // // // // // // //
|
||||
// Utilities
|
||||
// // // // // // // // // // // // // // // // // // // // // // // // //
|
||||
|
||||
@@ -123,23 +123,29 @@ func (e YamlEncoder) encode{{.expIdent}}(ctx context.Context, p envoyx.EncodePar
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
{{- else if .envoy.yaml.customEncoder -}}
|
||||
aux{{.expIdent}}, err := e.encode{{$res}}{{.expIdent}}C(ctx, p, tt, node, res, res.{{.expIdent}})
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
{{- end }}
|
||||
{{end}}
|
||||
|
||||
out, err = y7s.AddMap(out,
|
||||
{{ range .model.attributes -}}
|
||||
{{- if .envoy.yaml.omitEncoder }}{{continue}}{{ end -}}
|
||||
{{- if .envoy.yaml.customEncoder -}}
|
||||
"{{.ident}}", e.encode{{$res}}{{.expIdent}}(p, res.{{.expIdent}}),
|
||||
"{{.envoy.yaml.identKeyEncode}}", aux{{.expIdent}},
|
||||
{{- else if eq .dal.type "Timestamp" -}}
|
||||
{{- if .dal.nullable -}}
|
||||
"{{.ident}}", aux{{.expIdent}},
|
||||
"{{.envoy.yaml.identKeyEncode}}", aux{{.expIdent}},
|
||||
{{- else -}}
|
||||
"{{.ident}}", aux{{.expIdent}},
|
||||
"{{.envoy.yaml.identKeyEncode}}", aux{{.expIdent}},
|
||||
{{- end -}}
|
||||
{{- else if eq .dal.type "Ref" -}}
|
||||
"{{.ident}}", aux{{.expIdent}},
|
||||
"{{.envoy.yaml.identKeyEncode}}", aux{{.expIdent}},
|
||||
{{- else -}}
|
||||
"{{.ident}}", res.{{.expIdent}},
|
||||
"{{.envoy.yaml.identKeyEncode}}", res.{{.expIdent}},
|
||||
{{- end }}
|
||||
{{end}}
|
||||
)
|
||||
@@ -176,6 +182,20 @@ func (e YamlEncoder) encode{{.expIdent}}(ctx context.Context, p envoyx.EncodePar
|
||||
{{ end }}
|
||||
{{- end }}
|
||||
|
||||
{{- range .envoy.yaml.extendedResourceEncoders }}
|
||||
aux, err = e.encode{{.expIdent}}s(ctx, p, tt.ChildrenForResourceType(node, types.{{.expIdent}}ResourceType), tt)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
out, err = y7s.AddMap(out,
|
||||
"{{.identKey}}", aux,
|
||||
)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
{{- end }}
|
||||
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -100,6 +100,10 @@ import (
|
||||
|
||||
customDecoder: bool | *false
|
||||
customEncoder: bool | *false
|
||||
|
||||
identKeyEncode: string | *$attrIdent
|
||||
|
||||
omitEncoder: bool | *false
|
||||
}
|
||||
|
||||
// store decode/encode configs
|
||||
|
||||
@@ -186,6 +186,12 @@ import (
|
||||
supportMappedInput: bool | *true
|
||||
mappedField: string | *""
|
||||
}] | *[]
|
||||
|
||||
extendedResourceEncoders: [...{
|
||||
ident: string
|
||||
expIdent: string
|
||||
identKey: string | *""
|
||||
}] | *[]
|
||||
}
|
||||
|
||||
// store decode/encode configs
|
||||
|
||||
Reference in New Issue
Block a user