From 1cd0352babec193e0819289ed9114040067872b8 Mon Sep 17 00:00:00 2001 From: Pavel Karpy Date: Fri, 18 Jun 2021 13:35:31 +0300 Subject: [PATCH] [#622] pkg/innerring: Add composite validator Add `CompositeValidator` that wraps `netmap.NodeValidator`s and implements `NodeValidator` interface itself. Signed-off-by: Pavel Karpy --- .../nodevalidation/maddress/validator.go | 2 +- .../netmap/nodevalidation/validator.go | 37 +++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 pkg/innerring/processors/netmap/nodevalidation/validator.go diff --git a/pkg/innerring/processors/netmap/nodevalidation/maddress/validator.go b/pkg/innerring/processors/netmap/nodevalidation/maddress/validator.go index 91bb8da26..8f0c0f786 100644 --- a/pkg/innerring/processors/netmap/nodevalidation/maddress/validator.go +++ b/pkg/innerring/processors/netmap/nodevalidation/maddress/validator.go @@ -6,7 +6,7 @@ package maddress // For correct operation, Validator must be created // using the constructor (New). After successful creation, // the Validator is immediately ready to work through API. -type Validator struct {} +type Validator struct{} // New creates a new instance of the Validator. // diff --git a/pkg/innerring/processors/netmap/nodevalidation/validator.go b/pkg/innerring/processors/netmap/nodevalidation/validator.go new file mode 100644 index 000000000..23fa64515 --- /dev/null +++ b/pkg/innerring/processors/netmap/nodevalidation/validator.go @@ -0,0 +1,37 @@ +package nodevalidation + +import ( + apinetmap "github.com/nspcc-dev/neofs-api-go/pkg/netmap" + "github.com/nspcc-dev/neofs-node/pkg/innerring/processors/netmap" +) + +// CompositeValidator wraps `netmap.NodeValidator`s. +// +// For correct operation, CompositeValidator must be created +// using the constructor (New). After successful creation, +// the CompositeValidator is immediately ready to work through +// API. +type CompositeValidator struct { + validators []netmap.NodeValidator +} + +// New creates a new instance of the CompositeValidator. +// +// The created CompositeValidator does not require additional +// initialization and is completely ready for work. +func New(validators ...netmap.NodeValidator) *CompositeValidator { + return &CompositeValidator{validators} +} + +// VerifyAndUpdate passes apinetmap.NodeInfo to wrapped validators. +// +// If error appears, returns it immediately. +func (c *CompositeValidator) VerifyAndUpdate(ni *apinetmap.NodeInfo) error { + for _, v := range c.validators { + if err := v.VerifyAndUpdate(ni); err != nil { + return err + } + } + + return nil +}