[#523] Add putObjectACL notification

Signed-off-by: Angira Kekteeva <kira@nspcc.ru>
This commit is contained in:
Angira Kekteeva 2022-06-10 00:05:50 +04:00 committed by Kira
parent dd0d21b690
commit cfe7591cf7
2 changed files with 25 additions and 11 deletions

View file

@ -21,6 +21,7 @@ import (
"github.com/nspcc-dev/neofs-sdk-go/object" "github.com/nspcc-dev/neofs-sdk-go/object"
oid "github.com/nspcc-dev/neofs-sdk-go/object/id" oid "github.com/nspcc-dev/neofs-sdk-go/object/id"
"github.com/nspcc-dev/neofs-sdk-go/session" "github.com/nspcc-dev/neofs-sdk-go/session"
"go.uber.org/zap"
) )
var ( var (
@ -203,17 +204,17 @@ func (h *handler) PutBucketACLHandler(w http.ResponseWriter, r *http.Request) {
return return
} }
if err = h.updateBucketACL(r, astBucket, bktInfo, token); err != nil { if _, err = h.updateBucketACL(r, astBucket, bktInfo, token); err != nil {
h.logAndSendError(w, "could not update bucket acl", reqInfo, err) h.logAndSendError(w, "could not update bucket acl", reqInfo, err)
return return
} }
w.WriteHeader(http.StatusOK) w.WriteHeader(http.StatusOK)
} }
func (h *handler) updateBucketACL(r *http.Request, astChild *ast, bktInfo *data.BucketInfo, sessionToken *session.Container) error { func (h *handler) updateBucketACL(r *http.Request, astChild *ast, bktInfo *data.BucketInfo, sessionToken *session.Container) (bool, error) {
bucketACL, err := h.obj.GetBucketACL(r.Context(), bktInfo) bucketACL, err := h.obj.GetBucketACL(r.Context(), bktInfo)
if err != nil { if err != nil {
return fmt.Errorf("could not get bucket eacl: %w", err) return false, fmt.Errorf("could not get bucket eacl: %w", err)
} }
parentAst := tableToAst(bucketACL.EACL, bktInfo.Name) parentAst := tableToAst(bucketACL.EACL, bktInfo.Name)
@ -227,12 +228,12 @@ func (h *handler) updateBucketACL(r *http.Request, astChild *ast, bktInfo *data.
resAst, updated := mergeAst(parentAst, astChild) resAst, updated := mergeAst(parentAst, astChild)
if !updated { if !updated {
return nil return false, nil
} }
table, err := astToTable(resAst) table, err := astToTable(resAst)
if err != nil { if err != nil {
return fmt.Errorf("could not translate ast to table: %w", err) return false, fmt.Errorf("could not translate ast to table: %w", err)
} }
table.SetSessionToken(sessionToken) table.SetSessionToken(sessionToken)
@ -243,10 +244,10 @@ func (h *handler) updateBucketACL(r *http.Request, astChild *ast, bktInfo *data.
} }
if err = h.obj.PutBucketACL(r.Context(), p); err != nil { if err = h.obj.PutBucketACL(r.Context(), p); err != nil {
return fmt.Errorf("could not put bucket acl: %w", err) return false, fmt.Errorf("could not put bucket acl: %w", err)
} }
return nil return true, nil
} }
func (h *handler) GetObjectACLHandler(w http.ResponseWriter, r *http.Request) { func (h *handler) GetObjectACLHandler(w http.ResponseWriter, r *http.Request) {
@ -320,15 +321,28 @@ func (h *handler) PutObjectACLHandler(w http.ResponseWriter, r *http.Request) {
VersionID: versionID, VersionID: versionID,
} }
if _, err = h.obj.GetObjectInfo(r.Context(), p); err != nil { objInfo, err := h.obj.GetObjectInfo(r.Context(), p)
if err != nil {
h.logAndSendError(w, "could not get object info", reqInfo, err) h.logAndSendError(w, "could not get object info", reqInfo, err)
return return
} }
if err = h.updateBucketACL(r, astObject, bktInfo, token); err != nil { updated, err := h.updateBucketACL(r, astObject, bktInfo, token)
if err != nil {
h.logAndSendError(w, "could not update bucket acl", reqInfo, err) h.logAndSendError(w, "could not update bucket acl", reqInfo, err)
return return
} }
if updated {
s := &SendNotificationParams{
Event: EventObjectACLPut,
ObjInfo: objInfo,
BktInfo: bktInfo,
ReqInfo: reqInfo,
}
if err = h.sendNotifications(r.Context(), s); err != nil {
h.log.Error("couldn't send notification: %w", zap.Error(err))
}
}
w.WriteHeader(http.StatusOK) w.WriteHeader(http.StatusOK)
} }
@ -397,7 +411,7 @@ func (h *handler) PutBucketPolicyHandler(w http.ResponseWriter, r *http.Request)
return return
} }
if err = h.updateBucketACL(r, astPolicy, bktInfo, token); err != nil { if _, err = h.updateBucketACL(r, astPolicy, bktInfo, token); err != nil {
h.logAndSendError(w, "could not update bucket acl", reqInfo, err) h.logAndSendError(w, "could not update bucket acl", reqInfo, err)
return return
} }

View file

@ -432,7 +432,7 @@ func (h *handler) CompleteMultipartUploadHandler(w http.ResponseWriter, r *http.
h.logAndSendError(w, "could not translate acl of completed multipart upload to ast", reqInfo, err, additional...) h.logAndSendError(w, "could not translate acl of completed multipart upload to ast", reqInfo, err, additional...)
return return
} }
if err = h.updateBucketACL(r, astObject, bktInfo, sessionTokenSetEACL); err != nil { if _, err = h.updateBucketACL(r, astObject, bktInfo, sessionTokenSetEACL); err != nil {
h.logAndSendError(w, "could not update bucket acl while completing multipart upload", reqInfo, err, additional...) h.logAndSendError(w, "could not update bucket acl while completing multipart upload", reqInfo, err, additional...)
return return
} }