From 8e022103636121b13d2ad63d61b84ca927e4aeb1 Mon Sep 17 00:00:00 2001 From: Wojtek Kosior Date: Mon, 12 Sep 2022 13:55:35 +0200 Subject: [proxy] Add support for script blocking/allowing rules --- src/hydrilla/proxy/state.py | 47 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 45 insertions(+), 2 deletions(-) (limited to 'src/hydrilla/proxy/state.py') diff --git a/src/hydrilla/proxy/state.py b/src/hydrilla/proxy/state.py index abea7a7..1ba87b4 100644 --- a/src/hydrilla/proxy/state.py +++ b/src/hydrilla/proxy/state.py @@ -133,6 +133,47 @@ class Store(ABC, t.Generic[RefType]): ... +class RulePatternInvalid(HaketiloException): + pass + +@dc.dataclass(frozen=True) +class RuleDisplayInfo: + ref: 'RuleRef' + pattern: str + allow_scripts: bool + +# mypy needs to be corrected: +# https://stackoverflow.com/questions/70999513/conflict-between-mix-ins-for-abstract-dataclasses/70999704#70999704 +@dc.dataclass(frozen=True, unsafe_hash=True) # type: ignore[misc] +class RuleRef(Ref): + @abstractmethod + def remove(self) -> None: + ... + + @abstractmethod + def update( + self, + *, + pattern: t.Optional[str] = None, + allow: t.Optional[bool] = None + ) -> None: + ... + + @abstractmethod + def get_display_info(self) -> RuleDisplayInfo: + ... + +class RuleStore(Store[RuleRef]): + @abstractmethod + def get_display_infos(self, allow: t.Optional[bool] = None) \ + -> t.Sequence[RuleDisplayInfo]: + ... + + @abstractmethod + def add(self, pattern: str, allow: bool) -> RuleRef: + ... + + class RepoNameInvalid(HaketiloException): pass @@ -161,8 +202,6 @@ class FileMissingError(FileInstallationError): class RepoApiVersionUnsupported(HaketiloException): pass -# mypy needs to be corrected: -# https://stackoverflow.com/questions/70999513/conflict-between-mix-ins-for-abstract-dataclasses/70999704#70999704 @dc.dataclass(frozen=True, unsafe_hash=True) # type: ignore[misc] class RepoRef(Ref): """....""" @@ -442,6 +481,10 @@ class HaketiloState(ABC): def import_items(self, malcontent_path: Path) -> None: ... + @abstractmethod + def rule_store(self) -> RuleStore: + ... + @abstractmethod def repo_store(self) -> RepoStore: """....""" -- cgit v1.2.3