martindstone / pagerduty-cli

A command line interface for PagerDuty
MIT License
91 stars 12 forks source link

--me flag not working #6

Closed facundofc closed 3 years ago

facundofc commented 3 years ago

Hello there! I've noticed that the --me option to the incident:list doesn't work, giving me the following error:

Error: Request to /users/me failed: Legacy API tokens aren't supported for this operation

I tried with rest:get --endpoint users/me, and it works perfectly returning my own user.

I've poken trough the code and I see there's a function isBearerToken() which checks if the token is 64 characters long. Mine is 20, which according to the code it renders it a legacy token.

What's the reason for the need of the isBearerToken()? As far as PD goes, it does seem an artificial enforcement, given that the API endpoint actually works. I tried digging into the code history but that function was introduced in the initial commit.

I'd be willing to push an MR with the changes necessary, but I wanted first to double check this.

Cheers!

martindstone commented 3 years ago

Hi Facundo! So /users/me does work for bearer tokens obtained through pd oauth, and doesn’t work for what I call legacy domain tokens (provisioned by administrators under API Access...) but now it occurs to me that there’s a third type of token that’s provisioned in your individual PD User settings, that looks like a legacy token but may work with /users/me (although the Authorization: header gets constructed differently...) I can check this tomorrow and push a fix for you... can you confirm what kind of token you are using?

Best, Martin

On Dec 6, 2020, at 5:25 PM, Facundo notifications@github.com wrote:

 Hello there! I've noticed that the --me option to the incident:list doesn't work, giving me the following error:

Error: Request to /users/me failed: Legacy API tokens aren't supported for this operation I tried with rest:get --endpoint users/me, and it works perfectly returning my own user.

I've poken trough the code and I see there's a function isBearerToken() which checks if the token is 64 characters long. Mine is 20, which according to the code it renders it a legacy token.

What's the reason for the need of the isBearerToken()? As far as PD goes, it does seem an artificial enforcement, given that the API endpoint actually works. I tried digging into the code history but that function was introduced in the initial commit.

I'd be willing to push an MR with the changes necessary, but I wanted first to double check this.

Cheers!

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or unsubscribe.

facundofc commented 3 years ago

Hi Martin! Thanks for the speedy reply.

Indeed the token I got from my user settings, much like what's described here https://support.pagerduty.com/docs/generating-api-keys#section-generating-a-personal-rest-api-key. Let me know if this is enough to determine the token's type.

Cheers.

El dom, 6 dic 2020 a las 23:36, martindstone (notifications@github.com) escribió:

Hi Facundo! So /users/me does work for bearer tokens obtained through pd oauth, and doesn’t work for what I call legacy domain tokens (provisioned by administrators under API Access...) but now it occurs to me that there’s a third type of token that’s provisioned in your individual PD User settings, that looks like a legacy token but may work with /users/me (although the Authorization: header gets constructed differently...) I can check this tomorrow and push a fix for you... can you confirm what kind of token you are using?

Best, Martin

On Dec 6, 2020, at 5:25 PM, Facundo notifications@github.com wrote:

 Hello there! I've noticed that the --me option to the incident:list doesn't work, giving me the following error:

Error: Request to /users/me failed: Legacy API tokens aren't supported for this operation I tried with rest:get --endpoint users/me, and it works perfectly returning my own user.

I've poken trough the code and I see there's a function isBearerToken() which checks if the token is 64 characters long. Mine is 20, which according to the code it renders it a legacy token.

What's the reason for the need of the isBearerToken()? As far as PD goes, it does seem an artificial enforcement, given that the API endpoint actually works. I tried digging into the code history but that function was introduced in the initial commit.

I'd be willing to push an MR with the changes necessary, but I wanted first to double check this.

Cheers!

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or unsubscribe.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/martindstone/pagerduty-cli/issues/6#issuecomment-739576660, or unsubscribe https://github.com/notifications/unsubscribe-auth/AE4FOXPTA33NURVWE5RGOZTSTQBN7ANCNFSM4UPUSGFQ .

martindstone commented 3 years ago

Hi Facundo, this should be fixed with 0.0.43, just published. If you're using a user legacy API token, the --me option should now work with all the incident:* commands. Please reopen if you see anything bad... Thanks!

facundofc commented 3 years ago

Works perfect! Thanks!