[#709] Add expiration attribute for legal hold

Signed-off-by: Denis Kirillov <denis@nspcc.ru>
This commit is contained in:
Denis Kirillov 2022-09-20 13:30:29 +03:00 committed by Alex Vanin
parent 7573fb77e2
commit be4600988e

View file

@ -5,6 +5,7 @@ import (
"encoding/xml" "encoding/xml"
errorsStd "errors" errorsStd "errors"
"fmt" "fmt"
"math"
"strconv" "strconv"
"time" "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) { func (n *layer) attributesFromLock(ctx context.Context, lock *data.ObjectLock) ([][2]string, error) {
if lock.Retention == nil { var (
return nil, nil err error
} expEpoch uint64
result [][2]string
)
_, exp, err := n.neoFS.TimeToEpoch(ctx, lock.Retention.Until) if lock.Retention != nil {
if err != nil { if _, expEpoch, err = n.neoFS.TimeToEpoch(ctx, lock.Retention.Until); err != nil {
return nil, fmt.Errorf("fetch time to epoch: %w", err) return nil, fmt.Errorf("fetch time to epoch: %w", err)
} }
result := [][2]string{ if lock.Retention.IsCompliance {
{AttributeExpirationEpoch, strconv.FormatUint(exp, 10)}, result = append(result, [2]string{AttributeComplianceMode, "true"})
}
if lock.Retention.IsCompliance {
attrCompliance := [2]string{
AttributeComplianceMode, strconv.FormatBool(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 return result, nil
} }