Skip to content

Commit b2d6ab8

Browse files
authored
Merge pull request #166 from cloudgraphdev/aa-sm
fix(secretsManager): get all data pages
2 parents 5dd6fb7 + 0f2cff4 commit b2d6ab8

File tree

1 file changed

+21
-22
lines changed

1 file changed

+21
-22
lines changed

src/services/secretsManager/data.ts

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -67,40 +67,39 @@ export default async ({
6767

6868
regions.split(',').map(region => {
6969
const regionPromise = new Promise<void>(resolveSecretsManagerData => {
70-
new SM({ ...config, region, endpoint }).listSecrets(
71-
{},
72-
(err: AWSError, data) => {
73-
if (err) {
74-
errorLog.generateAwsErrorLog({
75-
functionName: 'sm:listSecrets',
76-
err,
77-
})
78-
}
79-
80-
if (isEmpty(data)) {
81-
return resolveSecretsManagerData()
82-
}
70+
const sm = new SM({ ...config, region, endpoint })
8371

84-
const { SecretList: secrets = [] } = data
72+
const listAllSecrets = async ({ nextToken }): Promise<void> => {
73+
try {
74+
const { SecretList, NextToken: nt } = await sm
75+
.listSecrets({ NextToken: nextToken })
76+
.promise()
8577

86-
if (isEmpty(secrets)) {
78+
if (isEmpty(SecretList)) {
8779
return resolveSecretsManagerData()
8880
}
89-
90-
logger.debug(lt.fetchedSecretsManager(secrets.length))
91-
81+
logger.debug(lt.fetchedSecretsManager(SecretList.length))
9282
smData.push(
93-
...secrets.map(({ Tags, ...secret }) => ({
83+
...SecretList.map(({ Tags, ...secret }) => ({
9484
...secret,
9585
region,
9686
Tags: convertAwsTagsToTagMap(Tags as AwsTag[]),
9787
}))
9888
)
99-
100-
resolveSecretsManagerData()
89+
if (nt) {
90+
await listAllSecrets({ nextToken: nt })
91+
}
92+
} catch (err) {
93+
errorLog.generateAwsErrorLog({
94+
functionName: 'sm:listSecrets',
95+
err,
96+
})
10197
}
102-
)
98+
}
99+
100+
listAllSecrets({ nextToken: null }).then(resolveSecretsManagerData)
103101
})
102+
104103
regionPromises.push(regionPromise)
105104
})
106105
await Promise.all(regionPromises)

0 commit comments

Comments
 (0)