Updated CRUD API. Work on an alternative to the x-account-id header value. General clean up.
This commit is contained in:
@@ -544,7 +544,7 @@ def sql_select(
|
|||||||
as_dict: bool|None = True,
|
as_dict: bool|None = True,
|
||||||
as_list: bool|None = False,
|
as_list: bool|None = False,
|
||||||
max_count: int = 100000,
|
max_count: int = 100000,
|
||||||
log_lvl: int = logging.DEBUG, # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
log_lvl: int = logging.INFO, # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||||
) -> None|bool|dict|list:
|
) -> None|bool|dict|list:
|
||||||
log.setLevel(log_lvl)
|
log.setLevel(log_lvl)
|
||||||
|
|
||||||
|
|||||||
@@ -99,6 +99,7 @@ class Common_Route_Params:
|
|||||||
self,
|
self,
|
||||||
x_account_id: int,
|
x_account_id: int,
|
||||||
x_account_id_random: str,
|
x_account_id_random: str,
|
||||||
|
x_no_account_id_token: str|None = None,
|
||||||
enabled: str = 'enabled',
|
enabled: str = 'enabled',
|
||||||
limit: int = 10,
|
limit: int = 10,
|
||||||
offset: int = 0,
|
offset: int = 0,
|
||||||
@@ -108,6 +109,7 @@ class Common_Route_Params:
|
|||||||
):
|
):
|
||||||
self.x_account_id = x_account_id
|
self.x_account_id = x_account_id
|
||||||
self.x_account_id_random = x_account_id_random
|
self.x_account_id_random = x_account_id_random
|
||||||
|
self.x_no_account_id_token = x_no_account_id_token
|
||||||
self.enabled = enabled
|
self.enabled = enabled
|
||||||
self.limit = limit
|
self.limit = limit
|
||||||
self.offset = offset
|
self.offset = offset
|
||||||
@@ -122,10 +124,12 @@ class Common_Route_Params:
|
|||||||
# Updated 2022-02-15
|
# 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()!
|
@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(
|
def common_route_params(
|
||||||
x_account_id: str = Header(..., min_length=11, max_length=22),
|
# x_account_id: str = Header(..., min_length=11, max_length=22), # NOTE WARNING: Commented out 2023-08-17
|
||||||
|
x_account_id: str = Header(None, min_length=11, max_length=22), # NOTE WARNING: Changed to this 2023-08-17
|
||||||
# x_aether_api_key: Optional[str] = Header(..., min_length=11, max_length=22),
|
# x_aether_api_key: Optional[str] = Header(..., min_length=11, max_length=22),
|
||||||
# x_aether_api_token: Optional[str] = Header(..., min_length=11, max_length=22),
|
# x_aether_api_token: Optional[str] = Header(..., min_length=11, max_length=22),
|
||||||
# x_aether_jwt_token: Optional[str] = Header(..., min_length=11, max_length=50),
|
# x_aether_jwt_token: Optional[str] = Header(..., min_length=11, max_length=50),
|
||||||
|
x_no_account_id_token: str|None = None, # NOTE: Not a header value! Added 2023-08-17
|
||||||
enabled: str = 'enabled', # all, enabled, disabled
|
enabled: str = 'enabled', # all, enabled, disabled
|
||||||
limit: int = 100,
|
limit: int = 100,
|
||||||
offset: int = 0,
|
offset: int = 0,
|
||||||
@@ -148,11 +152,21 @@ def common_route_params(
|
|||||||
|
|
||||||
if x_account_id := redis_lookup_id_random(table_name='account', record_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}')
|
log.info(f'Found the x-account-id header with the value: {x_account_id}')
|
||||||
|
elif x_no_account_id_token and len(x_no_account_id_token) > 10: # NOTE: Not a header value!
|
||||||
|
# NOTE WARNING: This token should be varified and able to be disabled quickly.
|
||||||
|
log.warning(f'Found the x_no_account_id_token URL param with the value: {x_no_account_id_token}')
|
||||||
|
|
||||||
|
if x_account_id := redis_lookup_id_random(table_name='account', record_id_random=x_no_account_id_token):
|
||||||
|
log.info(f'Found the x-account-id header with the value: {x_account_id}')
|
||||||
|
x_account_id_random = x_no_account_id_token
|
||||||
|
else:
|
||||||
|
x_account_id = 0
|
||||||
|
x_account_id_random = ''
|
||||||
else:
|
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}')
|
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
|
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 )
|
commons = Common_Route_Params( x_account_id=x_account_id, x_account_id_random=x_account_id_random, x_no_account_id_token=x_no_account_id_token, limit=limit, offset=offset, enabled=enabled, by_alias=by_alias, exclude_unset=exclude_unset, response=response )
|
||||||
|
|
||||||
log.debug(commons)
|
log.debug(commons)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user