support in Gacks Shell for functions that take an authtoken
smbaker [Thu, 22 Nov 2012 03:04:01 +0000 (19:04 -0800)]
apps/gacks/gacksclient.py

index 0822062..d3d6b2f 100644 (file)
@@ -1,5 +1,6 @@
 import base64
 import inspect
+import functools
 import xmlrpclib
 
 from gacksreceipt import *
@@ -26,6 +27,24 @@ class GacksClient(AuthenticatedClient):
        # creating request signatures
        self.keypair = Keypair(filename = self.key_file)
 
+       # XXX probably wont use the below; going to get them by inspecting the func
+       requires_auth = ["set_allocator",
+                "set_consumer",
+                "set_consumer_hrn",
+                "pick",
+                "add_asap",
+                "grm_delete",
+                "grm_reserve",
+                "delete_asap",
+                "get_account",
+                "get_invoice",
+                "admin_asap_run",
+                "admin_reset",
+                "admin_garbage_collect",
+                "admin_degragment",
+                "admin_apply_invoices",
+                "admin_mail_invoices"]
+
     def get_methods(self):
         methodNames = ["get_update",
                         "query_overlap",
@@ -57,7 +76,8 @@ class GacksClient(AuthenticatedClient):
             (args, varargs, keywords, default) = inspect.getargspec(func)
             methods[methodName] = {"name": methodName,
                                    "func": func,
-                                   "args": args}
+                                   "args": args,
+                                   "requires_auth": (len(args)>=2) and (args[1]=="authToken")}
 
         return methods
 
@@ -256,7 +276,8 @@ class GacksShell:
 
         for (name, d) in self.client.get_methods().items():
             if globals is not None:
-                globals[name] = d['func']
-
-
+                if d['requires_auth']:
+                    globals[name] = functools.partial(d['func'], self.authtoken)
+                else:
+                    globals[name] = d['func']