Skip to content

Instantly share code, notes, and snippets.

@justinabrahms
Created April 28, 2022 18:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save justinabrahms/7e16d2e0d8d8c5234d1697ea05cba3fa to your computer and use it in GitHub Desktop.
Save justinabrahms/7e16d2e0d8d8c5234d1697ea05cba3fa to your computer and use it in GitHub Desktop.
Information on how to generate a nodejs license scan using SBOMs
npm i --production
npx -p @cyclonedx/bom cyclonedx-node -o bom.json
python ../license-scan.py
#!/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