INNER CODE UNIT · Python
_read_json
onedr0p/cluster-template · template/scripts/plugin.py:23
def _read_json(file_path: str) -> dict[str, Any]:
try:
return json.loads(_read_stripped(file_path))
except json.JSONDecodeError:
raise ValueError(f"Could not decode JSON file: {file_path}") from None
# Return the age public or private key from age.key
def age_key(key_type: str, file_path: str = 'age.key') -> str:
file_content = _read_stripped(file_path)
if key_type == 'public':
# Matches both classic (age1...) and post-quantum (age1pq1...) recipients
key_match = re.search(r"# public key: (age1[\w]+)", file_content)
if not key_match:
raise ValueError("Could not find public key in the age key file.")
return key_match.group(1)
elif key_type == 'private':
# (?:PQ-)? matches post-quantum identities (AGE-SECRET-KEY-PQ-1...) as well as classic ones