File tree Expand file tree Collapse file tree 1 file changed +8
-5
lines changed
Expand file tree Collapse file tree 1 file changed +8
-5
lines changed Original file line number Diff line number Diff line change @@ -28,7 +28,7 @@ export function createAuthorizerHandler(deps: Deps): APIGatewayRequestAuthorizer
2828
2929
3030 checkCertificateExpiry ( event . requestContext . identity . clientCert , deps )
31- . then ( ( ) => deps . supplierRepo . getSupplierByApimId ( extractApimId ( event . headers , deps ) ) )
31+ . then ( ( ) => getSupplier ( event . headers , deps ) )
3232 . then ( ( supplier : Supplier ) => {
3333 deps . logger . info ( 'Allow event' ) ;
3434 callback ( null , generateAllow ( 'me' , event . methodArn , supplier . id ) ) ;
@@ -40,15 +40,18 @@ export function createAuthorizerHandler(deps: Deps): APIGatewayRequestAuthorizer
4040 } ;
4141}
4242
43-
44- function extractApimId ( headers : APIGatewayRequestAuthorizerEventHeaders | null , deps : Deps ) : string {
43+ async function getSupplier ( headers : APIGatewayRequestAuthorizerEventHeaders | null , deps : Deps ) : Promise < Supplier > {
4544 const apimId = Object . entries ( headers || { } )
4645 . find ( ( [ headerName , _ ] ) => headerName . toLowerCase ( ) === deps . env . APIM_APPLICATION_ID_HEADER ) ?. [ 1 ] as string ;
4746
4847 if ( ! apimId ) {
49- throw new Error ( "No APIM application ID found in header" ) ;
48+ throw new Error ( 'No APIM application ID found in header' ) ;
49+ }
50+ const supplier = await deps . supplierRepo . getSupplierByApimId ( apimId ) ;
51+ if ( supplier . status === 'DISABLED' ) {
52+ throw new Error ( `Supplier ${ supplier . id } is disabled` ) ;
5053 }
51- return apimId ;
54+ return supplier ;
5255}
5356
5457
You can’t perform that action at this time.
0 commit comments