Merge similar code into a helper function.
Signed-off-by: Michael Hanselmann <hansmi@google.com>
Reviewed-by: Guido Trotter <ultrotter@google.com>
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.
#
#
-# 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
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
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:
#!/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
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)))