Skip to content

Conversation

@moskyb
Copy link
Contributor

@moskyb moskyb commented Jul 22, 2025

This PR adds a new command to the cli, whoami. It looks like this:

$ bk whoami
Current organization: a-real-test-org

API Token Description: Benno's Cool Token
API Token Scopes: [read_teams read_pipelines write_pipelines graphql]

API Token user name: Benno Moskovitz
API Token user email: ben.m@buildkite.com

it also has a JSON output mode:

$ bk whoami --output json
{
  "organization_slug": "a-real-test-org",
  "token": {
    "uuid": "00000000-0000-0000-0000-000000000000",
    "scopes": [
      "read_teams",
      "read_pipelines",
      "write_pipelines",
      "graphql"
    ],
    "description": "Benno's Cool Token",
    "created_at": "2022-05-20T02:09:18Z",
    "user": {
      "name": "Benno Moskovitz",
      "email": "ben.m@buildkite.com"
    }
  }
}

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.

@moskyb moskyb requested a review from a team as a code owner July 22, 2025 23:58
Comment on lines 61 to 67
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))
Copy link
Contributor Author

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

Token: token,
}

err := json.NewEncoder(cmd.OutOrStdout()).Encode(whoamiInfo)
Copy link
Contributor Author

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.

Copy link
Contributor Author

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"}}}

Copy link
Contributor

@mcncl mcncl left a 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

@moskyb
Copy link
Contributor Author

moskyb commented Jul 23, 2025

@mcncl good call, added!

@moskyb moskyb merged commit 5ad0e57 into main Jul 23, 2025
1 check passed
@moskyb moskyb deleted the whoami branch July 23, 2025 07:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants