2023-11-18 12:36:17 +03:00
|
|
|
package convert
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net"
|
|
|
|
|
|
|
|
"github.com/Neur0toxine/sshpoke/pkg/dto"
|
|
|
|
"github.com/Neur0toxine/sshpoke/pkg/plugin/pb"
|
|
|
|
)
|
|
|
|
|
|
|
|
func MessageToAppEvent(event *pb.EventMessage) dto.Event {
|
|
|
|
return dto.Event{
|
2023-11-18 16:14:39 +03:00
|
|
|
Type: MessageEventTypeToApp(event.GetType()),
|
2023-11-18 12:36:17 +03:00
|
|
|
Container: dto.Container{
|
2023-11-18 16:14:39 +03:00
|
|
|
ID: event.GetContainer().GetId(),
|
|
|
|
Names: event.GetContainer().GetNames(),
|
|
|
|
IP: net.ParseIP(event.GetContainer().GetIp()),
|
|
|
|
Port: uint16(event.GetContainer().GetPort()),
|
|
|
|
Server: event.GetContainer().GetServer(),
|
|
|
|
Prefix: event.GetContainer().GetPrefix(),
|
|
|
|
Domain: event.GetContainer().GetDomain(),
|
2023-11-18 12:36:17 +03:00
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func AppEventToMessage(event dto.Event) *pb.EventMessage {
|
|
|
|
return &pb.EventMessage{
|
|
|
|
Type: AppEventTypeToMessage(event.Type),
|
|
|
|
Container: &pb.Container{
|
2023-11-18 16:14:39 +03:00
|
|
|
Id: event.Container.ID,
|
|
|
|
Names: event.Container.Names,
|
2023-11-18 12:36:17 +03:00
|
|
|
Ip: event.Container.IP.String(),
|
|
|
|
Port: uint32(event.Container.Port),
|
|
|
|
Server: event.Container.Server,
|
|
|
|
Prefix: event.Container.Prefix,
|
|
|
|
Domain: event.Container.Domain,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-11-18 16:14:39 +03:00
|
|
|
func MessageToAppEventStatus(val *pb.EventStatusMessage) dto.EventStatus {
|
|
|
|
return dto.EventStatus{
|
|
|
|
Type: MessageEventTypeToApp(val.GetType()),
|
|
|
|
ID: val.GetId(),
|
|
|
|
Error: val.GetError(),
|
|
|
|
Domain: val.GetDomain(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-11-18 12:36:17 +03:00
|
|
|
func AppEventStatusToMessage(status dto.EventStatus) *pb.EventStatusMessage {
|
|
|
|
return &pb.EventStatusMessage{
|
2023-11-18 16:14:39 +03:00
|
|
|
Type: AppEventTypeToMessage(status.Type),
|
2023-11-18 12:36:17 +03:00
|
|
|
Id: status.ID,
|
|
|
|
Error: status.Error,
|
|
|
|
Domain: status.Domain,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func MessageEventTypeToApp(typ pb.EventType) dto.EventType {
|
|
|
|
val := dto.EventType(typ.Number())
|
|
|
|
if val < dto.EventStart || val > dto.EventUnknown {
|
|
|
|
return dto.EventUnknown
|
|
|
|
}
|
|
|
|
return val
|
|
|
|
}
|
|
|
|
|
|
|
|
func AppEventTypeToMessage(typ dto.EventType) pb.EventType {
|
|
|
|
switch typ {
|
|
|
|
case 0:
|
|
|
|
return pb.EventType_EVENT_START
|
|
|
|
case 1:
|
|
|
|
return pb.EventType_EVENT_STOP
|
|
|
|
case 2:
|
2023-11-18 16:14:39 +03:00
|
|
|
return pb.EventType_EVENT_SHUTDOWN
|
|
|
|
case 3:
|
|
|
|
return pb.EventType_EVENT_ERROR
|
2023-11-18 12:36:17 +03:00
|
|
|
default:
|
|
|
|
return pb.EventType_EVENT_UNKNOWN
|
|
|
|
}
|
|
|
|
}
|