@@ -10,7 +10,6 @@ import (
10
10
"net/http"
11
11
"os"
12
12
"os/exec"
13
- "path"
14
13
"path/filepath"
15
14
"strings"
16
15
"unicode"
@@ -71,12 +70,12 @@ Examples:
71
70
if versionFlag == nil || * versionFlag == "" {
72
71
return cmderrors .Usage ("version is required" )
73
72
}
74
- c .version = * versionFlag
73
+ c .version = sanitizeVersion ( * versionFlag )
75
74
76
75
if outputDirFlag == nil || * outputDirFlag == "" {
77
76
return cmderrors .Usage ("output directory is required" )
78
77
}
79
- c .outputDir = getOutputDir (* outputDirFlag , * versionFlag )
78
+ c .outputDir = getOutputDir (* outputDirFlag , c . version )
80
79
81
80
if internalReleaseFlag == nil || ! * internalReleaseFlag {
82
81
c .internalRelease = false
@@ -283,7 +282,19 @@ func extractSBOM(attestationBytes []byte) (string, error) {
283
282
return "" , fmt .Errorf ("failed to decode payload: %w" , err )
284
283
}
285
284
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
287
298
}
288
299
289
300
func (c sbomConfig ) storeSBOM (sbom string , image string ) error {
@@ -296,7 +307,7 @@ func (c sbomConfig) storeSBOM(sbom string, image string) error {
296
307
}, image )
297
308
298
309
// Create the output file path
299
- outputFile := filepath .Join (c .outputDir , safeImageName + ".json" )
310
+ outputFile := filepath .Join (c .outputDir , safeImageName + ".cdx. json" )
300
311
301
312
// Ensure the output directory exists
302
313
if err := os .MkdirAll (c .outputDir , 0755 ); err != nil {
@@ -311,10 +322,6 @@ func (c sbomConfig) storeSBOM(sbom string, image string) error {
311
322
return nil
312
323
}
313
324
314
- func getOutputDir (parentDir , version string ) string {
315
- return path .Join (parentDir , "sourcegraph-" + version )
316
- }
317
-
318
325
// getImageReleaseListURL returns the URL for the list of images in a release, based on the version and whether it's an internal release.
319
326
func (c * sbomConfig ) getImageReleaseListURL () string {
320
327
if c .internalRelease {
0 commit comments