Skip to content

Commit fcbd78b

Browse files
committed
fix: fixed services that returned only the first page of paged results
1 parent 13d0560 commit fcbd78b

25 files changed

Lines changed: 343 additions & 263 deletions

File tree

src/services/apiGatewayResource/data.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,9 @@ const getResources = async ({ apiGw, restApiId }): Promise<ListOfResource> =>
6666

6767
if (position) {
6868
listAllResources(position)
69+
} else {
70+
resolve(resourceList)
6971
}
70-
71-
resolve(resourceList)
7272
}
7373
)
7474
} catch (error) {

src/services/apiGatewayRestApi/data.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,9 @@ export const getRestApisForRegion = async (
6464

6565
if (position) {
6666
listAllRestApis(position)
67+
} else {
68+
resolve(restApiList)
6769
}
68-
69-
resolve(restApiList)
7070
})
7171
} catch (error) {
7272
resolve([])

src/services/cloud9/data.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,17 @@ const errorLog = new AwsErrorLog(serviceName)
2828
const endpoint = initTestEndpoint(serviceName)
2929
const MAX_ITEMS = 25
3030

31-
const listEnvironmentsForRegion = async ({ cloud9, resolveRegion }) =>
31+
const listEnvironmentsForRegion = async ({
32+
cloud9,
33+
resolveRegion,
34+
}: {
35+
cloud9: Cloud9
36+
resolveRegion: () => void
37+
}): Promise<EnvironmentId[]> =>
3238
new Promise<EnvironmentId[]>(resolve => {
3339
const environmentIdList: EnvironmentIdList = []
3440
const listEnvironmentsOpts: ListEnvironmentsRequest = {}
35-
const listAllEnvironments = (token?: string) => {
41+
const listAllEnvironments = (token?: string): void => {
3642
if (token) {
3743
listEnvironmentsOpts.nextToken = token
3844
}
@@ -61,9 +67,9 @@ const listEnvironmentsForRegion = async ({ cloud9, resolveRegion }) =>
6167
lt.foundMoreCloud9Environments(environmentIds.length)
6268
)
6369
listAllEnvironments(nextToken)
70+
} else {
71+
resolve(environmentIdList)
6472
}
65-
66-
resolve(environmentIdList)
6773
}
6874
)
6975
} catch (error) {

src/services/cloudFormationStack/data.ts

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -42,24 +42,28 @@ const getAllStacks = async (cf: CloudFormation): Promise<Stack[]> =>
4242
opts.NextToken = token
4343
}
4444

45-
cf.describeStacks(opts, (err: AWSError, data: DescribeStacksOutput) => {
46-
const { Stacks = [], NextToken } = data || {}
47-
48-
if (err) {
49-
errorLog.generateAwsErrorLog({
50-
functionName: 'CloudFormationStack:describeStacks',
51-
err,
52-
})
53-
}
45+
try {
46+
cf.describeStacks(opts, (err: AWSError, data: DescribeStacksOutput) => {
47+
const { Stacks = [], NextToken } = data || {}
5448

55-
fullStacks.push(...Stacks)
49+
if (err) {
50+
errorLog.generateAwsErrorLog({
51+
functionName: 'CloudFormationStack:describeStacks',
52+
err,
53+
})
54+
}
5655

57-
if (NextToken) {
58-
listAllStacks(NextToken)
59-
}
56+
fullStacks.push(...Stacks)
6057

61-
resolve(fullStacks)
62-
})
58+
if (NextToken) {
59+
listAllStacks(NextToken)
60+
} else {
61+
resolve(fullStacks)
62+
}
63+
})
64+
} catch (error) {
65+
resolve([])
66+
}
6367
}
6468
listAllStacks()
6569
})

src/services/cloudfront/data.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,9 @@ const listCloudfrontDistributions = async (
7575

7676
if (IsTruncated) {
7777
listDistributions(nextToken)
78+
} else {
79+
resolve(distributions)
7880
}
79-
80-
resolve(distributions)
8181
}
8282
)
8383
}

src/services/cloudwatch/data.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,9 @@ const listMetricAlarmsForRegion = async ({
7676
if (nextToken) {
7777
logger.debug(lt.foundMoreCloudwatchAlarms(metricAlarms.length))
7878
listAllAlarms(nextToken)
79+
} else {
80+
resolve(metricAlarmsList)
7981
}
80-
81-
resolve(metricAlarmsList)
8282
}
8383
)
8484
} catch (error) {
@@ -88,7 +88,10 @@ const listMetricAlarmsForRegion = async ({
8888
listAllAlarms()
8989
})
9090

91-
const getResourceTags = async (cloudwatch: CloudWatch, arn: string) =>
91+
const getResourceTags = async (
92+
cloudwatch: CloudWatch,
93+
arn: string
94+
): Promise<TagMap> =>
9295
new Promise<TagMap>(resolve => {
9396
try {
9497
cloudwatch.listTagsForResource(

src/services/cloudwatchLogs/data.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,9 @@ const listLogGroupsForRegion = async ({
7676
region,
7777
}))
7878

79-
resolve(logGroupsData)
79+
if (!nextToken) {
80+
resolve(logGroupsData)
81+
}
8082
}
8183
)
8284
} catch (error) {

src/services/ebs/data.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,10 +123,13 @@ const listEbsVolumes = async ({
123123
const ebsVolumes = []
124124

125125
for (const { Tags, SnapshotId, ...volume } of volumes) {
126-
const snapshotAttributes = await listEbsSnapshotAttribute({
127-
ec2,
128-
snapshotId: SnapshotId,
129-
})
126+
let snapshotAttributes: CreateVolumePermission[] = []
127+
if (SnapshotId) {
128+
snapshotAttributes = await listEbsSnapshotAttribute({
129+
ec2,
130+
snapshotId: SnapshotId,
131+
})
132+
}
130133
ebsVolumes.push({
131134
...volume,
132135
region,

src/services/ecr/data.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,10 @@ const listReposForRegion = async ({
6464
if (nextToken) {
6565
logger.debug(lt.foundMoreECRRepos(repositories.length))
6666
listAllRepos(nextToken)
67+
} else {
68+
logger.debug(lt.fetchedECRRepos(repositoryList.length))
69+
resolve(repositoryList)
6770
}
68-
69-
logger.debug(lt.fetchedECRRepos(repositoryList.length))
70-
resolve(repositoryList)
7171
}
7272
)
7373
} catch (error) {

src/services/eksCluster/data.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,17 @@ const errorLog = new AwsErrorLog(serviceName)
2323
const endpoint = initTestEndpoint(serviceName)
2424
const MAX_ITEMS = 100
2525

26-
const listClustersForRegion = async ({ eks, resolveRegion }) =>
26+
const listClustersForRegion = async ({
27+
eks,
28+
resolveRegion,
29+
}: {
30+
eks: EKS
31+
resolveRegion: () => void
32+
}): Promise<string[]> =>
2733
new Promise<string[]>(resolve => {
2834
const clusterList: string[] = []
2935
const listClustersOpts: ListClustersRequest = {}
30-
const listAllClusters = (token?: string) => {
36+
const listAllClusters = (token?: string): void => {
3137
listClustersOpts.maxResults = MAX_ITEMS
3238
if (token) {
3339
listClustersOpts.nextToken = token
@@ -55,9 +61,10 @@ const listClustersForRegion = async ({ eks, resolveRegion }) =>
5561
if (nextToken) {
5662
logger.debug(lt.foundMoreEKSClusters(clusters.length))
5763
listAllClusters(nextToken)
64+
} else {
65+
resolve(clusterList)
5866
}
5967

60-
resolve(clusterList)
6168
}
6269
)
6370
} catch (error) {

0 commit comments

Comments
 (0)