diff options
author | Gauvain Pocentek <gauvain@pocentek.net> | 2017-05-28 11:40:44 +0200 |
---|---|---|
committer | Gauvain Pocentek <gauvain@pocentek.net> | 2017-06-02 15:41:37 +0200 |
commit | a1c9e2bce1d0df0eff0468fabad4919d0565f09f (patch) | |
tree | 872a0effed6d8a36523439794f652bd11e239394 /gitlab/v4/objects.py | |
parent | a50690288f9c03ec37ff374839d1f465c74ecf0a (diff) | |
download | gitlab-a1c9e2bce1d0df0eff0468fabad4919d0565f09f.tar.gz |
New API: handle gl.auth() and CurrentUser* classes
Diffstat (limited to 'gitlab/v4/objects.py')
-rw-r--r-- | gitlab/v4/objects.py | 53 |
1 files changed, 29 insertions, 24 deletions
diff --git a/gitlab/v4/objects.py b/gitlab/v4/objects.py index 34100d8..62bb046 100644 --- a/gitlab/v4/objects.py +++ b/gitlab/v4/objects.py @@ -180,41 +180,46 @@ class UserManager(CRUDMixin, RESTManager): return new_data -class CurrentUserEmail(GitlabObject): - _url = '/user/emails' - canUpdate = False - shortPrintAttr = 'email' - requiredCreateAttrs = ['email'] +class CurrentUserEmail(RESTObject): + _short_print_attr = 'email' -class CurrentUserEmailManager(BaseManager): - obj_cls = CurrentUserEmail +class CurrentUserEmailManager(RetrieveMixin, CreateMixin, DeleteMixin, + RESTManager): + _path = '/user/emails' + _obj_cls = CurrentUserEmail + _create_attrs = {'required': ('email', ), 'optional': tuple()} -class CurrentUserKey(GitlabObject): - _url = '/user/keys' - canUpdate = False - shortPrintAttr = 'title' - requiredCreateAttrs = ['title', 'key'] +class CurrentUserKey(RESTObject): + _short_print_attr = 'title' -class CurrentUserKeyManager(BaseManager): - obj_cls = CurrentUserKey +class CurrentUserKeyManager(RetrieveMixin, CreateMixin, DeleteMixin, + RESTManager): + _path = '/user/keys' + _obj_cls = CurrentUserKey + _create_attrs = {'required': ('title', 'key'), 'optional': tuple()} -class CurrentUser(GitlabObject): - _url = '/user' - canList = False - canCreate = False - canUpdate = False - canDelete = False - shortPrintAttr = 'username' - managers = ( - ('emails', 'CurrentUserEmailManager', [('user_id', 'id')]), - ('keys', 'CurrentUserKeyManager', [('user_id', 'id')]), +class CurrentUser(RESTObject): + _id_attr = None + _short_print_attr = 'username' + _managers = ( + ('emails', 'CurrentUserEmailManager'), + ('keys', 'CurrentUserKeyManager'), ) +class CurrentUserManager(GetWithoutIdMixin, RESTManager): + _path = '/user' + _obj_cls = CurrentUser + + def credentials_auth(self, email, password): + data = {'email': email, 'password': password} + server_data = self.gitlab.http_post('/session', post_data=data) + return CurrentUser(self, server_data) + class ApplicationSettings(SaveMixin, RESTObject): _id_attr = None |