Skip to content

fix: resolve region #560

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 17, 2019
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
6 changes: 3 additions & 3 deletions packages/middleware-location-constraint/src/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ describe("locationConstrainMiddleware", () => {

it("should remove any CreateBucketConfiguration from requests directed at us-east-1", async () => {
const handler = locationConstraintMiddleware({
region: "us-east-1"
region: () => Promise.resolve("us-east-1")
})(next, {} as any);
const input = {
CreateBucketConfiguration: { LocationConstraint: "us-east-1" },
Expand All @@ -28,7 +28,7 @@ describe("locationConstrainMiddleware", () => {

it("should apply a CreateBucketConfiguration with a LocationConstraint of the target region for requests directed outside of us-east-1", async () => {
const handler = locationConstraintMiddleware({
region: "us-east-2"
region: () => Promise.resolve("us-east-2")
})(next, {} as any);
const input = {
foo: "bar"
Expand All @@ -47,7 +47,7 @@ describe("locationConstrainMiddleware", () => {

it("should do nothing if a LocationConstraint had already been set on a request directed outside of us-east-1", async () => {
const handler = locationConstraintMiddleware({
region: "us-east-2"
region: () => Promise.resolve("us-east-2")
})(next, {} as any);
const input = {
CreateBucketConfiguration: { LocationConstraint: "us-east-1" },
Expand Down
6 changes: 4 additions & 2 deletions packages/middleware-location-constraint/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ export function locationConstraintMiddleware(
args: InitializeHandlerArguments<any>
): Promise<InitializeHandlerOutput<Output>> => {
const { CreateBucketConfiguration } = args.input;
//After region config resolution, region is a Provider<string>
const region = await options.region();
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you add comment that the region will always be a Provider<string> after region config resolver?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

comment in 448d2f8

if (
!CreateBucketConfiguration ||
!CreateBucketConfiguration.LocationConstraint
Expand All @@ -32,10 +34,10 @@ export function locationConstraintMiddleware(
...args,
input: {
...args.input,
CreateBucketConfiguration: { LocationConstraint: options.region }
CreateBucketConfiguration: { LocationConstraint: region }
}
};
} else if (options.region === "us-east-1") {
} else if (region === "us-east-1") {
args = {
...args,
input: {
Expand Down