@@ -10,7 +10,6 @@ import (
1010 "net/http"
1111 "os"
1212 "os/exec"
13- "path"
1413 "path/filepath"
1514 "strings"
1615 "unicode"
@@ -71,12 +70,12 @@ Examples:
7170 if versionFlag == nil || * versionFlag == "" {
7271 return cmderrors .Usage ("version is required" )
7372 }
74- c .version = * versionFlag
73+ c .version = sanitizeVersion ( * versionFlag )
7574
7675 if outputDirFlag == nil || * outputDirFlag == "" {
7776 return cmderrors .Usage ("output directory is required" )
7877 }
79- c .outputDir = getOutputDir (* outputDirFlag , * versionFlag )
78+ c .outputDir = getOutputDir (* outputDirFlag , c . version )
8079
8180 if internalReleaseFlag == nil || ! * internalReleaseFlag {
8281 c .internalRelease = false
@@ -283,7 +282,19 @@ func extractSBOM(attestationBytes []byte) (string, error) {
283282 return "" , fmt .Errorf ("failed to decode payload: %w" , err )
284283 }
285284
286- return string (decodedPayload ), nil
285+ // Unmarshal the decoded payload to extract predicate
286+ var payload map [string ]json.RawMessage
287+ if err := json .Unmarshal (decodedPayload , & payload ); err != nil {
288+ return "" , fmt .Errorf ("failed to unmarshal decoded payload: %w" , err )
289+ }
290+
291+ // Extract just the predicate field
292+ predicate , ok := payload ["predicate" ]
293+ if ! ok {
294+ return "" , fmt .Errorf ("no predicate field found in payload" )
295+ }
296+
297+ return string (predicate ), nil
287298}
288299
289300func (c sbomConfig ) storeSBOM (sbom string , image string ) error {
@@ -296,7 +307,7 @@ func (c sbomConfig) storeSBOM(sbom string, image string) error {
296307 }, image )
297308
298309 // Create the output file path
299- outputFile := filepath .Join (c .outputDir , safeImageName + ".json" )
310+ outputFile := filepath .Join (c .outputDir , safeImageName + ".cdx. json" )
300311
301312 // Ensure the output directory exists
302313 if err := os .MkdirAll (c .outputDir , 0755 ); err != nil {
@@ -311,10 +322,6 @@ func (c sbomConfig) storeSBOM(sbom string, image string) error {
311322 return nil
312323}
313324
314- func getOutputDir (parentDir , version string ) string {
315- return path .Join (parentDir , "sourcegraph-" + version )
316- }
317-
318325// getImageReleaseListURL returns the URL for the list of images in a release, based on the version and whether it's an internal release.
319326func (c * sbomConfig ) getImageReleaseListURL () string {
320327 if c .internalRelease {
0 commit comments