forked from TrueCloudLab/frostfs-s3-gw
[#357] Add ObjectDelete notifications
Signed-off-by: Angira Kekteeva <kira@nspcc.ru>
This commit is contained in:
parent
021f5d4dd0
commit
a718b92652
2 changed files with 41 additions and 1 deletions
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue