From 1c7aff5dd912d89e4c571e93369517928a71db55 Mon Sep 17 00:00:00 2001 From: Kristoffer Dalby Date: Sun, 21 Nov 2021 09:44:38 +0000 Subject: [PATCH] Add expired column to machine list command --- cmd/headscale/cli/nodes.go | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/cmd/headscale/cli/nodes.go b/cmd/headscale/cli/nodes.go index 218d25bd..878fc7a4 100644 --- a/cmd/headscale/cli/nodes.go +++ b/cmd/headscale/cli/nodes.go @@ -412,6 +412,7 @@ func nodesToPtables( "Ephemeral", "Last seen", "Online", + "Expired", }, } @@ -420,12 +421,19 @@ func nodesToPtables( if machine.PreAuthKey != nil && machine.PreAuthKey.Ephemeral { ephemeral = true } + var lastSeen time.Time var lastSeenTime string if machine.LastSeen != nil { lastSeen = machine.LastSeen.AsTime() lastSeenTime = lastSeen.Format("2006-01-02 15:04:05") } + + var expiry time.Time + if machine.Expiry != nil { + expiry = machine.Expiry.AsTime() + } + nKey, err := wgkey.ParseHex(machine.NodeKey) if err != nil { return nil, err @@ -436,9 +444,21 @@ func nodesToPtables( if lastSeen.After( time.Now().Add(-5 * time.Minute), ) { // TODO: Find a better way to reliably show if online - online = pterm.LightGreen("true") + online = pterm.LightGreen("online") } else { - online = pterm.LightRed("false") + online = pterm.LightRed("offline") + } + + fmt.Printf( + "Machine %s, expiry: %s\n", + machine.Name, + expiry.Format("2006-01-02 15:04:05"), + ) + var expired string + if expiry.IsZero() || expiry.After(time.Now()) { + expired = pterm.LightGreen("no") + } else { + expired = pterm.LightRed("yes") } var namespace string @@ -459,6 +479,7 @@ func nodesToPtables( strconv.FormatBool(ephemeral), lastSeenTime, online, + expired, }, ) }