From: Oto Šťáva Date: Fri, 19 Jul 2024 13:01:22 +0000 (+0200) Subject: kresctl: add generation of policy-loader Lua script X-Git-Tag: v6.0.8~2^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a4c89123d122fda5b6b538ec1b3cf0f5ac05b9cc;p=thirdparty%2Fknot-resolver.git kresctl: add generation of policy-loader Lua script --- diff --git a/doc/user/manager-client.rst b/doc/user/manager-client.rst index f21a69a7d..61ff2fff0 100644 --- a/doc/user/manager-client.rst +++ b/doc/user/manager-client.rst @@ -262,6 +262,15 @@ single ``kresctl`` command. Ignore strict rules during validation, e.g. path/file existence. + .. option:: --type= + + Which type of Lua script to generate. + + * ``worker`` generates a script for the daemon (default) + * ``policy-loader`` generates a script for the one-shot policy loader, + which generates a rule database based on ``views``, ``local-data``, + and ``forward`` configuration + .. option:: File with the declarative configuration in YAML or JSON format. diff --git a/manager/knot_resolver_manager/cli/cmd/convert.py b/manager/knot_resolver_manager/cli/cmd/convert.py index aab2740a9..7bb2858fd 100644 --- a/manager/knot_resolver_manager/cli/cmd/convert.py +++ b/manager/knot_resolver_manager/cli/cmd/convert.py @@ -21,6 +21,7 @@ class ConvertCommand(Command): self.input_file: str = namespace.input_file self.output_file: Optional[str] = namespace.output_file self.strict: bool = namespace.strict + self.type: str = namespace.type @staticmethod def register_args_subparser( @@ -34,6 +35,9 @@ class ConvertCommand(Command): action="store_false", dest="strict", ) + convert.add_argument( + "--type", help="The type of Lua script to generate", choices=["worker", "policy-loader"], default="worker" + ) convert.add_argument( "input_file", type=str, @@ -61,7 +65,14 @@ class ConvertCommand(Command): try: parsed = try_to_parse(data) set_global_validation_context(Context(Path(Path(self.input_file).parent), self.strict)) - lua = KresConfig(parsed).render_lua() + + if self.type == "worker": + lua = KresConfig(parsed).render_lua() + elif self.type == "policy-loader": + lua = KresConfig(parsed).render_lua_policy() + else: + raise ValueError(f"Invalid self.type={self.type}") + reset_global_validation_context() except (DataParsingError, DataValidationError) as e: print(e, file=sys.stderr)