2023-11-17 20:39:00 +03:00
|
|
|
package null
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
|
|
|
"github.com/Neur0toxine/sshpoke/internal/config"
|
2023-11-18 16:14:39 +03:00
|
|
|
"github.com/Neur0toxine/sshpoke/internal/server/driver/base"
|
2023-11-18 12:36:17 +03:00
|
|
|
"github.com/Neur0toxine/sshpoke/pkg/dto"
|
2023-11-17 20:39:00 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
// Null driver only logs container events to debug log. It is used when user provides invalid driver type.
|
|
|
|
// You can use it directly, but it won't do anything, so... why bother?
|
|
|
|
type Null struct {
|
2023-11-18 16:14:39 +03:00
|
|
|
base.Base
|
2023-11-17 20:39:00 +03:00
|
|
|
}
|
|
|
|
|
2023-11-18 16:14:39 +03:00
|
|
|
func New(ctx context.Context, name string, params config.DriverParams) (base.Driver, error) {
|
|
|
|
return &Null{
|
|
|
|
Base: base.New(ctx, name),
|
|
|
|
}, nil
|
2023-11-17 20:39:00 +03:00
|
|
|
}
|
|
|
|
|
2023-11-18 12:36:17 +03:00
|
|
|
func (d *Null) Handle(event dto.Event) error {
|
2023-11-18 16:14:39 +03:00
|
|
|
d.Log().Debugw("handling event with null driver", "serverName", d.Name(), "event", event)
|
|
|
|
switch event.Type {
|
|
|
|
case dto.EventStart:
|
|
|
|
d.PushEventStatus(dto.EventStatus{
|
|
|
|
Type: dto.EventStart,
|
|
|
|
ID: event.Container.ID,
|
|
|
|
Domain: "https://" + event.Container.ID + "null.dev",
|
|
|
|
})
|
|
|
|
case dto.EventStop, dto.EventShutdown:
|
|
|
|
d.PushEventStatus(dto.EventStatus{
|
|
|
|
Type: event.Type,
|
|
|
|
ID: event.Container.ID,
|
|
|
|
})
|
|
|
|
}
|
2023-11-17 20:39:00 +03:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (d *Null) Driver() config.DriverType {
|
|
|
|
return config.DriverNull
|
|
|
|
}
|
|
|
|
|
|
|
|
func (d *Null) WaitForShutdown() {}
|