diff --git a/lib/rapi/baserlib.py b/lib/rapi/baserlib.py index 9534e3b765f18db515907b674f5eca1696b83034..4b6cc8987fd561397a6482fd96b28e72badee9f9 100644 --- a/lib/rapi/baserlib.py +++ b/lib/rapi/baserlib.py @@ -406,6 +406,17 @@ def GetResourceOpcodes(cls): for (_, op_attr, _, _) in _OPCODE_ATTRS))) +def GetHandlerAccess(handler, method): + """Returns the access rights for a method on a handler. + + @type handler: L{ResourceBase} + @type method: string + @rtype: string or None + + """ + return getattr(handler, "%s_ACCESS" % method, None) + + class _MetaOpcodeResource(type): """Meta class for RAPI resources. diff --git a/lib/server/rapi.py b/lib/server/rapi.py index 3fda622db9f1a7d63ca373cb74b9a95d07959615..65162ee936447e079d93eeb08ebdedfdf18c0ee5 100644 --- a/lib/server/rapi.py +++ b/lib/server/rapi.py @@ -1,7 +1,7 @@ # # -# Copyright (C) 2006, 2007, 2008, 2009, 2010, 2012 Google Inc. +# Copyright (C) 2006, 2007, 2008, 2009, 2010, 2012, 2013 Google Inc. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -49,6 +49,7 @@ from ganeti import compat from ganeti import utils from ganeti import pathutils from ganeti.rapi import connector +from ganeti.rapi import baserlib import ganeti.http.auth # pylint: disable=W0611 import ganeti.http.server @@ -120,7 +121,7 @@ class RemoteApiHandler(http.auth.HttpServerRequestAuthentication, raise http.HttpNotImplemented("Method %s is unsupported for path %s" % (method, req.request_path)) - ctx.handler_access = getattr(ctx.handler, "%s_ACCESS" % method, None) + ctx.handler_access = baserlib.GetHandlerAccess(ctx.handler, method) # Require permissions definition (usually in the base class) if ctx.handler_access is None: diff --git a/test/py/ganeti.rapi.rlib2_unittest.py b/test/py/ganeti.rapi.rlib2_unittest.py index b66d01a4cab3220a16bef7a4a4d7e21ea37af602..77c44353b590dc6cf7f19365a1fd4fdf172f9def 100755 --- a/test/py/ganeti.rapi.rlib2_unittest.py +++ b/test/py/ganeti.rapi.rlib2_unittest.py @@ -1,7 +1,7 @@ #!/usr/bin/python # -# Copyright (C) 2010, 2012 Google Inc. +# Copyright (C) 2010, 2012, 2013 Google Inc. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -1770,7 +1770,8 @@ class TestPermissions(unittest.TestCase): def testMethodAccess(self): for handler in connector.CONNECTOR.values(): for method in baserlib._SUPPORTED_METHODS: - access = getattr(handler, "%s_ACCESS" % method) + access = baserlib.GetHandlerAccess(handler, method) + self.assertFalse(access is None) self.assertFalse(set(access) - rapi.RAPI_ACCESS_ALL, msg=("Handler '%s' uses unknown access options for" " method %s" % (handler, method)))