link_sbom.py 1.3 KB

1234567891011121314151617181920212223242526272829303132333435
  1. import argparse
  2. import json
  3. import os
  4. def main():
  5. parser = argparse.ArgumentParser(description='Generate SBOM data from used contribs info')
  6. parser.add_argument('-o', '--output', type=argparse.FileType('w', encoding='UTF-8'), help='resulting SBOM file', required=True)
  7. parser.add_argument('--vcs-info', type=argparse.FileType('r', encoding='UTF-8'), help='VCS information file', required=True)
  8. parser.add_argument('--mod-path', type=str, help='Path to module in arcadia', required=True)
  9. parser.add_argument('components', metavar='N', type=argparse.FileType('r', encoding='UTF-8'), nargs='*', help='dependencies info in SBOM component JSON format')
  10. args = parser.parse_args()
  11. vcs = json.load(args.vcs_info)
  12. res = {}
  13. res['$schema'] = "http://cyclonedx.org/schema/bom-1.5.schema.json"
  14. res["bomFormat"] = "CycloneDX"
  15. res["specVersion"] = "1.5"
  16. res["version"] = 1
  17. res["components"] = [json.load(dep) for dep in args.components]
  18. res["properties"] = [
  19. {'name': 'commit_hash', 'value': vcs['ARCADIA_SOURCE_HG_HASH']},
  20. {'name': 'arcadia_module_subdir', 'value': args.mod_path}
  21. ]
  22. if vcs.get('DIRTY', '') == 'dirty':
  23. res["properties"].append({'name': 'has_uncommitted_changes', 'value': True})
  24. json.dump(res, args.output)
  25. args.output.close()
  26. if __name__ == '__main__':
  27. main()