-
Notifications
You must be signed in to change notification settings - Fork 3
/
info.go
64 lines (55 loc) · 1.38 KB
/
info.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package cmd
import (
"fmt"
"os"
"strconv"
"github.com/foxglove/foxglove-cli/foxglove/api"
tw "github.com/foxglove/foxglove-cli/foxglove/util/tablewriter"
"github.com/spf13/cobra"
)
func executeInfo(baseURL, clientID, token, userAgent string) error {
isUsingApiKey := TokenIsApiKey(token)
if isUsingApiKey {
fmt.Println("Authenticated with API key")
return nil
}
client := api.NewRemoteFoxgloveClient(baseURL, clientID, token, userAgent)
me, err := client.Me()
if err != nil {
return err
}
headers := []string{
"Email",
"Email verified",
"Org ID",
"Org Slug",
"Admin",
}
data := [][]string{{
me.Email,
strconv.FormatBool(me.EmailVerified),
me.OrgId,
me.OrgSlug,
strconv.FormatBool(me.Admin),
}}
fmt.Println("Authenticated with session token")
tw.PrintTable(os.Stdout, headers, data)
return nil
}
func newInfoCommand(params *baseParams) *cobra.Command {
loginCmd := &cobra.Command{
Use: "info",
Short: "Display information about the currently authenticated user",
Run: func(cmd *cobra.Command, args []string) {
if !IsAuthenticated() {
dief("Not signed in. Run `foxglove auth login` or `foxglove auth configure-api-key` to continue.")
}
err := executeInfo(params.baseURL, *params.clientID, params.token, params.userAgent)
if err != nil {
dief("Info command failed: %s", err)
}
},
}
loginCmd.InheritedFlags()
return loginCmd
}