-
Notifications
You must be signed in to change notification settings - Fork 585
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: location constraint migration (#497)
* feat: rename location-constraint * feat: migrate locationConstraintMiddleware * feat: apply LocationConstraint plugin
- Loading branch information
Showing
16 changed files
with
116 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# @aws-sdk/middleware-location-constraint | ||
|
||
[![NPM version](https://img.shields.io/npm/v/@aws-sdk/middleware-location-constraint/preview.svg)](https://www.npmjs.com/package/@aws-sdk/middleware-location-constraint) | ||
[![NPM downloads](https://img.shields.io/npm/dm/@aws-sdk/middleware-location-constraint.svg)](https://www.npmjs.com/package/@aws-sdk/middleware-location-constraint) |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
packages/middleware-location-constraint/src/configuration.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { Provider } from "@aws-sdk/types"; | ||
|
||
export interface LocationConstraintInputConfig {} | ||
|
||
interface PreviouslyResolved { | ||
region: Provider<string>; | ||
} | ||
|
||
export interface LocationConstraintResolvedConfig { | ||
region: Provider<string>; | ||
} | ||
export function resolveLocationConstraintConfig<T>( | ||
input: T & LocationConstraintInputConfig & PreviouslyResolved | ||
): T & LocationConstraintResolvedConfig { | ||
return { ...input }; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import { | ||
InitializeHandler, | ||
InitializeMiddleware, | ||
InitializeHandlerArguments, | ||
InitializeHandlerOptions, | ||
InitializeHandlerOutput, | ||
MetadataBearer, | ||
Pluggable | ||
} from "@aws-sdk/types"; | ||
import { LocationConstraintResolvedConfig } from "./configuration"; | ||
|
||
/** | ||
* This middleware modifies the input on S3 CreateBucket requests. If the LocationConstraint has not been set, this | ||
* middleware will set a LocationConstraint to match the configured region. The CreateBucketConfiguration will be | ||
* removed entirely on requests to the us-east-1 region. | ||
*/ | ||
|
||
export function locationConstraintMiddleware( | ||
options: LocationConstraintResolvedConfig | ||
): InitializeMiddleware<any, any> { | ||
return <Output extends MetadataBearer>( | ||
next: InitializeHandler<any, Output> | ||
): InitializeHandler<any, Output> => async ( | ||
args: InitializeHandlerArguments<any> | ||
): Promise<InitializeHandlerOutput<Output>> => { | ||
const { CreateBucketConfiguration } = args.input; | ||
if ( | ||
!CreateBucketConfiguration || | ||
!CreateBucketConfiguration.LocationConstraint | ||
) { | ||
args = { | ||
...args, | ||
input: { | ||
...args.input, | ||
CreateBucketConfiguration: { LocationConstraint: options.region } | ||
} | ||
}; | ||
} else if (options.region === "us-east-1") { | ||
args = { | ||
...args, | ||
input: { | ||
...args.input, | ||
CreateBucketConfiguration: undefined | ||
} | ||
}; | ||
} | ||
|
||
return next(args); | ||
}; | ||
} | ||
|
||
export const locationConstraintMiddlewareOptions: InitializeHandlerOptions = { | ||
step: "initialize", | ||
tags: ["LOCATION_CONSTRAINT", "CREATE_BUCKET_CONFIGURATION"], | ||
name: "locationConstraintMiddleware" | ||
}; | ||
|
||
export const getLocationConstraintPlugin = ( | ||
config: LocationConstraintResolvedConfig | ||
): Pluggable<any, any> => ({ | ||
applyToStack: clientStack => { | ||
clientStack.add( | ||
locationConstraintMiddleware(config), | ||
locationConstraintMiddlewareOptions | ||
); | ||
} | ||
}); |
File renamed without changes.
File renamed without changes.