summaryrefslogtreecommitdiff
path: root/gitlab/__init__.py
diff options
context:
space:
mode:
authorGauvain Pocentek <gauvain@pocentek.net>2017-05-28 11:40:44 +0200
committerGauvain Pocentek <gauvain@pocentek.net>2017-06-02 15:41:37 +0200
commita1c9e2bce1d0df0eff0468fabad4919d0565f09f (patch)
tree872a0effed6d8a36523439794f652bd11e239394 /gitlab/__init__.py
parenta50690288f9c03ec37ff374839d1f465c74ecf0a (diff)
downloadgitlab-a1c9e2bce1d0df0eff0468fabad4919d0565f09f.tar.gz
New API: handle gl.auth() and CurrentUser* classes
Diffstat (limited to 'gitlab/__init__.py')
-rw-r--r--gitlab/__init__.py20
1 files changed, 12 insertions, 8 deletions
diff --git a/gitlab/__init__.py b/gitlab/__init__.py
index 50928ee..2ea5e14 100644
--- a/gitlab/__init__.py
+++ b/gitlab/__init__.py
@@ -94,6 +94,7 @@ class Gitlab(object):
objects = importlib.import_module('gitlab.v%s.objects' %
self._api_version)
+ self._objects = objects
self.broadcastmessages = objects.BroadcastMessageManager(self)
self.deploykeys = objects.DeployKeyManager(self)
@@ -191,13 +192,16 @@ class Gitlab(object):
if not self.email or not self.password:
raise GitlabAuthenticationError("Missing email/password")
- data = json.dumps({'email': self.email, 'password': self.password})
- r = self._raw_post('/session', data, content_type='application/json')
- raise_error_from_response(r, GitlabAuthenticationError, 201)
- self.user = CurrentUser(self, r.json())
- """(gitlab.objects.CurrentUser): Object representing the user currently
- logged.
- """
+ if self.api_version == '3':
+ data = json.dumps({'email': self.email, 'password': self.password})
+ r = self._raw_post('/session', data,
+ content_type='application/json')
+ raise_error_from_response(r, GitlabAuthenticationError, 201)
+ self.user = objects.CurrentUser(self, r.json())
+ else:
+ manager = self._objects.CurrentUserManager()
+ self.user = credentials_auth(self.email, self.password)
+
self._set_token(self.user.private_token)
def token_auth(self):
@@ -207,7 +211,7 @@ class Gitlab(object):
self._token_auth()
def _token_auth(self):
- self.user = CurrentUser(self)
+ self.user = self._objects.CurrentUserManager(self).get()
def version(self):
"""Returns the version and revision of the gitlab server.