Skip to content

Commit e5ff4d7

Browse files
authored
[DE-671]: GET + PUT /_api/admin/license (#285)
* initial commit * new: set license test for community
1 parent 371be70 commit e5ff4d7

File tree

3 files changed

+78
-0
lines changed

3 files changed

+78
-0
lines changed

arango/database.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@
4444
ServerEchoError,
4545
ServerEncryptionError,
4646
ServerEngineError,
47+
ServerLicenseGetError,
48+
ServerLicenseSetError,
4749
ServerLogLevelError,
4850
ServerLogLevelSetError,
4951
ServerMetricsError,
@@ -350,6 +352,54 @@ def response_handler(resp: Response) -> Json:
350352

351353
return self._execute(request, response_handler)
352354

355+
def license(self) -> Result[Json]:
356+
"""View the license information and status of an
357+
Enterprise Edition instance. Can be called on
358+
single servers, Coordinators, and DB-Servers.
359+
360+
:return: Server license.
361+
:rtype: dict
362+
:raise arango.exceptions.ServerLicenseGetError: If retrieval fails.
363+
"""
364+
request = Request(method="get", endpoint="/_admin/license")
365+
366+
def response_handler(resp: Response) -> Json:
367+
if resp.is_success:
368+
result: Json = resp.body
369+
return result
370+
raise ServerLicenseGetError(resp, request)
371+
372+
return self._execute(request, response_handler)
373+
374+
def set_license(self, license: str, force: bool = False) -> Result[Json]:
375+
"""Set a new license for an Enterprise Edition
376+
instance. Can be called on single servers, Coordinators,
377+
and DB-Servers.
378+
379+
:param license: The Base64-encoded license string.
380+
:type license: str
381+
:param force: If set to True, the new license will be set even if
382+
it expires sooner than the current license.
383+
:type force: bool
384+
:return: Server license.
385+
:rtype: dict
386+
:raise arango.exceptions.ServerLicenseError: If retrieval fails.
387+
"""
388+
request = Request(
389+
method="put",
390+
endpoint="/_admin/license",
391+
params={"force": force},
392+
data=license,
393+
)
394+
395+
def response_handler(resp: Response) -> Json:
396+
if resp.is_success:
397+
result: Json = resp.body
398+
return result
399+
raise ServerLicenseSetError(resp, request)
400+
401+
return self._execute(request, response_handler)
402+
353403
def status(self) -> Result[Json]:
354404
"""Return ArangoDB server status.
355405

arango/exceptions.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -622,6 +622,14 @@ class ServerDetailsError(ArangoServerError):
622622
"""Failed to retrieve server details."""
623623

624624

625+
class ServerLicenseGetError(ArangoServerError):
626+
"""Failed to retrieve server license."""
627+
628+
629+
class ServerLicenseSetError(ArangoServerError):
630+
"""Failed to set server license."""
631+
632+
625633
class ServerStatusError(ArangoServerError):
626634
"""Failed to retrieve server status."""
627635

tests/test_database.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
ServerDetailsError,
2121
ServerEchoError,
2222
ServerEngineError,
23+
ServerLicenseSetError,
2324
ServerLogLevelError,
2425
ServerLogLevelSetError,
2526
ServerMetricsError,
@@ -333,3 +334,22 @@ def test_database_utf8(sys_db, db_version, special_db_names):
333334
assert sys_db.create_database(name)
334335
assert sys_db.has_database(name)
335336
assert sys_db.delete_database(name)
337+
338+
339+
def test_license(sys_db, enterprise):
340+
license = sys_db.license()
341+
assert isinstance(license, dict)
342+
343+
if enterprise:
344+
assert set(license.keys()) == {
345+
"upgrading",
346+
"features",
347+
"hash",
348+
"license",
349+
"version",
350+
"status",
351+
}
352+
else:
353+
assert license == {"license": "none"}
354+
with pytest.raises(ServerLicenseSetError):
355+
sys_db.set_license("abc")

0 commit comments

Comments
 (0)