Skip to content

Commit d62b991

Browse files
authored
feat: "cdk flags" command reports active and missing feature flags (unstable) (#699)
- Read feature flag artifacts from the Cloud Assembly - Introduces `cdk flags`, which displays user's current feature flag configuration in the form of a table --- By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license
1 parent 286b063 commit d62b991

30 files changed

+1396
-953
lines changed

.projenrc.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ import { TypecheckTests } from './projenrc/TypecheckTests';
2121

2222
const TYPESCRIPT_VERSION = '5.8';
2323

24+
// This is a temporary aws-cdk-lib version until this PR is released: https://github.com/aws/aws-cdk/pull/34919
25+
const AWS_CDK_LIB_VERSION = '2.203.0';
26+
2427
/**
2528
* When adding an SDK dependency for a library, use this function
2629
*
@@ -851,7 +854,7 @@ const toolkitLib = configureProject(
851854
'@smithy/util-stream',
852855
'@types/fs-extra',
853856
'@types/split2',
854-
'aws-cdk-lib',
857+
`aws-cdk-lib@${AWS_CDK_LIB_VERSION}`,
855858
'aws-sdk-client-mock',
856859
'aws-sdk-client-mock-jest',
857860
'fast-check',

packages/@aws-cdk/cli-lib-alpha/THIRD_PARTY_LICENSES

Lines changed: 52 additions & 52 deletions
Large diffs are not rendered by default.

packages/@aws-cdk/cli-lib-alpha/package.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk/integ-runner/THIRD_PARTY_LICENSES

Lines changed: 51 additions & 51 deletions
Large diffs are not rendered by default.

packages/@aws-cdk/integ-runner/package.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk/toolkit-lib/.projen/deps.json

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk/toolkit-lib/.projen/tasks.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk/toolkit-lib/lib/api/io/toolkit-action.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,5 @@ export type ToolkitAction =
1818
| 'metadata'
1919
| 'init'
2020
| 'migrate'
21-
| 'refactor';
21+
| 'refactor'
22+
| 'flags';

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

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import '../private/dispose-polyfill';
22
import * as path from 'node:path';
3+
import type { FeatureFlagReportProperties } from '@aws-cdk/cloud-assembly-schema';
4+
import { ArtifactType } from '@aws-cdk/cloud-assembly-schema';
35
import type { TemplateDiff } from '@aws-cdk/cloudformation-diff';
46
import * as cxapi from '@aws-cdk/cx-api';
57
import * as chalk from 'chalk';
@@ -9,7 +11,7 @@ import { NonInteractiveIoHost } from './non-interactive-io-host';
911
import type { ToolkitServices } from './private';
1012
import { assemblyFromSource } from './private';
1113
import { ToolkitError } from './toolkit-error';
12-
import type { DeployResult, DestroyResult, RollbackResult } from './types';
14+
import type { FeatureFlag, DeployResult, DestroyResult, RollbackResult } from './types';
1315
import type {
1416
BootstrapEnvironments,
1517
BootstrapOptions,
@@ -142,7 +144,7 @@ export interface ToolkitOptions {
142144
* Names of toolkit features that are still under development, and may change in
143145
* the future.
144146
*/
145-
export type UnstableFeature = 'refactor';
147+
export type UnstableFeature = 'refactor' | 'flags';
146148

147149
/**
148150
* The AWS CDK Programmatic Toolkit
@@ -1271,6 +1273,33 @@ export class Toolkit extends CloudAssemblySourceBuilder {
12711273
}
12721274
}
12731275

1276+
/**
1277+
* Retrieve feature flag information from the cloud assembly
1278+
*/
1279+
1280+
public async flags(cx: ICloudAssemblySource): Promise<FeatureFlag[]> {
1281+
this.requireUnstableFeature('flags');
1282+
1283+
const ioHelper = asIoHelper(this.ioHost, 'flags');
1284+
await using assembly = await assemblyFromSource(ioHelper, cx);
1285+
const artifacts = assembly.cloudAssembly.manifest.artifacts;
1286+
1287+
return Object.values(artifacts!)
1288+
.filter(a => a.type === ArtifactType.FEATURE_FLAG_REPORT)
1289+
.flatMap(report => {
1290+
const properties = report.properties as FeatureFlagReportProperties;
1291+
const moduleName = properties.module;
1292+
1293+
return Object.entries(properties.flags).map(([flagName, flagInfo]) => ({
1294+
module: moduleName,
1295+
name: flagName,
1296+
recommendedValue: flagInfo.recommendedValue,
1297+
userValue: flagInfo.userValue ?? undefined,
1298+
explanation: flagInfo.explanation ?? '',
1299+
}));
1300+
});
1301+
}
1302+
12741303
private requireUnstableFeature(requestedFeature: UnstableFeature) {
12751304
if (!this.unstableFeatures.includes(requestedFeature)) {
12761305
throw new ToolkitError(`Unstable feature '${requestedFeature}' is not enabled. Please enable it under 'unstableFeatures'`);

packages/@aws-cdk/toolkit-lib/lib/toolkit/types.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,3 +116,11 @@ export interface RolledBackStack extends PhysicalStack {
116116
}
117117

118118
export type StackRollbackResult = 'rolled-back' | 'already-stable';
119+
120+
export interface FeatureFlag {
121+
readonly module: string;
122+
readonly name: string;
123+
readonly recommendedValue: unknown;
124+
readonly userValue?: unknown;
125+
readonly explanation?: string;
126+
}

0 commit comments

Comments
 (0)