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

Appearance settings

Commit 5183069

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

File tree

Expand file treeCollapse file tree

3 files changed

+51
-9
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

3 files changed

+51
-9
lines changed
Open diff view settings
Collapse file

‎gitlab/__init__.py‎

Copy file name to clipboardExpand all lines: gitlab/__init__.py
+38-9Lines 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']
Collapse file

‎gitlab/exceptions.py‎

Copy file name to clipboardExpand all lines: gitlab/exceptions.py
+4Lines 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
Collapse file

‎tools/ee-test.py‎

Copy file name to clipboardExpand all lines: tools/ee-test.py
+9Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.