Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions packages/util-endpoints/src/lib/aws/parseArn.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,16 @@ describe(parseArn.name, () => {
resourceId: ["accesspoint", "myendpoint"],
},
],
[
"arn:aws:s3:us-west-2:123456789012::myendpoint",
{
partition: "aws",
service: "s3",
region: "us-west-2",
accountId: "123456789012",
resourceId: ["", "myendpoint"],
},
],
[
"arn:aws:s3:us-west-2:123456789012:accesspoint/myendpoint",
{
Expand Down Expand Up @@ -64,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) => {
Expand Down
13 changes: 9 additions & 4 deletions packages/util-endpoints/src/lib/aws/parseArn.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,29 @@
import { EndpointARN } from "@smithy/types";

const ARN_DELIMITER = ":";
const RESOURCE_DELIMITER = "/";

/**
* Evaluates a single string argument value, and returns an object containing
* details about the parsed ARN.
* If the input was not a valid ARN, the function returns null.
*/
export const parseArn = (value: string): EndpointARN | null => {
const segments = value.split(":");
const segments = value.split(ARN_DELIMITER);

if (segments.length < 6) return null;

const [arn, partition, service, region, accountId, ...resourceId] = segments;
const [arn, partition, service, region, accountId, ...resourcePath] = segments;

if (arn !== "arn" || partition === "" || service === "" || resourcePath.join(ARN_DELIMITER) === "") return null;

if (arn !== "arn" || partition === "" || service === "" || resourceId[0] === "") return null;
const resourceId = resourcePath.map((resource) => resource.split(RESOURCE_DELIMITER)).flat();

return {
partition,
service,
region,
accountId,
resourceId: resourceId[0].includes("/") ? resourceId[0].split("/") : resourceId,
resourceId,
};
};
5 changes: 1 addition & 4 deletions tests/endpoints-2.0/endpoints-integration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,7 @@ function runTestCases(service: ServiceModel, namespace: ServiceNamespace) {
const observedError = await (async () => defaultEndpointResolver(endpointParams as any))().catch(pass);
expect(observedError).not.toBeUndefined();
expect(observedError?.url).toBeUndefined();
// ToDo: debug why 'client-s3 > empty arn type' test case is failing
if (serviceId !== "s3" && documentation !== "empty arn type") {
expect(normalizeQuotes(String(observedError))).toContain(normalizeQuotes(error));
}
expect(normalizeQuotes(String(observedError))).toContain(normalizeQuotes(error));
}
}
});
Expand Down