@@ -9,21 +9,54 @@ import {
99  getUserProfile , 
1010}  from  "../../api/functions/entraId.js" ; 
1111import  {  DynamoDBClient  }  from  "@aws-sdk/client-dynamodb" ; 
12- import  {  environmentConfig ,  genericConfig  }  from  "../../common/config.js" ; 
12+ import  { 
13+   environmentConfig , 
14+   genericConfig , 
15+   roleArns , 
16+ }  from  "../../common/config.js" ; 
1317import  {  SecretsManagerClient  }  from  "@aws-sdk/client-secrets-manager" ; 
1418import  {  issueAppleWalletMembershipCard  }  from  "../../api/functions/mobileWallet.js" ; 
1519import  {  generateMembershipEmailCommand  }  from  "../../api/functions/ses.js" ; 
1620import  {  SESClient  }  from  "@aws-sdk/client-ses" ; 
21+ import  pino  from  "pino" ; 
22+ import  {  getRoleCredentials  }  from  "api/functions/sts.js" ; 
23+ 
24+ const  getAuthorizedClients  =  async  ( 
25+   logger : pino . Logger , 
26+   commonConfig : {  region : string  } , 
27+ )  =>  { 
28+   if  ( roleArns . Entra )  { 
29+     logger . info ( 
30+       `Attempting to assume Entra role ${ roleArns . Entra }   to get the Entra token...` , 
31+     ) ; 
32+     const  credentials  =  await  getRoleCredentials ( roleArns . Entra ) ; 
33+     const  clients  =  { 
34+       smClient : new  SecretsManagerClient ( { 
35+         region : genericConfig . AwsRegion , 
36+         credentials, 
37+       } ) , 
38+       dynamoClient : new  DynamoDBClient ( { 
39+         region : genericConfig . AwsRegion , 
40+         credentials, 
41+       } ) , 
42+     } ; 
43+     logger . info ( `Assumed Entra role ${ roleArns . Entra }   to get the Entra token.` ) ; 
44+     return  clients ; 
45+   }  else  { 
46+     logger . debug ( "Did not assume Entra role as no env variable was present" ) ; 
47+     return  { 
48+       smClient : new  SecretsManagerClient ( commonConfig ) , 
49+       dynamoClient : new  DynamoDBClient ( commonConfig ) , 
50+     } ; 
51+   } 
52+ } ; 
1753
1854export  const  emailMembershipPassHandler : SQSHandlerFunction < 
1955  AvailableSQSFunctions . EmailMembershipPass 
2056>  =  async  ( payload ,  _metadata ,  logger )  =>  { 
2157  const  email  =  payload . email ; 
2258  const  commonConfig  =  {  region : genericConfig . AwsRegion  } ; 
23-   const  clients  =  { 
24-     smClient : new  SecretsManagerClient ( commonConfig ) , 
25-     dynamoClient : new  DynamoDBClient ( commonConfig ) , 
26-   } ; 
59+   const  clients  =  await  getAuthorizedClients ( logger ,  commonConfig ) ; 
2760  const  entraIdToken  =  await  getEntraIdToken ( 
2861    clients , 
2962    currentEnvironmentConfig . AadValidClientId , 
0 commit comments