From 272ae8dc3d3843a9b68ecf8cabfac061326fddb5 Mon Sep 17 00:00:00 2001 From: Chase Coalwell Date: Wed, 18 Dec 2019 10:26:10 -0800 Subject: [PATCH] feat: migrate route-53 middleware and apply plugin (#550) --- .../typescript/codegen/AddBuiltinPlugins.java | 14 +++ .../aws/typescript/codegen/AwsDependency.java | 1 + .../.gitignore | 0 .../.npmignore | 0 .../LICENSE | 0 packages/middleware-sdk-route53/README.md | 4 + .../jest.config.js | 0 .../package.json | 6 +- .../src/change-resource-record-sets.spec.ts} | 32 +---- .../src/change-resource-record-sets.ts | 86 ++++++++++++++ .../middleware-sdk-route53/src/constants.ts | 1 + .../src/id-normalizer-spec.ts | 24 ++++ .../src/id-normalizer.ts | 55 +++++++++ .../middleware-sdk-route53/src/index.spec.ts | 24 ++++ packages/middleware-sdk-route53/src/index.ts | 2 + .../tsconfig.json | 0 .../tsconfig.test.json | 0 .../CHANGELOG.md | 111 ------------------ .../README.md | 4 - .../src/index.ts | 90 -------------- 20 files changed, 219 insertions(+), 235 deletions(-) rename packages/{route53-id-normalizer-middleware => middleware-sdk-route53}/.gitignore (100%) rename packages/{route53-id-normalizer-middleware => middleware-sdk-route53}/.npmignore (100%) rename packages/{route53-id-normalizer-middleware => middleware-sdk-route53}/LICENSE (100%) create mode 100644 packages/middleware-sdk-route53/README.md rename packages/{route53-id-normalizer-middleware => middleware-sdk-route53}/jest.config.js (100%) rename packages/{route53-id-normalizer-middleware => middleware-sdk-route53}/package.json (85%) rename packages/{route53-id-normalizer-middleware/src/index.spec.ts => middleware-sdk-route53/src/change-resource-record-sets.spec.ts} (65%) create mode 100644 packages/middleware-sdk-route53/src/change-resource-record-sets.ts create mode 100644 packages/middleware-sdk-route53/src/constants.ts create mode 100644 packages/middleware-sdk-route53/src/id-normalizer-spec.ts create mode 100644 packages/middleware-sdk-route53/src/id-normalizer.ts create mode 100644 packages/middleware-sdk-route53/src/index.spec.ts create mode 100644 packages/middleware-sdk-route53/src/index.ts rename packages/{route53-id-normalizer-middleware => middleware-sdk-route53}/tsconfig.json (100%) rename packages/{route53-id-normalizer-middleware => middleware-sdk-route53}/tsconfig.test.json (100%) delete mode 100644 packages/route53-id-normalizer-middleware/CHANGELOG.md delete mode 100644 packages/route53-id-normalizer-middleware/README.md delete mode 100644 packages/route53-id-normalizer-middleware/src/index.ts diff --git a/codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/AddBuiltinPlugins.java b/codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/AddBuiltinPlugins.java index 1971950c8813..341a98247406 100644 --- a/codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/AddBuiltinPlugins.java +++ b/codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/AddBuiltinPlugins.java @@ -39,6 +39,8 @@ public class AddBuiltinPlugins implements TypeScriptIntegration { private static final Set SSEC_OPERATIONS = SetUtils.of("SSECustomerKey", "CopySourceSSECustomerKey"); + private static final Set ROUTE_53_ID_MEMBERS = SetUtils.of("DelegationSetId", "HostedZoneId", "Id"); + private static final Set S3_MD5_OPERATIONS = SetUtils.of( "DeleteObjects", "PutBucketCors", @@ -115,6 +117,18 @@ public List getClientPlugins() { HAS_MIDDLEWARE) .servicePredicate((m, s) -> testServiceId(s, "S3")) .operationPredicate((m, s, o) -> S3_MD5_OPERATIONS.contains(o.getId().getName())) + .build(), + RuntimeClientPlugin.builder() + .withConventions(AwsDependency.ROUTE53_MIDDLEWARE.dependency, + "ChangeResourceRecordSets", HAS_MIDDLEWARE) + .servicePredicate((m, s) -> testServiceId(s, "Route 53")) + .operationPredicate((m, s, o) -> o.getId().getName().equals("ChangeResourceRecordSets")) + .build(), + RuntimeClientPlugin.builder() + .withConventions(AwsDependency.ROUTE53_MIDDLEWARE.dependency, "IdNormalizer", + HAS_MIDDLEWARE) + .servicePredicate((m, s) -> testServiceId(s, "Route 53")) + .operationPredicate((m, s, o) -> testInputContainsMember(m, o, ROUTE_53_ID_MEMBERS)) .build() ); } diff --git a/codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/AwsDependency.java b/codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/AwsDependency.java index ba6de29de0a3..3e9fe4571bd1 100644 --- a/codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/AwsDependency.java +++ b/codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/AwsDependency.java @@ -41,6 +41,7 @@ public enum AwsDependency implements SymbolDependencyContainer { MD5_BROWSER(NORMAL_DEPENDENCY, "@aws-sdk/md5-js", "^0.1.0-preview.6"), STREAM_HASHER_NODE(NORMAL_DEPENDENCY, "@aws-sdk/hash-stream-node", "^0.1.0-preview.4"), STREAM_HASHER_BROWSER(NORMAL_DEPENDENCY, "@aws-sdk/hash-blob-browser", "^0.1.0-preview.4"), + ROUTE53_MIDDLEWARE(NORMAL_DEPENDENCY, "@aws-sdk/middleware-sdk-route53", "^0.1.0-preview.1"), BODY_CHECKSUM(NORMAL_DEPENDENCY, "@aws-sdk/middleware-apply-body-checksum", "^0.1.0-preview.5"); public final String packageName; diff --git a/packages/route53-id-normalizer-middleware/.gitignore b/packages/middleware-sdk-route53/.gitignore similarity index 100% rename from packages/route53-id-normalizer-middleware/.gitignore rename to packages/middleware-sdk-route53/.gitignore diff --git a/packages/route53-id-normalizer-middleware/.npmignore b/packages/middleware-sdk-route53/.npmignore similarity index 100% rename from packages/route53-id-normalizer-middleware/.npmignore rename to packages/middleware-sdk-route53/.npmignore diff --git a/packages/route53-id-normalizer-middleware/LICENSE b/packages/middleware-sdk-route53/LICENSE similarity index 100% rename from packages/route53-id-normalizer-middleware/LICENSE rename to packages/middleware-sdk-route53/LICENSE diff --git a/packages/middleware-sdk-route53/README.md b/packages/middleware-sdk-route53/README.md new file mode 100644 index 000000000000..6cda7dc6f5ab --- /dev/null +++ b/packages/middleware-sdk-route53/README.md @@ -0,0 +1,4 @@ +# @aws-sdk/middleware-sdk-route53 + +[![NPM version](https://img.shields.io/npm/v/@aws-sdk/middleware-sdk-route53/preview.svg)](https://www.npmjs.com/package/@aws-sdk/middleware-sdk-route53) +[![NPM downloads](https://img.shields.io/npm/dm/@aws-sdk/middleware-sdk-route53.svg)](https://www.npmjs.com/package/@aws-sdk/middleware-sdk-route53) diff --git a/packages/route53-id-normalizer-middleware/jest.config.js b/packages/middleware-sdk-route53/jest.config.js similarity index 100% rename from packages/route53-id-normalizer-middleware/jest.config.js rename to packages/middleware-sdk-route53/jest.config.js diff --git a/packages/route53-id-normalizer-middleware/package.json b/packages/middleware-sdk-route53/package.json similarity index 85% rename from packages/route53-id-normalizer-middleware/package.json rename to packages/middleware-sdk-route53/package.json index d5c736f32970..bbab0cf9d06f 100644 --- a/packages/route53-id-normalizer-middleware/package.json +++ b/packages/middleware-sdk-route53/package.json @@ -1,6 +1,6 @@ { - "name": "@aws-sdk/route53-id-normalizer-middleware", - "version": "0.1.0-preview.7", + "name": "@aws-sdk/middleware-sdk-route53", + "version": "0.1.0-preview.1", "scripts": { "prepublishOnly": "tsc", "pretest": "tsc -p tsconfig.test.json", @@ -22,4 +22,4 @@ "jest": "^24.7.1", "typescript": "~3.4.0" } -} +} \ No newline at end of file diff --git a/packages/route53-id-normalizer-middleware/src/index.spec.ts b/packages/middleware-sdk-route53/src/change-resource-record-sets.spec.ts similarity index 65% rename from packages/route53-id-normalizer-middleware/src/index.spec.ts rename to packages/middleware-sdk-route53/src/change-resource-record-sets.spec.ts index df7f8eb4e6af..99f8bd642eb5 100644 --- a/packages/route53-id-normalizer-middleware/src/index.spec.ts +++ b/packages/middleware-sdk-route53/src/change-resource-record-sets.spec.ts @@ -1,30 +1,8 @@ -import { - idNormalizerMiddleware, - changeBatchAliasTargetIdNormalizerMiddleware -} from "./"; +import { changeResourceRecordSetsMiddleware } from "./change-resource-record-sets"; const prefixedProps = ["/hostedzone/ID", "/change/ID", "/delegationset/ID"]; -const idParams = ["DelegationSetId", "HostedZoneId", "Id"]; -describe("locationConstrainMiddleware", () => { - for (const paramName of idParams) { - for (const prefixed of prefixedProps) { - it(`should strip the prefix from the ${paramName} parameter`, async () => { - const next = jest.fn(); - const input = { [paramName]: prefixed }; - - await idNormalizerMiddleware(next)({ input }); - - expect(next.mock.calls.length).toBe(1); - expect(next.mock.calls[0][0]).toEqual({ - input: { [paramName]: "ID" } - }); - }); - } - } -}); - -describe("changeBatchAliasTargetIdNormalizerMiddleware", () => { +describe("changeResourceRecordSetsMiddleware", () => { for (const prefixed of prefixedProps) { it(`should strip the prefix from the ChangeBatch.Changes[*].ResourceRecordSet.AliasTarget.HostedZoneId parameter`, async () => { const next = jest.fn(); @@ -45,9 +23,9 @@ describe("changeBatchAliasTargetIdNormalizerMiddleware", () => { } }; - await changeBatchAliasTargetIdNormalizerMiddleware(next)({ - input - }); + const handler = changeResourceRecordSetsMiddleware()(next, {} as any); + + await handler({ input }); expect(next.mock.calls.length).toBe(1); expect(next.mock.calls[0][0]).toEqual({ diff --git a/packages/middleware-sdk-route53/src/change-resource-record-sets.ts b/packages/middleware-sdk-route53/src/change-resource-record-sets.ts new file mode 100644 index 000000000000..ce4cfdf939a9 --- /dev/null +++ b/packages/middleware-sdk-route53/src/change-resource-record-sets.ts @@ -0,0 +1,86 @@ +import { + InitializeHandler, + InitializeMiddleware, + InitializeHandlerArguments, + InitializeHandlerOptions, + InitializeHandlerOutput, + MetadataBearer, + Pluggable +} from "@aws-sdk/types"; +import { IDENTIFIER_PREFIX_PATTERN } from "./constants"; + +export interface Change { + ResourceRecordSet: { + AliasTarget?: { + HostedZoneId: string; + }; + }; +} + +export interface ChangeBatchBearer { + ChangeBatch: { + Changes: Iterable; + }; +} + +export function changeResourceRecordSetsMiddleware(): InitializeMiddleware< + any, + any +> { + return ( + next: InitializeHandler + ): InitializeHandler => async ( + args: InitializeHandlerArguments + ): Promise> => { + const { ChangeBatch } = args.input; + const Changes: Array = []; + for (const change of ChangeBatch.Changes) { + const { AliasTarget } = change.ResourceRecordSet; + if (AliasTarget) { + Changes.push({ + ...change, + ResourceRecordSet: { + ...change.ResourceRecordSet, + AliasTarget: { + ...AliasTarget, + HostedZoneId: AliasTarget.HostedZoneId.replace( + IDENTIFIER_PREFIX_PATTERN, + "" + ) + } + } + }); + } else { + Changes.push(change); + } + } + + return next({ + ...args, + input: { + ...(args.input as any), + ChangeBatch: { + ...ChangeBatch, + Changes + } + } + }); + }; +} + +export const changeResourceRecordSetsMiddlewareOptions: InitializeHandlerOptions = { + step: "initialize", + tags: ["ROUTE53_IDS", "CHANGE_RESOURCE_RECORD_SETS"], + name: "changeResourceRecordSetsMiddleware" +}; + +export const getChangeResourceRecordSetsPlugin = ( + unused: any +): Pluggable => ({ + applyToStack: clientStack => { + clientStack.add( + changeResourceRecordSetsMiddleware(), + changeResourceRecordSetsMiddlewareOptions + ); + } +}); diff --git a/packages/middleware-sdk-route53/src/constants.ts b/packages/middleware-sdk-route53/src/constants.ts new file mode 100644 index 000000000000..339c8074cb20 --- /dev/null +++ b/packages/middleware-sdk-route53/src/constants.ts @@ -0,0 +1 @@ +export const IDENTIFIER_PREFIX_PATTERN = /^\/(hostedzone|change|delegationset)\//; diff --git a/packages/middleware-sdk-route53/src/id-normalizer-spec.ts b/packages/middleware-sdk-route53/src/id-normalizer-spec.ts new file mode 100644 index 000000000000..dfc19ffd5bbe --- /dev/null +++ b/packages/middleware-sdk-route53/src/id-normalizer-spec.ts @@ -0,0 +1,24 @@ +import { idNormalizerMiddleware } from "./id-normalizer"; + +const prefixedProps = ["/hostedzone/ID", "/change/ID", "/delegationset/ID"]; +const idParams = ["DelegationSetId", "HostedZoneId", "Id"]; + +describe("idNormalizerMiddleware", () => { + for (const paramName of idParams) { + for (const prefixed of prefixedProps) { + it(`should strip the prefix from the ${paramName} parameter`, async () => { + const next = jest.fn(); + const input = { [paramName]: prefixed }; + + const handler = idNormalizerMiddleware()(next, {} as any); + + await handler({ input }); + + expect(next.mock.calls.length).toBe(1); + expect(next.mock.calls[0][0]).toEqual({ + input: { [paramName]: "ID" } + }); + }); + } + } +}); diff --git a/packages/middleware-sdk-route53/src/id-normalizer.ts b/packages/middleware-sdk-route53/src/id-normalizer.ts new file mode 100644 index 000000000000..b8680435766f --- /dev/null +++ b/packages/middleware-sdk-route53/src/id-normalizer.ts @@ -0,0 +1,55 @@ +import { + InitializeHandler, + InitializeMiddleware, + InitializeHandlerArguments, + InitializeHandlerOptions, + InitializeHandlerOutput, + MetadataBearer, + Pluggable +} from "@aws-sdk/types"; +import { IDENTIFIER_PREFIX_PATTERN } from "./constants"; + +export interface IdentifierBearer { + DelegationSetId?: string; + HostedZoneId?: string; + Id?: string; +} + +const IDENTIFIER_PARAMETERS: Array = [ + "DelegationSetId", + "HostedZoneId", + "Id" +]; + +export function idNormalizerMiddleware(): InitializeMiddleware { + return ( + next: InitializeHandler + ): InitializeHandler => async ( + args: InitializeHandlerArguments + ): Promise> => { + const input = { ...(args.input as any) }; + for (const paramName of IDENTIFIER_PARAMETERS) { + const param = input[paramName]; + if (param) { + input[paramName] = param.replace(IDENTIFIER_PREFIX_PATTERN, ""); + } + } + + return next({ + ...args, + input + }); + }; +} + +export const idNormalizerMiddlewareOptions: InitializeHandlerOptions = { + step: "initialize", + tags: ["ROUTE53_IDS"], + name: "idNormalizerMiddleware" +}; + +export const getIdNormalizerPlugin = (unused: any): Pluggable => ({ + applyToStack: clientStack => { + clientStack.add(idNormalizerMiddleware(), idNormalizerMiddlewareOptions); + } +}); diff --git a/packages/middleware-sdk-route53/src/index.spec.ts b/packages/middleware-sdk-route53/src/index.spec.ts new file mode 100644 index 000000000000..c920f50ef6d6 --- /dev/null +++ b/packages/middleware-sdk-route53/src/index.spec.ts @@ -0,0 +1,24 @@ +import { + changeResourceRecordSetsMiddleware, + getChangeResourceRecordSetsPlugin, + idNormalizerMiddleware, + getIdNormalizerPlugin +} from "./index"; + +describe("middleware-sdk-route53 package exports", () => { + it("changeResourceRecordSetsMiddleware", () => { + expect(typeof changeResourceRecordSetsMiddleware).toBe("function"); + }); + + it("getChangeResourceRecordSetsPlugin", () => { + expect(typeof getChangeResourceRecordSetsPlugin).toBe("function"); + }); + + it("idNormalizerMiddleware", () => { + expect(typeof idNormalizerMiddleware).toBe("function"); + }); + + it("getIdNormalizerPlugin", () => { + expect(typeof getIdNormalizerPlugin).toBe("function"); + }); +}); diff --git a/packages/middleware-sdk-route53/src/index.ts b/packages/middleware-sdk-route53/src/index.ts new file mode 100644 index 000000000000..c111eed0344f --- /dev/null +++ b/packages/middleware-sdk-route53/src/index.ts @@ -0,0 +1,2 @@ +export * from "./change-resource-record-sets"; +export * from "./id-normalizer"; diff --git a/packages/route53-id-normalizer-middleware/tsconfig.json b/packages/middleware-sdk-route53/tsconfig.json similarity index 100% rename from packages/route53-id-normalizer-middleware/tsconfig.json rename to packages/middleware-sdk-route53/tsconfig.json diff --git a/packages/route53-id-normalizer-middleware/tsconfig.test.json b/packages/middleware-sdk-route53/tsconfig.test.json similarity index 100% rename from packages/route53-id-normalizer-middleware/tsconfig.test.json rename to packages/middleware-sdk-route53/tsconfig.test.json diff --git a/packages/route53-id-normalizer-middleware/CHANGELOG.md b/packages/route53-id-normalizer-middleware/CHANGELOG.md deleted file mode 100644 index 3db274b1e8e5..000000000000 --- a/packages/route53-id-normalizer-middleware/CHANGELOG.md +++ /dev/null @@ -1,111 +0,0 @@ -# Change Log - -All notable changes to this project will be documented in this file. -See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. - -# [0.1.0-preview.7](https://github.com/aws/aws-sdk-js-v3/compare/@aws-sdk/route53-id-normalizer-middleware@0.1.0-preview.2...@aws-sdk/route53-id-normalizer-middleware@0.1.0-preview.7) (2019-10-30) - - - -# 0.3.0 (2019-09-09) - - -### Features - -* commit all clients ([#324](https://github.com/aws/aws-sdk-js-v3/issues/324)) ([cb268ed](https://github.com/aws/aws-sdk-js-v3/commit/cb268ed)) - - - -# 0.2.0 (2019-07-12) - - -### Features - -* add npm badges for individual packages ([#251](https://github.com/aws/aws-sdk-js-v3/issues/251)) ([8adc10c](https://github.com/aws/aws-sdk-js-v3/commit/8adc10c)) -* update jest v20 to v24 ([#243](https://github.com/aws/aws-sdk-js-v3/issues/243)) ([1e156ab](https://github.com/aws/aws-sdk-js-v3/commit/1e156ab)) - - - -# 0.1.0 (2019-04-19) - - - - - -# [0.1.0-preview.6](https://github.com/aws/aws-sdk-js-v3/compare/@aws-sdk/route53-id-normalizer-middleware@0.1.0-preview.2...@aws-sdk/route53-id-normalizer-middleware@0.1.0-preview.6) (2019-10-29) - - - -# 0.3.0 (2019-09-09) - - -### Features - -* commit all clients ([#324](https://github.com/aws/aws-sdk-js-v3/issues/324)) ([cb268ed](https://github.com/aws/aws-sdk-js-v3/commit/cb268ed)) - - - -# 0.2.0 (2019-07-12) - - -### Features - -* add npm badges for individual packages ([#251](https://github.com/aws/aws-sdk-js-v3/issues/251)) ([8adc10c](https://github.com/aws/aws-sdk-js-v3/commit/8adc10c)) -* update jest v20 to v24 ([#243](https://github.com/aws/aws-sdk-js-v3/issues/243)) ([1e156ab](https://github.com/aws/aws-sdk-js-v3/commit/1e156ab)) - - - -# 0.1.0 (2019-04-19) - - - - - -# [0.1.0-preview.5](https://github.com/aws/aws-sdk-js-v3/compare/@aws-sdk/route53-id-normalizer-middleware@0.1.0-preview.2...@aws-sdk/route53-id-normalizer-middleware@0.1.0-preview.5) (2019-09-09) - - -### Features - -* commit all clients ([#324](https://github.com/aws/aws-sdk-js-v3/issues/324)) ([cb268ed](https://github.com/aws/aws-sdk-js-v3/commit/cb268ed)) - - - -# 0.2.0 (2019-07-12) - - -### Features - -* add npm badges for individual packages ([#251](https://github.com/aws/aws-sdk-js-v3/issues/251)) ([8adc10c](https://github.com/aws/aws-sdk-js-v3/commit/8adc10c)) -* update jest v20 to v24 ([#243](https://github.com/aws/aws-sdk-js-v3/issues/243)) ([1e156ab](https://github.com/aws/aws-sdk-js-v3/commit/1e156ab)) - - - -# 0.1.0 (2019-04-19) - - - - - -# [0.1.0-preview.4](https://github.com/aws/aws-sdk-js-v3/compare/@aws-sdk/route53-id-normalizer-middleware@0.1.0-preview.2...@aws-sdk/route53-id-normalizer-middleware@0.1.0-preview.4) (2019-07-12) - - -### Features - -* add npm badges for individual packages ([#251](https://github.com/aws/aws-sdk-js-v3/issues/251)) ([8adc10c](https://github.com/aws/aws-sdk-js-v3/commit/8adc10c)) -* update jest v20 to v24 ([#243](https://github.com/aws/aws-sdk-js-v3/issues/243)) ([1e156ab](https://github.com/aws/aws-sdk-js-v3/commit/1e156ab)) - - - -# 0.1.0 (2019-04-19) - - - - - -# [0.1.0-preview.3](https://github.com/aws/aws-sdk-js-v3/compare/@aws-sdk/route53-id-normalizer-middleware@0.1.0-preview.2...@aws-sdk/route53-id-normalizer-middleware@0.1.0-preview.3) (2019-04-19) - -**Note:** Version bump only for package @aws-sdk/route53-id-normalizer-middleware - -# [0.1.0-preview.2](https://github.com/aws/aws-sdk-js-v3/compare/@aws-sdk/route53-id-normalizer-middleware@0.1.0-preview.1...@aws-sdk/route53-id-normalizer-middleware@0.1.0-preview.2) (2019-03-27) - -**Note:** Version bump only for package @aws-sdk/route53-id-normalizer-middleware diff --git a/packages/route53-id-normalizer-middleware/README.md b/packages/route53-id-normalizer-middleware/README.md deleted file mode 100644 index 67d4f9a4d259..000000000000 --- a/packages/route53-id-normalizer-middleware/README.md +++ /dev/null @@ -1,4 +0,0 @@ -# @aws-sdk/route53-id-normalizer-middleware - -[![NPM version](https://img.shields.io/npm/v/@aws-sdk/route53-id-normalizer-middleware/preview.svg)](https://www.npmjs.com/package/@aws-sdk/route53-id-normalizer-middleware) -[![NPM downloads](https://img.shields.io/npm/dm/@aws-sdk/route53-id-normalizer-middleware.svg)](https://www.npmjs.com/package/@aws-sdk/route53-id-normalizer-middleware) diff --git a/packages/route53-id-normalizer-middleware/src/index.ts b/packages/route53-id-normalizer-middleware/src/index.ts deleted file mode 100644 index dab5c186e4bb..000000000000 --- a/packages/route53-id-normalizer-middleware/src/index.ts +++ /dev/null @@ -1,90 +0,0 @@ -import { Handler, HandlerArguments } from "@aws-sdk/types"; - -export interface IdentifierBearer { - DelegationSetId?: string; - HostedZoneId?: string; - Id?: string; -} - -const IDENTIFIER_PARAMETERS: Array = [ - "DelegationSetId", - "HostedZoneId", - "Id" -]; - -const IDENTIFIER_PREFIX_PATTERN = /^\/(hostedzone|change|delegationset)\//; - -export function idNormalizerMiddleware< - Input extends IdentifierBearer, - Output extends object ->(next: Handler): Handler { - return async (args: HandlerArguments): Promise => { - const input = { ...(args.input as any) }; - for (const paramName of IDENTIFIER_PARAMETERS) { - const param = input[paramName]; - if (param) { - input[paramName] = param.replace(IDENTIFIER_PREFIX_PATTERN, ""); - } - } - - return next({ - ...args, - input - }); - }; -} - -export interface Change { - ResourceRecordSet: { - AliasTarget?: { - HostedZoneId: string; - }; - }; -} - -export interface ChangeBatchBearer { - ChangeBatch: { - Changes: Iterable; - }; -} - -export function changeBatchAliasTargetIdNormalizerMiddleware< - Input extends ChangeBatchBearer, - Output extends object ->(next: Handler): Handler { - return async (args: HandlerArguments): Promise => { - const { ChangeBatch } = args.input; - const Changes: Array = []; - for (const change of ChangeBatch.Changes) { - const { AliasTarget } = change.ResourceRecordSet; - if (AliasTarget) { - Changes.push({ - ...change, - ResourceRecordSet: { - ...change.ResourceRecordSet, - AliasTarget: { - ...AliasTarget, - HostedZoneId: AliasTarget.HostedZoneId.replace( - IDENTIFIER_PREFIX_PATTERN, - "" - ) - } - } - }); - } else { - Changes.push(change); - } - } - - return next({ - ...args, - input: { - ...(args.input as any), - ChangeBatch: { - ...ChangeBatch, - Changes - } - } - }); - }; -}