-
Notifications
You must be signed in to change notification settings - Fork 590
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: migrate route-53 middleware and apply plugin (#550)
- Loading branch information
Showing
20 changed files
with
219 additions
and
235 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
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-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) |
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
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
86 changes: 86 additions & 0 deletions
86
packages/middleware-sdk-route53/src/change-resource-record-sets.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,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<Change>; | ||
}; | ||
} | ||
|
||
export function changeResourceRecordSetsMiddleware(): InitializeMiddleware< | ||
any, | ||
any | ||
> { | ||
return <Output extends MetadataBearer>( | ||
next: InitializeHandler<any, Output> | ||
): InitializeHandler<any, Output> => async ( | ||
args: InitializeHandlerArguments<any> | ||
): Promise<InitializeHandlerOutput<Output>> => { | ||
const { ChangeBatch } = args.input; | ||
const Changes: Array<Change> = []; | ||
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<any, any> => ({ | ||
applyToStack: clientStack => { | ||
clientStack.add( | ||
changeResourceRecordSetsMiddleware(), | ||
changeResourceRecordSetsMiddlewareOptions | ||
); | ||
} | ||
}); |
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 @@ | ||
export const IDENTIFIER_PREFIX_PATTERN = /^\/(hostedzone|change|delegationset)\//; |
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,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" } | ||
}); | ||
}); | ||
} | ||
} | ||
}); |
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,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<keyof IdentifierBearer> = [ | ||
"DelegationSetId", | ||
"HostedZoneId", | ||
"Id" | ||
]; | ||
|
||
export function idNormalizerMiddleware(): InitializeMiddleware<any, any> { | ||
return <Output extends MetadataBearer>( | ||
next: InitializeHandler<any, Output> | ||
): InitializeHandler<any, Output> => async ( | ||
args: InitializeHandlerArguments<any> | ||
): Promise<InitializeHandlerOutput<Output>> => { | ||
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<any, any> => ({ | ||
applyToStack: clientStack => { | ||
clientStack.add(idNormalizerMiddleware(), idNormalizerMiddlewareOptions); | ||
} | ||
}); |
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,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"); | ||
}); | ||
}); |
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,2 @@ | ||
export * from "./change-resource-record-sets"; | ||
export * from "./id-normalizer"; |
File renamed without changes.
File renamed without changes.
Oops, something went wrong.