Skip to content

Commit

Permalink
Merge pull request #5 from marbindrakon/ssl_verify_option
Browse files Browse the repository at this point in the history
Add ssl_verify option to Gitlab object.
  • Loading branch information
Gauvain Pocentek committed Aug 26, 2013
2 parents 7431d91 + 309f1fe commit bb7ba7a
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions gitlab.py
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit bb7ba7a

Please sign in to comment.