Some general clean up and updates.
This commit is contained in:
@@ -19,19 +19,19 @@ async def get_token_header(x_token:str = Header(...)):
|
|||||||
|
|
||||||
|
|
||||||
# ### BEGIN ### API Lib General ### async get_account_header() ###
|
# ### BEGIN ### API Lib General ### async get_account_header() ###
|
||||||
|
# Updated 2021-08-23
|
||||||
async def get_account_header(x_account_id:str = Header(...)):
|
async def get_account_header(x_account_id:str = Header(...)):
|
||||||
log.setLevel(logging.WARNING) # DEBUG, INFO, WARN, WARNING, ERROR, EXCEPTION, CRITICAL
|
log.setLevel(logging.WARNING) # DEBUG, INFO, WARN, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||||
log.debug(locals())
|
log.debug(locals())
|
||||||
|
|
||||||
if len(x_account_id):
|
if len(x_account_id):
|
||||||
log.info('The x-account-id header has a value.')
|
log.info(f'The x-account-id header has a value. x-account-id: {x_account_id}')
|
||||||
if account_id := redis_lookup_id_random(table_name='account', record_id_random=x_account_id):
|
if account_id := redis_lookup_id_random(table_name='account', record_id_random=x_account_id):
|
||||||
log.setLevel(logging.DEBUG)
|
log.setLevel(logging.DEBUG)
|
||||||
log.info('Found the account_id with the account_id_random value: '+x_account_id)
|
log.info('Found the account_id with the account_id_random value: '+x_account_id)
|
||||||
account = { 'id': account_id, 'id_random': x_account_id }
|
account = { 'id': account_id, 'id_random': x_account_id }
|
||||||
else:
|
else:
|
||||||
log.setLevel(logging.DEBUG)
|
log.warning('The x-account-id Account ID was not found or it was invalid...')
|
||||||
log.info('The x-account-id was invalid and not empty...')
|
|
||||||
#raise HTTPException(status_code=500)
|
#raise HTTPException(status_code=500)
|
||||||
raise HTTPException(status_code=400) # or 404?
|
raise HTTPException(status_code=400) # or 404?
|
||||||
#return False
|
#return False
|
||||||
@@ -40,7 +40,6 @@ async def get_account_header(x_account_id:str = Header(...)):
|
|||||||
account = { 'id': None, 'id_random': None }
|
account = { 'id': None, 'id_random': None }
|
||||||
#account = { 'id': 0, 'id_random': 'abcdef123456' }
|
#account = { 'id': 0, 'id_random': 'abcdef123456' }
|
||||||
|
|
||||||
|
|
||||||
return account
|
return account
|
||||||
# ### END ### API Lib General ### async get_account_header() ###
|
# ### END ### API Lib General ### async get_account_header() ###
|
||||||
|
|
||||||
|
|||||||
@@ -13,7 +13,8 @@ from app.models.common_field_schema import base_fields, default_num_bytes
|
|||||||
|
|
||||||
|
|
||||||
# ### BEGIN ### API Response Model ### Resp_Body_Base() ###
|
# ### BEGIN ### API Response Model ### Resp_Body_Base() ###
|
||||||
# The pydantic BaseModel to help make consistent REST responses - STI 2021-03-05
|
# The pydantic BaseModel to help make consistent REST responses.
|
||||||
|
# Updated 2021-03-05
|
||||||
class Resp_Body_Base(BaseModel):
|
class Resp_Body_Base(BaseModel):
|
||||||
log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||||
log.debug(locals())
|
log.debug(locals())
|
||||||
@@ -28,7 +29,8 @@ class Resp_Body_Base(BaseModel):
|
|||||||
|
|
||||||
|
|
||||||
# ### BEGIN ### API Response Model ### mk_resp() ###
|
# ### BEGIN ### API Response Model ### mk_resp() ###
|
||||||
# The make response function for REST - STI 2021-03-17
|
# The method for making responses for REST. Returns a dict, but currently uses Resp_Body_Base inside the function.
|
||||||
|
# Update 2021-08-23
|
||||||
def mk_resp(
|
def mk_resp(
|
||||||
data: None|bool|dict|list,
|
data: None|bool|dict|list,
|
||||||
dict_to_json: bool = False,
|
dict_to_json: bool = False,
|
||||||
@@ -40,7 +42,7 @@ def mk_resp(
|
|||||||
by_alias: bool = True,
|
by_alias: bool = True,
|
||||||
exclude_unset: bool = True,
|
exclude_unset: bool = True,
|
||||||
response: Response = None
|
response: Response = None
|
||||||
):
|
) -> dict:
|
||||||
log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||||
log.debug(locals())
|
log.debug(locals())
|
||||||
|
|
||||||
@@ -110,4 +112,4 @@ def mk_resp(
|
|||||||
log.debug(resp_body_dict)
|
log.debug(resp_body_dict)
|
||||||
|
|
||||||
return resp_body_dict
|
return resp_body_dict
|
||||||
# ### END ### API Response Model ### mk_resp() ###
|
# ### END ### API Response Model ### mk_resp() ###
|
||||||
|
|||||||
Reference in New Issue
Block a user