Fix Envoy setting value handling
This commit is contained in:
@@ -61,6 +61,8 @@ func (n *setting) Encode(ctx context.Context, pl *payload) (err error) {
|
||||
} else {
|
||||
res.UpdatedAt = *now()
|
||||
}
|
||||
} else {
|
||||
res.UpdatedAt = *now()
|
||||
}
|
||||
|
||||
if us != nil {
|
||||
|
||||
@@ -2,6 +2,7 @@ package yaml
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
|
||||
"github.com/cortezaproject/corteza-server/pkg/envoy"
|
||||
"github.com/cortezaproject/corteza-server/pkg/envoy/resource"
|
||||
@@ -53,9 +54,14 @@ func (n *setting) Encode(ctx context.Context, doc *Document, state *envoy.Resour
|
||||
}
|
||||
|
||||
func (c *setting) MarshalYAML() (interface{}, error) {
|
||||
var aux interface{}
|
||||
err := json.Unmarshal(c.res.Value, &aux)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
nn, err := makeMap(
|
||||
"name", c.res.Name,
|
||||
"value", c.res.Value.String(),
|
||||
"value", aux,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -30,15 +30,60 @@ func (wset *settingSet) UnmarshalYAML(n *yaml.Node) error {
|
||||
}
|
||||
|
||||
default:
|
||||
jj, err := json.Marshal(v.Value)
|
||||
if err != nil {
|
||||
return y7s.NodeErr(n, err.Error())
|
||||
}
|
||||
wrap.res.Value = jj
|
||||
|
||||
if err = y7s.DecodeScalar(k, "setting", &wrap.res.Name); err != nil {
|
||||
if err = y7s.DecodeScalar(k, "setting name", &wrap.res.Name); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if y7s.IsKind(v, yaml.SequenceNode) {
|
||||
aux := make([]interface{}, 0, 10)
|
||||
|
||||
y7s.EachSeq(v, func(n *yaml.Node) error {
|
||||
var vx interface{}
|
||||
err := y7s.DecodeScalar(n, "setting value", &vx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
aux = append(aux, vx)
|
||||
return nil
|
||||
})
|
||||
|
||||
m, err := json.Marshal(aux)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
wrap.res.Value = sqlt.JSONText(m)
|
||||
} else if y7s.IsKind(v, yaml.MappingNode) {
|
||||
aux := make(map[string]interface{})
|
||||
|
||||
y7s.EachMap(v, func(k, v *yaml.Node) error {
|
||||
var vx interface{}
|
||||
err := y7s.DecodeScalar(v, "setting value", &vx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
aux[k.Value] = vx
|
||||
return nil
|
||||
})
|
||||
|
||||
m, err := json.Marshal(aux)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
wrap.res.Value = sqlt.JSONText(m)
|
||||
} else {
|
||||
var aux interface{}
|
||||
err = y7s.DecodeScalar(v, "setting value", &aux)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
m, err := json.Marshal(aux)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
wrap.res.Value = sqlt.JSONText(m)
|
||||
}
|
||||
}
|
||||
|
||||
*wset = append(*wset, wrap)
|
||||
@@ -80,12 +125,16 @@ func (wrap *setting) UnmarshalYAML(n *yaml.Node) (err error) {
|
||||
return y7s.DecodeScalar(v, "setting name", &wrap.res.Name)
|
||||
|
||||
case "value":
|
||||
aux := ""
|
||||
var aux interface{}
|
||||
err = y7s.DecodeScalar(v, "setting value", &aux)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
wrap.res.Value = sqlt.JSONText(aux)
|
||||
m, err := json.Marshal(aux)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
wrap.res.Value = sqlt.JSONText(m)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -8888,6 +8888,78 @@ modules:
|
||||
options:
|
||||
format: "0000000"
|
||||
precision: 0
|
||||
ScoreBudget:
|
||||
label: Budget
|
||||
kind: Number
|
||||
options:
|
||||
format: "0"
|
||||
precision: 2
|
||||
ScoreAuthority:
|
||||
label: Authority
|
||||
kind: Number
|
||||
options:
|
||||
format: "0"
|
||||
precision: 2
|
||||
ScoreNeed:
|
||||
label: Need
|
||||
kind: Number
|
||||
options:
|
||||
format: "0"
|
||||
precision: 2
|
||||
ScoreTimescale:
|
||||
label: Timescale
|
||||
kind: Number
|
||||
options:
|
||||
format: "0"
|
||||
precision: 2
|
||||
ScoreTurnover:
|
||||
label: Turnover
|
||||
kind: Number
|
||||
options:
|
||||
format: "0"
|
||||
precision: 2
|
||||
ScoreYearsInBusiness:
|
||||
label: Yrs in Business
|
||||
kind: Number
|
||||
options:
|
||||
format: "0"
|
||||
precision: 2
|
||||
ScoreSource:
|
||||
label: Source
|
||||
kind: Number
|
||||
options:
|
||||
format: "0"
|
||||
precision: 2
|
||||
ScoreProductKnowlege:
|
||||
label: Product Knowlege
|
||||
kind: Number
|
||||
options:
|
||||
format: "0"
|
||||
precision: 2
|
||||
ScoreTechnicalDepth:
|
||||
label: Technical Depth
|
||||
kind: Number
|
||||
options:
|
||||
format: "0"
|
||||
precision: 2
|
||||
ScoreCompetition:
|
||||
label: Competition
|
||||
kind: Number
|
||||
options:
|
||||
format: "0"
|
||||
precision: 2
|
||||
ScoreCriticality:
|
||||
label:
|
||||
kind: Number
|
||||
options:
|
||||
format: "0"
|
||||
precision: 2
|
||||
ScoreRepeatPurchase:
|
||||
label: Repeat Purchase
|
||||
kind: Number
|
||||
options:
|
||||
format: "0"
|
||||
precision: 2
|
||||
Solution:
|
||||
(envoy): { onExisting: "skip" }
|
||||
name: Solution
|
||||
|
||||
@@ -3,14 +3,15 @@ package service
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/cortezaproject/corteza-server/pkg/errors"
|
||||
"github.com/cortezaproject/corteza-server/pkg/logger"
|
||||
"github.com/cortezaproject/corteza-server/store"
|
||||
"github.com/cortezaproject/corteza-server/system/types"
|
||||
"go.uber.org/zap"
|
||||
"go.uber.org/zap/zapcore"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
type (
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
package types
|
||||
|
||||
import (
|
||||
"github.com/pkg/errors"
|
||||
"reflect"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
type (
|
||||
|
||||
@@ -542,13 +542,13 @@ func TestStoreYaml_base(t *testing.T) {
|
||||
|
||||
sv := ss[0]
|
||||
req.Equal("base_setting_1", sv.Name)
|
||||
req.Equal("{\"k\": \"vs1\"}", sv.Value.String())
|
||||
req.Equal("10", sv.Value.String())
|
||||
req.Equal(updatedAt.Format(time.RFC3339), sv.UpdatedAt.Format(time.RFC3339))
|
||||
req.Equal(usr.ID, sv.UpdatedBy)
|
||||
|
||||
sv = ss[1]
|
||||
req.Equal("base_setting_2", sv.Name)
|
||||
req.Equal("{\"k\": \"vs2\"}", sv.Value.String())
|
||||
req.Equal("20", sv.Value.String())
|
||||
req.Equal(updatedAt.Format(time.RFC3339), sv.UpdatedAt.Format(time.RFC3339))
|
||||
req.Equal(usr.ID, sv.UpdatedBy)
|
||||
},
|
||||
|
||||
@@ -83,13 +83,13 @@ func sTestSettings(ctx context.Context, t *testing.T, s store.Storer, usrID uint
|
||||
ss := types.SettingValueSet{
|
||||
{
|
||||
Name: pfx + "_setting_1",
|
||||
Value: []byte("{\"k\": \"vs1\"}"),
|
||||
Value: []byte(`10`),
|
||||
UpdatedAt: updatedAt,
|
||||
UpdatedBy: usrID,
|
||||
},
|
||||
{
|
||||
Name: pfx + "_setting_2",
|
||||
Value: []byte("{\"k\": \"vs2\"}"),
|
||||
Value: []byte(`20`),
|
||||
UpdatedAt: updatedAt,
|
||||
UpdatedBy: usrID,
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user