Skip to content

Commit eb31c0c

Browse files
authored
Merge pull request moby#3479 from jedevc/ensure-spdx-order
exporter: ensure spdx order prioritizes primary sbom
2 parents e86ba94 + eabeb4f commit eb31c0c

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

exporter/attestation/unbundle.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,13 +81,41 @@ func Unbundle(ctx context.Context, s session.Group, bundled []exporter.Attestati
8181
for _, atts := range unbundled {
8282
joined = append(joined, atts...)
8383
}
84+
joined = sort(joined)
8485

8586
if err := Validate(joined); err != nil {
8687
return nil, err
8788
}
8889
return joined, nil
8990
}
9091

92+
func sort(atts []exporter.Attestation) []exporter.Attestation {
93+
isCore := make([]bool, len(atts))
94+
for i, att := range atts {
95+
name, ok := att.Metadata[result.AttestationSBOMCore]
96+
if !ok {
97+
continue
98+
}
99+
if n, _, _ := strings.Cut(att.Path, "."); n != string(name) {
100+
continue
101+
}
102+
isCore[i] = true
103+
}
104+
105+
result := make([]exporter.Attestation, 0, len(atts))
106+
for i, att := range atts {
107+
if isCore[i] {
108+
result = append(result, att)
109+
}
110+
}
111+
for i, att := range atts {
112+
if !isCore[i] {
113+
result = append(result, att)
114+
}
115+
}
116+
return result
117+
}
118+
91119
func unbundle(ctx context.Context, root string, bundle exporter.Attestation) ([]exporter.Attestation, error) {
92120
dir, err := fs.RootPath(root, bundle.Path)
93121
if err != nil {

0 commit comments

Comments
 (0)