-
Notifications
You must be signed in to change notification settings - Fork 2.2k
[Update] Added Forbidden Response Check in PagerDuty Detector Verification #4521
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
base: main
Are you sure you want to change the base?
[Update] Added Forbidden Response Check in PagerDuty Detector Verification #4521
Conversation
martinlocklear
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.
Approving to unblock, but I think we should consider adding unit tests for this case.
|
|
||
| // 403 with "Access Denied" and "2010" means valid credentials with insufficient permissions. | ||
| // Ref: https://developer.pagerduty.com/docs/errors | ||
| if strings.Contains(bodyStr, "Access Denied") && strings.Contains(bodyStr, "2010") { |
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.
I wish there was unit test coverage for this. Also, does it make sense to actually parse the JSON, rather than to just do a string contains?
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.
Thanks for the review @martinlocklear, an additional unit test would be beneficial, yes.
Generally in detectors I've seen us rely on string contains, unless we need to extract something from the response. If our matching string is specific enough -- which I feel it is, in our case -- I lean towards string contains. IMO this would would also be slightly more adaptive to any potential change in the response shape (e.g. if keys get renamed but the message still contains these keywords)
Description:
Improved PagerDuty detector logic for credential validation.
Added handling for PagerDuty’s 403 Forbidden response for API tokens which are valid but do not have access to the resource:
If the 403 response body contains the string "Access Denied" and the code "2010", the detector now treats this specific case as a successful credential validation (
return true, nil).Any other 403 response will return an unverified response with verification error since credential validity can’t be confirmed.
Checklist:
make test-community)?make lintthis requires golangci-lint)?