2020-09-29 12:37:19 +00:00
|
|
|
package object
|
|
|
|
|
|
|
|
import (
|
2023-04-12 14:01:29 +00:00
|
|
|
"context"
|
2021-05-31 08:55:40 +00:00
|
|
|
"crypto/ecdsa"
|
2023-07-28 12:44:35 +00:00
|
|
|
"crypto/sha256"
|
2021-05-18 08:12:51 +00:00
|
|
|
"errors"
|
|
|
|
"fmt"
|
2021-02-15 08:28:42 +00:00
|
|
|
"strconv"
|
2020-09-29 12:37:19 +00:00
|
|
|
|
2023-07-28 12:44:35 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/core/container"
|
2023-03-07 13:38:26 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/core/netmap"
|
2023-08-07 06:54:47 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/util/logger"
|
2024-11-07 14:32:10 +00:00
|
|
|
objectV2 "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/api/object"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/api/refs"
|
2023-08-07 06:54:47 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/acl"
|
2023-03-07 13:38:26 +00:00
|
|
|
frostfsecdsa "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/crypto/ecdsa"
|
2023-07-06 12:36:41 +00:00
|
|
|
objectSDK "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object"
|
2023-03-07 13:38:26 +00:00
|
|
|
oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/user"
|
2020-09-29 12:37:19 +00:00
|
|
|
)
|
|
|
|
|
2022-04-21 11:28:05 +00:00
|
|
|
// FormatValidator represents an object format validator.
|
2020-10-03 10:14:09 +00:00
|
|
|
type FormatValidator struct {
|
|
|
|
*cfg
|
2023-08-07 06:54:47 +00:00
|
|
|
|
|
|
|
senderClassifier SenderClassifier
|
2020-10-03 10:14:09 +00:00
|
|
|
}
|
|
|
|
|
2022-04-21 11:28:05 +00:00
|
|
|
// FormatValidatorOption represents a FormatValidator constructor option.
|
2020-10-03 10:14:09 +00:00
|
|
|
type FormatValidatorOption func(*cfg)
|
|
|
|
|
|
|
|
type cfg struct {
|
2023-07-28 12:44:35 +00:00
|
|
|
netState netmap.State
|
|
|
|
e LockSource
|
|
|
|
ir InnerRing
|
|
|
|
netmap netmap.Source
|
|
|
|
containers container.Source
|
2023-08-07 06:54:47 +00:00
|
|
|
log *logger.Logger
|
2023-07-28 12:44:35 +00:00
|
|
|
verifyTokenIssuer bool
|
|
|
|
}
|
|
|
|
|
2023-03-15 01:07:27 +00:00
|
|
|
// LockSource is a source of lock relations between the objects.
|
|
|
|
type LockSource interface {
|
|
|
|
// IsLocked must clarify object's lock status.
|
2023-04-12 14:01:29 +00:00
|
|
|
IsLocked(ctx context.Context, address oid.Address) (bool, error)
|
2023-03-15 01:07:27 +00:00
|
|
|
}
|
|
|
|
|
2020-09-29 12:37:19 +00:00
|
|
|
var errNilObject = errors.New("object is nil")
|
|
|
|
|
|
|
|
var errNilID = errors.New("missing identifier")
|
|
|
|
|
|
|
|
var errNilCID = errors.New("missing container identifier")
|
|
|
|
|
2021-02-19 09:29:42 +00:00
|
|
|
var errNoExpirationEpoch = errors.New("missing expiration epoch attribute")
|
|
|
|
|
|
|
|
var errTombstoneExpiration = errors.New("tombstone body and header contain different expiration values")
|
|
|
|
|
2023-07-13 13:43:41 +00:00
|
|
|
var errMissingSignature = errors.New("missing signature")
|
|
|
|
|
2020-10-03 10:14:09 +00:00
|
|
|
func defaultCfg() *cfg {
|
|
|
|
return new(cfg)
|
|
|
|
}
|
|
|
|
|
2020-09-29 12:37:19 +00:00
|
|
|
// NewFormatValidator creates, initializes and returns FormatValidator instance.
|
2020-10-03 10:14:09 +00:00
|
|
|
func NewFormatValidator(opts ...FormatValidatorOption) *FormatValidator {
|
|
|
|
cfg := defaultCfg()
|
|
|
|
|
|
|
|
for i := range opts {
|
|
|
|
opts[i](cfg)
|
|
|
|
}
|
|
|
|
|
|
|
|
return &FormatValidator{
|
2023-08-07 06:54:47 +00:00
|
|
|
cfg: cfg,
|
|
|
|
senderClassifier: NewSenderClassifier(cfg.ir, cfg.netmap, cfg.log),
|
2020-10-03 10:14:09 +00:00
|
|
|
}
|
2020-09-29 12:37:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Validate validates object format.
|
|
|
|
//
|
2020-09-30 17:53:12 +00:00
|
|
|
// Does not validate payload checksum and content.
|
2022-04-04 13:04:18 +00:00
|
|
|
// If unprepared is true, only fields set by user are validated.
|
2020-09-30 17:53:12 +00:00
|
|
|
//
|
2022-04-21 11:28:05 +00:00
|
|
|
// Returns nil error if the object has valid structure.
|
2023-07-06 12:36:41 +00:00
|
|
|
func (v *FormatValidator) Validate(ctx context.Context, obj *objectSDK.Object, unprepared bool) error {
|
2020-09-29 12:37:19 +00:00
|
|
|
if obj == nil {
|
|
|
|
return errNilObject
|
2022-05-12 16:37:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
_, idSet := obj.ID()
|
|
|
|
if !unprepared && !idSet {
|
2020-09-29 12:37:19 +00:00
|
|
|
return errNilID
|
2022-05-12 16:37:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
_, cnrSet := obj.ContainerID()
|
|
|
|
if !cnrSet {
|
2020-09-29 12:37:19 +00:00
|
|
|
return errNilCID
|
|
|
|
}
|
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
if err := v.checkOwner(obj); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2021-10-14 17:25:16 +00:00
|
|
|
if err := v.checkAttributes(obj); err != nil {
|
|
|
|
return fmt.Errorf("invalid attributes: %w", err)
|
|
|
|
}
|
2020-10-01 11:42:17 +00:00
|
|
|
|
2024-06-18 12:06:54 +00:00
|
|
|
exp, err := expirationEpochAttribute(obj)
|
|
|
|
if err != nil {
|
|
|
|
if !errors.Is(err, errNoExpirationEpoch) {
|
|
|
|
return fmt.Errorf("object did not pass expiration check: %w", err)
|
|
|
|
}
|
|
|
|
} else if !unprepared && exp < v.netState.CurrentEpoch() {
|
|
|
|
if err := v.checkIfExpired(ctx, obj); err != nil {
|
|
|
|
return fmt.Errorf("object did not pass expiration check: %w", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-04 13:04:18 +00:00
|
|
|
if !unprepared {
|
|
|
|
if err := v.validateSignatureKey(obj); err != nil {
|
|
|
|
return fmt.Errorf("(%T) could not validate signature key: %w", v, err)
|
|
|
|
}
|
2021-02-15 08:28:42 +00:00
|
|
|
|
2023-07-06 12:36:41 +00:00
|
|
|
if err := objectSDK.CheckHeaderVerificationFields(obj); err != nil {
|
2022-04-04 13:04:18 +00:00
|
|
|
return fmt.Errorf("(%T) could not validate header fields: %w", v, err)
|
|
|
|
}
|
2021-10-14 17:25:16 +00:00
|
|
|
}
|
|
|
|
|
2022-03-03 14:19:05 +00:00
|
|
|
if obj = obj.Parent(); obj != nil {
|
2022-04-04 13:04:18 +00:00
|
|
|
// Parent object already exists.
|
2023-04-12 14:01:29 +00:00
|
|
|
return v.Validate(ctx, obj, false)
|
2020-09-29 12:37:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2023-07-06 12:36:41 +00:00
|
|
|
func (v *FormatValidator) validateSignatureKey(obj *objectSDK.Object) error {
|
2022-05-16 13:15:31 +00:00
|
|
|
sig := obj.Signature()
|
|
|
|
if sig == nil {
|
2023-07-13 13:43:41 +00:00
|
|
|
return errMissingSignature
|
2022-05-16 13:15:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var sigV2 refs.Signature
|
|
|
|
sig.WriteToV2(&sigV2)
|
|
|
|
|
2022-05-18 15:20:08 +00:00
|
|
|
binKey := sigV2.GetKey()
|
|
|
|
|
2022-12-23 17:35:35 +00:00
|
|
|
var key frostfsecdsa.PublicKey
|
2022-05-18 15:20:08 +00:00
|
|
|
|
|
|
|
err := key.Decode(binKey)
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("decode public key: %w", err)
|
|
|
|
}
|
|
|
|
|
2020-11-16 09:43:52 +00:00
|
|
|
token := obj.SessionToken()
|
2023-11-21 08:42:30 +00:00
|
|
|
ownerID := obj.OwnerID()
|
2020-09-29 12:37:19 +00:00
|
|
|
|
2024-05-16 07:02:41 +00:00
|
|
|
if token == nil && obj.ECHeader() != nil {
|
|
|
|
role, err := v.isIROrContainerNode(obj, binKey)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if role == acl.RoleContainer {
|
|
|
|
// EC part could be restored or created by container node, so ownerID could not match object signature
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
return v.checkOwnerKey(ownerID, key)
|
|
|
|
}
|
|
|
|
|
2022-05-18 15:20:08 +00:00
|
|
|
if token == nil || !token.AssertAuthKey(&key) {
|
2023-07-17 13:46:46 +00:00
|
|
|
return v.checkOwnerKey(ownerID, key)
|
|
|
|
}
|
|
|
|
|
2023-07-28 12:44:35 +00:00
|
|
|
if v.verifyTokenIssuer {
|
2024-05-16 07:02:41 +00:00
|
|
|
role, err := v.isIROrContainerNode(obj, binKey)
|
2023-07-28 12:44:35 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2024-05-16 07:02:41 +00:00
|
|
|
if role == acl.RoleContainer || role == acl.RoleInnerRing {
|
2023-07-28 12:44:35 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
if !token.Issuer().Equals(ownerID) {
|
|
|
|
return fmt.Errorf("(%T) different token issuer and object owner identifiers %s/%s", v, token.Issuer(), ownerID)
|
|
|
|
}
|
|
|
|
return nil
|
2020-09-29 12:37:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2024-05-16 07:02:41 +00:00
|
|
|
func (v *FormatValidator) isIROrContainerNode(obj *objectSDK.Object, signerKey []byte) (acl.Role, error) {
|
2023-07-28 12:44:35 +00:00
|
|
|
cnrID, containerIDSet := obj.ContainerID()
|
|
|
|
if !containerIDSet {
|
2024-05-16 07:02:41 +00:00
|
|
|
return acl.RoleOthers, errNilCID
|
2023-07-28 12:44:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
cnrIDBin := make([]byte, sha256.Size)
|
|
|
|
cnrID.Encode(cnrIDBin)
|
|
|
|
|
|
|
|
cnr, err := v.containers.Get(cnrID)
|
|
|
|
if err != nil {
|
2024-05-16 07:02:41 +00:00
|
|
|
return acl.RoleOthers, fmt.Errorf("failed to get container (id=%s): %w", cnrID.EncodeToString(), err)
|
2023-07-28 12:44:35 +00:00
|
|
|
}
|
|
|
|
|
2023-08-07 06:54:47 +00:00
|
|
|
res, err := v.senderClassifier.IsInnerRingOrContainerNode(signerKey, cnrID, cnr.Value)
|
2023-07-28 12:44:35 +00:00
|
|
|
if err != nil {
|
2024-05-16 07:02:41 +00:00
|
|
|
return acl.RoleOthers, err
|
2023-07-28 12:44:35 +00:00
|
|
|
}
|
2024-05-16 07:02:41 +00:00
|
|
|
return res.Role, nil
|
2023-07-28 12:44:35 +00:00
|
|
|
}
|
|
|
|
|
2022-12-23 17:35:35 +00:00
|
|
|
func (v *FormatValidator) checkOwnerKey(id user.ID, key frostfsecdsa.PublicKey) error {
|
2022-05-17 13:59:46 +00:00
|
|
|
var id2 user.ID
|
2022-05-18 15:20:08 +00:00
|
|
|
user.IDFromKey(&id2, (ecdsa.PublicKey)(key))
|
2020-09-29 12:37:19 +00:00
|
|
|
|
2022-05-17 13:59:46 +00:00
|
|
|
if !id.Equals(id2) {
|
2021-05-31 10:30:59 +00:00
|
|
|
return fmt.Errorf("(%T) different owner identifiers %s/%s", v, id, id2)
|
2020-09-29 12:37:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
2020-09-30 11:07:28 +00:00
|
|
|
|
2023-02-05 15:59:38 +00:00
|
|
|
// ContentMeta describes FrostFS meta information that brings object's payload if the object
|
2022-11-01 17:32:43 +00:00
|
|
|
// is one of:
|
|
|
|
// - object.TypeTombstone;
|
|
|
|
// - object.TypeLock.
|
|
|
|
type ContentMeta struct {
|
2023-07-06 12:36:41 +00:00
|
|
|
typ objectSDK.Type
|
2022-11-01 17:32:43 +00:00
|
|
|
|
|
|
|
objs []oid.ID
|
|
|
|
}
|
|
|
|
|
|
|
|
// Type returns object's type.
|
2023-07-06 12:36:41 +00:00
|
|
|
func (i ContentMeta) Type() objectSDK.Type {
|
2022-11-01 17:32:43 +00:00
|
|
|
return i.typ
|
|
|
|
}
|
|
|
|
|
|
|
|
// Objects returns objects that the original object's payload affects:
|
|
|
|
// - inhumed objects, if the original object is a Tombstone;
|
|
|
|
// - locked objects, if the original object is a Lock;
|
|
|
|
// - nil, if the original object is a Regular object.
|
|
|
|
func (i ContentMeta) Objects() []oid.ID {
|
|
|
|
return i.objs
|
|
|
|
}
|
|
|
|
|
2022-04-21 11:28:05 +00:00
|
|
|
// ValidateContent validates payload content according to the object type.
|
2023-07-06 12:36:41 +00:00
|
|
|
func (v *FormatValidator) ValidateContent(o *objectSDK.Object) (ContentMeta, error) {
|
2022-11-01 17:32:43 +00:00
|
|
|
meta := ContentMeta{
|
|
|
|
typ: o.Type(),
|
|
|
|
}
|
|
|
|
|
2020-12-01 11:23:28 +00:00
|
|
|
switch o.Type() {
|
2023-07-06 12:36:41 +00:00
|
|
|
case objectSDK.TypeTombstone:
|
2023-04-06 10:02:37 +00:00
|
|
|
if err := v.fillAndValidateTombstoneMeta(o, &meta); err != nil {
|
|
|
|
return ContentMeta{}, err
|
2020-09-30 11:07:28 +00:00
|
|
|
}
|
2023-07-06 12:36:41 +00:00
|
|
|
case objectSDK.TypeLock:
|
2023-04-06 10:02:37 +00:00
|
|
|
if err := v.fillAndValidateLockMeta(o, &meta); err != nil {
|
2022-11-01 17:32:43 +00:00
|
|
|
return ContentMeta{}, err
|
2021-02-19 09:29:42 +00:00
|
|
|
}
|
2023-04-06 10:02:37 +00:00
|
|
|
default:
|
|
|
|
// ignore all other object types, they do not need payload formatting
|
|
|
|
}
|
2021-02-19 09:29:42 +00:00
|
|
|
|
2023-04-06 10:02:37 +00:00
|
|
|
return meta, nil
|
|
|
|
}
|
2021-02-19 09:29:42 +00:00
|
|
|
|
2023-07-06 12:36:41 +00:00
|
|
|
func (v *FormatValidator) fillAndValidateLockMeta(o *objectSDK.Object, meta *ContentMeta) error {
|
2023-04-06 10:02:37 +00:00
|
|
|
if len(o.Payload()) == 0 {
|
|
|
|
return errors.New("empty payload in lock")
|
|
|
|
}
|
2022-05-12 16:37:46 +00:00
|
|
|
|
2023-04-06 10:02:37 +00:00
|
|
|
if _, ok := o.ContainerID(); !ok {
|
|
|
|
return errors.New("missing container")
|
|
|
|
}
|
2020-12-17 16:54:38 +00:00
|
|
|
|
2023-04-06 10:02:37 +00:00
|
|
|
if _, ok := o.ID(); !ok {
|
|
|
|
return errors.New("missing ID")
|
|
|
|
}
|
|
|
|
// check that LOCK object has correct expiration epoch
|
|
|
|
lockExp, err := expirationEpochAttribute(o)
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("lock object expiration epoch: %w", err)
|
|
|
|
}
|
2020-12-17 16:54:38 +00:00
|
|
|
|
2023-04-06 10:02:37 +00:00
|
|
|
if currEpoch := v.netState.CurrentEpoch(); lockExp < currEpoch {
|
|
|
|
return fmt.Errorf("lock object expiration: %d; current: %d", lockExp, currEpoch)
|
|
|
|
}
|
2022-06-07 17:49:38 +00:00
|
|
|
|
2023-07-06 12:36:41 +00:00
|
|
|
var lock objectSDK.Lock
|
2022-11-01 17:32:43 +00:00
|
|
|
|
2023-04-06 10:02:37 +00:00
|
|
|
if err = lock.Unmarshal(o.Payload()); err != nil {
|
|
|
|
return fmt.Errorf("decode lock payload: %w", err)
|
|
|
|
}
|
2022-06-07 17:49:38 +00:00
|
|
|
|
2023-04-06 10:02:37 +00:00
|
|
|
num := lock.NumberOfMembers()
|
|
|
|
if num == 0 {
|
|
|
|
return errors.New("missing locked members")
|
|
|
|
}
|
2022-06-07 17:49:38 +00:00
|
|
|
|
2023-04-06 10:02:37 +00:00
|
|
|
meta.objs = make([]oid.ID, num)
|
|
|
|
lock.ReadMembers(meta.objs)
|
|
|
|
return nil
|
|
|
|
}
|
2022-06-07 17:49:38 +00:00
|
|
|
|
2023-07-06 12:36:41 +00:00
|
|
|
func (v *FormatValidator) fillAndValidateTombstoneMeta(o *objectSDK.Object, meta *ContentMeta) error {
|
2023-04-06 10:02:37 +00:00
|
|
|
if len(o.Payload()) == 0 {
|
|
|
|
return fmt.Errorf("(%T) empty payload in tombstone", v)
|
2020-09-30 11:07:28 +00:00
|
|
|
}
|
|
|
|
|
2023-07-06 12:36:41 +00:00
|
|
|
tombstone := objectSDK.NewTombstone()
|
2023-04-06 10:02:37 +00:00
|
|
|
|
|
|
|
if err := tombstone.Unmarshal(o.Payload()); err != nil {
|
|
|
|
return fmt.Errorf("(%T) could not unmarshal tombstone content: %w", v, err)
|
|
|
|
}
|
|
|
|
// check if the tombstone has the same expiration in the body and the header
|
|
|
|
exp, err := expirationEpochAttribute(o)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if exp != tombstone.ExpirationEpoch() {
|
|
|
|
return errTombstoneExpiration
|
|
|
|
}
|
|
|
|
|
|
|
|
// mark all objects from the tombstone body as removed in the storage engine
|
|
|
|
if _, ok := o.ContainerID(); !ok {
|
|
|
|
return errors.New("missing container ID")
|
|
|
|
}
|
|
|
|
|
|
|
|
meta.objs = tombstone.Members()
|
|
|
|
return nil
|
2020-09-30 11:07:28 +00:00
|
|
|
}
|
2020-10-03 10:14:09 +00:00
|
|
|
|
2021-02-15 08:28:42 +00:00
|
|
|
var errExpired = errors.New("object has expired")
|
|
|
|
|
2024-06-18 12:06:54 +00:00
|
|
|
func (v *FormatValidator) checkIfExpired(ctx context.Context, obj *objectSDK.Object) error {
|
|
|
|
// an object could be expired but locked;
|
|
|
|
// put such an object is a correct operation
|
2023-03-15 01:07:27 +00:00
|
|
|
|
2024-06-18 12:06:54 +00:00
|
|
|
cID, _ := obj.ContainerID()
|
|
|
|
oID, _ := obj.ID()
|
2023-03-15 01:07:27 +00:00
|
|
|
|
2024-06-18 12:06:54 +00:00
|
|
|
var addr oid.Address
|
|
|
|
addr.SetContainer(cID)
|
|
|
|
addr.SetObject(oID)
|
2023-03-15 01:07:27 +00:00
|
|
|
|
2024-06-18 12:06:54 +00:00
|
|
|
locked, err := v.e.IsLocked(ctx, addr)
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("locking status check for an expired object: %w", err)
|
|
|
|
}
|
2023-03-15 01:07:27 +00:00
|
|
|
|
2024-06-18 12:06:54 +00:00
|
|
|
if !locked {
|
|
|
|
return errExpired
|
2021-02-19 09:29:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2023-07-06 12:36:41 +00:00
|
|
|
func expirationEpochAttribute(obj *objectSDK.Object) (uint64, error) {
|
2021-02-19 09:29:42 +00:00
|
|
|
for _, a := range obj.Attributes() {
|
2024-09-20 07:58:22 +00:00
|
|
|
if a.Key() != objectV2.SysAttributeExpEpoch {
|
2021-02-19 09:29:42 +00:00
|
|
|
continue
|
2021-02-15 08:28:42 +00:00
|
|
|
}
|
|
|
|
|
2021-02-19 09:29:42 +00:00
|
|
|
return strconv.ParseUint(a.Value(), 10, 64)
|
2021-02-15 08:28:42 +00:00
|
|
|
}
|
|
|
|
|
2021-02-19 09:29:42 +00:00
|
|
|
return 0, errNoExpirationEpoch
|
2021-02-15 08:28:42 +00:00
|
|
|
}
|
|
|
|
|
2021-06-23 14:20:13 +00:00
|
|
|
var (
|
|
|
|
errDuplAttr = errors.New("duplication of attributes detected")
|
|
|
|
errEmptyAttrVal = errors.New("empty attribute value")
|
|
|
|
)
|
2021-06-23 13:30:14 +00:00
|
|
|
|
2023-07-06 12:36:41 +00:00
|
|
|
func (v *FormatValidator) checkAttributes(obj *objectSDK.Object) error {
|
2021-06-23 13:30:14 +00:00
|
|
|
as := obj.Attributes()
|
|
|
|
|
|
|
|
mUnique := make(map[string]struct{}, len(as))
|
|
|
|
|
|
|
|
for _, a := range as {
|
|
|
|
key := a.Key()
|
|
|
|
|
|
|
|
if _, was := mUnique[key]; was {
|
|
|
|
return errDuplAttr
|
|
|
|
}
|
|
|
|
|
2021-06-23 14:20:13 +00:00
|
|
|
if a.Value() == "" {
|
|
|
|
return errEmptyAttrVal
|
|
|
|
}
|
|
|
|
|
2021-06-23 13:30:14 +00:00
|
|
|
mUnique[key] = struct{}{}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2021-10-14 17:25:16 +00:00
|
|
|
var errIncorrectOwner = errors.New("incorrect object owner")
|
|
|
|
|
2023-07-06 12:36:41 +00:00
|
|
|
func (v *FormatValidator) checkOwner(obj *objectSDK.Object) error {
|
2023-11-21 08:42:30 +00:00
|
|
|
if idOwner := obj.OwnerID(); idOwner.IsEmpty() {
|
2021-10-14 17:25:16 +00:00
|
|
|
return errIncorrectOwner
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2022-04-21 11:28:05 +00:00
|
|
|
// WithNetState returns options to set the network state interface.
|
2021-02-15 08:28:42 +00:00
|
|
|
func WithNetState(netState netmap.State) FormatValidatorOption {
|
|
|
|
return func(c *cfg) {
|
|
|
|
c.netState = netState
|
|
|
|
}
|
|
|
|
}
|
2023-03-15 01:07:27 +00:00
|
|
|
|
|
|
|
// WithLockSource return option to set the Storage Engine.
|
|
|
|
func WithLockSource(e LockSource) FormatValidatorOption {
|
|
|
|
return func(c *cfg) {
|
|
|
|
c.e = e
|
|
|
|
}
|
|
|
|
}
|
2023-07-28 12:44:35 +00:00
|
|
|
|
|
|
|
// WithInnerRing return option to set Inner Ring source.
|
|
|
|
func WithInnerRing(ir InnerRing) FormatValidatorOption {
|
|
|
|
return func(c *cfg) {
|
|
|
|
c.ir = ir
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// WithNetmapSource return option to set Netmap source.
|
|
|
|
func WithNetmapSource(ns netmap.Source) FormatValidatorOption {
|
|
|
|
return func(c *cfg) {
|
|
|
|
c.netmap = ns
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// WithContainersSource return option to set Containers source.
|
|
|
|
func WithContainersSource(cs container.Source) FormatValidatorOption {
|
|
|
|
return func(c *cfg) {
|
|
|
|
c.containers = cs
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// WithVerifySessionTokenIssuer return option to set verify session token issuer value.
|
|
|
|
func WithVerifySessionTokenIssuer(verifySessionTokenIssuer bool) FormatValidatorOption {
|
|
|
|
return func(c *cfg) {
|
|
|
|
c.verifyTokenIssuer = verifySessionTokenIssuer
|
|
|
|
}
|
|
|
|
}
|
2023-08-07 06:54:47 +00:00
|
|
|
|
|
|
|
// WithLogger return option to set logger.
|
|
|
|
func WithLogger(l *logger.Logger) FormatValidatorOption {
|
|
|
|
return func(c *cfg) {
|
|
|
|
c.log = l
|
|
|
|
}
|
|
|
|
}
|