Skip to content

Commit 5183069

Browse files
author
Gauvain Pocentek
committed
Add support for the EE license API
1 parent 3f88ad0 commit 5183069

File tree

3 files changed

+51
-9
lines changed

3 files changed

+51
-9
lines changed

gitlab/__init__.py

Lines changed: 38 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,7 @@ def version(self):
228228

229229
return self._server_version, self._server_revision
230230

231+
@on_http_error(GitlabVerifyError)
231232
def lint(self, content, **kwargs):
232233
"""Validate a gitlab CI configuration.
233234
@@ -244,13 +245,10 @@ def lint(self, content, **kwargs):
244245
otherwise
245246
"""
246247
post_data = {'content': content}
247-
try:
248-
data = self.http_post('/ci/lint', post_data=post_data, **kwargs)
249-
except Exception:
250-
raise GitlabVerifyError
251-
248+
data = self.http_post('/ci/lint', post_data=post_data, **kwargs)
252249
return (data['status'] == 'valid', data['errors'])
253250

251+
@on_http_error(GitlabMarkdownError)
254252
def markdown(self, text, gfm=False, project=None, **kwargs):
255253
"""Render an arbitrary Markdown document.
256254
@@ -272,12 +270,43 @@ def markdown(self, text, gfm=False, project=None, **kwargs):
272270
post_data = {'text': text, 'gfm': gfm}
273271
if project is not None:
274272
post_data['project'] = project
275-
try:
276-
data = self.http_post('/markdown', post_data=post_data, **kwargs)
277-
except Exception:
278-
raise GitlabMarkdownError
273+
data = self.http_post('/markdown', post_data=post_data, **kwargs)
279274
return data['html']
280275

276+
@on_http_error(GitlabLicenseError)
277+
def get_license(self, **kwargs):
278+
"""Retrieve information about the current license.
279+
280+
Args:
281+
**kwargs: Extra options to send to the server (e.g. sudo)
282+
283+
Raises:
284+
GitlabAuthenticationError: If authentication is not correct
285+
GitlabGetError: If the server cannot perform the request
286+
287+
Returns:
288+
dict: The current license information
289+
"""
290+
return self.http_get('/license', **kwargs)
291+
292+
@on_http_error(GitlabLicenseError)
293+
def set_license(self, license, **kwargs):
294+
"""Add a new license.
295+
296+
Args:
297+
license (str): The license string
298+
**kwargs: Extra options to send to the server (e.g. sudo)
299+
300+
Raises:
301+
GitlabAuthenticationError: If authentication is not correct
302+
GitlabPostError: If the server cannot perform the request
303+
304+
Returns:
305+
dict: The new license information
306+
"""
307+
data = {'license': license}
308+
return self.http_post('/license', post_data=data, **kwargs)
309+
281310
def _construct_url(self, id_, obj, parameters, action=None):
282311
if 'next_url' in parameters:
283312
return parameters['next_url']

gitlab/exceptions.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,10 @@ class GitlabRepairError(GitlabOperationError):
221221
pass
222222

223223

224+
class GitlabLicenseError(GitlabOperationError):
225+
pass
226+
227+
224228
def on_http_error(error):
225229
"""Manage GitlabHttpError exceptions.
226230

tools/ee-test.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,3 +111,12 @@ def end_log():
111111
assert(pr.deny_delete_tag == False)
112112
pr.delete()
113113
end_log()
114+
115+
start_log('license')
116+
l = gl.get_license()
117+
assert('user_limit' in l)
118+
try:
119+
gl.set_license('dummykey')
120+
except Exception as e:
121+
assert('The license key is invalid.' in e.error_message)
122+
end_log()

0 commit comments

Comments
 (0)