Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commita1c9e2b

Browse files
author
Gauvain Pocentek
committed
New API: handle gl.auth() and CurrentUser* classes
1 parenta506902 commita1c9e2b

File tree

2 files changed

+41
-32
lines changed

2 files changed

+41
-32
lines changed

‎gitlab/__init__.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ def __init__(self, url, private_token=None, email=None, password=None,
9494

9595
objects=importlib.import_module('gitlab.v%s.objects'%
9696
self._api_version)
97+
self._objects=objects
9798

9899
self.broadcastmessages=objects.BroadcastMessageManager(self)
99100
self.deploykeys=objects.DeployKeyManager(self)
@@ -191,13 +192,16 @@ def _credentials_auth(self):
191192
ifnotself.emailornotself.password:
192193
raiseGitlabAuthenticationError("Missing email/password")
193194

194-
data=json.dumps({'email':self.email,'password':self.password})
195-
r=self._raw_post('/session',data,content_type='application/json')
196-
raise_error_from_response(r,GitlabAuthenticationError,201)
197-
self.user=CurrentUser(self,r.json())
198-
"""(gitlab.objects.CurrentUser): Object representing the user currently
199-
logged.
200-
"""
195+
ifself.api_version=='3':
196+
data=json.dumps({'email':self.email,'password':self.password})
197+
r=self._raw_post('/session',data,
198+
content_type='application/json')
199+
raise_error_from_response(r,GitlabAuthenticationError,201)
200+
self.user=objects.CurrentUser(self,r.json())
201+
else:
202+
manager=self._objects.CurrentUserManager()
203+
self.user=credentials_auth(self.email,self.password)
204+
201205
self._set_token(self.user.private_token)
202206

203207
deftoken_auth(self):
@@ -207,7 +211,7 @@ def token_auth(self):
207211
self._token_auth()
208212

209213
def_token_auth(self):
210-
self.user=CurrentUser(self)
214+
self.user=self._objects.CurrentUserManager(self).get()
211215

212216
defversion(self):
213217
"""Returns the version and revision of the gitlab server.

‎gitlab/v4/objects.py

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -180,41 +180,46 @@ def _sanitize_data(self, data, action):
180180
returnnew_data
181181

182182

183-
classCurrentUserEmail(GitlabObject):
184-
_url='/user/emails'
185-
canUpdate=False
186-
shortPrintAttr='email'
187-
requiredCreateAttrs= ['email']
183+
classCurrentUserEmail(RESTObject):
184+
_short_print_attr='email'
188185

189186

190-
classCurrentUserEmailManager(BaseManager):
191-
obj_cls=CurrentUserEmail
187+
classCurrentUserEmailManager(RetrieveMixin,CreateMixin,DeleteMixin,
188+
RESTManager):
189+
_path='/user/emails'
190+
_obj_cls=CurrentUserEmail
191+
_create_attrs= {'required': ('email', ),'optional':tuple()}
192192

193193

194-
classCurrentUserKey(GitlabObject):
195-
_url='/user/keys'
196-
canUpdate=False
197-
shortPrintAttr='title'
198-
requiredCreateAttrs= ['title','key']
194+
classCurrentUserKey(RESTObject):
195+
_short_print_attr='title'
199196

200197

201-
classCurrentUserKeyManager(BaseManager):
202-
obj_cls=CurrentUserKey
198+
classCurrentUserKeyManager(RetrieveMixin,CreateMixin,DeleteMixin,
199+
RESTManager):
200+
_path='/user/keys'
201+
_obj_cls=CurrentUserKey
202+
_create_attrs= {'required': ('title','key'),'optional':tuple()}
203203

204204

205-
classCurrentUser(GitlabObject):
206-
_url='/user'
207-
canList=False
208-
canCreate=False
209-
canUpdate=False
210-
canDelete=False
211-
shortPrintAttr='username'
212-
managers= (
213-
('emails','CurrentUserEmailManager', [('user_id','id')]),
214-
('keys','CurrentUserKeyManager', [('user_id','id')]),
205+
classCurrentUser(RESTObject):
206+
_id_attr=None
207+
_short_print_attr='username'
208+
_managers= (
209+
('emails','CurrentUserEmailManager'),
210+
('keys','CurrentUserKeyManager'),
215211
)
216212

217213

214+
classCurrentUserManager(GetWithoutIdMixin,RESTManager):
215+
_path='/user'
216+
_obj_cls=CurrentUser
217+
218+
defcredentials_auth(self,email,password):
219+
data= {'email':email,'password':password}
220+
server_data=self.gitlab.http_post('/session',post_data=data)
221+
returnCurrentUser(self,server_data)
222+
218223
classApplicationSettings(SaveMixin,RESTObject):
219224
_id_attr=None
220225

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp