Certificate-checking xmlrpc interface + use /usr/boot/pubring.gpg as the default...
[nodemanager.git] / safexmlrpc.py
1 """Leverage curl to make XMLRPC requests that check the server's credentials."""
2
3 from subprocess import PIPE, Popen
4 import xmlrpclib
5
6
7 CURL = '/usr/bin/curl'
8
9 class CertificateCheckingSafeTransport(xmlrpclib.Transport):
10     def request(self, host, handler, request_body, verbose=0):
11         self.verbose = verbose
12         p = Popen((CURL, '--cacert', '/usr/boot/cacert.pem', '--data', '@-', 'https://%s%s' % (host, handler)), stdin=PIPE, stdout=PIPE, stderr=PIPE)
13         p.stdin.write(request_body)
14         p.stdin.close()
15         contents = p.stdout.read()
16         p.stdout.close()
17         error = p.stderr.read()
18         p.stderr.close()
19         rc = p.wait()
20         if rc != 0: raise xmlrpclib.ProtocolError(host + handler, rc, error, '')
21         return xmlrpclib.loads(contents)[0]
22
23 class ServerProxy(xmlrpclib.ServerProxy):
24     def __init__(self, handler, *args, **kw_args): xmlrpclib.ServerProxy.__init__(self, handler, CertificateCheckingSafeTransport())