Skip to content

Commit

Permalink
Fix: SDK error when retrieving fallback private key, but the symlink …
Browse files Browse the repository at this point in the history
…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 <desenfans.olivier@gmail.com>
  • Loading branch information
1yam and odesenfans authored Jul 7, 2023
1 parent 8aa9e6f commit b409dd2
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/aleph/sdk/chains/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@

from aleph.sdk.conf import settings

import logging

logger = logging.getLogger(__name__)

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

default_key_path = path.parent / "default.key"

# 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.warning("The symlink to the private key is broken")

# Create a symlink to use this key by default
if not default_key_path.exists():
# Create a symlink to use this key by default
default_key_path.symlink_to(path)
return private_key

0 comments on commit b409dd2

Please sign in to comment.