From: Aleš Mrázek Date: Thu, 22 Feb 2024 13:40:27 +0000 (+0100) Subject: datamodel: templates: policy config moved out of the kresd worker config X-Git-Tag: v6.0.8~8^2~22 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8738e35954321a06600e8aed7f271fee6b95dcb6;p=thirdparty%2Fknot-resolver.git datamodel: templates: policy config moved out of the kresd worker config --- diff --git a/manager/knot_resolver_manager/datamodel/config_schema.py b/manager/knot_resolver_manager/datamodel/config_schema.py index 8aa99446c..d1b147e5a 100644 --- a/manager/knot_resolver_manager/datamodel/config_schema.py +++ b/manager/knot_resolver_manager/datamodel/config_schema.py @@ -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: diff --git a/manager/knot_resolver_manager/datamodel/templates/__init__.py b/manager/knot_resolver_manager/datamodel/templates/__init__.py index 1846797b2..832503b7d 100644 --- a/manager/knot_resolver_manager/datamodel/templates/__init__.py +++ b/manager/knot_resolver_manager/datamodel/templates/__init__.py @@ -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 index 000000000..4c5c90484 --- /dev/null +++ b/manager/knot_resolver_manager/datamodel/templates/policy-config.lua.j2 @@ -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() diff --git a/manager/knot_resolver_manager/datamodel/templates/config.lua.j2 b/manager/knot_resolver_manager/datamodel/templates/worker-config.lua.j2 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 856dcf399..20a40def1 100644 --- a/manager/knot_resolver_manager/datamodel/templates/config.lua.j2 +++ b/manager/knot_resolver_manager/datamodel/templates/worker-config.lua.j2 @@ -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" %}