From be0588a389e31904f3061a2ae7b43792ad1fb07d Mon Sep 17 00:00:00 2001 From: 1yam Date: Wed, 5 Jul 2023 12:23:59 +0200 Subject: [PATCH 1/6] Fix: SDK error when retrieving fallback private key, but the symlink was dead. Solution: We add a check to determine if it is a symlink and if it is dead. In this case, we unlink it. --- src/aleph/sdk/chains/common.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/aleph/sdk/chains/common.py b/src/aleph/sdk/chains/common.py index 298f9d94..8549e844 100644 --- a/src/aleph/sdk/chains/common.py +++ b/src/aleph/sdk/chains/common.py @@ -120,7 +120,11 @@ def get_fallback_private_key(path: Optional[Path] = None) -> bytes: path.write_bytes(private_key) default_key_path = path.parent / "default.key" + + # We check if the symlink exist but dead to remove it + if default_key_path.is_symlink() and not default_key_path.resolve().exists(): + default_key_path.unlink() + + # We create the symlink if symlink not exist if not default_key_path.exists(): - # Create a symlink to use this key by default default_key_path.symlink_to(path) - return private_key From f595de306400531f38bd139df65631f633a5b50d Mon Sep 17 00:00:00 2001 From: 1yam Date: Wed, 5 Jul 2023 12:43:05 +0200 Subject: [PATCH 2/6] Fix : return private key --- src/aleph/sdk/chains/common.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/aleph/sdk/chains/common.py b/src/aleph/sdk/chains/common.py index 8549e844..36f23be4 100644 --- a/src/aleph/sdk/chains/common.py +++ b/src/aleph/sdk/chains/common.py @@ -128,3 +128,4 @@ def get_fallback_private_key(path: Optional[Path] = None) -> bytes: # We create the symlink if symlink not exist if not default_key_path.exists(): default_key_path.symlink_to(path) + return private_key From 4fd701a7f4709bf78f430c974977eb0d275aec9c Mon Sep 17 00:00:00 2001 From: 1yam <40899431+1yam@users.noreply.github.com> Date: Wed, 5 Jul 2023 14:19:58 +0200 Subject: [PATCH 3/6] Update src/aleph/sdk/chains/common.py Co-authored-by: Olivier Desenfans --- src/aleph/sdk/chains/common.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/aleph/sdk/chains/common.py b/src/aleph/sdk/chains/common.py index 36f23be4..1bb31a4a 100644 --- a/src/aleph/sdk/chains/common.py +++ b/src/aleph/sdk/chains/common.py @@ -121,7 +121,7 @@ def get_fallback_private_key(path: Optional[Path] = None) -> bytes: default_key_path = path.parent / "default.key" - # We check if the symlink exist but dead to remove it + # If the symlink exists but does not point to a file, delete it. if default_key_path.is_symlink() and not default_key_path.resolve().exists(): default_key_path.unlink() From fd78ec3edfab4fdff16dbcd96cdc0fdd99449864 Mon Sep 17 00:00:00 2001 From: 1yam <40899431+1yam@users.noreply.github.com> Date: Wed, 5 Jul 2023 14:20:28 +0200 Subject: [PATCH 4/6] Update src/aleph/sdk/chains/common.py Co-authored-by: Olivier Desenfans --- src/aleph/sdk/chains/common.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/aleph/sdk/chains/common.py b/src/aleph/sdk/chains/common.py index 1bb31a4a..9b1f227a 100644 --- a/src/aleph/sdk/chains/common.py +++ b/src/aleph/sdk/chains/common.py @@ -125,7 +125,7 @@ def get_fallback_private_key(path: Optional[Path] = None) -> bytes: if default_key_path.is_symlink() and not default_key_path.resolve().exists(): default_key_path.unlink() - # We create the symlink if symlink not exist + # Create a symlink to use this key by default if not default_key_path.exists(): default_key_path.symlink_to(path) return private_key From a418aafd1ce416199721d3d5e43627b9fe62414b Mon Sep 17 00:00:00 2001 From: 1yam Date: Thu, 6 Jul 2023 11:11:09 +0200 Subject: [PATCH 5/6] Fix: add logger warning --- src/aleph/sdk/chains/common.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/aleph/sdk/chains/common.py b/src/aleph/sdk/chains/common.py index 9b1f227a..6d9b8efe 100644 --- a/src/aleph/sdk/chains/common.py +++ b/src/aleph/sdk/chains/common.py @@ -7,6 +7,9 @@ from aleph.sdk.conf import settings +import logging + +logger = logging.getLogger(__name__) def get_verification_buffer(message: Dict) -> bytes: """ @@ -124,8 +127,10 @@ def get_fallback_private_key(path: Optional[Path] = None) -> bytes: # If the symlink exists but does not point to a file, delete it. if default_key_path.is_symlink() and not default_key_path.resolve().exists(): default_key_path.unlink() + logger.debug("Removed dead symlink") # Create a symlink to use this key by default if not default_key_path.exists(): default_key_path.symlink_to(path) + logger.debug("Create symlink") return private_key From 76ce7f4ee7940cde22fc9f4b2eb6e9a9854c423c Mon Sep 17 00:00:00 2001 From: 1yam Date: Thu, 6 Jul 2023 16:27:12 +0200 Subject: [PATCH 6/6] Fix: logger should be a warning and not debug --- src/aleph/sdk/chains/common.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/aleph/sdk/chains/common.py b/src/aleph/sdk/chains/common.py index 6d9b8efe..9deda62d 100644 --- a/src/aleph/sdk/chains/common.py +++ b/src/aleph/sdk/chains/common.py @@ -127,10 +127,9 @@ def get_fallback_private_key(path: Optional[Path] = None) -> bytes: # If the symlink exists but does not point to a file, delete it. if default_key_path.is_symlink() and not default_key_path.resolve().exists(): default_key_path.unlink() - logger.debug("Removed dead symlink") + logger.warning("The symlink to the private key is broken") # Create a symlink to use this key by default if not default_key_path.exists(): default_key_path.symlink_to(path) - logger.debug("Create symlink") return private_key