Skip to content
This repository was archived by the owner on Nov 4, 2020. It is now read-only.

Commit 15331e3

Browse files
authored
Merge branch 'develop' into issues/255
2 parents cf2e69d + 0cbcb30 commit 15331e3

File tree

2 files changed

+76
-60
lines changed

2 files changed

+76
-60
lines changed

gitlab/__init__.py

+6-59
Original file line numberDiff line numberDiff line change
@@ -43,75 +43,22 @@ def setsudo(self, user=None):
4343
else:
4444
self.headers['SUDO'] = user
4545

46-
def getsshkeys(self):
46+
def getsshkey(self, key_id):
4747
"""
48-
Gets all the ssh keys for the current user
48+
Get a single ssh key identified by key_id
4949
50-
:return: a dictionary with the lists
50+
:param key_id: the id of the key
51+
:return: the key itself
5152
"""
5253
request = requests.get(
53-
self.keys_url, headers=self.headers, verify=self.verify_ssl, auth=self.auth, timeout=self.timeout)
54+
'{0}/{1}'.format(self.keys_url, key_id),
55+
headers=self.headers, verify=self.verify_ssl, auth=self.auth, timeout=self.timeout)
5456

5557
if request.status_code == 200:
5658
return request.json()
5759
else:
5860
return False
5961

60-
def addsshkey(self, title, key):
61-
"""
62-
Add a new ssh key for the current user
63-
64-
:param title: title of the new key
65-
:param key: the key itself
66-
:return: true if added, false if it didn't add it (it could be because the name or key already exists)
67-
"""
68-
data = {'title': title, 'key': key}
69-
70-
request = requests.post(
71-
self.keys_url, headers=self.headers, data=data,
72-
verify=self.verify_ssl, auth=self.auth, timeout=self.timeout)
73-
74-
if request.status_code == 201:
75-
return True
76-
else:
77-
return False
78-
79-
def addsshkeyuser(self, user_id, title, key):
80-
"""
81-
Add a new ssh key for the user identified by id
82-
83-
:param user_id: id of the user to add the key to
84-
:param title: title of the new key
85-
:param key: the key itself
86-
:return: true if added, false if it didn't add it (it could be because the name or key already exists)
87-
"""
88-
data = {'title': title, 'key': key}
89-
90-
request = requests.post(
91-
'{0}/{1}/keys'.format(self.users_url, user_id), headers=self.headers,
92-
data=data, verify=self.verify_ssl, auth=self.auth, timeout=self.timeout)
93-
94-
if request.status_code == 201:
95-
return True
96-
else:
97-
return False
98-
99-
def deletesshkey(self, key_id):
100-
"""
101-
Deletes an sshkey for the current user identified by id
102-
103-
:param key_id: the id of the key
104-
:return: False if it didn't delete it, True if it was deleted
105-
"""
106-
request = requests.delete(
107-
'{0}/{1}'.format(self.keys_url, key_id), headers=self.headers,
108-
verify=self.verify_ssl, auth=self.auth, timeout=self.timeout)
109-
110-
if request.content == b'null':
111-
return False
112-
else:
113-
return True
114-
11562
def getprojectsowned(self, page=1, per_page=20):
11663
"""
11764
Returns a dictionary of all the projects for the current user

gitlab/users.py

+70-1
Original file line numberDiff line numberDiff line change
@@ -165,4 +165,73 @@ def blockuser(self, user_id, **kwargs):
165165
if request.status_code == 200:
166166
return request.json()
167167
else:
168-
return False
168+
return False
169+
170+
def getsshkeys(self):
171+
"""
172+
Gets all the ssh keys for the current user
173+
174+
:return: a dictionary with the lists
175+
"""
176+
request = requests.get(
177+
self.keys_url, headers=self.headers, verify=self.verify_ssl, auth=self.auth, timeout=self.timeout)
178+
179+
if request.status_code == 200:
180+
return request.json()
181+
else:
182+
return False
183+
184+
def addsshkey(self, title, key):
185+
"""
186+
Add a new ssh key for the current user
187+
188+
:param title: title of the new key
189+
:param key: the key itself
190+
:return: true if added, false if it didn't add it (it could be because the name or key already exists)
191+
"""
192+
data = {'title': title, 'key': key}
193+
194+
request = requests.post(
195+
self.keys_url, headers=self.headers, data=data,
196+
verify=self.verify_ssl, auth=self.auth, timeout=self.timeout)
197+
198+
if request.status_code == 201:
199+
return True
200+
else:
201+
return False
202+
203+
def addsshkeyuser(self, user_id, title, key):
204+
"""
205+
Add a new ssh key for the user identified by id
206+
207+
:param user_id: id of the user to add the key to
208+
:param title: title of the new key
209+
:param key: the key itself
210+
:return: true if added, false if it didn't add it (it could be because the name or key already exists)
211+
"""
212+
data = {'title': title, 'key': key}
213+
214+
request = requests.post(
215+
'{0}/{1}/keys'.format(self.users_url, user_id), headers=self.headers,
216+
data=data, verify=self.verify_ssl, auth=self.auth, timeout=self.timeout)
217+
218+
if request.status_code == 201:
219+
return True
220+
else:
221+
return False
222+
223+
def deletesshkey(self, key_id):
224+
"""
225+
Deletes an sshkey for the current user identified by id
226+
227+
:param key_id: the id of the key
228+
:return: False if it didn't delete it, True if it was deleted
229+
"""
230+
request = requests.delete(
231+
'{0}/{1}'.format(self.keys_url, key_id), headers=self.headers,
232+
verify=self.verify_ssl, auth=self.auth, timeout=self.timeout)
233+
234+
if request.content == b'null':
235+
return False
236+
else:
237+
return True

0 commit comments

Comments
 (0)