From: Vladimír Čunát Date: Sat, 12 Aug 2023 11:13:59 +0000 (+0200) Subject: datamodel: /local-data/subtrees/*: drop parts that are not implemented X-Git-Tag: v6.0.3~7^2~11 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5eb8b57fe1dbdc02048fcbe3445f05464a096c81;p=thirdparty%2Fknot-resolver.git datamodel: /local-data/subtrees/*: drop parts that are not implemented Otherwise we'd let confusing things pass all validations. --- diff --git a/manager/knot_resolver_manager/datamodel/local_data_schema.py b/manager/knot_resolver_manager/datamodel/local_data_schema.py index b782d8e79..c9a73593d 100644 --- a/manager/knot_resolver_manager/datamodel/local_data_schema.py +++ b/manager/knot_resolver_manager/datamodel/local_data_schema.py @@ -23,31 +23,37 @@ class SubtreeSchema(ConfigSchema): tags: Tags to link with other policy rules. ttl: Default TTL value used for added local subtree. nodata: Use NODATA synthesis. NODATA will be synthesised for matching name, but mismatching type(e.g. AAAA query when only A exists). - addresses: Subtree addresses. roots: Subtree roots. - roots_file: Subtree roots from given file. - roots_url: Subtree roots form given URL. - refresh: Refresh time to update data from 'roots-file' or 'roots-url'. """ + # addresses: Subtree addresses. + # roots_file: Subtree roots from given file. + # roots_url: Subtree roots form given URL. + # refresh: Refresh time to update data from 'roots-file' or 'roots-url'. + type: Literal["empty", "nxdomain", "redirect"] tags: Optional[List[IDPattern]] = None ttl: Optional[TimeUnit] = None nodata: bool = True - addresses: Optional[List[IPAddress]] = None roots: Optional[List[DomainName]] = None - roots_file: Optional[File] = None - roots_url: Optional[EscapedStr] = None - refresh: Optional[TimeUnit] = None + # # These aren't implemented yet. + # addresses: Optional[List[IPAddress]] = None + # roots_file: Optional[File] = None + # roots_url: Optional[EscapedStr] = None + # refresh: Optional[TimeUnit] = None + + # def _validate(self) -> None: + # options_sum = sum([bool(self.roots), bool(self.roots_file), bool(self.roots_url)]) + # if options_sum > 1: + # raise ValueError("only one of, 'roots', 'roots-file' or 'roots-url' can be configured") + # elif options_sum < 1: + # raise ValueError("one of, 'roots', 'roots-file' or 'roots-url' must be configured") + # if self.refresh and not (self.roots_file or self.roots_url): + # raise ValueError("'refresh' can be only configured with 'roots-file' or 'roots-url'") def _validate(self) -> None: - options_sum = sum([bool(self.roots), bool(self.roots_file), bool(self.roots_url)]) - if options_sum > 1: - raise ValueError("only one of, 'roots', 'roots-file' or 'roots-url' can be configured") - elif options_sum < 1: - raise ValueError("one of, 'roots', 'roots-file' or 'roots-url' must be configured") - if self.refresh and not (self.roots_file or self.roots_url): - raise ValueError("'refresh' can be only configured with 'roots-file' or 'roots-url'") + if self.roots is None: + raise ValueError("'roots' is missing") class RPZSchema(ConfigSchema): diff --git a/manager/tests/unit/datamodel/test_local_data.py b/manager/tests/unit/datamodel/test_local_data.py index fe529777a..3ad6dd7dc 100644 --- a/manager/tests/unit/datamodel/test_local_data.py +++ b/manager/tests/unit/datamodel/test_local_data.py @@ -11,9 +11,10 @@ from knot_resolver_manager.utils.modeling.exceptions import DataValidationError "val", [ {"type": "empty", "roots": ["sub2.example.org"]}, - {"type": "empty", "roots-url": "https://example.org/blocklist.txt", "refresh": "1d"}, - {"type": "nxdomain", "roots-file": "/etc/hosts"}, # must be an existing file or validation will fail - {"type": "redirect", "roots": ["sub4.example.org"], "addresses": ["127.0.0.1", "::1"]}, + {"type": "nxdomain", "roots": ["sub3.example.org", "sub5.example.net."], "ttl": "1h"}, + # {"type": "empty", "roots-url": "https://example.org/blocklist.txt", "refresh": "1d"}, + # {"type": "nxdomain", "roots-file": "/etc/hosts"}, # must be an existing file or validation will fail + {"type": "redirect", "roots": ["sub4.example.org"]}, ], ) def test_subtree_valid(val: Any):