66 lines
1.4 KiB
Go
66 lines
1.4 KiB
Go
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{
|
|
Type: MessageEventTypeToApp(event.Type),
|
|
ID: event.Id,
|
|
Container: dto.Container{
|
|
IP: net.ParseIP(event.Container.Ip),
|
|
Port: uint16(event.Container.Port),
|
|
Server: event.Container.Server,
|
|
Prefix: event.Container.Prefix,
|
|
Domain: event.Container.Domain,
|
|
},
|
|
}
|
|
}
|
|
|
|
func AppEventToMessage(event dto.Event) *pb.EventMessage {
|
|
return &pb.EventMessage{
|
|
Type: AppEventTypeToMessage(event.Type),
|
|
Id: event.ID,
|
|
Container: &pb.Container{
|
|
Ip: event.Container.IP.String(),
|
|
Port: uint32(event.Container.Port),
|
|
Server: event.Container.Server,
|
|
Prefix: event.Container.Prefix,
|
|
Domain: event.Container.Domain,
|
|
},
|
|
}
|
|
}
|
|
|
|
func AppEventStatusToMessage(status dto.EventStatus) *pb.EventStatusMessage {
|
|
return &pb.EventStatusMessage{
|
|
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:
|
|
fallthrough
|
|
default:
|
|
return pb.EventType_EVENT_UNKNOWN
|
|
}
|
|
}
|