X-Git-Url: https://git.mar77i.info/?a=blobdiff_plain;f=hub%2Fapp.py;h=22a7cd481a6db610c1f1417fe2abd093c6887d78;hb=16c0b1e580f2c92baf6882ec4dfa655c267d23b9;hp=2a0a712f515c6984a53f56ff562094c14433508d;hpb=6d1d482531b77da3cff5616ee40cf558a45c9fda;p=hublib diff --git a/hub/app.py b/hub/app.py index 2a0a712..22a7cd4 100644 --- a/hub/app.py +++ b/hub/app.py @@ -1,6 +1,8 @@ import socket import sys from argparse import ArgumentParser +from base64 import urlsafe_b64encode +from hashlib import pbkdf2_hmac from itertools import chain from pathlib import Path from secrets import token_urlsafe @@ -23,7 +25,7 @@ class App(FalconApp): self.base_dir = Path(__file__).parents[1] / "webroot" self.env = Environment( loader=FileSystemLoader(self.base_dir), - autoescape=select_autoescape, + autoescape=select_autoescape(), extensions=["hub.utils.StaticTag"], ) self.secret = secret or token_urlsafe(64) @@ -35,8 +37,15 @@ class App(FalconApp): HubApp(self, base_dir) self.add_error_handler(Exception, self.print_exception) - def get_hubapp_by_name(self, name): - return self.hubapps[name] + def scramble(self, value): + if isinstance(value, str): + value = value.encode() + secret = self.secret + if isinstance(secret, str): + secret = secret.encode() + return urlsafe_b64encode( + pbkdf2_hmac("sha512", value, secret, 221100) + ).rstrip(b"=").decode("ascii") async def print_exception(self, req, resp, ex, params): print_exception(*sys.exc_info())