Work on Stripe log

This commit is contained in:
Scott Idem
2022-07-26 09:22:35 -04:00
parent ef7531c980
commit 3b79802d32
2 changed files with 68 additions and 2 deletions

View File

@@ -90,6 +90,72 @@ def common_route_params(
# ### END ### API Lib General ### async common_route_params() ### # ### END ### API Lib General ### async common_route_params() ###
# ### BEGIN ### API Lib General ### class Common_Route_Params_Min ###
# Updated 2022-01-05
class Common_Route_Params_Min:
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_Min ###
# ### BEGIN ### API Lib General ### common_route_params_min() ###
# 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()!
def common_route_params_min(
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:
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')
if x_account_id:
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}')
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_Min( 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_min() ###
def secure_hash_string(string: str): def secure_hash_string(string: str):
string_hash = argon2.using(rounds=14, memory_cost=1536, parallelism=2).hash(string) string_hash = argon2.using(rounds=14, memory_cost=1536, parallelism=2).hash(string)

View File

@@ -3,7 +3,7 @@ from fastapi import APIRouter, Body, Depends, Header, HTTPException, Query, Resp
from pydantic import BaseModel, EmailStr, Field from pydantic import BaseModel, EmailStr, Field
from typing import Dict, List, Optional, Set, Union from typing import Dict, List, Optional, Set, Union
from app.lib_general import log, logging, common_route_params, Common_Route_Params from app.lib_general import log, logging, common_route_params, Common_Route_Params, common_route_params_min, Common_Route_Params_Min
from app.config import settings from app.config import settings
from app.db_sql import sql_enable_part, sql_insert, sql_update, sql_insert_or_update, sql_limit_offset_part, sql_select, sql_delete, redis_lookup_id_random from app.db_sql import sql_enable_part, sql_insert, sql_update, sql_insert_or_update, sql_limit_offset_part, sql_select, sql_delete, redis_lookup_id_random
@@ -28,7 +28,7 @@ async def post_stripe_log_obj(
# exclude_unset: Optional[bool] = True, # exclude_unset: Optional[bool] = True,
# response: Response = Response, # response: Response = Response,
commons: Common_Route_Params = Depends(common_route_params), commons: Common_Route_Params_Min = Depends(common_route_params_min),
): ):
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
log.debug(locals()) log.debug(locals())