Skip to content
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

fix: Validates New Relic provider api url has https #1152 #1172

Merged
merged 3 commits into from
May 15, 2024

Conversation

KanvaBhatia
Copy link
Contributor

Closes #1152

πŸ“‘ Description

Added a validation that the api url starts with 'https' in validate_config of NewrelicProvider.

βœ… Checks

  • My pull request adheres to the code style of this project
  • My code requires changes to the documentation
  • I have updated the documentation as required
  • All the tests have passed

β„Ή Additional Information

Old behaviour -
Earlier it used to show this error instead of validating url.
image

New -
Added https validation in the config, hence this meaningful error_msg.
image

  • I am not sure if this is the expected fix.

Thanks

Copy link

vercel bot commented May 13, 2024

@KanvaBhatia is attempting to deploy a commit to the KeepHQ Team on Vercel.

A member of the Team first needs to authorize it.

@KanvaBhatia KanvaBhatia changed the title Fix: Validates New Relic provider api url has https #1152 fix: Validates New Relic provider api url has https #1152 May 13, 2024
Copy link
Member

@talboren talboren left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@KanvaBhatia I think we should adjust frontend to accept different errors (not only scope validation) from the backend to display the error message you return from the URL validation properly. Are you up for fixing that too?

@KanvaBhatia
Copy link
Contributor Author

Sure, here's what I am thinking -

Here, status codes 409 and 412 are handled with provider already existing and invalid scopes respectively.

https://github.com/keephq/keep/blob/67a92f809b4ca45e0c2684e9b7504169d2757ec0/keep-ui/app/providers/provider-form.tsx#L290C5-L320C5

Whenever a provider throws a ProviderException or ProviderConfigException, it gets stuck here -

https://github.com/keephq/keep/blob/67a92f809b4ca45e0c2684e9b7504169d2757ec0/keep/api/routes/providers.py#L555C3-L557C6

Possible solution -
Backend - Add a try/except block around the ProvidersFactory.get_provider call and catch ProviderException and ProviderConfigException. Then, raise an HTTPException with another status code (maybe 400?).

Frontend - Handle the response code 400 also along with with 409 and 412 in a similar way as done above.

@talboren
Copy link
Member

@KanvaBhatia sounds perfect! Looking forward to reviewing this change

@KanvaBhatia
Copy link
Contributor Author

Added the changes @talboren. Please review.

@talboren talboren self-requested a review May 15, 2024 14:31
Copy link
Member

@talboren talboren left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! @KanvaBhatia mind adding a screenshot of how it looks before I merge it in?

Copy link

vercel bot commented May 15, 2024

The latest updates on your projects. Learn more about Vercel for Git β†—οΈŽ

Name Status Preview Comments Updated (UTC)
keep βœ… Ready (Inspect) Visit Preview πŸ’¬ Add feedback May 15, 2024 2:34pm

@KanvaBhatia
Copy link
Contributor Author

Sure @talboren here's how it'll look like -

image

If any other Provider throws ProviderException or ProviderConfigException, that exception's respective message will also be displayed similarly.

For example, for PagerdutyProvider similar thing was happening which is now displayed like this -

image

@talboren talboren merged commit 172d401 into keephq:main May 15, 2024
4 checks passed
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.

new relic validate the api URL is valid URL (starts with https)
2 participants