|
3 | 3 | from typing import Any, Optional
|
4 | 4 |
|
5 | 5 | from arangoasync.exceptions import (
|
| 6 | + FoxxCommitError, |
6 | 7 | FoxxConfigGetError,
|
7 | 8 | FoxxConfigReplaceError,
|
8 | 9 | FoxxConfigUpdateError,
|
9 | 10 | FoxxDependencyGetError,
|
10 | 11 | FoxxDependencyReplaceError,
|
11 | 12 | FoxxDependencyUpdateError,
|
| 13 | + FoxxDevModeDisableError, |
| 14 | + FoxxDevModeEnableError, |
| 15 | + FoxxDownloadError, |
| 16 | + FoxxReadmeGetError, |
12 | 17 | FoxxScriptListError,
|
13 | 18 | FoxxScriptRunError,
|
14 | 19 | FoxxServiceCreateError,
|
|
17 | 22 | FoxxServiceListError,
|
18 | 23 | FoxxServiceReplaceError,
|
19 | 24 | FoxxServiceUpdateError,
|
| 25 | + FoxxSwaggerGetError, |
20 | 26 | FoxxTestRunError,
|
21 | 27 | )
|
22 | 28 | from arangoasync.executor import ApiExecutor
|
@@ -638,3 +644,186 @@ def response_handler(resp: Response) -> str:
|
638 | 644 | return resp.raw_body.decode("utf-8")
|
639 | 645 |
|
640 | 646 | return await self._executor.execute(request, response_handler)
|
| 647 | + |
| 648 | + async def enable_development(self, mount: str) -> Result[Json]: |
| 649 | + """Puts the service into development mode. |
| 650 | +
|
| 651 | + While the service is running in development mode, it is reloaded from |
| 652 | + the file system, and its setup script (if any) is re-executed every |
| 653 | + time the service handles a request. |
| 654 | +
|
| 655 | + In a cluster with multiple coordinators, changes to the filesystem on |
| 656 | + one coordinator is not reflected across other coordinators. |
| 657 | +
|
| 658 | + Args: |
| 659 | + mount (str): Service mount path. |
| 660 | +
|
| 661 | + Returns: |
| 662 | + dict: Service metadata. |
| 663 | +
|
| 664 | + Raises: |
| 665 | + FoxxDevModeEnableError: If the operation fails. |
| 666 | +
|
| 667 | + References: |
| 668 | + - `enable-the-development-mode <https://docs.arangodb.com/stable/develop/http-api/foxx/#enable-the-development-mode>`__ |
| 669 | + """ # noqa: E501 |
| 670 | + request = Request( |
| 671 | + method=Method.POST, |
| 672 | + endpoint="/_api/foxx/development", |
| 673 | + params={"mount": mount}, |
| 674 | + ) |
| 675 | + |
| 676 | + def response_handler(resp: Response) -> Json: |
| 677 | + if not resp.is_success: |
| 678 | + raise FoxxDevModeEnableError(resp, request) |
| 679 | + result: Json = self.deserializer.loads(resp.raw_body) |
| 680 | + return result |
| 681 | + |
| 682 | + return await self._executor.execute(request, response_handler) |
| 683 | + |
| 684 | + async def disable_development(self, mount: str) -> Result[Json]: |
| 685 | + """Puts the service into production mode. |
| 686 | +
|
| 687 | + In a cluster with multiple coordinators, the services on all other |
| 688 | + coordinators are replaced with the version on the calling coordinator. |
| 689 | +
|
| 690 | + Args: |
| 691 | + mount (str): Service mount path. |
| 692 | +
|
| 693 | + Returns: |
| 694 | + dict: Service metadata. |
| 695 | +
|
| 696 | + Raises: |
| 697 | + FoxxDevModeDisableError: If the operation fails. |
| 698 | +
|
| 699 | + References: |
| 700 | + - `disable-the-development-mode <https://docs.arangodb.com/stable/develop/http-api/foxx/#disable-the-development-mode>`__ |
| 701 | + """ # noqa: E501 |
| 702 | + request = Request( |
| 703 | + method=Method.DELETE, |
| 704 | + endpoint="/_api/foxx/development", |
| 705 | + params={"mount": mount}, |
| 706 | + ) |
| 707 | + |
| 708 | + def response_handler(resp: Response) -> Json: |
| 709 | + if not resp.is_success: |
| 710 | + raise FoxxDevModeDisableError(resp, request) |
| 711 | + result: Json = self.deserializer.loads(resp.raw_body) |
| 712 | + return result |
| 713 | + |
| 714 | + return await self._executor.execute(request, response_handler) |
| 715 | + |
| 716 | + async def readme(self, mount: str) -> Result[str]: |
| 717 | + """Return the service readme. |
| 718 | +
|
| 719 | + Args: |
| 720 | + mount (str): Service mount path. |
| 721 | +
|
| 722 | + Returns: |
| 723 | + str: Service readme content. |
| 724 | +
|
| 725 | + Raises: |
| 726 | + FoxxReadmeGetError: If retrieval fails. |
| 727 | +
|
| 728 | + References: |
| 729 | + - `get-the-service-readme <https://docs.arangodb.com/stable/develop/http-api/foxx/#get-the-service-readme>`__ |
| 730 | + """ # noqa: E501 |
| 731 | + request = Request( |
| 732 | + method=Method.GET, |
| 733 | + endpoint="/_api/foxx/readme", |
| 734 | + params={"mount": mount}, |
| 735 | + ) |
| 736 | + |
| 737 | + def response_handler(resp: Response) -> str: |
| 738 | + if not resp.is_success: |
| 739 | + raise FoxxReadmeGetError(resp, request) |
| 740 | + return resp.raw_body.decode("utf-8") |
| 741 | + |
| 742 | + return await self._executor.execute(request, response_handler) |
| 743 | + |
| 744 | + async def swagger(self, mount: str) -> Result[Json]: |
| 745 | + """Return the Swagger API description for the given service. |
| 746 | +
|
| 747 | + Args: |
| 748 | + mount (str): Service mount path. |
| 749 | +
|
| 750 | + Returns: |
| 751 | + dict: Swagger API description. |
| 752 | +
|
| 753 | + Raises: |
| 754 | + FoxxSwaggerGetError: If retrieval fails. |
| 755 | +
|
| 756 | + References: |
| 757 | + - `get-the-swagger-description <https://docs.arangodb.com/stable/develop/http-api/foxx/#get-the-swagger-description>`__ |
| 758 | + """ # noqa: E501 |
| 759 | + request = Request( |
| 760 | + method=Method.GET, endpoint="/_api/foxx/swagger", params={"mount": mount} |
| 761 | + ) |
| 762 | + |
| 763 | + def response_handler(resp: Response) -> Json: |
| 764 | + if not resp.is_success: |
| 765 | + raise FoxxSwaggerGetError(resp, request) |
| 766 | + result: Json = self.deserializer.loads(resp.raw_body) |
| 767 | + return result |
| 768 | + |
| 769 | + return await self._executor.execute(request, response_handler) |
| 770 | + |
| 771 | + async def download(self, mount: str) -> Result[bytes]: |
| 772 | + """Downloads a zip bundle of the service directory. |
| 773 | +
|
| 774 | + When development mode is enabled, this always creates a new bundle. |
| 775 | + Otherwise, the bundle will represent the version of a service that is |
| 776 | + installed on that ArangoDB instance. |
| 777 | +
|
| 778 | + Args: |
| 779 | + mount (str): Service mount path. |
| 780 | +
|
| 781 | + Returns: |
| 782 | + bytes: Service bundle zip in raw bytes form. |
| 783 | +
|
| 784 | + Raises: |
| 785 | + FoxxDownloadError: If download fails. |
| 786 | +
|
| 787 | + References: |
| 788 | + - `download-a-service-bundle <https://docs.arangodb.com/stable/develop/http-api/foxx/#download-a-service-bundle>`__ |
| 789 | + """ # noqa: E501 |
| 790 | + request = Request( |
| 791 | + method=Method.POST, endpoint="/_api/foxx/download", params={"mount": mount} |
| 792 | + ) |
| 793 | + |
| 794 | + def response_handler(resp: Response) -> bytes: |
| 795 | + if not resp.is_success: |
| 796 | + raise FoxxDownloadError(resp, request) |
| 797 | + return resp.raw_body |
| 798 | + |
| 799 | + return await self._executor.execute(request, response_handler) |
| 800 | + |
| 801 | + async def commit(self, replace: Optional[bool] = None) -> None: |
| 802 | + """Commit local service state of the coordinator to the database. |
| 803 | +
|
| 804 | + This can be used to resolve service conflicts between coordinators |
| 805 | + that cannot be fixed automatically due to missing data. |
| 806 | +
|
| 807 | + Args: |
| 808 | + replace (bool | None): If set to `True`, any existing service files in the database |
| 809 | + will be overwritten. |
| 810 | +
|
| 811 | + Raises: |
| 812 | + FoxxCommitError: If commit fails. |
| 813 | +
|
| 814 | + References: |
| 815 | + - `commit-the-local-service-state <https://docs.arangodb.com/stable/develop/http-api/foxx/#commit-the-local-service-state>`__ |
| 816 | + """ # noqa: E501 |
| 817 | + params: Params = {} |
| 818 | + if replace is not None: |
| 819 | + params["replace"] = replace |
| 820 | + |
| 821 | + request = Request( |
| 822 | + method=Method.POST, endpoint="/_api/foxx/commit", params=params |
| 823 | + ) |
| 824 | + |
| 825 | + def response_handler(resp: Response) -> None: |
| 826 | + if not resp.is_success: |
| 827 | + raise FoxxCommitError(resp, request) |
| 828 | + |
| 829 | + await self._executor.execute(request, response_handler) |
0 commit comments