From b839a44b05971a4494b8886ff638d11cf875fbf2 Mon Sep 17 00:00:00 2001 From: Swann Croiset Date: Thu, 6 Feb 2014 13:53:15 +0100 Subject: [PATCH] Retrieve user_id from HTTP Headers to populate Context We need the user_id within notifications sent by Heat to be able to handle it in Ceilometer, currently only the username is provided which can be non-uniq per tenant and could confuse the integrity of data. The easiest way to do that is to populate the Context within the user_id retrieved from Headers. No need to store the user_id in Heat backend. Related-Blueprint: send-notification Change-Id: I88bd5612556d2000d72427308d17643f14d35306 --- heat/common/context.py | 7 ++++++- heat/tests/test_common_context.py | 2 ++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/heat/common/context.py b/heat/common/context.py index 8b146ecfd4..564d13b838 100644 --- a/heat/common/context.py +++ b/heat/common/context.py @@ -35,7 +35,7 @@ class RequestContext(context.RequestContext): """ def __init__(self, auth_token=None, username=None, password=None, - aws_creds=None, tenant=None, + aws_creds=None, tenant=None, user_id=None, tenant_id=None, auth_url=None, roles=None, is_admin=None, read_only=False, show_deleted=False, overwrite=True, trust_id=None, trustor_user_id=None, @@ -55,6 +55,7 @@ class RequestContext(context.RequestContext): request_id=request_id) self.username = username + self.user_id = user_id self.password = password self.aws_creds = aws_creds self.tenant_id = tenant_id @@ -84,6 +85,7 @@ class RequestContext(context.RequestContext): def to_dict(self): return {'auth_token': self.auth_token, 'username': self.username, + 'user_id': self.user_id, 'password': self.password, 'aws_creds': self.aws_creds, 'tenant': self.tenant, @@ -131,11 +133,13 @@ class ContextMiddleware(wsgi.Middleware): try: username = None + user_id = None password = None aws_creds = None if headers.get('X-Auth-User') is not None: username = headers.get('X-Auth-User') + user_id = headers.get('X-User-Id') password = headers.get('X-Auth-Key') elif headers.get('X-Auth-EC2-Creds') is not None: aws_creds = headers.get('X-Auth-EC2-Creds') @@ -155,6 +159,7 @@ class ContextMiddleware(wsgi.Middleware): tenant=tenant, tenant_id=tenant_id, aws_creds=aws_creds, username=username, + user_id=user_id, password=password, auth_url=auth_url, roles=roles) diff --git a/heat/tests/test_common_context.py b/heat/tests/test_common_context.py index 95dabdba1b..3813de7fa3 100644 --- a/heat/tests/test_common_context.py +++ b/heat/tests/test_common_context.py @@ -34,6 +34,7 @@ class TestRequestContext(HeatTestCase): 'show_deleted': False, 'roles': ['arole', 'notadmin'], 'tenant_id': '456tenant', + 'user_id': 'fooUser', 'tenant': 'atenant', 'auth_url': 'http://xyz', 'aws_creds': 'blah'} @@ -47,6 +48,7 @@ class TestRequestContext(HeatTestCase): aws_creds=self.ctx.get('aws_creds'), tenant=self.ctx.get('tenant'), tenant_id=self.ctx.get('tenant_id'), + user_id=self.ctx.get('user_id'), auth_url=self.ctx.get('auth_url'), roles=self.ctx.get('roles'), show_deleted=self.ctx.get('show_deleted'),