diff options
author | Zuul <zuul@review.openstack.org> | 2018-12-12 21:58:49 +0000 |
---|---|---|
committer | Gerrit Code Review <review@openstack.org> | 2018-12-12 21:58:49 +0000 |
commit | ac7c7fba0ab19f1a4941c158aa4c7762da38377d (patch) | |
tree | 1eadddb83984ea9dbf68b307106415b0eb7762e4 | |
parent | 58c5115e4aeadf0d5d80f08fc37214964e38da13 (diff) | |
parent | f2f5820c5f375064252bde77de1c9d468c4edc62 (diff) | |
download | keystonemiddleware-ac7c7fba0ab19f1a4941c158aa4c7762da38377d.tar.gz |
Merge "Added request_id and global_request_id to CADF notifications"
-rw-r--r-- | keystonemiddleware/audit/_api.py | 12 | ||||
-rw-r--r-- | keystonemiddleware/tests/unit/audit/test_audit_api.py | 22 | ||||
-rw-r--r-- | releasenotes/notes/bug-1803940-9a39c66014763af0.yaml | 5 |
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): class ClientResource(resource.Resource): - def __init__(self, project_id=None, **kwargs): + def __init__(self, project_id=None, request_id=None, + global_request_id=None, **kwargs): super(ClientResource, self).__init__(**kwargs) if project_id is not None: self.project_id = project_id + if request_id is not None: + self.request_id = request_id + if global_request_id is not None: + self.global_request_id = global_request_id class KeystoneCredential(credential.Credential): @@ -297,7 +302,10 @@ class OpenStackAuditApi(object): token=req.environ.get('HTTP_X_AUTH_TOKEN', ''), identity_status=req.environ.get('HTTP_X_IDENTITY_STATUS', taxonomy.UNKNOWN)), - project_id=req.environ.get('HTTP_X_PROJECT_ID', taxonomy.UNKNOWN)) + project_id=req.environ.get('HTTP_X_PROJECT_ID', taxonomy.UNKNOWN), + request_id=req.environ.get('openstack.request_id'), + global_request_id=req.environ.get('openstack.global_request_id')) + target = self.get_target_resource(req) 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): self.assertNotIn('reporterchain', payload) self.assertEqual(payload['observer']['id'], 'target') self.assertEqual(path, payload['requestPath']) + + def test_request_and_global_request_id(self): + path = '/v1/' + str(uuid.uuid4()) + url = 'https://23.253.72.207' + path + + request_id = 'req-%s' % uuid.uuid4() + global_request_id = 'req-%s' % uuid.uuid4() + + env_headers = self.get_environ_header('GET') + env_headers['openstack.request_id'] = request_id + env_headers['openstack.global_request_id'] = global_request_id + + payload = self.get_payload('GET', url, environ=env_headers) + + self.assertEqual(payload['initiator']['request_id'], request_id) + self.assertEqual(payload['initiator']['global_request_id'], + global_request_id) + + payload = self.get_payload('GET', url) + + self.assertNotIn('request_id', payload['initiator']) + 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 @@ +--- +features: + - > + [`bug 1803940 <https://bugs.launchpad.net/keystonemiddleware/+bug/1803940>`_] + Request ID and global request ID have been added to CADF notifications. |