Skip to content

Commit

Permalink
feat: add possibility to convert OWASP to opossum
Browse files Browse the repository at this point in the history
Signed-off-by: Dominikus Hellgartner <[email protected]>
  • Loading branch information
Hellgartner committed Feb 14, 2025
1 parent 4d37ac2 commit 8ace0fb
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 2 deletions.
8 changes: 7 additions & 1 deletion src/ElectronBackend/main/listeners.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ import {
} from '../errorHandling/errorHandling';
import { loadInputAndOutputFromFilePath } from '../input/importFromFile';
import { serializeAttributions } from '../input/parseInputData';
import { convertScancodeToOpossum } from '../opossum-file/convertScancodeToOpossum';
import {
convertOwaspToOpossum,
convertScancodeToOpossum,
} from '../opossum-file/convertToOpossum';
import { writeCsvToFile } from '../output/writeCsvToFile';
import { writeSpdxFile } from '../output/writeSpdxFile';
import { GlobalBackendState, OpossumOutputFile } from '../types/types';
Expand Down Expand Up @@ -227,6 +230,9 @@ export function getImportFileConvertAndLoadListener(
case FileType.SCANCODE_JSON:
await convertScancodeToOpossum(resourceFilePath, opossumFilePath);
break;
case FileType.OWASP_JSON:
await convertOwaspToOpossum(resourceFilePath, opossumFilePath);
break;
}

logger.info('Updating global backend state');
Expand Down
5 changes: 5 additions & 0 deletions src/ElectronBackend/main/menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,11 @@ export const importFileFormats: Array<FileFormatInfo> = [
name: 'ScanCode File',
extensions: ['json'],
},
{
fileType: FileType.OWASP_JSON,
name: 'OWASP Dependency-Check',
extensions: ['json'],
},
];

export async function createMenu(mainWindow: BrowserWindow): Promise<Menu> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { join } from 'path';

import { parseOpossumFile } from '../../input/parseFile';
import { isOpossumFileFormat } from '../../utils/isOpossumFileFormat';
import { convertScancodeToOpossum } from '../convertScancodeToOpossum';
import { convertScancodeToOpossum } from '../convertToOpossum';

describe('successfulConversionOfScanCodeFile', () => {
const SCANCODE_TEST_FILE = join(__dirname, 'scancode.json');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,22 @@ export async function convertScancodeToOpossum(
throw new Error('Conversion of ScanCode file to .opossum file failed');
}
}

export async function convertOwaspToOpossum(
pathToOwasp: string,
pathToOpossum: string,
): Promise<void> {
try {
await execFile(OPOSSUM_FILE_EXECUTABLE, [
'generate',
'-o',
pathToOpossum,
'--scan-code-json',
pathToOwasp,
]);
} catch (error) {
throw new Error(
'Conversion of OWASP Dependency-check file to .opossum file failed',
);
}
}
1 change: 1 addition & 0 deletions src/shared/shared-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ export interface ExternalAttributionSources {
export enum FileType {
LEGACY_OPOSSUM,
SCANCODE_JSON,
OWASP_JSON,
}

export interface FileFormatInfo {
Expand Down

0 comments on commit 8ace0fb

Please sign in to comment.