From 4f96e88b76aad9db12e66a847a45d76a96b5959b Mon Sep 17 00:00:00 2001 From: shreddedbacon Date: Fri, 6 Dec 2024 08:31:33 +1100 Subject: [PATCH] fix: force token refresh with lagoon login --- cmd/login.go | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/cmd/login.go b/cmd/login.go index 5aa16b44..af3132b7 100644 --- a/cmd/login.go +++ b/cmd/login.go @@ -16,12 +16,22 @@ import ( ) var loginCmd = &cobra.Command{ - Use: "login", - Short: "Log into a Lagoon instance", - Aliases: []string{"l"}, - Run: func(cmd *cobra.Command, args []string) { - validateToken(lagoonCLIConfig.Current) // get a new token if the current one is invalid - fmt.Println("Token fetched and saved.") + Use: "login", + Short: "Login or refresh an authentication token", + Long: `Login or refresh an authentication token +This can be used to clear out and force your CLI to refresh a token for a given context.`, + Aliases: []string{"token-refresh", "tr", "l"}, + RunE: func(cmd *cobra.Command, args []string) error { + // clear the current token + lc := lagoonCLIConfig.Lagoons[lagoonCLIConfig.Current] + lc.Token = "" + lagoonCLIConfig.Lagoons[lagoonCLIConfig.Current] = lc + // refresh and save new token + if err := validateTokenE(lagoonCLIConfig.Current); err != nil { + return err + } + fmt.Printf("token for context %s fetched and saved.\n", lagoonCLIConfig.Current) + return nil }, } @@ -181,3 +191,7 @@ func retrieveTokenViaSsh() (string, error) { } return strings.TrimSpace(string(out)), err } + +func init() { + loginCmd.Flags().Bool("reset-token", false, "clear the token before attempting to log in") +}