summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZuul <zuul@review.openstack.org>2018-12-12 21:58:49 +0000
committerGerrit Code Review <review@openstack.org>2018-12-12 21:58:49 +0000
commitac7c7fba0ab19f1a4941c158aa4c7762da38377d (patch)
tree1eadddb83984ea9dbf68b307106415b0eb7762e4
parent58c5115e4aeadf0d5d80f08fc37214964e38da13 (diff)
parentf2f5820c5f375064252bde77de1c9d468c4edc62 (diff)
Merge "Added request_id and global_request_id to CADF notifications"
-rw-r--r--keystonemiddleware/audit/_api.py12
-rw-r--r--keystonemiddleware/tests/unit/audit/test_audit_api.py22
-rw-r--r--releasenotes/notes/bug-1803940-9a39c66014763af0.yaml5
3 files changed, 37 insertions, 2 deletions
diff --git a/keystonemiddleware/audit/_api.py b/keystonemiddleware/audit/_api.py
index b84e140..c89abaa 100644
--- a/keystonemiddleware/audit/_api.py
+++ b/keystonemiddleware/audit/_api.py
@@ -57,10 +57,15 @@ class PycadfAuditApiConfigError(Exception):
57 57
58 58
59class ClientResource(resource.Resource): 59class 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 super(ClientResource, self).__init__(**kwargs) 62 super(ClientResource, self).__init__(**kwargs)
62 if project_id is not None: 63 if project_id is not None:
63 self.project_id = project_id 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
66class KeystoneCredential(credential.Credential): 71class KeystoneCredential(credential.Credential):
@@ -297,7 +302,10 @@ class OpenStackAuditApi(object):
297 token=req.environ.get('HTTP_X_AUTH_TOKEN', ''), 302 token=req.environ.get('HTTP_X_AUTH_TOKEN', ''),
298 identity_status=req.environ.get('HTTP_X_IDENTITY_STATUS', 303 identity_status=req.environ.get('HTTP_X_IDENTITY_STATUS',
299 taxonomy.UNKNOWN)), 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 target = self.get_target_resource(req) 309 target = self.get_target_resource(req)
302 310
303 event = factory.EventFactory().new_event( 311 event = factory.EventFactory().new_event(
diff --git a/keystonemiddleware/tests/unit/audit/test_audit_api.py b/keystonemiddleware/tests/unit/audit/test_audit_api.py
index f63f3d5..3843d43 100644
--- a/keystonemiddleware/tests/unit/audit/test_audit_api.py
+++ b/keystonemiddleware/tests/unit/audit/test_audit_api.py
@@ -395,3 +395,25 @@ class AuditApiLogicTest(base.BaseAuditMiddlewareTest):
395 self.assertNotIn('reporterchain', payload) 395 self.assertNotIn('reporterchain', payload)
396 self.assertEqual(payload['observer']['id'], 'target') 396 self.assertEqual(payload['observer']['id'], 'target')
397 self.assertEqual(path, payload['requestPath']) 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'])
diff --git a/releasenotes/notes/bug-1803940-9a39c66014763af0.yaml b/releasenotes/notes/bug-1803940-9a39c66014763af0.yaml
new file mode 100644
index 0000000..81d4834
--- /dev/null
+++ b/releasenotes/notes/bug-1803940-9a39c66014763af0.yaml
@@ -0,0 +1,5 @@
1---
2features:
3 - >
4 [`bug 1803940 <https://bugs.launchpad.net/keystonemiddleware/+bug/1803940>`_]
5 Request ID and global request ID have been added to CADF notifications.