2023-11-22 22:21:11 +03:00
|
|
|
package nil
|
2023-11-17 20:39:00 +03:00
|
|
|
|
|
|
|
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
|
|
|
)
|
|
|
|
|
2023-11-22 22:21:11 +03:00
|
|
|
// Nil driver only logs container events to debug log. It is used when user provides invalid driver type.
|
2023-11-17 20:39:00 +03:00
|
|
|
// You can use it directly, but it won't do anything, so... why bother?
|
2023-11-22 22:21:11 +03:00
|
|
|
type Nil 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) {
|
2023-11-22 22:21:11 +03:00
|
|
|
return &Nil{
|
2023-11-18 16:14:39 +03:00
|
|
|
Base: base.New(ctx, name),
|
|
|
|
}, nil
|
2023-11-17 20:39:00 +03:00
|
|
|
}
|
|
|
|
|
2023-11-22 22:21:11 +03:00
|
|
|
func (d *Nil) Handle(event dto.Event) error {
|
|
|
|
d.Log().Debugw("handling event with nil driver", "serverName", d.Name(), "event", event)
|
2023-11-18 16:14:39 +03:00
|
|
|
switch event.Type {
|
|
|
|
case dto.EventStart:
|
|
|
|
d.PushEventStatus(dto.EventStatus{
|
|
|
|
Type: dto.EventStart,
|
|
|
|
ID: event.Container.ID,
|
2023-11-22 22:21:11 +03:00
|
|
|
Domain: "https://" + event.Container.ID + ".nil.dev",
|
2023-11-18 16:14:39 +03:00
|
|
|
})
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2023-11-22 22:21:11 +03:00
|
|
|
func (d *Nil) Driver() config.DriverType {
|
|
|
|
return config.DriverNil
|
2023-11-17 20:39:00 +03:00
|
|
|
}
|
|
|
|
|
2023-11-22 22:21:11 +03:00
|
|
|
func (d *Nil) WaitForShutdown() {}
|