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

Commitc4920ee

Browse files
author
Gauvain Pocentek
committed
drop Session() and add a Gitlab.authenticate() method
1 parentbf25928 commitc4920ee

File tree

1 file changed

+26
-10
lines changed

1 file changed

+26
-10
lines changed

‎gitlab.py

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,33 @@ class GitlabCreateError(Exception):
3030
classGitlabUpdateError(Exception):
3131
pass
3232

33-
classGitlabSessionError(Exception):
33+
classGitlabAuthenticationError(Exception):
3434
pass
3535

3636
classGitlab(object):
37-
def__init__(self,url,private_token):
37+
def__init__(self,url,private_token=None,email=None,password=None):
3838
self.url='%s/api/v3'%url
3939
self.private_token=private_token
40+
self.email=email
41+
self.password=password
42+
43+
ifnotself.private_token:
44+
self.authenticate
45+
46+
defauthenticate(self,email=None,password=None):
47+
self.email=self.emailoremail
48+
self.password=self.passwordorpassword
49+
50+
ifnotself.emailornotself.password:
51+
raiseGitlabAuthenticationError("Missing email/password")
52+
53+
r=self.rawPost('/session', {'email':email,'password':password})
54+
ifr.status_code==201:
55+
self.user=User(self,r.json)
56+
else:
57+
raiseGitlabAuthenticationError()
58+
59+
self.private_token=self.user.private_token
4060

4161
defsetUrl(self,url):
4262
self.url='%s/api/v3'%url
@@ -234,13 +254,16 @@ def getObject(self, k, v):
234254

235255
def__init__(self,gl,data):
236256
self.gitlab=gl
257+
237258
fork,vindata.items():
238259
ifisinstance (v,list):
239260
self.__dict__[k]= []
240261
foriinv:
241262
self.__dict__[k].append(self.getObject(k,i))
242-
else:
263+
elifv:
243264
self.__dict__[k]=self.getObject(k,v)
265+
else:# None object
266+
self.__dict__[k]=None
244267

245268
def__str__(self):
246269
return'%s => %s'%(type(self),str(self.__dict__))
@@ -275,13 +298,6 @@ class Issue(GitlabObject):
275298
canUpdate=False
276299
canCreate=False
277300

278-
defSession(gl,email,password):
279-
r=gl.rawPost('/session', {'email':email,'password':password})
280-
ifr.status_code==201:
281-
returnUser(gl,r.json)
282-
else:
283-
raiseGitlabSessionError()
284-
285301
classProjectBranch(GitlabObject):
286302
url='/projects/%(project_id)d/repository/branches'
287303
canDelete=False

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp