Skip to content

Commit 39a2bb5

Browse files
committed
Check for disabled supplier
1 parent d603893 commit 39a2bb5

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

lambdas/authorizer/src/authorizer.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff 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

0 commit comments

Comments
 (0)