Files
upstream-corteza/server/pkg/envoy/yaml/role_unmarshal.go
upstream-mirror 7e385fc126
Some checks failed
SonarQube / SonarQube (push) Failing after 5m28s
E2e test on main branch push / server and client test (map[name:admin port:8080]) (push) Failing after 3m33s
Server and lib tests / Library test (js) (push) Failing after 1m36s
Server and lib tests / Library test (vue) (push) Successful in 2m24s
Server and lib tests / Web client test (admin) (push) Successful in 2m52s
Server and lib tests / Web client test (compose) (push) Successful in 3m23s
Server and lib tests / Web client test (discovery) (push) Successful in 2m49s
Server and lib tests / Web client test (one) (push) Successful in 2m52s
Server and lib tests / Web client test (privacy) (push) Successful in 2m44s
Server and lib tests / Web client test (reporter) (push) Successful in 2m56s
Server and lib tests / Web client test (workflow) (push) Successful in 3m0s
Server and lib tests / Server tests (push) Failing after 4m55s
E2e test on main branch push / notify-failure (push) Failing after 9s
Server and lib tests / Send matrix testing notification (push) Successful in 2s
Mark stale issues and pull requests / stale (push) Successful in 40s
snapshot of https://github.com/cortezaproject/corteza.git (2024.9.x, 2026-09-18; blobs > 131072B omitted)
2026-09-18 01:22:23 +05:00

99 lines
1.8 KiB
Go

package yaml
import (
"github.com/cortezaproject/corteza/server/pkg/envoy"
"github.com/cortezaproject/corteza/server/pkg/envoy/resource"
"github.com/cortezaproject/corteza/server/pkg/y7s"
"github.com/cortezaproject/corteza/server/system/types"
"gopkg.in/yaml.v3"
)
func (wset *roleSet) UnmarshalYAML(n *yaml.Node) error {
return y7s.Each(n, func(k, v *yaml.Node) (err error) {
var (
wrap = &role{}
)
if v == nil {
return y7s.NodeErr(n, "malformed role definition")
}
wrap.res = &types.Role{
// no special defaults
}
switch v.Kind {
case yaml.ScalarNode:
if err = y7s.DecodeScalar(v, "role name", &wrap.res.Name); err != nil {
return
}
case yaml.MappingNode:
if err = v.Decode(&wrap); err != nil {
return
}
}
if err = decodeRef(k, "role", &wrap.res.Handle); err != nil {
return err
}
*wset = append(*wset, wrap)
return
})
}
func (wrap *role) UnmarshalYAML(n *yaml.Node) (err error) {
if !y7s.IsKind(n, yaml.MappingNode) {
return y7s.NodeErr(n, "role definition must be a map")
}
if wrap.res == nil {
wrap.res = &types.Role{}
}
if err = n.Decode(&wrap.res); err != nil {
return
}
if wrap.rbac, err = decodeRbac(n); err != nil {
return
}
if wrap.envoyConfig, err = decodeEnvoyConfig(n); err != nil {
return
}
if wrap.ts, err = decodeTimestamps(n); err != nil {
return
}
return nil
}
func (wset roleSet) MarshalEnvoy() ([]resource.Interface, error) {
nn := make([]resource.Interface, 0, len(wset))
for _, res := range wset {
if tmp, err := res.MarshalEnvoy(); err != nil {
return nil, err
} else {
nn = append(nn, tmp...)
}
}
return nn, nil
}
func (wrap role) MarshalEnvoy() ([]resource.Interface, error) {
rs := resource.NewRole(wrap.res)
rs.SetTimestamps(wrap.ts)
rs.SetConfig(wrap.envoyConfig)
return envoy.CollectNodes(
rs,
wrap.rbac.bindResource(rs),
)
}