Skip to content

Commit

Permalink
fix(servicenow): scopes (#2491)
Browse files Browse the repository at this point in the history
  • Loading branch information
talboren authored Nov 14, 2024
1 parent 9e9ffdc commit 384ce0f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
3 changes: 2 additions & 1 deletion keep/iohandler/iohandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
20 changes: 17 additions & 3 deletions keep/providers/servicenow_provider/servicenow_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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 = {
Expand Down

0 comments on commit 384ce0f

Please sign in to comment.