[#195] Set Lock type to system lock objects

Signed-off-by: Denis Kirillov <denis@nspcc.ru>
This commit is contained in:
Denis Kirillov 2022-03-04 17:36:30 +03:00 committed by Angira Kekteeva
parent 13080d6d96
commit 32e83db064
8 changed files with 39 additions and 10 deletions

View file

@ -3,6 +3,8 @@ package data
import ( import (
"encoding/xml" "encoding/xml"
"time" "time"
oid "github.com/nspcc-dev/neofs-sdk-go/object/id"
) )
type ( type (
@ -37,5 +39,6 @@ type (
Until time.Time Until time.Time
LegalHold bool LegalHold bool
IsCompliance bool IsCompliance bool
Objects []oid.ID
} }
) )

View file

@ -7,6 +7,8 @@ import (
"strconv" "strconv"
"time" "time"
oid "github.com/nspcc-dev/neofs-sdk-go/object/id"
"github.com/nspcc-dev/neofs-s3-gw/api" "github.com/nspcc-dev/neofs-s3-gw/api"
"github.com/nspcc-dev/neofs-s3-gw/api/data" "github.com/nspcc-dev/neofs-s3-gw/api/data"
apiErrors "github.com/nspcc-dev/neofs-s3-gw/api/errors" apiErrors "github.com/nspcc-dev/neofs-s3-gw/api/errors"
@ -173,7 +175,7 @@ func (h *handler) PutObjectLegalHoldHandler(w http.ResponseWriter, r *http.Reque
ps := &layer.PutSystemObjectParams{ ps := &layer.PutSystemObjectParams{
BktInfo: bktInfo, BktInfo: bktInfo,
ObjName: objInfo.LegalHoldObject(), ObjName: objInfo.LegalHoldObject(),
Lock: &data.ObjectLock{LegalHold: true}, Lock: &data.ObjectLock{LegalHold: true, Objects: []oid.ID{*objInfo.ID}},
Metadata: make(map[string]string), Metadata: make(map[string]string),
} }
if _, err = h.obj.PutSystemObject(r.Context(), ps); err != nil { if _, err = h.obj.PutSystemObject(r.Context(), ps); err != nil {
@ -272,6 +274,7 @@ func (h *handler) PutObjectRetentionHandler(w http.ResponseWriter, r *http.Reque
h.logAndSendError(w, "could not get object info", reqInfo, err) h.logAndSendError(w, "could not get object info", reqInfo, err)
return return
} }
lock.Objects = append(lock.Objects, *objInfo.ID)
lockInfo, err := h.obj.HeadSystemObject(r.Context(), bktInfo, objInfo.RetentionObject()) lockInfo, err := h.obj.HeadSystemObject(r.Context(), bktInfo, objInfo.RetentionObject())
if err != nil && !apiErrors.IsS3Error(err, apiErrors.ErrNoSuchKey) { if err != nil && !apiErrors.IsS3Error(err, apiErrors.ErrNoSuchKey) {
@ -279,6 +282,8 @@ func (h *handler) PutObjectRetentionHandler(w http.ResponseWriter, r *http.Reque
return return
} }
//objectv2.ReadLock()
if err = checkLockInfo(lockInfo, r.Header); err != nil { if err = checkLockInfo(lockInfo, r.Header); err != nil {
h.logAndSendError(w, "couldn't change lock mode", reqInfo, err) h.logAndSendError(w, "couldn't change lock mode", reqInfo, err)
return return

View file

@ -113,6 +113,9 @@ type PrmObjectCreate struct {
// Key-value object attributes. // Key-value object attributes.
Attributes [][2]string Attributes [][2]string
// List of ids to lock (optional).
Locks []oid.ID
// Full payload size (optional). // Full payload size (optional).
PayloadSize uint64 PayloadSize uint64

View file

@ -204,6 +204,7 @@ func (n *layer) objectPut(ctx context.Context, bkt *data.BucketInfo, p *PutObjec
if p.Lock != nil { if p.Lock != nil {
objInfo := &data.ObjectInfo{ID: id, Name: p.Object} objInfo := &data.ObjectInfo{ID: id, Name: p.Object}
p.Lock.Objects = append(p.Lock.Objects, *id)
if p.Lock.LegalHold { if p.Lock.LegalHold {
if err = n.putLockObject(ctx, bkt, objInfo.LegalHoldObject(), p.Lock); err != nil { if err = n.putLockObject(ctx, bkt, objInfo.LegalHoldObject(), p.Lock); err != nil {
return nil, err return nil, err

View file

@ -100,9 +100,8 @@ func (n *layer) putSystemObjectIntoNeoFS(ctx context.Context, p *PutSystemObject
v = tagEmptyMark v = tagEmptyMark
} }
if p.Lock != nil { if p.Lock != nil && len(p.Lock.Objects) > 0 {
// todo form lock system object prm.Locks = p.Lock.Objects
prm.Attributes = append(prm.Attributes, attributesFromLock(p.Lock)...) prm.Attributes = append(prm.Attributes, attributesFromLock(p.Lock)...)
} }

View file

@ -38,5 +38,6 @@ func (x *layerNeoFS) CreateObject(ctx context.Context, prm layer.PrmObjectCreate
Payload: prm.Payload, Payload: prm.Payload,
BearerToken: prm.BearerToken, BearerToken: prm.BearerToken,
PrivateKey: prm.PrivateKey, PrivateKey: prm.PrivateKey,
Locks: prm.Locks,
}) })
} }

View file

@ -12,6 +12,7 @@ import (
"strings" "strings"
"time" "time"
objectv2 "github.com/nspcc-dev/neofs-api-go/v2/object"
"github.com/nspcc-dev/neofs-s3-gw/api/layer/neofs" "github.com/nspcc-dev/neofs-s3-gw/api/layer/neofs"
"github.com/nspcc-dev/neofs-s3-gw/authmate" "github.com/nspcc-dev/neofs-s3-gw/authmate"
"github.com/nspcc-dev/neofs-s3-gw/creds/tokens" "github.com/nspcc-dev/neofs-s3-gw/creds/tokens"
@ -235,6 +236,9 @@ type PrmObjectCreate struct {
// Key-value object attributes. // Key-value object attributes.
Attributes [][2]string Attributes [][2]string
// List of ids to lock (optional).
Locks []oid.ID
// Object payload encapsulated in io.Reader primitive. // Object payload encapsulated in io.Reader primitive.
Payload io.Reader Payload io.Reader
@ -290,11 +294,17 @@ func (x *NeoFS) CreateObject(ctx context.Context, prm PrmObjectCreate) (*oid.ID,
attrs = append(attrs, *a) attrs = append(attrs, *a)
} }
raw := object.New() obj := object.New()
raw.SetContainerID(&prm.Container) obj.SetContainerID(&prm.Container)
raw.SetOwnerID(&prm.Creator) obj.SetOwnerID(&prm.Creator)
raw.SetAttributes(attrs...) obj.SetAttributes(attrs...)
raw.SetPayloadSize(prm.PayloadSize) obj.SetPayloadSize(prm.PayloadSize)
if len(prm.Locks) > 0 {
lock := new(object.Lock)
lock.WriteMembers(prm.Locks)
objectv2.WriteLock(obj.ToV2(), (objectv2.Lock)(*lock))
}
var callOpt pool.CallOption var callOpt pool.CallOption
@ -304,7 +314,7 @@ func (x *NeoFS) CreateObject(ctx context.Context, prm PrmObjectCreate) (*oid.ID,
callOpt = pool.WithKey(prm.PrivateKey) callOpt = pool.WithKey(prm.PrivateKey)
} }
idObj, err := x.pool.PutObject(ctx, *raw, prm.Payload, callOpt) idObj, err := x.pool.PutObject(ctx, *obj, prm.Payload, callOpt)
if err != nil { if err != nil {
return nil, fmt.Errorf("save object via connection pool: %w", err) return nil, fmt.Errorf("save object via connection pool: %w", err)
} }

View file

@ -10,6 +10,7 @@ import (
"strconv" "strconv"
"strings" "strings"
objectv2 "github.com/nspcc-dev/neofs-api-go/v2/object"
"github.com/nspcc-dev/neofs-s3-gw/api/layer/neofs" "github.com/nspcc-dev/neofs-s3-gw/api/layer/neofs"
"github.com/nspcc-dev/neofs-sdk-go/container" "github.com/nspcc-dev/neofs-sdk-go/container"
cid "github.com/nspcc-dev/neofs-sdk-go/container/id" cid "github.com/nspcc-dev/neofs-sdk-go/container/id"
@ -209,6 +210,12 @@ func (t *TestNeoFS) CreateObject(_ context.Context, prm neofs.PrmObjectCreate) (
obj.SetCreationEpoch(t.currentEpoch) obj.SetCreationEpoch(t.currentEpoch)
t.currentEpoch++ t.currentEpoch++
if len(prm.Locks) > 0 {
lock := new(object.Lock)
lock.WriteMembers(prm.Locks)
objectv2.WriteLock(obj.ToV2(), (objectv2.Lock)(*lock))
}
if prm.Payload != nil { if prm.Payload != nil {
all, err := io.ReadAll(prm.Payload) all, err := io.ReadAll(prm.Payload)
if err != nil { if err != nil {