11import asyncio
22import logging
33import uuid
4+ from typing import Annotated
45
56import httpx
7+ from fastapi import Depends
68from openg2p_fastapi_common .controller import BaseController
9+ from openg2p_g2pconnect_common_lib .jwt_signature_validator import JWTSignatureValidator
710from openg2p_g2pconnect_common_lib .schemas import (
811 AsyncCallbackRequest ,
912 AsyncResponse ,
@@ -89,8 +92,21 @@ def __init__(self, **kwargs):
8992 methods = ["POST" ],
9093 )
9194
92- async def link_async (self , link_request : LinkRequest ):
95+ async def link_async (
96+ self ,
97+ link_request : LinkRequest ,
98+ is_signature_valid : Annotated [bool , Depends (JWTSignatureValidator ())],
99+ ):
93100 correlation_id = str (uuid .uuid4 ())
101+ try :
102+ RequestValidation .get_component ().validate_signature (is_signature_valid )
103+ except RequestValidationException as e :
104+ error_response = (
105+ AsyncResponseHelper .get_component ().construct_error_async_response (
106+ link_request , e
107+ )
108+ )
109+ return error_response
94110 await asyncio .create_task (
95111 self .handle_service_and_link_callback (link_request , correlation_id , "link" )
96112 )
@@ -99,8 +115,21 @@ async def link_async(self, link_request: LinkRequest):
99115 correlation_id ,
100116 )
101117
102- async def update_async (self , update_request : UpdateRequest ):
118+ async def update_async (
119+ self ,
120+ update_request : UpdateRequest ,
121+ is_signature_valid : Annotated [bool , Depends (JWTSignatureValidator ())],
122+ ):
103123 correlation_id = str (uuid .uuid4 ())
124+ try :
125+ RequestValidation .get_component ().validate_signature (is_signature_valid )
126+ except RequestValidationException as e :
127+ error_response = (
128+ AsyncResponseHelper .get_component ().construct_error_async_response (
129+ update_request , e
130+ )
131+ )
132+ return error_response
104133 await asyncio .create_task (
105134 self .handle_service_and_update_callback (
106135 update_request , correlation_id , "update"
@@ -111,8 +140,21 @@ async def update_async(self, update_request: UpdateRequest):
111140 correlation_id ,
112141 )
113142
114- async def resolve_async (self , resolve_request : ResolveRequest ):
143+ async def resolve_async (
144+ self ,
145+ resolve_request : ResolveRequest ,
146+ is_signature_valid : Annotated [bool , Depends (JWTSignatureValidator ())],
147+ ):
115148 correlation_id = str (uuid .uuid4 ())
149+ try :
150+ RequestValidation .get_component ().validate_signature (is_signature_valid )
151+ except RequestValidationException as e :
152+ error_response = (
153+ AsyncResponseHelper .get_component ().construct_error_async_response (
154+ resolve_request , e
155+ )
156+ )
157+ return error_response
116158 await asyncio .create_task (
117159 self .handle_service_and_resolve_callback (
118160 resolve_request , correlation_id , "resolve"
@@ -123,8 +165,21 @@ async def resolve_async(self, resolve_request: ResolveRequest):
123165 correlation_id ,
124166 )
125167
126- async def unlink_async (self , unlink_request : UnlinkRequest ):
168+ async def unlink_async (
169+ self ,
170+ unlink_request : UnlinkRequest ,
171+ is_signature_valid : Annotated [bool , Depends (JWTSignatureValidator ())],
172+ ):
127173 correlation_id = str (uuid .uuid4 ())
174+ try :
175+ RequestValidation .get_component ().validate_signature (is_signature_valid )
176+ except RequestValidationException as e :
177+ error_response = (
178+ AsyncResponseHelper .get_component ().construct_error_async_response (
179+ unlink_request , e
180+ )
181+ )
182+ return error_response
128183 try :
129184 RequestValidation .get_component ().validate_request (unlink_request )
130185 RequestValidation .get_component ().validate_unlink_async_request_header (
@@ -148,7 +203,10 @@ async def unlink_async(self, unlink_request: UnlinkRequest):
148203 )
149204
150205 async def handle_service_and_link_callback (
151- self , link_request : LinkRequest , correlation_id : str , action : str
206+ self ,
207+ link_request : LinkRequest ,
208+ correlation_id : str ,
209+ action : str ,
152210 ):
153211 try :
154212 RequestValidation .get_component ().validate_async_request (link_request )
0 commit comments