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(servicenow): scopes #2491

Merged
merged 1 commit into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading