gen_sbom.py 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. import argparse
  2. import json
  3. import os
  4. def deduce_name(path):
  5. name = os.path.basename(path)
  6. for prefix in ['contrib/libs/', 'contrib/python/py2/', 'contrib/python/py3/', 'contrib/python/']:
  7. if path.startswith(prefix):
  8. name = path[len(prefix):].replace('/', '-')
  9. break
  10. return name
  11. def main():
  12. parser = argparse.ArgumentParser(description='Generate single SBOM component JSON object for current third-party library')
  13. parser.add_argument('-o', '--output', type=argparse.FileType('w', encoding='UTF-8'), help='resulting SBOM component file', required=True)
  14. parser.add_argument('--path', type=str, help='Path to module in arcadia', required=True)
  15. parser.add_argument('--ver', type=str, help='Version of the contrib module', required=True)
  16. parser.add_argument('--lang', type=str, help='Language of the library', required=True)
  17. args = parser.parse_args()
  18. res = {}
  19. res['type'] = 'library'
  20. res['name'] = deduce_name(args.path)
  21. res['version'] = args.ver
  22. res["properties"] = [
  23. {'name': 'arcadia_module_subdir', 'value': args.path},
  24. {'name': 'language', 'value': args.lang}
  25. ]
  26. json.dump(res, args.output)
  27. args.output.close()
  28. if __name__ == '__main__':
  29. main()