import repository from arizona
[raven.git] / lib / ravenlib / modpythonapi / AuthenticatedClient.py
1 from sfa.trust.certificate import Keypair
2 from sfa.trust.gid import GID
3
4 from BaseClient import BaseClient
5
6 class AuthenticatedClient(BaseClient):
7     def __init__(self, url, private_key_file, gid_file=None, cred_file=None):
8         BaseClient.__init__(self, url)
9         self.private_key_file = private_key_file
10         self.gid_file = gid_file
11         self.cred_file = cred_file
12         self.private_key = Keypair(filename = self.private_key_file)
13         if gid_file:
14             self.gid = GID(filename = self.gid_file)
15         if cred_file:
16             self.cred = Credential(filename = self.cred_file)
17
18     def credToStr(self, cred):
19         # deals with the new credential's save_to_string() method not working
20         # for legacy credentials.
21         if hasattr(cred, "legacy") and (cred.legacy != None):
22             return cred.legacy.save_to_string(save_parents = True)
23         else:
24             return cred.save_to_string(save_parents = True)
25
26     def computeRequestHash(self, argList):
27         return self.private_key.sign_string(str(argList))
28
29     def gidNoop(self, value, gid=None):
30         if not gid:
31             gid = self.gid
32         gidStr = gid.save_to_string(True)
33         reqHash = self.computeRequestHash([gidStr, value])
34         return self.server.gidNoop(gidStr, value, reqHash)
35
36     def credNoop(self, value, cred=None):
37         if not cred:
38             cred = self.cred
39         credStr = self.credToStr(cred)
40         reqHash = self.computeRequestHash([credStr, value])
41         return self.server.credNoop(credStr, value, reqHash)