]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
kresctl: add generation of policy-loader Lua script docs-develop-kres-zlfkk2/deployments/4585
authorOto Šťáva <oto.stava@nic.cz>
Fri, 19 Jul 2024 13:01:22 +0000 (15:01 +0200)
committerOto Šťáva <oto.stava@nic.cz>
Fri, 19 Jul 2024 13:09:10 +0000 (15:09 +0200)
doc/user/manager-client.rst
manager/knot_resolver_manager/cli/cmd/convert.py

index f21a69a7d2ca88d936b6e780dc440a9561e4ce48..61ff2fff0a658ccfbd7586092963d9f9a1cb13e2 100644 (file)
@@ -262,6 +262,15 @@ single ``kresctl`` command.
 
         Ignore strict rules during validation, e.g. path/file existence.
 
+    .. option:: --type=<worker|policy-loader>
+
+        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:: <input_file>
 
         File with the declarative configuration in YAML or JSON format.
index aab2740a956a4b50c02b566e02de18c73173ed9b..7bb2858fd13b9381cd746b694e4668640db7b52d 100644 (file)
@@ -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)