From 2398431a7ba6a15e9f57090f9a8ea4d27fdc832f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?c=C4=83t=C4=83lin?= Date: Tue, 9 May 2023 20:29:36 +0200 Subject: [PATCH] fix: refactor and fix the recipient paths parsing that was missing the remote urls --- README.md | 2 +- halig/__version__.py | 2 +- halig/settings.py | 25 +++++++++++++++++-------- 3 files changed, 19 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 3b0adc2..9e8f9b8 100644 --- a/README.md +++ b/README.md @@ -37,7 +37,7 @@ cat << EOF > "${XDG_CONFIG_HOME:-$HOME/.config}/halig/halig.yml" notebooks_root_path: ~/Documents/Notebooks identity_paths: - ~/.ssh/id_ed25519 -recipient_path: +recipient_paths: - ~/.ssh/id_ed25519.pub - https://github.com/.keys - https://gitlab.com/.keys diff --git a/halig/__version__.py b/halig/__version__.py index 3ced358..493f741 100644 --- a/halig/__version__.py +++ b/halig/__version__.py @@ -1 +1 @@ -__version__ = "0.2.1" +__version__ = "0.3.0" diff --git a/halig/settings.py b/halig/settings.py index 062493c..40f10c1 100644 --- a/halig/settings.py +++ b/halig/settings.py @@ -1,6 +1,7 @@ import os from functools import lru_cache from pathlib import Path +from typing import Any import httpx import yaml @@ -29,17 +30,25 @@ class Settings(BaseSettings): ] @validator("identity_paths", "recipient_paths", pre=True) - def validate_paths(cls, v: list[str]): # noqa: N805 + def validate_paths(cls, v: Any): # noqa: N805 + if not isinstance(v, list): + v = [v] new_v = [] for path in v: - if isinstance(path, str): - if not path.startswith("http"): - new_v.append(Path(path).expanduser()) - elif isinstance(path, Path): - new_v.append(path.expanduser()) - else: - new_v.append(path) + new_path = path + if isinstance(path, str) and not path.startswith("http"): + new_path = Path(path) + new_v.append( + new_path.expanduser() if isinstance(new_path, Path) else new_path, + ) + return new_v + @validator("notebooks_root_path", pre=True) + def validate_notebooks_path(cls, v: Any): # noqa: N805 + if isinstance(v, str): + return Path(v).expanduser() + if isinstance(v, Path): + return v.expanduser() return v def load_private_keys(self) -> set[str]: