Files
home-cluster/bootstrap/scripts/plugin.py
T
Devin Buhl 4be97f78e8 feat: update makejinja to 2.5.0 (#1221)
* feat: update makejinja to 2.5.0 and implement mjfilter

Signed-off-by: Devin Buhl <devin@buhl.casa>

* fix: move logic for skip tests

Signed-off-by: Devin Buhl <devin@buhl.casa>

* feat: update makejinja to 2.5.0

Signed-off-by: Devin Buhl <devin@buhl.casa>

---------

Signed-off-by: Devin Buhl <devin@buhl.casa>
2024-01-21 17:37:48 -05:00

30 lines
714 B
Python

from typing import Any
import bcrypt
import makejinja
import netaddr
import validation
def nthhost(value: str, query: int) -> str:
value = netaddr.IPNetwork(value)
try:
nth = int(query)
if value.size > nth:
return str(value[nth])
except ValueError:
return False
return value
def encrypt(value: str) -> str:
return bcrypt.hashpw(value.encode(), bcrypt.gensalt(rounds=10)).decode("ascii")
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) -> makejinja.plugin.Filters:
return [nthhost, encrypt]