Created
April 28, 2022 18:09
-
-
Save justinabrahms/7e16d2e0d8d8c5234d1697ea05cba3fa to your computer and use it in GitHub Desktop.
Information on how to generate a nodejs license scan using SBOMs
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
npm i --production | |
npx -p @cyclonedx/bom cyclonedx-node -o bom.json | |
python ../license-scan.py |
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
#!/usr/bin/env python3 | |
import json | |
from collections import defaultdict | |
f = open('./bom.json') | |
j = ''.join(f.readlines()) | |
data = json.loads(j) | |
licenses = defaultdict(list) | |
for component in data['components']: | |
if 'licenses' not in component: | |
licenses['unknown'].append(component['bom-ref']) | |
continue | |
try: | |
all_licenses = [x['license'].get('id') or x['license'].get('name') for x in component['licenses']] | |
for l in all_licenses: | |
licenses[l].append(component['bom-ref']) | |
except: | |
import pdb; pdb.set_trace() | |
for l, pkgs in licenses.items(): | |
print(f"{l}:{', '.join(pkgs)}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment