From be4600988e745eac6e6babe168745aa3836d59ad Mon Sep 17 00:00:00 2001 From: Denis Kirillov Date: Tue, 20 Sep 2022 13:30:29 +0300 Subject: [PATCH] [#709] Add expiration attribute for legal hold Signed-off-by: Denis Kirillov --- api/layer/system_object.go | 43 ++++++++++++++++++++++++-------------- 1 file changed, 27 insertions(+), 16 deletions(-) diff --git a/api/layer/system_object.go b/api/layer/system_object.go index 9186ddeb..c05bb062 100644 --- a/api/layer/system_object.go +++ b/api/layer/system_object.go @@ -5,6 +5,7 @@ import ( "encoding/xml" errorsStd "errors" "fmt" + "math" "strconv" "time" @@ -233,24 +234,34 @@ func (n *layer) PutBucketSettings(ctx context.Context, p *PutSettingsParams) err } func (n *layer) attributesFromLock(ctx context.Context, lock *data.ObjectLock) ([][2]string, error) { - if lock.Retention == nil { - return nil, nil - } + var ( + err error + expEpoch uint64 + result [][2]string + ) - _, exp, err := n.neoFS.TimeToEpoch(ctx, lock.Retention.Until) - if err != nil { - return nil, fmt.Errorf("fetch time to epoch: %w", err) - } - - result := [][2]string{ - {AttributeExpirationEpoch, strconv.FormatUint(exp, 10)}, - } - - if lock.Retention.IsCompliance { - attrCompliance := [2]string{ - AttributeComplianceMode, strconv.FormatBool(true), + if lock.Retention != nil { + if _, expEpoch, err = n.neoFS.TimeToEpoch(ctx, lock.Retention.Until); err != nil { + return nil, fmt.Errorf("fetch time to epoch: %w", err) + } + + if lock.Retention.IsCompliance { + result = append(result, [2]string{AttributeComplianceMode, "true"}) } - result = append(result, attrCompliance) } + + if lock.LegalHold != nil && lock.LegalHold.Enabled { + // todo: (@KirillovDenis) reconsider this when NeoFS will support Legal Hold https://github.com/nspcc-dev/neofs-contract/issues/247 + // Currently lock object must have an expiration epoch. + // Besides we need to override retention expiration epoch since legal hold cannot be deleted yet. + expEpoch = math.MaxUint64 + } + + if expEpoch != 0 { + result = append(result, [2]string{ + AttributeExpirationEpoch, strconv.FormatUint(expEpoch, 10), + }) + } + return result, nil }