Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ test-integration: bundles
make test-endpoints

test-endpoints:
npx jest -c ./tests/endpoints-2.0/jest.config.js --bail
npx jest -c ./tests/endpoints-2.0/jest.config.js --bail --verbose false

test-e2e: bundles
yarn g:vitest run -c vitest.config.e2e.ts --retry=4
Expand Down
1 change: 1 addition & 0 deletions clients/client-s3-control/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"@aws-crypto/sha256-js": "5.2.0",
"@aws-sdk/core": "*",
"@aws-sdk/credential-provider-node": "*",
"@aws-sdk/middleware-bucket-endpoint": "*",
"@aws-sdk/middleware-host-header": "*",
"@aws-sdk/middleware-logger": "*",
"@aws-sdk/middleware-recursion-detection": "*",
Expand Down
4 changes: 4 additions & 0 deletions clients/client-s3-control/src/S3ControlClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -707,6 +707,10 @@ export interface ClientDefaults extends Partial<__SmithyConfiguration<__HttpHand
*/
credentialDefaultProvider?: (input: any) => AwsCredentialIdentityProvider;

/**
* Whether to override the request region with the region inferred from requested resource's ARN. Defaults to undefined.
*/
useArnRegion?: boolean | undefined | Provider<boolean | undefined>;
/**
* Value for how many times a request will be made at most in case of retry.
*/
Expand Down
1 change: 0 additions & 1 deletion clients/client-s3-control/src/models/models_1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import {
StorageLensTag,
Tag,
} from "./models_0";

import { S3ControlServiceException as __BaseException } from "./S3ControlServiceException";

/**
Expand Down
1 change: 1 addition & 0 deletions clients/client-s3-control/src/runtimeConfig.shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export const getRuntimeConfig = (config: S3ControlClientConfig) => {
serviceId: config?.serviceId ?? "S3 Control",
signingEscapePath: config?.signingEscapePath ?? false,
urlParser: config?.urlParser ?? parseUrl,
useArnRegion: config?.useArnRegion ?? undefined,
utf8Decoder: config?.utf8Decoder ?? fromUtf8,
utf8Encoder: config?.utf8Encoder ?? toUtf8,
};
Expand Down
2 changes: 2 additions & 0 deletions clients/client-s3-control/src/runtimeConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import packageInfo from "../package.json"; // eslint-disable-line

import { NODE_AUTH_SCHEME_PREFERENCE_OPTIONS, emitWarningIfUnsupportedVersion as awsCheckVersion } from "@aws-sdk/core";
import { defaultProvider as credentialDefaultProvider } from "@aws-sdk/credential-provider-node";
import { NODE_USE_ARN_REGION_CONFIG_OPTIONS } from "@aws-sdk/middleware-bucket-endpoint";
import { NODE_APP_ID_CONFIG_OPTIONS, createDefaultUserAgentProvider } from "@aws-sdk/util-user-agent-node";
import {
NODE_REGION_CONFIG_FILE_OPTIONS,
Expand Down Expand Up @@ -67,6 +68,7 @@ export const getRuntimeConfig = (config: S3ControlClientConfig) => {
sha256: config?.sha256 ?? Hash.bind(null, "sha256"),
streamCollector: config?.streamCollector ?? streamCollector,
streamHasher: config?.streamHasher ?? streamHasher,
useArnRegion: config?.useArnRegion ?? loadNodeConfig(NODE_USE_ARN_REGION_CONFIG_OPTIONS, loaderConfig),
useDualstackEndpoint:
config?.useDualstackEndpoint ?? loadNodeConfig(NODE_USE_DUALSTACK_ENDPOINT_CONFIG_OPTIONS, loaderConfig),
useFipsEndpoint: config?.useFipsEndpoint ?? loadNodeConfig(NODE_USE_FIPS_ENDPOINT_CONFIG_OPTIONS, loaderConfig),
Expand Down
4 changes: 2 additions & 2 deletions clients/client-s3-control/test/S3Control.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ describe("S3Control Client", () => {
expect(request.headers[HEADER_OUTPOST_ID]).eql(OutpostId);
expect(request.headers[HEADER_ACCOUNT_ID]).eql(AccountId);
expect(request.headers["authorization"]).contains(
`Credential=${credentials.accessKeyId}/${dateStr}/${region}/s3/aws4_request`
`Credential=${credentials.accessKeyId}/${dateStr}/${region}/s3-outposts/aws4_request`
);
});
});
Expand Down Expand Up @@ -129,7 +129,7 @@ describe("S3Control Client", () => {
expect(request.headers[HEADER_OUTPOST_ID]).eql(OutpostId);
expect(request.headers[HEADER_ACCOUNT_ID]).eql(AccountId);
expect(request.headers["authorization"]).contains(
`Credential=${credentials.accessKeyId}/${dateStr}/${region}/s3/aws4_request`
`Credential=${credentials.accessKeyId}/${dateStr}/${region}/s3-outposts/aws4_request`
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this undoes the change from #4065

);
});
});
Expand Down
4 changes: 2 additions & 2 deletions clients/client-s3/src/S3Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -755,9 +755,9 @@ export interface ClientDefaults extends Partial<__SmithyConfiguration<__HttpHand
signingEscapePath?: boolean;

/**
* Whether to override the request region with the region inferred from requested resource's ARN. Defaults to false.
* Whether to override the request region with the region inferred from requested resource's ARN. Defaults to undefined.
*/
useArnRegion?: boolean | Provider<boolean>;
useArnRegion?: boolean | undefined | Provider<boolean | undefined>;
/**
* The internal function that inject utilities to runtime-specific stream to help users consume the data
* @internal
Expand Down
1 change: 0 additions & 1 deletion clients/client-s3/src/models/models_0.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// smithy-typescript generated code
import { ExceptionOptionType as __ExceptionOptionType, SENSITIVE_STRING } from "@smithy/smithy-client";

import { StreamingBlobTypes } from "@smithy/types";

import { S3ServiceException as __BaseException } from "./S3ServiceException";
Expand Down
2 changes: 0 additions & 2 deletions clients/client-s3/src/models/models_1.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// smithy-typescript generated code
import { ExceptionOptionType as __ExceptionOptionType, SENSITIVE_STRING } from "@smithy/smithy-client";

import { StreamingBlobTypes } from "@smithy/types";

import {
Expand Down Expand Up @@ -41,7 +40,6 @@ import {
Tag,
TransitionDefaultMinimumObjectSize,
} from "./models_0";

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

/**
Expand Down
2 changes: 1 addition & 1 deletion clients/client-s3/src/runtimeConfig.shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export const getRuntimeConfig = (config: S3ClientConfig) => {
signerConstructor: config?.signerConstructor ?? SignatureV4MultiRegion,
signingEscapePath: config?.signingEscapePath ?? false,
urlParser: config?.urlParser ?? parseUrl,
useArnRegion: config?.useArnRegion ?? false,
useArnRegion: config?.useArnRegion ?? undefined,
utf8Decoder: config?.utf8Decoder ?? fromUtf8,
utf8Encoder: config?.utf8Encoder ?? toUtf8,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import software.amazon.smithy.model.Model;
import software.amazon.smithy.model.knowledge.OperationIndex;
import software.amazon.smithy.model.knowledge.TopDownIndex;
import software.amazon.smithy.model.pattern.SmithyPattern;
import software.amazon.smithy.model.shapes.MemberShape;
import software.amazon.smithy.model.shapes.OperationShape;
import software.amazon.smithy.model.shapes.ServiceShape;
Expand All @@ -47,6 +48,7 @@
import software.amazon.smithy.model.traits.HttpHeaderTrait;
import software.amazon.smithy.model.traits.HttpPayloadTrait;
import software.amazon.smithy.model.traits.StreamingTrait;
import software.amazon.smithy.model.traits.Trait;
import software.amazon.smithy.model.transform.ModelTransformer;
import software.amazon.smithy.rulesengine.traits.EndpointRuleSetTrait;
import software.amazon.smithy.typescript.codegen.LanguageTarget;
Expand Down Expand Up @@ -89,7 +91,23 @@ public final class AddS3Config implements TypeScriptIntegration {
public static Shape removeHostPrefixTrait(Shape shape) {
return shape.asOperationShape()
.map(OperationShape::shapeToBuilder)
.map(builder -> ((OperationShape.Builder) builder).removeTrait(EndpointTrait.ID))
.map((Object object) -> {
OperationShape.Builder builder = (OperationShape.Builder) object;
Trait trait = builder.getAllTraits().get(EndpointTrait.ID);
if (trait instanceof EndpointTrait endpointTrait) {
if (
endpointTrait.getHostPrefix().equals(
SmithyPattern.builder()
.segments(List.of())
.pattern("{AccountId}.")
.build()
)
) {
builder.removeTrait(EndpointTrait.ID);
}
}
return builder;
})
.map(OperationShape.Builder::build)
.map(s -> (Shape) s)
.orElse(shape);
Expand Down Expand Up @@ -224,7 +242,7 @@ public Model preprocessModel(Model model, TypeScriptSettings settings) {

Model builtModel = modelBuilder.addShapes(inputShapes).build();
if (hasRuleset) {
ModelTransformer.create().mapShapes(
return ModelTransformer.create().mapShapes(
builtModel, AddS3Config::removeHostPrefixTrait
);
}
Expand All @@ -246,9 +264,9 @@ public void addConfigInterfaceFields(
.write("signingEscapePath?: boolean;\n");
writer.writeDocs(
"Whether to override the request region with the region inferred from requested resource's ARN."
+ " Defaults to false.")
+ " Defaults to undefined.")
.addImport("Provider", "Provider", TypeScriptDependency.SMITHY_TYPES)
.write("useArnRegion?: boolean | Provider<boolean>;");
.write("useArnRegion?: boolean | undefined | Provider<boolean | undefined>;");
}

@Override
Expand All @@ -266,7 +284,7 @@ public Map<String, Consumer<TypeScriptWriter>> getRuntimeConfigWriters(
writer.write("false");
},
"useArnRegion", writer -> {
writer.write("false");
writer.write("undefined");
}
);
case NODE:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import software.amazon.smithy.model.transform.ModelTransformer;
import software.amazon.smithy.rulesengine.traits.EndpointRuleSetTrait;
import software.amazon.smithy.typescript.codegen.LanguageTarget;
import software.amazon.smithy.typescript.codegen.TypeScriptDependency;
import software.amazon.smithy.typescript.codegen.TypeScriptSettings;
import software.amazon.smithy.typescript.codegen.TypeScriptWriter;
import software.amazon.smithy.typescript.codegen.endpointsV2.AddDefaultEndpointRuleSet;
Expand All @@ -58,6 +59,22 @@ public List<String> runAfter() {
);
}

@Override
public void addConfigInterfaceFields(TypeScriptSettings settings,
Model model,
SymbolProvider symbolProvider,
TypeScriptWriter writer) {
ServiceShape service = settings.getService(model);
if (!isS3Control(service)) {
return;
}
writer.writeDocs(
"Whether to override the request region with the region inferred from requested resource's ARN."
+ " Defaults to undefined.")
.addImport("Provider", "Provider", TypeScriptDependency.SMITHY_TYPES)
.write("useArnRegion?: boolean | undefined | Provider<boolean | undefined>;");
}

@Override
public List<RuntimeClientPlugin> getClientPlugins() {
return ListUtils.of(
Expand Down Expand Up @@ -118,10 +135,26 @@ public Map<String, Consumer<TypeScriptWriter>> getRuntimeConfigWriters(
}
switch (target) {
case SHARED:
return MapUtils.of("signingEscapePath", writer -> {
writer.write("false");
});
return MapUtils.of(
"signingEscapePath", writer -> {
writer.write("false");
},
"useArnRegion", writer -> {
writer.write("undefined");
}
);
case NODE:
return MapUtils.of(
"useArnRegion", writer -> {
writer.addDependency(TypeScriptDependency.NODE_CONFIG_PROVIDER)
.addImport("loadConfig", "loadNodeConfig",
TypeScriptDependency.NODE_CONFIG_PROVIDER)
.addDependency(AwsDependency.BUCKET_ENDPOINT_MIDDLEWARE)
.addImport("NODE_USE_ARN_REGION_CONFIG_OPTIONS", "NODE_USE_ARN_REGION_CONFIG_OPTIONS",
AwsDependency.BUCKET_ENDPOINT_MIDDLEWARE)
.write("loadNodeConfig(NODE_USE_ARN_REGION_CONFIG_OPTIONS, loaderConfig)");
}
);
default:
return Collections.emptyMap();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ describe("NODE_USE_ARN_REGION_CONFIG_OPTIONS", () => {
test(configFileSelector, profileContent, NODE_USE_ARN_REGION_INI_NAME, SelectorType.CONFIG);
});

it("returns false for default", () => {
it("returns undefined for default", () => {
const { default: defaultValue } = NODE_USE_ARN_REGION_CONFIG_OPTIONS;
expect(defaultValue).toEqual(false);
expect(defaultValue).toEqual(undefined);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,15 @@ export const NODE_USE_ARN_REGION_INI_NAME = "s3_use_arn_region";
/**
* Config to load useArnRegion from environment variables and shared INI files
*
* @api private
* @internal
*/
export const NODE_USE_ARN_REGION_CONFIG_OPTIONS: LoadedConfigSelectors<boolean> = {
export const NODE_USE_ARN_REGION_CONFIG_OPTIONS: LoadedConfigSelectors<boolean | undefined> = {
environmentVariableSelector: (env: NodeJS.ProcessEnv) =>
booleanSelector(env, NODE_USE_ARN_REGION_ENV_NAME, SelectorType.ENV),
configFileSelector: (profile) => booleanSelector(profile, NODE_USE_ARN_REGION_INI_NAME, SelectorType.CONFIG),
default: false,
/**
* useArnRegion has specific behavior when undefined instead of false.
* We therefore use undefined as the default value instead of false.
*/
default: undefined,
};
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ import { parse, validate } from "@aws-sdk/util-arn-parser";
import { bucketEndpointMiddleware } from "./bucketEndpointMiddleware";
import { bucketHostname } from "./bucketHostname";

describe("bucketEndpointMiddleware", () => {
/**
* @deprecated unused as of EndpointsV2.
*/
describe.skip("bucketEndpointMiddleware", () => {
const input = { Bucket: "bucket" };
const mockRegion = "us-foo-1";
const requestInput = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ import {
import { bucketHostname } from "./bucketHostname";
import { BucketEndpointResolvedConfig } from "./configurations";

/**
* @deprecated unused as of EndpointsV2.
* @internal
*/
export const bucketEndpointMiddleware =
(options: BucketEndpointResolvedConfig): BuildMiddleware<any, any> =>
<Output extends MetadataBearer>(
Expand Down Expand Up @@ -98,6 +102,10 @@ export const bucketEndpointMiddleware =
return next({ ...args, request });
};

/**
* @deprecated unused as of EndpointsV2.
* @internal
*/
export const bucketEndpointMiddlewareOptions: RelativeMiddlewareOptions = {
tags: ["BUCKET_ENDPOINT"],
name: "bucketEndpointMiddleware",
Expand All @@ -106,6 +114,10 @@ export const bucketEndpointMiddlewareOptions: RelativeMiddlewareOptions = {
override: true,
};

/**
* @deprecated unused as of EndpointsV2.
* @internal
*/
export const getBucketEndpointPlugin = (options: BucketEndpointResolvedConfig): Pluggable<any, any> => ({
applyToStack: (clientStack) => {
clientStack.addRelativeTo(bucketEndpointMiddleware(options), bucketEndpointMiddlewareOptions);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ import { describe, expect, test as it } from "vitest";

import { bucketHostname } from "./bucketHostname";

describe("bucketHostname", () => {
/**
* @deprecated unused as of EndpointsV2.
*/
describe.skip("bucketHostname", () => {
const region = "us-west-2";
describe("from bucket name", () => {
[
Expand Down
Loading
Loading