forked from sensu/sensu-go
/
logout.go
38 lines (33 loc) · 909 Bytes
/
logout.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package logout
import (
"errors"
"fmt"
"github.com/sensu/sensu-go/cli"
"github.com/sensu/sensu-go/types"
"github.com/spf13/cobra"
)
// Command defines new configuration command
func Command(cli *cli.SensuCli) *cobra.Command {
return &cobra.Command{
Use: "logout",
Short: "Logout from sensuctl",
SilenceUsage: true,
RunE: func(cmd *cobra.Command, args []string) error {
if len(args) != 0 {
_ = cmd.Help()
return errors.New("invalid argument(s) received")
}
// Logout from the configured Sensu instance
tokens := cli.Config.Tokens()
if err := cli.Client.Logout(tokens.Refresh); err != nil {
return err
}
// Remove the configured tokens from the local configuration file
if err := cli.Config.SaveTokens(&types.Tokens{}); err != nil {
return err
}
fmt.Fprintln(cmd.OutOrStdout(), "You have been logged out")
return nil
},
}
}