Skip to content

Commit

Permalink
Change file name to file path in SBOM (#48)
Browse files Browse the repository at this point in the history
* Update sbom_utils.py

* Update scan_dir.py

* Update sbom_utils.py
  • Loading branch information
xlin7799 authored Aug 10, 2022
1 parent 89bf6cc commit d675859
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
8 changes: 4 additions & 4 deletions sbom-generator/sbom_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ def package_hash(file_list: str) -> str:
h = hashlib.sha1("".join(file_list).encode())
return h.hexdigest()

def file_writer(output, filepath: str, filename: str, sha1: str, license: str, copyright='NOASSERTION', comment='NOASSERTION'):
output.write('FileName: '+ filename + '\n')
output.write('SPDXID: SPDXRef-File-'+ filename.replace('/', '-') + '\n')
output.write('FileChecksum: SHA1: '+ hash_sha1(filepath) + '\n')
def file_writer(output, filepath: str, sha1: str, license: str, copyright='NOASSERTION', comment='NOASSERTION'):
output.write('FileName: .'+ filepath + '\n')
output.write('SPDXID: SPDXRef-File'+ filepath.replace('/', '-') + '\n')
output.write('FileChecksum: SHA1: '+ sha1 + '\n')
output.write('LicenseConcluded: '+ license + '\n')
output.write('FileCopyrightText: '+ copyright + '\n')
output.write('FileComment: '+ comment + '\n')
Expand Down
6 changes: 3 additions & 3 deletions sbom-generator/scan_dir.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def scan_dir():
file_checksum = hash_sha1(filepath)
total_file_list.append(file_checksum)
if file.endswith('.c'):
file_writer(output_buffer[root_name], filepath, file, file_checksum, root_license)
file_writer(output_buffer[root_name], filepath.replace(SOURCE_PATH, ''), file_checksum, root_license)

#scan dependencies
if os.path.exists(dependency_path):
Expand All @@ -69,7 +69,7 @@ def scan_dir():
filepath = os.path.join(subdir, file)
file_checksum = hash_sha1(filepath)
if file.endswith('.c'):
file_writer(buffer, filepath, file, file_checksum, library_lic)
file_writer(buffer, filepath.replace(SOURCE_PATH, ''), file_checksum, library_lic)
total_file_list.append(file_checksum)
temp_list.append(file_checksum)

Expand All @@ -96,7 +96,7 @@ def scan_dir():
filepath = os.path.join(subdir, file)
file_checksum = hash_sha1(filepath)
if file.endswith('.c'):
file_writer(buffer, filepath, file, file_checksum, library_lic)
file_writer(buffer, filepath.replace(SOURCE_PATH, ''), file_checksum, library_lic)
total_file_list.append(file_checksum)
temp_list.append(file_checksum)

Expand Down

0 comments on commit d675859

Please sign in to comment.