Skip to content

Commit 272ae8d

Browse files
Chase Coalwelltrivikr
Chase Coalwell
authored andcommitted
feat: migrate route-53 middleware and apply plugin (#550)
1 parent f8a9c54 commit 272ae8d

File tree

20 files changed

+219
-235
lines changed

20 files changed

+219
-235
lines changed

codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/AddBuiltinPlugins.java

+14
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ public class AddBuiltinPlugins implements TypeScriptIntegration {
3939

4040
private static final Set<String> SSEC_OPERATIONS = SetUtils.of("SSECustomerKey", "CopySourceSSECustomerKey");
4141

42+
private static final Set<String> ROUTE_53_ID_MEMBERS = SetUtils.of("DelegationSetId", "HostedZoneId", "Id");
43+
4244
private static final Set<String> S3_MD5_OPERATIONS = SetUtils.of(
4345
"DeleteObjects",
4446
"PutBucketCors",
@@ -115,6 +117,18 @@ public List<RuntimeClientPlugin> getClientPlugins() {
115117
HAS_MIDDLEWARE)
116118
.servicePredicate((m, s) -> testServiceId(s, "S3"))
117119
.operationPredicate((m, s, o) -> S3_MD5_OPERATIONS.contains(o.getId().getName()))
120+
.build(),
121+
RuntimeClientPlugin.builder()
122+
.withConventions(AwsDependency.ROUTE53_MIDDLEWARE.dependency,
123+
"ChangeResourceRecordSets", HAS_MIDDLEWARE)
124+
.servicePredicate((m, s) -> testServiceId(s, "Route 53"))
125+
.operationPredicate((m, s, o) -> o.getId().getName().equals("ChangeResourceRecordSets"))
126+
.build(),
127+
RuntimeClientPlugin.builder()
128+
.withConventions(AwsDependency.ROUTE53_MIDDLEWARE.dependency, "IdNormalizer",
129+
HAS_MIDDLEWARE)
130+
.servicePredicate((m, s) -> testServiceId(s, "Route 53"))
131+
.operationPredicate((m, s, o) -> testInputContainsMember(m, o, ROUTE_53_ID_MEMBERS))
118132
.build()
119133
);
120134
}

codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/AwsDependency.java

+1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ public enum AwsDependency implements SymbolDependencyContainer {
4141
MD5_BROWSER(NORMAL_DEPENDENCY, "@aws-sdk/md5-js", "^0.1.0-preview.6"),
4242
STREAM_HASHER_NODE(NORMAL_DEPENDENCY, "@aws-sdk/hash-stream-node", "^0.1.0-preview.4"),
4343
STREAM_HASHER_BROWSER(NORMAL_DEPENDENCY, "@aws-sdk/hash-blob-browser", "^0.1.0-preview.4"),
44+
ROUTE53_MIDDLEWARE(NORMAL_DEPENDENCY, "@aws-sdk/middleware-sdk-route53", "^0.1.0-preview.1"),
4445
BODY_CHECKSUM(NORMAL_DEPENDENCY, "@aws-sdk/middleware-apply-body-checksum", "^0.1.0-preview.5");
4546

4647
public final String packageName;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# @aws-sdk/middleware-sdk-route53
2+
3+
[![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)
4+
[![NPM downloads](https://img.shields.io/npm/dm/@aws-sdk/middleware-sdk-route53.svg)](https://www.npmjs.com/package/@aws-sdk/middleware-sdk-route53)

packages/route53-id-normalizer-middleware/package.json renamed to packages/middleware-sdk-route53/package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
2-
"name": "@aws-sdk/route53-id-normalizer-middleware",
3-
"version": "0.1.0-preview.7",
2+
"name": "@aws-sdk/middleware-sdk-route53",
3+
"version": "0.1.0-preview.1",
44
"scripts": {
55
"prepublishOnly": "tsc",
66
"pretest": "tsc -p tsconfig.test.json",
@@ -22,4 +22,4 @@
2222
"jest": "^24.7.1",
2323
"typescript": "~3.4.0"
2424
}
25-
}
25+
}

packages/route53-id-normalizer-middleware/src/index.spec.ts renamed to packages/middleware-sdk-route53/src/change-resource-record-sets.spec.ts

+5-27
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,8 @@
1-
import {
2-
idNormalizerMiddleware,
3-
changeBatchAliasTargetIdNormalizerMiddleware
4-
} from "./";
1+
import { changeResourceRecordSetsMiddleware } from "./change-resource-record-sets";
52

63
const prefixedProps = ["/hostedzone/ID", "/change/ID", "/delegationset/ID"];
7-
const idParams = ["DelegationSetId", "HostedZoneId", "Id"];
84

9-
describe("locationConstrainMiddleware", () => {
10-
for (const paramName of idParams) {
11-
for (const prefixed of prefixedProps) {
12-
it(`should strip the prefix from the ${paramName} parameter`, async () => {
13-
const next = jest.fn();
14-
const input = { [paramName]: prefixed };
15-
16-
await idNormalizerMiddleware(next)({ input });
17-
18-
expect(next.mock.calls.length).toBe(1);
19-
expect(next.mock.calls[0][0]).toEqual({
20-
input: { [paramName]: "ID" }
21-
});
22-
});
23-
}
24-
}
25-
});
26-
27-
describe("changeBatchAliasTargetIdNormalizerMiddleware", () => {
5+
describe("changeResourceRecordSetsMiddleware", () => {
286
for (const prefixed of prefixedProps) {
297
it(`should strip the prefix from the ChangeBatch.Changes[*].ResourceRecordSet.AliasTarget.HostedZoneId parameter`, async () => {
308
const next = jest.fn();
@@ -45,9 +23,9 @@ describe("changeBatchAliasTargetIdNormalizerMiddleware", () => {
4523
}
4624
};
4725

48-
await changeBatchAliasTargetIdNormalizerMiddleware(next)({
49-
input
50-
});
26+
const handler = changeResourceRecordSetsMiddleware()(next, {} as any);
27+
28+
await handler({ input });
5129

5230
expect(next.mock.calls.length).toBe(1);
5331
expect(next.mock.calls[0][0]).toEqual({
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
import {
2+
InitializeHandler,
3+
InitializeMiddleware,
4+
InitializeHandlerArguments,
5+
InitializeHandlerOptions,
6+
InitializeHandlerOutput,
7+
MetadataBearer,
8+
Pluggable
9+
} from "@aws-sdk/types";
10+
import { IDENTIFIER_PREFIX_PATTERN } from "./constants";
11+
12+
export interface Change {
13+
ResourceRecordSet: {
14+
AliasTarget?: {
15+
HostedZoneId: string;
16+
};
17+
};
18+
}
19+
20+
export interface ChangeBatchBearer {
21+
ChangeBatch: {
22+
Changes: Iterable<Change>;
23+
};
24+
}
25+
26+
export function changeResourceRecordSetsMiddleware(): InitializeMiddleware<
27+
any,
28+
any
29+
> {
30+
return <Output extends MetadataBearer>(
31+
next: InitializeHandler<any, Output>
32+
): InitializeHandler<any, Output> => async (
33+
args: InitializeHandlerArguments<any>
34+
): Promise<InitializeHandlerOutput<Output>> => {
35+
const { ChangeBatch } = args.input;
36+
const Changes: Array<Change> = [];
37+
for (const change of ChangeBatch.Changes) {
38+
const { AliasTarget } = change.ResourceRecordSet;
39+
if (AliasTarget) {
40+
Changes.push({
41+
...change,
42+
ResourceRecordSet: {
43+
...change.ResourceRecordSet,
44+
AliasTarget: {
45+
...AliasTarget,
46+
HostedZoneId: AliasTarget.HostedZoneId.replace(
47+
IDENTIFIER_PREFIX_PATTERN,
48+
""
49+
)
50+
}
51+
}
52+
});
53+
} else {
54+
Changes.push(change);
55+
}
56+
}
57+
58+
return next({
59+
...args,
60+
input: {
61+
...(args.input as any),
62+
ChangeBatch: {
63+
...ChangeBatch,
64+
Changes
65+
}
66+
}
67+
});
68+
};
69+
}
70+
71+
export const changeResourceRecordSetsMiddlewareOptions: InitializeHandlerOptions = {
72+
step: "initialize",
73+
tags: ["ROUTE53_IDS", "CHANGE_RESOURCE_RECORD_SETS"],
74+
name: "changeResourceRecordSetsMiddleware"
75+
};
76+
77+
export const getChangeResourceRecordSetsPlugin = (
78+
unused: any
79+
): Pluggable<any, any> => ({
80+
applyToStack: clientStack => {
81+
clientStack.add(
82+
changeResourceRecordSetsMiddleware(),
83+
changeResourceRecordSetsMiddlewareOptions
84+
);
85+
}
86+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const IDENTIFIER_PREFIX_PATTERN = /^\/(hostedzone|change|delegationset)\//;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { idNormalizerMiddleware } from "./id-normalizer";
2+
3+
const prefixedProps = ["/hostedzone/ID", "/change/ID", "/delegationset/ID"];
4+
const idParams = ["DelegationSetId", "HostedZoneId", "Id"];
5+
6+
describe("idNormalizerMiddleware", () => {
7+
for (const paramName of idParams) {
8+
for (const prefixed of prefixedProps) {
9+
it(`should strip the prefix from the ${paramName} parameter`, async () => {
10+
const next = jest.fn();
11+
const input = { [paramName]: prefixed };
12+
13+
const handler = idNormalizerMiddleware()(next, {} as any);
14+
15+
await handler({ input });
16+
17+
expect(next.mock.calls.length).toBe(1);
18+
expect(next.mock.calls[0][0]).toEqual({
19+
input: { [paramName]: "ID" }
20+
});
21+
});
22+
}
23+
}
24+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import {
2+
InitializeHandler,
3+
InitializeMiddleware,
4+
InitializeHandlerArguments,
5+
InitializeHandlerOptions,
6+
InitializeHandlerOutput,
7+
MetadataBearer,
8+
Pluggable
9+
} from "@aws-sdk/types";
10+
import { IDENTIFIER_PREFIX_PATTERN } from "./constants";
11+
12+
export interface IdentifierBearer {
13+
DelegationSetId?: string;
14+
HostedZoneId?: string;
15+
Id?: string;
16+
}
17+
18+
const IDENTIFIER_PARAMETERS: Array<keyof IdentifierBearer> = [
19+
"DelegationSetId",
20+
"HostedZoneId",
21+
"Id"
22+
];
23+
24+
export function idNormalizerMiddleware(): InitializeMiddleware<any, any> {
25+
return <Output extends MetadataBearer>(
26+
next: InitializeHandler<any, Output>
27+
): InitializeHandler<any, Output> => async (
28+
args: InitializeHandlerArguments<any>
29+
): Promise<InitializeHandlerOutput<Output>> => {
30+
const input = { ...(args.input as any) };
31+
for (const paramName of IDENTIFIER_PARAMETERS) {
32+
const param = input[paramName];
33+
if (param) {
34+
input[paramName] = param.replace(IDENTIFIER_PREFIX_PATTERN, "");
35+
}
36+
}
37+
38+
return next({
39+
...args,
40+
input
41+
});
42+
};
43+
}
44+
45+
export const idNormalizerMiddlewareOptions: InitializeHandlerOptions = {
46+
step: "initialize",
47+
tags: ["ROUTE53_IDS"],
48+
name: "idNormalizerMiddleware"
49+
};
50+
51+
export const getIdNormalizerPlugin = (unused: any): Pluggable<any, any> => ({
52+
applyToStack: clientStack => {
53+
clientStack.add(idNormalizerMiddleware(), idNormalizerMiddlewareOptions);
54+
}
55+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import {
2+
changeResourceRecordSetsMiddleware,
3+
getChangeResourceRecordSetsPlugin,
4+
idNormalizerMiddleware,
5+
getIdNormalizerPlugin
6+
} from "./index";
7+
8+
describe("middleware-sdk-route53 package exports", () => {
9+
it("changeResourceRecordSetsMiddleware", () => {
10+
expect(typeof changeResourceRecordSetsMiddleware).toBe("function");
11+
});
12+
13+
it("getChangeResourceRecordSetsPlugin", () => {
14+
expect(typeof getChangeResourceRecordSetsPlugin).toBe("function");
15+
});
16+
17+
it("idNormalizerMiddleware", () => {
18+
expect(typeof idNormalizerMiddleware).toBe("function");
19+
});
20+
21+
it("getIdNormalizerPlugin", () => {
22+
expect(typeof getIdNormalizerPlugin).toBe("function");
23+
});
24+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export * from "./change-resource-record-sets";
2+
export * from "./id-normalizer";

0 commit comments

Comments
 (0)