diff --git a/slices/__init__.py b/slices/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/slices/bodyfetcher.py b/slices/bodyfetcher.py new file mode 100644 index 0000000..aaa167c --- /dev/null +++ b/slices/bodyfetcher.py @@ -0,0 +1,13 @@ +import cherrypy +import cherrypy_cors +import json + +def body_json(): + result = None + if cherrypy.request.method == 'OPTIONS': + cherrypy_cors.preflight(allowed_methods=['GET', 'POST']) + if cherrypy.request.method == 'POST': + cherrypy.serving.response.headers['Content-Type'] = 'application/json' + body_request = cherrypy.request.body.read() + result = json.loads(body_request.decode()) + return result diff --git a/core/loggorilla.py b/slices/loggorilla.py similarity index 100% rename from core/loggorilla.py rename to slices/loggorilla.py diff --git a/core/mailme.py b/slices/sendwave.py similarity index 100% rename from core/mailme.py rename to slices/sendwave.py diff --git a/slices/tokenguard.py b/slices/tokenguard.py new file mode 100644 index 0000000..b2d6ef6 --- /dev/null +++ b/slices/tokenguard.py @@ -0,0 +1,23 @@ +from cryptography.hazmat.primitives import serialization +import jwt + +def encode(payload, id_rsa, passphrase): + private_key = open(id_rsa, 'r').read() + key = serialization.load_ssh_private_key(private_key.encode(), password=passphrase) + token = jwt.encode( + payload = payload, + key = key, + algorithm = 'RS256' + ) + return token + +def decode(token, id_rsa): + public_key = open(id_rsa, 'r').read() + key = serialization.load_ssh_public_key(public_key.encode()) + header = jwt.get_unverified_header(token) + payload = jwt.decode( + jwt = token, + key = key, + algorithms = [header['alg'], ] + ) + return payload