Skip to content

Commit 769bbb2

Browse files
committed
fix: force token refresh with lagoon login
1 parent 2dacb03 commit 769bbb2

3 files changed

Lines changed: 29 additions & 9 deletions

File tree

cmd/login.go

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,22 @@ import (
1616
)
1717

1818
var loginCmd = &cobra.Command{
19-
Use: "login",
20-
Short: "Log into a Lagoon instance",
21-
Aliases: []string{"l"},
22-
Run: func(cmd *cobra.Command, args []string) {
23-
validateToken(lagoonCLIConfig.Current) // get a new token if the current one is invalid
24-
fmt.Println("Token fetched and saved.")
19+
Use: "login",
20+
Short: "Login or refresh an authentication token",
21+
Long: `Login or refresh an authentication token
22+
This can be used to clear out and force your CLI to refresh a token for a given context.`,
23+
Aliases: []string{"token-refresh", "tr", "l"},
24+
RunE: func(cmd *cobra.Command, args []string) error {
25+
// clear the current token
26+
lc := lagoonCLIConfig.Lagoons[lagoonCLIConfig.Current]
27+
lc.Token = ""
28+
lagoonCLIConfig.Lagoons[lagoonCLIConfig.Current] = lc
29+
// refresh and save new token
30+
if err := validateTokenE(lagoonCLIConfig.Current); err != nil {
31+
return err
32+
}
33+
fmt.Printf("token for context %s fetched and saved.\n", lagoonCLIConfig.Current)
34+
return nil
2535
},
2636
}
2737

@@ -181,3 +191,7 @@ func retrieveTokenViaSsh() (string, error) {
181191
}
182192
return strings.TrimSpace(string(out)), err
183193
}
194+
195+
func init() {
196+
loginCmd.Flags().Bool("reset-token", false, "clear the token before attempting to log in")
197+
}

docs/commands/lagoon.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ lagoon [flags]
4545
* [lagoon import](lagoon_import.md) - Import a config from a yaml file
4646
* [lagoon kibana](lagoon_kibana.md) - Launch the kibana interface
4747
* [lagoon list](lagoon_list.md) - List projects, environments, deployments, variables or notifications
48-
* [lagoon login](lagoon_login.md) - Log into a Lagoon instance
48+
* [lagoon login](lagoon_login.md) - Login or refresh an authentication token
4949
* [lagoon logs](lagoon_logs.md) - Display logs for a service of an environment and project
5050
* [lagoon raw](lagoon_raw.md) - Run a custom query or mutation
5151
* [lagoon reset-password](lagoon_reset-password.md) - Send a password reset email

docs/commands/lagoon_login.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
## lagoon login
22

3-
Log into a Lagoon instance
3+
Login or refresh an authentication token
4+
5+
### Synopsis
6+
7+
Login or refresh an authentication token
8+
This can be used to clear out and force your CLI to refresh a token for a given context.
49

510
```
611
lagoon login [flags]
@@ -9,7 +14,8 @@ lagoon login [flags]
914
### Options
1015

1116
```
12-
-h, --help help for login
17+
-h, --help help for login
18+
--reset-token clear the token before attempting to log in
1319
```
1420

1521
### Options inherited from parent commands

0 commit comments

Comments
 (0)