2018-05-04 16:53:21 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/pkg/errors"
|
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-02-02 20:16:59 +00:00
|
|
|
return errors.Wrap(err, "error logging out")
|
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 {
|
2018-05-04 16:53:21 +00:00
|
|
|
return errors.Wrap(err, "error setting token for the current context")
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Printf("[+] Fleet logout successful and local token cleared!\n")
|
|
|
|
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|