Skip to content

Commit

Permalink
Merge pull request #102 from sapcc/ironic_support_request_context
Browse files Browse the repository at this point in the history
Fix project_id handling for RequestContext objects
  • Loading branch information
notque authored Nov 19, 2024
2 parents bf61780 + a12f3b4 commit e1bca84
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions auditmiddleware/_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -520,13 +520,25 @@ def _create_cadf_event(self, project, res_spec, res_id, res_parent_id,
if not action:
return None

# Try to get project_id from request headers
project_id = request.environ.get('HTTP_X_PROJECT_ID')
# If project_id is undefined, look for another variable. This is
# added specific to catching delete events from Neutron

# If no project_id found, try to get it from the request context
if project_id is None:
# Get the adhoc attributes from the request environment
adhoc_attrs = request.environ.get('webob.adhoc_attrs', {})

# Get the context - could be dict or RequestContext object
context = adhoc_attrs.get('context', {})
original_resources = context.get('original_resources', [])

# Handle both dict and RequestContext object types
original_resources = []
if hasattr(context, 'original_resources'):
original_resources = context.original_resources
else:
original_resources = context.get('original_resources', [])

# If we found original_resources and it's a list, get project_id
if original_resources and isinstance(original_resources, list):
first_resource = original_resources[0]
if isinstance(first_resource, dict):
Expand Down

0 comments on commit e1bca84

Please sign in to comment.