notifiers plugin: replace params with a struct

Fixes #658

Signed-off-by: Nicola Murino <nicola.murino@gmail.com>
This commit is contained in:
Nicola Murino
2022-01-02 15:16:35 +01:00
parent 6c6a6e3d16
commit 85c2d474d9
13 changed files with 249 additions and 187 deletions

View File

@@ -69,14 +69,35 @@ type GRPCServer struct {
// SendFsEvent implements the serve side fs notify method
func (s *GRPCServer) SendFsEvent(ctx context.Context, req *proto.FsEvent) (*emptypb.Empty, error) {
err := s.Impl.NotifyFsEvent(req.Timestamp, req.Action, req.Username, req.FsPath, req.FsTargetPath, req.SshCmd,
req.Protocol, req.Ip, req.VirtualPath, req.VirtualTargetPath, req.SessionId, req.FileSize, int(req.Status))
event := &FsEvent{
Action: req.Action,
Username: req.Username,
Path: req.FsPath,
TargetPath: req.FsTargetPath,
VirtualPath: req.VirtualPath,
SSHCmd: req.SshCmd,
FileSize: req.FileSize,
Status: int(req.Status),
Protocol: req.Protocol,
IP: req.Ip,
SessionID: req.SessionId,
Timestamp: req.Timestamp,
}
err := s.Impl.NotifyFsEvent(event)
return &emptypb.Empty{}, err
}
// SendProviderEvent implements the serve side provider event notify method
func (s *GRPCServer) SendProviderEvent(ctx context.Context, req *proto.ProviderEvent) (*emptypb.Empty, error) {
err := s.Impl.NotifyProviderEvent(req.Timestamp, req.Action, req.Username, req.ObjectType, req.ObjectName,
req.Ip, req.ObjectData)
event := &ProviderEvent{
Action: req.Action,
Username: req.Username,
ObjectType: req.ObjectType,
ObjectName: req.ObjectName,
IP: req.Ip,
ObjectData: req.ObjectData,
Timestamp: req.Timestamp,
}
err := s.Impl.NotifyProviderEvent(event)
return &emptypb.Empty{}, err
}

View File

@@ -30,11 +30,42 @@ var PluginMap = map[string]plugin.Plugin{
PluginName: &Plugin{},
}
// FsEvent defines a file system event
type FsEvent struct {
Action string `json:"action"`
Username string `json:"username"`
Path string `json:"path"`
TargetPath string `json:"target_path,omitempty"`
VirtualPath string `json:"virtual_path"`
VirtualTargetPath string `json:"virtual_target_path,omitempty"`
SSHCmd string `json:"ssh_cmd,omitempty"`
FileSize int64 `json:"file_size,omitempty"`
FsProvider int `json:"fs_provider"`
Bucket string `json:"bucket,omitempty"`
Endpoint string `json:"endpoint,omitempty"`
Status int `json:"status"`
Protocol string `json:"protocol"`
IP string `json:"ip"`
SessionID string `json:"session_id"`
Timestamp int64 `json:"timestamp"`
OpenFlags int `json:"open_flags,omitempty"`
}
// ProviderEvent defines a provider event
type ProviderEvent struct {
Action string
Username string
ObjectType string
ObjectName string
IP string
ObjectData []byte
Timestamp int64
}
// Notifier defines the interface for notifiers plugins
type Notifier interface {
NotifyFsEvent(timestamp int64, action, username, fsPath, fsTargetPath, sshCmd, protocol, ip,
virtualPath, virtualTargetPath, sessionID string, fileSize int64, status int) error
NotifyProviderEvent(timestamp int64, action, username, objectType, objectName, ip string, object []byte) error
NotifyFsEvent(event *FsEvent) error
NotifyProviderEvent(event *ProviderEvent) error
}
// Plugin defines the implementation to serve/connect to a notifier plugin