mirror of
https://git.collinwebdesigns.de/oscar.krause/fastapi-dls.git
synced 2024-11-23 23:41:06 +03:00
code styling & improved logging
This commit is contained in:
parent
eff6aae25d
commit
21f19be8ab
@ -60,9 +60,11 @@ app.add_middleware(
|
|||||||
allow_headers=['*'],
|
allow_headers=['*'],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
LOG_LEVEL = logging.DEBUG if DEBUG else logging.INFO
|
||||||
logging.basicConfig()
|
logging.basicConfig()
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
logger.setLevel(logging.DEBUG if DEBUG else logging.INFO)
|
logger.setLevel(LOG_LEVEL)
|
||||||
|
logging.getLogger('util').setLevel(LOG_LEVEL)
|
||||||
|
|
||||||
|
|
||||||
def __get_token(request: Request) -> dict:
|
def __get_token(request: Request) -> dict:
|
||||||
|
16
app/util.py
16
app/util.py
@ -1,10 +1,17 @@
|
|||||||
def load_file(filename) -> bytes:
|
import logging
|
||||||
|
|
||||||
|
logging.basicConfig()
|
||||||
|
|
||||||
|
|
||||||
|
def load_file(filename: str) -> bytes:
|
||||||
|
log = logging.getLogger(f'{__name__}')
|
||||||
|
log.debug(f'Loading contents of file "{filename}')
|
||||||
with open(filename, 'rb') as file:
|
with open(filename, 'rb') as file:
|
||||||
content = file.read()
|
content = file.read()
|
||||||
return content
|
return content
|
||||||
|
|
||||||
|
|
||||||
def load_key(filename) -> "RsaKey":
|
def load_key(filename: str) -> "RsaKey":
|
||||||
try:
|
try:
|
||||||
# Crypto | Cryptodome on Debian
|
# Crypto | Cryptodome on Debian
|
||||||
from Crypto.PublicKey import RSA
|
from Crypto.PublicKey import RSA
|
||||||
@ -13,6 +20,8 @@ def load_key(filename) -> "RsaKey":
|
|||||||
from Cryptodome.PublicKey import RSA
|
from Cryptodome.PublicKey import RSA
|
||||||
from Cryptodome.PublicKey.RSA import RsaKey
|
from Cryptodome.PublicKey.RSA import RsaKey
|
||||||
|
|
||||||
|
log = logging.getLogger(__name__)
|
||||||
|
log.debug(f'Importing RSA-Key from "{filename}"')
|
||||||
return RSA.import_key(extern_key=load_file(filename), passphrase=None)
|
return RSA.import_key(extern_key=load_file(filename), passphrase=None)
|
||||||
|
|
||||||
|
|
||||||
@ -24,5 +33,6 @@ def generate_key() -> "RsaKey":
|
|||||||
except ModuleNotFoundError:
|
except ModuleNotFoundError:
|
||||||
from Cryptodome.PublicKey import RSA
|
from Cryptodome.PublicKey import RSA
|
||||||
from Cryptodome.PublicKey.RSA import RsaKey
|
from Cryptodome.PublicKey.RSA import RsaKey
|
||||||
|
log = logging.getLogger(__name__)
|
||||||
|
log.debug(f'Generating RSA-Key')
|
||||||
return RSA.generate(bits=2048)
|
return RSA.generate(bits=2048)
|
||||||
|
Loading…
Reference in New Issue
Block a user