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.`);
}
}
private async printChanges() {
cfnDiff.formatDifferences(process.stdout, this.diff, this.logicalToPathMap)
return true
}
}