Skip to content

Commit 05d3c83

Browse files
committed
fix: generate no-touch notice in codegen
1 parent 58862ef commit 05d3c83

File tree

8 files changed

+84
-11
lines changed

8 files changed

+84
-11
lines changed

clients/client-sts/defaultRoleAssumers.spec.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// Please do not touch this file. It's generated from template in:
2+
// https://github.com/aws/aws-sdk-js-v3/blob/main/codegen/smithy-aws-typescript-codegen/src/main/resources/software/amazon/smithy/aws/typescript/codegen/sts-client-defaultRoleAssumers.spec.ts
13
import { HttpResponse } from "@aws-sdk/protocol-http";
24
import { Readable } from "stream";
35
const assumeRoleResponse = `<AssumeRoleResponse xmlns="https://sts.amazonaws.com/doc/2011-06-15/">

clients/client-sts/defaultRoleAssumers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Please do not touch this file. It's generated from template:
1+
// Please do not touch this file. It's generated from template in:
22
// https://github.com/aws/aws-sdk-js-v3/blob/main/codegen/smithy-aws-typescript-codegen/src/main/resources/software/amazon/smithy/aws/typescript/codegen/sts-client-defaultRoleAssumers.ts
33
import {
44
DefaultCredentialProvider,

clients/client-sts/defaultStsRoleAssumers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Please do not touch this file. It's generated from template:
1+
// Please do not touch this file. It's generated from template in:
22
// https://github.com/aws/aws-sdk-js-v3/blob/main/codegen/smithy-aws-typescript-codegen/src/main/resources/software/amazon/smithy/aws/typescript/codegen/sts-client-defaultStsRoleAssumers.ts
33
import { Credentials, Provider } from "@aws-sdk/types";
44

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

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import static software.amazon.smithy.typescript.codegen.integration.RuntimeClientPlugin.Convention.HAS_CONFIG;
2020
import static software.amazon.smithy.typescript.codegen.integration.RuntimeClientPlugin.Convention.HAS_MIDDLEWARE;
2121

22+
import java.io.File;
2223
import java.util.Collections;
2324
import java.util.List;
2425
import java.util.Map;
@@ -53,6 +54,7 @@
5354
public final class AddAwsAuthPlugin implements TypeScriptIntegration {
5455
static final String STS_CLIENT_PREFIX = "sts-client-";
5556
static final String ROLE_ASSUMERS_FILE = "defaultRoleAssumers";
57+
static final String ROLE_ASSUMERS_TEST_FILE = "defaultRoleAssumers.spec";
5658
static final String STS_ROLE_ASSUMERS_FILE = "defaultStsRoleAssumers";
5759

5860
@Override
@@ -155,14 +157,25 @@ public void writeAdditionalFiles(
155157
if (!testServiceId(service, "STS")) {
156158
return;
157159
}
160+
String noTouchNoticePrefix = "// Please do not touch this file. It's generated from template in:\n"
161+
+ "// https://github.com/aws/aws-sdk-js-v3/blob/main/codegen/smithy-aws-typescript-codegen/"
162+
+ "src/main/resources/software/amazon/smithy/aws/typescript/codegen/";
158163
writerFactory.accept("defaultRoleAssumers.ts", writer -> {
159-
String source = IoUtils.readUtf8Resource(getClass(),
160-
String.format("%s%s.ts", STS_CLIENT_PREFIX, ROLE_ASSUMERS_FILE));
164+
String resourceName = String.format("%s%s.ts", STS_CLIENT_PREFIX, ROLE_ASSUMERS_FILE);
165+
String source = IoUtils.readUtf8Resource(getClass(), resourceName);
166+
writer.write("$L$L", noTouchNoticePrefix, resourceName);
161167
writer.write("$L", source);
162168
});
163169
writerFactory.accept("defaultStsRoleAssumers.ts", writer -> {
164-
String source = IoUtils.readUtf8Resource(getClass(),
165-
String.format("%s%s.ts", STS_CLIENT_PREFIX, STS_ROLE_ASSUMERS_FILE));
170+
String resourceName = String.format("%s%s.ts", STS_CLIENT_PREFIX, STS_ROLE_ASSUMERS_FILE);
171+
String source = IoUtils.readUtf8Resource(getClass(), resourceName);
172+
writer.write("$L$L", noTouchNoticePrefix, resourceName);
173+
writer.write("$L", source);
174+
});
175+
writerFactory.accept("defaultRoleAssumers.spec.ts", writer -> {
176+
String resourceName = String.format("%s%s.ts", STS_CLIENT_PREFIX, ROLE_ASSUMERS_TEST_FILE);
177+
String source = IoUtils.readUtf8Resource(getClass(), resourceName);
178+
writer.write("$L$L", noTouchNoticePrefix, resourceName);
166179
writer.write("$L", source);
167180
});
168181
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import { HttpResponse } from "@aws-sdk/protocol-http";
2+
import { Readable } from "stream";
3+
const assumeRoleResponse = `<AssumeRoleResponse xmlns="https://sts.amazonaws.com/doc/2011-06-15/">
4+
<AssumeRoleResult>
5+
<AssumedRoleUser>
6+
<AssumedRoleId>AROAZOX2IL27GNRBJHWC2:session</AssumedRoleId>
7+
<Arn>arn:aws:sts::123:assumed-role/assume-role-test/session</Arn>
8+
</AssumedRoleUser>
9+
<Credentials>
10+
<AccessKeyId>key</AccessKeyId>
11+
<SecretAccessKey>secrete</SecretAccessKey>
12+
<SessionToken>session-token</SessionToken>
13+
<Expiration>2021-05-05T23:22:08Z</Expiration>
14+
</Credentials>
15+
</AssumeRoleResult>
16+
<ResponseMetadata>
17+
<RequestId>12345678id</RequestId>
18+
</ResponseMetadata>
19+
</AssumeRoleResponse>`;
20+
const mockHandle = jest.fn().mockResolvedValue({
21+
response: new HttpResponse({
22+
statusCode: 200,
23+
body: Readable.from([""]),
24+
}),
25+
});
26+
jest.mock("@aws-sdk/node-http-handler", () => ({
27+
NodeHttpHandler: jest.fn().mockImplementation(() => ({
28+
destroy: () => {},
29+
handle: mockHandle,
30+
})),
31+
streamCollector: async () => Buffer.from(assumeRoleResponse),
32+
}));
33+
34+
import { getDefaultRoleAssumer } from "./defaultRoleAssumers";
35+
import type { AssumeRoleCommandInput } from "./commands/AssumeRoleCommand";
36+
37+
describe("getDefaultRoleAssumer", () => {
38+
beforeEach(() => {
39+
jest.clearAllMocks();
40+
});
41+
it("should use supplied source credentials", async () => {
42+
const roleAssumer = getDefaultRoleAssumer();
43+
const params: AssumeRoleCommandInput = {
44+
RoleArn: "arn:aws:foo",
45+
RoleSessionName: "session",
46+
};
47+
const sourceCred1 = { accessKeyId: "key1", secretAccessKey: "secrete1" };
48+
await roleAssumer(sourceCred1, params);
49+
expect(mockHandle).toBeCalledTimes(1);
50+
// Validate request is signed by sourceCred1
51+
expect(mockHandle.mock.calls[0][0].headers?.authorization).toEqual(
52+
expect.stringContaining("AWS4-HMAC-SHA256 Credential=key1/")
53+
);
54+
const sourceCred2 = { accessKeyId: "key2", secretAccessKey: "secrete1" };
55+
await roleAssumer(sourceCred2, params);
56+
// Validate request is signed by sourceCred2
57+
expect(mockHandle).toBeCalledTimes(2);
58+
expect(mockHandle.mock.calls[1][0].headers?.authorization).toEqual(
59+
expect.stringContaining("AWS4-HMAC-SHA256 Credential=key2/")
60+
);
61+
});
62+
});

codegen/smithy-aws-typescript-codegen/src/main/resources/software/amazon/smithy/aws/typescript/codegen/sts-client-defaultRoleAssumers.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// Please do not touch this file. It's generated from template:
2-
// https://github.com/aws/aws-sdk-js-v3/blob/main/codegen/smithy-aws-typescript-codegen/src/main/resources/software/amazon/smithy/aws/typescript/codegen/sts-client-defaultRoleAssumers.ts
31
import {
42
DefaultCredentialProvider,
53
getDefaultRoleAssumer as StsGetDefaultRoleAssumer,

codegen/smithy-aws-typescript-codegen/src/main/resources/software/amazon/smithy/aws/typescript/codegen/sts-client-defaultStsRoleAssumers.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// Please do not touch this file. It's generated from template:
2-
// https://github.com/aws/aws-sdk-js-v3/blob/main/codegen/smithy-aws-typescript-codegen/src/main/resources/software/amazon/smithy/aws/typescript/codegen/sts-client-defaultStsRoleAssumers.ts
31
import { Credentials, Provider } from "@aws-sdk/types";
42

53
import { AssumeRoleCommand, AssumeRoleCommandInput } from "./commands/AssumeRoleCommand";

scripts/generate-clients/copy-to-clients.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const getOverwritablePredicate = (packageName) => (pathName) => {
2121
"README.md",
2222
];
2323
const additionalGeneratedFiles = {
24-
"@aws-sdk/client-sts": ["defaultRoleAssumers.ts", "defaultStsRoleAssumers.ts"],
24+
"@aws-sdk/client-sts": ["defaultRoleAssumers.ts", "defaultStsRoleAssumers.ts", "defaultRoleAssumers.spec.ts"],
2525
};
2626
return (
2727
pathName

0 commit comments

Comments
 (0)