Skip to content

Commit e5f5eb6

Browse files
committed
fix(client-s3): defer endpoint validations to ruleset
1 parent 2e76c7e commit e5f5eb6

File tree

15 files changed

+103
-69
lines changed

15 files changed

+103
-69
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ test-integration: bundles
4141
make test-endpoints
4242

4343
test-endpoints:
44-
npx jest -c ./tests/endpoints-2.0/jest.config.js --bail --watch --verbose false
44+
npx jest -c ./tests/endpoints-2.0/jest.config.js --bail --verbose false
4545

4646
test-e2e: bundles
4747
yarn g:vitest run -c vitest.config.e2e.ts --retry=4

clients/client-s3/src/S3Client.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -755,7 +755,7 @@ export interface ClientDefaults extends Partial<__SmithyConfiguration<__HttpHand
755755
signingEscapePath?: boolean;
756756

757757
/**
758-
* Whether to override the request region with the region inferred from requested resource's ARN. Defaults to false.
758+
* Whether to override the request region with the region inferred from requested resource's ARN. Defaults to undefined.
759759
*/
760760
useArnRegion?: boolean | Provider<boolean>;
761761
/**

clients/client-s3/src/models/models_0.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// smithy-typescript generated code
22
import { ExceptionOptionType as __ExceptionOptionType, SENSITIVE_STRING } from "@smithy/smithy-client";
3-
43
import { StreamingBlobTypes } from "@smithy/types";
54

65
import { S3ServiceException as __BaseException } from "./S3ServiceException";

clients/client-s3/src/models/models_1.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// smithy-typescript generated code
22
import { ExceptionOptionType as __ExceptionOptionType, SENSITIVE_STRING } from "@smithy/smithy-client";
3-
43
import { StreamingBlobTypes } from "@smithy/types";
54

65
import {
@@ -41,7 +40,6 @@ import {
4140
Tag,
4241
TransitionDefaultMinimumObjectSize,
4342
} from "./models_0";
44-
4543
import { S3ServiceException as __BaseException } from "./S3ServiceException";
4644

4745
/**

clients/client-s3/src/protocols/Aws_restXml.ts

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,7 @@
22
import { loadRestXmlErrorCode, parseXmlBody as parseBody, parseXmlErrorBody as parseErrorBody } from "@aws-sdk/core";
33
import { XmlNode as __XmlNode, XmlText as __XmlText } from "@aws-sdk/xml-builder";
44
import { requestBuilder as rb } from "@smithy/core";
5-
import {
6-
HttpRequest as __HttpRequest,
7-
HttpResponse as __HttpResponse,
8-
isValidHostname as __isValidHostname,
9-
} from "@smithy/protocol-http";
5+
import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@smithy/protocol-http";
106
import {
117
collectBody,
128
dateToUtcString as __dateToUtcString,
@@ -3215,18 +3211,6 @@ export const se_WriteGetObjectResponseCommand = async (
32153211
contents = input.Body;
32163212
body = contents;
32173213
}
3218-
let { hostname: resolvedHostname } = await context.endpoint();
3219-
if (context.disableHostPrefix !== true) {
3220-
resolvedHostname = "{RequestRoute}." + resolvedHostname;
3221-
if (input.RequestRoute === undefined) {
3222-
throw new Error("Empty value provided for input host prefix: RequestRoute.");
3223-
}
3224-
resolvedHostname = resolvedHostname.replace("{RequestRoute}", input.RequestRoute!);
3225-
if (!__isValidHostname(resolvedHostname)) {
3226-
throw new Error("ValidationError: prefixed hostname must be hostname compatible.");
3227-
}
3228-
}
3229-
b.hn(resolvedHostname);
32303214
b.m("POST").h(headers).b(body);
32313215
return b.build();
32323216
};

clients/client-s3/src/runtimeConfig.shared.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export const getRuntimeConfig = (config: S3ClientConfig) => {
4343
signerConstructor: config?.signerConstructor ?? SignatureV4MultiRegion,
4444
signingEscapePath: config?.signingEscapePath ?? false,
4545
urlParser: config?.urlParser ?? parseUrl,
46-
useArnRegion: config?.useArnRegion ?? false,
46+
useArnRegion: config?.useArnRegion ?? (undefined as unknown as boolean),
4747
utf8Decoder: config?.utf8Decoder ?? fromUtf8,
4848
utf8Encoder: config?.utf8Encoder ?? toUtf8,
4949
};

codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/AddS3Config.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ public Model preprocessModel(Model model, TypeScriptSettings settings) {
224224

225225
Model builtModel = modelBuilder.addShapes(inputShapes).build();
226226
if (hasRuleset) {
227-
ModelTransformer.create().mapShapes(
227+
return ModelTransformer.create().mapShapes(
228228
builtModel, AddS3Config::removeHostPrefixTrait
229229
);
230230
}
@@ -246,7 +246,7 @@ public void addConfigInterfaceFields(
246246
.write("signingEscapePath?: boolean;\n");
247247
writer.writeDocs(
248248
"Whether to override the request region with the region inferred from requested resource's ARN."
249-
+ " Defaults to false.")
249+
+ " Defaults to undefined.")
250250
.addImport("Provider", "Provider", TypeScriptDependency.SMITHY_TYPES)
251251
.write("useArnRegion?: boolean | Provider<boolean>;");
252252
}
@@ -266,7 +266,7 @@ public Map<String, Consumer<TypeScriptWriter>> getRuntimeConfigWriters(
266266
writer.write("false");
267267
},
268268
"useArnRegion", writer -> {
269-
writer.write("false");
269+
writer.write("undefined as unknown as boolean");
270270
}
271271
);
272272
case NODE:

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,18 @@ export const NODE_USE_ARN_REGION_INI_NAME = "s3_use_arn_region";
77
/**
88
* Config to load useArnRegion from environment variables and shared INI files
99
*
10-
* @api private
10+
* @internal
1111
*/
1212
export const NODE_USE_ARN_REGION_CONFIG_OPTIONS: LoadedConfigSelectors<boolean> = {
1313
environmentVariableSelector: (env: NodeJS.ProcessEnv) =>
1414
booleanSelector(env, NODE_USE_ARN_REGION_ENV_NAME, SelectorType.ENV),
1515
configFileSelector: (profile) => booleanSelector(profile, NODE_USE_ARN_REGION_INI_NAME, SelectorType.CONFIG),
16-
default: false,
16+
/**
17+
* useArnRegion has specific behavior when undefined instead of false.
18+
* We therefore use undefined as the default value instead of false.
19+
*
20+
* We cast to boolean because the endpoint type system expected a boolean.
21+
* todo(endpoint) that can be fixed in the code generator dependency.
22+
*/
23+
default: undefined as unknown as boolean,
1724
};

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export const bucketEndpointMiddleware =
3434
const useFipsEndpoint = await options.useFipsEndpoint();
3535
const { partition, signingRegion = clientRegion } =
3636
(await options.regionInfoProvider(clientRegion, { useDualstackEndpoint, useFipsEndpoint })) || {};
37-
const useArnRegion = await options.useArnRegion();
37+
const useArnRegion = await options.useArnRegion?.();
3838
const {
3939
hostname,
4040
bucketEndpoint,

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -131,17 +131,17 @@ export const validateRegion = (
131131
}
132132
if (options.useFipsEndpoint) {
133133
if (!options.allowFipsRegion) {
134-
throw new Error("FIPS region is not supported");
134+
// throw new Error("FIPS region is not supported");
135135
} else if (!isEqualRegions(region, options.clientRegion)) {
136-
throw new Error(`Client FIPS region ${options.clientRegion} doesn't match region ${region} in ARN`);
136+
// throw new Error(`Client FIPS region ${options.clientRegion} doesn't match region ${region} in ARN`);
137137
}
138138
}
139139
if (
140140
!options.useArnRegion &&
141141
!isEqualRegions(region, options.clientRegion || "") &&
142142
!isEqualRegions(region, options.clientSigningRegion || "")
143143
) {
144-
throw new Error(`Region in ARN is incompatible, got ${region} but expected ${options.clientRegion}`);
144+
// throw new Error(`Region in ARN is incompatible, got ${region} but expected ${options.clientRegion}`);
145145
}
146146
};
147147

@@ -235,8 +235,9 @@ export const getArnResources = (
235235
* @internal
236236
*/
237237
export const validateNoDualstack = (dualstackEndpoint?: boolean) => {
238-
if (dualstackEndpoint)
239-
throw new Error("Dualstack endpoint is not supported with Outpost or Multi-region Access Point ARN.");
238+
if (dualstackEndpoint) {
239+
// throw new Error("Dualstack endpoint is not supported with Outpost or Multi-region Access Point ARN.");
240+
}
240241
};
241242

242243
/**

0 commit comments

Comments
 (0)