Skip to content

Commit e263a6b

Browse files
committed
feat: add deps.dev API integration
1 parent 07e4d5a commit e263a6b

File tree

14 files changed

+1143
-22
lines changed

14 files changed

+1143
-22
lines changed

README.md

Lines changed: 77 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
* [ecosyste.ms](https://ecosyste.ms)
1111
* [Snyk](https://snyk.io)
1212
* [OpenSSF Scorecard](https://securityscorecards.dev/)
13+
* [deps.dev](https://deps.dev)
1314

1415
By enrich, we mean add additional information. You put in an SBOM, and you get a richer SBOM back. In many cases SBOMs have a minimum of information, often just the name and version of a given package. By enriching that with additional information we can make better decisions about the packages we're using.
1516

@@ -191,7 +192,7 @@ Snyk will add a new [vulnerability](https://cyclonedx.org/docs/1.4/json/#vulnera
191192
}
192193
```
193194

194-
For SPDX, vulnerability informatio is added as additional `externalRefs`:
195+
For SPDX, vulnerability information is added as additional `externalRefs`:
195196

196197
```json
197198
{
@@ -246,6 +247,74 @@ This will currently add an external reference to the [Scorecard API](https://api
246247

247248
We're currently looking at the best way of encoding some of the scorecard data in the SBOM itself as well.
248249

250+
## Enriching with deps.dev
251+
252+
The [deps.dev](https://deps.dev) service provides repository insights and security data for open source packages. `parlay` can enrich SBOMs with repository metadata from deps.dev.
253+
254+
```
255+
parlay deps enrich testing/sbom-with-vcs.cyclonedx.json
256+
```
257+
258+
This will add repository information as properties for components that have VCS external references:
259+
260+
```json
261+
{
262+
"bom-ref": "[email protected]",
263+
"type": "library",
264+
"name": "subtext",
265+
"version": "6.0.12",
266+
"purl": "pkg:npm/[email protected]",
267+
"externalReferences": [
268+
{
269+
"url": "https://github.com/hapijs/subtext",
270+
"type": "vcs"
271+
}
272+
],
273+
"properties": [
274+
{
275+
"name": "deps:open_issues_count",
276+
"value": "7"
277+
},
278+
{
279+
"name": "deps:stars_count",
280+
"value": "24"
281+
},
282+
{
283+
"name": "deps:forks_count",
284+
"value": "25"
285+
},
286+
{
287+
"name": "deps:license",
288+
"value": "non-standard"
289+
},
290+
{
291+
"name": "deps:description",
292+
"value": "HTTP payload parser"
293+
},
294+
{
295+
"name": "deps:scorecard",
296+
"value": "4.30"
297+
}
298+
]
299+
}
300+
```
301+
302+
For SPDX format, the same information is added as external references:
303+
304+
```json
305+
{
306+
"referenceCategory": "OTHER",
307+
"referenceType": "deps:stars_count",
308+
"referenceLocator": "24",
309+
"comment": "deps.dev deps:stars_count"
310+
}
311+
```
312+
313+
You can also return raw JSON information about a specific repository from deps.dev:
314+
315+
```
316+
parlay deps repo github.com/hapijs/subtext
317+
```
249318

250319
## What about enriching with other data sources?
251320

@@ -256,10 +325,10 @@ There are lots of other sources of package data, and it would be great to add su
256325

257326
`parlay` is a fan of stdin and stdout. You can pipe SBOMs from other tools into `parlay`, and pipe between the separate `enrich` commands too.
258327

259-
Maybe you want to enrich an SBOM with both ecosyste.ms and Snyk data:
328+
Maybe you want to enrich an SBOM with ecosyste.ms, Snyk, and deps.dev data:
260329

261330
```
262-
cat testing/sbom.cyclonedx.json | ./parlay e enrich - | ./parlay s enrich - | jq
331+
cat testing/sbom.cyclonedx.json | ./parlay e enrich - | ./parlay s enrich - | ./parlay d enrich - | jq
263332
```
264333

265334
Maybe you want to take the output from Syft and add vulnerabilitity data?
@@ -268,7 +337,7 @@ Maybe you want to take the output from Syft and add vulnerabilitity data?
268337
syft -o cyclonedx-json nginx | parlay s enrich - | jq
269338
```
270339

271-
Maybe you want to geneate an SBOM with `cdxgen`, enrich that with extra information, and test that with `bomber`:
340+
Maybe you want to generate an SBOM with `cdxgen`, enrich that with extra information, and test that with `bomber`:
272341

273342
```
274343
cdxgen -o | parlay e enrich - | bomber scan --provider snyk -
@@ -348,3 +417,7 @@ The various services used to enrich the SBOM data have data for a subset of purl
348417
* `pypi`
349418

350419
Note that Scorecard data is available only for a subset of projects from supported Git repositories. See the [Scorecard project](https://github.com/ossf/scorecard) for more information.
420+
421+
### deps.dev
422+
423+
deps.dev enrichment works with any component that has VCS external references pointing to supported Git repositories (GitHub, GitLab, etc.).

acceptance.bats

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,8 @@
2929
run ./parlay ecosystems enrich not-here
3030
[ "$status" -eq 1 ]
3131
}
32+
33+
@test "Not fail when testing deps enrichment" {
34+
run ./parlay deps enrich testing/sbom-with-vcs.cyclonedx.json
35+
[ "$status" -eq 0 ]
36+
}

go.mod

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ go 1.23
55
require (
66
github.com/CycloneDX/cyclonedx-go v0.9.2
77
github.com/deepmap/oapi-codegen v1.12.4
8-
github.com/edoardottt/depsdev v0.0.3
98
github.com/google/uuid v1.5.0
109
github.com/hashicorp/go-retryablehttp v0.7.7
1110
github.com/jarcoal/httpmock v1.3.0
@@ -22,7 +21,6 @@ require (
2221
require (
2322
github.com/anchore/go-struct-converter v0.0.0-20221118182256-c68fdcfa2092 // indirect
2423
github.com/apapsch/go-jsonmerge/v2 v2.0.0 // indirect
25-
github.com/avast/retry-go v3.0.0+incompatible // indirect
2624
github.com/davecgh/go-spew v1.1.1 // indirect
2725
github.com/fsnotify/fsnotify v1.6.0 // indirect
2826
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect

go.sum

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,6 @@ github.com/anchore/go-struct-converter v0.0.0-20221118182256-c68fdcfa2092 h1:aM1
4545
github.com/anchore/go-struct-converter v0.0.0-20221118182256-c68fdcfa2092/go.mod h1:rYqSE9HbjzpHTI74vwPvae4ZVYZd1lue2ta6xHPdblA=
4646
github.com/apapsch/go-jsonmerge/v2 v2.0.0 h1:axGnT1gRIfimI7gJifB699GoE/oq+F2MU7Dml6nw9rQ=
4747
github.com/apapsch/go-jsonmerge/v2 v2.0.0/go.mod h1:lvDnEdqiQrp0O42VQGgmlKpxL1AP2+08jFMw88y4klk=
48-
github.com/avast/retry-go v3.0.0+incompatible h1:4SOWQ7Qs+oroOTQOYnAHqelpCO0biHSxpiH9JdtuBj0=
49-
github.com/avast/retry-go v3.0.0+incompatible/go.mod h1:XtSnn+n/sHqQIpZ10K1qAevBhOOCWBLXXy3hyiqqBrY=
5048
github.com/bmatcuk/doublestar v1.1.1/go.mod h1:UD6OnuiIn0yFxxA2le/rnRU1G4RaI4UvFv1sNto9p6w=
5149
github.com/bradleyjkemp/cupaloy/v2 v2.8.0 h1:any4BmKE+jGIaMpnU8YgH/I2LPiLBufr6oMMlVBbn9M=
5250
github.com/bradleyjkemp/cupaloy/v2 v2.8.0/go.mod h1:bm7JXdkRd4BHJk9HpwqAI8BoAY1lps46Enkdqw6aRX0=
@@ -65,8 +63,6 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
6563
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
6664
github.com/deepmap/oapi-codegen v1.12.4 h1:pPmn6qI9MuOtCz82WY2Xaw46EQjgvxednXXrP7g5Q2s=
6765
github.com/deepmap/oapi-codegen v1.12.4/go.mod h1:3lgHGMu6myQ2vqbbTXH2H1o4eXFTGnFiDaOaKKl5yas=
68-
github.com/edoardottt/depsdev v0.0.3 h1:QqTZGjdvrq8aZ0qhlPxUHiDrB+LadqUVsHX9a03pWO0=
69-
github.com/edoardottt/depsdev v0.0.3/go.mod h1:IQTpYyqJbheAt6AXD/96CUMSGHha5r6rMLNKD8CXkiY=
7066
github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
7167
github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
7268
github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98=

internal/commands/deps/enrich.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package deps
2+
3+
import (
4+
"os"
5+
6+
"github.com/snyk/parlay/internal/utils"
7+
"github.com/snyk/parlay/lib/deps"
8+
"github.com/snyk/parlay/lib/sbom"
9+
10+
"github.com/rs/zerolog"
11+
"github.com/spf13/cobra"
12+
)
13+
14+
func NewEnrichCommand(logger *zerolog.Logger) *cobra.Command {
15+
cmd := cobra.Command{
16+
Use: "enrich <sbom>",
17+
Short: "Enrich an SBOM with deps.dev data",
18+
Args: cobra.ExactArgs(1),
19+
Run: func(cmd *cobra.Command, args []string) {
20+
b, err := utils.GetUserInput(args[0], os.Stdin)
21+
if err != nil {
22+
logger.Fatal().Err(err).Msg("Failed to read input")
23+
}
24+
25+
doc, err := sbom.DecodeSBOMDocument(b)
26+
if err != nil {
27+
logger.Fatal().Err(err).Msg("Failed to read SBOM input")
28+
}
29+
30+
deps.EnrichSBOM(doc, logger)
31+
32+
if err := doc.Encode(os.Stdout); err != nil {
33+
logger.Fatal().Err(err).Msg("Failed to encode new SBOM")
34+
}
35+
},
36+
}
37+
return &cmd
38+
}

internal/commands/deps/root.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ func NewDepsRootCommand(logger *zerolog.Logger) *cobra.Command {
2020
}
2121

2222
cmd.AddCommand(NewRepoCommand(logger))
23+
cmd.AddCommand(NewEnrichCommand(logger))
2324

2425
return &cmd
2526
}

lib/deps/enrich.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* © 2023 Snyk Limited All rights reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package deps
18+
19+
import (
20+
cdx "github.com/CycloneDX/cyclonedx-go"
21+
"github.com/rs/zerolog"
22+
"github.com/spdx/tools-golang/spdx"
23+
24+
"github.com/snyk/parlay/lib/sbom"
25+
)
26+
27+
func EnrichSBOM(doc *sbom.SBOMDocument, logger *zerolog.Logger) *sbom.SBOMDocument {
28+
switch bom := doc.BOM.(type) {
29+
case *cdx.BOM:
30+
enrichCDX(bom, logger)
31+
case *spdx.Document:
32+
enrichSPDX(bom, logger)
33+
default:
34+
logger.Debug().Msg("Unsupported SBOM format for deps.dev enrichment")
35+
}
36+
return doc
37+
}

0 commit comments

Comments
 (0)