From a1f4a8207e5b1e77112d407d959cd53d37b67032 Mon Sep 17 00:00:00 2001 From: Jon Michael Aanes Date: Wed, 8 Jan 2025 15:12:57 +0100 Subject: [PATCH] Load collection filter from file --- favro_sync/__main__.py | 2 +- favro_sync/favro_client.py | 2 +- favro_sync/favro_fuse.py | 8 ++++---- favro_sync/secrets.py | 10 ++++++++++ 4 files changed, 16 insertions(+), 6 deletions(-) diff --git a/favro_sync/__main__.py b/favro_sync/__main__.py index b0bef18..7f8de10 100644 --- a/favro_sync/__main__.py +++ b/favro_sync/__main__.py @@ -29,7 +29,7 @@ def main(): ) client.check_logged_in() - start_favro_fuse(client) + start_favro_fuse(client, secrets.favro_collection_filter()) if __name__ == '__main__': diff --git a/favro_sync/favro_client.py b/favro_sync/favro_client.py index ecd9ff7..4614461 100644 --- a/favro_sync/favro_client.py +++ b/favro_sync/favro_client.py @@ -215,7 +215,7 @@ class FavroClient: def _invalidate_cache(self, card_id: CardId) -> None: card = self.card_cache.remove(card_id) if card: - self.session.card_cache.delete( + self.session.cache.delete( requests=[self._get_cards_prepared_request(seq_id=card.seq_id)], ) diff --git a/favro_sync/favro_fuse.py b/favro_sync/favro_fuse.py index cd17978..c2d8a06 100644 --- a/favro_sync/favro_fuse.py +++ b/favro_sync/favro_fuse.py @@ -213,6 +213,8 @@ class FavroFuse(fuse.Fuse): return st def _is_allowed_collection(self, item: CollectionFileSystemItem) -> bool: + if self.collection_filter is None: + return True return item.collection_name in self.collection_filter def readdir(self, path: str, offset: int) -> Iterator[fuse.Direntry]: @@ -347,10 +349,8 @@ Userspace hello example ) -def start_favro_fuse(favro_client: FavroClient): - logger.info('Starting favro FUSE') - collection_filter = frozenset(['Platform']) - # TODO: +def start_favro_fuse(favro_client: FavroClient, collection_filter: frozenset[str]): + logger.info('Starting favro FUSE with collection filter: %s', collection_filter) server = FavroFuse( favro_client=favro_client, formatter=CardFileFormatter(), diff --git a/favro_sync/secrets.py b/favro_sync/secrets.py index 8e45c52..c3fe255 100644 --- a/favro_sync/secrets.py +++ b/favro_sync/secrets.py @@ -17,3 +17,13 @@ def favro_username(): def favro_password(): return secrets.load_or_fail('FAVRO_PASSWORD') + + +def favro_collection_filter() -> frozenset[str]: + loaded = secrets.load('FAVRO_COLLECTION_FILTER') + if loaded is None: + return None + values = loaded.strip().split('\n') + values = [v.strip() for v in values] + values = [v for v in values if v] + return frozenset(values)