@aws-cdk/cloudformation-diff
Version:
Utilities to diff CDK stacks against CloudFormation templates
109 lines (108 loc) • 5.04 kB
TypeScript
import type { DifferenceCollection, TemplateDiff } from './diff/types';
import type { Difference, ResourceDifference } from './diff-template';
import { ResourceImpact } from './diff-template';
import type { IamChanges } from './iam/iam-changes';
import type { SecurityGroupChanges } from './network/security-group-changes';
export interface FormatStream extends NodeJS.WritableStream {
columns?: number;
}
/**
* Renders template differences to the process' console.
*
* @param stream - The IO stream where to output the rendered diff.
* @param templateDiff - TemplateDiff to be rendered to the console.
* @param logicalToPathMap - A map from logical ID to construct path. Useful in
* case there is no aws:cdk:path metadata in the template.
* @param context - the number of context lines to use in arbitrary JSON diff (defaults to 3).
*/
export declare function formatDifferences(stream: FormatStream, templateDiff: TemplateDiff, logicalToPathMap?: {
[logicalId: string]: string;
}, context?: number): void;
/**
* Renders a diff of security changes to the given stream
*/
export declare function formatSecurityChanges(stream: NodeJS.WritableStream, templateDiff: TemplateDiff, logicalToPathMap?: {
[logicalId: string]: string;
}, context?: number): void;
export declare class Formatter {
private readonly stream;
private readonly logicalToPathMap;
private readonly context;
constructor(stream: FormatStream, logicalToPathMap: {
[logicalId: string]: string;
}, diff?: TemplateDiff, context?: number);
print(fmt: string, ...args: any[]): void;
warning(fmt: string, ...args: any[]): void;
formatSection<V, T extends Difference<V>>(title: string, entryType: string, collection: DifferenceCollection<V, T>, formatter?: (type: string, id: string, diff: T) => void): void;
printSectionHeader(title: string): void;
printSectionFooter(): void;
/**
* Print a simple difference for a given named entity.
*
* @param logicalId - the name of the entity that is different.
* @param diff - the difference to be rendered.
*/
formatDifference(type: string, logicalId: string, diff: Difference<any> | undefined): void;
/**
* Print a resource difference for a given logical ID.
*
* @param logicalId - the logical ID of the resource that changed.
* @param diff - the change to be rendered.
*/
formatResourceDifference(_type: string, logicalId: string, diff: ResourceDifference): void;
formatResourcePrefix(diff: ResourceDifference): string;
formatPrefix<T>(diff: Difference<T>): string;
/**
* @param value - the value to be formatted.
* @param color - the color to be used.
*
* @returns the formatted string, with color applied.
*/
formatValue(value: any, color: (str: string) => string): string | undefined;
/**
* @param impact - the impact to be formatted
* @returns a user-friendly, colored string representing the impact.
*/
formatImpact(impact: ResourceImpact): string;
private formatMove;
/**
* Renders a tree of differences under a particular name.
* @param name - the name of the root of the tree.
* @param diff - the difference on the tree.
* @param last - whether this is the last node of a parent tree.
*/
formatTreeDiff(name: string, diff: Difference<any>, last: boolean): void;
/**
* Renders the difference between two objects, looking for the differences as deep as possible,
* and rendering a tree graph of the path until the difference is found.
*
* @param oldObject - the old object.
* @param newObject - the new object.
* @param linePrefix - a prefix (indent-like) to be used on every line.
*/
formatObjectDiff(oldObject: any, newObject: any, linePrefix: string): void;
/**
* @param oldValue - the old value of a difference.
* @param newValue - the new value of a difference.
*
* @returns a tag to be rendered in the diff, reflecting whether the difference
* was an ADDITION, UPDATE or REMOVAL.
*/
changeTag(oldValue: any | undefined, newValue: any | undefined): string;
/**
* Find 'aws:cdk:path' metadata in the diff and add it to the logicalToPathMap
*
* There are multiple sources of logicalID -> path mappings: synth metadata
* and resource metadata, and we combine all sources into a single map.
*/
readConstructPathsFrom(templateDiff: TemplateDiff): void;
formatLogicalId(logicalId: string): string;
normalizedLogicalIdPath(logicalId: string): string | undefined;
formatIamChanges(changes: IamChanges): void;
formatSecurityGroupChanges(changes: SecurityGroupChanges): void;
deepSubstituteBracedLogicalIds(rows: string[][]): string[][];
/**
* Substitute all strings like ${LogId.xxx} with the path instead of the logical ID
*/
substituteBracedLogicalIds(source: string): string;
}