[#195] Use exp epoch attribute instead of tick

Signed-off-by: Denis Kirillov <denis@nspcc.ru>
This commit is contained in:
Denis Kirillov 2022-03-17 17:03:06 +03:00 committed by Angira Kekteeva
parent cfcc8933e4
commit 9d19acadcd
4 changed files with 15 additions and 35 deletions

View file

@ -21,7 +21,6 @@ import (
cid "github.com/nspcc-dev/neofs-sdk-go/container/id" cid "github.com/nspcc-dev/neofs-sdk-go/container/id"
"github.com/nspcc-dev/neofs-sdk-go/eacl" "github.com/nspcc-dev/neofs-sdk-go/eacl"
"github.com/nspcc-dev/neofs-sdk-go/netmap" "github.com/nspcc-dev/neofs-sdk-go/netmap"
"github.com/nspcc-dev/neofs-sdk-go/object/address"
oid "github.com/nspcc-dev/neofs-sdk-go/object/id" oid "github.com/nspcc-dev/neofs-sdk-go/object/id"
"github.com/nspcc-dev/neofs-sdk-go/owner" "github.com/nspcc-dev/neofs-sdk-go/owner"
"github.com/nspcc-dev/neofs-sdk-go/pool" "github.com/nspcc-dev/neofs-sdk-go/pool"
@ -290,9 +289,7 @@ func (n *layer) Initialize(ctx context.Context, c Notificator) error {
return fmt.Errorf("already initialized") return fmt.Errorf("already initialized")
} }
if err := c.Subscribe(ctx, LockTopic, MsgHandlerFunc(n.handleLockTick)); err != nil { // todo add notification handlers (e.g. for lifecycles)
return fmt.Errorf("couldn't initialize layer: %w", err)
}
c.Listen(ctx) c.Listen(ctx)
@ -304,19 +301,6 @@ func (n *layer) IsNotificationEnabled() bool {
return n.ncontroller != nil return n.ncontroller != nil
} }
func (n *layer) handleLockTick(ctx context.Context, msg *nats.Msg) error {
addr := address.NewAddress()
if err := addr.Parse(string(msg.Data)); err != nil {
return fmt.Errorf("invalid msg, address expected: %w", err)
}
n.log.Debug("handling lock tick", zap.String("address", string(msg.Data)))
// todo clear cache
// and make sure having right access
return n.objectDelete(ctx, addr.ContainerID(), addr.ObjectID())
}
// IsAuthenticatedRequest check if access box exists in current request. // IsAuthenticatedRequest check if access box exists in current request.
func IsAuthenticatedRequest(ctx context.Context) bool { func IsAuthenticatedRequest(ctx context.Context) bool {
_, ok := ctx.Value(api.BoxData).(*accessbox.Box) _, ok := ctx.Value(api.BoxData).(*accessbox.Box)

View file

@ -33,15 +33,12 @@ func TestObjectLockAttributes(t *testing.T) {
lockObj := tc.getSystemObject(obj.RetentionObject()) lockObj := tc.getSystemObject(obj.RetentionObject())
require.NotNil(t, lockObj) require.NotNil(t, lockObj)
tickTopic, tickEpoch := false, false expEpoch := false
for _, attr := range lockObj.Attributes() { for _, attr := range lockObj.Attributes() {
if attr.Key() == AttributeSysTickEpoch { if attr.Key() == AttributeExpirationEpoch {
tickEpoch = true expEpoch = true
} else if attr.Key() == AttributeSysTickTopic {
tickTopic = true
} }
} }
require.Truef(t, tickTopic, "system header __NEOFS__TICK_TOPIC presence") require.Truef(t, expEpoch, "system header __NEOFS__EXPIRATION_EPOCH presence")
require.Truef(t, tickEpoch, "system header __NEOFS__TICK_EPOCH presence")
} }

View file

@ -20,9 +20,9 @@ import (
const ( const (
AttributeComplianceMode = ".s3-compliance-mode" AttributeComplianceMode = ".s3-compliance-mode"
AttributeRetainUntil = ".s3-retain-until" AttributeRetainUntil = ".s3-retain-until"
AttributeExpirationEpoch = "__NEOFS__EXPIRATION_EPOCH"
AttributeSysTickEpoch = "__NEOFS__TICK_EPOCH" AttributeSysTickEpoch = "__NEOFS__TICK_EPOCH"
AttributeSysTickTopic = "__NEOFS__TICK_TOPIC" AttributeSysTickTopic = "__NEOFS__TICK_TOPIC"
LockTopic = "lock"
) )
func (n *layer) PutSystemObject(ctx context.Context, p *PutSystemObjectParams) (*data.ObjectInfo, error) { func (n *layer) PutSystemObject(ctx context.Context, p *PutSystemObjectParams) (*data.ObjectInfo, error) {
@ -296,8 +296,7 @@ func (n *layer) attributesFromLock(ctx context.Context, lock *data.ObjectLock) (
} }
attrs := [][2]string{ attrs := [][2]string{
{AttributeSysTickEpoch, strconv.FormatUint(exp, 10)}, {AttributeExpirationEpoch, strconv.FormatUint(exp, 10)},
{AttributeSysTickTopic, LockTopic},
{AttributeRetainUntil, lock.Until.Format(time.RFC3339)}, {AttributeRetainUntil, lock.Until.Format(time.RFC3339)},
} }

View file

@ -187,20 +187,20 @@ func (t *TestNeoFS) ReadObject(_ context.Context, prm neofs.PrmObjectRead) (*neo
func (t *TestNeoFS) CreateObject(_ context.Context, prm neofs.PrmObjectCreate) (*oid.ID, error) { func (t *TestNeoFS) CreateObject(_ context.Context, prm neofs.PrmObjectCreate) (*oid.ID, error) {
id := test.ID() id := test.ID()
attrs := make([]*object.Attribute, 0) attrs := make([]object.Attribute, 0)
if prm.Filename != "" { if prm.Filename != "" {
a := object.NewAttribute() a := object.NewAttribute()
a.SetKey(object.AttributeFileName) a.SetKey(object.AttributeFileName)
a.SetValue(prm.Filename) a.SetValue(prm.Filename)
attrs = append(attrs, a) attrs = append(attrs, *a)
} }
for i := range prm.Attributes { for i := range prm.Attributes {
a := object.NewAttribute() a := object.NewAttribute()
a.SetKey(prm.Attributes[i][0]) a.SetKey(prm.Attributes[i][0])
a.SetValue(prm.Attributes[i][1]) a.SetValue(prm.Attributes[i][1])
attrs = append(attrs, a) attrs = append(attrs, *a)
} }
obj := object.New() obj := object.New()
@ -245,7 +245,7 @@ func (t *TestNeoFS) TimeToEpoch(ctx context.Context, futureTime time.Time) (uint
return t.currentEpoch, t.currentEpoch + uint64(futureTime.Second()), nil return t.currentEpoch, t.currentEpoch + uint64(futureTime.Second()), nil
} }
func isMatched(attributes []*object.Attribute, filter object.SearchFilter) bool { func isMatched(attributes []object.Attribute, filter object.SearchFilter) bool {
for _, attr := range attributes { for _, attr := range attributes {
if attr.Key() == filter.Header() && attr.Value() == filter.Value() { if attr.Key() == filter.Header() && attr.Value() == filter.Value() {
return true return true