Skip to content

Commit b56bae9

Browse files
authored
Merge branch 'main' into conroy/teleminteg
2 parents 7dcb254 + 30ee4c9 commit b56bae9

File tree

8 files changed

+73
-21
lines changed

8 files changed

+73
-21
lines changed

packages/@aws-cdk-testing/cli-integ/tests/cli-integ-tests/cli-telemetry/cdk-cli-telemetry-reports-status.integtest.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ integTest(
1111
try {
1212
// default status is enabled
1313
const output1 = await fixture.cdk(['cli-telemetry', '--status']);
14-
expect(output1).toContain('CLI Telemetry is enabled. See https://github.com/aws/aws-cdk-cli/tree/main/packages/aws-cdk#cdk-cli-telemetry for ways to disable.');
14+
expect(output1).toContain('CLI Telemetry is enabled. See https://docs.aws.amazon.com/cdk/v2/guide/cli-telemetry.html for ways to disable.');
1515

1616
// disable status
1717
await fs.writeFile(userContextFile, JSON.stringify({ context: { 'cli-telemetry': false } }));
1818
const output2 = await fixture.cdk(['cli-telemetry', '--status']);
19-
expect(output2).toContain('CLI Telemetry is disabled. See https://github.com/aws/aws-cdk-cli/tree/main/packages/aws-cdk#cdk-cli-telemetry for ways to enable.');
19+
expect(output2).toContain('CLI Telemetry is disabled. See https://docs.aws.amazon.com/cdk/v2/guide/cli-telemetry.html for ways to enable.');
2020
} finally {
2121
await fs.unlink(userContextFile);
2222
}

packages/@aws-cdk/toolkit-lib/lib/api/cloudformation/template-body-parameter.ts

Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,21 @@ export async function makeBodyParameter(
9999
*
100100
* Replaces environment placeholders (which this field may contain),
101101
* and reformats s3://.../... urls into S3 REST URLs (which CloudFormation
102-
* expects)
102+
* expects).
103+
*
104+
* We need to return the official region- and partition-specific URL for AWS S3
105+
* here, so we use the SDK's information about endpoints. At the same time, the
106+
* SDK allows overriding this URL by setting an environment variable
107+
* (specifically $AWS_ENDPOINT_URL_S3) but we want to *not* honor that, because
108+
* there's a 99.9% chance this URL will not be routable from AWS CloudFormation.
109+
*
110+
* To allow for the off chance that someone is running this tool against a
111+
* custom build of CloudFormation that does need a specific S3 endpoint passed
112+
* to it, we'll introduce a new environment variable that we'll respect instead:
113+
*
114+
* AWS_ENDPOINT_URL_S3_FOR_CLOUDFORMATION
103115
*/
104-
async function restUrlFromManifest(url: string, environment: Environment): Promise<string> {
116+
export async function restUrlFromManifest(url: string, environment: Environment): Promise<string> {
105117
const doNotUseMarker = '**DONOTUSE**';
106118
const region = environment.region;
107119
// This URL may contain placeholders, so still substitute those.
@@ -127,13 +139,26 @@ async function restUrlFromManifest(url: string, environment: Environment): Promi
127139
const bucketName = s3Url[1];
128140
const objectKey = s3Url[2];
129141

130-
// SDK v3 no longer allows for getting endpoints from only region.
131-
// A command and client config must now be provided.
132-
const s3 = new S3Client({ region });
133-
const endpoint = await getEndpointFromInstructions({}, HeadObjectCommand, {
134-
...s3.config,
135-
});
136-
endpoint.url.hostname;
142+
const originalOverrideS3Endpoint = process.env.AWS_ENDPOINT_URL_S3;
143+
setEnv('AWS_ENDPOINT_URL_S3', process.env.AWS_ENDPOINT_URL_S3_FOR_CLOUDFORMATION);
144+
try {
145+
// SDK v3 no longer allows for getting endpoints from only region.
146+
// A command and client config must now be provided.
147+
const s3 = new S3Client({ region });
148+
const endpoint = await getEndpointFromInstructions({}, HeadObjectCommand, {
149+
...s3.config,
150+
});
151+
152+
return `${endpoint.url.origin}/${bucketName}/${objectKey}`;
153+
} finally {
154+
setEnv('AWS_ENDPOINT_URL_S3', originalOverrideS3Endpoint);
155+
}
156+
}
137157

138-
return `${endpoint.url.origin}/${bucketName}/${objectKey}`;
158+
function setEnv(name: string, value: string | undefined) {
159+
if (value) {
160+
process.env[name] = value;
161+
} else {
162+
delete process.env[name];
163+
}
139164
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { restUrlFromManifest } from '../../../lib/api/cloudformation/template-body-parameter';
2+
3+
test('restUrlFromManifest ignores AWS_ENDPOINT_URL_S3', async () => {
4+
process.env.AWS_ENDPOINT_URL_S3 = 'https://boop.com/';
5+
try {
6+
await expect(restUrlFromManifest('s3://my-bucket/object', {
7+
account: '123456789012',
8+
region: 'us-east-1',
9+
name: 'env',
10+
})).resolves.toEqual('https://s3.us-east-1.amazonaws.com/my-bucket/object');
11+
} finally {
12+
delete process.env.AWS_ENDPOINT_URL_S3;
13+
}
14+
});
15+
16+
test('restUrlFromManifest respects AWS_ENDPOINT_URL_S3_FOR_CLOUDFORMATION', async () => {
17+
process.env.AWS_ENDPOINT_URL_S3_FOR_CLOUDFORMATION = 'https://boop.com/';
18+
try {
19+
await expect(restUrlFromManifest('s3://my-bucket/object', {
20+
account: '123456789012',
21+
region: 'us-east-1',
22+
name: 'env',
23+
})).resolves.toEqual('https://boop.com/my-bucket/object');
24+
} finally {
25+
delete process.env.AWS_ENDPOINT_URL_S3_FOR_CLOUDFORMATION;
26+
}
27+
});

packages/aws-cdk/lib/cli/cdk-toolkit.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,9 +210,9 @@ export class CdkToolkit {
210210
const args = { ['version-reporting']: versionReporting };
211211
const canCollect = canCollectTelemetry(args, this.props.configuration.context);
212212
if (canCollect) {
213-
await this.ioHost.asIoHelper().defaults.info('CLI Telemetry is enabled. See https://github.com/aws/aws-cdk-cli/tree/main/packages/aws-cdk#cdk-cli-telemetry for ways to disable.');
213+
await this.ioHost.asIoHelper().defaults.info('CLI Telemetry is enabled. See https://docs.aws.amazon.com/cdk/v2/guide/cli-telemetry.html for ways to disable.');
214214
} else {
215-
await this.ioHost.asIoHelper().defaults.info('CLI Telemetry is disabled. See https://github.com/aws/aws-cdk-cli/tree/main/packages/aws-cdk#cdk-cli-telemetry for ways to enable.');
215+
await this.ioHost.asIoHelper().defaults.info('CLI Telemetry is disabled. See https://docs.aws.amazon.com/cdk/v2/guide/cli-telemetry.html for ways to enable.');
216216
}
217217
}
218218

packages/aws-cdk/lib/init-templates/app/typescript/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"ts-jest": "^29.2.5",
1818
"aws-cdk": "%cdk-cli-version%",
1919
"ts-node": "^10.9.2",
20-
"typescript": "~5.6.3"
20+
"typescript": "~5.9.3"
2121
},
2222
"dependencies": {
2323
"aws-cdk-lib": "%cdk-version%",

packages/aws-cdk/lib/init-templates/lib/typescript/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"constructs": "%constructs-version%",
1616
"jest": "^29.7.0",
1717
"ts-jest": "^29.2.5",
18-
"typescript": "~5.6.3"
18+
"typescript": "~5.9.3"
1919
},
2020
"peerDependencies": {
2121
"aws-cdk-lib": "%cdk-version%",

packages/aws-cdk/lib/init-templates/sample-app/typescript/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"ts-jest": "^29.2.5",
1818
"aws-cdk": "%cdk-cli-version%",
1919
"ts-node": "^10.9.2",
20-
"typescript": "~5.6.3"
20+
"typescript": "~5.9.3"
2121
},
2222
"dependencies": {
2323
"aws-cdk-lib": "%cdk-version%",

packages/aws-cdk/test/commands/telemetry.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ describe('telemetry command', () => {
4646
await toolkit.cliTelemetryStatus();
4747

4848
// THEN
49-
expect(notifySpy).toHaveBeenCalledWith(expect.objectContaining({ level: 'info', message: 'CLI Telemetry is enabled. See https://github.com/aws/aws-cdk-cli/tree/main/packages/aws-cdk#cdk-cli-telemetry for ways to disable.' }));
49+
expect(notifySpy).toHaveBeenCalledWith(expect.objectContaining({ level: 'info', message: 'CLI Telemetry is enabled. See https://docs.aws.amazon.com/cdk/v2/guide/cli-telemetry.html for ways to disable.' }));
5050
});
5151

5252
test('status reports current telemetry status -- enabled intentionally', async () => {
@@ -55,7 +55,7 @@ describe('telemetry command', () => {
5555
await toolkit.cliTelemetryStatus();
5656

5757
// THEN
58-
expect(notifySpy).toHaveBeenCalledWith(expect.objectContaining({ level: 'info', message: 'CLI Telemetry is enabled. See https://github.com/aws/aws-cdk-cli/tree/main/packages/aws-cdk#cdk-cli-telemetry for ways to disable.' }));
58+
expect(notifySpy).toHaveBeenCalledWith(expect.objectContaining({ level: 'info', message: 'CLI Telemetry is enabled. See https://docs.aws.amazon.com/cdk/v2/guide/cli-telemetry.html for ways to disable.' }));
5959
});
6060

6161
test('status reports current telemetry status -- disabled via context', async () => {
@@ -64,7 +64,7 @@ describe('telemetry command', () => {
6464
await toolkit.cliTelemetryStatus();
6565

6666
// THEN
67-
expect(notifySpy).toHaveBeenCalledWith(expect.objectContaining({ level: 'info', message: 'CLI Telemetry is disabled. See https://github.com/aws/aws-cdk-cli/tree/main/packages/aws-cdk#cdk-cli-telemetry for ways to enable.' }));
67+
expect(notifySpy).toHaveBeenCalledWith(expect.objectContaining({ level: 'info', message: 'CLI Telemetry is disabled. See https://docs.aws.amazon.com/cdk/v2/guide/cli-telemetry.html for ways to enable.' }));
6868
});
6969

7070
test('status reports current telemetry status -- disabled via env var', async () => {
@@ -73,7 +73,7 @@ describe('telemetry command', () => {
7373
await toolkit.cliTelemetryStatus();
7474

7575
// THEN
76-
expect(notifySpy).toHaveBeenCalledWith(expect.objectContaining({ level: 'info', message: 'CLI Telemetry is disabled. See https://github.com/aws/aws-cdk-cli/tree/main/packages/aws-cdk#cdk-cli-telemetry for ways to enable.' }));
76+
expect(notifySpy).toHaveBeenCalledWith(expect.objectContaining({ level: 'info', message: 'CLI Telemetry is disabled. See https://docs.aws.amazon.com/cdk/v2/guide/cli-telemetry.html for ways to enable.' }));
7777
}, {
7878
CDK_DISABLE_CLI_TELEMETRY: 'true',
7979
});

0 commit comments

Comments
 (0)