Skip to content

Commit e7fa7a9

Browse files
committed
Adding more Administration methods
1 parent d534fc0 commit e7fa7a9

File tree

4 files changed

+337
-0
lines changed

4 files changed

+337
-0
lines changed

arangoasync/database.py

Lines changed: 231 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
]
77

88

9+
from datetime import datetime
910
from typing import Any, List, Optional, Sequence, TypeVar, cast
1011
from warnings import warn
1112

@@ -30,6 +31,7 @@
3031
DatabaseDeleteError,
3132
DatabaseListError,
3233
DatabasePropertiesError,
34+
DatabaseSupportInfoError,
3335
GraphCreateError,
3436
GraphDeleteError,
3537
GraphListError,
@@ -39,9 +41,17 @@
3941
PermissionListError,
4042
PermissionResetError,
4143
PermissionUpdateError,
44+
ServerAvailableOptionsGetError,
45+
ServerCheckAvailabilityError,
46+
ServerCurrentOptionsGetError,
4247
ServerEncryptionError,
4348
ServerEngineError,
49+
ServerLicenseGetError,
50+
ServerLicenseSetError,
51+
ServerModeError,
52+
ServerModeSetError,
4453
ServerStatusError,
54+
ServerTimeError,
4555
ServerTLSError,
4656
ServerTLSReloadError,
4757
ServerVersionError,
@@ -2460,6 +2470,227 @@ def response_handler(resp: Response) -> Json:
24602470

24612471
return await self._executor.execute(request, response_handler)
24622472

2473+
async def time(self) -> Result[datetime]:
2474+
"""Return server system time.
2475+
2476+
Returns:
2477+
datetime.datetime: Server system time.
2478+
2479+
Raises:
2480+
ServerTimeError: If the operation fails.
2481+
2482+
References:
2483+
- `get-the-system-time <https://docs.arangodb.com/stable/develop/http-api/administration/#get-the-system-time>`__
2484+
""" # noqa: E501
2485+
request = Request(method=Method.GET, endpoint="/_admin/time")
2486+
2487+
def response_handler(resp: Response) -> datetime:
2488+
if not resp.is_success:
2489+
raise ServerTimeError(resp, request)
2490+
return datetime.fromtimestamp(
2491+
self.deserializer.loads(resp.raw_body)["time"]
2492+
)
2493+
2494+
return await self._executor.execute(request, response_handler)
2495+
2496+
async def check_availability(self) -> Result[str]:
2497+
"""Return ArangoDB server availability mode.
2498+
2499+
Returns:
2500+
str: Server availability mode, either "readonly" or "default".
2501+
2502+
Raises:
2503+
ServerCheckAvailabilityError: If the operation fails.
2504+
2505+
References:
2506+
- `check-server-availability <https://docs.arangodb.com/stable/develop/http-api/administration/#check-server-availability>`__
2507+
""" # noqa: E501
2508+
request = Request(
2509+
method=Method.GET,
2510+
endpoint="/_admin/server/availability",
2511+
)
2512+
2513+
def response_handler(resp: Response) -> str:
2514+
if not resp.is_success:
2515+
raise ServerCheckAvailabilityError(resp, request)
2516+
result: Json = self.deserializer.loads(resp.raw_body)
2517+
return str(result["mode"])
2518+
2519+
return await self._executor.execute(request, response_handler)
2520+
2521+
async def support_info(self) -> Result[Json]:
2522+
"""Retrieves deployment information for support purposes.
2523+
2524+
Note:
2525+
As this API may reveal sensitive data about the deployment, it can only be accessed from inside the _system database.
2526+
2527+
Returns:
2528+
dict: Deployment information
2529+
2530+
Raises:
2531+
DatabaseSupportInfoError: If the operation fails.
2532+
2533+
References:
2534+
- `get-information-about-the-deployment <https://docs.arangodb.com/stable/develop/http-api/administration/#get-information-about-the-deployment>`__
2535+
""" # noqa: E501
2536+
request = Request(method=Method.GET, endpoint="/_admin/support-info")
2537+
2538+
def response_handler(resp: Response) -> Json:
2539+
if not resp.is_success:
2540+
raise DatabaseSupportInfoError(resp, request)
2541+
2542+
result: Json = self.deserializer.loads(resp.raw_body)
2543+
return result
2544+
2545+
return await self._executor.execute(request, response_handler)
2546+
2547+
async def options(self) -> Result[Json]:
2548+
"""Return the currently-set server options.
2549+
2550+
Returns:
2551+
dict: Server options.
2552+
2553+
Raises:
2554+
ServerCurrentOptionsGetError: If the operation fails.
2555+
2556+
References:
2557+
- `get-the-startup-option-configuration <https://docs.arangodb.com/stable/develop/http-api/administration/#get-the-startup-option-configuration>`__
2558+
""" # noqa: E501
2559+
request = Request(method=Method.GET, endpoint="/_admin/options")
2560+
2561+
def response_handler(resp: Response) -> Json:
2562+
if not resp.is_success:
2563+
raise ServerCurrentOptionsGetError(resp, request)
2564+
result: Json = self.deserializer.loads(resp.raw_body)
2565+
return result
2566+
2567+
return await self._executor.execute(request, response_handler)
2568+
2569+
async def options_available(self) -> Result[Json]:
2570+
"""Return a description of all available server options.
2571+
2572+
Returns:
2573+
dict: Server options description.
2574+
2575+
Raises:
2576+
ServerAvailableOptionsGetError: If the operation fails.
2577+
2578+
References:
2579+
- `get-the-available-startup-options <https://docs.arangodb.com/stable/develop/http-api/administration/#get-the-available-startup-options>`__
2580+
""" # noqa: E501
2581+
request = Request(method=Method.GET, endpoint="/_admin/options-description")
2582+
2583+
def response_handler(resp: Response) -> Json:
2584+
if not resp.is_success:
2585+
raise ServerAvailableOptionsGetError(resp, request)
2586+
result: Json = self.deserializer.loads(resp.raw_body)
2587+
return result
2588+
2589+
return await self._executor.execute(request, response_handler)
2590+
2591+
async def mode(self) -> Result[str]:
2592+
"""Return the server mode ("default" or "readonly").
2593+
2594+
Returns:
2595+
str: Server mode, either "default" or "readonly".
2596+
2597+
Raises:
2598+
ServerModeError: If the operation fails.
2599+
2600+
References:
2601+
- `return-whether-or-not-a-server-is-in-read-only-mode <https://docs.arangodb.com/stable/develop/http-api/administration/#return-whether-or-not-a-server-is-in-read-only-mode>`__
2602+
""" # noqa: E501
2603+
request = Request(method=Method.GET, endpoint="/_admin/server/mode")
2604+
2605+
def response_handler(resp: Response) -> str:
2606+
if not resp.is_success:
2607+
raise ServerModeError(resp, request)
2608+
return str(self.deserializer.loads(resp.raw_body)["mode"])
2609+
2610+
return await self._executor.execute(request, response_handler)
2611+
2612+
async def set_mode(self, mode: str) -> Result[str]:
2613+
"""Set the server mode to read-only or default.
2614+
2615+
Args:
2616+
mode (str): Server mode. Possible values are "default" or "readonly".
2617+
2618+
Returns:
2619+
str: New server mode.
2620+
2621+
Raises:
2622+
ServerModeSetError: If the operation fails.
2623+
2624+
References:
2625+
- `set-the-server-mode-to-read-only-or-default <https://docs.arangodb.com/stable/develop/http-api/administration/#set-the-server-mode-to-read-only-or-default>`__
2626+
""" # noqa: E501
2627+
request = Request(
2628+
method=Method.PUT,
2629+
endpoint="/_admin/server/mode",
2630+
data=self.serializer.dumps({"mode": mode}),
2631+
)
2632+
2633+
def response_handler(resp: Response) -> str:
2634+
if not resp.is_success:
2635+
raise ServerModeSetError(resp, request)
2636+
result: Json = self.deserializer.loads(resp.raw_body)
2637+
return str(result["mode"])
2638+
2639+
return await self._executor.execute(request, response_handler)
2640+
2641+
async def license(self) -> Result[Json]:
2642+
"""View the license information and status of an Enterprise Edition instance.
2643+
2644+
Returns:
2645+
dict: Server license information.
2646+
2647+
Raises:
2648+
ServerLicenseGetError: If the operation fails.
2649+
2650+
References:
2651+
- `get-information-about-the-current-license <https://docs.arangodb.com/stable/develop/http-api/administration/#get-information-about-the-current-license>`__
2652+
""" # noqa: E501
2653+
request = Request(method=Method.GET, endpoint="/_admin/license")
2654+
2655+
def response_handler(resp: Response) -> Json:
2656+
if not resp.is_success:
2657+
raise ServerLicenseGetError(resp, request)
2658+
result: Json = self.deserializer.loads(resp.raw_body)
2659+
return result
2660+
2661+
return await self._executor.execute(request, response_handler)
2662+
2663+
async def set_license(self, license: str, force: Optional[bool] = False) -> None:
2664+
"""Set a new license for an Enterprise Edition instance.
2665+
2666+
Args:
2667+
license (str) -> Base64-encoded license string, wrapped in double-quotes.
2668+
force (bool | None) -> Set to `True` to change the license even if it
2669+
expires sooner than the current one.
2670+
2671+
Raises:
2672+
ServerLicenseSetError: If the operation fails.
2673+
2674+
References:
2675+
- `set-a-new-license <https://docs.arangodb.com/stable/develop/http-api/administration/#set-a-new-license>`__
2676+
""" # noqa: E501
2677+
params: Params = {}
2678+
if force is not None:
2679+
params["force"] = force
2680+
2681+
request = Request(
2682+
method=Method.PUT,
2683+
endpoint="/_admin/license",
2684+
params=params,
2685+
data=license,
2686+
)
2687+
2688+
def response_handler(resp: Response) -> None:
2689+
if not resp.is_success:
2690+
raise ServerLicenseSetError(resp, request)
2691+
2692+
await self._executor.execute(request, response_handler)
2693+
24632694

24642695
class StandardDatabase(Database):
24652696
"""Standard database API wrapper.

arangoasync/exceptions.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,10 @@ class DatabasePropertiesError(ArangoServerError):
335335
"""Failed to retrieve database properties."""
336336

337337

338+
class DatabaseSupportInfoError(ArangoServerError):
339+
"""Failed to retrieve support info for deployment."""
340+
341+
338342
class DeserializationError(ArangoClientError):
339343
"""Failed to deserialize the server response."""
340344

@@ -547,10 +551,22 @@ class SerializationError(ArangoClientError):
547551
"""Failed to serialize the request."""
548552

549553

554+
class ServerAvailableOptionsGetError(ArangoServerError):
555+
"""Failed to retrieve available server options."""
556+
557+
558+
class ServerCheckAvailabilityError(ArangoServerError):
559+
"""Failed to retrieve server availability mode."""
560+
561+
550562
class ServerConnectionError(ArangoServerError):
551563
"""Failed to connect to ArangoDB server."""
552564

553565

566+
class ServerCurrentOptionsGetError(ArangoServerError):
567+
"""Failed to retrieve currently-set server options."""
568+
569+
554570
class ServerEncryptionError(ArangoServerError):
555571
"""Failed to reload user-defined encryption keys."""
556572

@@ -559,6 +575,22 @@ class ServerEngineError(ArangoServerError):
559575
"""Failed to retrieve database engine."""
560576

561577

578+
class ServerModeError(ArangoServerError):
579+
"""Failed to retrieve server mode."""
580+
581+
582+
class ServerModeSetError(ArangoServerError):
583+
"""Failed to set server mode."""
584+
585+
586+
class ServerLicenseGetError(ArangoServerError):
587+
"""Failed to retrieve server license."""
588+
589+
590+
class ServerLicenseSetError(ArangoServerError):
591+
"""Failed to set server license."""
592+
593+
562594
class ServerStatusError(ArangoServerError):
563595
"""Failed to retrieve server status."""
564596

@@ -571,6 +603,10 @@ class ServerTLSReloadError(ArangoServerError):
571603
"""Failed to reload TLS."""
572604

573605

606+
class ServerTimeError(ArangoServerError):
607+
"""Failed to retrieve server system time."""
608+
609+
574610
class ServerVersionError(ArangoServerError):
575611
"""Failed to retrieve server version."""
576612

docs/admin.rst

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,21 @@ Most of these operations can only be performed by admin users via the
2121
2222
# Retrieve the database engine.
2323
await sys_db.engine()
24+
25+
# Retrieve the server time..
26+
time = await sys_db.time()
27+
28+
# Check server availability
29+
availability = sys_db.check_availability()
30+
31+
# Support info
32+
info = sys_db.support_info()
33+
34+
# Get the startup option configuration
35+
options = await sys_db.options()
36+
37+
# Get the available startup options
38+
options = await sys_db.options_available()
39+
40+
# Return whether or not a server is in read-only mode
41+
mode = await sys_db.mode()

0 commit comments

Comments
 (0)