Skip to content

Commit 7b8dbf5

Browse files
committed
DE-741 | initial commit
1 parent 99f5d9b commit 7b8dbf5

File tree

3 files changed

+71
-0
lines changed

3 files changed

+71
-0
lines changed

arango/database.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@
4040
PermissionListError,
4141
PermissionResetError,
4242
PermissionUpdateError,
43+
ServerAvailableOptionsGetError,
44+
ServerCurrentOptionsGetError,
4345
ServerDetailsError,
4446
ServerEchoError,
4547
ServerEncryptionError,
@@ -933,6 +935,58 @@ def response_handler(resp: Response) -> Json:
933935

934936
return self._execute(request, response_handler)
935937

938+
def options(self) -> Result[Json]:
939+
"""Return the currently-set server options.
940+
941+
As this API may reveal sensitive data about the deployment, it can only
942+
be accessed from inside the _system database. In addition, there is a
943+
policy control startup option --server.options-api that determines if and
944+
to whom the API is made available. This option can have the following
945+
values:
946+
- disabled: API is disabled.
947+
- jwt: API can only be accessed via superuser JWT.
948+
- admin: API can be accessed by admin users in the _system database only.
949+
- public: everyone with access to _system database can access the API.
950+
951+
:return: Server options.
952+
:rtype: dict
953+
"""
954+
request = Request(method="get", endpoint="/_admin/options")
955+
956+
def response_handler(resp: Response) -> Json:
957+
if resp.is_success:
958+
result: Json = resp.body
959+
return result
960+
raise ServerCurrentOptionsGetError(resp, request)
961+
962+
return self._execute(request, response_handler)
963+
964+
def options_available(self) -> Result[Json]:
965+
"""Return a description of all available server options.
966+
967+
As this API may reveal sensitive data about the deployment, it can only
968+
be accessed from inside the _system database. In addition, there is a
969+
policy control startup option --server.options-api that determines if and
970+
to whom the API is made available. This option can have the following
971+
values:
972+
- disabled: API is disabled.
973+
- jwt: API can only be accessed via superuser JWT.
974+
- admin: API can be accessed by admin users in the _system database only.
975+
- public: everyone with access to _system database can access the options API.
976+
977+
:return: Server options.
978+
:rtype: dict
979+
"""
980+
request = Request(method="get", endpoint="/_admin/options-description")
981+
982+
def response_handler(resp: Response) -> Json:
983+
if resp.is_success:
984+
result: Json = resp.body
985+
return result
986+
raise ServerAvailableOptionsGetError(resp, request)
987+
988+
return self._execute(request, response_handler)
989+
936990
#######################
937991
# Database Management #
938992
#######################

arango/exceptions.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -698,6 +698,14 @@ class ServerEncryptionError(ArangoServerError):
698698
"""Failed to reload user-defined encryption keys."""
699699

700700

701+
class ServerCurrentOptionsGetError(ArangoServerError):
702+
"""Failed to retrieve currently-set server options."""
703+
704+
705+
class ServerAvailableOptionsGetError(ArangoServerError):
706+
"""Failed to retrieve available server options."""
707+
708+
701709
#####################
702710
# Task Exceptions #
703711
#####################

tests/test_database.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,3 +373,12 @@ def test_license(sys_db, enterprise):
373373
assert license == {"license": "none"}
374374
with pytest.raises(ServerLicenseSetError):
375375
sys_db.set_license("abc")
376+
377+
378+
def test_options(sys_db, db_version):
379+
# Skip if below 3.12
380+
if db_version < version.parse("3.12.0"):
381+
pytest.skip("Database options require ArangoDB 3.12+")
382+
383+
assert sys_db.options()
384+
assert sys_db.options_available()

0 commit comments

Comments
 (0)