Skip to content

Commit 830e789

Browse files
committed
Fix Validator Config
Use the server config provided validator config, by copying it to the datastoreconfigs.
1 parent 1dc332e commit 830e789

File tree

5 files changed

+30
-13
lines changed

5 files changed

+30
-13
lines changed

pkg/config/validation.go

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,22 @@
11
package config
22

33
type Validation struct {
4-
DisabledValidators Validators `yaml:"disabled-validators,omitempty" json:"disabled-validators,omitempty"`
5-
DisableConcurrency bool `yaml:"disable-concurrency,omitempty" json:"disable-concurrency,omitempty"`
4+
DisabledValidators *Validators `yaml:"disabled-validators,omitempty" json:"disabled-validators,omitempty"`
5+
DisableConcurrency bool `yaml:"disable-concurrency,omitempty" json:"disable-concurrency,omitempty"`
66
}
77

88
func (v *Validation) validateSetDefaults() error {
9+
// no change required, all the bools default to false
910
return nil
1011
}
1112

13+
func (v *Validation) DeepCopy() *Validation {
14+
return &Validation{
15+
DisabledValidators: v.DisabledValidators.DeepCopy(),
16+
DisableConcurrency: v.DisableConcurrency,
17+
}
18+
}
19+
1220
type Validators struct {
1321
Mandatory bool `yaml:"mandatory,omitempty" json:"mandatory,omitempty"`
1422
Leafref bool `yaml:"leafref,omitempty" json:"leafref,omitempty"`
@@ -30,3 +38,16 @@ func (v *Validators) DisableAll() {
3038
v.Pattern = true
3139
v.Range = true
3240
}
41+
42+
func (v *Validators) DeepCopy() *Validators {
43+
return &Validators{
44+
Mandatory: v.Mandatory,
45+
Leafref: v.Leafref,
46+
LeafrefMinMaxAttributes: v.LeafrefMinMaxAttributes,
47+
Pattern: v.Pattern,
48+
MustStatement: v.MustStatement,
49+
Length: v.Length,
50+
Range: v.Range,
51+
MaxElements: v.MaxElements,
52+
}
53+
}

pkg/datastore/transaction_rpc.go

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"strings"
88
"time"
99

10-
"github.com/sdcio/data-server/pkg/config"
1110
"github.com/sdcio/data-server/pkg/datastore/types"
1211
"github.com/sdcio/data-server/pkg/tree"
1312
treeproto "github.com/sdcio/data-server/pkg/tree/importer/proto"
@@ -23,10 +22,6 @@ var (
2322
ErrValidationError = errors.New("validation error")
2423
)
2524

26-
const (
27-
ConcurrentValidate = false
28-
)
29-
3025
// SdcpbTransactionIntentToInternalTI converts sdcpb.TransactionIntent to types.TransactionIntent
3126
func (d *Datastore) SdcpbTransactionIntentToInternalTI(ctx context.Context, req *sdcpb.TransactionIntent) (*types.TransactionIntent, error) {
3227

@@ -96,7 +91,7 @@ func (d *Datastore) replaceIntent(ctx context.Context, transaction *types.Transa
9691
log.TraceFn(func() []interface{} { return []interface{}{root.String()} })
9792

9893
// perform validation
99-
validationResult := root.Validate(ctx, &config.Validation{DisableConcurrency: !ConcurrentValidate})
94+
validationResult := root.Validate(ctx, d.config.Validation)
10095
validationResult.ErrorsStr()
10196
if validationResult.HasErrors() {
10297
return nil, validationResult.JoinErrors()
@@ -126,7 +121,7 @@ func (d *Datastore) replaceIntent(ctx context.Context, transaction *types.Transa
126121
func (d *Datastore) LoadAllButRunningIntents(ctx context.Context, root *tree.RootEntry) ([]string, error) {
127122

128123
intentNames := []string{}
129-
IntentChan := make(chan *tree_persist.Intent, 0)
124+
IntentChan := make(chan *tree_persist.Intent)
130125
ErrChan := make(chan error, 1)
131126

132127
go d.cacheClient.IntentGetAll(ctx, []string{"running"}, IntentChan, ErrChan)
@@ -223,7 +218,7 @@ func (d *Datastore) lowlevelTransactionSet(ctx context.Context, transaction *typ
223218
log.Debug(root.String())
224219

225220
// perform validation
226-
validationResult := root.Validate(ctx, &config.Validation{DisableConcurrency: !ConcurrentValidate})
221+
validationResult := root.Validate(ctx, d.config.Validation)
227222

228223
// prepare the response struct
229224
result := &sdcpb.TransactionSetResponse{

pkg/server/datastore.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,8 @@ func (s *Server) CreateDataStore(ctx context.Context, req *sdcpb.CreateDataStore
132132
Vendor: req.GetSchema().GetVendor(),
133133
Version: req.GetSchema().GetVersion(),
134134
},
135-
SBI: sbi,
135+
SBI: sbi,
136+
Validation: s.config.Validation.DeepCopy(),
136137
}
137138
if req.GetSync() != nil {
138139
dsConfig.Sync = &config.Sync{

pkg/tree/default_value_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ func TestDefaultValueRetrieve(t *testing.T) {
149149
return rsp.GetSchema()
150150
},
151151
wanterr: false,
152-
want: types.NewUpdate(types.PathSlice{}, &sdcpb.TypedValue{Value: &sdcpb.TypedValue_LeaflistVal{LeaflistVal: &sdcpb.ScalarArray{Element: []*sdcpb.TypedValue{&sdcpb.TypedValue{Value: &sdcpb.TypedValue_StringVal{StringVal: "foo"}}, &sdcpb.TypedValue{Value: &sdcpb.TypedValue_StringVal{StringVal: "bar"}}}}}}, 5, "owner1", 0),
152+
want: types.NewUpdate(types.PathSlice{}, &sdcpb.TypedValue{Value: &sdcpb.TypedValue_LeaflistVal{LeaflistVal: &sdcpb.ScalarArray{Element: []*sdcpb.TypedValue{{Value: &sdcpb.TypedValue_StringVal{StringVal: "foo"}}, {Value: &sdcpb.TypedValue_StringVal{StringVal: "bar"}}}}}}, 5, "owner1", 0),
153153
},
154154
}
155155
for _, tt := range tests {

pkg/tree/sharedEntryAttributes_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -718,7 +718,7 @@ func Test_sharedEntryAttributes_validateMandatory(t *testing.T) {
718718
dv.DisableAll()
719719
dv.Mandatory = false
720720

721-
validationResults := root.Validate(ctx, &config.Validation{DisableConcurrency: true, DisabledValidators: *dv})
721+
validationResults := root.Validate(ctx, &config.Validation{DisableConcurrency: true, DisabledValidators: dv})
722722

723723
results := []string{}
724724
for _, e := range validationResults {

0 commit comments

Comments
 (0)