Skip to content

Commit 9cf9e58

Browse files
committed
initial commit
1 parent fda5a41 commit 9cf9e58

File tree

3 files changed

+75
-0
lines changed

3 files changed

+75
-0
lines changed

arango/database.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@
4343
ServerEchoError,
4444
ServerEncryptionError,
4545
ServerEngineError,
46+
ServerLicenseGetError,
47+
ServerLicenseSetError,
4648
ServerLogLevelError,
4749
ServerLogLevelSetError,
4850
ServerMetricsError,
@@ -348,6 +350,54 @@ def response_handler(resp: Response) -> Json:
348350

349351
return self._execute(request, response_handler)
350352

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

arango/exceptions.py

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

616616

617+
class ServerLicenseGetError(ArangoServerError):
618+
"""Failed to retrieve server license."""
619+
620+
621+
class ServerLicenseSetError(ArangoServerError):
622+
"""Failed to set server license."""
623+
624+
617625
class ServerStatusError(ArangoServerError):
618626
"""Failed to retrieve server status."""
619627

tests/test_database.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,3 +319,20 @@ def test_database_utf8(sys_db, db_version, special_db_names):
319319
assert sys_db.create_database(name)
320320
assert sys_db.has_database(name)
321321
assert sys_db.delete_database(name)
322+
323+
324+
def test_license(sys_db, db, enterprise):
325+
license = sys_db.license()
326+
assert isinstance(license, dict)
327+
328+
if enterprise:
329+
assert set(license.keys()) == {
330+
"upgrading",
331+
"features",
332+
"hash",
333+
"license",
334+
"version",
335+
"status",
336+
}
337+
else:
338+
assert license == {"license": "none"}

0 commit comments

Comments
 (0)