3
3
checkPaidMembershipFromRedis ,
4
4
checkExternalMembership ,
5
5
MEMBER_CACHE_SECONDS ,
6
- checkPaidMembershipFromEntra ,
7
6
setPaidMembershipInTable ,
8
7
} from "api/functions/membership.js" ;
9
8
import { FastifyPluginAsync } from "fastify" ;
@@ -321,47 +320,10 @@ const membershipV2Plugin: FastifyPluginAsync = async (fastify, _options) => {
321
320
"EX" ,
322
321
MEMBER_CACHE_SECONDS ,
323
322
) ;
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
- ) ;
354
323
} else {
355
324
notMembers . add ( netId ) ;
356
325
}
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
+ }
365
327
}
366
328
}
367
329
@@ -491,32 +453,6 @@ const membershipV2Plugin: FastifyPluginAsync = async (fastify, _options) => {
491
453
. header ( "X-ACM-Data-Source" , "dynamo" )
492
454
. send ( { netId, isPaidMember : true } ) ;
493
455
}
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
- }
520
456
await setKey ( {
521
457
redisClient : fastify . redisClient ,
522
458
key : cacheKey ,
@@ -525,7 +461,7 @@ const membershipV2Plugin: FastifyPluginAsync = async (fastify, _options) => {
525
461
logger : request . log ,
526
462
} ) ;
527
463
return reply
528
- . header ( "X-ACM-Data-Source" , "aad " )
464
+ . header ( "X-ACM-Data-Source" , "dynamo " )
529
465
. send ( { netId, isPaidMember : false } ) ;
530
466
} ,
531
467
) ;
0 commit comments