Skip to content

Commit

Permalink
fix: fixed invalid ssm order
Browse files Browse the repository at this point in the history
  • Loading branch information
mbret committed May 26, 2024
1 parent f4b8969 commit b34932c
Showing 1 changed file with 24 additions and 6 deletions.
30 changes: 24 additions & 6 deletions packages/api/src/libs/ssm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,27 @@ export const getParameterValue = (
export const getParametersValue = (options: {
Names: ParameterName[]
WithDecryption: boolean
}) =>
ssm
.send(new GetParametersCommand(options))
.then(
(value) => value.Parameters?.map((parameter) => parameter.Value) ?? []
)
}) => {
/**
* parameters are not necessary in the same order when we get them
* so we will reorder them
*/
const orderMap = options.Names.reduce(
(acc, value, index) => {
acc[value as string] = index

return acc
},
{} as Record<string, number>
)

return ssm.send(new GetParametersCommand(options)).then(
(value) =>
value.Parameters?.slice()
.sort(
(a, b) =>
(orderMap[a.Name ?? ``] ?? 1) - (orderMap[b.Name ?? ``] ?? 1)
)
.map((parameter) => parameter.Value) ?? []
)
}

0 comments on commit b34932c

Please sign in to comment.