diff options
author | Christian Heimes <cheimes@redhat.com> | 2015-08-07 19:08:52 +0200 |
---|---|---|
committer | Endi S. Dewata <edewata@redhat.com> | 2015-08-08 06:47:06 +0200 |
commit | a6423245a01217a295091407dfcb8fe79e019342 (patch) | |
tree | 2ce3c880b5b9397893d8c87f5e383862c7de988e /base/common/python/pki | |
parent | 5015475c6084d9397017e5531299f1545fae2a33 (diff) | |
download | pki-a6423245a01217a295091407dfcb8fe79e019342.tar.gz pki-a6423245a01217a295091407dfcb8fe79e019342.tar.xz pki-a6423245a01217a295091407dfcb8fe79e019342.zip |
Temporary silence InsecureRequestWarning
https://fedorahosted.org/pki/ticket/1253
Diffstat (limited to 'base/common/python/pki')
-rw-r--r-- | base/common/python/pki/client.py | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/base/common/python/pki/client.py b/base/common/python/pki/client.py index 90939930a..d28a41d63 100644 --- a/base/common/python/pki/client.py +++ b/base/common/python/pki/client.py @@ -19,7 +19,27 @@ # All rights reserved. # +import functools +import warnings + import requests +from requests.packages.urllib3.exceptions import InsecureRequestWarning + + +def catch_insecure_warning(func): + """Temporary silence InsecureRequestWarning + + PKIConnection is not able to verify HTTPS connections yet. This decorator + catches the warning. + + :see: https://fedorahosted.org/pki/ticket/1253 + """ + @functools.wraps(func) + def wrapper(self, *args, **kwargs): + with warnings.catch_warnings(): + warnings.simplefilter('ignore', InsecureRequestWarning) + return func(self, *args, **kwargs) + return wrapper class PKIConnection: @@ -91,6 +111,7 @@ class PKIConnection: raise Exception("No path for the certificate specified.") self.session.cert = pem_cert_path + @catch_insecure_warning def get(self, path, headers=None, params=None, payload=None): """ Uses python-requests to issue a GET request to the server. @@ -116,6 +137,7 @@ class PKIConnection: r.raise_for_status() return r + @catch_insecure_warning def post(self, path, payload, headers=None, params=None): """ Uses python-requests to issue a POST request to the server. @@ -141,6 +163,7 @@ class PKIConnection: r.raise_for_status() return r + @catch_insecure_warning def put(self, path, payload, headers=None): """ Uses python-requests to issue a PUT request to the server. @@ -159,6 +182,7 @@ class PKIConnection: r.raise_for_status() return r + @catch_insecure_warning def delete(self, path, headers=None): """ Uses python-requests to issue a DEL request to the server. |