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
This commit is contained in:
Swann Croiset 2014-02-06 13:53:15 +01:00
parent 5859c68bf0
commit b839a44b05
2 changed files with 8 additions and 1 deletions

View File

@ -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)

View File

@ -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'),