fix: fix wrong client selection

This commit is contained in:
2024-12-26 11:53:29 +09:00
parent ab74b2fcfa
commit eb30242fe1
7 changed files with 14 additions and 11 deletions

View File

@ -15,14 +15,17 @@ import shajs from 'sha.js'
export class Memorizer {
private static memorized = new Map<string, Memorizer>()
public static memo (client: Client<any, any, any, any>) {
const memorized = this.memorized.get(client.constructor.name)
public static memo (client: Client<any, any, any, any>, salt = '') {
const serialized = JSON.stringify([client.constructor.name, salt])
const hashed = shajs('sha256').update(serialized).digest('hex')
const memorized = this.memorized.get(hashed)
if (memorized !== undefined)
return memorized
const newMemo = new Memorizer(client)
this.memorized.set(client.constructor.name, newMemo)
this.memorized.set(hashed, newMemo)
return newMemo
}

View File

@ -38,9 +38,9 @@ export class IAMPolicyNoStatementsWithAdminAccess implements BPSet {
for (const statement of statements) {
if (
statement.Action === '*' &&
statement.Resource === '*' &&
statement.Effect === 'Allow'
statement?.Action === '*' &&
statement?.Resource === '*' &&
statement?.Effect === 'Allow'
) {
nonCompliantResources.push(policy.Arn!)
break

View File

@ -26,7 +26,7 @@ export class S3LastBackupRecoveryPointCreated implements BPSet {
const buckets = await this.getBuckets()
for (const bucket of buckets) {
const recoveryPoints = await this.memoClient.send(
const recoveryPoints = await this.backupClient.send(
new ListRecoveryPointsByResourceCommand({
ResourceArn: `arn:aws:s3:::${bucket.Name!}`
})

View File

@ -11,7 +11,7 @@ export class WAFv2LoggingEnabled implements BPSet {
private readonly regionalClient = new WAFV2Client({});
private readonly globalClient = new WAFV2Client({ region: 'us-east-1' });
private readonly memoRegionalClient = Memorizer.memo(this.regionalClient);
private readonly memoGlobalClient = Memorizer.memo(this.globalClient);
private readonly memoGlobalClient = Memorizer.memo(this.globalClient, 'global');
private readonly getWebACLs = async (scope: 'REGIONAL' | 'CLOUDFRONT') => {
const client = scope === 'REGIONAL' ? this.memoRegionalClient : this.memoGlobalClient;

View File

@ -11,7 +11,7 @@ export class WAFv2RuleGroupLoggingEnabled implements BPSet {
private readonly regionalClient = new WAFV2Client({});
private readonly globalClient = new WAFV2Client({ region: 'us-east-1' });
private readonly memoRegionalClient = Memorizer.memo(this.regionalClient);
private readonly memoGlobalClient = Memorizer.memo(this.globalClient);
private readonly memoGlobalClient = Memorizer.memo(this.globalClient, 'global');
private readonly getRuleGroups = async (scope: 'REGIONAL' | 'CLOUDFRONT') => {
const client = scope === 'REGIONAL' ? this.memoRegionalClient : this.memoGlobalClient;

View File

@ -11,7 +11,7 @@ export class WAFv2RuleGroupNotEmpty implements BPSet {
private readonly regionalClient = new WAFV2Client({});
private readonly globalClient = new WAFV2Client({ region: 'us-east-1' });
private readonly memoRegionalClient = Memorizer.memo(this.regionalClient);
private readonly memoGlobalClient = Memorizer.memo(this.globalClient);
private readonly memoGlobalClient = Memorizer.memo(this.globalClient, 'global');
private readonly getRuleGroups = async (scope: 'REGIONAL' | 'CLOUDFRONT') => {
const client = scope === 'REGIONAL' ? this.memoRegionalClient : this.memoGlobalClient;

View File

@ -11,7 +11,7 @@ export class WAFv2WebACLNotEmpty implements BPSet {
private readonly regionalClient = new WAFV2Client({});
private readonly globalClient = new WAFV2Client({ region: 'us-east-1' });
private readonly memoRegionalClient = Memorizer.memo(this.regionalClient);
private readonly memoGlobalClient = Memorizer.memo(this.globalClient);
private readonly memoGlobalClient = Memorizer.memo(this.globalClient, 'global');
private readonly getWebACLs = async (scope: 'REGIONAL' | 'CLOUDFRONT') => {
const client = scope === 'REGIONAL' ? this.memoRegionalClient : this.memoGlobalClient;