-
Notifications
You must be signed in to change notification settings - Fork 583
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(util-endpoints): check for entire resource-path being empty (#6380)
- Loading branch information
Showing
3 changed files
with
22 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,31 @@ | ||
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[0].includes(RESOURCE_DELIMITER) | ||
? resourcePath[0].split(RESOURCE_DELIMITER) | ||
: resourcePath; | ||
|
||
return { | ||
partition, | ||
service, | ||
region, | ||
accountId, | ||
resourceId: resourceId[0].includes("/") ? resourceId[0].split("/") : resourceId, | ||
resourceId, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters