-
Notifications
You must be signed in to change notification settings - Fork 49
Add whoami command #512
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add whoami command #512
Conversation
pkg/cmd/whoami/whoami.go
Outdated
| b.WriteString(fmt.Sprintf("Current organization: %s\n", orgSlug)) | ||
| b.WriteRune('\n') | ||
| b.WriteString(fmt.Sprintf("API Token Description: %s\n", token.Description)) | ||
| b.WriteString(fmt.Sprintf("API Token Scopes: %v\n", token.Scopes)) | ||
| b.WriteRune('\n') | ||
| b.WriteString(fmt.Sprintf("API Token user name: %s\n", token.User.Name)) | ||
| b.WriteString(fmt.Sprintf("API Token user email: %s\n", token.User.Email)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe we should quote these? use %q instead of %s
pkg/cmd/whoami/whoami.go
Outdated
| Token: token, | ||
| } | ||
|
|
||
| err := json.NewEncoder(cmd.OutOrStdout()).Encode(whoamiInfo) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This marshals without indentation, so it all comes out on one line. The idea of json is to be machine parsable, and we have the exact same information available as human readable, so i don't see it as much of an issue, but i'm happy to change this if people have strong feelings.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
eg.
{"organization_slug":"a-very-real-org","token":{"uuid":"00000000-0000-0000-0000-000000000000","scopes":["read_teams","read_pipelines","write_pipelines","graphql"],"description":"My cool token","created_at":"2022-05-20T02:09:18Z","user":{"name":"Benno Moskovitz","email":"ben.m@buildkite.com"}}}
mcncl
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@moskyb I wrote an output package a while ago which might help here, but open to feedback if it adds unintended complexity
https://github.com/buildkite/cli/blob/main/pkg/output/output.go
|
@mcncl good call, added! |
This PR adds a new command to the cli,
whoami. It looks like this:it also has a JSON output mode:
very happy to take notes on the output format -- it was basically just what first came into my head, i'm sure there are better ways to show this information.