summaryrefslogtreecommitdiffstats
path: root/base/common/python/pki/client.py
diff options
context:
space:
mode:
authorAde Lee <alee@redhat.com>2014-02-12 11:44:47 -0500
committerAde Lee <alee@redhat.com>2014-02-19 10:48:06 -0500
commita9c460f532a5f9697b56aa116c3df772b0fd27e9 (patch)
tree8c979fc91e121ab6fbade87ac506807723bb10c6 /base/common/python/pki/client.py
parent03f688d8becf32748711a5832af1a736e838905d (diff)
downloadpki-a9c460f532a5f9697b56aa116c3df772b0fd27e9.tar.gz
pki-a9c460f532a5f9697b56aa116c3df772b0fd27e9.tar.xz
pki-a9c460f532a5f9697b56aa116c3df772b0fd27e9.zip
Initial work on python API
This patch includes code for most of the python client library for the KeyResource and KeyRequestResource for the DRM. Some place holder code has been added for the CertResource, but this needs to be further refined and tested.
Diffstat (limited to 'base/common/python/pki/client.py')
-rw-r--r--base/common/python/pki/client.py28
1 files changed, 23 insertions, 5 deletions
diff --git a/base/common/python/pki/client.py b/base/common/python/pki/client.py
index 00343bb7c..c95cb2927 100644
--- a/base/common/python/pki/client.py
+++ b/base/common/python/pki/client.py
@@ -26,7 +26,7 @@ class PKIConnection:
def __init__(self,
protocol='http',
hostname='localhost',
- port=80,
+ port='8080',
subsystem='ca',
accept='application/json'):
@@ -47,19 +47,37 @@ class PKIConnection:
if username is not None and password is not None:
self.session.auth = (username, password)
- def get(self, path, headers=None):
+ def set_authentication_cert(self, pem_cert_path):
+ if pem_cert_path is None:
+ raise Exception("No path for the certificate specified.")
+ if len(str(pem_cert_path)) == 0:
+ raise Exception("No path for the certificate specified.")
+ self.session.cert = pem_cert_path
+
+ def get(self, path, headers=None, params=None):
r = self.session.get(
self.serverURI + path,
verify=False,
- headers=headers)
+ headers=headers,
+ params=params)
r.raise_for_status()
return r
- def post(self, path, payload, headers=None):
+ def post(self, path, payload, headers=None, params=None):
r = self.session.post(
self.serverURI + path,
verify=False,
data=payload,
- headers=headers)
+ headers=headers,
+ params=params)
r.raise_for_status()
return r
+def main():
+ conn = PKIConnection()
+ headers = {'Content-type': 'application/json',
+ 'Accept': 'application/json'}
+ conn.set_authentication_cert('/root/temp4.pem')
+ print conn.get("", headers).json()
+
+if __name__ == "__main__":
+ main()