Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 1 addition & 55 deletions packages/@aws-cdk/service-spec-importers/src/diff-fmt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import {
UpdatedResource,
UpdatedService,
UpdatedTypeDefinition,
VendedLog,
Event,
EventTypeDefinition,
EventProperty,
Expand Down Expand Up @@ -157,7 +156,7 @@ export class DiffFormatter {
new PrintableTree(...listFromDiffs(d)).indent(META_INDENT),
listWithCaption('properties', this.renderPropertyDiff(r.properties)),
listWithCaption('attributes', this.renderPropertyDiff(r.attributes)),
listWithCaption('vendedLogs', this.renderVendedLogsDiff(r.vendedLogs)),
listWithCaption('vendedLogs', this.renderVendedLogsArrayDiff(r.vendedLogs)),
listWithCaption('vendedLogsConfig', this.renderVendedLogsArrayDiff(r.vendedLogsConfig)),
listWithCaption(
'types',
Expand Down Expand Up @@ -423,59 +422,6 @@ export class DiffFormatter {
return changes;
}

private renderVendedLogsDiff(diff: ScalarDiff<VendedLog | undefined> | undefined): PrintableTree[] {
if (!diff || (!diff.old && !diff.new)) {
return [];
}
const tree: PrintableTree[] = [];

if (!diff.old && diff.new) {
return [this.renderVendedLogsType(diff.new).prefix([chalk.green(ADDITION), ' '], [' '])];
}
if (diff.old && !diff.new) {
return [this.renderVendedLogsType(diff.old).prefix([chalk.red(REMOVAL), ' '], [' '])];
}

if (diff.old && diff.new) {
if (diff.old.permissionsVersion !== diff.new.permissionsVersion) {
tree.push(
new PrintableTree(`permissionsVersion:`).addBullets([
new PrintableTree(`- ${diff.old.permissionsVersion}`).colorize(chalk.red),
new PrintableTree(`+ ${diff.new.permissionsVersion}`).colorize(chalk.green),
]),
);
}

this.renderVendedLogListDiff(diff, tree, 'logTypes');
this.renderVendedLogListDiff(diff, tree, 'destinations');
}
return tree;
}

private renderVendedLogsType(vendedLogs: VendedLog): PrintableTree {
return new PrintableTree(`vendedLogs`).addBullets([
new PrintableTree(`permissionsVersion: ${vendedLogs.permissionsVersion}`),
new PrintableTree(`logTypes: [${vendedLogs.logTypes.join(', ')}]`),
new PrintableTree(`destinations: [${vendedLogs.destinations.join(', ')}]`),
]);
}

private renderVendedLogListDiff(diff: ScalarDiff<VendedLog | undefined>, tree: PrintableTree[], diffShown: string) {
if (diff.old && diff.new) {
// the array should correspond to the value of diffShown
const oldList = new Set(diffShown === 'logTypes' ? diff.new.logTypes : diff.new.destinations);
const newList = new Set(diffShown === 'logTypes' ? diff.new.logTypes : diff.new.destinations);
const added = [...newList].filter((t) => !oldList.has(t));
const removed = [...oldList].filter((t) => !newList.has(t));
if (added.length > 0 || removed.length > 0) {
const bullets: PrintableTree[] = [];
removed.forEach((obj) => bullets.push(new PrintableTree(`- ${obj}`).colorize(chalk.red)));
added.forEach((obj) => bullets.push(new PrintableTree(`+ ${obj}`).colorize(chalk.green)));
tree.push(new PrintableTree(`${diffShown}:`).addBullets(bullets));
}
}
}

private renderEvent(e: Event, db: number): PrintableTree {
const propsTree = new PrintableTree(
`description: ${render(e.description)}`,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { DeliveryDestination, DestinationService, SpecDatabase } from '@aws-cdk/service-spec-types';
import { DeliveryDestination, SpecDatabase } from '@aws-cdk/service-spec-types';
import { failure } from '@cdklabs/tskb';
import { ProblemReport, ReportAudience } from '../report';

Expand Down Expand Up @@ -29,21 +29,6 @@ export function importLogSources(
);
}

const oldDestinations = value.Destinations.map((dest) => dest.DestinationType as DestinationService);

resource.vendedLogs ??= {
// we take whatever the newest permissions value is and assume that all logs in a resource use the same permissions
permissionsVersion: permissionValue,
logTypes: [],
destinations: [],
};

resource.vendedLogs.logTypes.push(value.LogType);
// dedupes incoming destinations
const newDestinations = oldDestinations.filter((dest) => !resource.vendedLogs!.destinations.includes(dest));

resource.vendedLogs.destinations.push(...newDestinations);

const destinations: DeliveryDestination[] = value.Destinations.map((dest) => ({
destinationType: dest.DestinationType,
}));
Expand All @@ -54,6 +39,8 @@ export function importLogSources(
destinations: destinations,
};

resource.vendedLogs ??= [];
resource.vendedLogs.push(newLog);
resource.vendedLogsConfig ??= [];
resource.vendedLogsConfig.push(newLog);
} catch (err) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ test('adds log type to resource', () => {
);

const res = db.lookup('resource', 'cloudFormationType', 'equals', 'AWS::Some::Type')[0];
expect(res.vendedLogsConfig).toEqual([
expect(res.vendedLogs).toEqual([
{
permissionsVersion: 'V2',
logType: 'SOME_LOGS',
Expand Down Expand Up @@ -107,7 +107,7 @@ test('adds multiple log types to resource and does not add duplicate destination
);

const res = db.lookup('resource', 'cloudFormationType', 'equals', 'AWS::Some::Type')[0];
expect(res.vendedLogsConfig).toEqual([
expect(res.vendedLogs).toEqual([
{
permissionsVersion: 'V2',
logType: 'APPLICATION_LOGS',
Expand Down Expand Up @@ -148,7 +148,7 @@ test('adds log types to multiple resources', () => {
);

const someRes = db.lookup('resource', 'cloudFormationType', 'equals', 'AWS::Some::Type')[0];
expect(someRes.vendedLogsConfig).toEqual([
expect(someRes.vendedLogs).toEqual([
{
permissionsVersion: 'V2',
logType: 'APPLICATION_LOGS',
Expand All @@ -161,7 +161,7 @@ test('adds log types to multiple resources', () => {
]);

const otherRes = db.lookup('resource', 'cloudFormationType', 'equals', 'AWS::Other::Type')[0];
expect(otherRes.vendedLogsConfig).toEqual([
expect(otherRes.vendedLogs).toEqual([
{
permissionsVersion: 'V2',
logType: 'APPLICATION_LOGS',
Expand Down
22 changes: 1 addition & 21 deletions packages/@aws-cdk/service-spec-types/src/types/resource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export interface Resource extends Entity {
readonly validations?: unknown;
arnTemplate?: string;
isStateful?: boolean;
vendedLogs?: VendedLog;
vendedLogs?: VendedLogs[];
vendedLogsConfig?: VendedLogs[];

/**
Expand Down Expand Up @@ -422,26 +422,6 @@ export interface RelationshipRef {
readonly propertyName: string;
}

export type DestinationService = 'S3' | 'CWL' | 'FH' | 'XRAY';

/**
* Represents the types of logs a Cloudformation Resource can produce and what destinations can consume them
*/
export interface VendedLog {
/**
* What version of permissions the destination supports V1 | V2
*/
readonly permissionsVersion: string;
/**
* List of the types of logs a Cloudformation resource can produce
*/
readonly logTypes: string[];
/**
* List of the destinations the can consume those logs
*/
readonly destinations: DestinationService[];
}

/**
* Represents a delivery destination that a Cloudformation resource can send logs to
*/
Expand Down
Loading