Skip to content

Commit

Permalink
feat: store more BOM artifacts
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisdlangton committed Oct 2, 2024
1 parent 11d9253 commit f002826
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 6 deletions.
18 changes: 16 additions & 2 deletions functions/cdx/upload.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AuthResult, ensureStrReqBody, hex, isCDX, OSV, Server } from "@/utils";
import { AuthResult, ensureStrReqBody, hex, isCDX, OSV, saveArtifact, Server } from "@/utils";
import { PrismaD1 } from '@prisma/adapter-d1';
import { PrismaClient } from '@prisma/client';

Expand Down Expand Up @@ -34,11 +34,25 @@ export async function onRequestPost(context) {
if (!isCDX(cdx)) {
return Response.json({ ok: false, error: { message: 'CDX is missing necessary fields.' } })
}
// const cdxStr = JSON.stringify(cdx) //TODO: Add to TEA
const componentsJSON = JSON.stringify(cdx.components)
const cdxId = await hex(cdx.metadata?.component?.name + componentsJSON)

const originalCdx = await prisma.CycloneDXInfo.findFirst({
where: {
cdxId,
orgId: verificationResult.session.orgId,
}
})
let artifact;
const artifactUuid = originalCdx?.artifactUuid || cdx.serialNumber.startsWith('urn:uuid:') ? cdx.serialNumber.substring(9) : crypto.randomUUID()
if (!originalCdx) {
const cdxStr = JSON.stringify(cdx)
artifact = await saveArtifact(prisma, env.r2artifacts, cdxStr, artifactUuid, `cyclonedx`)
}

const cdxData = {
cdxId,
artifactUuid,
source: 'upload',
orgId: verificationResult.session.orgId,
memberEmail: verificationResult.session.memberEmail,
Expand Down
23 changes: 20 additions & 3 deletions functions/spdx/upload.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AuthResult, OSV, Server, ensureStrReqBody, hex, isSPDX } from "@/utils";
import { AuthResult, OSV, Server, ensureStrReqBody, hex, isSPDX, saveArtifact } from "@/utils";
import { PrismaD1 } from '@prisma/adapter-d1';
import { PrismaClient } from '@prisma/client';

Expand Down Expand Up @@ -33,10 +33,22 @@ export async function onRequestPost(context) {
if (!isSPDX(spdx)) {
return Response.json({ ok: false, error: { message: 'SPDX is missing necessary fields.' } })
}
const spdxStr = JSON.stringify(spdx)
const spdxId = await hex(spdxStr)
const spdxId = await makeId(spdx)
const originalSpdx = await prisma.SPDXInfo.findFirst({
where: {
spdxId,
orgId: verificationResult.session.orgId,
}
})
let artifact;
if (!originalSpdx) {
const spdxStr = JSON.stringify(spdx)
artifact = await saveArtifact(prisma, env.r2artifacts, spdxStr, crypto.randomUUID(), `spdx`)
}
const artifactUuid = originalSpdx?.artifactUuid || artifact?.uuid
const spdxData = {
spdxId,
artifactUuid,
source: 'upload',
orgId: verificationResult.session.orgId,
memberEmail: verificationResult.session.memberEmail,
Expand Down Expand Up @@ -168,3 +180,8 @@ export async function onRequestPost(context) {

return Response.json({ ok: true, files, error: { message: errors } })
}

const makeId = async spdx => {
const packages = JSON.stringify(spdx.packages)
return hex(spdx.name + packages)
}
2 changes: 1 addition & 1 deletion src/pages/CycloneDXManager.vue
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class Controller {
}
break
}
if (data.spdx.length < pageSize) {
if (data.cdx.length < pageSize) {
hasMore = false
if (initial !== true) {
state.info = "Refreshed CycloneDX"
Expand Down

0 comments on commit f002826

Please sign in to comment.