From 4fb1fff521d3ebd0dba425cb49cc5ddba163b35d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?c=C4=83t=C4=83lin?= Date: Wed, 29 Nov 2023 18:15:34 +0100 Subject: [PATCH] feat: add `remote_public_keys_timeout` option in order to set the time after which the retrieval of external public keys should be interrupted --- halig/__version__.py | 2 +- halig/settings.py | 9 +++++++-- tests/commands/test_edit.py | 3 ++- tests/commands/test_import.py | 4 +++- tests/commands/test_show.py | 3 ++- tests/test_encryption.py | 2 +- 6 files changed, 16 insertions(+), 7 deletions(-) diff --git a/halig/__version__.py b/halig/__version__.py index 06399fe..5d3f424 100644 --- a/halig/__version__.py +++ b/halig/__version__.py @@ -1 +1 @@ -__version__ = "0.4.2a1" +__version__ = "0.4.2a2" diff --git a/halig/settings.py b/halig/settings.py index 83ce7db..65549f5 100644 --- a/halig/settings.py +++ b/halig/settings.py @@ -26,6 +26,8 @@ class Settings(BaseSettings): `[~/.ssh/id_ed25519.pub]` cache_path (DirectoryPath): a *valid* path used to cache some stuff, particularly remote public keys. Defaults to $XDG_CACHE_HOME/halig + remote_public_keys_timeout (float): time after which the retrieval of external public keys + (e.g. github ssh keys) should be interrupted. Defaults to 0.5. """ notebooks_root_path: DirectoryPath @@ -38,12 +40,12 @@ class Settings(BaseSettings): ], ) cache_path: DirectoryPath = Field( - ..., default_factory=lambda: platformdirs.user_cache_path( "halig", ensure_exists=True, ), ) + remote_public_keys_timeout: float = 0.5 @field_validator("identity_paths", "recipient_paths", mode="before") @classmethod @@ -83,7 +85,10 @@ class Settings(BaseSettings): with hishel.CacheClient( storage=hishel.FileStorage(base_path=self.cache_path / "hishel"), ) as client: - response = client.get(str(path)) + response = client.get( + str(path), + timeout=self.remote_public_keys_timeout, + ) if response.status_code == httpx.codes.OK: for line in response.content.decode().split("\n"): if line: diff --git a/tests/commands/test_edit.py b/tests/commands/test_edit.py index 5eb2a55..a37eb9f 100644 --- a/tests/commands/test_edit.py +++ b/tests/commands/test_edit.py @@ -16,7 +16,8 @@ def test_edit_raises_invalid_age_file(notes, settings: Settings): def test_edit_current_note(mock_edit, current_note, settings: Settings, encryptor): edit_command = EditCommand( - note_path=settings.notebooks_root_path, settings=settings, + note_path=settings.notebooks_root_path, + settings=settings, ) assert edit_command.note_path == current_note edit_command.run() diff --git a/tests/commands/test_import.py b/tests/commands/test_import.py index 2aae32b..2c64645 100644 --- a/tests/commands/test_import.py +++ b/tests/commands/test_import.py @@ -35,7 +35,9 @@ def test_import(unencrypted_notes: Path, command: ImportCommand, encryptor: Encr def test_import_unlink( - unencrypted_notes: Path, command: ImportCommand, encryptor: Encryptor, + unencrypted_notes: Path, + command: ImportCommand, + encryptor: Encryptor, ): command.unlink = True command.run() diff --git a/tests/commands/test_show.py b/tests/commands/test_show.py index 8c26daa..62a5743 100644 --- a/tests/commands/test_show.py +++ b/tests/commands/test_show.py @@ -26,7 +26,8 @@ def test_show_raises_note_path_is_not_age_valid(notes, settings: Settings): def test_show_current_note(current_note, settings): show_command = ShowCommand( - note_path=settings.notebooks_root_path, settings=settings, + note_path=settings.notebooks_root_path, + settings=settings, ) assert show_command.note_path == current_note assert show_command.decrypt() == "foo" diff --git a/tests/test_encryption.py b/tests/test_encryption.py index dd612e2..8f7435f 100644 --- a/tests/test_encryption.py +++ b/tests/test_encryption.py @@ -24,7 +24,7 @@ def test_instance_encryptor_from_age_keys(halig_path, notebooks_path): f.write(str(identity.to_public())) recipient_paths.append(recipient_path) - #cache_path = platformdirs.user_cache_path("halig", ensure_exists=True) + # cache_path = platformdirs.user_cache_path("halig", ensure_exists=True) settings = Settings( notebooks_root_path=notebooks_path, identity_paths=identity_paths,