@@ -28,43 +28,54 @@ import (
28
28
"github.com/snyk/parlay/lib/ecosystems"
29
29
)
30
30
31
- func cdxEnrichExternalReference (component cdx.Component , url string , comment string , refType cdx.ExternalReferenceType ) cdx. Component {
31
+ func cdxEnrichExternalReference (comp * cdx.Component , url , comment string , refType cdx.ExternalReferenceType ) {
32
32
ext := cdx.ExternalReference {
33
33
URL : url ,
34
34
Comment : comment ,
35
35
Type : refType ,
36
36
}
37
- if component .ExternalReferences == nil {
38
- component .ExternalReferences = & []cdx.ExternalReference {ext }
37
+
38
+ if comp .ExternalReferences == nil {
39
+ comp .ExternalReferences = & []cdx.ExternalReference {ext }
39
40
} else {
40
- * component .ExternalReferences = append (* component .ExternalReferences , ext )
41
+ * comp .ExternalReferences = append (* comp .ExternalReferences , ext )
41
42
}
42
- return component
43
43
}
44
44
45
45
func enrichCDX (bom * cdx.BOM ) {
46
46
comps := utils .DiscoverCDXComponents (bom )
47
+
47
48
wg := sizedwaitgroup .New (20 )
49
+
48
50
for i := range comps {
49
51
wg .Add ()
50
52
go func (component * cdx.Component ) {
51
53
defer wg .Done ()
54
+
52
55
purl , err := packageurl .FromString (component .PackageURL )
53
56
if err != nil {
54
57
return
55
58
}
59
+
56
60
resp , err := ecosystems .GetPackageData (purl )
57
- if err == nil && resp .JSON200 != nil && resp .JSON200 .RepositoryUrl != nil {
58
- scorecardUrl := strings .ReplaceAll (* resp .JSON200 .RepositoryUrl , "https://" , "https://api.securityscorecards.dev/projects/" )
59
- response , err := http .Get (scorecardUrl )
60
- if err == nil {
61
- defer response .Body .Close ()
62
- if response .StatusCode == http .StatusOK {
63
- * component = cdxEnrichExternalReference (* component , scorecardUrl , "OpenSSF Scorecard" , cdx .ERTypeOther )
64
- }
65
- }
61
+ if err != nil {
62
+ return
66
63
}
64
+
65
+ if resp .JSON200 == nil || resp .JSON200 .RepositoryUrl == nil {
66
+ return
67
+ }
68
+
69
+ scorecardUrl := strings .ReplaceAll (* resp .JSON200 .RepositoryUrl , "https://" , "https://api.securityscorecards.dev/projects/" )
70
+ response , err := http .Get (scorecardUrl )
71
+ response .Body .Close ()
72
+ if err != nil || response .StatusCode != http .StatusOK {
73
+ return
74
+ }
75
+
76
+ cdxEnrichExternalReference (component , scorecardUrl , "OpenSSF Scorecard" , cdx .ERTypeOther )
67
77
}(comps [i ])
68
78
}
79
+
69
80
wg .Wait ()
70
81
}
0 commit comments