from base64 import urlsafe_b64encode from hashlib import pbkdf2_hmac from pathlib import Path from jinja2_simple_tags import StandaloneTag class StaticTag(StandaloneTag): tags = {"static"} def render(self, filename="/", hubapp=None): if not hubapp: hubapp = self.context["hubapp"] elif isinstance(hubapp, str): hubapp = self.context["hubapp"].app.get_hubapp_by_name(hubapp) return hubapp.uri_from(Path(filename)) def scramble(secret, value): if isinstance(value, str): value = value.encode() if isinstance(secret, str): secret = secret.encode() return urlsafe_b64encode( pbkdf2_hmac("sha512", value, secret, 221100) ).rstrip(b"=").decode("ascii") def get_redis_pass(redis_conf): prefix = "requirepass " with open(redis_conf, "rt") as fh: for line in fh: if not line.startswith(prefix): continue return line[len(prefix) :].rstrip() return None