General clean up

This commit is contained in:
Scott Idem
2023-01-30 15:06:02 -05:00
parent 536c4c4732
commit db58d9267c
3 changed files with 103 additions and 25 deletions

View File

@@ -26,6 +26,74 @@ def get_token_header(x_token: str = Header(...)):
# ### END ### API Lib General ### async get_token_header() ###
# ### BEGIN ### API Lib General ### class Common_Route_Params ###
# Updated 2023-01-30
class Common_Route_Params_No_Account_ID:
def __init__(
self,
x_account_id: int = None,
x_account_id_random: str = None,
enabled: str = 'enabled',
limit: int = 10,
offset: int = 0,
by_alias: bool = True,
exclude_unset: bool = True,
response = None,
):
self.x_account_id = x_account_id
self.x_account_id_random = x_account_id_random
self.enabled = enabled
self.limit = limit
self.offset = offset
self.by_alias = by_alias
self.exclude_unset = exclude_unset
self.response = response
# log.debug(response)
# ### END ### API Lib General ### class Common_Route_Params ###
# ### BEGIN ### API Lib General ### common_route_params() ###
# Updated 2023-01-30
@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_no_account_id(
x_account_id: str = Header(None, min_length=11, max_length=22),
enabled: str = 'enabled', # all, enabled, disabled
limit: int = 100,
offset: int = 0,
by_alias: bool = True,
exclude_none: Optional[bool] = True,
exclude_unset: bool = True,
# NOTE: Uncommenting either exclude or include breaks the JSON body format. I do not know why? Should be: {} Becomes this: {"obj_name": {"data_name": "data_value"}} -STI 2022-01-05
# 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_No_Account_ID:
log.setLevel(log_lvl)
log.debug(locals())
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 header with the value: {x_account_id}')
elif x_account_id is None:
log.warning(f'No x-account-id header value passed')
else:
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_No_Account_ID( 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 )
log.debug(commons)
return commons
# ### END ### API Lib General ### async common_route_params() ###
# ### BEGIN ### API Lib General ### class Common_Route_Params ###
# Updated 2022-01-05
class Common_Route_Params: