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
110 lines
2.3 KiB
Go
110 lines
2.3 KiB
Go
package yaml
|
|
|
|
import (
|
|
"strings"
|
|
|
|
"github.com/cortezaproject/corteza/server/pkg/envoy/resource"
|
|
"github.com/cortezaproject/corteza/server/pkg/y7s"
|
|
"gopkg.in/yaml.v3"
|
|
)
|
|
|
|
func decodeTimestamps(n *yaml.Node) (*resource.Timestamps, error) {
|
|
var (
|
|
st = &resource.Timestamps{}
|
|
)
|
|
|
|
// Little helper to make timestamps
|
|
f := func(v *yaml.Node) (*resource.Timestamp, error) {
|
|
aux := ""
|
|
err := y7s.DecodeScalar(v, "decode "+v.Value, &aux)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return resource.MakeTimestamp(aux), nil
|
|
}
|
|
|
|
return st, y7s.EachMap(n, func(k, v *yaml.Node) (err error) {
|
|
switch strings.ToLower(k.Value) {
|
|
case "createdat":
|
|
st.CreatedAt, err = f(v)
|
|
case "updatedat":
|
|
st.UpdatedAt, err = f(v)
|
|
case "deletedat":
|
|
st.DeletedAt, err = f(v)
|
|
case "suspendedat":
|
|
st.SuspendedAt, err = f(v)
|
|
case "archivedat":
|
|
st.ArchivedAt, err = f(v)
|
|
}
|
|
return err
|
|
})
|
|
}
|
|
|
|
func decodeUserstamps(n *yaml.Node) (*resource.Userstamps, error) {
|
|
var (
|
|
us = &resource.Userstamps{}
|
|
)
|
|
|
|
// Little helper to make userstamps
|
|
f := func(v *yaml.Node) (*resource.Userstamp, error) {
|
|
aux := ""
|
|
err := y7s.DecodeScalar(v, "decode "+v.Value, &aux)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return resource.MakeUserstampFromRef(aux), nil
|
|
}
|
|
|
|
return us, y7s.EachMap(n, func(k, v *yaml.Node) (err error) {
|
|
switch strings.ToLower(k.Value) {
|
|
case "createdby",
|
|
"creatorid",
|
|
"creator":
|
|
us.CreatedBy, err = f(v)
|
|
case "updatedby":
|
|
us.UpdatedBy, err = f(v)
|
|
case "deletedby":
|
|
us.DeletedBy, err = f(v)
|
|
case "ownedby",
|
|
"ownerid",
|
|
"owner":
|
|
us.OwnedBy, err = f(v)
|
|
case "runas",
|
|
"runasid",
|
|
"runner":
|
|
us.RunAs, err = f(v)
|
|
}
|
|
return err
|
|
})
|
|
}
|
|
|
|
// mapTimestamps helper encodes Timestamps into the mapping node
|
|
func encodeTimestamps(n *yaml.Node, ts *resource.Timestamps) (*yaml.Node, error) {
|
|
if ts == nil {
|
|
return n, nil
|
|
}
|
|
|
|
return addMap(n,
|
|
"createdAt", ts.CreatedAt,
|
|
"updatedAt", ts.UpdatedAt,
|
|
"deletedAt", ts.DeletedAt,
|
|
"archivedAt", ts.ArchivedAt,
|
|
"suspendedAt", ts.SuspendedAt,
|
|
)
|
|
}
|
|
|
|
// mapUserstamps helper encodes Userstamps into the mapping node
|
|
func encodeUserstamps(n *yaml.Node, us *resource.Userstamps) (*yaml.Node, error) {
|
|
if us == nil {
|
|
return n, nil
|
|
}
|
|
|
|
return addMap(n,
|
|
"createdBy", us.CreatedBy,
|
|
"updatedBy", us.UpdatedBy,
|
|
"deletedBy", us.DeletedBy,
|
|
"ownedBy", us.OwnedBy,
|
|
"runAs", us.RunAs,
|
|
)
|
|
}
|