From a9a40071fab64c8e29ca6e8ef2fced70502a2e81 Mon Sep 17 00:00:00 2001 From: Charles Hu Date: Fri, 9 Aug 2024 13:15:18 -0400 Subject: [PATCH] Review changes Signed-off-by: Charles Hu --- .../src/cyclonedx-sbom-mapper.ts | 67 ++++++------------- 1 file changed, 21 insertions(+), 46 deletions(-) diff --git a/libs/hdf-converters/src/cyclonedx-sbom-mapper.ts b/libs/hdf-converters/src/cyclonedx-sbom-mapper.ts index 9327baa5df..d2faced269 100644 --- a/libs/hdf-converters/src/cyclonedx-sbom-mapper.ts +++ b/libs/hdf-converters/src/cyclonedx-sbom-mapper.ts @@ -109,7 +109,7 @@ export class CycloneDXSBOMResults { // Pull components from raw data data.components = [ ...(_.cloneDeep(data.raw.components) as ComponentRepository) - ].map((element) => Object(element)); + ] as unknown as IntermediaryComponent[]; // Look through every component at the top level of the list for (const component of data.components) { @@ -155,7 +155,7 @@ export class CycloneDXSBOMResults { // Pull vulnerabilities from raw data data.vulnerabilities = [ ...(_.cloneDeep(data.raw.vulnerabilities) as VulnerabilityRepository) - ].map((element) => Object(element)); + ] as unknown as IntermediaryVulnerability[]; for (const vulnerability of data.vulnerabilities) { vulnerability.affectedComponents = []; @@ -203,18 +203,15 @@ export class CycloneDXSBOMResults { // Pull vulnerabilities from raw data data.vulnerabilities = [ ...(_.cloneDeep(data.raw.vulnerabilities) as VulnerabilityRepository) - ].map((element) => Object(element)); + ] as unknown as IntermediaryVulnerability[]; for (const vulnerability of data.vulnerabilities) { - vulnerability.affectedComponents = []; - for (const id of vulnerability.affects) { - // Build a dummy component for each bom-ref identified as being affected by the vulnerability - // Add that component to the corresponding vulnerability object - vulnerability.affectedComponents.push({ - 'bom-ref': `${id.ref}`, - name: `${id.ref}` - }); - } + // Build a dummy component for each bom-ref identified as being affected by the vulnerability + // Add that component to the corresponding vulnerability object + vulnerability.affectedComponents = vulnerability.affects.map((id) => ({ + 'bom-ref': `${id.ref}`, + name: `${id.ref}` + })); } } @@ -331,30 +328,22 @@ export class CycloneDXSBOMMapper extends BaseConverter { descriptions: [ { path: 'detail', - transformer: ( - input: Record - ): Record | undefined => + transformer: (input: Record) => input ? {data: input, label: 'Detail'} : undefined } as unknown as ExecJSON.ControlDescription, { path: 'recommendation', - transformer: ( - input: Record - ): Record | undefined => + transformer: (input: string) => input ? {data: input, label: 'Recommendation'} : undefined } as unknown as ExecJSON.ControlDescription, { path: 'workaround', - transformer: ( - input: Record - ): Record | undefined => + transformer: (input: string) => input ? {data: input, label: 'Workaround'} : undefined } as unknown as ExecJSON.ControlDescription, { path: 'proofOfConcept', - transformer: ( - input: Record - ): Record | undefined => + transformer: (input: Record) => input ? { data: JSON.stringify(input, null, 2), @@ -364,55 +353,41 @@ export class CycloneDXSBOMMapper extends BaseConverter { } as unknown as ExecJSON.ControlDescription, { path: 'created', - transformer: ( - input: Record - ): Record | undefined => + transformer: (input: Record) => input ? {data: input, label: 'Date created'} : undefined } as unknown as ExecJSON.ControlDescription, { path: 'published', - transformer: ( - input: Record - ): Record | undefined => + transformer: (input: Record) => input ? {data: input, label: 'Date published'} : undefined } as unknown as ExecJSON.ControlDescription, { path: 'updated', - transformer: ( - input: Record - ): Record | undefined => + transformer: (input: Record) => input ? {data: input, label: 'Date updated'} : undefined } as unknown as ExecJSON.ControlDescription, { path: 'rejected', - transformer: ( - input: Record - ): Record | undefined => + transformer: (input: Record) => input ? {data: input, label: 'Date rejected'} : undefined } as unknown as ExecJSON.ControlDescription, { path: 'credits', - transformer: ( - input: Record - ): Record | undefined => + transformer: (input: Record) => input ? {data: JSON.stringify(input, null, 2), label: 'Credits'} : undefined } as unknown as ExecJSON.ControlDescription, { path: 'tools', - transformer: ( - input: Record - ): Record | undefined => + transformer: (input: Record) => input ? {data: JSON.stringify(input, null, 2), label: 'Tools'} : undefined } as unknown as ExecJSON.ControlDescription, { path: 'analysis', - transformer: ( - input: Record - ): Record | undefined => + transformer: (input: Record) => input ? {data: JSON.stringify(input, null, 2), label: 'Analysis'} : undefined @@ -516,7 +491,7 @@ export class CycloneDXSBOMMapper extends BaseConverter { } } }; - constructor(exportJson: Record, withRaw = false) { + constructor(exportJson: DataStorage, withRaw = false) { super(exportJson, true); this.withRaw = withRaw; }