summaryrefslogtreecommitdiffstats
path: root/client/go/cmd/logout.go
blob: c0a6b60ab2e30c5e8c74aabd5ea5f07aa0f479c0 (plain) (blame)
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
39
40
41
package cmd

import (
	"log"

	"github.com/spf13/cobra"
	"github.com/vespa-engine/vespa/client/go/auth/auth0"
)

func newLogoutCmd(cli *CLI) *cobra.Command {
	return &cobra.Command{
		Use:               "logout",
		Args:              cobra.NoArgs,
		Short:             "Log out of Vespa Cli",
		Example:           "$ vespa auth logout",
		DisableAutoGenTag: true,
		SilenceUsage:      true,
		RunE: func(cmd *cobra.Command, args []string) error {
			targetType, err := cli.config.targetType()
			if err != nil {
				return err
			}
			system, err := cli.system(targetType)
			if err != nil {
				return err
			}
			a, err := auth0.GetAuth0(cli.config.authConfigPath(), system.Name, system.URL)
			if err != nil {
				return err
			}
			if err := a.RemoveSystem(system.Name); err != nil {
				return err
			}

			log.Print("\n")
			log.Println("Successfully logged out.")
			log.Print("\n")
			return nil
		},
	}
}