Skip to content

Commit

Permalink
SCP-55 Adds extra info into licenses output
Browse files Browse the repository at this point in the history
  • Loading branch information
isasmendiagus authored and francostramana committed Jan 23, 2024
1 parent dc762bf commit c634347
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 23 deletions.
1 change: 1 addition & 0 deletions src/services/result.interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export interface ScannerComponent extends CommonComponent {
osadl_updated: string
source: string
incompatible_with?: string
url: string
}[]
dependencies: {
vendor: string
Expand Down
40 changes: 30 additions & 10 deletions src/services/result.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,47 @@ export async function readResult(filepath: string): Promise<ScannerResults> {
return JSON.parse(content) as ScannerResults
}

export function getLicenses(results: ScannerResults): string[] {
const licenses = new Set<string>()
export interface Licenses {
spdxid: string
copyleft: boolean | null
url: string | null
}

export function getLicenses(results: ScannerResults): Licenses[] {
const licenses = new Array<Licenses>()

for (const component of Object.values(results)) {
for (const c of component) {
if (c.id === ComponentID.FILE || c.id === ComponentID.SNIPPET) {
for (const l of (c as ScannerComponent).licenses) {
licenses.push({
spdxid: l.name,
copyleft: !l.copyleft ? null : l.copyleft === 'yes' ? true : false,
url: l?.url ? l.url : null
})
}
}

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 (!l.spdx_id) continue
licenses.push({ spdxid: l.spdx_id, copyleft: null, url: null })
}
}
}

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)
const seenSpdxIds = new Set<string>()
const uniqueLicenses = licenses.filter(license => {
if (!seenSpdxIds.has(license.spdxid)) {
seenSpdxIds.add(license.spdxid)
return true
}
return false
})

return uniqueLicenses
}
Loading

0 comments on commit c634347

Please sign in to comment.