From 309f1fe0fbaca19a400ed521a27362adad89b4d5 Mon Sep 17 00:00:00 2001 From: Andrew Austin Date: Mon, 26 Aug 2013 03:47:19 +0000 Subject: [PATCH] Add ssl_verify option to Gitlab object. Defauls to True --- gitlab.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/gitlab.py b/gitlab.py index 6f016fcad..3901eafd8 100644 --- a/gitlab.py +++ b/gitlab.py @@ -74,7 +74,7 @@ class GitlabAuthenticationError(Exception): class Gitlab(object): """Represents a GitLab server connection""" - def __init__(self, url, private_token=None, email=None, password=None): + def __init__(self, url, private_token=None, email=None, password=None, ssl_verify=True): """Stores informations about the server url: the URL of the Gitlab server @@ -86,6 +86,7 @@ def __init__(self, url, private_token=None, email=None, password=None): self.private_token = private_token self.email = email self.password = password + self.ssl_verify = ssl_verify def auth(self): """Performs an authentication using either the private token, or the @@ -139,7 +140,7 @@ def rawGet(self, path, with_token=False): url += "?private_token=%s" % self.private_token try: - r = requests.get(url) + r = requests.get(url, verify=self.ssl_verify) except: raise GitlabConnectionError( "Can't connect to GitLab server (%s)" % self._url) @@ -149,7 +150,7 @@ def rawGet(self, path, with_token=False): def rawPost(self, path, data): url = '%s%s' % (self._url, path) try: - r = requests.post(url, data) + r = requests.post(url, data, verify=self.ssl_verify) except: raise GitlabConnectionError( "Can't connect to GitLab server (%s)" % self._url) @@ -162,7 +163,7 @@ def rawPut(self, path, with_token=False): url += "?private_token=%s" % self.private_token try: - r = requests.put(url) + r = requests.put(url, verify=self.ssl_verify) except: raise GitlabConnectionError( "Can't connect to GitLab server (%s)" % self._url) @@ -187,7 +188,7 @@ def list(self, obj_class, **kwargs): ["%s=%s" % (k, v) for k, v in kwargs.items()])) try: - r = requests.get(url) + r = requests.get(url, verify=self.ssl_verify) except: raise GitlabConnectionError( "Can't connect to GitLab server (%s)" % self._url) @@ -233,7 +234,7 @@ def get(self, obj_class, id=None, **kwargs): (self._url, url, self.private_token) try: - r = requests.get(url) + r = requests.get(url, verify=self.ssl_verify) except: raise GitlabConnectionError( "Can't connect to GitLab server (%s)" % self._url) @@ -253,7 +254,7 @@ def delete(self, obj): (self._url, url, obj.id, self.private_token) try: - r = requests.delete(url) + r = requests.delete(url, verify=self.ssl_verify) except: raise GitlabConnectionError( "Can't connect to GitLab server (%s)" % self._url) @@ -281,7 +282,7 @@ def create(self, obj): try: # TODO: avoid too much work on the server side by filtering the # __dict__ keys - r = requests.post(url, obj.__dict__) + r = requests.post(url, obj.__dict__, verify=self.ssl_verify) except: raise GitlabConnectionError( "Can't connect to GitLab server (%s)" % self._url) @@ -305,7 +306,7 @@ def update(self, obj): d[k] = str(v) try: - r = requests.put(url, d) + r = requests.put(url, d, verify=self.ssl_verify) except: raise GitlabConnectionError( "Can't connect to GitLab server (%s)" % self._url)