From b7aac223df394bdaca0a9ac055e209e05364b2e2 Mon Sep 17 00:00:00 2001 From: Angira Kekteeva Date: Thu, 31 Mar 2022 10:21:38 +0400 Subject: [PATCH] [#357] Add ObjectCreated notifications Signed-off-by: Angira Kekteeva --- api/handler/copy.go | 10 ++++++++++ api/handler/multipart_upload.go | 10 ++++++++++ api/handler/put.go | 20 ++++++++++++++++++++ 3 files changed, 40 insertions(+) diff --git a/api/handler/copy.go b/api/handler/copy.go index 459520b96..0056f4369 100644 --- a/api/handler/copy.go +++ b/api/handler/copy.go @@ -133,6 +133,16 @@ func (h *handler) CopyObjectHandler(w http.ResponseWriter, r *http.Request) { zap.String("bucket", info.Bucket), zap.String("object", info.Name), zap.Stringer("object_id", info.ID)) + + s := &layer.SendNotificationParams{ + Event: layer.EventObjectCreatedCopy, + ObjInfo: info, + BktInfo: dstBktInfo, + ReqInfo: reqInfo, + } + if err := h.obj.SendNotifications(r.Context(), s); err != nil { + h.log.Error("couldn't send notification: %w", zap.Error(err)) + } } func parseCopyObjectArgs(headers http.Header) (*copyObjectArgs, error) { diff --git a/api/handler/multipart_upload.go b/api/handler/multipart_upload.go index b84bfe7d3..880ba1f50 100644 --- a/api/handler/multipart_upload.go +++ b/api/handler/multipart_upload.go @@ -426,6 +426,16 @@ func (h *handler) CompleteMultipartUploadHandler(w http.ResponseWriter, r *http. } } + s := &layer.SendNotificationParams{ + Event: layer.EventObjectCreatedCompleteMultipartUpload, + ObjInfo: objInfo, + BktInfo: bktInfo, + ReqInfo: reqInfo, + } + if err := h.obj.SendNotifications(r.Context(), s); err != nil { + h.log.Error("couldn't send notification: %w", zap.Error(err)) + } + if _, err = h.obj.DeleteObjects(r.Context(), bktInfo, []*layer.VersionedObject{{Name: initPart.Name}}); err != nil { h.logAndSendError(w, "could not delete init file of multipart upload", reqInfo, err, additional...) return diff --git a/api/handler/put.go b/api/handler/put.go index 503e2d0a1..9ce116d20 100644 --- a/api/handler/put.go +++ b/api/handler/put.go @@ -223,6 +223,16 @@ func (h *handler) PutObjectHandler(w http.ResponseWriter, r *http.Request) { return } + s := &layer.SendNotificationParams{ + Event: layer.EventObjectCreatedPut, + ObjInfo: info, + BktInfo: bktInfo, + ReqInfo: reqInfo, + } + if err := h.obj.SendNotifications(r.Context(), s); err != nil { + h.log.Error("couldn't send notification: %w", zap.Error(err)) + } + if containsACLHeaders(r) { if newEaclTable, err = h.getNewEAclTable(r, bktInfo, info); err != nil { h.logAndSendError(w, "could not get new eacl table", reqInfo, err) @@ -320,6 +330,16 @@ func (h *handler) PostObject(w http.ResponseWriter, r *http.Request) { return } + s := &layer.SendNotificationParams{ + Event: layer.EventObjectCreatedPost, + ObjInfo: info, + BktInfo: bktInfo, + ReqInfo: reqInfo, + } + if err := h.obj.SendNotifications(r.Context(), s); err != nil { + h.log.Error("couldn't send notification: %w", zap.Error(err)) + } + if acl := auth.MultipartFormValue(r, "acl"); acl != "" { r.Header.Set(api.AmzACL, acl) r.Header.Set(api.AmzGrantFullControl, "")