Add missing bits from V1, slight touchup
This commit is contained in:
@@ -65,9 +65,21 @@ apigw_route: {
|
||||
supportMappedInput: true
|
||||
mappedField: "Endpoint"
|
||||
identKeyAlias: ["endpoints"]
|
||||
extendedResourceDecoders: [{
|
||||
ident: "filters"
|
||||
expIdent: "Filters"
|
||||
identKeys: ["filters"]
|
||||
supportMappedInput: false
|
||||
}]
|
||||
extendedResourceEncoders: [{
|
||||
ident: "apigwFilter"
|
||||
expIdent: "ApigwFilter"
|
||||
identKey: "filters"
|
||||
}]
|
||||
}
|
||||
store: {
|
||||
handleField: "Endpoint"
|
||||
extendedDecoder: true
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -74,7 +74,6 @@ application: {
|
||||
identKeyAlias: ["apps"]
|
||||
}
|
||||
store: {
|
||||
extendedRefDecoder: true
|
||||
handleField: "Name"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,6 +49,12 @@ auth_client: {
|
||||
dal: { type: "JSON", defaultEmptyObject: true }
|
||||
omitSetter: true
|
||||
omitGetter: true
|
||||
envoy: {
|
||||
yaml: {
|
||||
customDecoder: true
|
||||
customEncoder: true
|
||||
}
|
||||
}
|
||||
}
|
||||
owned_by: schema.AttributeUserRef
|
||||
created_at: schema.SortableTimestampNowField
|
||||
@@ -92,7 +98,9 @@ auth_client: {
|
||||
mappedField: "Handle"
|
||||
identKeyAlias: ["authclients"]
|
||||
}
|
||||
store: {}
|
||||
store: {
|
||||
extendedRefDecoder: true
|
||||
}
|
||||
}
|
||||
|
||||
rbac: {
|
||||
|
||||
@@ -63,7 +63,9 @@ dal_connection: {
|
||||
mappedField: "Handle"
|
||||
identKeyAlias: ["connection", "connections"]
|
||||
}
|
||||
store: {}
|
||||
store: {
|
||||
extendedRefDecoder: true
|
||||
}
|
||||
}
|
||||
|
||||
rbac: {
|
||||
|
||||
Generated
+26
-2
@@ -84,6 +84,12 @@ func (d StoreDecoder) decode(ctx context.Context, s store.Storer, dl dal.FullSer
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// @todo consider changing this.
|
||||
// Currently it's required because the .decode may return some
|
||||
// nested nodes as well.
|
||||
// Consider a flag or a new function.
|
||||
aux = envoyx.NodesForResourceType(ref.ResourceType, aux...)
|
||||
if len(aux) == 0 {
|
||||
return nil, fmt.Errorf("invalid reference %v", ref)
|
||||
}
|
||||
@@ -223,6 +229,16 @@ func (d StoreDecoder) decode(ctx context.Context, s store.Storer, dl dal.FullSer
|
||||
}
|
||||
out = append(out, aux...)
|
||||
|
||||
default:
|
||||
aux, err = d.extendDecoder(ctx, s, dl, wf.rt, refNodes[i], wf.f)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
for _, a := range aux {
|
||||
a.Identifiers = a.Identifiers.Merge(wf.f.Identifiers)
|
||||
a.References = envoyx.MergeRefs(a.References, refRefs[i])
|
||||
}
|
||||
out = append(out, aux...)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -255,8 +271,6 @@ func (d StoreDecoder) decodeApplication(ctx context.Context, s store.Storer, dl
|
||||
},
|
||||
}
|
||||
|
||||
refs = envoyx.MergeRefs(refs, d.decodeApplicationRefs(r))
|
||||
|
||||
var scope envoyx.Scope
|
||||
|
||||
out = append(out, &envoyx.Node{
|
||||
@@ -349,6 +363,12 @@ func (d StoreDecoder) decodeApigwRoute(ctx context.Context, s store.Storer, dl d
|
||||
})
|
||||
}
|
||||
|
||||
aux, err := d.extendedApigwRouteDecoder(ctx, s, dl, f, out)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
out = append(out, aux...)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
@@ -494,6 +514,8 @@ func (d StoreDecoder) decodeAuthClient(ctx context.Context, s store.Storer, dl d
|
||||
},
|
||||
}
|
||||
|
||||
refs = envoyx.MergeRefs(refs, d.decodeAuthClientRefs(r))
|
||||
|
||||
var scope envoyx.Scope
|
||||
|
||||
scope = envoyx.Scope{
|
||||
@@ -919,6 +941,8 @@ func (d StoreDecoder) decodeDalConnection(ctx context.Context, s store.Storer, d
|
||||
},
|
||||
}
|
||||
|
||||
refs = envoyx.MergeRefs(refs, d.decodeDalConnectionRefs(r))
|
||||
|
||||
var scope envoyx.Scope
|
||||
|
||||
out = append(out, &envoyx.Node{
|
||||
|
||||
@@ -1,12 +1,73 @@
|
||||
package envoy
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/cortezaproject/corteza/server/pkg/dal"
|
||||
"github.com/cortezaproject/corteza/server/pkg/envoyx"
|
||||
"github.com/cortezaproject/corteza/server/store"
|
||||
"github.com/cortezaproject/corteza/server/system/types"
|
||||
)
|
||||
|
||||
func (d StoreDecoder) decodeApplicationRefs(c *types.Application) (refs map[string]envoyx.Ref) {
|
||||
|
||||
// @todo
|
||||
func (d StoreDecoder) extendDecoder(ctx context.Context, s store.Storer, dl dal.FullService, rt string, nodes map[string]*envoyx.Node, f envoyx.ResourceFilter) (out envoyx.NodeSet, err error) {
|
||||
return
|
||||
}
|
||||
|
||||
func (d StoreDecoder) extendedApigwRouteDecoder(ctx context.Context, s store.Storer, dl dal.FullService, f types.ApigwRouteFilter, base envoyx.NodeSet) (out envoyx.NodeSet, err error) {
|
||||
for _, b := range base {
|
||||
route := b.Resource.(*types.ApigwRoute)
|
||||
|
||||
filters, err := d.decodeApigwFilter(ctx, s, dl, types.ApigwFilterFilter{
|
||||
RouteID: route.ID,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
out = append(out, filters...)
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func (d StoreDecoder) decodeAuthClientRefs(c *types.AuthClient) (refs map[string]envoyx.Ref) {
|
||||
refs = make(map[string]envoyx.Ref, 4)
|
||||
|
||||
if c.Security.ImpersonateUser > 0 {
|
||||
refs["Security.ImpersonateUser"] = envoyx.Ref{
|
||||
ResourceType: types.UserResourceType,
|
||||
Identifiers: envoyx.MakeIdentifiers(c.Security.ImpersonateUser),
|
||||
}
|
||||
}
|
||||
|
||||
d.roleSliceToRefs(refs, "Security.PermittedRoles", c.Security.PermittedRoles)
|
||||
d.roleSliceToRefs(refs, "Security.ProhibitedRoles", c.Security.ProhibitedRoles)
|
||||
d.roleSliceToRefs(refs, "Security.ForcedRoles", c.Security.ForcedRoles)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func (d StoreDecoder) decodeDalConnectionRefs(c *types.DalConnection) (refs map[string]envoyx.Ref) {
|
||||
if c.Config.Privacy.SensitivityLevelID == 0 {
|
||||
return
|
||||
}
|
||||
|
||||
refs = map[string]envoyx.Ref{
|
||||
"Config.Privacy.SensitivityLevelID": {
|
||||
ResourceType: types.DalSensitivityLevelResourceType,
|
||||
Identifiers: envoyx.MakeIdentifiers(c.Config.Privacy.SensitivityLevelID),
|
||||
},
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func (d StoreDecoder) roleSliceToRefs(refs map[string]envoyx.Ref, k string, rr []string) {
|
||||
for i, r := range rr {
|
||||
refs[fmt.Sprintf("%s.%d.RoleID", k, i)] = envoyx.Ref{
|
||||
ResourceType: types.RoleResourceType,
|
||||
Identifiers: envoyx.MakeIdentifiers(r),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,23 @@
|
||||
package envoy
|
||||
|
||||
import "github.com/cortezaproject/corteza/server/system/types"
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"github.com/cortezaproject/corteza/server/pkg/envoyx"
|
||||
"github.com/cortezaproject/corteza/server/store"
|
||||
"github.com/cortezaproject/corteza/server/system/types"
|
||||
)
|
||||
|
||||
func (e StoreEncoder) prepare(ctx context.Context, p envoyx.EncodeParams, s store.Storer, rt string, nn envoyx.NodeSet) (err error) {
|
||||
return
|
||||
}
|
||||
|
||||
func (e StoreEncoder) setApplicationDefaults(res *types.Application) (err error) {
|
||||
if res.CreatedAt.IsZero() {
|
||||
res.CreatedAt = time.Now()
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
@@ -11,6 +26,10 @@ func (e StoreEncoder) validateApplication(res *types.Application) (err error) {
|
||||
}
|
||||
|
||||
func (e StoreEncoder) setApigwRouteDefaults(res *types.ApigwRoute) (err error) {
|
||||
if res.CreatedAt.IsZero() {
|
||||
res.CreatedAt = time.Now()
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
@@ -19,6 +38,10 @@ func (e StoreEncoder) validateApigwRoute(res *types.ApigwRoute) (err error) {
|
||||
}
|
||||
|
||||
func (e StoreEncoder) setApigwFilterDefaults(res *types.ApigwFilter) (err error) {
|
||||
if res.CreatedAt.IsZero() {
|
||||
res.CreatedAt = time.Now()
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
@@ -27,6 +50,10 @@ func (e StoreEncoder) validateApigwFilter(res *types.ApigwFilter) (err error) {
|
||||
}
|
||||
|
||||
func (e StoreEncoder) setAuthClientDefaults(res *types.AuthClient) (err error) {
|
||||
if res.CreatedAt.IsZero() {
|
||||
res.CreatedAt = time.Now()
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
@@ -35,6 +62,10 @@ func (e StoreEncoder) validateAuthClient(res *types.AuthClient) (err error) {
|
||||
}
|
||||
|
||||
func (e StoreEncoder) setQueueDefaults(res *types.Queue) (err error) {
|
||||
if res.CreatedAt.IsZero() {
|
||||
res.CreatedAt = time.Now()
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
@@ -43,6 +74,10 @@ func (e StoreEncoder) validateQueue(res *types.Queue) (err error) {
|
||||
}
|
||||
|
||||
func (e StoreEncoder) setReportDefaults(res *types.Report) (err error) {
|
||||
if res.CreatedAt.IsZero() {
|
||||
res.CreatedAt = time.Now()
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
@@ -51,6 +86,10 @@ func (e StoreEncoder) validateReport(res *types.Report) (err error) {
|
||||
}
|
||||
|
||||
func (e StoreEncoder) setRoleDefaults(res *types.Role) (err error) {
|
||||
if res.CreatedAt.IsZero() {
|
||||
res.CreatedAt = time.Now()
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
@@ -59,6 +98,10 @@ func (e StoreEncoder) validateRole(res *types.Role) (err error) {
|
||||
}
|
||||
|
||||
func (e StoreEncoder) setTemplateDefaults(res *types.Template) (err error) {
|
||||
if res.CreatedAt.IsZero() {
|
||||
res.CreatedAt = time.Now()
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
@@ -67,6 +110,10 @@ func (e StoreEncoder) validateTemplate(res *types.Template) (err error) {
|
||||
}
|
||||
|
||||
func (e StoreEncoder) setUserDefaults(res *types.User) (err error) {
|
||||
if res.CreatedAt.IsZero() {
|
||||
res.CreatedAt = time.Now()
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
@@ -75,6 +122,10 @@ func (e StoreEncoder) validateUser(res *types.User) (err error) {
|
||||
}
|
||||
|
||||
func (e StoreEncoder) setDalConnectionDefaults(res *types.DalConnection) (err error) {
|
||||
if res.CreatedAt.IsZero() {
|
||||
res.CreatedAt = time.Now()
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
@@ -83,6 +134,10 @@ func (e StoreEncoder) validateDalConnection(res *types.DalConnection) (err error
|
||||
}
|
||||
|
||||
func (e StoreEncoder) setDalSensitivityLevelDefaults(res *types.DalSensitivityLevel) (err error) {
|
||||
if res.CreatedAt.IsZero() {
|
||||
res.CreatedAt = time.Now()
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
Generated
+136
@@ -298,6 +298,7 @@ func (d *auxYamlDoc) unmarshalApplicationNode(dctx documentContext, n *yaml.Node
|
||||
auxOut envoyx.NodeSet
|
||||
nestedNodes envoyx.NodeSet
|
||||
scope envoyx.Scope
|
||||
envoyConfig envoyx.NodeConfig
|
||||
rbacNodes envoyx.NodeSet
|
||||
)
|
||||
_ = auxOut
|
||||
@@ -348,6 +349,8 @@ func (d *auxYamlDoc) unmarshalApplicationNode(dctx documentContext, n *yaml.Node
|
||||
}
|
||||
rbacNodes = append(rbacNodes, auxOut...)
|
||||
auxOut = nil
|
||||
case "(envoy)":
|
||||
envoyConfig = d.decodeEnvoyConfig(n)
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -422,6 +425,8 @@ func (d *auxYamlDoc) unmarshalApplicationNode(dctx documentContext, n *yaml.Node
|
||||
ResourceType: types.ApplicationResourceType,
|
||||
Identifiers: ii,
|
||||
References: refs,
|
||||
|
||||
Config: envoyConfig,
|
||||
}
|
||||
// Update RBAC resource nodes with references regarding the resource
|
||||
for _, rn := range rbacNodes {
|
||||
@@ -488,6 +493,22 @@ func (d *auxYamlDoc) unmarshalApigwRouteMap(dctx documentContext, n *yaml.Node)
|
||||
return
|
||||
}
|
||||
|
||||
// unmarshalFiltersExtendedSeq unmarshals Filters when provided as a sequence node
|
||||
func (d *auxYamlDoc) unmarshalExtendedFiltersSeq(dctx documentContext, n *yaml.Node) (out envoyx.NodeSet, err error) {
|
||||
var aux envoyx.NodeSet
|
||||
err = y7s.EachSeq(n, func(n *yaml.Node) error {
|
||||
aux, err = d.unmarshalFiltersExtendedNode(dctx, n)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
out = append(out, aux...)
|
||||
|
||||
return nil
|
||||
})
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// unmarshalApigwRouteNode is a cookie-cutter function to unmarshal
|
||||
// the yaml node into the corresponding Corteza type & Node
|
||||
func (d *auxYamlDoc) unmarshalApigwRouteNode(dctx documentContext, n *yaml.Node, meta ...*yaml.Node) (out envoyx.NodeSet, err error) {
|
||||
@@ -519,6 +540,7 @@ func (d *auxYamlDoc) unmarshalApigwRouteNode(dctx documentContext, n *yaml.Node,
|
||||
auxOut envoyx.NodeSet
|
||||
nestedNodes envoyx.NodeSet
|
||||
scope envoyx.Scope
|
||||
envoyConfig envoyx.NodeConfig
|
||||
rbacNodes envoyx.NodeSet
|
||||
)
|
||||
_ = auxOut
|
||||
@@ -608,6 +630,8 @@ func (d *auxYamlDoc) unmarshalApigwRouteNode(dctx documentContext, n *yaml.Node,
|
||||
}
|
||||
rbacNodes = append(rbacNodes, auxOut...)
|
||||
auxOut = nil
|
||||
case "(envoy)":
|
||||
envoyConfig = d.decodeEnvoyConfig(n)
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -636,6 +660,14 @@ func (d *auxYamlDoc) unmarshalApigwRouteNode(dctx documentContext, n *yaml.Node,
|
||||
|
||||
switch strings.ToLower(k.Value) {
|
||||
|
||||
case "filters":
|
||||
if y7s.IsSeq(n) {
|
||||
nestedNodes, err = d.unmarshalExtendedFiltersSeq(dctx, n)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
break
|
||||
}
|
||||
|
||||
// Iterate nested nodes and update their reference to the current resource
|
||||
@@ -682,6 +714,8 @@ func (d *auxYamlDoc) unmarshalApigwRouteNode(dctx documentContext, n *yaml.Node,
|
||||
ResourceType: types.ApigwRouteResourceType,
|
||||
Identifiers: ii,
|
||||
References: refs,
|
||||
|
||||
Config: envoyConfig,
|
||||
}
|
||||
// Update RBAC resource nodes with references regarding the resource
|
||||
for _, rn := range rbacNodes {
|
||||
@@ -760,6 +794,7 @@ func (d *auxYamlDoc) unmarshalApigwFilterNode(dctx documentContext, n *yaml.Node
|
||||
auxOut envoyx.NodeSet
|
||||
nestedNodes envoyx.NodeSet
|
||||
scope envoyx.Scope
|
||||
envoyConfig envoyx.NodeConfig
|
||||
)
|
||||
_ = auxOut
|
||||
_ = refs
|
||||
@@ -832,6 +867,8 @@ func (d *auxYamlDoc) unmarshalApigwFilterNode(dctx documentContext, n *yaml.Node
|
||||
|
||||
break
|
||||
|
||||
case "(envoy)":
|
||||
envoyConfig = d.decodeEnvoyConfig(n)
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -906,6 +943,8 @@ func (d *auxYamlDoc) unmarshalApigwFilterNode(dctx documentContext, n *yaml.Node
|
||||
ResourceType: types.ApigwFilterResourceType,
|
||||
Identifiers: ii,
|
||||
References: refs,
|
||||
|
||||
Config: envoyConfig,
|
||||
}
|
||||
|
||||
// Put it all together...
|
||||
@@ -985,6 +1024,7 @@ func (d *auxYamlDoc) unmarshalAuthClientNode(dctx documentContext, n *yaml.Node,
|
||||
auxOut envoyx.NodeSet
|
||||
nestedNodes envoyx.NodeSet
|
||||
scope envoyx.Scope
|
||||
envoyConfig envoyx.NodeConfig
|
||||
rbacNodes envoyx.NodeSet
|
||||
)
|
||||
_ = auxOut
|
||||
@@ -1055,6 +1095,25 @@ func (d *auxYamlDoc) unmarshalAuthClientNode(dctx documentContext, n *yaml.Node,
|
||||
|
||||
break
|
||||
|
||||
case "security":
|
||||
|
||||
// Handle custom node decoder
|
||||
//
|
||||
// The decoder may update the passed resource with arbitrary values
|
||||
// as well as provide additional references and identifiers for the node.
|
||||
var (
|
||||
auxRefs map[string]envoyx.Ref
|
||||
auxIdents envoyx.Identifiers
|
||||
)
|
||||
auxRefs, auxIdents, err = d.unmarshalAuthClientSecurityNode(r, n)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
refs = envoyx.MergeRefs(refs, auxRefs)
|
||||
ii = ii.Merge(auxIdents)
|
||||
|
||||
break
|
||||
|
||||
case "updatedby":
|
||||
// Handle references
|
||||
err = y7s.DecodeScalar(n, "updatedBy", &auxNodeValue)
|
||||
@@ -1084,6 +1143,8 @@ func (d *auxYamlDoc) unmarshalAuthClientNode(dctx documentContext, n *yaml.Node,
|
||||
}
|
||||
rbacNodes = append(rbacNodes, auxOut...)
|
||||
auxOut = nil
|
||||
case "(envoy)":
|
||||
envoyConfig = d.decodeEnvoyConfig(n)
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -1169,6 +1230,8 @@ func (d *auxYamlDoc) unmarshalAuthClientNode(dctx documentContext, n *yaml.Node,
|
||||
References: refs,
|
||||
|
||||
Scope: scope,
|
||||
|
||||
Config: envoyConfig,
|
||||
}
|
||||
// Update RBAC resource nodes with references regarding the resource
|
||||
for _, rn := range rbacNodes {
|
||||
@@ -1266,6 +1329,7 @@ func (d *auxYamlDoc) unmarshalQueueNode(dctx documentContext, n *yaml.Node, meta
|
||||
auxOut envoyx.NodeSet
|
||||
nestedNodes envoyx.NodeSet
|
||||
scope envoyx.Scope
|
||||
envoyConfig envoyx.NodeConfig
|
||||
rbacNodes envoyx.NodeSet
|
||||
)
|
||||
_ = auxOut
|
||||
@@ -1352,6 +1416,8 @@ func (d *auxYamlDoc) unmarshalQueueNode(dctx documentContext, n *yaml.Node, meta
|
||||
}
|
||||
rbacNodes = append(rbacNodes, auxOut...)
|
||||
auxOut = nil
|
||||
case "(envoy)":
|
||||
envoyConfig = d.decodeEnvoyConfig(n)
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -1437,6 +1503,8 @@ func (d *auxYamlDoc) unmarshalQueueNode(dctx documentContext, n *yaml.Node, meta
|
||||
References: refs,
|
||||
|
||||
Scope: scope,
|
||||
|
||||
Config: envoyConfig,
|
||||
}
|
||||
// Update RBAC resource nodes with references regarding the resource
|
||||
for _, rn := range rbacNodes {
|
||||
@@ -1534,6 +1602,7 @@ func (d *auxYamlDoc) unmarshalReportNode(dctx documentContext, n *yaml.Node, met
|
||||
auxOut envoyx.NodeSet
|
||||
nestedNodes envoyx.NodeSet
|
||||
scope envoyx.Scope
|
||||
envoyConfig envoyx.NodeConfig
|
||||
rbacNodes envoyx.NodeSet
|
||||
)
|
||||
_ = auxOut
|
||||
@@ -1633,6 +1702,8 @@ func (d *auxYamlDoc) unmarshalReportNode(dctx documentContext, n *yaml.Node, met
|
||||
}
|
||||
rbacNodes = append(rbacNodes, auxOut...)
|
||||
auxOut = nil
|
||||
case "(envoy)":
|
||||
envoyConfig = d.decodeEnvoyConfig(n)
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -1707,6 +1778,8 @@ func (d *auxYamlDoc) unmarshalReportNode(dctx documentContext, n *yaml.Node, met
|
||||
ResourceType: types.ReportResourceType,
|
||||
Identifiers: ii,
|
||||
References: refs,
|
||||
|
||||
Config: envoyConfig,
|
||||
}
|
||||
// Update RBAC resource nodes with references regarding the resource
|
||||
for _, rn := range rbacNodes {
|
||||
@@ -1804,6 +1877,7 @@ func (d *auxYamlDoc) unmarshalRoleNode(dctx documentContext, n *yaml.Node, meta
|
||||
auxOut envoyx.NodeSet
|
||||
nestedNodes envoyx.NodeSet
|
||||
scope envoyx.Scope
|
||||
envoyConfig envoyx.NodeConfig
|
||||
rbacNodes envoyx.NodeSet
|
||||
)
|
||||
_ = auxOut
|
||||
@@ -1851,6 +1925,8 @@ func (d *auxYamlDoc) unmarshalRoleNode(dctx documentContext, n *yaml.Node, meta
|
||||
}
|
||||
rbacNodes = append(rbacNodes, auxOut...)
|
||||
auxOut = nil
|
||||
case "(envoy)":
|
||||
envoyConfig = d.decodeEnvoyConfig(n)
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -1925,6 +2001,8 @@ func (d *auxYamlDoc) unmarshalRoleNode(dctx documentContext, n *yaml.Node, meta
|
||||
ResourceType: types.RoleResourceType,
|
||||
Identifiers: ii,
|
||||
References: refs,
|
||||
|
||||
Config: envoyConfig,
|
||||
}
|
||||
// Update RBAC resource nodes with references regarding the resource
|
||||
for _, rn := range rbacNodes {
|
||||
@@ -2022,6 +2100,7 @@ func (d *auxYamlDoc) unmarshalTemplateNode(dctx documentContext, n *yaml.Node, m
|
||||
auxOut envoyx.NodeSet
|
||||
nestedNodes envoyx.NodeSet
|
||||
scope envoyx.Scope
|
||||
envoyConfig envoyx.NodeConfig
|
||||
rbacNodes envoyx.NodeSet
|
||||
)
|
||||
_ = auxOut
|
||||
@@ -2082,6 +2161,8 @@ func (d *auxYamlDoc) unmarshalTemplateNode(dctx documentContext, n *yaml.Node, m
|
||||
}
|
||||
rbacNodes = append(rbacNodes, auxOut...)
|
||||
auxOut = nil
|
||||
case "(envoy)":
|
||||
envoyConfig = d.decodeEnvoyConfig(n)
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -2156,6 +2237,8 @@ func (d *auxYamlDoc) unmarshalTemplateNode(dctx documentContext, n *yaml.Node, m
|
||||
ResourceType: types.TemplateResourceType,
|
||||
Identifiers: ii,
|
||||
References: refs,
|
||||
|
||||
Config: envoyConfig,
|
||||
}
|
||||
// Update RBAC resource nodes with references regarding the resource
|
||||
for _, rn := range rbacNodes {
|
||||
@@ -2253,6 +2336,7 @@ func (d *auxYamlDoc) unmarshalUserNode(dctx documentContext, n *yaml.Node, meta
|
||||
auxOut envoyx.NodeSet
|
||||
nestedNodes envoyx.NodeSet
|
||||
scope envoyx.Scope
|
||||
envoyConfig envoyx.NodeConfig
|
||||
rbacNodes envoyx.NodeSet
|
||||
)
|
||||
_ = auxOut
|
||||
@@ -2284,6 +2368,25 @@ func (d *auxYamlDoc) unmarshalUserNode(dctx documentContext, n *yaml.Node, meta
|
||||
|
||||
break
|
||||
|
||||
case "roles":
|
||||
|
||||
// Handle custom node decoder
|
||||
//
|
||||
// The decoder may update the passed resource with arbitrary values
|
||||
// as well as provide additional references and identifiers for the node.
|
||||
var (
|
||||
auxRefs map[string]envoyx.Ref
|
||||
auxIdents envoyx.Identifiers
|
||||
)
|
||||
auxRefs, auxIdents, err = d.unmarshalUserRolesNode(r, n)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
refs = envoyx.MergeRefs(refs, auxRefs)
|
||||
ii = ii.Merge(auxIdents)
|
||||
|
||||
break
|
||||
|
||||
// Handle RBAC rules
|
||||
case "allow":
|
||||
auxOut, err = unmarshalAllowNode(n)
|
||||
@@ -2300,6 +2403,8 @@ func (d *auxYamlDoc) unmarshalUserNode(dctx documentContext, n *yaml.Node, meta
|
||||
}
|
||||
rbacNodes = append(rbacNodes, auxOut...)
|
||||
auxOut = nil
|
||||
case "(envoy)":
|
||||
envoyConfig = d.decodeEnvoyConfig(n)
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -2374,6 +2479,8 @@ func (d *auxYamlDoc) unmarshalUserNode(dctx documentContext, n *yaml.Node, meta
|
||||
ResourceType: types.UserResourceType,
|
||||
Identifiers: ii,
|
||||
References: refs,
|
||||
|
||||
Config: envoyConfig,
|
||||
}
|
||||
// Update RBAC resource nodes with references regarding the resource
|
||||
for _, rn := range rbacNodes {
|
||||
@@ -2471,6 +2578,7 @@ func (d *auxYamlDoc) unmarshalDalConnectionNode(dctx documentContext, n *yaml.No
|
||||
auxOut envoyx.NodeSet
|
||||
nestedNodes envoyx.NodeSet
|
||||
scope envoyx.Scope
|
||||
envoyConfig envoyx.NodeConfig
|
||||
rbacNodes envoyx.NodeSet
|
||||
)
|
||||
_ = auxOut
|
||||
@@ -2557,6 +2665,8 @@ func (d *auxYamlDoc) unmarshalDalConnectionNode(dctx documentContext, n *yaml.No
|
||||
}
|
||||
rbacNodes = append(rbacNodes, auxOut...)
|
||||
auxOut = nil
|
||||
case "(envoy)":
|
||||
envoyConfig = d.decodeEnvoyConfig(n)
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -2631,6 +2741,8 @@ func (d *auxYamlDoc) unmarshalDalConnectionNode(dctx documentContext, n *yaml.No
|
||||
ResourceType: types.DalConnectionResourceType,
|
||||
Identifiers: ii,
|
||||
References: refs,
|
||||
|
||||
Config: envoyConfig,
|
||||
}
|
||||
// Update RBAC resource nodes with references regarding the resource
|
||||
for _, rn := range rbacNodes {
|
||||
@@ -2728,6 +2840,7 @@ func (d *auxYamlDoc) unmarshalDalSensitivityLevelNode(dctx documentContext, n *y
|
||||
auxOut envoyx.NodeSet
|
||||
nestedNodes envoyx.NodeSet
|
||||
scope envoyx.Scope
|
||||
envoyConfig envoyx.NodeConfig
|
||||
)
|
||||
_ = auxOut
|
||||
_ = refs
|
||||
@@ -2797,6 +2910,8 @@ func (d *auxYamlDoc) unmarshalDalSensitivityLevelNode(dctx documentContext, n *y
|
||||
|
||||
break
|
||||
|
||||
case "(envoy)":
|
||||
envoyConfig = d.decodeEnvoyConfig(n)
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -2871,6 +2986,8 @@ func (d *auxYamlDoc) unmarshalDalSensitivityLevelNode(dctx documentContext, n *y
|
||||
ResourceType: types.DalSensitivityLevelResourceType,
|
||||
Identifiers: ii,
|
||||
References: refs,
|
||||
|
||||
Config: envoyConfig,
|
||||
}
|
||||
|
||||
// Put it all together...
|
||||
@@ -2996,6 +3113,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
|
||||
// // // // // // // // // // // // // // // // // // // // // // // // //
|
||||
|
||||
@@ -1,10 +1,84 @@
|
||||
package envoy
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/cortezaproject/corteza/server/pkg/envoyx"
|
||||
"github.com/cortezaproject/corteza/server/pkg/y7s"
|
||||
"github.com/cortezaproject/corteza/server/system/types"
|
||||
"gopkg.in/yaml.v3"
|
||||
)
|
||||
|
||||
func (d *auxYamlDoc) unmarshalYAML(k string, n *yaml.Node) (out envoyx.NodeSet, err error) {
|
||||
return
|
||||
}
|
||||
|
||||
func (d *auxYamlDoc) unmarshalFiltersExtendedNode(dctx documentContext, n *yaml.Node, meta ...*yaml.Node) (out envoyx.NodeSet, err error) {
|
||||
return d.unmarshalApigwFilterNode(dctx, n, meta...)
|
||||
}
|
||||
|
||||
func (d *auxYamlDoc) unmarshalUserRolesNode(r *types.User, n *yaml.Node) (refs map[string]envoyx.Ref, idents envoyx.Identifiers, err error) {
|
||||
refs = make(map[string]envoyx.Ref, len(n.Content))
|
||||
|
||||
i := 0
|
||||
err = y7s.EachSeq(n, func(n *yaml.Node) error {
|
||||
refs[fmt.Sprintf("Roles.%d", i)] = envoyx.Ref{
|
||||
ResourceType: types.RoleResourceType,
|
||||
Identifiers: envoyx.MakeIdentifiers(n.Value),
|
||||
}
|
||||
|
||||
return nil
|
||||
})
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func (d *auxYamlDoc) unmarshalAuthClientSecurityNode(r *types.AuthClient, n *yaml.Node) (refs map[string]envoyx.Ref, idents envoyx.Identifiers, err error) {
|
||||
refs = make(map[string]envoyx.Ref)
|
||||
|
||||
err = y7s.EachMap(n, func(k, v *yaml.Node) (err error) {
|
||||
switch strings.ToLower(k.Value) {
|
||||
case "impersonateuser":
|
||||
var av string
|
||||
err = y7s.DecodeScalar(v, "Impersonate user", &av)
|
||||
|
||||
refs["Security.ImpersonateUser"] = envoyx.Ref{
|
||||
ResourceType: types.UserResourceType,
|
||||
Identifiers: envoyx.MakeIdentifiers(av),
|
||||
}
|
||||
break
|
||||
|
||||
case "permittedroles":
|
||||
refs = envoyx.MergeRefs(refs, roleSliceToRefs("Security.PermittedRoles", v))
|
||||
break
|
||||
|
||||
case "prohibitedroles":
|
||||
refs = envoyx.MergeRefs(refs, roleSliceToRefs("Security.ProhibitedRoles", v))
|
||||
break
|
||||
|
||||
case "forcedroles":
|
||||
refs = envoyx.MergeRefs(refs, roleSliceToRefs("Security.ForcedRoles", v))
|
||||
break
|
||||
|
||||
}
|
||||
|
||||
return nil
|
||||
})
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func roleSliceToRefs(k string, n *yaml.Node) (refs map[string]envoyx.Ref) {
|
||||
i := 0
|
||||
y7s.EachSeq(n, func(n *yaml.Node) error {
|
||||
refs[fmt.Sprintf("%s.%d", k, i)] = envoyx.Ref{
|
||||
ResourceType: types.RoleResourceType,
|
||||
Identifiers: envoyx.MakeIdentifiers(n.Value),
|
||||
}
|
||||
i++
|
||||
return nil
|
||||
})
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
Generated
+18
-1
@@ -316,6 +316,17 @@ func (e YamlEncoder) encodeApigwRoute(ctx context.Context, p envoyx.EncodeParams
|
||||
var aux *yaml.Node
|
||||
_ = aux
|
||||
|
||||
aux, err = e.encodeApigwFilters(ctx, p, tt.ChildrenForResourceType(node, types.ApigwFilterResourceType), tt)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
out, err = y7s.AddMap(out,
|
||||
"filters", aux,
|
||||
)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
@@ -454,6 +465,11 @@ func (e YamlEncoder) encodeAuthClient(ctx context.Context, p envoyx.EncodeParams
|
||||
return
|
||||
}
|
||||
|
||||
auxSecurity, err := e.encodeAuthClientSecurityC(ctx, p, tt, node, res, res.Security)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
auxUpdatedAt, err := e.encodeTimestampNil(p, res.UpdatedAt)
|
||||
if err != nil {
|
||||
return
|
||||
@@ -481,7 +497,7 @@ func (e YamlEncoder) encodeAuthClient(ctx context.Context, p envoyx.EncodeParams
|
||||
"redirectURI", res.RedirectURI,
|
||||
"scope", res.Scope,
|
||||
"secret", res.Secret,
|
||||
"security", res.Security,
|
||||
"security", auxSecurity,
|
||||
"trusted", res.Trusted,
|
||||
"updatedAt", auxUpdatedAt,
|
||||
"updatedBy", auxUpdatedBy,
|
||||
@@ -853,6 +869,7 @@ func (e YamlEncoder) encodeUser(ctx context.Context, p envoyx.EncodeParams, node
|
||||
"kind", res.Kind,
|
||||
"meta", res.Meta,
|
||||
"name", res.Name,
|
||||
"roles", res.Roles,
|
||||
"suspendedAt", auxSuspendedAt,
|
||||
"updatedAt", auxUpdatedAt,
|
||||
"username", res.Username,
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
package envoy
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/cortezaproject/corteza/server/pkg/envoyx"
|
||||
"github.com/cortezaproject/corteza/server/pkg/y7s"
|
||||
"github.com/cortezaproject/corteza/server/system/types"
|
||||
"gopkg.in/yaml.v3"
|
||||
)
|
||||
|
||||
func (e YamlEncoder) encodeAuthClientSecurityC(ctx context.Context, p envoyx.EncodeParams, tt envoyx.Traverser, n *envoyx.Node, ac *types.AuthClient, sec *types.AuthClientSecurity) (_ any, err error) {
|
||||
sqPermittedRoles, err := e.encodeRoleSlice(n, tt, "Security.PermittedRoles", sec.PermittedRoles)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
sqProhibitedRoles, err := e.encodeRoleSlice(n, tt, "Security.ProhibitedRoles", sec.ProhibitedRoles)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
sqForcedRoles, err := e.encodeRoleSlice(n, tt, "Security.ForcedRoles", sec.ForcedRoles)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
var impersonateUser string
|
||||
if _, ok := n.References["Security.ImpersonateUser.UserID"]; ok {
|
||||
node := tt.ParentForRef(n, n.References["Security.ImpersonateUser.UserID"])
|
||||
if node == nil {
|
||||
err = fmt.Errorf("node not found @todo error")
|
||||
return
|
||||
}
|
||||
impersonateUser = n.Identifiers.FriendlyIdentifier()
|
||||
}
|
||||
|
||||
return y7s.MakeMap(
|
||||
"impersonateUser", impersonateUser,
|
||||
"permittedRoles", sqPermittedRoles,
|
||||
"prohibitedRoles", sqProhibitedRoles,
|
||||
"forcedRoles", sqForcedRoles,
|
||||
)
|
||||
}
|
||||
|
||||
func (e YamlEncoder) encodeRoleSlice(n *envoyx.Node, tt envoyx.Traverser, k string, rr []string) (out *yaml.Node, err error) {
|
||||
sq, _ := y7s.MakeSeq()
|
||||
|
||||
for i := range rr {
|
||||
node := tt.ParentForRef(n, n.References[fmt.Sprintf("%s.%d.RoleID", k, i)])
|
||||
if node == nil {
|
||||
err = fmt.Errorf("node not found @todo error")
|
||||
return
|
||||
}
|
||||
|
||||
sq, err = y7s.AddSeq(sq, node.Identifiers.FriendlyIdentifier())
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
return sq, nil
|
||||
}
|
||||
@@ -24,6 +24,17 @@ user: {
|
||||
ignoreCase: true
|
||||
dal: {}
|
||||
}
|
||||
roles: {
|
||||
goType: "[]uint64",
|
||||
store: false
|
||||
omitSetter: true
|
||||
omitGetter: true
|
||||
envoy: {
|
||||
yaml: {
|
||||
customDecoder: true
|
||||
}
|
||||
}
|
||||
}
|
||||
name: {
|
||||
sortable: true
|
||||
dal: {}
|
||||
|
||||
Reference in New Issue
Block a user