summaryrefslogtreecommitdiff
path: root/nova/context.py
diff options
context:
space:
mode:
authorJamie Lennox <jamielennox@gmail.com>2016-07-14 11:25:09 +1000
committerJamie Lennox <jamielennox@gmail.com>2016-07-14 12:04:21 +1000
commit13b5ab26861e4d6f6b5d99052004d5d1da8ccab5 (patch)
treee073aa487674b2cd218d6a64445b9dbcb7c51bb6 /nova/context.py
parent2a610741b5a1d02f984a6af132131b8838d8c156 (diff)
downloadnova-13b5ab26861e4d6f6b5d99052004d5d1da8ccab5.tar.gz
Use from_environ when creating a context
The from_environ method is designed to pick up all the parameters set from auth_token middleware and other oslo middlewares and create a context with them. By doing this there will be information available to libraries like oslo.policy and oslo.logging without nova having to track each change to the base library. There is ongoing work here to move more values to the base class that will be cleaned up in future. Change-Id: I6b61028fcecb86cc6c25fb69977774e266a8ea5b Related-Bug: #1602081
Diffstat (limited to 'nova/context.py')
-rw-r--r--nova/context.py13
1 files changed, 13 insertions, 0 deletions
diff --git a/nova/context.py b/nova/context.py
index 57c6658a1e..60f2b3f4c4 100644
--- a/nova/context.py
+++ b/nova/context.py
@@ -197,6 +197,19 @@ class RequestContext(context.RequestContext):
instance_lock_checked=values.get('instance_lock_checked', False),
)
+ @classmethod
+ def from_environ(cls, environ, **kwargs):
+ ctx = super(RequestContext, cls).from_environ(environ, **kwargs)
+
+ # the base oslo.context sets its user param and tenant param but not
+ # our user_id and project_id param so fix those up.
+ if ctx.user and not ctx.user_id:
+ ctx.user_id = ctx.user
+ if ctx.tenant and not ctx.project_id:
+ ctx.project_id = ctx.tenant
+
+ return ctx
+
def elevated(self, read_deleted=None):
"""Return a version of this context with admin flag set."""
context = copy.copy(self)