]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
datamodel: templates: policy config moved out of the kresd worker config
authorAleš Mrázek <ales.mrazek@nic.cz>
Thu, 22 Feb 2024 13:40:27 +0000 (14:40 +0100)
committerAleš Mrázek <ales.mrazek@nic.cz>
Tue, 2 Jul 2024 12:07:48 +0000 (14:07 +0200)
manager/knot_resolver_manager/datamodel/config_schema.py
manager/knot_resolver_manager/datamodel/templates/__init__.py
manager/knot_resolver_manager/datamodel/templates/policy-config.lua.j2 [new file with mode: 0644]
manager/knot_resolver_manager/datamodel/templates/worker-config.lua.j2 [moved from manager/knot_resolver_manager/datamodel/templates/config.lua.j2 with 88% similarity]

index 8aa99446c482b57dd283dbecc7c01d601ced3423..d1b147e5ae431353cdb97a38ed0b1ed19ab29e4a 100644 (file)
@@ -17,7 +17,7 @@ from knot_resolver_manager.datamodel.management_schema import ManagementSchema
 from knot_resolver_manager.datamodel.monitoring_schema import MonitoringSchema
 from knot_resolver_manager.datamodel.network_schema import NetworkSchema
 from knot_resolver_manager.datamodel.options_schema import OptionsSchema
-from knot_resolver_manager.datamodel.templates import MAIN_TEMPLATE
+from knot_resolver_manager.datamodel.templates import POLICY_CONFIG_TEMPLATE, WORKER_CONFIG_TEMPLATE
 from knot_resolver_manager.datamodel.types import Dir, EscapedStr, IntPositive
 from knot_resolver_manager.datamodel.view_schema import ViewSchema
 from knot_resolver_manager.datamodel.webmgmt_schema import WebmgmtSchema
@@ -159,7 +159,10 @@ class KresConfig(ConfigSchema):
         # FIXME the `cwd` argument is used only for configuring control socket path
         # it should be removed and relative path used instead as soon as issue
         # https://gitlab.nic.cz/knot/knot-resolver/-/issues/720 is fixed
-        return MAIN_TEMPLATE.render(cfg=self, cwd=os.getcwd())
+        return WORKER_CONFIG_TEMPLATE.render(cfg=self, cwd=os.getcwd())
+
+    def render_lua_policy(self) -> str:
+        return POLICY_CONFIG_TEMPLATE.render(cfg=self, cwd=os.getcwd())
 
 
 def get_rundir_without_validation(data: Dict[str, Any]) -> Dir:
index 1846797b2bdb5818b05749701e2f9ccac47fe425..832503b7dfeae0f08b518e6d96840cb47eb35834 100644 (file)
@@ -17,8 +17,15 @@ def _get_templates_dir() -> str:
 _TEMPLATES_DIR = _get_templates_dir()
 
 
-def _import_main_template() -> Template:
-    path = os.path.join(_TEMPLATES_DIR, "config.lua.j2")
+def _import_kresd_worker_config_template() -> Template:
+    path = os.path.join(_TEMPLATES_DIR, "worker-config.lua.j2")
+    with open(path, "r", encoding="UTF-8") as file:
+        template = file.read()
+    return template_from_str(template)
+
+
+def _import_kresd_policy_config_template() -> Template:
+    path = os.path.join(_TEMPLATES_DIR, "policy-config.lua.j2")
     with open(path, "r", encoding="UTF-8") as file:
         template = file.read()
     return template_from_str(template)
@@ -30,4 +37,7 @@ def template_from_str(template: str) -> Template:
     return env.from_string(template)
 
 
-MAIN_TEMPLATE = _import_main_template()
+WORKER_CONFIG_TEMPLATE = _import_kresd_worker_config_template()
+
+
+POLICY_CONFIG_TEMPLATE = _import_kresd_policy_config_template()
diff --git a/manager/knot_resolver_manager/datamodel/templates/policy-config.lua.j2 b/manager/knot_resolver_manager/datamodel/templates/policy-config.lua.j2
new file mode 100644 (file)
index 0000000..4c5c904
--- /dev/null
@@ -0,0 +1,40 @@
+{% if not cfg.lua.script_only %}
+
+-- FFI library
+ffi = require('ffi')
+local C = ffi.C
+
+-- logging.level
+log_level('{{ cfg.logging.level }}')
+
+{% if cfg.logging.target -%}
+-- logging.target
+log_target('{{ cfg.logging.target }}')
+{%- endif %}
+
+{% if cfg.logging.groups %}
+-- logging.groups
+log_groups({
+{% for g in cfg.logging.groups %}
+{% if g != "manager" and g != "supervisord" and g != "cache-gc" %}
+    '{{ g }}',
+{% endif %}
+{% endfor %}
+})
+{% endif %}
+
+-- Config required for the cache opening
+cache.open({{ cfg.cache.size_max.bytes() }}, 'lmdb://{{ cfg.cache.storage }}')
+
+-- VIEWS section ------------------------------------
+{% include "views.lua.j2" %}
+
+-- LOCAL-DATA section -------------------------------
+{% include "local_data.lua.j2" %}
+
+-- FORWARD section ----------------------------------
+{% include "forward.lua.j2" %}
+
+{% endif %}
+
+quit()
similarity index 88%
rename from manager/knot_resolver_manager/datamodel/templates/config.lua.j2
rename to manager/knot_resolver_manager/datamodel/templates/worker-config.lua.j2
index 856dcf39963c72d5664b0ed6badaf259537e0756..20a40def138eff52d2a9dc3a1c8d4ab01a7c14fd 100644 (file)
@@ -28,15 +28,9 @@ nsid.name('{{ cfg.nsid }}' .. worker.id)
 -- NETWORK section ----------------------------------
 {% include "network.lua.j2" %}
 
--- VIEWS section ------------------------------------
-{% include "views.lua.j2" %}
-
 -- DNSSEC section -----------------------------------
 {% include "dnssec.lua.j2" %}
 
--- LOCAL-DATA section -------------------------------
-{% include "local_data.lua.j2" %}
-
 -- FORWARD section ----------------------------------
 {% include "forward.lua.j2" %}