Skip to content

Commit 826dbd1

Browse files
committed
fix(services): fix waf service for global instances
1 parent 9d8654c commit 826dbd1

1 file changed

Lines changed: 25 additions & 16 deletions

File tree

src/services/wafV2WebAcl/data.ts

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -29,29 +29,31 @@ export default async ({
2929
}: {
3030
regions: string
3131
config: Config
32-
}): Promise<{[region: string]: RawAwsWafV2WebAcl[]}> => {
32+
}): Promise<{ [region: string]: RawAwsWafV2WebAcl[] }> => {
3333
const result: RawAwsWafV2WebAcl[] = []
3434

3535
const activeRegions = regions.split(',')
36-
// TODO: how to support global instances
3736
activeRegions.push('global')
3837
for (const region of activeRegions) {
39-
const client = new WAFV2({ ...config, region: region === 'global' ? 'us-east-1' : region, endpoint })
38+
const client = new WAFV2({
39+
...config,
40+
region: region === 'global' ? 'us-east-1' : region,
41+
endpoint,
42+
})
4043
const scope = region === 'global' ? scopes.cloudfront : scopes.regional
4144
const WafV2WebAclData: WebACLSummaries = []
4245
try {
43-
const { WebACLs, NextMarker } = await client.listWebACLs({ Scope: scope, Limit: 10 }).promise()
46+
const { WebACLs, NextMarker } = await client
47+
.listWebACLs({ Scope: scope, Limit: 10 })
48+
.promise()
4449
WafV2WebAclData.push(...WebACLs)
4550
let marker = NextMarker
46-
while(marker) {
47-
const { WebACLs, NextMarker } = await client.listWebACLs({ Scope: scope, Limit: 10, NextMarker: marker }).promise()
48-
// There is some issue with wafV2 where it always returns a next marker
49-
if (WebACLs.find(({ Name }) => Name === NextMarker)) {
50-
marker = undefined
51-
} else {
52-
marker = NextMarker
53-
WafV2WebAclData.push(...WebACLs)
54-
}
51+
while (marker) {
52+
const { WebACLs, NextMarker } = await client
53+
.listWebACLs({ Scope: scope, Limit: 10, NextMarker: marker })
54+
.promise()
55+
marker = NextMarker
56+
WafV2WebAclData.push(...WebACLs)
5557
}
5658
} catch (err) {
5759
errorLog.generateAwsErrorLog({ functionName: 'listWebAcls', err })
@@ -65,12 +67,19 @@ export default async ({
6567
.promise()
6668

6769
const arn = wafData?.WebACL?.ARN
68-
const loggingConfiguration = await client.getLoggingConfiguration({ ResourceArn: arn }).promise()
69-
wafData.loggingConfiguration = loggingConfiguration.LoggingConfiguration
70+
const loggingConfiguration = await client
71+
.getLoggingConfiguration({ ResourceArn: arn })
72+
.promise()
73+
wafData.loggingConfiguration =
74+
loggingConfiguration.LoggingConfiguration
7075
} catch (err) {
7176
errorLog.generateAwsErrorLog({ functionName: 'getWebACL', err })
7277
}
73-
result.push({ ...wafData?.WebACL, loggingConfiguration: wafData?.loggingConfiguration, region })
78+
result.push({
79+
...wafData?.WebACL,
80+
loggingConfiguration: wafData?.loggingConfiguration,
81+
region,
82+
})
7483
}
7584
}
7685
}

0 commit comments

Comments
 (0)