diff --git a/app/lib_general.py b/app/lib_general.py index 6f3cf0b..749d63e 100644 --- a/app/lib_general.py +++ b/app/lib_general.py @@ -126,6 +126,7 @@ class Common_Route_Params: def common_route_params( # 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_no_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_token: Optional[str] = Header(..., min_length=11, max_length=22), # x_aether_jwt_token: Optional[str] = Header(..., min_length=11, max_length=50), @@ -141,7 +142,7 @@ def common_route_params( # 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 + log_lvl: int = logging.INFO, # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL ) -> Common_Route_Params: log.setLevel(log_lvl) log.debug(locals()) @@ -150,8 +151,18 @@ def common_route_params( 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}') + if 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}') + 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 + elif x_no_account_id and len(x_no_account_id) > 10: + log.warning(f'Found the x_no_account_id header param with the value: {x_no_account_id}') + + x_account_id = 0 + x_account_id_random = '--- NOT SET ---' + 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}') @@ -162,9 +173,12 @@ def common_route_params( else: x_account_id = 0 x_account_id_random = '' + + x_account_id = 0 + x_account_id_random = '--- NOT SET ---' 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 + log.warning(f'The x-account-id and x-no-account-id-token headers were not found.') + raise HTTPException(status_code=403, detail='The x-account-id and x-no-account-id-token headers were not found.') # Forbidden 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 ) diff --git a/app/routers/api_crud.py b/app/routers/api_crud.py index 4e6f9c0..89cf091 100644 --- a/app/routers/api_crud.py +++ b/app/routers/api_crud.py @@ -374,7 +374,7 @@ async def get_obj_li( log.info(f'base_name was found. Returning data using {base_name} model.') resp_data = base_name(**record).dict(by_alias=commons.by_alias, exclude_unset=commons.exclude_unset) else: - log.info('base_name model was not found. Returning raw data.') + log.warning('base_name model was not found. Returning raw data.') resp_data = record resp_data_li.append(resp_data) return mk_resp(data=resp_data_li, response=commons.response)