AuthenticatedAPI class, currently unused
smbaker [Tue, 15 Jan 2013 07:28:54 +0000 (23:28 -0800)]
apps/gacks/gackshandler_plc.py

index 87d1572..3bcee22 100644 (file)
@@ -1,3 +1,5 @@
+import bridgeconfig
+import functools
 import xmlrpclib
 import logging
 import os
@@ -32,6 +34,17 @@ class GacksPLCConnectFailed(GacksPLCException):
 class GacksPLCAuthFailed(GacksPLCException):
     pass
 
+class AuthenticatedPLC:
+    """ A wrapper around an XMLRPCServer that passes plcAuth as the first arg
+        of every method call.
+    """
+    def __init__(self, plc, plcAuth):
+        self.plc = plc
+        self.plcAuth = plcAuth
+
+    def __getattr__(self, name):
+        return functools.partial(getattr(self.plc, name), self.plcAuth)
+
 class GacksPLCHandler(GacksHandler):
     def __init__(self, resourceDefinition):
         GacksHandler.__init__(self, resourceDefinition)
@@ -453,3 +466,4 @@ class GacksPLCHandler(GacksHandler):
 
         self.mylogger().info("renewSlice: updated slice %s expiration from %s to %s" % (sliceName, time.ctime(slices[0]["expires"]), time.ctime(tExpire)))
 
+