Skip to content

Commit 5f73604

Browse files
committed
docs(middleware-bucket-endpoint): add docs
1 parent 6f56381 commit 5f73604

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

packages/middleware-bucket-endpoint/src/bucketHostnameUtils.ts

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,17 @@ export const isBucketNameOptions = (
3232
options: BucketHostnameParams | ArnHostnameParams
3333
): options is BucketHostnameParams => typeof options.bucketName === "string";
3434

35+
/**
36+
* Get pseudo region from supplied region. For example, if supplied with `fips-us-west-2`, it returns `us-west-2`.
37+
* @internal
38+
*/
3539
export const getPseudoRegion = (region: string) => (isFipsRegion(region) ? region.replace(/fips-|-fips/, "") : region);
3640

3741
/**
3842
* Determines whether a given string is DNS compliant per the rules outlined by
3943
* S3. Length, capitaization, and leading dot restrictions are enforced by the
4044
* DOMAIN_PATTERN regular expression.
45+
* @internal
4146
*
4247
* @see https://docs.aws.amazon.com/AmazonS3/latest/dev/BucketRestrictions.html
4348
*/
@@ -52,6 +57,12 @@ const getRegionalSuffix = (hostname: string): [string, string] => {
5257
export const getSuffix = (hostname: string): [string, string] =>
5358
S3_US_EAST_1_ALTNAME_PATTERN.test(hostname) ? ["us-east-1", AWS_PARTITION_SUFFIX] : getRegionalSuffix(hostname);
5459

60+
/**
61+
* Infer region and hostname suffix from a complete hostname
62+
* @internal
63+
* @param hostname - Hostname
64+
* @returns [Region, Hostname suffix]
65+
*/
5566
export const getSuffixForArnEndpoint = (hostname: string): [string, string] =>
5667
S3_US_EAST_1_ALTNAME_PATTERN.test(hostname)
5768
? [hostname.replace(`.${AWS_PARTITION_SUFFIX}`, ""), AWS_PARTITION_SUFFIX]
@@ -91,12 +102,22 @@ export const validateOutpostService = (service: string) => {
91102
}
92103
};
93104

105+
/**
106+
* Validate partition inferred from ARN is the same to `options.clientPartition`.
107+
* @internal
108+
*/
94109
export const validatePartition = (partition: string, options: { clientPartition: string }) => {
95110
if (partition !== options.clientPartition) {
96111
throw new Error(`Partition in ARN is incompatible, got "${partition}" but expected "${options.clientPartition}"`);
97112
}
98113
};
99114

115+
/**
116+
* validate region value inferred from ARN. If `options.useArnRegion` is set, it validates the region is not a FIPS
117+
* region. If `options.useArnRegion` is unset, it validates the region is equal to `options.clientRegion` or
118+
* `options.clientSigningRegion`.
119+
* @internal
120+
*/
100121
export const validateRegion = (
101122
region: string,
102123
options: {
@@ -125,12 +146,20 @@ const isFipsRegion = (region: string) => region.startsWith("fips-") || region.en
125146
const isEqualRegions = (regionA: string, regionB: string) =>
126147
regionA === regionB || getPseudoRegion(regionA) === regionB || regionA === getPseudoRegion(regionB);
127148

149+
/**
150+
* Validate an account ID
151+
* @internal
152+
*/
128153
export const validateAccountId = (accountId: string) => {
129154
if (!/[0-9]{12}/.exec(accountId)) {
130155
throw new Error("Access point ARN accountID does not match regex '[0-9]{12}'");
131156
}
132157
};
133158

159+
/**
160+
* Validate a host label according to https://tools.ietf.org/html/rfc3986#section-3.2.2
161+
* @internal
162+
*/
134163
export const validateDNSHostLabel = (label: string, options: { tlsCompatible?: boolean } = { tlsCompatible: true }) => {
135164
// reference: https://tools.ietf.org/html/rfc3986#section-3.2.2
136165
if (
@@ -144,6 +173,13 @@ export const validateDNSHostLabel = (label: string, options: { tlsCompatible?: b
144173
}
145174
};
146175

176+
/**
177+
* Validate and parse an Access Point ARN or Outposts ARN
178+
* @internal
179+
*
180+
* @param resource - The resource section of an ARN
181+
* @returns Access Point Name and optional Outpost ID.
182+
*/
147183
export const getArnResources = (
148184
resource: string
149185
): {
@@ -172,10 +208,18 @@ export const getArnResources = (
172208
}
173209
};
174210

211+
/**
212+
* Throw if dual stack configuration is set to true.
213+
* @internal
214+
*/
175215
export const validateNoDualstack = (dualstackEndpoint: boolean) => {
176216
if (dualstackEndpoint) throw new Error("Dualstack endpoint is not supported with Outpost");
177217
};
178218

219+
/**
220+
* Validate region is not appended or prepended with a `fips-`
221+
* @internal
222+
*/
179223
export const validateNoFIPS = (region: string) => {
180224
if (isFipsRegion(region ?? "")) throw new Error(`FIPS region is not supported with Outpost, got ${region}`);
181225
};

0 commit comments

Comments
 (0)