Skip to content

Commit

Permalink
Merge branch 'main' into DE-741
Browse files Browse the repository at this point in the history
  • Loading branch information
aMahanna committed Apr 22, 2024
2 parents 85e1266 + d5d867c commit c42c54d
Show file tree
Hide file tree
Showing 40 changed files with 1,204 additions and 164 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ workflows:
python_version: ["3.8", "3.9", "3.10", "3.11"] # "3.12"
arangodb_config: ["single", "cluster"]
arangodb_license: ["community", "enterprise"]
arangodb_version: ["3.10.10", "3.11.4", "latest"]
arangodb_version: ["3.11", "latest"]

jobs:
lint:
Expand Down
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
![Logo](https://user-images.githubusercontent.com/2701938/108583516-c3576680-72ee-11eb-883f-2d9b52e74e45.png)

[![CircleCI](https://dl.circleci.com/status-badge/img/gh/ArangoDB-Community/python-arango/tree/main.svg?style=svg)](https://dl.circleci.com/status-badge/redirect/gh/ArangoDB-Community/python-arango/tree/main)
[![CodeQL](https://github.com/ArangoDB-Community/python-arango/actions/workflows/codeql.yaml/badge.svg)](https://github.com/ArangoDB-Community/python-arango/actions/workflows/codeql.yaml)
[![Docs](https://github.com/ArangoDB-Community/python-arango/actions/workflows/docs.yaml/badge.svg)](https://github.com/ArangoDB-Community/python-arango/actions/workflows/docs.yaml)
[![Coverage Status](https://codecov.io/gh/ArangoDB-Community/python-arango/branch/main/graph/badge.svg?token=M8zrjrzsUY)](https://codecov.io/gh/ArangoDB-Community/python-arango)
[![Last commit](https://img.shields.io/github/last-commit/ArangoDB-Community/python-arango)](https://github.com/ArangoDB-Community/python-arango/commits/master)
[![CircleCI](https://dl.circleci.com/status-badge/img/gh/arangodb/python-arango/tree/main.svg?style=svg)](https://dl.circleci.com/status-badge/redirect/gh/arangodb/python-arango/tree/main)
[![CodeQL](https://github.com/arangodb/python-arango/actions/workflows/codeql.yaml/badge.svg)](https://github.com/arangodb/python-arango/actions/workflows/codeql.yaml)
[![Docs](https://github.com/arangodb/python-arango/actions/workflows/docs.yaml/badge.svg)](https://github.com/arangodb/python-arango/actions/workflows/docs.yaml)
[![Coverage Status](https://codecov.io/gh/arangodb/python-arango/branch/main/graph/badge.svg?token=M8zrjrzsUY)](https://codecov.io/gh/arangodb/python-arango)
[![Last commit](https://img.shields.io/github/last-commit/arangodb/python-arango)](https://github.com/arangodb/python-arango/commits/master)

[![PyPI version badge](https://img.shields.io/pypi/v/python-arango?color=3775A9&style=for-the-badge&logo=pypi&logoColor=FFD43B)](https://pypi.org/project/python-arango/)
[![Python versions badge](https://img.shields.io/badge/3.8%2B-3776AB?style=for-the-badge&logo=python&logoColor=FFD43B&label=Python)](https://pypi.org/project/python-arango/)

[![License](https://img.shields.io/github/license/ArangoDB-Community/python-arango?color=9E2165&style=for-the-badge)](https://github.com/ArangoDB-Community/python-arango/blob/master/LICENSE)
[![License](https://img.shields.io/github/license/arangodb/python-arango?color=9E2165&style=for-the-badge)](https://github.com/arangodb/python-arango/blob/master/LICENSE)
[![Code style: black](https://img.shields.io/static/v1?style=for-the-badge&label=code%20style&message=black&color=black)](https://github.com/psf/black)
[![Downloads](https://img.shields.io/pepy/dt/python-arango?style=for-the-badge&color=282661
)](https://pepy.tech/project/python-arango)
Expand All @@ -21,7 +21,7 @@ database natively supporting documents, graphs and search.

## Requirements

- ArangoDB version 3.9+
- ArangoDB version 3.11+
- Python version 3.8+

## Installation
Expand Down
28 changes: 26 additions & 2 deletions arango/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@
)
from arango.database import StandardDatabase
from arango.exceptions import ServerConnectionError
from arango.http import DEFAULT_REQUEST_TIMEOUT, DefaultHTTPClient, HTTPClient
from arango.http import (
DEFAULT_REQUEST_TIMEOUT,
DefaultHTTPClient,
HTTPClient,
RequestCompression,
)
from arango.resolver import (
FallbackHostResolver,
HostResolver,
Expand All @@ -33,7 +38,7 @@ def default_serializer(x: Any) -> str:
:return: The object serialized as a JSON string
:rtype: str
"""
return dumps(x)
return dumps(x, separators=(",", ":"))


def default_deserializer(x: str) -> Any:
Expand Down Expand Up @@ -85,6 +90,12 @@ class ArangoClient:
None: No timeout.
int: Timeout value in seconds.
:type request_timeout: int | float
:param request_compression: Will compress requests to the server according to
the given algorithm. No compression happens by default.
:type request_compression: arango.http.RequestCompression | None
:param response_compression: Tells the server what compression algorithm is
acceptable for the response. No compression happens by default.
:type response_compression: str | None
"""

def __init__(
Expand All @@ -97,6 +108,8 @@ def __init__(
deserializer: Callable[[str], Any] = default_deserializer,
verify_override: Union[bool, str, None] = None,
request_timeout: Union[int, float, None] = DEFAULT_REQUEST_TIMEOUT,
request_compression: Optional[RequestCompression] = None,
response_compression: Optional[str] = None,
) -> None:
if isinstance(hosts, str):
self._hosts = [host.strip("/") for host in hosts.split(",")]
Expand Down Expand Up @@ -133,6 +146,9 @@ def __init__(
for session in self._sessions:
session.verify = verify_override

self._request_compression = request_compression
self._response_compression = response_compression

def __repr__(self) -> str:
return f"<ArangoClient {','.join(self._hosts)}>"

Expand Down Expand Up @@ -231,6 +247,8 @@ def db(
serializer=self._serializer,
deserializer=self._deserializer,
superuser_token=superuser_token,
request_compression=self._request_compression,
response_compression=self._response_compression,
)
elif user_token is not None:
connection = JwtConnection(
Expand All @@ -242,6 +260,8 @@ def db(
serializer=self._serializer,
deserializer=self._deserializer,
user_token=user_token,
request_compression=self._request_compression,
response_compression=self._response_compression,
)
elif auth_method.lower() == "basic":
connection = BasicConnection(
Expand All @@ -254,6 +274,8 @@ def db(
http_client=self._http,
serializer=self._serializer,
deserializer=self._deserializer,
request_compression=self._request_compression,
response_compression=self._response_compression,
)
elif auth_method.lower() == "jwt":
connection = JwtConnection(
Expand All @@ -266,6 +288,8 @@ def db(
http_client=self._http,
serializer=self._serializer,
deserializer=self._deserializer,
request_compression=self._request_compression,
response_compression=self._response_compression,
)
else:
raise ValueError(f"invalid auth_method: {auth_method}")
Expand Down
74 changes: 74 additions & 0 deletions arango/cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
ClusterServerCountError,
ClusterServerEngineError,
ClusterServerIDError,
ClusterServerModeError,
ClusterServerRoleError,
ClusterServerStatisticsError,
ClusterServerVersionError,
Expand Down Expand Up @@ -57,6 +58,27 @@ def response_handler(resp: Response) -> str:

return self._execute(request, response_handler)

def server_mode(self) -> Result[str]:
"""Return the server mode.
In a read-only server, all write operations will fail
with an error code of 1004 (ERROR_READ_ONLY). Creating or dropping
databases and collections will also fail with error code 11 (ERROR_FORBIDDEN).
:return: Server mode. Possible values are "default" or "readonly".
:rtype: str
:raise arango.exceptions.ClusterServerModeError: If retrieval fails.
"""
request = Request(method="get", endpoint="/_admin/server/mode")

def response_handler(resp: Response) -> str:
if resp.is_success:
return str(resp.body["mode"])

raise ClusterServerModeError(resp, request)

return self._execute(request, response_handler)

def server_version(self, server_id: str) -> Result[Json]:
"""Return the version of the given server.
Expand Down Expand Up @@ -140,6 +162,58 @@ def response_handler(resp: Response) -> Json:

return self._execute(request, response_handler)

def server_maintenance_mode(self, server_id: str) -> Result[Json]:
"""Return the maintenance status for the given server.
:param server_id: Server ID.
:type server_id: str
:return: Maintenance status for the given server.
:rtype: dict
:raise arango.exceptions.ClusterMaintenanceModeError: If retrieval fails.
"""
request = Request(
method="get",
endpoint=f"/_admin/cluster/maintenance/{server_id}",
)

def response_handler(resp: Response) -> Json:
if resp.is_success:
result: Json = resp.body.get("result", {})
return result

raise ClusterMaintenanceModeError(resp, request)

return self._execute(request, response_handler)

def toggle_server_maintenance_mode(
self, server_id: str, mode: str, timeout: Optional[int] = None
) -> Result[Json]:
"""Enable or disable the maintenance mode for the given server.
:param server_id: Server ID.
:type server_id: str
:param mode: Maintenance mode. Allowed values are "normal" and "maintenance".
:type mode: str
:param timeout: Timeout in seconds.
:type timeout: Optional[int]
:return: Result of the operation.
:rtype: dict
:raise arango.exceptions.ClusterMaintenanceModeError: If toggle fails.
"""
request = Request(
method="put",
endpoint=f"/_admin/cluster/maintenance/{server_id}",
data={"mode": mode, "timeout": timeout},
)

def response_handler(resp: Response) -> Json:
if resp.is_success:
return format_body(resp.body)

raise ClusterMaintenanceModeError(resp, request)

return self._execute(request, response_handler)

def health(self) -> Result[Json]:
"""Return the cluster health.
Expand Down
Loading

0 comments on commit c42c54d

Please sign in to comment.