-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Generate a summary spdx manifest when multiple manifests are loaded
- Loading branch information
1 parent
abd1a2a
commit a1a5cfb
Showing
3 changed files
with
101 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import path from 'path'; | ||
import { getCreatorOrganization } from '../models/spdx/2.3/ICreationInfo'; | ||
import { DocumentVersion, IDocument } from '../models/spdx/2.3/IDocument'; | ||
|
||
/** | ||
* Merge multiple SPDX documents to a single SPDX document | ||
* @param packageName The name of the merged ackage | ||
* @param packageVersion The version of the merged package | ||
* @param sourceDocuments The source SPDX documents to be merged | ||
* @return The merged SPDX document | ||
*/ | ||
export function mergeSpdxDocuments( | ||
packageName: string | undefined, | ||
packageVersion: string | undefined, | ||
sourceDocuments: IDocument[], | ||
): IDocument { | ||
const packageGuid = crypto.randomUUID(); | ||
const rootDocument = sourceDocuments[0]; | ||
const rootNamespaceUri = new URL(rootDocument.documentNamespace); | ||
const rootOrganisation = getCreatorOrganization(rootDocument.creationInfo); | ||
return { | ||
SPDXID: 'SPDXRef-DOCUMENT', | ||
spdxVersion: DocumentVersion.SPDX_2_3, | ||
name: `${packageName} ${packageVersion}`.trim(), | ||
dataLicense: rootDocument.dataLicense || 'CC0-1.0', | ||
documentNamespace: `${rootNamespaceUri.protocol}//${rootNamespaceUri.host}/${packageName}/${packageVersion}/${packageGuid}`, | ||
creationInfo: { | ||
created: new Date().toISOString(), | ||
creators: [`Organization: ${rootOrganisation}`, `Tool: rhyskoedijk/sbom-azure-devops-1.0`], | ||
}, | ||
files: sourceDocuments.flatMap((d) => | ||
d.files.map((f) => ({ | ||
...f, | ||
fileName: path.join(d.packages.find((p) => p.SPDXID == d.documentDescribes[0])?.name || '', f.fileName), | ||
})), | ||
), | ||
packages: sourceDocuments.flatMap((d) => d.packages), | ||
externalDocumentRefs: sourceDocuments.flatMap((d) => d.externalDocumentRefs), | ||
relationships: sourceDocuments.flatMap((d) => d.relationships), | ||
documentDescribes: sourceDocuments.flatMap((d) => d.documentDescribes), | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters