Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DE-671]: GET + PUT /_api/admin/license #285

Merged
merged 2 commits into from
Sep 15, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions arango/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@
ServerEchoError,
ServerEncryptionError,
ServerEngineError,
ServerLicenseGetError,
ServerLicenseSetError,
ServerLogLevelError,
ServerLogLevelSetError,
ServerMetricsError,
Expand Down Expand Up @@ -348,6 +350,54 @@ def response_handler(resp: Response) -> Json:

return self._execute(request, response_handler)

def license(self) -> Result[Json]:
"""View the license information and status of an
Enterprise Edition instance. Can be called on
single servers, Coordinators, and DB-Servers.

:return: Server license.
:rtype: dict
:raise arango.exceptions.ServerLicenseGetError: If retrieval fails.
"""
request = Request(method="get", endpoint="/_admin/license")

def response_handler(resp: Response) -> Json:
if resp.is_success:
result: Json = resp.body
return result
raise ServerLicenseGetError(resp, request)

return self._execute(request, response_handler)

def set_license(self, license: str, force: bool = False) -> Result[Json]:
"""Set a new license for an Enterprise Edition
instance. Can be called on single servers, Coordinators,
and DB-Servers.

:param license: The Base64-encoded license string.
:type license: str
:param force: If set to True, the new license will be set even if
it expires sooner than the current license.
:type force: bool
:return: Server license.
:rtype: dict
:raise arango.exceptions.ServerLicenseError: If retrieval fails.
"""
request = Request(
method="put",
endpoint="/_admin/license",
params={"force": force},
data=license,
)

def response_handler(resp: Response) -> Json:
if resp.is_success:
result: Json = resp.body
return result
raise ServerLicenseSetError(resp, request)

return self._execute(request, response_handler)

def status(self) -> Result[Json]:
"""Return ArangoDB server status.

Expand Down
8 changes: 8 additions & 0 deletions arango/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -614,6 +614,14 @@ class ServerDetailsError(ArangoServerError):
"""Failed to retrieve server details."""


class ServerLicenseGetError(ArangoServerError):
"""Failed to retrieve server license."""


class ServerLicenseSetError(ArangoServerError):
"""Failed to set server license."""


class ServerStatusError(ArangoServerError):
"""Failed to retrieve server status."""

Expand Down
17 changes: 17 additions & 0 deletions tests/test_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,3 +319,20 @@ def test_database_utf8(sys_db, db_version, special_db_names):
assert sys_db.create_database(name)
assert sys_db.has_database(name)
assert sys_db.delete_database(name)


def test_license(sys_db, db, enterprise):
aMahanna marked this conversation as resolved.
Show resolved Hide resolved
license = sys_db.license()
assert isinstance(license, dict)

if enterprise:
assert set(license.keys()) == {
"upgrading",
"features",
"hash",
"license",
"version",
"status",
}
else:
assert license == {"license": "none"}