-
Notifications
You must be signed in to change notification settings - Fork 598
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(middleware-sdk-s3-control): ignore IP address in host prefix dedu…
…pe (#4944)
- Loading branch information
Showing
5 changed files
with
39 additions
and
3 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
11 changes: 8 additions & 3 deletions
11
packages/middleware-sdk-s3-control/src/host-prefix-deduplication/deduplicateHostPrefix.ts
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,11 +1,16 @@ | ||
import { isIpAddress } from "@aws-sdk/util-endpoints"; | ||
|
||
/** | ||
* @example | ||
* 12345.12345.____.com should become 12345.____.com. | ||
*/ | ||
export const deduplicateHostPrefix = (hostname: string): string => { | ||
const [prefix1, prefix2, ...rest] = hostname.split("."); | ||
if (prefix1 === prefix2) { | ||
return [prefix1, ...rest].join("."); | ||
const [p1, p2, p3, p4, ...rest] = hostname.split("."); | ||
if (isIpAddress(`${p1}.${p2}.${p3}.${parseInt(p4, 10)}`)) { | ||
return hostname; | ||
} | ||
if (p1 === p2) { | ||
return [p2, p3, p4, ...rest].join("."); | ||
} | ||
return hostname; | ||
}; |
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,3 +1,4 @@ | ||
export * from "./lib/aws/partition"; | ||
export * from "./lib/isIpAddress"; | ||
export * from "./resolveEndpoint"; | ||
export * from "./types"; |