Skip to content

Commit

Permalink
feat: remove ephemeral machines on logout
Browse files Browse the repository at this point in the history
  • Loading branch information
jsiebens committed Oct 9, 2022
1 parent dfb91d2 commit 11af121
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions internal/handlers/registration.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit 11af121

Please sign in to comment.