Fix a fer nits jaypipes found in review.
This commit is contained in:
@@ -21,6 +21,7 @@ from nova import log as logging
|
||||
from nova import wsgi
|
||||
|
||||
from nova.auth import manager
|
||||
from nova.api.openstack import faults
|
||||
|
||||
FLAGS = flags.FLAGS
|
||||
LOG = logging.getLogger('nova.api.openstack')
|
||||
@@ -44,11 +45,17 @@ class Controller(wsgi.Controller):
|
||||
self.manager = manager.AuthManager()
|
||||
|
||||
def _check_admin(self, context):
|
||||
""" We cannot depend on the db layer to check for admin access
|
||||
for the auth manager, so we do it here """
|
||||
"""We cannot depend on the db layer to check for admin access
|
||||
for the auth manager, so we do it here"""
|
||||
if not context.is_admin:
|
||||
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):
|
||||
"""Return data about the given account id"""
|
||||
account = self.manager.get_project(id)
|
||||
@@ -59,8 +66,13 @@ class Controller(wsgi.Controller):
|
||||
self.manager.delete_project(id)
|
||||
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):
|
||||
""" This is really create or update. """
|
||||
"""This is really create or update."""
|
||||
self._check_admin(req.environ['nova.context'])
|
||||
env = self._deserialize(req.body, req)
|
||||
description = env['account'].get('description')
|
||||
|
||||
@@ -45,8 +45,8 @@ class Controller(wsgi.Controller):
|
||||
self.manager = manager.AuthManager()
|
||||
|
||||
def _check_admin(self, context):
|
||||
""" We cannot depend on the db layer to check for admin access
|
||||
for the auth manager, so we do it here """
|
||||
"""We cannot depend on the db layer to check for admin access
|
||||
for the auth manager, so we do it here"""
|
||||
if not context.is_admin:
|
||||
raise exception.NotAuthorized(_("Not admin user"))
|
||||
|
||||
|
||||
@@ -14,9 +14,10 @@
|
||||
# under the License.
|
||||
|
||||
|
||||
import json
|
||||
|
||||
import stubout
|
||||
import webob
|
||||
import json
|
||||
|
||||
import nova.api
|
||||
import nova.api.openstack.auth
|
||||
@@ -47,8 +48,7 @@ class AccountsTest(test.TestCase):
|
||||
fake_init)
|
||||
self.stubs.Set(nova.api.openstack.accounts.Controller, '_check_admin',
|
||||
fake_admin_check)
|
||||
fakes.FakeAuthManager.auth_data = {}
|
||||
fakes.FakeAuthManager.projects = {}
|
||||
fakes.FakeAuthManager.clear_fakes()
|
||||
fakes.FakeAuthDatabase.data = {}
|
||||
fakes.stub_out_networking(self.stubs)
|
||||
fakes.stub_out_rate_limiting(self.stubs)
|
||||
|
||||
@@ -51,9 +51,7 @@ class Test(test.TestCase):
|
||||
|
||||
def test_authorize_user(self):
|
||||
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))
|
||||
|
||||
req = webob.Request.blank('/v1.0/')
|
||||
req.headers['X-Auth-User'] = 'herp'
|
||||
@@ -67,9 +65,7 @@ class Test(test.TestCase):
|
||||
|
||||
def test_authorize_token(self):
|
||||
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))
|
||||
|
||||
req = webob.Request.blank('/v1.0/', {'HTTP_HOST': 'foo'})
|
||||
req.headers['X-Auth-User'] = 'herp'
|
||||
@@ -86,7 +82,7 @@ class Test(test.TestCase):
|
||||
token = result.headers['X-Auth-Token']
|
||||
self.stubs.Set(nova.api.openstack, 'APIRouter',
|
||||
fakes.FakeRouter)
|
||||
req = webob.Request.blank('/v1.0/test/fake')
|
||||
req = webob.Request.blank('/v1.0/fake')
|
||||
req.headers['X-Auth-Token'] = token
|
||||
result = req.get_response(fakes.wsgi_app())
|
||||
self.assertEqual(result.status, '200 OK')
|
||||
@@ -180,9 +176,6 @@ class TestLimiter(test.TestCase):
|
||||
|
||||
def test_authorize_token(self):
|
||||
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))
|
||||
|
||||
req = webob.Request.blank('/v1.0/')
|
||||
@@ -194,7 +187,7 @@ class TestLimiter(test.TestCase):
|
||||
token = result.headers['X-Auth-Token']
|
||||
self.stubs.Set(nova.api.openstack, 'APIRouter',
|
||||
fakes.FakeRouter)
|
||||
req = webob.Request.blank('/v1.0/test/fake')
|
||||
req = webob.Request.blank'/v1.0/fake')
|
||||
req.method = 'POST'
|
||||
req.headers['X-Auth-Token'] = token
|
||||
result = req.get_response(fakes.wsgi_app())
|
||||
|
||||
@@ -13,10 +13,10 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import json
|
||||
|
||||
import stubout
|
||||
import webob
|
||||
import json
|
||||
|
||||
import nova.api
|
||||
import nova.api.openstack.auth
|
||||
|
||||
Reference in New Issue
Block a user