diff --git a/packages/@aws-cdk/service-spec-importers/src/diff-fmt.ts b/packages/@aws-cdk/service-spec-importers/src/diff-fmt.ts index 55302de00..182b7adae 100644 --- a/packages/@aws-cdk/service-spec-importers/src/diff-fmt.ts +++ b/packages/@aws-cdk/service-spec-importers/src/diff-fmt.ts @@ -16,7 +16,6 @@ import { UpdatedResource, UpdatedService, UpdatedTypeDefinition, - VendedLog, Event, EventTypeDefinition, EventProperty, @@ -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', @@ -423,59 +422,6 @@ export class DiffFormatter { return changes; } - private renderVendedLogsDiff(diff: ScalarDiff | 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, 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)}`, diff --git a/packages/@aws-cdk/service-spec-importers/src/importers/import-log-source.ts b/packages/@aws-cdk/service-spec-importers/src/importers/import-log-source.ts index d4244cd0c..07f4e0eb8 100644 --- a/packages/@aws-cdk/service-spec-importers/src/importers/import-log-source.ts +++ b/packages/@aws-cdk/service-spec-importers/src/importers/import-log-source.ts @@ -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'; @@ -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, })); @@ -54,6 +39,8 @@ export function importLogSources( destinations: destinations, }; + resource.vendedLogs ??= []; + resource.vendedLogs.push(newLog); resource.vendedLogsConfig ??= []; resource.vendedLogsConfig.push(newLog); } catch (err) { diff --git a/packages/@aws-cdk/service-spec-importers/test/log-sources.test.ts b/packages/@aws-cdk/service-spec-importers/test/log-sources.test.ts index 263361346..8e7caa84d 100644 --- a/packages/@aws-cdk/service-spec-importers/test/log-sources.test.ts +++ b/packages/@aws-cdk/service-spec-importers/test/log-sources.test.ts @@ -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', @@ -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', @@ -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', @@ -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', diff --git a/packages/@aws-cdk/service-spec-types/src/types/resource.ts b/packages/@aws-cdk/service-spec-types/src/types/resource.ts index cd6ce7a83..405cd0ce2 100644 --- a/packages/@aws-cdk/service-spec-types/src/types/resource.ts +++ b/packages/@aws-cdk/service-spec-types/src/types/resource.ts @@ -67,7 +67,7 @@ export interface Resource extends Entity { readonly validations?: unknown; arnTemplate?: string; isStateful?: boolean; - vendedLogs?: VendedLog; + vendedLogs?: VendedLogs[]; vendedLogsConfig?: VendedLogs[]; /** @@ -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 */