Skip to content

Commit

Permalink
fix: Validates New Relic provider api url has https #1152 (#1172)
Browse files Browse the repository at this point in the history
  • Loading branch information
KanvaBhatia committed May 15, 2024
1 parent 67a92f8 commit 172d401
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
3 changes: 3 additions & 0 deletions keep-ui/app/providers/provider-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,9 @@ const ProviderForm = ({
if (!response.ok) {
// If the response is not okay, throw the error message
return response_json.then((errorData) => {
if (response.status === 400) {
throw `${errorData.detail}`;
}
if (response.status === 409) {
throw `Provider with name ${formValues.provider_name} already exists`;
}
Expand Down
14 changes: 11 additions & 3 deletions keep/api/routes/providers.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import time
import uuid
from typing import Callable, Optional
from keep.exceptions.provider_config_exception import ProviderConfigException
from keep.exceptions.provider_exception import ProviderException

import sqlalchemy
from fastapi import APIRouter, Body, Depends, HTTPException, Request
Expand Down Expand Up @@ -552,9 +554,15 @@ async def install_provider(

# Instantiate the provider object and perform installation process
context_manager = ContextManager(tenant_id=tenant_id)
provider = ProvidersFactory.get_provider(
context_manager, provider_id, provider_type, provider_config
)
try:
provider = ProvidersFactory.get_provider(
context_manager, provider_id, provider_type, provider_config
)
except (ProviderException, ProviderConfigException) as e:
raise HTTPException(
status_code=400,
detail=str(e)
)

validated_scopes = validate_scopes(provider)

Expand Down
6 changes: 6 additions & 0 deletions keep/providers/newrelic_provider/newrelic_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,14 @@ def validate_config(self):
Raises:
ProviderConfigException: user or account is missing in authentication.
ProviderConfigException: private key
ProviderConfigException: new_relic_api_url must start with https
"""
self.newrelic_config = NewrelicProviderAuthConfig(**self.config.authentication)
if (
self.newrelic_config.new_relic_api_url
and not self.newrelic_config.new_relic_api_url.startswith("https")
):
raise ProviderConfigException("New Relic API URL must start with https", self.provider_id)

def __make_add_webhook_destination_query(self, url: str, name: str) -> dict:
query = f"""mutation {{
Expand Down

0 comments on commit 172d401

Please sign in to comment.