aboutsummaryrefslogtreecommitdiffstats
path: root/client/go/cmd/login.go
blob: 2ac480d05f5cfaa00e38fd4643dca53aea148710 (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/auth0"
)

var loginCmd = &cobra.Command{
	Use:               "login",
	Args:              cobra.NoArgs,
	Short:             "Authenticate the Vespa CLI",
	Example:           "$ vespa auth login",
	DisableAutoGenTag: true,
	SilenceUsage:      true,
	RunE: func(cmd *cobra.Command, args []string) error {
		ctx := cmd.Context()
		cfg, err := LoadConfig()
		if err != nil {
			return err
		}
		targetType, err := getTargetType()
		if err != nil {
			return err
		}
		system, err := getSystem(targetType)
		if err != nil {
			return err
		}
		a, err := auth0.GetAuth0(cfg.AuthConfigPath(), system.Name, system.URL)
		if err != nil {
			return err
		}
		_, err = auth0.RunLogin(ctx, a, false)
		return err
	},
}