|
6 | 6 | ]
|
7 | 7 |
|
8 | 8 |
|
| 9 | +from datetime import datetime |
9 | 10 | from typing import Any, List, Optional, Sequence, TypeVar, cast
|
10 | 11 | from warnings import warn
|
11 | 12 |
|
|
30 | 31 | DatabaseDeleteError,
|
31 | 32 | DatabaseListError,
|
32 | 33 | DatabasePropertiesError,
|
| 34 | + DatabaseSupportInfoError, |
33 | 35 | GraphCreateError,
|
34 | 36 | GraphDeleteError,
|
35 | 37 | GraphListError,
|
|
39 | 41 | PermissionListError,
|
40 | 42 | PermissionResetError,
|
41 | 43 | PermissionUpdateError,
|
| 44 | + ServerAvailableOptionsGetError, |
| 45 | + ServerCheckAvailabilityError, |
| 46 | + ServerCurrentOptionsGetError, |
42 | 47 | ServerEncryptionError,
|
43 | 48 | ServerEngineError,
|
| 49 | + ServerLicenseGetError, |
| 50 | + ServerLicenseSetError, |
| 51 | + ServerModeError, |
| 52 | + ServerModeSetError, |
44 | 53 | ServerStatusError,
|
| 54 | + ServerTimeError, |
45 | 55 | ServerTLSError,
|
46 | 56 | ServerTLSReloadError,
|
47 | 57 | ServerVersionError,
|
@@ -2460,6 +2470,227 @@ def response_handler(resp: Response) -> Json:
|
2460 | 2470 |
|
2461 | 2471 | return await self._executor.execute(request, response_handler)
|
2462 | 2472 |
|
| 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 | + |
2463 | 2694 |
|
2464 | 2695 | class StandardDatabase(Database):
|
2465 | 2696 | """Standard database API wrapper.
|
|
0 commit comments