Skip to content

Commit 61744c7

Browse files
authored
chore(middleware-bucket-endpoint): include fips/dualstack checks in s3 hostname pattern (#3004)
1 parent 331c55a commit 61744c7

File tree

2 files changed

+4
-9
lines changed

2 files changed

+4
-9
lines changed

Diff for: packages/middleware-bucket-endpoint/src/bucketHostname.ts

+2-7
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,11 @@ export interface BucketHostname {
3333

3434
export const bucketHostname = (options: BucketHostnameParams | ArnHostnameParams): BucketHostname => {
3535
validateCustomEndpoint(options);
36-
37-
// TODO: Remove checks for ".dualstack" from entire middleware.
38-
const { dualstackEndpoint, baseHostname } = options;
39-
const updatedBaseHostname = dualstackEndpoint ? baseHostname.replace(".dualstack", "") : baseHostname;
40-
4136
return isBucketNameOptions(options)
4237
? // Construct endpoint when bucketName is a string referring to a bucket name
43-
getEndpointFromBucketName({ ...options, baseHostname: updatedBaseHostname })
38+
getEndpointFromBucketName(options)
4439
: // Construct endpoint when bucketName is an ARN referring to an S3 resource like Access Point
45-
getEndpointFromArn({ ...options, baseHostname: updatedBaseHostname });
40+
getEndpointFromArn(options);
4641
};
4742

4843
const getEndpointFromBucketName = ({

Diff for: packages/middleware-bucket-endpoint/src/bucketHostnameUtils.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const DOMAIN_PATTERN = /^[a-z0-9][a-z0-9\.\-]{1,61}[a-z0-9]$/;
44
const IP_ADDRESS_PATTERN = /(\d+\.){3}\d+/;
55
const DOTS_PATTERN = /\.\./;
66
export const DOT_PATTERN = /\./;
7-
export const S3_HOSTNAME_PATTERN = /^(.+\.)?s3[.-]([a-z0-9-]+)\./;
7+
export const S3_HOSTNAME_PATTERN = /^(.+\.)?s3(-fips)?(\.dualstack)?[.-]([a-z0-9-]+)\./;
88
const S3_US_EAST_1_ALTNAME_PATTERN = /^s3(-external-1)?\.amazonaws\.com$/;
99
const AWS_PARTITION_SUFFIX = "amazonaws.com";
1010

@@ -49,7 +49,7 @@ export const isDnsCompatibleBucketName = (bucketName: string): boolean =>
4949

5050
const getRegionalSuffix = (hostname: string): [string, string] => {
5151
const parts = hostname.match(S3_HOSTNAME_PATTERN)!;
52-
return [parts[2], hostname.replace(new RegExp(`^${parts[0]}`), "")];
52+
return [parts[4], hostname.replace(new RegExp(`^${parts[0]}`), "")];
5353
};
5454

5555
export const getSuffix = (hostname: string): [string, string] =>

0 commit comments

Comments
 (0)