mirror of
https://github.com/jsiebens/ionscale.git
synced 2026-03-31 15:07:49 +01:00
feat: add /machine/update-health handler
This commit is contained in:
@@ -0,0 +1,49 @@
|
|||||||
|
package handlers
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/jsiebens/ionscale/internal/domain"
|
||||||
|
"github.com/labstack/echo/v4"
|
||||||
|
"go.uber.org/zap"
|
||||||
|
"net/http"
|
||||||
|
"tailscale.com/tailcfg"
|
||||||
|
"tailscale.com/types/key"
|
||||||
|
)
|
||||||
|
|
||||||
|
func NewUpdateHealthHandlers(machineKey key.MachinePublic, repository domain.Repository) *UpdateFeatureHandlers {
|
||||||
|
return &UpdateFeatureHandlers{machineKey: machineKey, repository: repository}
|
||||||
|
}
|
||||||
|
|
||||||
|
type UpdateFeatureHandlers struct {
|
||||||
|
machineKey key.MachinePublic
|
||||||
|
repository domain.Repository
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *UpdateFeatureHandlers) UpdateHealth(c echo.Context) error {
|
||||||
|
ctx := c.Request().Context()
|
||||||
|
|
||||||
|
req := new(tailcfg.HealthChangeRequest)
|
||||||
|
if err := c.Bind(req); err != nil {
|
||||||
|
return logError(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
machineKey := h.machineKey.String()
|
||||||
|
nodeKey := req.NodeKey.String()
|
||||||
|
|
||||||
|
machine, err := h.repository.GetMachineByKeys(ctx, machineKey, nodeKey)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if machine == nil {
|
||||||
|
return echo.NewHTTPError(http.StatusBadRequest)
|
||||||
|
}
|
||||||
|
|
||||||
|
zap.L().Debug("Health checks updated",
|
||||||
|
zap.Uint64("tailnet", machine.TailnetID),
|
||||||
|
zap.Uint64("machine", machine.ID),
|
||||||
|
zap.String("subsystem", req.Subsys),
|
||||||
|
zap.String("err", req.Error),
|
||||||
|
)
|
||||||
|
|
||||||
|
return c.String(http.StatusOK, "OK")
|
||||||
|
}
|
||||||
@@ -122,6 +122,7 @@ func Start(ctx context.Context, c *config.Config) error {
|
|||||||
idTokenHandlers := handlers.NewIDTokenHandlers(machinePublicKey, c, repository)
|
idTokenHandlers := handlers.NewIDTokenHandlers(machinePublicKey, c, repository)
|
||||||
sshActionHandlers := handlers.NewSSHActionHandlers(machinePublicKey, c, repository)
|
sshActionHandlers := handlers.NewSSHActionHandlers(machinePublicKey, c, repository)
|
||||||
queryFeatureHandlers := handlers.NewQueryFeatureHandlers(machinePublicKey, dnsProvider, repository)
|
queryFeatureHandlers := handlers.NewQueryFeatureHandlers(machinePublicKey, dnsProvider, repository)
|
||||||
|
updateHealthHandlers := handlers.NewUpdateHealthHandlers(machinePublicKey, repository)
|
||||||
|
|
||||||
e := echo.New()
|
e := echo.New()
|
||||||
e.Binder = handlers.JsonBinder{}
|
e.Binder = handlers.JsonBinder{}
|
||||||
@@ -134,6 +135,7 @@ func Start(ctx context.Context, c *config.Config) error {
|
|||||||
e.GET("/machine/ssh/action/:src_machine_id/to/:dst_machine_id/:check_period", sshActionHandlers.StartAuth)
|
e.GET("/machine/ssh/action/:src_machine_id/to/:dst_machine_id/:check_period", sshActionHandlers.StartAuth)
|
||||||
e.GET("/machine/ssh/action/check/:key", sshActionHandlers.CheckAuth)
|
e.GET("/machine/ssh/action/check/:key", sshActionHandlers.CheckAuth)
|
||||||
e.POST("/machine/feature/query", queryFeatureHandlers.QueryFeature)
|
e.POST("/machine/feature/query", queryFeatureHandlers.QueryFeature)
|
||||||
|
e.POST("/machine/update-health", updateHealthHandlers.UpdateHealth)
|
||||||
|
|
||||||
return e
|
return e
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user