forked from pyapi-gitlab/pyapi-gitlab
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsession.py
More file actions
29 lines (24 loc) · 954 Bytes
/
session.py
File metadata and controls
29 lines (24 loc) · 954 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
from .base import Base
class Session(Base):
def login(self, email=None, password=None, user=None):
"""
Logs the user in and setups the header with the private token
:param email: Gitlab user Email
:param user: Gitlab username
:param password: Gitlab user password
:return: True if login successful
:raise: HttpError
:raise: ValueError
"""
if user is not None:
data = {'login': user, 'password': password}
elif email is not None:
data = {'email': email, 'password': password}
else:
raise ValueError('Neither username nor email provided to login')
self.headers = {'connection': 'close'}
response = self.post('/session', **data)
self.token = response['private_token']
self.headers = {'PRIVATE-TOKEN': self.token,
'connection': 'close'}
return response