@@ -32,12 +32,17 @@ export const isBucketNameOptions = (
32
32
options : BucketHostnameParams | ArnHostnameParams
33
33
) : options is BucketHostnameParams => typeof options . bucketName === "string" ;
34
34
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
+ */
35
39
export const getPseudoRegion = ( region : string ) => ( isFipsRegion ( region ) ? region . replace ( / f i p s - | - f i p s / , "" ) : region ) ;
36
40
37
41
/**
38
42
* Determines whether a given string is DNS compliant per the rules outlined by
39
43
* S3. Length, capitaization, and leading dot restrictions are enforced by the
40
44
* DOMAIN_PATTERN regular expression.
45
+ * @internal
41
46
*
42
47
* @see https://docs.aws.amazon.com/AmazonS3/latest/dev/BucketRestrictions.html
43
48
*/
@@ -52,6 +57,12 @@ const getRegionalSuffix = (hostname: string): [string, string] => {
52
57
export const getSuffix = ( hostname : string ) : [ string , string ] =>
53
58
S3_US_EAST_1_ALTNAME_PATTERN . test ( hostname ) ? [ "us-east-1" , AWS_PARTITION_SUFFIX ] : getRegionalSuffix ( hostname ) ;
54
59
60
+ /**
61
+ * Infer region and hostname suffix from a complete hostname
62
+ * @internal
63
+ * @param hostname - Hostname
64
+ * @returns [Region, Hostname suffix]
65
+ */
55
66
export const getSuffixForArnEndpoint = ( hostname : string ) : [ string , string ] =>
56
67
S3_US_EAST_1_ALTNAME_PATTERN . test ( hostname )
57
68
? [ hostname . replace ( `.${ AWS_PARTITION_SUFFIX } ` , "" ) , AWS_PARTITION_SUFFIX ]
@@ -91,12 +102,22 @@ export const validateOutpostService = (service: string) => {
91
102
}
92
103
} ;
93
104
105
+ /**
106
+ * Validate partition inferred from ARN is the same to `options.clientPartition`.
107
+ * @internal
108
+ */
94
109
export const validatePartition = ( partition : string , options : { clientPartition : string } ) => {
95
110
if ( partition !== options . clientPartition ) {
96
111
throw new Error ( `Partition in ARN is incompatible, got "${ partition } " but expected "${ options . clientPartition } "` ) ;
97
112
}
98
113
} ;
99
114
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
+ */
100
121
export const validateRegion = (
101
122
region : string ,
102
123
options : {
@@ -125,12 +146,20 @@ const isFipsRegion = (region: string) => region.startsWith("fips-") || region.en
125
146
const isEqualRegions = ( regionA : string , regionB : string ) =>
126
147
regionA === regionB || getPseudoRegion ( regionA ) === regionB || regionA === getPseudoRegion ( regionB ) ;
127
148
149
+ /**
150
+ * Validate an account ID
151
+ * @internal
152
+ */
128
153
export const validateAccountId = ( accountId : string ) => {
129
154
if ( ! / [ 0 - 9 ] { 12 } / . exec ( accountId ) ) {
130
155
throw new Error ( "Access point ARN accountID does not match regex '[0-9]{12}'" ) ;
131
156
}
132
157
} ;
133
158
159
+ /**
160
+ * Validate a host label according to https://tools.ietf.org/html/rfc3986#section-3.2.2
161
+ * @internal
162
+ */
134
163
export const validateDNSHostLabel = ( label : string , options : { tlsCompatible ?: boolean } = { tlsCompatible : true } ) => {
135
164
// reference: https://tools.ietf.org/html/rfc3986#section-3.2.2
136
165
if (
@@ -144,6 +173,13 @@ export const validateDNSHostLabel = (label: string, options: { tlsCompatible?: b
144
173
}
145
174
} ;
146
175
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
+ */
147
183
export const getArnResources = (
148
184
resource : string
149
185
) : {
@@ -172,10 +208,18 @@ export const getArnResources = (
172
208
}
173
209
} ;
174
210
211
+ /**
212
+ * Throw if dual stack configuration is set to true.
213
+ * @internal
214
+ */
175
215
export const validateNoDualstack = ( dualstackEndpoint : boolean ) => {
176
216
if ( dualstackEndpoint ) throw new Error ( "Dualstack endpoint is not supported with Outpost" ) ;
177
217
} ;
178
218
219
+ /**
220
+ * Validate region is not appended or prepended with a `fips-`
221
+ * @internal
222
+ */
179
223
export const validateNoFIPS = ( region : string ) => {
180
224
if ( isFipsRegion ( region ?? "" ) ) throw new Error ( `FIPS region is not supported with Outpost, got ${ region } ` ) ;
181
225
} ;
0 commit comments