summaryrefslogtreecommitdiffstats
path: root/nova/api
diff options
context:
space:
mode:
authorVishvananda Ishaya <vishvananda@gmail.com>2011-07-22 19:47:41 +0000
committerVishvananda Ishaya <vishvananda@gmail.com>2011-07-22 19:47:41 +0000
commit44d1024a53b8150cf9542d08d5886f430365f161 (patch)
tree8e77f618882649835622ff5dc29f5b46a3b0b3bd /nova/api
parente1cf345fa82c3a9b8088237f1025c41db0f4e829 (diff)
fix all tests
Diffstat (limited to 'nova/api')
-rw-r--r--nova/api/ec2/__init__.py29
-rw-r--r--nova/api/openstack/auth.py20
2 files changed, 27 insertions, 22 deletions
diff --git a/nova/api/ec2/__init__.py b/nova/api/ec2/__init__.py
index edae94331..0a743075c 100644
--- a/nova/api/ec2/__init__.py
+++ b/nova/api/ec2/__init__.py
@@ -66,7 +66,7 @@ class RequestLogging(wsgi.Middleware):
else:
controller = None
action = None
- ctxt = request.environ.get('ec2.context', None)
+ ctxt = request.environ.get('nova.context', None)
delta = utils.utcnow() - start
seconds = delta.seconds
microseconds = delta.microseconds
@@ -138,20 +138,8 @@ class Lockout(wsgi.Middleware):
return res
-class InjectContext(wsgi.Middleware):
- """Always add a fake 'ec2.context' to WSGI environ."""
- def __init__(self, context, *args, **kwargs):
- self.context = context
- super(InjectContext, self).__init__(*args, **kwargs)
-
- @webob.dec.wsgify(RequestClass=wsgi.Request)
- def __call__(self, req):
- req.environ['ec2.context'] = self.context
- return self.application
-
-
class Authenticate(wsgi.Middleware):
- """Authenticate an EC2 request and add 'ec2.context' to WSGI environ."""
+ """Authenticate an EC2 request and add 'nova.context' to WSGI environ."""
@webob.dec.wsgify(RequestClass=wsgi.Request)
def __call__(self, req):
@@ -187,12 +175,13 @@ class Authenticate(wsgi.Middleware):
remote_address = req.headers.get('X-Forwarded-For', remote_address)
ctxt = context.RequestContext(user_id=user.id,
project_id=project.id,
+ is_admin=user.is_admin(),
remote_address=remote_address)
- req.environ['ec2.context'] = ctxt
+ req.environ['nova.context'] = ctxt
uname = user.name
pname = project.name
msg = _('Authenticated Request For %(uname)s:%(pname)s)') % locals()
- LOG.audit(msg, context=req.environ['ec2.context'])
+ LOG.audit(msg, context=req.environ['nova.context'])
return self.application
@@ -239,7 +228,7 @@ class Authorizer(wsgi.Middleware):
"""Authorize an EC2 API request.
Return a 401 if ec2.controller and ec2.action in WSGI environ may not be
- executed in ec2.context.
+ executed in nova.context.
"""
def __init__(self, application):
@@ -293,7 +282,7 @@ class Authorizer(wsgi.Middleware):
@webob.dec.wsgify(RequestClass=wsgi.Request)
def __call__(self, req):
- context = req.environ['ec2.context']
+ context = req.environ['nova.context']
controller = req.environ['ec2.request'].controller.__class__.__name__
action = req.environ['ec2.request'].action
allowed_roles = self.action_roles[controller].get(action, ['none'])
@@ -319,14 +308,14 @@ class Executor(wsgi.Application):
"""Execute an EC2 API request.
- Executes 'ec2.action' upon 'ec2.controller', passing 'ec2.context' and
+ Executes 'ec2.action' upon 'ec2.controller', passing 'nova.context' and
'ec2.action_args' (all variables in WSGI environ.) Returns an XML
response, or a 400 upon failure.
"""
@webob.dec.wsgify(RequestClass=wsgi.Request)
def __call__(self, req):
- context = req.environ['ec2.context']
+ context = req.environ['nova.context']
api_request = req.environ['ec2.request']
result = None
try:
diff --git a/nova/api/openstack/auth.py b/nova/api/openstack/auth.py
index 5b387c081..9caa14a4e 100644
--- a/nova/api/openstack/auth.py
+++ b/nova/api/openstack/auth.py
@@ -58,9 +58,25 @@ class AuthMiddleware(wsgi.Middleware):
try:
project_id = req.headers["X-Auth-Project-Id"]
except KeyError:
- project_id = user_id
+ # FIXME(usrleon): It needed only for compatibility
+ # while osapi clients don't use this header
+ projects = self.auth.get_projects(user_id)
+ if projects:
+ project_id = projects[0]
+ else:
+ return faults.Fault(webob.exc.HTTPUnauthorized())
+
+ is_admin = self.auth.is_admin(user_id)
+ req.environ['nova.context'] = context.RequestContext(user_id,
+ project_id,
+ is_admin)
+ if not is_admin and not self.auth.is_project_member(user_id,
+ project_id):
+ msg = _("%(user_id)s must be an admin or a "
+ "member of %(project_id)s")
+ LOG.warn(msg % locals())
+ return faults.Fault(webob.exc.HTTPUnauthorized())
- req.environ['nova.context'] = context.RequestContext(user_id, project_id)
return self.application
def has_authentication(self, req):