|
8 | 8 |
|
9 | 9 | from . import exceptions
|
10 | 10 | from .session import Session
|
| 11 | +from .users import Users |
11 | 12 | from .helper import deprecated, format_string
|
12 | 13 |
|
13 | 14 |
|
14 |
| -class Gitlab(Session): |
| 15 | +class Gitlab(Session, Users): |
15 | 16 | """
|
16 | 17 | Gitlab class
|
17 | 18 |
|
@@ -41,166 +42,6 @@ def setsudo(self, user=None):
|
41 | 42 | else:
|
42 | 43 | self.headers['SUDO'] = user
|
43 | 44 |
|
44 |
| - def get_users(self, search=None, page=1, per_page=20, **kwargs): |
45 |
| - """ |
46 |
| - Returns a list of users from the Gitlab server |
47 |
| -
|
48 |
| - :param search: Optional search query |
49 |
| - :param page: Page number (default: 1) |
50 |
| - :param per_page: Number of items to list per page (default: 20, max: 100) |
51 |
| - :return: List of Dictionaries containing users |
52 |
| - :raise: HttpError if invalid response returned |
53 |
| - """ |
54 |
| - if search: |
55 |
| - return self.get('/users', page=page, per_page=per_page, search=search, **kwargs) |
56 |
| - |
57 |
| - return self.get('/users', page=page, per_page=per_page, **kwargs) |
58 |
| - |
59 |
| - @deprecated |
60 |
| - def getusers(self, search=None, page=1, per_page=20, **kwargs): |
61 |
| - """ |
62 |
| - Returns a list of users from the Gitlab server |
63 |
| -
|
64 |
| - .. warning:: Warning this is being deprecated please use :func:`gitlab.Gitlab.get_users` |
65 |
| -
|
66 |
| - :param search: Optional search query |
67 |
| - :param page: Page number (default: 1) |
68 |
| - :param per_page: Number of items to list per page (default: 20, max: 100) |
69 |
| - :return: returns a dictionary of the users, false if there is an error |
70 |
| - """ |
71 |
| - return self.get_users(search=search, page=page, per_page=per_page, **kwargs) |
72 |
| - |
73 |
| - def getuser(self, user_id): |
74 |
| - """ |
75 |
| - Get info for a user identified by id |
76 |
| -
|
77 |
| - :param user_id: id of the user |
78 |
| - :return: False if not found, a dictionary if found |
79 |
| - """ |
80 |
| - request = requests.get( |
81 |
| - '{0}/{1}'.format(self.users_url, user_id), |
82 |
| - headers=self.headers, verify=self.verify_ssl, auth=self.auth, timeout=self.timeout) |
83 |
| - |
84 |
| - if request.status_code == 200: |
85 |
| - return request.json() |
86 |
| - else: |
87 |
| - return False |
88 |
| - |
89 |
| - def createuser(self, name, username, password, email, **kwargs): |
90 |
| - """ |
91 |
| - Create a user |
92 |
| -
|
93 |
| - :param name: Obligatory |
94 |
| - :param username: Obligatory |
95 |
| - :param password: Obligatory |
96 |
| - :param email: Obligatory |
97 |
| - :param kwargs: Any param the the Gitlab API supports |
98 |
| - :return: True if the user was created,false if it wasn't(already exists) |
99 |
| - """ |
100 |
| - data = {'name': name, 'username': username, 'password': password, 'email': email} |
101 |
| - |
102 |
| - if kwargs: |
103 |
| - data.update(kwargs) |
104 |
| - |
105 |
| - request = requests.post( |
106 |
| - self.users_url, headers=self.headers, data=data, |
107 |
| - verify=self.verify_ssl, auth=self.auth, timeout=self.timeout) |
108 |
| - |
109 |
| - if request.status_code == 201: |
110 |
| - return request.json() |
111 |
| - elif request.status_code == 404: |
112 |
| - return False |
113 |
| - |
114 |
| - def delete_user(self, user): |
115 |
| - """ |
116 |
| - Deletes a user. Available only for administrators. |
117 |
| - This is an idempotent function, calling this function for a non-existent user id |
118 |
| - still returns a status code 200 OK. |
119 |
| - The JSON response differs if the user was actually deleted or not. |
120 |
| - In the former the user is returned and in the latter not. |
121 |
| -
|
122 |
| - :param user: The ID of the user |
123 |
| - :return: Empty Dict |
124 |
| - :raise: HttpError: If invalid response returned |
125 |
| - """ |
126 |
| - return self.delete('/users/{user}'.format(user=user), default_response={}) |
127 |
| - |
128 |
| - @deprecated |
129 |
| - def deleteuser(self, user_id): |
130 |
| - """ |
131 |
| - Deletes a user. Available only for administrators. |
132 |
| - This is an idempotent function, calling this function for a non-existent user id |
133 |
| - still returns a status code 200 OK. |
134 |
| - The JSON response differs if the user was actually deleted or not. |
135 |
| - In the former the user is returned and in the latter not. |
136 |
| -
|
137 |
| - .. warning:: Warning this is being deprecated please use :func:`gitlab.Gitlab.delete_user` |
138 |
| -
|
139 |
| - :param user_id: The ID of the user |
140 |
| - :return: True if it deleted, False if it couldn't |
141 |
| - """ |
142 |
| - deleted = self.delete_user(user_id) |
143 |
| - |
144 |
| - if deleted is False: |
145 |
| - return False |
146 |
| - else: |
147 |
| - return True |
148 |
| - |
149 |
| - def currentuser(self): |
150 |
| - """ |
151 |
| - Returns the current user parameters. The current user is linked to the secret token |
152 |
| -
|
153 |
| - :return: a list with the current user properties |
154 |
| - """ |
155 |
| - request = requests.get( |
156 |
| - '{0}/api/v3/user'.format(self.host), |
157 |
| - headers=self.headers, verify=self.verify_ssl, auth=self.auth, timeout=self.timeout) |
158 |
| - |
159 |
| - return request.json() |
160 |
| - |
161 |
| - def edituser(self, user_id, **kwargs): |
162 |
| - """ |
163 |
| - Edits an user data. |
164 |
| -
|
165 |
| - :param user_id: id of the user to change |
166 |
| - :param kwargs: Any param the the Gitlab API supports |
167 |
| - :return: Dict of the user |
168 |
| - """ |
169 |
| - data = {} |
170 |
| - |
171 |
| - if kwargs: |
172 |
| - data.update(kwargs) |
173 |
| - |
174 |
| - request = requests.put( |
175 |
| - '{0}/{1}'.format(self.users_url, user_id), |
176 |
| - headers=self.headers, data=data, timeout=self.timeout, verify=self.verify_ssl, auth=self.auth) |
177 |
| - |
178 |
| - if request.status_code == 200: |
179 |
| - return request.json() |
180 |
| - else: |
181 |
| - return False |
182 |
| - |
183 |
| - def blockuser(self, user_id, **kwargs): |
184 |
| - """ |
185 |
| - Block a user. |
186 |
| -
|
187 |
| - :param user_id: id of the user to change |
188 |
| - :param kwargs: Any param the the Gitlab API supports |
189 |
| - :return: Dict of the user |
190 |
| - """ |
191 |
| - data = {} |
192 |
| - |
193 |
| - if kwargs: |
194 |
| - data.update(kwargs) |
195 |
| - |
196 |
| - request = requests.put( |
197 |
| - '{0}/{1}/block'.format(self.users_url, user_id), |
198 |
| - headers=self.headers, data=data, timeout=self.timeout, verify=self.verify_ssl) |
199 |
| - |
200 |
| - if request.status_code == 200: |
201 |
| - return request.json() |
202 |
| - else: |
203 |
| - return False |
204 | 45 |
|
205 | 46 | def getsshkeys(self):
|
206 | 47 | """
|
|
0 commit comments