-
Notifications
You must be signed in to change notification settings - Fork 3
/
login.go
41 lines (36 loc) · 1.05 KB
/
login.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
39
40
41
package cmd
import (
"context"
"fmt"
"github.com/foxglove/foxglove-cli/foxglove/api"
"github.com/spf13/cobra"
)
func executeLogin(baseURL, clientID, userAgent string, authDelegate api.AuthDelegate) error {
ctx := context.Background()
client := api.NewRemoteFoxgloveClient(baseURL, clientID, "", userAgent)
bearerToken, err := api.Login(ctx, client, authDelegate)
if err != nil {
return err
}
err = configureAuth(bearerToken, baseURL, TokenSession)
if err != nil {
return fmt.Errorf("Failed to configure auth: %w", err)
}
return nil
}
func newLoginCommand(params *baseParams) *cobra.Command {
var baseURL string
loginCmd := &cobra.Command{
Use: "login",
Short: "Log in to Foxglove Data Platform",
Run: func(cmd *cobra.Command, args []string) {
err := executeLogin(baseURL, *params.clientID, params.userAgent, &api.PlatformAuthDelegate{})
if err != nil {
dief("Login failed: %s", err)
}
},
}
loginCmd.InheritedFlags()
loginCmd.PersistentFlags().StringVarP(&baseURL, "base-url", "", defaultBaseURL, "API server")
return loginCmd
}