Fix a fer nits jaypipes found in review.

This commit is contained in:
Monsyne Dragon
2011-03-10 22:14:53 +00:00
parent 9f1847ca33
commit be66b329d5
5 changed files with 25 additions and 20 deletions

View File

@@ -21,6 +21,7 @@ from nova import log as logging
from nova import wsgi from nova import wsgi
from nova.auth import manager from nova.auth import manager
from nova.api.openstack import faults
FLAGS = flags.FLAGS FLAGS = flags.FLAGS
LOG = logging.getLogger('nova.api.openstack') LOG = logging.getLogger('nova.api.openstack')
@@ -44,11 +45,17 @@ class Controller(wsgi.Controller):
self.manager = manager.AuthManager() self.manager = manager.AuthManager()
def _check_admin(self, context): def _check_admin(self, context):
""" We cannot depend on the db layer to check for admin access """We cannot depend on the db layer to check for admin access
for the auth manager, so we do it here """ for the auth manager, so we do it here"""
if not context.is_admin: if not context.is_admin:
raise exception.NotAuthorized(_("Not admin user.")) raise exception.NotAuthorized(_("Not admin user."))
def index(self, req):
raise faults.Fault(exc.HTTPNotImplemented())
def detail(self, req):
raise faults.Fault(exc.HTTPNotImplemented())
def show(self, req, id): def show(self, req, id):
"""Return data about the given account id""" """Return data about the given account id"""
account = self.manager.get_project(id) account = self.manager.get_project(id)
@@ -59,8 +66,13 @@ class Controller(wsgi.Controller):
self.manager.delete_project(id) self.manager.delete_project(id)
return {} return {}
def create(self, req):
"""We use update with create-or-update semantics
because the id comes from an external source"""
raise faults.Fault(exc.HTTPNotImplemented())
def update(self, req, id): def update(self, req, id):
""" This is really create or update. """ """This is really create or update."""
self._check_admin(req.environ['nova.context']) self._check_admin(req.environ['nova.context'])
env = self._deserialize(req.body, req) env = self._deserialize(req.body, req)
description = env['account'].get('description') description = env['account'].get('description')

View File

@@ -45,8 +45,8 @@ class Controller(wsgi.Controller):
self.manager = manager.AuthManager() self.manager = manager.AuthManager()
def _check_admin(self, context): def _check_admin(self, context):
""" We cannot depend on the db layer to check for admin access """We cannot depend on the db layer to check for admin access
for the auth manager, so we do it here """ for the auth manager, so we do it here"""
if not context.is_admin: if not context.is_admin:
raise exception.NotAuthorized(_("Not admin user")) raise exception.NotAuthorized(_("Not admin user"))

View File

@@ -14,9 +14,10 @@
# under the License. # under the License.
import json
import stubout import stubout
import webob import webob
import json
import nova.api import nova.api
import nova.api.openstack.auth import nova.api.openstack.auth
@@ -47,8 +48,7 @@ class AccountsTest(test.TestCase):
fake_init) fake_init)
self.stubs.Set(nova.api.openstack.accounts.Controller, '_check_admin', self.stubs.Set(nova.api.openstack.accounts.Controller, '_check_admin',
fake_admin_check) fake_admin_check)
fakes.FakeAuthManager.auth_data = {} fakes.FakeAuthManager.clear_fakes()
fakes.FakeAuthManager.projects = {}
fakes.FakeAuthDatabase.data = {} fakes.FakeAuthDatabase.data = {}
fakes.stub_out_networking(self.stubs) fakes.stub_out_networking(self.stubs)
fakes.stub_out_rate_limiting(self.stubs) fakes.stub_out_rate_limiting(self.stubs)

View File

@@ -51,9 +51,7 @@ class Test(test.TestCase):
def test_authorize_user(self): def test_authorize_user(self):
f = fakes.FakeAuthManager() f = fakes.FakeAuthManager()
u = nova.auth.manager.User(1, 'herp', None, None, None) f.add_user('derp', nova.auth.manager.User(1, 'herp', None, None, None))
f.add_user('derp', u)
f.create_project('test', u)
req = webob.Request.blank('/v1.0/') req = webob.Request.blank('/v1.0/')
req.headers['X-Auth-User'] = 'herp' req.headers['X-Auth-User'] = 'herp'
@@ -67,9 +65,7 @@ class Test(test.TestCase):
def test_authorize_token(self): def test_authorize_token(self):
f = fakes.FakeAuthManager() f = fakes.FakeAuthManager()
u = nova.auth.manager.User(1, 'herp', None, None, None) f.add_user('derp', nova.auth.manager.User(1, 'herp', None, None, None))
f.add_user('derp', u)
f.create_project('test', u)
req = webob.Request.blank('/v1.0/', {'HTTP_HOST': 'foo'}) req = webob.Request.blank('/v1.0/', {'HTTP_HOST': 'foo'})
req.headers['X-Auth-User'] = 'herp' req.headers['X-Auth-User'] = 'herp'
@@ -86,7 +82,7 @@ class Test(test.TestCase):
token = result.headers['X-Auth-Token'] token = result.headers['X-Auth-Token']
self.stubs.Set(nova.api.openstack, 'APIRouter', self.stubs.Set(nova.api.openstack, 'APIRouter',
fakes.FakeRouter) fakes.FakeRouter)
req = webob.Request.blank('/v1.0/test/fake') req = webob.Request.blank('/v1.0/fake')
req.headers['X-Auth-Token'] = token req.headers['X-Auth-Token'] = token
result = req.get_response(fakes.wsgi_app()) result = req.get_response(fakes.wsgi_app())
self.assertEqual(result.status, '200 OK') self.assertEqual(result.status, '200 OK')
@@ -180,9 +176,6 @@ class TestLimiter(test.TestCase):
def test_authorize_token(self): def test_authorize_token(self):
f = fakes.FakeAuthManager() f = fakes.FakeAuthManager()
u = nova.auth.manager.User(1, 'herp', None, None, None)
f.add_user('derp', u)
f.create_project('test', u)
f.add_user('derp', nova.auth.manager.User(1, 'herp', None, None, None)) f.add_user('derp', nova.auth.manager.User(1, 'herp', None, None, None))
req = webob.Request.blank('/v1.0/') req = webob.Request.blank('/v1.0/')
@@ -194,7 +187,7 @@ class TestLimiter(test.TestCase):
token = result.headers['X-Auth-Token'] token = result.headers['X-Auth-Token']
self.stubs.Set(nova.api.openstack, 'APIRouter', self.stubs.Set(nova.api.openstack, 'APIRouter',
fakes.FakeRouter) fakes.FakeRouter)
req = webob.Request.blank('/v1.0/test/fake') req = webob.Request.blank'/v1.0/fake')
req.method = 'POST' req.method = 'POST'
req.headers['X-Auth-Token'] = token req.headers['X-Auth-Token'] = token
result = req.get_response(fakes.wsgi_app()) result = req.get_response(fakes.wsgi_app())

View File

@@ -13,10 +13,10 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
import json
import stubout import stubout
import webob import webob
import json
import nova.api import nova.api
import nova.api.openstack.auth import nova.api.openstack.auth