Skip to content

Commit 2ebda70

Browse files
committed
validate ranges
1 parent e012382 commit 2ebda70

File tree

2 files changed

+24
-13
lines changed

2 files changed

+24
-13
lines changed

pkg/tree/entry.go

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -641,20 +641,40 @@ func (s *sharedEntryAttributes) Validate(ctx context.Context, errchan chan<- err
641641
}(c)
642642
}
643643

644-
// TODO: Validate Mandatory is skipped for now, until we have running
645-
// configuration information in the tree, to perform proper validation
646-
647-
// // validate the mandatory statement on this entry
644+
// validate the mandatory statement on this entry
648645
if s.remainsToExist() {
649646
s.validateMandatory(errchan)
650647
s.validateLeafRefs(ctx, errchan)
651648
s.validateLeafListMinMaxAttributes(errchan)
652649
s.validatePattern(errchan)
653650
s.validateMustStatements(ctx, errchan)
654651
s.validateLength(errchan)
652+
s.validateRange(errchan)
655653
}
656654
}
657655

656+
func (s *sharedEntryAttributes) validateRange(errchan chan<- error) {
657+
658+
lv := s.leafVariants.GetHighestPrecedence(false)
659+
if lv == nil {
660+
return
661+
}
662+
663+
tv, err := lv.Value()
664+
if err != nil {
665+
errchan <- fmt.Errorf("failed reading value from %s LeafVariant %v: %w", s.Path(), lv, err)
666+
return
667+
}
668+
669+
if schema := s.schema.GetField(); schema != nil {
670+
for _, rng := range schema.GetType().Range {
671+
_ = tv
672+
_ = rng
673+
}
674+
}
675+
676+
}
677+
658678
// validateLeafListMinMaxAttributes validates the Min-, and Max-Elements attribute of the Entry if it is a Leaflists.
659679
func (s *sharedEntryAttributes) validateLeafListMinMaxAttributes(errchan chan<- error) {
660680
if schema := s.schema.GetLeaflist(); schema != nil {
@@ -679,14 +699,6 @@ func (s *sharedEntryAttributes) validateLeafListMinMaxAttributes(errchan chan<-
679699
}
680700
}
681701

682-
// func (s *sharedEntryAttributes) validateUnique(errchan chan<- error) {
683-
// if schema := s.schema.GetLeaflist(); schema != nil {
684-
// if schema. {
685-
// return
686-
// }
687-
// }
688-
// }
689-
690702
func (s *sharedEntryAttributes) validateLength(errchan chan<- error) {
691703
if schema := s.schema.GetField(); schema != nil {
692704

pkg/tree/tree_context.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ type TreeContext struct {
1717
RunningStoreIndex map[string]*cache.Update // contains the keys of the running config
1818
treeSchemaCacheClient TreeSchemaCacheClient
1919
actualOwner string
20-
intendedOnly bool // indicates that if a delete is going on, if the delete will make it through to the device. This info is used for leafref validation
2120
}
2221

2322
func NewTreeContext(tscc TreeSchemaCacheClient, actualOwner string) *TreeContext {

0 commit comments

Comments
 (0)