From 567d46dd24edc8fc04b9df550e54c992bca47820 Mon Sep 17 00:00:00 2001 From: talboren Date: Wed, 13 Dec 2023 17:31:33 +0200 Subject: [PATCH] fix: scopes validation logs (#630) --- keep/api/routes/providers.py | 8 ++++++++ keep/providers/grafana_provider/grafana_provider.py | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/keep/api/routes/providers.py b/keep/api/routes/providers.py index 9c7c2e61d..b6d275126 100644 --- a/keep/api/routes/providers.py +++ b/keep/api/routes/providers.py @@ -302,6 +302,7 @@ def delete_provider( def validate_scopes( provider: BaseProvider, validate_mandatory=True ) -> dict[str, bool | str]: + logger.info("Validating provider scopes") validated_scopes = provider.validate_scopes() if validate_mandatory: mandatory_scopes_validated = True @@ -316,10 +317,17 @@ def validate_scopes( break # Otherwise we fail the installation if not mandatory_scopes_validated: + logger.warning( + "Failed to validate mandatory provider scopes", + extra={"validated_scopes": validated_scopes}, + ) raise HTTPException( status_code=412, detail=validated_scopes, ) + logger.info( + "Validated provider scopes", extra={"validated_scopes": validated_scopes} + ) return validated_scopes diff --git a/keep/providers/grafana_provider/grafana_provider.py b/keep/providers/grafana_provider/grafana_provider.py index 8aa79707f..bb9605226 100644 --- a/keep/providers/grafana_provider/grafana_provider.py +++ b/keep/providers/grafana_provider/grafana_provider.py @@ -108,7 +108,7 @@ def validate_scopes(self) -> dict[str, bool | str]: f"{self.authentication_config.host}/api/access-control/user/permissions" ) try: - response = requests.get(permissions_api, headers=headers).json() + response = requests.get(permissions_api, headers=headers, timeout=5).json() except requests.exceptions.ConnectionError: validated_scopes = { scope.name: "Failed to connect to Grafana. Please check your host."