Skip to content

Commit

Permalink
Handle empty retention in get/put object retention (minio#9948)
Browse files Browse the repository at this point in the history
  • Loading branch information
kannappanr authored Jun 30, 2020
1 parent c0ac25b commit 5089a71
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
14 changes: 12 additions & 2 deletions cmd/object-handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -2844,8 +2844,13 @@ func (api objectAPIHandlers) PutObjectRetentionHandler(w http.ResponseWriter, r
return
}

objInfo.UserDefined[strings.ToLower(xhttp.AmzObjectLockMode)] = string(objRetention.Mode)
objInfo.UserDefined[strings.ToLower(xhttp.AmzObjectLockRetainUntilDate)] = objRetention.RetainUntilDate.UTC().Format(time.RFC3339)
if objRetention.Mode.Valid() {
objInfo.UserDefined[strings.ToLower(xhttp.AmzObjectLockMode)] = string(objRetention.Mode)
objInfo.UserDefined[strings.ToLower(xhttp.AmzObjectLockRetainUntilDate)] = objRetention.RetainUntilDate.UTC().Format(time.RFC3339)
} else {
delete(objInfo.UserDefined, strings.ToLower(xhttp.AmzObjectLockRetainUntilDate))
delete(objInfo.UserDefined, strings.ToLower(xhttp.AmzObjectLockMode))
}
if objInfo.UserTags != "" {
objInfo.UserDefined[xhttp.AmzObjectTagging] = objInfo.UserTags
}
Expand Down Expand Up @@ -2914,6 +2919,11 @@ func (api objectAPIHandlers) GetObjectRetentionHandler(w http.ResponseWriter, r

retention := objectlock.GetObjectRetentionMeta(objInfo.UserDefined)

if !retention.Mode.Valid() {
writeErrorResponse(ctx, w, errorCodes.ToAPIErr(ErrNoSuchObjectLockConfiguration), r.URL, guessIsBrowserReq(r))
return
}

writeSuccessResponseXML(w, encodeResponse(retention))
// Notify object retention accessed via a GET request.
sendEvent(eventArgs{
Expand Down
11 changes: 11 additions & 0 deletions pkg/bucket/object/lock/lock.go
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,14 @@ func ParseObjectRetention(reader io.Reader) (*ObjectRetention, error) {
return &ret, ErrUnknownWORMModeDirective
}

if ret.Mode.Valid() && ret.RetainUntilDate.IsZero() {
return &ret, ErrMalformedXML
}

if !ret.Mode.Valid() && !ret.RetainUntilDate.IsZero() {
return &ret, ErrMalformedXML
}

t, err := UTCNowNTP()
if err != nil {
logger.LogIf(context.Background(), err)
Expand Down Expand Up @@ -431,7 +439,10 @@ func GetObjectRetentionMeta(meta map[string]string) ObjectRetention {
}
if ok {
mode = parseRetMode(modeStr)
} else {
return ObjectRetention{}
}

tillStr, ok = meta[strings.ToLower(AmzObjectLockRetainUntilDate)]
if !ok {
tillStr, ok = meta[AmzObjectLockRetainUntilDate]
Expand Down

0 comments on commit 5089a71

Please sign in to comment.