diff --git a/Taskfile.yaml b/Taskfile.yaml index c817d272..ea7e7f5a 100644 --- a/Taskfile.yaml +++ b/Taskfile.yaml @@ -67,7 +67,7 @@ tasks: preconditions: - { msg: "Missing virtual environment", sh: "test -d {{.ROOT_DIR}}/.venv" } - { msg: "Missing Makejinja config file", sh: "test -f {{.MAKEJINJA_CONFIG_FILE}}" } - - { msg: "Missing Makejinja loader file", sh: "test -f {{.BOOTSTRAP_DIR}}/scripts/loader.py" } + - { msg: "Missing Makejinja plugin file", sh: "test -f {{.BOOTSTRAP_DIR}}/scripts/plugin.py" } - { msg: "Missing bootstrap addons file", sh: "test -f {{.BOOTSTRAP_ADDONS_FILE}}" } - { msg: "Missing bootstrap config file", sh: "test -f {{.BOOTSTRAP_CONFIG_FILE}}" } diff --git a/bootstrap/scripts/loader.py b/bootstrap/scripts/plugin.py similarity index 75% rename from bootstrap/scripts/loader.py rename to bootstrap/scripts/plugin.py index e170f9ab..a86a7911 100644 --- a/bootstrap/scripts/loader.py +++ b/bootstrap/scripts/plugin.py @@ -1,4 +1,6 @@ +from typing import Any import bcrypt +import makejinja import netaddr import validation @@ -16,12 +18,12 @@ def nthhost(value: str, query: int) -> str: def encrypt(value: str) -> str: return bcrypt.hashpw(value.encode(), bcrypt.gensalt(rounds=10)).decode("ascii") -class Loader: - def __init__(self, data): +class Plugin(makejinja.plugin.Plugin): + def __init__(self, data: dict[str, Any]): if data.get("skip_tests", False): return validation.validate(data) - def filters(self): + def filters(self) -> makejinja.plugin.Filters: return [nthhost, encrypt] diff --git a/makejinja.toml b/makejinja.toml index 2ec26fc7..a3f4f22d 100644 --- a/makejinja.toml +++ b/makejinja.toml @@ -4,7 +4,7 @@ output = "./" exclude_patterns = ["*.partial.yaml.j2"] data = ["./bootstrap/vars/addons.yaml", "./bootstrap/vars/config.yaml"] import_paths = ["./bootstrap/scripts"] -loaders = ["loader:Loader"] +loaders = ["plugin:Plugin"] jinja_suffix = ".j2" force = true undefined = "chainable" @@ -19,6 +19,3 @@ comment_start = "#|" comment_end = "|#" variable_start = "#{" variable_end = "}#" - -[makejinja.whitespace] -keep_trailing_newline = true diff --git a/requirements.txt b/requirements.txt index b57b43e9..2dd7b2c0 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,6 @@ bcrypt==4.1.2 cloudflare==2.16.0 email-validator==2.1.0 -makejinja==2.3.5 +makejinja==2.5.0 netaddr==0.10.1 passlib==1.7.4