Slices, an extension script for CostaPy
This commit is contained in:
parent
8fa748fd62
commit
a2df8314dc
0
slices/__init__.py
Normal file
0
slices/__init__.py
Normal file
13
slices/bodyfetcher.py
Normal file
13
slices/bodyfetcher.py
Normal file
@ -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
|
23
slices/tokenguard.py
Normal file
23
slices/tokenguard.py
Normal file
@ -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
|
Loading…
Reference in New Issue
Block a user