diff --git a/api/handler/delete.go b/api/handler/delete.go index e43bd75..ac75c1f 100644 --- a/api/handler/delete.go +++ b/api/handler/delete.go @@ -57,9 +57,10 @@ type DeleteObjectsResponse struct { func (h *handler) DeleteObjectHandler(w http.ResponseWriter, r *http.Request) { reqInfo := api.GetReqInfo(r.Context()) + versionID := reqInfo.URL.Query().Get(api.QueryVersionID) versionedObject := []*layer.VersionedObject{{ Name: reqInfo.ObjectName, - VersionID: reqInfo.URL.Query().Get(api.QueryVersionID), + VersionID: versionID, }} bktInfo, err := h.getBucketAndCheckOwner(r, reqInfo.BucketName) @@ -96,6 +97,41 @@ func (h *handler) DeleteObjectHandler(w http.ResponseWriter, r *http.Request) { zap.Error(err)) } + var m *layer.SendNotificationParams + + if bktSettings.VersioningEnabled && len(versionID) == 0 { + m = &layer.SendNotificationParams{ + Event: layer.EventObjectRemovedDeleteMarkerCreated, + ObjInfo: &data.ObjectInfo{ + Name: reqInfo.ObjectName, + HashSum: deletedObject.DeleteMarkerEtag, + }, + BktInfo: bktInfo, + ReqInfo: reqInfo, + } + } else { + oid := oid.NewID() + if len(versionID) != 0 { + if err := oid.Parse(versionID); err != nil { + h.log.Error("couldn't send notification: %w", zap.Error(err)) + } + } + + m = &layer.SendNotificationParams{ + Event: layer.EventObjectRemovedDelete, + ObjInfo: &data.ObjectInfo{ + Name: reqInfo.ObjectName, + ID: oid, + }, + BktInfo: bktInfo, + ReqInfo: reqInfo, + } + } + + if err := h.obj.SendNotifications(r.Context(), m); err != nil { + h.log.Error("couldn't send notification: %w", zap.Error(err)) + } + if deletedObject.DeleteMarkVersion != "" { w.Header().Set(api.AmzDeleteMarker, strconv.FormatBool(true)) w.Header().Set(api.AmzVersionID, deletedObject.DeleteMarkVersion) diff --git a/api/layer/layer.go b/api/layer/layer.go index 79866ee..3842ae5 100644 --- a/api/layer/layer.go +++ b/api/layer/layer.go @@ -181,6 +181,7 @@ type ( Name string VersionID string DeleteMarkVersion string + DeleteMarkerEtag string Error error } @@ -617,6 +618,9 @@ func (n *layer) deleteObject(ctx context.Context, bkt *data.BucketInfo, settings } if len(obj.VersionID) == 0 { obj.DeleteMarkVersion = objInfo.Version() + if versioningEnabled { + obj.DeleteMarkerEtag = objInfo.HashSum + } } return obj