Skip to content

Commit 9c5bbc3

Browse files
committed
fix(client-s3): defer endpoint validations to ruleset
1 parent f02693b commit 9c5bbc3

File tree

19 files changed

+278
-123
lines changed

19 files changed

+278
-123
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-control/src/models/models_1.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import {
1919
StorageLensTag,
2020
Tag,
2121
} from "./models_0";
22-
2322
import { S3ControlServiceException as __BaseException } from "./S3ControlServiceException";
2423

2524
/**

clients/client-s3/src/S3Client.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -755,9 +755,9 @@ 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
*/
760-
useArnRegion?: boolean | Provider<boolean>;
760+
useArnRegion?: boolean | undefined | Provider<boolean | undefined>;
761761
/**
762762
* The internal function that inject utilities to runtime-specific stream to help users consume the data
763763
* @internal

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/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,
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: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import software.amazon.smithy.model.Model;
3434
import software.amazon.smithy.model.knowledge.OperationIndex;
3535
import software.amazon.smithy.model.knowledge.TopDownIndex;
36+
import software.amazon.smithy.model.pattern.SmithyPattern;
3637
import software.amazon.smithy.model.shapes.MemberShape;
3738
import software.amazon.smithy.model.shapes.OperationShape;
3839
import software.amazon.smithy.model.shapes.ServiceShape;
@@ -47,6 +48,7 @@
4748
import software.amazon.smithy.model.traits.HttpHeaderTrait;
4849
import software.amazon.smithy.model.traits.HttpPayloadTrait;
4950
import software.amazon.smithy.model.traits.StreamingTrait;
51+
import software.amazon.smithy.model.traits.Trait;
5052
import software.amazon.smithy.model.transform.ModelTransformer;
5153
import software.amazon.smithy.rulesengine.traits.EndpointRuleSetTrait;
5254
import software.amazon.smithy.typescript.codegen.LanguageTarget;
@@ -89,7 +91,23 @@ public final class AddS3Config implements TypeScriptIntegration {
8991
public static Shape removeHostPrefixTrait(Shape shape) {
9092
return shape.asOperationShape()
9193
.map(OperationShape::shapeToBuilder)
92-
.map(builder -> ((OperationShape.Builder) builder).removeTrait(EndpointTrait.ID))
94+
.map((Object object) -> {
95+
OperationShape.Builder builder = (OperationShape.Builder) object;
96+
Trait trait = builder.getAllTraits().get(EndpointTrait.ID);
97+
if (trait instanceof EndpointTrait endpointTrait) {
98+
if (
99+
endpointTrait.getHostPrefix().equals(
100+
SmithyPattern.builder()
101+
.segments(List.of())
102+
.pattern("{AccountId}.")
103+
.build()
104+
)
105+
) {
106+
builder.removeTrait(EndpointTrait.ID);
107+
}
108+
}
109+
return builder;
110+
})
93111
.map(OperationShape.Builder::build)
94112
.map(s -> (Shape) s)
95113
.orElse(shape);
@@ -224,7 +242,7 @@ public Model preprocessModel(Model model, TypeScriptSettings settings) {
224242

225243
Model builtModel = modelBuilder.addShapes(inputShapes).build();
226244
if (hasRuleset) {
227-
ModelTransformer.create().mapShapes(
245+
return ModelTransformer.create().mapShapes(
228246
builtModel, AddS3Config::removeHostPrefixTrait
229247
);
230248
}
@@ -246,9 +264,9 @@ public void addConfigInterfaceFields(
246264
.write("signingEscapePath?: boolean;\n");
247265
writer.writeDocs(
248266
"Whether to override the request region with the region inferred from requested resource's ARN."
249-
+ " Defaults to false.")
267+
+ " Defaults to undefined.")
250268
.addImport("Provider", "Provider", TypeScriptDependency.SMITHY_TYPES)
251-
.write("useArnRegion?: boolean | Provider<boolean>;");
269+
.write("useArnRegion?: boolean | undefined | Provider<boolean | undefined>;");
252270
}
253271

254272
@Override
@@ -266,7 +284,7 @@ public Map<String, Consumer<TypeScriptWriter>> getRuntimeConfigWriters(
266284
writer.write("false");
267285
},
268286
"useArnRegion", writer -> {
269-
writer.write("false");
287+
writer.write("undefined");
270288
}
271289
);
272290
case NODE:

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ describe("NODE_USE_ARN_REGION_CONFIG_OPTIONS", () => {
4444
test(configFileSelector, profileContent, NODE_USE_ARN_REGION_INI_NAME, SelectorType.CONFIG);
4545
});
4646

47-
it("returns false for default", () => {
47+
it("returns undefined for default", () => {
4848
const { default: defaultValue } = NODE_USE_ARN_REGION_CONFIG_OPTIONS;
49-
expect(defaultValue).toEqual(false);
49+
expect(defaultValue).toEqual(undefined);
5050
});
5151
});

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,15 @@ 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
*/
12-
export const NODE_USE_ARN_REGION_CONFIG_OPTIONS: LoadedConfigSelectors<boolean> = {
12+
export const NODE_USE_ARN_REGION_CONFIG_OPTIONS: LoadedConfigSelectors<boolean | undefined> = {
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+
default: undefined,
1721
};

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@ import { parse, validate } from "@aws-sdk/util-arn-parser";
1919
import { bucketEndpointMiddleware } from "./bucketEndpointMiddleware";
2020
import { bucketHostname } from "./bucketHostname";
2121

22-
describe("bucketEndpointMiddleware", () => {
22+
/**
23+
* @deprecated unused as of EndpointsV2.
24+
*/
25+
describe.skip("bucketEndpointMiddleware", () => {
2326
const input = { Bucket: "bucket" };
2427
const mockRegion = "us-foo-1";
2528
const requestInput = {

0 commit comments

Comments
 (0)