33 checkPaidMembershipFromRedis ,
44 checkExternalMembership ,
55 MEMBER_CACHE_SECONDS ,
6- checkPaidMembershipFromEntra ,
76 setPaidMembershipInTable ,
87} from "api/functions/membership.js" ;
98import { FastifyPluginAsync } from "fastify" ;
@@ -321,47 +320,10 @@ const membershipV2Plugin: FastifyPluginAsync = async (fastify, _options) => {
321320 "EX" ,
322321 MEMBER_CACHE_SECONDS ,
323322 ) ;
324- }
325- }
326- }
327-
328- const netIdsForEntra = netIdsToCheck . filter (
329- ( id ) => ! foundInDynamo . has ( id ) ,
330- ) ;
331- if ( netIdsForEntra . length > 0 ) {
332- const entraIdToken = await getEntraIdToken ( {
333- clients : await getAuthorizedClients ( ) ,
334- clientId : fastify . environmentConfig . AadValidClientId ,
335- secretName : genericConfig . EntraSecretName ,
336- logger : request . log ,
337- } ) ;
338- const paidMemberGroup = fastify . environmentConfig . PaidMemberGroupId ;
339- const entraCheckPromises = netIdsForEntra . map ( async ( netId ) => {
340- const isMember = await checkPaidMembershipFromEntra (
341- netId ,
342- entraIdToken ,
343- paidMemberGroup ,
344- ) ;
345- if ( isMember ) {
346- members . add ( netId ) ;
347- setPaidMembershipInTable ( netId , fastify . dynamoClient ) . catch (
348- ( err ) =>
349- request . log . error (
350- err ,
351- `Failed to write back Entra membership for ${ netId } ` ,
352- ) ,
353- ) ;
354323 } else {
355324 notMembers . add ( netId ) ;
356325 }
357- cachePipeline . set (
358- `membership:${ netId } :${ list } ` ,
359- JSON . stringify ( { isMember } ) ,
360- "EX" ,
361- MEMBER_CACHE_SECONDS ,
362- ) ;
363- } ) ;
364- await Promise . all ( entraCheckPromises ) ;
326+ }
365327 }
366328 }
367329
@@ -491,32 +453,6 @@ const membershipV2Plugin: FastifyPluginAsync = async (fastify, _options) => {
491453 . header ( "X-ACM-Data-Source" , "dynamo" )
492454 . send ( { netId, isPaidMember : true } ) ;
493455 }
494- const entraIdToken = await getEntraIdToken ( {
495- clients : await getAuthorizedClients ( ) ,
496- clientId : fastify . environmentConfig . AadValidClientId ,
497- secretName : genericConfig . EntraSecretName ,
498- logger : request . log ,
499- } ) ;
500- const paidMemberGroup = fastify . environmentConfig . PaidMemberGroupId ;
501- const isAadMember = await checkPaidMembershipFromEntra (
502- netId ,
503- entraIdToken ,
504- paidMemberGroup ,
505- ) ;
506- if ( isAadMember ) {
507- await setKey ( {
508- redisClient : fastify . redisClient ,
509- key : cacheKey ,
510- data : JSON . stringify ( { isMember : true } ) ,
511- expiresIn : MEMBER_CACHE_SECONDS ,
512- logger : request . log ,
513- } ) ;
514- reply
515- . header ( "X-ACM-Data-Source" , "aad" )
516- . send ( { netId, isPaidMember : true } ) ;
517- await setPaidMembershipInTable ( netId , fastify . dynamoClient ) ;
518- return ;
519- }
520456 await setKey ( {
521457 redisClient : fastify . redisClient ,
522458 key : cacheKey ,
@@ -525,7 +461,7 @@ const membershipV2Plugin: FastifyPluginAsync = async (fastify, _options) => {
525461 logger : request . log ,
526462 } ) ;
527463 return reply
528- . header ( "X-ACM-Data-Source" , "aad " )
464+ . header ( "X-ACM-Data-Source" , "dynamo " )
529465 . send ( { netId, isPaidMember : false } ) ;
530466 } ,
531467 ) ;
0 commit comments