Some general clean up and updates.

This commit is contained in:
Scott Idem
2021-08-23 12:36:30 -04:00
parent 824bdd29a2
commit e281b1d385
2 changed files with 9 additions and 8 deletions

View File

@@ -19,19 +19,19 @@ async def get_token_header(x_token:str = Header(...)):
# ### BEGIN ### API Lib General ### async get_account_header() ###
# Updated 2021-08-23
async def get_account_header(x_account_id:str = Header(...)):
log.setLevel(logging.WARNING) # DEBUG, INFO, WARN, WARNING, ERROR, EXCEPTION, CRITICAL
log.debug(locals())
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):
log.setLevel(logging.DEBUG)
log.info('Found the account_id with the account_id_random value: '+x_account_id)
account = { 'id': account_id, 'id_random': x_account_id }
else:
log.setLevel(logging.DEBUG)
log.info('The x-account-id was invalid and not empty...')
log.warning('The x-account-id Account ID was not found or it was invalid...')
#raise HTTPException(status_code=500)
raise HTTPException(status_code=400) # or 404?
#return False
@@ -40,7 +40,6 @@ async def get_account_header(x_account_id:str = Header(...)):
account = { 'id': None, 'id_random': None }
#account = { 'id': 0, 'id_random': 'abcdef123456' }
return account
# ### END ### API Lib General ### async get_account_header() ###

View File

@@ -13,7 +13,8 @@ from app.models.common_field_schema import base_fields, default_num_bytes
# ### 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):
log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
log.debug(locals())
@@ -28,7 +29,8 @@ class Resp_Body_Base(BaseModel):
# ### 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(
data: None|bool|dict|list,
dict_to_json: bool = False,
@@ -40,7 +42,7 @@ def mk_resp(
by_alias: bool = True,
exclude_unset: bool = True,
response: Response = None
):
) -> dict:
log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
log.debug(locals())
@@ -110,4 +112,4 @@ def mk_resp(
log.debug(resp_body_dict)
return resp_body_dict
# ### END ### API Response Model ### mk_resp() ###
# ### END ### API Response Model ### mk_resp() ###