Skip to content

Commit

Permalink
template obscurement
Browse files Browse the repository at this point in the history
  • Loading branch information
comcalvi committed Aug 12, 2024
1 parent 7d2e9d0 commit 9cc1a01
Showing 1 changed file with 31 additions and 6 deletions.
37 changes: 31 additions & 6 deletions packages/aws-cdk/lib/cdk-toolkit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ export class CdkToolkit {

public async metadata(stackName: string, json: boolean) {
const stacks = await this.selectSingleStackByName(stackName);
data(serializeStructure(stacks.firstStack.manifest.metadata ?? {}, json));
printSerializedObject(stacks.firstStack.manifest.metadata ?? {}, json);
}

public async acknowledge(noticeId: string) {
Expand Down Expand Up @@ -632,7 +632,7 @@ export class CdkToolkit {
});

if (options.long && options.showDeps) {
data(serializeStructure(stacks, options.json ?? false));
printSerializedObject(stacks, options.json ?? false);
return 0;
}

Expand All @@ -646,7 +646,7 @@ export class CdkToolkit {
});
}

data(serializeStructure(stackDeps, options.json ?? false));
printSerializedObject(stackDeps, options.json ?? false);
return 0;
}

Expand All @@ -660,7 +660,7 @@ export class CdkToolkit {
environment: stack.environment,
});
}
data(serializeStructure(long, options.json ?? false));
printSerializedObject(long, options.json ?? false);
return 0;
}

Expand All @@ -687,7 +687,7 @@ export class CdkToolkit {
// if we have a single stack, print it to STDOUT
if (stacks.stackCount === 1) {
if (!quiet) {
data(serializeStructure(stacks.firstStack.template, json ?? false));
printSerializedObject(obscureTemplate(stacks.firstStack.template), json ?? false);
}
return undefined;
}
Expand All @@ -701,7 +701,7 @@ export class CdkToolkit {
// behind an environment variable.
const isIntegMode = process.env.CDK_INTEG_MODE === '1';
if (isIntegMode) {
data(serializeStructure(stacks.stackArtifacts.map(s => s.template), json ?? false));
printSerializedObject(stacks.stackArtifacts.map(s => obscureTemplate(s.template)), json ?? false);
}

// not outputting template to stdout, let's explain things to the user a little bit...
Expand Down Expand Up @@ -1045,6 +1045,13 @@ export class CdkToolkit {
}
}

/**
* Print a serialized object (YAML or JSON) to stdout.
*/
function printSerializedObject(obj: any, json: boolean) {
data(serializeStructure(obj, json));
}

export interface DiffOptions {
/**
* Stack names to diff
Expand Down Expand Up @@ -1526,3 +1533,21 @@ function buildParameterMap(parameters: {

return parameterMap;
}

/**
* Remove any template elements that we don't want to show users.
*/
function obscureTemplate(template: any = {}) {
if (template.Rules) {
// see https://github.com/aws/aws-cdk/issues/17942
if (template.Rules.CheckBootstrapVersion) {
if (Object.keys(template.Rules).length > 2) {
delete template.Rules.CheckBootstrapVersion;
} else {
delete template.Rules;
}
}
}

return template;
}

0 comments on commit 9cc1a01

Please sign in to comment.