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

handle payload json string to dict, type check #106

Merged
merged 3 commits into from
Feb 3, 2025
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
19 changes: 19 additions & 0 deletions auditmiddleware/_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -776,7 +776,26 @@ def _get_action_from_payload(self, request, res_spec, res_id):
"""Determine the CADF action from the payload."""
try:
payload = request.json

# Handle case where payload is a string (JSON-encoded)
if isinstance(payload, str):
try:
payload = json.loads(payload)
except json.JSONDecodeError:
self._log.warning(
"Invalid JSON string payload for path: %s",
request.path)
return None

if payload:
# Type checking for payload
if not isinstance(payload, dict):
self._log.warning(
"Unexpected payload type %s for path: %s",
type(payload), request.path
)
return None

rest_action = next(iter(payload))
# check for individual mapping of action
action = res_spec.custom_actions.get(rest_action)
Expand Down
1 change: 1 addition & 0 deletions test-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ coverage!=4.4,>=4.0 # Apache-2.0
fixtures>=3.0.0 # Apache-2.0/BSD
mock>=3.0.0 # BSD
oslotest>=3.8.0 # Apache-2.0
pytz==2024.2 # MIT
requests-mock>=1.2.0 # Apache-2.0
#stevedore>=1.20.0 # Apache-2.0
stestr>=2.0.0 # Apache-2.0
Expand Down