aboutsummaryrefslogtreecommitdiffstats
path: root/client/go/internal/cli/cmd/logout.go
blob: 204513145aa9d60d0019a0aa892a8bcbf30d5fd4 (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
package cmd

import (
	"github.com/spf13/cobra"
	"github.com/vespa-engine/vespa/client/go/internal/cli/auth/auth0"
)

func newLogoutCmd(cli *CLI) *cobra.Command {
	return &cobra.Command{
		Use:               "logout",
		Args:              cobra.NoArgs,
		Short:             "Sign out of Vespa Cloud",
		Example:           "$ vespa auth logout",
		DisableAutoGenTag: true,
		SilenceUsage:      true,
		RunE: func(cmd *cobra.Command, args []string) error {
			targetType, err := cli.targetType(true)
			if err != nil {
				return err
			}
			system, err := cli.system(targetType.name)
			if err != nil {
				return err
			}
			a, err := auth0.NewClient(cli.httpClient, auth0.Options{ConfigPath: cli.config.authConfigPath(), SystemName: system.Name, SystemURL: system.URL})
			if err != nil {
				return err
			}
			if err := a.RemoveCredentials(); err != nil {
				return err
			}
			cli.printSuccess("Logged out")
			return nil
		},
	}
}