forked from TrueCloudLab/frostfs-api-go
[#194] pkg/container: Implement container constructor with format check
Implement NewVerifiedFromV2 function that verifies format of NeoFS API V2 Container message. Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
parent
70c29ca3e5
commit
7988405753
3 changed files with 80 additions and 0 deletions
27
pkg/container/fmt.go
Normal file
27
pkg/container/fmt.go
Normal file
|
@ -0,0 +1,27 @@
|
|||
package container
|
||||
|
||||
import (
|
||||
"github.com/nspcc-dev/neofs-api-go/pkg"
|
||||
"github.com/nspcc-dev/neofs-api-go/v2/container"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
// NewVerifiedFromV2 constructs Container from NeoFS API V2 Container message.
|
||||
// Returns error if message does not meet NeoFS API V2 specification.
|
||||
//
|
||||
// Additionally checks if message carries supported version.
|
||||
func NewVerifiedFromV2(cnrV2 *container.Container) (*Container, error) {
|
||||
cnr := NewContainerFromV2(cnrV2)
|
||||
|
||||
// check version support
|
||||
if err := pkg.IsSupportedVersion(cnr.Version()); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// check nonce format
|
||||
if _, err := cnr.NonceUUID(); err != nil {
|
||||
return nil, errors.Wrap(err, "invalid nonce")
|
||||
}
|
||||
|
||||
return cnr, nil
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue