Work membership and general clean up
This commit is contained in:
@@ -10,17 +10,18 @@ from .log import *
|
||||
from .db_sql import sql_select
|
||||
|
||||
|
||||
async def get_token_header(x_token: str = Header(...)):
|
||||
# ### BEGIN ### API Lib General ### async get_token_header() ###
|
||||
async 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() ###
|
||||
|
||||
|
||||
async def get_account_header(x_account_id: str = Header(...)):
|
||||
# ### BEGIN ### API Lib General ### async get_account_header() ###
|
||||
async def get_account_header(x_account_id:str = Header(...)):
|
||||
log.setLevel(logging.WARNING) # DEBUG, INFO, WARN, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
log.debug(locals())
|
||||
|
||||
print('get_account_header(): '+x_account_id)
|
||||
|
||||
if len(x_account_id):
|
||||
log.info('The x-account-id header has a value.')
|
||||
if account_id := redis_lookup_id_random(table_name='account', record_id_random=x_account_id):
|
||||
@@ -38,24 +39,22 @@ async def get_account_header(x_account_id: str = Header(...)):
|
||||
account = { 'id': None, 'id_random': None }
|
||||
|
||||
return account
|
||||
# ### END ### API Lib General ### async get_account_header() ###
|
||||
|
||||
|
||||
# ### BEGIN ### API Lib General ### redis_lookup_id_random() ###
|
||||
# Just return the value if it is an integer
|
||||
# Check if the id_random value is a string and the correct length
|
||||
# Attempt to look up id_random key in Redis
|
||||
# If success then return the ID number
|
||||
# If not success and there is a table_name then check the database table passed
|
||||
# If found in database table then store in Redis and return the ID number
|
||||
def redis_lookup_id_random(record_id_random=None, table_name=None):
|
||||
def redis_lookup_id_random(record_id_random:int|str, table_name:str):
|
||||
log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
log.debug(locals())
|
||||
|
||||
if record_id_random is None: return False
|
||||
if isinstance(record_id_random, bool): return False
|
||||
if isinstance(record_id_random, int):
|
||||
return record_id_random
|
||||
elif isinstance(record_id_random, str):
|
||||
pass
|
||||
if isinstance(record_id_random, str): pass
|
||||
elif isinstance(record_id_random, int): return record_id_random
|
||||
else:
|
||||
log.warning(f'Unexpected data type: {str(type(record_id_random))} Expected type is a string 11 or 22 characters long.')
|
||||
return False
|
||||
@@ -119,11 +118,13 @@ def redis_lookup_id_random(record_id_random=None, table_name=None):
|
||||
log.setLevel(logging.ERROR) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
log.error('We should not be here. Something unexpected happened.')
|
||||
return False # Just in case
|
||||
# ### BEGIN ### API Lib General ### redis_lookup_id_random() ###
|
||||
|
||||
|
||||
# ### BEGIN ### API Lib General ### lookup_id_random_pop() ###
|
||||
# Look up and resolve id_random values to their id
|
||||
# Remove the unneeded *_id_random key from the dict
|
||||
def lookup_id_random_pop(obj_data=None):
|
||||
def lookup_id_random_pop(obj_data:dict):
|
||||
log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
log.debug(locals())
|
||||
|
||||
@@ -236,3 +237,4 @@ def lookup_id_random_pop(obj_data=None):
|
||||
obj_data.pop('from_object_id_random')
|
||||
|
||||
return obj_data
|
||||
# ### END ### API Lib General ### lookup_id_random_pop() ###
|
||||
|
||||
Reference in New Issue
Block a user