snapshot of https://github.com/cortezaproject/corteza.git (2024.9.x, 2026-09-18; blobs > 131072B omitted)
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
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
This commit is contained in:
124
server/pkg/envoyx/datasource.go
Normal file
124
server/pkg/envoyx/datasource.go
Normal file
@@ -0,0 +1,124 @@
|
||||
package envoyx
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strings"
|
||||
|
||||
"github.com/cortezaproject/corteza/server/pkg/envoyx/datasource"
|
||||
"github.com/cortezaproject/corteza/server/pkg/y7s"
|
||||
"gopkg.in/yaml.v3"
|
||||
)
|
||||
|
||||
type (
|
||||
Provider interface {
|
||||
Next(ctx context.Context, out datasource.RawRecord) (more bool, err error)
|
||||
Reset(ctx context.Context) error
|
||||
SetIdent(string)
|
||||
SetConfigs(map[string]any) error
|
||||
Ident() string
|
||||
}
|
||||
|
||||
Datasource interface {
|
||||
Next(ctx context.Context, out datasource.RawRecord) (ident []string, more bool, err error)
|
||||
Reset(ctx context.Context) error
|
||||
SetProvider(Provider) bool
|
||||
}
|
||||
|
||||
MapEntry struct {
|
||||
Column string
|
||||
Field string
|
||||
Skip bool
|
||||
}
|
||||
|
||||
FieldMapping struct {
|
||||
// @note This had to be like so to simplify decoding
|
||||
Map map[string]MapEntry
|
||||
}
|
||||
|
||||
DatasourceMapping struct {
|
||||
SourceIdent string `yaml:"source"`
|
||||
KeyField []string `yaml:"key"`
|
||||
References map[string]string
|
||||
Scope map[string]string
|
||||
|
||||
// Defaultable indicates wether the mapping should keep the values where
|
||||
// the ident is not explicitly mapped.
|
||||
//
|
||||
// When true, the value is assigned to the given identifier.
|
||||
Defaultable bool `yaml:"defaultable"`
|
||||
Mapping FieldMapping
|
||||
}
|
||||
)
|
||||
|
||||
func SetDecoderSources(nn NodeSet, dd ...Provider) {
|
||||
for _, n := range nn {
|
||||
if n.Datasource == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
for _, d := range dd {
|
||||
if n.Datasource.SetProvider(d) {
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// UnmarshalYAML is used to get the yaml parsed into a series of nodes so
|
||||
// we can easily pass it down
|
||||
func (d *FieldMapping) UnmarshalYAML(n *yaml.Node) (err error) {
|
||||
d.Map = make(map[string]MapEntry)
|
||||
if y7s.IsSeq(n) {
|
||||
err = y7s.EachSeq(n, func(n *yaml.Node) error {
|
||||
a, err := d.unmarshalMappingNode(n)
|
||||
d.Map[a.Column] = a
|
||||
return err
|
||||
})
|
||||
} else {
|
||||
err = y7s.EachMap(n, func(k, n *yaml.Node) error {
|
||||
a, err := d.unmarshalMappingNode(n)
|
||||
if a.Column == "" {
|
||||
err = y7s.DecodeScalar(k, "fieldMapping column", &a.Column)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
d.Map[a.Column] = a
|
||||
return err
|
||||
})
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func (d *FieldMapping) unmarshalMappingNode(n *yaml.Node) (out MapEntry, err error) {
|
||||
if y7s.IsKind(n, yaml.ScalarNode) {
|
||||
err = y7s.DecodeScalar(n, "Column", &out.Column)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
err = y7s.DecodeScalar(n, "Field", &out.Field)
|
||||
return
|
||||
}
|
||||
|
||||
// @todo we're omitting errors because there will be a bunch due to invalid
|
||||
// resource field types. This might be a bit unstable as other errors may
|
||||
// also get ignored.
|
||||
//
|
||||
// A potential fix would be to firstly unmarshal into an any, check errors
|
||||
// and then unmarshal into the resource while omitting errors.
|
||||
n.Decode(&out)
|
||||
|
||||
err = y7s.EachMap(n, func(k, v *yaml.Node) error {
|
||||
switch strings.ToLower(k.Value) {
|
||||
case "skip":
|
||||
if v.Value == "/" {
|
||||
out.Skip = true
|
||||
}
|
||||
}
|
||||
return nil
|
||||
})
|
||||
|
||||
return
|
||||
}
|
||||
Reference in New Issue
Block a user