General code clean up for debugging. Also work on event badge related.

This commit is contained in:
Scott Idem
2022-02-15 11:33:35 -05:00
parent 57b3b358ad
commit cfa58f2c32
6 changed files with 98 additions and 122 deletions

View File

@@ -1,4 +1,4 @@
from __future__ import annotations
# from __future__ import annotations
import datetime, html2text, jwt, os, pandas, pathlib, pytz, redis, time
from passlib.hash import argon2
@@ -20,7 +20,7 @@ from app.db_sql import redis_lookup_id_random, sql_select
# ### BEGIN ### API Lib General ### async get_token_header() ###
async def get_token_header(x_token: str = Header(...)):
def get_token_header(x_token: str = Header(...)):
if x_token != 'fake-super-secret-token':
raise HTTPException(status_code=400, detail='X-Token header invalid')
# ### END ### API Lib General ### async get_token_header() ###
@@ -52,9 +52,10 @@ class Common_Route_Params:
# ### END ### API Lib General ### class Common_Route_Params ###
# ### BEGIN ### API Lib General ### async route_commons() ###
# Updated 2022-01-05
async def common_route_params(
# ### BEGIN ### API Lib General ### common_route_params() ###
# Updated 2022-02-15
@logger_reset # This breaks things for some reason when the function is async. Do not use async def common_route_params()!
def common_route_params(
x_account_id: str = Header(..., min_length=11, max_length=22),
enabled: str = 'enabled', # all, enabled, disabled
limit: int = 100,
@@ -66,23 +67,19 @@ async def common_route_params(
# exclude: Optional[list] = [], # Leaving this and include commented out
# include: Optional[list] = [], # Leaving this and exclude commented out
response: Response = Response,
log_lvl: int = logging.WARNING, # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
) -> Common_Route_Params:
log.setLevel(logging.INFO) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
log.setLevel(log_lvl)
log.debug(locals())
log.info(f'Setting commons values')
log.info(f'The x-account-id header has a value. x-account-id: {x_account_id}')
log.info(f'Setting commons values: x_account_id, x_account_id_random, limit, offset, enabled, by_alias, exclude_unset, response')
x_account_id_random = x_account_id
if x_account_id := redis_lookup_id_random(table_name='account', record_id_random=x_account_id):
log.info(f'Found the x-account-id with the value: {x_account_id}')
# x_account = { 'id': account_id, 'id_random': x_account_id }
# log.debug(x_account)
# return x_account
log.info(f'Found the x-account-id header with the value: {x_account_id}')
else:
log.warning(f'The x-account-id Account ID was not found. Account ID: {x_account_id}')
log.warning(f'The x-account-id header was found, but the Account ID was not found or is not valid. Account ID: {x_account_id}')
raise HTTPException(status_code=403, detail='The x-account-id Account ID was not found.') # Forbidden
commons = Common_Route_Params( x_account_id=x_account_id, x_account_id_random=x_account_id_random, limit=limit, offset=offset, enabled=enabled, by_alias=by_alias, exclude_unset=exclude_unset, response=response )
@@ -90,7 +87,7 @@ async def common_route_params(
log.debug(commons)
return commons
# ### END ### API Lib General ### async route_commons() ###
# ### END ### API Lib General ### async common_route_params() ###
def secure_hash_string(string: str):