From 02bcbe975453f5be5b37aa73c1e7521daa38bd7e Mon Sep 17 00:00:00 2001 From: Angira Kekteeva Date: Fri, 1 Apr 2022 12:06:44 +0400 Subject: [PATCH] [#357] Replace prepareEvent params by struct By struct SendNotificationParams Signed-off-by: Angira Kekteeva --- api/notifications/controller.go | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/api/notifications/controller.go b/api/notifications/controller.go index 57f7b3f7..0c54a5a6 100644 --- a/api/notifications/controller.go +++ b/api/notifications/controller.go @@ -8,8 +8,6 @@ import ( "time" "github.com/nats-io/nats.go" - "github.com/nspcc-dev/neofs-s3-gw/api" - "github.com/nspcc-dev/neofs-s3-gw/api/data" "github.com/nspcc-dev/neofs-s3-gw/api/layer" "go.uber.org/zap" ) @@ -182,7 +180,7 @@ func (c *Controller) Listen(ctx context.Context) { } func (c *Controller) SendNotifications(topics map[string]string, p *layer.SendNotificationParams) error { - event := prepareEvent(p.Event, p.User, p.BktInfo, p.ObjInfo, p.ReqInfo) + event := prepareEvent(p) for id, topic := range topics { event.Records[0].S3.ConfigurationID = id @@ -216,7 +214,7 @@ func (c *Controller) SendTestNotification(topic, bucketName, requestID, HostID s return c.publish(topic, msg) } -func prepareEvent(eventName string, initiatorID string, bkt *data.BucketInfo, obj *data.ObjectInfo, reqInfo *api.ReqInfo) *Event { +func prepareEvent(p *layer.SendNotificationParams) *Event { return &Event{ Records: []EventRecord{ { @@ -224,27 +222,27 @@ func prepareEvent(eventName string, initiatorID string, bkt *data.BucketInfo, ob EventSource: "neofs:s3", AWSRegion: "", EventTime: time.Now(), - EventName: eventName, + EventName: p.Event, UserIdentity: UserIdentity{ - PrincipalID: initiatorID, + PrincipalID: p.User, }, RequestParameters: RequestParameters{ - SourceIPAddress: reqInfo.RemoteHost, + SourceIPAddress: p.ReqInfo.RemoteHost, }, ResponseElements: nil, S3: S3Entity{ SchemaVersion: "1.0", // ConfigurationID is skipped and will be placed later Bucket: Bucket{ - Name: bkt.Name, - OwnerIdentity: UserIdentity{PrincipalID: bkt.Owner.String()}, - Arn: bkt.Name, + Name: p.BktInfo.Name, + OwnerIdentity: UserIdentity{PrincipalID: p.BktInfo.Owner.String()}, + Arn: p.BktInfo.Name, }, Object: Object{ - Key: obj.Name, - Size: obj.Size, - VersionID: obj.Version(), - ETag: obj.HashSum, + Key: p.ObjInfo.Name, + Size: p.ObjInfo.Size, + VersionID: p.ObjInfo.Version(), + ETag: p.ObjInfo.HashSum, Sequencer: "", }, },