2022-02-28 08:29:03 +00:00
|
|
|
package handler
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/xml"
|
|
|
|
"fmt"
|
|
|
|
"net/http"
|
2022-02-28 13:39:04 +00:00
|
|
|
"strconv"
|
2022-02-28 10:22:07 +00:00
|
|
|
"time"
|
2022-02-28 08:29:03 +00:00
|
|
|
|
|
|
|
"github.com/nspcc-dev/neofs-s3-gw/api"
|
|
|
|
"github.com/nspcc-dev/neofs-s3-gw/api/data"
|
|
|
|
apiErrors "github.com/nspcc-dev/neofs-s3-gw/api/errors"
|
|
|
|
"github.com/nspcc-dev/neofs-s3-gw/api/layer"
|
2022-03-05 08:53:01 +00:00
|
|
|
oid "github.com/nspcc-dev/neofs-sdk-go/object/id"
|
2022-02-28 08:29:03 +00:00
|
|
|
)
|
|
|
|
|
2022-02-28 10:22:07 +00:00
|
|
|
const (
|
|
|
|
dayDuration = 24 * time.Hour
|
|
|
|
yearDuration = 365 * dayDuration
|
|
|
|
|
|
|
|
enabledValue = "Enabled"
|
|
|
|
governanceMode = "GOVERNANCE"
|
|
|
|
complianceMode = "COMPLIANCE"
|
|
|
|
legalHoldOn = "ON"
|
2022-02-28 13:39:04 +00:00
|
|
|
legalHoldOff = "OFF"
|
2022-02-28 10:22:07 +00:00
|
|
|
)
|
|
|
|
|
2022-02-28 08:29:03 +00:00
|
|
|
func (h *handler) PutBucketObjectLockConfigHandler(w http.ResponseWriter, r *http.Request) {
|
|
|
|
reqInfo := api.GetReqInfo(r.Context())
|
|
|
|
|
2022-03-18 13:04:09 +00:00
|
|
|
bktInfo, err := h.getBucketAndCheckOwner(r, reqInfo.BucketName)
|
2022-02-28 08:29:03 +00:00
|
|
|
if err != nil {
|
|
|
|
h.logAndSendError(w, "could not get bucket info", reqInfo, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if !bktInfo.ObjectLockEnabled {
|
|
|
|
h.logAndSendError(w, "couldn't put object locking configuration", reqInfo,
|
|
|
|
apiErrors.GetAPIError(apiErrors.ErrObjectLockConfigurationNotAllowed))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
lockingConf := &data.ObjectLockConfiguration{}
|
|
|
|
if err = xml.NewDecoder(r.Body).Decode(lockingConf); err != nil {
|
|
|
|
h.logAndSendError(w, "couldn't parse locking configuration", reqInfo, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if err = checkLockConfiguration(lockingConf); err != nil {
|
|
|
|
h.logAndSendError(w, "invalid lock configuration", reqInfo, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
settings, err := h.obj.GetBucketSettings(r.Context(), bktInfo)
|
|
|
|
if err != nil {
|
|
|
|
h.logAndSendError(w, "couldn't get bucket settings", reqInfo, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
settings.LockConfiguration = lockingConf
|
|
|
|
|
|
|
|
sp := &layer.PutSettingsParams{
|
|
|
|
BktInfo: bktInfo,
|
|
|
|
Settings: settings,
|
|
|
|
}
|
|
|
|
|
|
|
|
if err = h.obj.PutBucketSettings(r.Context(), sp); err != nil {
|
|
|
|
h.logAndSendError(w, "couldn't put bucket settings", reqInfo, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (h *handler) GetBucketObjectLockConfigHandler(w http.ResponseWriter, r *http.Request) {
|
|
|
|
reqInfo := api.GetReqInfo(r.Context())
|
|
|
|
|
2022-03-18 13:04:09 +00:00
|
|
|
bktInfo, err := h.getBucketAndCheckOwner(r, reqInfo.BucketName)
|
2022-02-28 08:29:03 +00:00
|
|
|
if err != nil {
|
|
|
|
h.logAndSendError(w, "could not get bucket info", reqInfo, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if !bktInfo.ObjectLockEnabled {
|
|
|
|
h.logAndSendError(w, "object lock disabled", reqInfo,
|
|
|
|
apiErrors.GetAPIError(apiErrors.ErrObjectLockConfigurationNotFound))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2022-03-01 15:07:15 +00:00
|
|
|
settings, err := h.obj.GetBucketSettings(r.Context(), bktInfo)
|
|
|
|
if err != nil {
|
|
|
|
h.logAndSendError(w, "couldn't get bucket settings", reqInfo, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2022-02-28 08:29:03 +00:00
|
|
|
if settings.LockConfiguration == nil {
|
|
|
|
settings.LockConfiguration = &data.ObjectLockConfiguration{}
|
|
|
|
}
|
|
|
|
if settings.LockConfiguration.ObjectLockEnabled == "" {
|
|
|
|
settings.LockConfiguration.ObjectLockEnabled = enabledValue
|
|
|
|
}
|
|
|
|
|
|
|
|
if err = api.EncodeToResponse(w, settings.LockConfiguration); err != nil {
|
|
|
|
h.logAndSendError(w, "something went wrong", reqInfo, err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-28 13:39:04 +00:00
|
|
|
func (h *handler) PutObjectLegalHoldHandler(w http.ResponseWriter, r *http.Request) {
|
|
|
|
reqInfo := api.GetReqInfo(r.Context())
|
|
|
|
|
2022-03-18 13:04:09 +00:00
|
|
|
bktInfo, err := h.getBucketAndCheckOwner(r, reqInfo.BucketName)
|
2022-02-28 13:39:04 +00:00
|
|
|
if err != nil {
|
|
|
|
h.logAndSendError(w, "could not get bucket info", reqInfo, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if !bktInfo.ObjectLockEnabled {
|
|
|
|
h.logAndSendError(w, "object lock disabled", reqInfo,
|
|
|
|
apiErrors.GetAPIError(apiErrors.ErrObjectLockConfigurationNotFound))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
legalHold := &data.LegalHold{}
|
|
|
|
if err = xml.NewDecoder(r.Body).Decode(legalHold); err != nil {
|
|
|
|
h.logAndSendError(w, "couldn't parse legal hold configuration", reqInfo, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if legalHold.Status != legalHoldOn && legalHold.Status != legalHoldOff {
|
|
|
|
h.logAndSendError(w, "invalid legal hold status", reqInfo,
|
|
|
|
fmt.Errorf("invalid status %s", legalHold.Status))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
p := &layer.HeadObjectParams{
|
2022-03-18 13:04:09 +00:00
|
|
|
BktInfo: bktInfo,
|
2022-02-28 13:39:04 +00:00
|
|
|
Object: reqInfo.ObjectName,
|
|
|
|
VersionID: reqInfo.URL.Query().Get(api.QueryVersionID),
|
|
|
|
}
|
|
|
|
|
|
|
|
objInfo, err := h.obj.GetObjectInfo(r.Context(), p)
|
|
|
|
if err != nil {
|
|
|
|
h.logAndSendError(w, "could not get object info", reqInfo, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
lockInfo, err := h.obj.HeadSystemObject(r.Context(), bktInfo, objInfo.LegalHoldObject())
|
|
|
|
if err != nil && !apiErrors.IsS3Error(err, apiErrors.ErrNoSuchKey) {
|
|
|
|
h.logAndSendError(w, "couldn't head lock object", reqInfo, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if lockInfo == nil && legalHold.Status == legalHoldOff ||
|
|
|
|
lockInfo != nil && legalHold.Status == legalHoldOn {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if lockInfo != nil {
|
|
|
|
if err = h.obj.DeleteSystemObject(r.Context(), bktInfo, objInfo.LegalHoldObject()); err != nil {
|
|
|
|
h.logAndSendError(w, "couldn't delete legal hold", reqInfo, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
ps := &layer.PutSystemObjectParams{
|
2022-03-01 15:07:15 +00:00
|
|
|
BktInfo: bktInfo,
|
|
|
|
ObjName: objInfo.LegalHoldObject(),
|
2022-03-04 14:36:30 +00:00
|
|
|
Lock: &data.ObjectLock{LegalHold: true, Objects: []oid.ID{*objInfo.ID}},
|
2022-03-01 15:07:15 +00:00
|
|
|
Metadata: make(map[string]string),
|
2022-02-28 13:39:04 +00:00
|
|
|
}
|
|
|
|
if _, err = h.obj.PutSystemObject(r.Context(), ps); err != nil {
|
|
|
|
h.logAndSendError(w, "couldn't put legal hold", reqInfo, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (h *handler) GetObjectLegalHoldHandler(w http.ResponseWriter, r *http.Request) {
|
|
|
|
reqInfo := api.GetReqInfo(r.Context())
|
|
|
|
|
2022-03-18 13:04:09 +00:00
|
|
|
bktInfo, err := h.getBucketAndCheckOwner(r, reqInfo.BucketName)
|
2022-02-28 13:39:04 +00:00
|
|
|
if err != nil {
|
|
|
|
h.logAndSendError(w, "could not get bucket info", reqInfo, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if !bktInfo.ObjectLockEnabled {
|
|
|
|
h.logAndSendError(w, "object lock disabled", reqInfo,
|
|
|
|
apiErrors.GetAPIError(apiErrors.ErrObjectLockConfigurationNotFound))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
p := &layer.HeadObjectParams{
|
2022-03-18 13:04:09 +00:00
|
|
|
BktInfo: bktInfo,
|
2022-02-28 13:39:04 +00:00
|
|
|
Object: reqInfo.ObjectName,
|
|
|
|
VersionID: reqInfo.URL.Query().Get(api.QueryVersionID),
|
|
|
|
}
|
|
|
|
|
|
|
|
objInfo, err := h.obj.GetObjectInfo(r.Context(), p)
|
|
|
|
if err != nil {
|
|
|
|
h.logAndSendError(w, "could not get object info", reqInfo, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
lockInfo, err := h.obj.HeadSystemObject(r.Context(), bktInfo, objInfo.LegalHoldObject())
|
|
|
|
if err != nil && !apiErrors.IsS3Error(err, apiErrors.ErrNoSuchKey) {
|
|
|
|
h.logAndSendError(w, "couldn't head lock object", reqInfo, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
legalHold := &data.LegalHold{Status: legalHoldOff}
|
|
|
|
if lockInfo != nil {
|
|
|
|
legalHold.Status = legalHoldOn
|
|
|
|
}
|
|
|
|
|
|
|
|
if err = api.EncodeToResponse(w, legalHold); err != nil {
|
|
|
|
h.logAndSendError(w, "something went wrong", reqInfo, err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (h *handler) PutObjectRetentionHandler(w http.ResponseWriter, r *http.Request) {
|
|
|
|
reqInfo := api.GetReqInfo(r.Context())
|
|
|
|
|
2022-03-18 13:04:09 +00:00
|
|
|
bktInfo, err := h.getBucketAndCheckOwner(r, reqInfo.BucketName)
|
2022-02-28 13:39:04 +00:00
|
|
|
if err != nil {
|
|
|
|
h.logAndSendError(w, "could not get bucket info", reqInfo, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if !bktInfo.ObjectLockEnabled {
|
|
|
|
h.logAndSendError(w, "object lock disabled", reqInfo,
|
|
|
|
apiErrors.GetAPIError(apiErrors.ErrObjectLockConfigurationNotFound))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
retention := &data.Retention{}
|
|
|
|
if err = xml.NewDecoder(r.Body).Decode(retention); err != nil {
|
|
|
|
h.logAndSendError(w, "couldn't parse object retention", reqInfo, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
lock, err := formObjectLockFromRetention(retention, r.Header)
|
|
|
|
if err != nil {
|
|
|
|
h.logAndSendError(w, "invalid retention configuration", reqInfo, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
p := &layer.HeadObjectParams{
|
2022-03-18 13:04:09 +00:00
|
|
|
BktInfo: bktInfo,
|
2022-02-28 13:39:04 +00:00
|
|
|
Object: reqInfo.ObjectName,
|
|
|
|
VersionID: reqInfo.URL.Query().Get(api.QueryVersionID),
|
|
|
|
}
|
|
|
|
|
|
|
|
objInfo, err := h.obj.GetObjectInfo(r.Context(), p)
|
|
|
|
if err != nil {
|
|
|
|
h.logAndSendError(w, "could not get object info", reqInfo, err)
|
|
|
|
return
|
|
|
|
}
|
2022-03-04 14:36:30 +00:00
|
|
|
lock.Objects = append(lock.Objects, *objInfo.ID)
|
2022-02-28 13:39:04 +00:00
|
|
|
|
|
|
|
lockInfo, err := h.obj.HeadSystemObject(r.Context(), bktInfo, objInfo.RetentionObject())
|
|
|
|
if err != nil && !apiErrors.IsS3Error(err, apiErrors.ErrNoSuchKey) {
|
|
|
|
h.logAndSendError(w, "couldn't head lock object", reqInfo, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2022-03-01 15:07:15 +00:00
|
|
|
if err = checkLockInfo(lockInfo, r.Header); err != nil {
|
|
|
|
h.logAndSendError(w, "couldn't change lock mode", reqInfo, err)
|
2022-02-28 13:39:04 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
ps := &layer.PutSystemObjectParams{
|
2022-03-01 15:07:15 +00:00
|
|
|
BktInfo: bktInfo,
|
|
|
|
ObjName: objInfo.RetentionObject(),
|
|
|
|
Lock: lock,
|
|
|
|
Metadata: make(map[string]string),
|
2022-02-28 13:39:04 +00:00
|
|
|
}
|
|
|
|
if _, err = h.obj.PutSystemObject(r.Context(), ps); err != nil {
|
|
|
|
h.logAndSendError(w, "couldn't put legal hold", reqInfo, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-01 15:07:15 +00:00
|
|
|
func checkLockInfo(lock *data.ObjectInfo, header http.Header) error {
|
|
|
|
if lock == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
if lock.Headers[layer.AttributeComplianceMode] != "" {
|
|
|
|
return fmt.Errorf("it's forbidden to change compliance lock mode")
|
|
|
|
}
|
|
|
|
|
|
|
|
if bypass, err := strconv.ParseBool(header.Get(api.AmzBypassGovernanceRetention)); err != nil || !bypass {
|
|
|
|
return fmt.Errorf("cannot bypass governance mode")
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2022-02-28 13:39:04 +00:00
|
|
|
func (h *handler) GetObjectRetentionHandler(w http.ResponseWriter, r *http.Request) {
|
|
|
|
reqInfo := api.GetReqInfo(r.Context())
|
|
|
|
|
2022-03-18 13:04:09 +00:00
|
|
|
bktInfo, err := h.getBucketAndCheckOwner(r, reqInfo.BucketName)
|
2022-02-28 13:39:04 +00:00
|
|
|
if err != nil {
|
|
|
|
h.logAndSendError(w, "could not get bucket info", reqInfo, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if !bktInfo.ObjectLockEnabled {
|
|
|
|
h.logAndSendError(w, "object lock disabled", reqInfo,
|
|
|
|
apiErrors.GetAPIError(apiErrors.ErrObjectLockConfigurationNotFound))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
p := &layer.HeadObjectParams{
|
2022-03-18 13:04:09 +00:00
|
|
|
BktInfo: bktInfo,
|
2022-02-28 13:39:04 +00:00
|
|
|
Object: reqInfo.ObjectName,
|
|
|
|
VersionID: reqInfo.URL.Query().Get(api.QueryVersionID),
|
|
|
|
}
|
|
|
|
|
|
|
|
objInfo, err := h.obj.GetObjectInfo(r.Context(), p)
|
|
|
|
if err != nil {
|
|
|
|
h.logAndSendError(w, "could not get object info", reqInfo, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
lockInfo, err := h.obj.HeadSystemObject(r.Context(), bktInfo, objInfo.RetentionObject())
|
|
|
|
if err != nil {
|
|
|
|
h.logAndSendError(w, "couldn't head lock object", reqInfo, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
retention := &data.Retention{
|
|
|
|
Mode: governanceMode,
|
|
|
|
RetainUntilDate: lockInfo.Headers[layer.AttributeRetainUntil],
|
|
|
|
}
|
|
|
|
if lockInfo.Headers[layer.AttributeComplianceMode] != "" {
|
|
|
|
retention.Mode = complianceMode
|
|
|
|
}
|
|
|
|
|
|
|
|
if err = api.EncodeToResponse(w, retention); err != nil {
|
|
|
|
h.logAndSendError(w, "something went wrong", reqInfo, err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-28 08:29:03 +00:00
|
|
|
func checkLockConfiguration(conf *data.ObjectLockConfiguration) error {
|
|
|
|
if conf.ObjectLockEnabled != "" && conf.ObjectLockEnabled != enabledValue {
|
|
|
|
return fmt.Errorf("invalid ObjectLockEnabled value: %s", conf.ObjectLockEnabled)
|
|
|
|
}
|
|
|
|
|
|
|
|
if conf.Rule == nil || conf.Rule.DefaultRetention == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
retention := conf.Rule.DefaultRetention
|
2022-02-28 10:22:07 +00:00
|
|
|
if retention.Mode != governanceMode && retention.Mode != complianceMode {
|
2022-02-28 08:29:03 +00:00
|
|
|
return fmt.Errorf("invalid Mode value: %s", retention.Mode)
|
|
|
|
}
|
|
|
|
|
|
|
|
if retention.Days == 0 && retention.Years == 0 {
|
|
|
|
return fmt.Errorf("you must specify Days or Years")
|
|
|
|
}
|
|
|
|
|
|
|
|
if retention.Days != 0 && retention.Years != 0 {
|
|
|
|
return fmt.Errorf("you cannot specify Days and Years at the same time")
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
2022-02-28 10:22:07 +00:00
|
|
|
|
2022-03-01 15:07:15 +00:00
|
|
|
func formObjectLock(bktInfo *data.BucketInfo, defaultConfig *data.ObjectLockConfiguration, header http.Header) (*data.ObjectLock, error) {
|
2022-02-28 10:22:07 +00:00
|
|
|
if !bktInfo.ObjectLockEnabled {
|
|
|
|
if existLockHeaders(header) {
|
2022-03-01 15:07:15 +00:00
|
|
|
return nil, apiErrors.GetAPIError(apiErrors.ErrObjectLockConfigurationNotFound)
|
2022-02-28 10:22:07 +00:00
|
|
|
}
|
2022-03-01 15:07:15 +00:00
|
|
|
return nil, nil
|
2022-02-28 10:22:07 +00:00
|
|
|
}
|
|
|
|
|
2022-03-01 15:07:15 +00:00
|
|
|
objectLock := &data.ObjectLock{}
|
|
|
|
|
2022-02-28 10:22:07 +00:00
|
|
|
if defaultConfig == nil {
|
|
|
|
defaultConfig = &data.ObjectLockConfiguration{}
|
|
|
|
}
|
|
|
|
|
|
|
|
if defaultConfig.Rule != nil && defaultConfig.Rule.DefaultRetention != nil {
|
|
|
|
defaultRetention := defaultConfig.Rule.DefaultRetention
|
|
|
|
objectLock.IsCompliance = defaultRetention.Mode == complianceMode
|
|
|
|
now := time.Now()
|
|
|
|
if defaultRetention.Days != 0 {
|
|
|
|
objectLock.Until = now.Add(time.Duration(defaultRetention.Days) * dayDuration)
|
|
|
|
} else {
|
|
|
|
objectLock.Until = now.Add(time.Duration(defaultRetention.Years) * yearDuration)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
objectLock.LegalHold = header.Get(api.AmzObjectLockLegalHold) == legalHoldOn
|
|
|
|
|
|
|
|
mode := header.Get(api.AmzObjectLockMode)
|
|
|
|
if mode != "" {
|
|
|
|
objectLock.IsCompliance = mode == complianceMode
|
|
|
|
}
|
|
|
|
|
|
|
|
until := header.Get(api.AmzObjectLockRetainUntilDate)
|
|
|
|
if until != "" {
|
|
|
|
retentionDate, err := time.Parse(time.RFC3339, until)
|
|
|
|
if err != nil {
|
2022-03-01 15:07:15 +00:00
|
|
|
return nil, fmt.Errorf("invalid header %s: '%s'", api.AmzObjectLockRetainUntilDate, until)
|
2022-02-28 10:22:07 +00:00
|
|
|
}
|
|
|
|
objectLock.Until = retentionDate
|
|
|
|
}
|
|
|
|
|
2022-03-01 15:07:15 +00:00
|
|
|
return objectLock, nil
|
2022-02-28 10:22:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func existLockHeaders(header http.Header) bool {
|
|
|
|
return header.Get(api.AmzObjectLockMode) != "" ||
|
|
|
|
header.Get(api.AmzObjectLockLegalHold) != "" ||
|
|
|
|
header.Get(api.AmzObjectLockRetainUntilDate) != ""
|
|
|
|
}
|
2022-02-28 13:39:04 +00:00
|
|
|
|
|
|
|
func formObjectLockFromRetention(retention *data.Retention, header http.Header) (*data.ObjectLock, error) {
|
|
|
|
if retention.Mode != governanceMode && retention.Mode != complianceMode {
|
|
|
|
return nil, fmt.Errorf("invalid retention mode: %s", retention.Mode)
|
|
|
|
}
|
|
|
|
|
|
|
|
retentionDate, err := time.Parse(time.RFC3339, retention.RetainUntilDate)
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("couldn't parse retain until date: %s", retention.RetainUntilDate)
|
|
|
|
}
|
|
|
|
|
|
|
|
lock := &data.ObjectLock{
|
|
|
|
Until: retentionDate,
|
|
|
|
IsCompliance: retention.Mode == complianceMode,
|
|
|
|
}
|
|
|
|
|
|
|
|
return lock, nil
|
|
|
|
}
|