From 11af121126722a201ac77eb517a302637acead94 Mon Sep 17 00:00:00 2001 From: Johan Siebens Date: Sun, 9 Oct 2022 08:52:58 +0200 Subject: [PATCH] feat: remove ephemeral machines on logout --- internal/handlers/registration.go | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/internal/handlers/registration.go b/internal/handlers/registration.go index 5f6530a7..0d2c94e1 100644 --- a/internal/handlers/registration.go +++ b/internal/handlers/registration.go @@ -68,12 +68,18 @@ func (h *RegistrationHandlers) Register(c echo.Context) error { if !req.Expiry.IsZero() && req.Expiry.Before(time.Now()) { m.ExpiresAt = req.Expiry - if err := h.repository.SaveMachine(ctx, m); err != nil { - return err + if m.Ephemeral { + if _, err := h.repository.DeleteMachine(ctx, m.ID); err != nil { + return err + } + h.pubsub.Publish(m.TailnetID, &broker.Signal{PeersRemoved: []uint64{m.ID}}) + } else { + if err := h.repository.SaveMachine(ctx, m); err != nil { + return err + } + h.pubsub.Publish(m.TailnetID, &broker.Signal{PeerUpdated: &m.ID}) } - h.pubsub.Publish(m.TailnetID, &broker.Signal{PeerUpdated: &m.ID}) - response := tailcfg.RegisterResponse{NodeKeyExpired: true} return binder.WriteResponse(c, http.StatusOK, response) }