Skip to content

Commit

Permalink
Merge pull request #16 from Indicio-tech/update/ACA-Py-0.11.0
Browse files Browse the repository at this point in the history
Update to ACA-Py 0.11.0
  • Loading branch information
dbluhm authored Dec 8, 2023
2 parents d48b6f9 + 4d70d32 commit 9d470d2
Show file tree
Hide file tree
Showing 9 changed files with 578 additions and 537 deletions.
50 changes: 21 additions & 29 deletions acapy_cache_redis/v0_1/redis_base_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@
from aries_cloudagent.core.profile import Profile
from aries_cloudagent.core.error import BaseError
from redis.asyncio import RedisCluster
from redis.exceptions import RedisError, RedisClusterException, ResponseError
from redis.exceptions import RedisError, RedisClusterException
from typing import Any, Sequence, Text, Union
from uuid import uuid4

LOGGER = logging.getLogger(__name__)

Expand Down Expand Up @@ -82,33 +81,26 @@ async def check_for_redis_cluster(self):
reassign redis to redis.asyncio.RedisCluster client.
"""
try:
# Execute a redis SET command on a fake test_key prefix with b""
# value. In case, connection string is that of a single redis
# host then it will return None as it doesn't exists. Otherwise,
# it will raise a MOVED error.
fake_test_key = f"test_key_{str(uuid4())}"
await self.redis.set(fake_test_key, b"", ex=1)
except ResponseError as err:
if "MOVED" in str(err):
self.redis = self.root_profile.inject_or(RedisCluster)
if not self.redis:
self.redis = RedisCluster.from_url(
self.connection,
max_connections=self.max_connections,
username=self.username,
password=self.password,
)
# Binds RedisCluster cluster instance, so that it is
# accessible to redis_queue plugin.
LOGGER.info(
"Found redis connection string correspond to a cluster node,"
" reassigning redis to redis.asyncio.RedisCluster client."
)
self.root_profile.injector.bind_instance(RedisCluster, self.redis)
await self.redis.ping(target_nodes=RedisCluster.PRIMARIES)
else:
LOGGER.info("Using an existing provided instance of RedisCluster.")
cluster_info = await self.redis.info("cluster")
if "cluster_enabled" in cluster_info and cluster_info["cluster_enabled"] == 1:
self.redis = self.root_profile.inject_or(RedisCluster)
if not self.redis:
self.redis = RedisCluster.from_url(
self.connection,
max_connections=self.max_connections,
username=self.username,
password=self.password,
)
# Binds RedisCluster cluster instance, so that it is
# accessible to redis_queue plugin.
LOGGER.info(
"Found redis connection string correspond to a cluster node,"
" reassigning redis to redis.asyncio.RedisCluster client."
)
self.root_profile.injector.bind_instance(RedisCluster, self.redis)
await self.redis.ping(target_nodes=RedisCluster.PRIMARIES)
else:
LOGGER.info("Using an existing provided instance of RedisCluster.")

def _getKey(self, key: Text) -> Text:
return f"{self.prefix}:{key}"
Expand Down
60 changes: 30 additions & 30 deletions int/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion int/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "acapy-cache-redis-int-tests"
version = "0.1.0"
description = "Integration tests for ACA-Py Redis Cache Plugin"
authors = ["Colton Wolkins <[email protected]"]
authors = ["Colton Wolkins <[email protected]>", "Kim Ebert <[email protected]>", "Alex Walker <[email protected]>"]

[tool.poetry.dependencies]
python = "^3.9"
Expand Down
6 changes: 2 additions & 4 deletions int/tests/cluster/test_connectivity.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,9 @@ async def test_send_and_receive(echo: EchoClient, connection: ConnectionInfo):
await echo.send_message(
connection,
{
"@type": "did:sov:BzCbsNYhMrjHiqZDTUASHg;spec/trust_ping/1.0/ping",
"@type": "https://didcomm.org/trust_ping/1.0/ping",
"response_resquested": True,
},
)
response = await echo.get_message(connection)
assert response["@type"] == (
"did:sov:BzCbsNYhMrjHiqZDTUASHg;spec/trust_ping/1.0/ping_response"
)
assert response["@type"] == ("https://didcomm.org/trust_ping/1.0/ping_response")
1 change: 0 additions & 1 deletion int/tests/cluster/test_redis.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import json



LOGGER = logging.getLogger(__name__)


Expand Down
6 changes: 2 additions & 4 deletions int/tests/host/test_connectivity.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,9 @@ async def test_send_and_receive(echo: EchoClient, connection: ConnectionInfo):
await echo.send_message(
connection,
{
"@type": "did:sov:BzCbsNYhMrjHiqZDTUASHg;spec/trust_ping/1.0/ping",
"@type": "https://didcomm.org/trust_ping/1.0/ping",
"response_resquested": True,
},
)
response = await echo.get_message(connection)
assert response["@type"] == (
"did:sov:BzCbsNYhMrjHiqZDTUASHg;spec/trust_ping/1.0/ping_response"
)
assert response["@type"] == ("https://didcomm.org/trust_ping/1.0/ping_response")
1 change: 0 additions & 1 deletion int/tests/host/test_redis.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import json



LOGGER = logging.getLogger(__name__)


Expand Down
Loading

0 comments on commit 9d470d2

Please sign in to comment.