Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SBOM/SPDX Generation: Add in LicenseRef info for licenses which are not recognized by SPDX (OASIS-IPR) #104

Merged
merged 2 commits into from
Apr 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion sbom-generator/scan_dir.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@
REPO_PATH = ''
SOURCE_PATH = ''

def needs_licenseref(license):
#SPDX license list can be found at https://spdx.org/licenses/
not_in_spdx = ["OASIS-IPR"]
if license in not_in_spdx:
return True
return False

def scan_dir():
dependency_path = os.path.join(REPO_PATH, 'source/dependency')
path_3rdparty = os.path.join(REPO_PATH, 'source/dependency/3rdparty')
Expand All @@ -20,6 +27,7 @@ def scan_dir():
total_file_list = []
dependency_info = {}
dependency_file_list = {}
licenseref_info = ""
with open(manifest_path) as f:
manifest = yaml.load(f, Loader=SafeLoader)
root_license = manifest['license']
Expand Down Expand Up @@ -111,7 +119,17 @@ def scan_dir():
if library_name == root_name:
continue
info = dependency_info[library_name]
package_writer(output, library_name, info['version'], info['repository']['url'], info['license'], package_hash(dependency_file_list[library_name]))

#Is this license part of the SPDX license list? If not, then we need to use LicenseRef for proper SPDX validation
if needs_licenseref(info['license']):
license = "LicenseRef-" + info['license']
licenseref_info += "\nLicenseID: LicenseRef-%s\n" % info['license']
licenseref_info += "LicenseName: %s\n" % info['license']
licenseref_info += "ExtractedText: <text>%s</text>\n" % info['license']
else:
license = info['license']

package_writer(output, library_name, info['version'], info['repository']['url'], license, package_hash(dependency_file_list[library_name]))
output.write(output_buffer[library_name].getvalue())

#print relationships
Expand All @@ -120,6 +138,10 @@ def scan_dir():
continue
output.write('Relationship: SPDXRef-Package-' + manifest['name'] + ' DEPENDS_ON SPDXRef-Package-' + library_name + '\n')

#print any LicenseRef info
if licenseref_info != "":
output.write(licenseref_info)

if __name__ == "__main__":
parser = ArgumentParser(description='SBOM generator')
parser.add_argument('--repo-root-path',
Expand Down
Loading