2018-05-04 16:53:21 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
2021-03-13 00:42:38 +00:00
|
|
|
"github.com/urfave/cli/v2"
|
2018-05-04 16:53:21 +00:00
|
|
|
)
|
|
|
|
|
2021-03-13 00:42:38 +00:00
|
|
|
func logoutCommand() *cli.Command {
|
|
|
|
return &cli.Command{
|
2018-05-04 16:53:21 +00:00
|
|
|
Name: "logout",
|
2021-02-02 20:16:59 +00:00
|
|
|
Usage: "Log out of Fleet",
|
2018-05-04 16:53:21 +00:00
|
|
|
UsageText: `fleetctl logout [options]`,
|
|
|
|
Flags: []cli.Flag{
|
|
|
|
configFlag(),
|
|
|
|
contextFlag(),
|
2021-02-03 02:55:16 +00:00
|
|
|
debugFlag(),
|
2018-05-04 16:53:21 +00:00
|
|
|
},
|
|
|
|
Action: func(c *cli.Context) error {
|
|
|
|
fleet, err := clientFromCLI(c)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := fleet.Logout(); err != nil {
|
2021-11-22 14:13:26 +00:00
|
|
|
return fmt.Errorf("error logging out: %w", err)
|
2018-05-04 16:53:21 +00:00
|
|
|
}
|
|
|
|
|
2021-01-29 01:15:38 +00:00
|
|
|
configPath, context := c.String("config"), c.String("context")
|
|
|
|
|
|
|
|
if err := setConfigValue(configPath, context, "token", ""); err != nil {
|
2021-11-22 14:13:26 +00:00
|
|
|
return fmt.Errorf("error setting token for the current context: %w", err)
|
2018-05-04 16:53:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Printf("[+] Fleet logout successful and local token cleared!\n")
|
|
|
|
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|