From 855f1fa613997ff2c2c0a08412e58c041911e834 Mon Sep 17 00:00:00 2001 From: "Kamat, Trivikram" <16024985+trivikr@users.noreply.github.com> Date: Tue, 13 Aug 2024 14:15:29 +0000 Subject: [PATCH] fix(util-endpoints): handle case when resourcePath contains both delimiters --- packages/util-endpoints/src/lib/aws/parseArn.spec.ts | 10 ++++++++++ packages/util-endpoints/src/lib/aws/parseArn.ts | 4 +--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/packages/util-endpoints/src/lib/aws/parseArn.spec.ts b/packages/util-endpoints/src/lib/aws/parseArn.spec.ts index 3b715868c92f..16e0342dae98 100644 --- a/packages/util-endpoints/src/lib/aws/parseArn.spec.ts +++ b/packages/util-endpoints/src/lib/aws/parseArn.spec.ts @@ -74,6 +74,16 @@ describe(parseArn.name, () => { resourceId: ["myTopic"], }, ], + [ + "arn:aws:s3:us-west-2:123456789012:my:folder/my:file", + { + partition: "aws", + service: "s3", + region: "us-west-2", + accountId: "123456789012", + resourceId: ["my", "folder", "my", "file"], + }, + ], ]; it.each(VALID_TEST_CASES)("returns for valid arn %s", (input: string, outout: EndpointARN) => { diff --git a/packages/util-endpoints/src/lib/aws/parseArn.ts b/packages/util-endpoints/src/lib/aws/parseArn.ts index 99ce11f55c65..2c6078b647b5 100644 --- a/packages/util-endpoints/src/lib/aws/parseArn.ts +++ b/packages/util-endpoints/src/lib/aws/parseArn.ts @@ -17,9 +17,7 @@ export const parseArn = (value: string): EndpointARN | null => { if (arn !== "arn" || partition === "" || service === "" || resourcePath.join(ARN_DELIMITER) === "") return null; - const resourceId = resourcePath[0].includes(RESOURCE_DELIMITER) - ? resourcePath[0].split(RESOURCE_DELIMITER) - : resourcePath; + const resourceId = resourcePath.map((resource) => resource.split(RESOURCE_DELIMITER)).flat(); return { partition,