in src/lambdas/modular_api_handler/handler.py [0:0]
def __call__(self, event: ProcessedEvent) -> ProcessedEvent:
if not event['cognito_user_id']:
# endpoint without auth
return event
if event['is_system']:
# is system user is making a request it should provide customer_id
# as a parameter to make a request on his behalf.
if (event['resource'], event['method']) in self.can_work_without_customer_id: # noqa
return event
cid = (event['query'].get('customer_id')
or event['body'].get('customer_id'))
if not cid:
raise ResponseFactory(HTTPStatus.BAD_REQUEST).message(
'Please, provide customer_id param to make a request on '
'his behalf'
).exc()
if not self._cs.get(cid):
raise ResponseFactory(HTTPStatus.BAD_REQUEST).message(
f'Customer {cid} does not exist. You cannot make a request'
f' on his behalf'
).exc()
return event
match event['method']:
case HTTPMethod.GET:
event['query']['customer_id'] = event['cognito_customer']
case _:
event['body']['customer_id'] = event['cognito_customer']
return event