Browse Source

Merge "Added request_id and global_request_id to CADF notifications"

tags/6.0.0
Zuul 5 months ago
parent
commit
ac7c7fba0a

+ 10
- 2
keystonemiddleware/audit/_api.py View File

@@ -57,10 +57,15 @@ class PycadfAuditApiConfigError(Exception):
57 57
 
58 58
 
59 59
 class ClientResource(resource.Resource):
60
-    def __init__(self, project_id=None, **kwargs):
60
+    def __init__(self, project_id=None, request_id=None,
61
+                 global_request_id=None, **kwargs):
61 62
         super(ClientResource, self).__init__(**kwargs)
62 63
         if project_id is not None:
63 64
             self.project_id = project_id
65
+        if request_id is not None:
66
+            self.request_id = request_id
67
+        if global_request_id is not None:
68
+            self.global_request_id = global_request_id
64 69
 
65 70
 
66 71
 class KeystoneCredential(credential.Credential):
@@ -297,7 +302,10 @@ class OpenStackAuditApi(object):
297 302
                 token=req.environ.get('HTTP_X_AUTH_TOKEN', ''),
298 303
                 identity_status=req.environ.get('HTTP_X_IDENTITY_STATUS',
299 304
                                                 taxonomy.UNKNOWN)),
300
-            project_id=req.environ.get('HTTP_X_PROJECT_ID', taxonomy.UNKNOWN))
305
+            project_id=req.environ.get('HTTP_X_PROJECT_ID', taxonomy.UNKNOWN),
306
+            request_id=req.environ.get('openstack.request_id'),
307
+            global_request_id=req.environ.get('openstack.global_request_id'))
308
+
301 309
         target = self.get_target_resource(req)
302 310
 
303 311
         event = factory.EventFactory().new_event(

+ 22
- 0
keystonemiddleware/tests/unit/audit/test_audit_api.py View File

@@ -395,3 +395,25 @@ class AuditApiLogicTest(base.BaseAuditMiddlewareTest):
395 395
         self.assertNotIn('reporterchain', payload)
396 396
         self.assertEqual(payload['observer']['id'], 'target')
397 397
         self.assertEqual(path, payload['requestPath'])
398
+
399
+    def test_request_and_global_request_id(self):
400
+        path = '/v1/' + str(uuid.uuid4())
401
+        url = 'https://23.253.72.207' + path
402
+
403
+        request_id = 'req-%s' % uuid.uuid4()
404
+        global_request_id = 'req-%s' % uuid.uuid4()
405
+
406
+        env_headers = self.get_environ_header('GET')
407
+        env_headers['openstack.request_id'] = request_id
408
+        env_headers['openstack.global_request_id'] = global_request_id
409
+
410
+        payload = self.get_payload('GET', url, environ=env_headers)
411
+
412
+        self.assertEqual(payload['initiator']['request_id'], request_id)
413
+        self.assertEqual(payload['initiator']['global_request_id'],
414
+                         global_request_id)
415
+
416
+        payload = self.get_payload('GET', url)
417
+
418
+        self.assertNotIn('request_id', payload['initiator'])
419
+        self.assertNotIn('global_request_id', payload['initiator'])

+ 5
- 0
releasenotes/notes/bug-1803940-9a39c66014763af0.yaml View File

@@ -0,0 +1,5 @@
1
+---
2
+features:
3
+  - >
4
+    [`bug 1803940 <https://bugs.launchpad.net/keystonemiddleware/+bug/1803940>`_]
5
+    Request ID and global request ID have been added to CADF notifications.

Loading…
Cancel
Save