@@ -41,11 +41,16 @@ const handlers: SQSFunctionPayloadTypes = {
4141export const runEnvironment = process . env . RunEnvironment as RunEnvironment ;
4242export const currentEnvironmentConfig = environmentConfig [ runEnvironment ] ;
4343
44+ const restrictedQueues : Record < string , AvailableSQSFunctions [ ] > = {
45+ "infra-core-api-sqs-sales" : [ AvailableSQSFunctions . SendSaleEmail ] ,
46+ } ;
47+
4448export const handler = middy ( )
4549 . use ( eventNormalizerMiddleware ( ) )
4650 . use ( sqsPartialBatchFailure ( ) )
4751 . handler ( ( event : SQSEvent , _context : Context , { signal : _signal } ) => {
4852 const recordsPromises = event . Records . map ( async ( record , _index ) => {
53+ const sourceQueue = record . eventSourceARN . split ( ":" ) . slice ( - 1 ) [ 0 ] ;
4954 try {
5055 let parsedBody = parseSQSPayload ( record . body ) ;
5156 if ( parsedBody instanceof ZodError ) {
@@ -58,6 +63,13 @@ export const handler = middy()
5863 } ) ;
5964 }
6065 parsedBody = parsedBody as AnySQSPayload ;
66+ if (
67+ restrictedQueues [ sourceQueue ] ?. includes ( parsedBody . function ) === false
68+ ) {
69+ throw new ValidationError ( {
70+ message : `Queue ${ sourceQueue } is not permitted to call the function ${ parsedBody . function } !` ,
71+ } ) ;
72+ }
6173 const childLogger = logger . child ( {
6274 sqsMessageId : record . messageId ,
6375 metadata : parsedBody . metadata ,
0 commit comments