Skip to content

Commit e1bca84

Browse files
authored
Merge pull request #102 from sapcc/ironic_support_request_context
Fix project_id handling for RequestContext objects
2 parents bf61780 + a12f3b4 commit e1bca84

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

auditmiddleware/_api.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -520,13 +520,25 @@ def _create_cadf_event(self, project, res_spec, res_id, res_parent_id,
520520
if not action:
521521
return None
522522

523+
# Try to get project_id from request headers
523524
project_id = request.environ.get('HTTP_X_PROJECT_ID')
524-
# If project_id is undefined, look for another variable. This is
525-
# added specific to catching delete events from Neutron
525+
526+
# If no project_id found, try to get it from the request context
526527
if project_id is None:
528+
# Get the adhoc attributes from the request environment
527529
adhoc_attrs = request.environ.get('webob.adhoc_attrs', {})
530+
531+
# Get the context - could be dict or RequestContext object
528532
context = adhoc_attrs.get('context', {})
529-
original_resources = context.get('original_resources', [])
533+
534+
# Handle both dict and RequestContext object types
535+
original_resources = []
536+
if hasattr(context, 'original_resources'):
537+
original_resources = context.original_resources
538+
else:
539+
original_resources = context.get('original_resources', [])
540+
541+
# If we found original_resources and it's a list, get project_id
530542
if original_resources and isinstance(original_resources, list):
531543
first_resource = original_resources[0]
532544
if isinstance(first_resource, dict):

0 commit comments

Comments
 (0)