Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
public assertUsing(inspector: StackInspector): boolean {
const diff = cfnDiff.diffTemplate(this.template, inspector.value);
const acceptable = this.isDiffAcceptable(diff);
if (!acceptable) {
// Print the diff
cfnDiff.formatDifferences(process.stderr, diff);
// Print the actual template
process.stdout.write('--------------------------------------------------------------------------------------\n');
process.stdout.write(JSON.stringify(inspector.value, undefined, 2) + '\n');
}
return acceptable;
}
stream?: cfnDiff.FormatStream): number {
const diff = cfnDiff.diffTemplate(oldTemplate, newTemplate.template);
// filter out 'AWS::CDK::Metadata' resources from the template
if (diff.resources && !strict) {
diff.resources = diff.resources.filter(change => {
if (!change) { return true; }
if (change.newResourceType === 'AWS::CDK::Metadata') { return false; }
if (change.oldResourceType === 'AWS::CDK::Metadata') { return false; }
return true;
});
}
if (!diff.isEmpty) {
cfnDiff.formatDifferences(stream || process.stderr, diff, buildLogicalToPathMap(newTemplate), context);
} else {
print(colors.green('There were no differences'));
}
return diff.differenceCount;
}
async diffStack() {
const sdk = new cdk.SDK({})
const synthStack = this.synthesizeStack(this.projectName)
const cfn = await sdk.cloudFormation(synthStack.environment, 0)
const templateData = { StackName: synthStack.name }
const template = await cfn.getTemplate(templateData).promise()
const body = template.TemplateBody
const curTemplate = (body && yaml.parse(body, { schema: 'yaml-1.1' })) || {}
const logicalToPathMap = lib.createLogicalToPathMap(synthStack)
const diff = cfnDiff.diffTemplate(curTemplate, synthStack.template)
// tslint:disable-next-line:no-unused-expression
diff.isEmpty && lib.noChangesInDiff()
cfnDiff.formatDifferences(process.stdout, diff, logicalToPathMap)
}
}
const expected = await test.readExpected();
const args = new Array();
args.push('--no-path-metadata');
args.push('--no-asset-metadata');
args.push('--no-staging');
const actual = await test.invoke(['--json', ...args, 'synth'], { json: true, context: STATIC_TEST_CONTEXT });
const diff = diffTemplate(expected, actual);
if (!diff.isEmpty) {
failures.push(test.name);
process.stdout.write('CHANGED.\n');
formatDifferences(process.stdout, diff);
} else {
process.stdout.write('OK.\n');
}
}
if (failures.length > 0) {
// tslint:disable-next-line:max-line-length
throw new Error(`The following integ stacks have changed: ${failures.join(', ')}. Run 'npm run integ' to verify that everything still deploys.`);
}
}
process.stdout.write(`Verifying ${test.name} against ${test.expectedFileName}... `);
if (!test.hasExpected()) {
throw new Error(`No such file: ${test.expectedFileName}. Run 'npm run integ'.`);
}
const expected = await test.readExpected();
const args = new Array();
args.push('--no-path-metadata');
args.push('--no-asset-metadata');
args.push('--no-staging');
const actual = await test.invoke(['--json', ...args, 'synth'], { json: true, context: STATIC_TEST_CONTEXT });
const diff = diffTemplate(expected, actual);
if (!diff.isEmpty) {
failures.push(test.name);
process.stdout.write('CHANGED.\n');
formatDifferences(process.stdout, diff);
} else {
process.stdout.write('OK.\n');
}
}
if (failures.length > 0) {
// tslint:disable-next-line:max-line-length
throw new Error(`The following integ stacks have changed: ${failures.join(', ')}. Run 'npm run integ' to verify that everything still deploys.`);
}
}
export function printStackDiff(
oldTemplate: any,
newTemplate: cxapi.CloudFormationStackArtifact,
strict: boolean,
context: number,
stream?: cfnDiff.FormatStream): number {
const diff = cfnDiff.diffTemplate(oldTemplate, newTemplate.template);
// filter out 'AWS::CDK::Metadata' resources from the template
if (diff.resources && !strict) {
diff.resources = diff.resources.filter(change => {
if (!change) { return true; }
if (change.newResourceType === 'AWS::CDK::Metadata') { return false; }
if (change.oldResourceType === 'AWS::CDK::Metadata') { return false; }
return true;
});
}
if (!diff.isEmpty) {
cfnDiff.formatDifferences(stream || process.stderr, diff, buildLogicalToPathMap(newTemplate), context);
} else {
print(colors.green('There were no differences'));
}
export function printSecurityDiff(oldTemplate: any, newTemplate: cxapi.CloudFormationStackArtifact, requireApproval: RequireApproval): boolean {
const diff = cfnDiff.diffTemplate(oldTemplate, newTemplate.template);
if (difRequiresApproval(diff, requireApproval)) {
// tslint:disable-next-line:max-line-length
warning(`This deployment will make potentially sensitive changes according to your current security approval level (--require-approval ${requireApproval}).`);
warning(`Please confirm you intend to make the following modifications:\n`);
cfnDiff.formatSecurityChanges(process.stdout, diff, buildLogicalToPathMap(newTemplate));
return true;
}
return false;
}
public assertUsing(inspector: StackInspector): boolean {
const diff = cfnDiff.diffTemplate(this.template, inspector.value);
const acceptable = this.isDiffAcceptable(diff);
if (!acceptable) {
// Print the diff
cfnDiff.formatDifferences(process.stderr, diff);
// Print the actual template
process.stdout.write('--------------------------------------------------------------------------------------\n');
process.stdout.write(JSON.stringify(inspector.value, undefined, 2) + '\n');
}
return acceptable;
}
async diffStack() {
const sdk = new cdk.SDK({})
const synthStack = this.synthesizeStack(this.projectName)
const cfn = await sdk.cloudFormation(synthStack.environment, 0)
const templateData = { StackName: synthStack.name }
const template = await cfn.getTemplate(templateData).promise()
const body = template.TemplateBody
const curTemplate = (body && yaml.parse(body, { schema: 'yaml-1.1' })) || {}
const logicalToPathMap = lib.createLogicalToPathMap(synthStack)
const diff = cfnDiff.diffTemplate(curTemplate, synthStack.template)
// tslint:disable-next-line:no-unused-expression
diff.isEmpty && lib.noChangesInDiff()
cfnDiff.formatDifferences(process.stdout, diff, logicalToPathMap)
}
}
export function printSecurityDiff(oldTemplate: any, newTemplate: cxapi.CloudFormationStackArtifact, requireApproval: RequireApproval): boolean {
const diff = cfnDiff.diffTemplate(oldTemplate, newTemplate.template);
if (difRequiresApproval(diff, requireApproval)) {
// tslint:disable-next-line:max-line-length
warning(`This deployment will make potentially sensitive changes according to your current security approval level (--require-approval ${requireApproval}).`);
warning(`Please confirm you intend to make the following modifications:\n`);
cfnDiff.formatSecurityChanges(process.stdout, diff, buildLogicalToPathMap(newTemplate));
return true;
}
return false;
}