Skip to content

Commit cd58b50

Browse files
authored
chore: add option unacknowledged to cdk notices (#31250)
### Issue # (if applicable) Closes #23078 ### Reason for this change `cdk notices` will show all the notices the cdk version is affected by. The additional command `cdk notices --unacknowledged` will show the notices the customer hasn't acknowledge with `cdk acknowledge <NUMBER>`. The output will display the number of unacknowledged notices, with the following line as the last statement: `There are <NUMBER> unacknowledged notice(s).` Customer or automation tools can use this command to filter for the number of unacknowledged notices. ### Checklist - [x] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md) ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 130b62b commit cd58b50

File tree

5 files changed

+188
-6
lines changed

5 files changed

+188
-6
lines changed

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

+10
Original file line numberDiff line numberDiff line change
@@ -2190,3 +2190,13 @@ async function listChildren(parent: string, pred: (x: string) => Promise<boolean
21902190
async function listChildDirs(parent: string) {
21912191
return listChildren(parent, async (fullPath: string) => (await fs.stat(fullPath)).isDirectory());
21922192
}
2193+
2194+
integTest(
2195+
'cdk notices with --unacknowledged',
2196+
withDefaultFixture(async (fixture) => {
2197+
const noticesUnacknowledged = await fixture.cdk(['notices', '--unacknowledged'], { verbose: false });
2198+
const noticesUnacknowledgedAlias = await fixture.cdk(['notices', '-u'], { verbose: false });
2199+
expect(noticesUnacknowledged).toEqual(expect.stringMatching(/There are \d{1,} unacknowledged notice\(s\)./));
2200+
expect(noticesUnacknowledged).toEqual(noticesUnacknowledgedAlias);
2201+
}),
2202+
);

packages/aws-cdk/README.md

+25
Original file line numberDiff line numberDiff line change
@@ -963,6 +963,31 @@ NOTICES
963963
If you don’t want to see a notice anymore, use "cdk acknowledge <id>". For example, "cdk acknowledge 16603".
964964
```
965965

966+
List the unacknowledged notices:
967+
968+
```console
969+
$ cdk notices --unacknowledged
970+
971+
NOTICES (What's this? https://github.com/aws/aws-cdk/wiki/CLI-Notices)
972+
973+
29483 (cli): Upgrading to v2.132.0 or v2.132.1 breaks cdk diff functionality
974+
975+
Overview: cdk diff functionality used to rely on assuming lookup-role.
976+
With a recent change present in v2.132.0 and v2.132.1, it is
977+
now trying to assume deploy-role with the lookup-role. This
978+
leads to an authorization error if permissions were not
979+
defined to assume deploy-role.
980+
981+
Affected versions: cli: >=2.132.0 <=2.132.1
982+
983+
More information at: https://github.com/aws/aws-cdk/issues/29483
984+
985+
986+
If you don’t want to see a notice anymore, use "cdk acknowledge <id>". For example, "cdk acknowledge 29483".
987+
988+
There are 1 unacknowledged notice(s).
989+
```
990+
966991
### Bundling
967992

968993
By default asset bundling is skipped for `cdk list` and `cdk destroy`. For `cdk deploy`, `cdk diff`

packages/aws-cdk/lib/cli.ts

+11-2
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,9 @@ async function parseCommandLineArguments(args: string[]) {
268268
.option('change-set', { type: 'boolean', alias: 'changeset', desc: 'Whether to create a changeset to analyze resource replacements. In this mode, diff will use the deploy role instead of the lookup role.', default: true }))
269269
.command('metadata [STACK]', 'Returns all metadata associated with this stack')
270270
.command(['acknowledge [ID]', 'ack [ID]'], 'Acknowledge a notice so that it does not show up anymore')
271-
.command('notices', 'Returns a list of relevant notices')
271+
.command('notices', 'Returns a list of relevant notices', (yargs: Argv) => yargs
272+
.option('unacknowledged', { type: 'boolean', alias: 'u', default: false, desc: 'Returns a list of unacknowledged notices' }),
273+
)
272274
.command('init [TEMPLATE]', 'Create a new, empty CDK project from a template.', (yargs: Argv) => yargs
273275
.option('language', { type: 'string', alias: 'l', desc: 'The language to be used for the new project (default can be configured in ~/.cdk.json)', choices: initTemplateLanguages })
274276
.option('list', { type: 'boolean', desc: 'List the available templates' })
@@ -439,7 +441,14 @@ export async function exec(args: string[], synthesizer?: Synthesizer): Promise<n
439441
await version.displayVersionMessage();
440442

441443
if (shouldDisplayNotices()) {
442-
if (cmd === 'notices') {
444+
if (cmd === 'notices' && argv.unacknowledged === true) {
445+
await displayNotices({
446+
outdir: configuration.settings.get(['output']) ?? 'cdk.out',
447+
acknowledgedIssueNumbers: configuration.context.get('acknowledged-issue-numbers') ?? [],
448+
ignoreCache: true,
449+
unacknowledged: true,
450+
});
451+
} else if (cmd === 'notices') {
443452
await displayNotices({
444453
outdir: configuration.settings.get(['output']) ?? 'cdk.out',
445454
acknowledgedIssueNumbers: [],

packages/aws-cdk/lib/notices.ts

+19-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import * as path from 'path';
44
import * as fs from 'fs-extra';
55
import * as semver from 'semver';
66
import { debug, print } from './logging';
7-
import { some, ConstructTreeNode, loadTreeFromDir } from './tree';
7+
import { ConstructTreeNode, loadTreeFromDir, some } from './tree';
88
import { flatMap } from './util';
99
import { cdkCacheDir } from './util/directories';
1010
import { versionNumber } from './version';
@@ -30,6 +30,13 @@ export interface DisplayNoticesProps {
3030
* @default false
3131
*/
3232
readonly ignoreCache?: boolean;
33+
34+
/**
35+
* Whether to append the number of unacknowledged notices to the display.
36+
*
37+
* @default false
38+
*/
39+
readonly unacknowledged?: boolean;
3340
}
3441

3542
export async function refreshNotices() {
@@ -50,11 +57,19 @@ export async function generateMessage(dataSource: NoticeDataSource, props: Displ
5057
acknowledgedIssueNumbers: new Set(props.acknowledgedIssueNumbers),
5158
});
5259

60+
let messageString: string = '';
5361
if (filteredNotices.length > 0) {
54-
const individualMessages = formatNotices(filteredNotices);
55-
return finalMessage(individualMessages, filteredNotices[0].issueNumber);
62+
messageString = getFilteredMessages(filteredNotices);
63+
}
64+
if (props.unacknowledged) {
65+
messageString = [messageString, `There are ${filteredNotices.length} unacknowledged notice(s).`].join('\n\n');
5666
}
57-
return '';
67+
return messageString;
68+
}
69+
70+
function getFilteredMessages(filteredNotices: Notice[]): string {
71+
const individualMessages = formatNotices(filteredNotices);
72+
return finalMessage(individualMessages, filteredNotices[0].issueNumber);
5873
}
5974

6075
function dataSourceReference(ignoreCache: boolean): NoticeDataSource {

packages/aws-cdk/test/notices.test.ts

+123
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,32 @@ const MULTIPLE_AFFECTED_VERSIONS_NOTICE = {
3737
schemaVersion: '1',
3838
};
3939

40+
const CLI_2_132_AFFECTED_NOTICE_1 = {
41+
title: '(cli): Some bug affecting cdk deploy.',
42+
issueNumber: 29420,
43+
overview: 'cdk deploy bug',
44+
components: [
45+
{
46+
name: 'cli',
47+
version: '2.132.0',
48+
},
49+
],
50+
schemaVersion: '1',
51+
};
52+
53+
const CLI_2_132_AFFECTED_NOTICE_2 = {
54+
title: '(cli): Some bug affecting cdk diff.',
55+
issueNumber: 29483,
56+
overview: 'cdk diff bug',
57+
components: [
58+
{
59+
name: 'cli',
60+
version: '>=2.132.0 <=2.132.1',
61+
},
62+
],
63+
schemaVersion: '1',
64+
};
65+
4066
const FRAMEWORK_2_1_0_AFFECTED_NOTICE = {
4167
title: 'Regression on module foobar',
4268
issueNumber: 1234,
@@ -381,6 +407,19 @@ describe('cli notices', () => {
381407
expect(result).toEqual('');
382408
});
383409

410+
test('Shows no notices when there are no notices with --unacknowledged', async () => {
411+
const dataSource = createDataSource();
412+
dataSource.fetch.mockResolvedValue([]);
413+
414+
const result = await generateMessage(dataSource, {
415+
acknowledgedIssueNumbers: [],
416+
outdir: '/tmp',
417+
unacknowledged: true,
418+
});
419+
420+
expect(result).toEqual('\n\nThere are 0 unacknowledged notice(s).');
421+
});
422+
384423
test('shows notices that pass the filter', async () => {
385424
const dataSource = createDataSource();
386425
dataSource.fetch.mockResolvedValue([BASIC_NOTICE, MULTIPLE_AFFECTED_VERSIONS_NOTICE]);
@@ -415,3 +454,87 @@ If you don’t want to see a notice anymore, use "cdk acknowledge <id>". For exa
415454
}
416455
});
417456
});
457+
458+
describe('mock cdk version 2.132.0', () => {
459+
beforeAll(() => {
460+
jest
461+
.spyOn(version, 'versionNumber')
462+
.mockImplementation(() => '2.132.0');
463+
});
464+
465+
afterAll(() => {
466+
jest.restoreAllMocks();
467+
});
468+
469+
test('Shows notices that pass the filter with --unacknowledged', async () => {
470+
const dataSource = createDataSource();
471+
dataSource.fetch.mockResolvedValue([CLI_2_132_AFFECTED_NOTICE_1, CLI_2_132_AFFECTED_NOTICE_2]);
472+
473+
const allNotices = await generateMessage(dataSource, {
474+
acknowledgedIssueNumbers: [],
475+
outdir: '/tmp',
476+
unacknowledged: true,
477+
});
478+
479+
expect(allNotices).toEqual(`
480+
NOTICES (What's this? https://github.com/aws/aws-cdk/wiki/CLI-Notices)
481+
482+
29420 (cli): Some bug affecting cdk deploy.
483+
484+
Overview: cdk deploy bug
485+
486+
Affected versions: cli: 2.132.0
487+
488+
More information at: https://github.com/aws/aws-cdk/issues/29420
489+
490+
491+
29483 (cli): Some bug affecting cdk diff.
492+
493+
Overview: cdk diff bug
494+
495+
Affected versions: cli: >=2.132.0 <=2.132.1
496+
497+
More information at: https://github.com/aws/aws-cdk/issues/29483
498+
499+
500+
If you don’t want to see a notice anymore, use "cdk acknowledge <id>". For example, "cdk acknowledge 29420".
501+
502+
There are 2 unacknowledged notice(s).`);
503+
504+
const acknowledgeNotice29420 = await generateMessage(dataSource, {
505+
acknowledgedIssueNumbers: [29420],
506+
outdir: '/tmp',
507+
unacknowledged: true,
508+
});
509+
510+
expect(acknowledgeNotice29420).toEqual(`
511+
NOTICES (What's this? https://github.com/aws/aws-cdk/wiki/CLI-Notices)
512+
513+
29483 (cli): Some bug affecting cdk diff.
514+
515+
Overview: cdk diff bug
516+
517+
Affected versions: cli: >=2.132.0 <=2.132.1
518+
519+
More information at: https://github.com/aws/aws-cdk/issues/29483
520+
521+
522+
If you don’t want to see a notice anymore, use "cdk acknowledge <id>". For example, "cdk acknowledge 29483".
523+
524+
There are 1 unacknowledged notice(s).`);
525+
526+
const allAcknowledgedNotices = await generateMessage(dataSource, {
527+
acknowledgedIssueNumbers: [29420, 29483],
528+
outdir: '/tmp',
529+
unacknowledged: true,
530+
});
531+
532+
expect(allAcknowledgedNotices).toEqual('\n\nThere are 0 unacknowledged notice(s).');
533+
534+
function createDataSource() {
535+
return {
536+
fetch: jest.fn(),
537+
};
538+
}
539+
});
540+
});

0 commit comments

Comments
 (0)