-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SCP-48 Extract licenses from results
- Loading branch information
1 parent
73dbc23
commit dc762bf
Showing
9 changed files
with
297 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
{ | ||
"printWidth": 80, | ||
"printWidth": 120, | ||
"tabWidth": 2, | ||
"useTabs": false, | ||
"semi": false, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
export type ScannerResults = Record<string, ScannerComponent[] | DependencyComponent[]> | ||
|
||
export enum ComponentID { | ||
Check failure on line 3 in src/services/result.interfaces.ts GitHub Actions / TypeScript Tests
|
||
NONE = 'none', | ||
FILE = 'file', | ||
SNIPPET = 'snippet', | ||
DEPENDENCY = 'dependency' | ||
} | ||
|
||
interface CommonComponent { | ||
id: ComponentID | ||
status: string | ||
} | ||
|
||
export interface DependencyComponent extends CommonComponent { | ||
dependencies: { | ||
licenses: { | ||
is_spdx_approved: boolean | ||
name: string | ||
spdx_id: string | ||
}[] | ||
purl: string | ||
url: string | ||
version: string | ||
}[] | ||
} | ||
|
||
export interface ScannerComponent extends CommonComponent { | ||
lines: string | ||
oss_lines: string | ||
matched: string | ||
purl: string[] | ||
vendor: string | ||
component: string | ||
version: string | ||
latest: string | ||
url: string | ||
release_date: string | ||
file: string | ||
url_hash: string | ||
file_hash: string | ||
source_hash: string | ||
file_url: string | ||
licenses: { | ||
name: string | ||
patent_hints: string | ||
copyleft: string | ||
checklist_url: string | ||
osadl_updated: string | ||
source: string | ||
incompatible_with?: string | ||
}[] | ||
dependencies: { | ||
vendor: string | ||
component: string | ||
version: string | ||
source: string | ||
}[] | ||
copyrights: { | ||
name: string | ||
source: string | ||
}[] | ||
vulnerabilities: { | ||
ID: string | ||
CVE: string | ||
severity: string | ||
reported: string | ||
introduced: string | ||
patched: string | ||
summary: string | ||
source: string | ||
}[] | ||
quality: { | ||
score: string | ||
source: string | ||
}[] | ||
cryptography: any[] | ||
Check failure on line 77 in src/services/result.interfaces.ts GitHub Actions / TypeScript Tests
|
||
health: { | ||
creation_date: string | ||
issues: number | ||
last_push: string | ||
last_update: string | ||
watchers: number | ||
country: string | ||
stars: number | ||
forks: number | ||
} | ||
server: { | ||
version: string | ||
kb_version: { monthly: string; daily: string } | ||
hostname: string | ||
flags: string | ||
elapsed: string | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { ComponentID, DependencyComponent, ScannerComponent, ScannerResults } from './result.interfaces' | ||
import * as fs from 'fs' | ||
|
||
export async function readResult(filepath: string): Promise<ScannerResults> { | ||
const content = await fs.promises.readFile(filepath, 'utf-8') | ||
return JSON.parse(content) as ScannerResults | ||
} | ||
|
||
export function getLicenses(results: ScannerResults): string[] { | ||
const licenses = new Set<string>() | ||
|
||
for (const component of Object.values(results)) { | ||
for (const c of component) { | ||
if (c.id === ComponentID.DEPENDENCY) { | ||
const dependencies = (c as DependencyComponent).dependencies | ||
for (const d of dependencies) { | ||
for (const l of d.licenses) { | ||
licenses.add(l.spdx_id) | ||
} | ||
} | ||
} | ||
|
||
if (c.id === ComponentID.FILE || c.id === ComponentID.SNIPPET) { | ||
for (const l of (c as ScannerComponent).licenses) { | ||
licenses.add(l.name) | ||
} | ||
} | ||
} | ||
} | ||
|
||
return Array.from(licenses) | ||
} |
Oops, something went wrong.