hookdeck / hookdeck-cli

Alternative to ngrok for localhost asynchronous web development (e.g. webhooks). No account required.
https://hookdeck.com?ref=github-hookdeck-cli
Apache License 2.0
276 stars 9 forks source link

feat: add a whoami command #26

Closed valeriangalliat closed 2 years ago

valeriangalliat commented 2 years ago

I was wondering what workspace I logged in with the CLI locally and found it would be useful to have a hookdeck whoami command to quickly be able to tell.

This PR adds hookdeck whoami.

$ hookdeck whoami
Logged in as Val in workspace Hello

I realized we currently were setting DisplayName in the config field team_name so the command will not show the proper team name for the previously logged-in users until they reauthenticate.

alexbouchardd commented 2 years ago

Thanks, @valeriangalliat! Could we make that backward compatible? I would also make sure to document in it the readme and our CLI Ref.

valeriangalliat commented 2 years ago

Definitely, that would be a good exercise to practice my Go. 😄

Basically if teamName == displayName query API to get real team name.

alexbouchardd commented 2 years ago

That's the fancy solution, alternatively, the command could only print "Logged in as %" omitting the workspace

valeriangalliat commented 2 years ago

@alexbouchardd I couldn't do that because there's 150 legit users who have a workspace with the same name!

In that case the GetTeamName function calls the /poll endpoint again to get back the team name (it's the only endpoint allowed for a CLI token to return the team name) and refreshes it in the config.

@leetrout I'm learning Go so I would love if you give me a pretty strict review!

alexbouchardd commented 2 years ago

Sounds good!

valeriangalliat commented 2 years ago

in most Go code the error check is considered part of the logical block where it is assigned and there isn't a blank line between them

Good to know!

I don't remember what was the channel leak thing but ping me when you want to work on it, I'm definitely interested :)