Lot of cleanup

This commit is contained in:
Thomas Sileo
2018-05-29 21:36:05 +02:00
parent 559c65f474
commit 6aea610fb6
9 changed files with 143 additions and 25 deletions

View File

@@ -2,14 +2,18 @@ import os
import binascii
from Crypto.PublicKey import RSA
from typing import Callable
KEY_DIR = 'config/'
def get_secret_key(name:str) -> str:
def _new_key() -> str:
return binascii.hexlify(os.urandom(32)).decode('utf-8')
def get_secret_key(name: str, new_key: Callable[[], str] = _new_key) -> str:
key_path = f'{KEY_DIR}{name}.key'
if not os.path.exists(key_path):
k = binascii.hexlify(os.urandom(32)).decode('utf-8')
k = new_key()
with open(key_path, 'w+') as f:
f.write(k)
return k