[#357] Replace prepareEvent params by struct
By struct SendNotificationParams Signed-off-by: Angira Kekteeva <kira@nspcc.ru>
This commit is contained in:
parent
a718b92652
commit
02bcbe9754
1 changed files with 12 additions and 14 deletions
|
@ -8,8 +8,6 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/nats-io/nats.go"
|
"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"
|
"github.com/nspcc-dev/neofs-s3-gw/api/layer"
|
||||||
"go.uber.org/zap"
|
"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 {
|
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 {
|
for id, topic := range topics {
|
||||||
event.Records[0].S3.ConfigurationID = id
|
event.Records[0].S3.ConfigurationID = id
|
||||||
|
@ -216,7 +214,7 @@ func (c *Controller) SendTestNotification(topic, bucketName, requestID, HostID s
|
||||||
return c.publish(topic, msg)
|
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{
|
return &Event{
|
||||||
Records: []EventRecord{
|
Records: []EventRecord{
|
||||||
{
|
{
|
||||||
|
@ -224,27 +222,27 @@ func prepareEvent(eventName string, initiatorID string, bkt *data.BucketInfo, ob
|
||||||
EventSource: "neofs:s3",
|
EventSource: "neofs:s3",
|
||||||
AWSRegion: "",
|
AWSRegion: "",
|
||||||
EventTime: time.Now(),
|
EventTime: time.Now(),
|
||||||
EventName: eventName,
|
EventName: p.Event,
|
||||||
UserIdentity: UserIdentity{
|
UserIdentity: UserIdentity{
|
||||||
PrincipalID: initiatorID,
|
PrincipalID: p.User,
|
||||||
},
|
},
|
||||||
RequestParameters: RequestParameters{
|
RequestParameters: RequestParameters{
|
||||||
SourceIPAddress: reqInfo.RemoteHost,
|
SourceIPAddress: p.ReqInfo.RemoteHost,
|
||||||
},
|
},
|
||||||
ResponseElements: nil,
|
ResponseElements: nil,
|
||||||
S3: S3Entity{
|
S3: S3Entity{
|
||||||
SchemaVersion: "1.0",
|
SchemaVersion: "1.0",
|
||||||
// ConfigurationID is skipped and will be placed later
|
// ConfigurationID is skipped and will be placed later
|
||||||
Bucket: Bucket{
|
Bucket: Bucket{
|
||||||
Name: bkt.Name,
|
Name: p.BktInfo.Name,
|
||||||
OwnerIdentity: UserIdentity{PrincipalID: bkt.Owner.String()},
|
OwnerIdentity: UserIdentity{PrincipalID: p.BktInfo.Owner.String()},
|
||||||
Arn: bkt.Name,
|
Arn: p.BktInfo.Name,
|
||||||
},
|
},
|
||||||
Object: Object{
|
Object: Object{
|
||||||
Key: obj.Name,
|
Key: p.ObjInfo.Name,
|
||||||
Size: obj.Size,
|
Size: p.ObjInfo.Size,
|
||||||
VersionID: obj.Version(),
|
VersionID: p.ObjInfo.Version(),
|
||||||
ETag: obj.HashSum,
|
ETag: p.ObjInfo.HashSum,
|
||||||
Sequencer: "",
|
Sequencer: "",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in a new issue