Skip to content

Commit b409dd2

Browse files
1yamodesenfans
andauthored
Fix: SDK error when retrieving fallback private key, but the symlink was dead. (#33)
Solution: We add a check to determine if it is a symlink and if it is dead. In this case, we unlink it. Co-authored-by: Olivier Desenfans <[email protected]>
1 parent 8aa9e6f commit b409dd2

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/aleph/sdk/chains/common.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77

88
from aleph.sdk.conf import settings
99

10+
import logging
11+
12+
logger = logging.getLogger(__name__)
1013

1114
def get_verification_buffer(message: Dict) -> bytes:
1215
"""
@@ -120,7 +123,13 @@ def get_fallback_private_key(path: Optional[Path] = None) -> bytes:
120123
path.write_bytes(private_key)
121124

122125
default_key_path = path.parent / "default.key"
126+
127+
# If the symlink exists but does not point to a file, delete it.
128+
if default_key_path.is_symlink() and not default_key_path.resolve().exists():
129+
default_key_path.unlink()
130+
logger.warning("The symlink to the private key is broken")
131+
132+
# Create a symlink to use this key by default
123133
if not default_key_path.exists():
124-
# Create a symlink to use this key by default
125134
default_key_path.symlink_to(path)
126135
return private_key

0 commit comments

Comments
 (0)