fix: refactor and fix the recipient paths parsing that was missing the remote urls

This commit is contained in:
cătălin 2023-05-09 20:29:36 +02:00
commit 2398431a7b
Signed by: catalin
GPG key ID: 0178DF42F43E5FD2
3 changed files with 19 additions and 10 deletions

View file

@ -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/<username>.keys
- https://gitlab.com/<username>.keys

View file

@ -1 +1 @@
__version__ = "0.2.1"
__version__ = "0.3.0"

View file

@ -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]: