From 384ce0fb57514942010dd30f21d3447c7b32e3b0 Mon Sep 17 00:00:00 2001 From: Tal Date: Thu, 14 Nov 2024 16:14:37 +0200 Subject: [PATCH] fix(servicenow): scopes (#2491) --- keep/iohandler/iohandler.py | 3 ++- .../servicenow_provider.py | 20 ++++++++++++++++--- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/keep/iohandler/iohandler.py b/keep/iohandler/iohandler.py index ea7467582..88a857aff 100644 --- a/keep/iohandler/iohandler.py +++ b/keep/iohandler/iohandler.py @@ -281,7 +281,8 @@ def _parse(self, tree): pass else: _arg = arg.id - if _arg: + # if the value is empty '', we still need to pass it to the function + if _arg or _arg == "": _args.append(_arg) # check if we need to inject tenant_id keep_func = getattr(keep_functions, func.attr) diff --git a/keep/providers/servicenow_provider/servicenow_provider.py b/keep/providers/servicenow_provider/servicenow_provider.py index 8c15c3a0f..c9c1ee967 100644 --- a/keep/providers/servicenow_provider/servicenow_provider.py +++ b/keep/providers/servicenow_provider/servicenow_provider.py @@ -89,7 +89,15 @@ def validate_scopes(self): verify=False, timeout=10, ) - if response.status_code == 200: + + try: + response.raise_for_status() + except requests.exceptions.HTTPError as e: + self.logger.exception(f"Failed to get roles from ServiceNow: {e}") + scopes = {"itil": str(e)} + return scopes + + if response.ok: roles = response.json() roles_names = [role.get("name") for role in roles.get("result")] if "itil" in roles_names: @@ -103,8 +111,14 @@ def validate_scopes(self): "itil": "This user does not have the ITIL role", } else: - self.logger.info("Failed to get roles from ServiceNow") - scopes["itil"] = "Failed to get roles from ServiceNow" + self.logger.error( + "Failed to get roles from ServiceNow", + extra={ + "response": response.text, + "status_code": response.status_code, + }, + ) + scopes = {"itil": "Failed to get roles from ServiceNow"} except Exception as e: self.logger.exception("Error validating scopes") scopes = {