-
Notifications
You must be signed in to change notification settings - Fork 2
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 4107f21
Showing
9 changed files
with
303 additions
and
36 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,98 @@ | ||
export type ScannerResults = Record< | ||
string, | ||
ScannerComponent[] | DependencyComponent[] | ||
> | ||
|
||
export enum ComponentID { | ||
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[] | ||
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,31 @@ | ||
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) { | ||
const licenses = new Set<string>() | ||
|
||
for (const [path, component] of Object.entries(results)) { | ||
component.forEach(c => { | ||
if (c.id === ComponentID.DEPENDENCY) { | ||
;(c as DependencyComponent).dependencies.forEach(d => { | ||
d.licenses.forEach(l => { | ||
licenses.add(l.spdx_id) | ||
}) | ||
}) | ||
} | ||
|
||
if (c.id === ComponentID.FILE || c.id === ComponentID.SNIPPET) { | ||
;(c as ScannerComponent).licenses.forEach(l => { | ||
licenses.add(l.name) | ||
}) | ||
} | ||
}) | ||
} | ||
|
||
return Array.from(licenses) | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.