-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This commit adds a command to display info such as org Id, org name, email used, type of token etc. This should make it easier to debug users' request failures.
- Loading branch information
Showing
7 changed files
with
115 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"strconv" | ||
|
||
"github.com/foxglove/foxglove-cli/foxglove/console" | ||
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 := console.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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters