Use PRIVATE-TOKEN header for passing the auth token by dekimsey · Pull Request #3 · python-gitlab/python-gitlab
def rawGet(self, path, with_token=False): url = '%s%s' % (self._url, path) if with_token: url += "?private_token=%s" % self.private_token
try: r = requests.get(url) if with_token: r = requests.get(url, headers={"PRIVATE-TOKEN": self.private_token}) else: r = requests.get(url) except: raise GitlabConnectionError( "Can't connect to GitLab server (%s)" % self._url)
def rawPut(self, path, with_token=False): url = '%s%s' % (self._url, path) if with_token: url += "?private_token=%s" % self.private_token
try: r = requests.put(url) if with_token: r = requests.put(url, headers={"PRIVATE-TOKEN": self.private_token}) else: r = requests.put(url) except: raise GitlabConnectionError( "Can't connect to GitLab server (%s)" % self._url)
try: r = requests.get(url) r = requests.get(url, headers={"PRIVATE-TOKEN": self.private_token}) except: raise GitlabConnectionError( "Can't connect to GitLab server (%s)" % self._url)
try: r = requests.get(url) r = requests.get(url, headers={"PRIVATE-TOKEN": self.private_token}) except: raise GitlabConnectionError( "Can't connect to GitLab server (%s)" % self._url)
def delete(self, obj): url = obj._url % obj.__dict__ url = '%s%s/%d?private_token=%s' % \ (self._url, url, obj.id, self.private_token) url = '%s%s/%d' % \ (self._url, url, obj.id)
try: r = requests.delete(url) r = requests.delete(url, headers={"PRIVATE-TOKEN": self.private_token}) except: raise GitlabConnectionError( "Can't connect to GitLab server (%s)" % self._url)
url = obj._url % obj.__dict__ url = '%s%s?private_token=%s' % (self._url, url, self.private_token) url = '%s%s' % (self._url, url)
print url print obj.__dict__
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__, headers={"PRIVATE-TOKEN": self.private_token}) except: raise GitlabConnectionError( "Can't connect to GitLab server (%s)" % self._url)
def update(self, obj): url = obj._url % obj.__dict__ url = '%s%s/%d?private_token=%s' % \ (self._url, url, obj.id, self.private_token) url = '%s%s/%d' % \ (self._url, url, obj.id)
# build a dict of data that can really be sent to server d = {}
try: r = requests.put(url, d) r = requests.put(url, d, headers={"PRIVATE-TOKEN": self.private_token}) except: raise GitlabConnectionError( "Can't connect to GitLab server (%s)" % self._url)
def transfer_project(self, id): url = '/groups/%d/projects/%d?private_token=%s' % \ (self.id, id, self.gitlab.private_token) r = self.gitlab.rawPost(url, None) url = '/groups/%d/projects/%d' % \ (self.id, id) r = self.gitlab.rawPost(url, None, headers={"PRIVATE-TOKEN": self.gitlab.private_token}) if r.status_code != 201: raise GitlabTransferProjectError()