Skip to content

Commit 64c0c74

Browse files
authored
Merge pull request #14 from jeffmendoza/sbomcoords
Add sbomcoords tool
2 parents 1f19bcb + a83f7af commit 64c0c74

File tree

6 files changed

+162
-40
lines changed

6 files changed

+162
-40
lines changed

README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,35 @@ not specified.
5959
Supported formats are the [same as
6060
Protobom](https://github.com/protobom/protobom/blob/main/README.md#supported-versions-and-formats).
6161

62+
## sbomcoords
63+
64+
### Install:
65+
66+
```sh
67+
go install github.com/jeffmendoza/cdsbom/sbomcoords@latest
68+
```
69+
70+
Make sure `$GOBIN` is in your path.
71+
72+
- `$GOBIN` defaults to `$GOPATH/bin`
73+
- `$GOPATH` defaults to `$HOME/go` on Unix and `%USERPROFILE%\go` on Windows
74+
75+
### Use:
76+
77+
Example:
78+
```sh
79+
sbomcoords -out coords.json input-sbom.json
80+
```
81+
82+
This will read `input-sbom.json` and parse all the dependencies found, looking
83+
for PURL identifiers. These PURLs will be converted to [ClearlyDefined
84+
Coordinates](https://docs.clearlydefined.io/docs/get-involved/using-data#clearlydefined-coordinates)
85+
and de-duplicated. The output file `coords.json` will be a json array of
86+
Coordinates.
87+
88+
Supported formats are the [same as
89+
Protobom](https://github.com/protobom/protobom/blob/main/README.md#supported-versions-and-formats).
90+
6291
## Thanks
6392

6493
This project is possible due to

go.mod

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,29 +3,30 @@ module github.com/jeffmendoza/cdsbom
33
go 1.23.3
44

55
require (
6-
github.com/guacsec/sw-id-core v0.1.0
7-
github.com/protobom/protobom v0.5.0
8-
golang.org/x/time v0.10.0
6+
github.com/guacsec/sw-id-core v0.1.1
7+
github.com/hashicorp/go-retryablehttp v0.7.7
8+
github.com/protobom/protobom v0.5.2
9+
golang.org/x/time v0.11.0
910
)
1011

1112
//replace github.com/guacsec/sw-id-core => ../sw-id-core
1213

1314
require (
14-
github.com/CycloneDX/cyclonedx-go v0.9.1 // indirect
15-
github.com/anchore/go-struct-converter v0.0.0-20230627203149-c72ef8859ca9 // indirect
15+
github.com/CycloneDX/cyclonedx-go v0.9.2 // indirect
16+
github.com/anchore/go-struct-converter v0.0.0-20250211213226-cce56d595160 // indirect
1617
github.com/blang/semver/v4 v4.0.0 // indirect
1718
github.com/common-nighthawk/go-figure v0.0.0-20210622060536-734e95fb86be // indirect
18-
github.com/google/go-cmp v0.6.0 // indirect
19+
github.com/google/go-cmp v0.7.0 // indirect
1920
github.com/google/uuid v1.6.0 // indirect
2021
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
21-
github.com/hashicorp/go-retryablehttp v0.7.7 // indirect
2222
github.com/inconshreveable/mousetrap v1.1.0 // indirect
2323
github.com/package-url/packageurl-go v0.1.3 // indirect
2424
github.com/sirupsen/logrus v1.9.3 // indirect
2525
github.com/spdx/tools-golang v0.5.5 // indirect
26-
github.com/spf13/cobra v1.8.1 // indirect
27-
github.com/spf13/pflag v1.0.5 // indirect
28-
golang.org/x/sys v0.25.0 // indirect
29-
google.golang.org/protobuf v1.35.1 // indirect
30-
sigs.k8s.io/release-utils v0.8.4 // indirect
26+
github.com/spf13/cobra v1.9.1 // indirect
27+
github.com/spf13/pflag v1.0.6 // indirect
28+
golang.org/x/mod v0.24.0 // indirect
29+
golang.org/x/sys v0.32.0 // indirect
30+
google.golang.org/protobuf v1.36.6 // indirect
31+
sigs.k8s.io/release-utils v0.11.1 // indirect
3132
)

go.sum

Lines changed: 37 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,56 @@
1-
github.com/CycloneDX/cyclonedx-go v0.9.1 h1:yffaWOZsv77oTJa/SdVZYdgAgFioCeycBUKkqS2qzQM=
2-
github.com/CycloneDX/cyclonedx-go v0.9.1/go.mod h1:NE/EWvzELOFlG6+ljX/QeMlVt9VKcTwu8u0ccsACEsw=
1+
github.com/CycloneDX/cyclonedx-go v0.9.2 h1:688QHn2X/5nRezKe2ueIVCt+NRqf7fl3AVQk+vaFcIo=
2+
github.com/CycloneDX/cyclonedx-go v0.9.2/go.mod h1:vcK6pKgO1WanCdd61qx4bFnSsDJQ6SbM2ZuMIgq86Jg=
33
github.com/anchore/go-struct-converter v0.0.0-20221118182256-c68fdcfa2092/go.mod h1:rYqSE9HbjzpHTI74vwPvae4ZVYZd1lue2ta6xHPdblA=
4-
github.com/anchore/go-struct-converter v0.0.0-20230627203149-c72ef8859ca9 h1:6COpXWpHbhWM1wgcQN95TdsmrLTba8KQfPgImBXzkjA=
5-
github.com/anchore/go-struct-converter v0.0.0-20230627203149-c72ef8859ca9/go.mod h1:rYqSE9HbjzpHTI74vwPvae4ZVYZd1lue2ta6xHPdblA=
4+
github.com/anchore/go-struct-converter v0.0.0-20250211213226-cce56d595160 h1:r8/1fxpbDMlQO6GgQiud1uL5eAu3p/NVUmfNx95/KY8=
5+
github.com/anchore/go-struct-converter v0.0.0-20250211213226-cce56d595160/go.mod h1:rYqSE9HbjzpHTI74vwPvae4ZVYZd1lue2ta6xHPdblA=
66
github.com/blang/semver/v4 v4.0.0 h1:1PFHFE6yCCTv8C1TeyNNarDzntLi7wMI5i/pzqYIsAM=
77
github.com/blang/semver/v4 v4.0.0/go.mod h1:IbckMUScFkM3pff0VJDNKRiT6TG/YpiHIM2yvyW5YoQ=
88
github.com/bradleyjkemp/cupaloy/v2 v2.8.0 h1:any4BmKE+jGIaMpnU8YgH/I2LPiLBufr6oMMlVBbn9M=
99
github.com/bradleyjkemp/cupaloy/v2 v2.8.0/go.mod h1:bm7JXdkRd4BHJk9HpwqAI8BoAY1lps46Enkdqw6aRX0=
1010
github.com/common-nighthawk/go-figure v0.0.0-20210622060536-734e95fb86be h1:J5BL2kskAlV9ckgEsNQXscjIaLiOYiZ75d4e94E6dcQ=
1111
github.com/common-nighthawk/go-figure v0.0.0-20210622060536-734e95fb86be/go.mod h1:mk5IQ+Y0ZeO87b858TlA645sVcEcbiX6YqP98kt+7+w=
12-
github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
12+
github.com/cpuguy83/go-md2man/v2 v2.0.6/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g=
1313
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
1414
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
1515
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
16+
github.com/fatih/color v1.16.0 h1:zmkK9Ngbjj+K0yRhTVONQh1p/HknKYSlNT+vZCzyokM=
17+
github.com/fatih/color v1.16.0/go.mod h1:fL2Sau1YI5c0pdGEVCbKQbLXB6edEj1ZgiY4NijnWvE=
1618
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
17-
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
1819
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
20+
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
21+
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
1922
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
2023
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
21-
github.com/guacsec/sw-id-core v0.1.0 h1:8aOlnXqKChc77iZihZgc1Hsb15fJYARAD24ffYg1gxQ=
22-
github.com/guacsec/sw-id-core v0.1.0/go.mod h1:9VKdfHjGRKxwLEOKf4hmRt7NWav1n5tObHszoTLbcuQ=
24+
github.com/guacsec/sw-id-core v0.1.1 h1:e3ZjaXoAlJy3F39wO1QJsiakIsS9ZTB/qq3MUOYILhw=
25+
github.com/guacsec/sw-id-core v0.1.1/go.mod h1:U2RI90W0zQUfk8Qy+84zFUC7yflBSRpQVupl+iIdYhg=
2326
github.com/hashicorp/go-cleanhttp v0.5.2 h1:035FKYIWjmULyFRBKPs8TBQoi0x6d9G4xc9neXJWAZQ=
2427
github.com/hashicorp/go-cleanhttp v0.5.2/go.mod h1:kO/YDlP8L1346E6Sodw+PrpBSV4/SoxCXGY6BqNFT48=
28+
github.com/hashicorp/go-hclog v1.6.3 h1:Qr2kF+eVWjTiYmU7Y31tYlP1h0q/X3Nl3tPGdaB11/k=
29+
github.com/hashicorp/go-hclog v1.6.3/go.mod h1:W4Qnvbt70Wk/zYJryRzDRU/4r0kIg0PVHBcfoyhpF5M=
2530
github.com/hashicorp/go-retryablehttp v0.7.7 h1:C8hUCYzor8PIfXHa4UrZkU4VvK8o9ISHxT2Q8+VepXU=
2631
github.com/hashicorp/go-retryablehttp v0.7.7/go.mod h1:pkQpWZeYWskR+D1tR2O5OcBFOxfA7DoAO6xtkuQnHTk=
2732
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
2833
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
34+
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
35+
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
36+
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
37+
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
2938
github.com/package-url/packageurl-go v0.1.3 h1:4juMED3hHiz0set3Vq3KeQ75KD1avthoXLtmE3I0PLs=
3039
github.com/package-url/packageurl-go v0.1.3/go.mod h1:nKAWB8E6uk1MHqiS/lQb9pYBGH2+mdJ2PJc2s50dQY0=
3140
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
3241
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
33-
github.com/protobom/protobom v0.5.0 h1:jJYqGpdHq99zwh0/n1SOPl1aickCBZdA8pHS9V/f+XQ=
34-
github.com/protobom/protobom v0.5.0/go.mod h1:HL47tggz7SXYXgNm3WjQQrWB6iOirYnrATsXAEyTUkI=
42+
github.com/protobom/protobom v0.5.2 h1:GQacWLer4tDskyjQpqbglXkT3ZlNy7AJCw/S2XZkVS8=
43+
github.com/protobom/protobom v0.5.2/go.mod h1:io5yUKGWBqGa2sx1n7aVPg+tG13Hun9oMz4Y+EjNjjc=
3544
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
3645
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
3746
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
3847
github.com/spdx/gordf v0.0.0-20201111095634-7098f93598fb/go.mod h1:uKWaldnbMnjsSAXRurWqqrdyZen1R7kxl8TkmWk2OyM=
3948
github.com/spdx/tools-golang v0.5.5 h1:61c0KLfAcNqAjlg6UNMdkwpMernhw3zVRwDZ2x9XOmk=
4049
github.com/spdx/tools-golang v0.5.5/go.mod h1:MVIsXx8ZZzaRWNQpUDhC4Dud34edUYJYecciXgrw5vE=
41-
github.com/spf13/cobra v1.8.1 h1:e5/vxKd/rZsfSJMUX1agtjeTDf+qv1/JdBF8gg5k9ZM=
42-
github.com/spf13/cobra v1.8.1/go.mod h1:wHxEcudfqmLYa8iTfL+OuZPbBZkmvliBWKIezN3kD9Y=
43-
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
44-
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
50+
github.com/spf13/cobra v1.9.1 h1:CXSaggrXdbHK9CF+8ywj8Amf7PBRmPCOJugH954Nnlo=
51+
github.com/spf13/cobra v1.9.1/go.mod h1:nDyEzZ8ogv936Cinf6g1RU9MRY64Ir93oCnqb9wxYW0=
52+
github.com/spf13/pflag v1.0.6 h1:jFzHGLGAlb3ruxLB8MhbI6A8+AQX/2eW4qeyNZXNp2o=
53+
github.com/spf13/pflag v1.0.6/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
4554
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
4655
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
4756
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
@@ -50,27 +59,30 @@ github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
5059
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
5160
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
5261
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
53-
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
5462
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
55-
github.com/terminalstatic/go-xsd-validate v0.1.5 h1:RqpJnf6HGE2CB/lZB1A8BYguk8uRtcvYAPLCF15qguo=
56-
github.com/terminalstatic/go-xsd-validate v0.1.5/go.mod h1:18lsvYFofBflqCrvo1umpABZ99+GneNTw2kEEc8UPJw=
63+
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
64+
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
65+
github.com/terminalstatic/go-xsd-validate v0.1.6 h1:TenYeQ3eY631qNi1/cTmLH/s2slHPRKTTHT+XSHkepo=
66+
github.com/terminalstatic/go-xsd-validate v0.1.6/go.mod h1:18lsvYFofBflqCrvo1umpABZ99+GneNTw2kEEc8UPJw=
5767
github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f h1:J9EGpcZtP0E/raorCMxlFGSTBrsSlaDGf3jU/qvAE2c=
5868
github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f/go.mod h1:N2zxlSyiKSe5eX1tZViRH5QA0qijqEDrYZiPEAiq3wU=
5969
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 h1:EzJWgHovont7NscjpAxXsDA8S8BMYve8Y5+7cuRE7R0=
6070
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415/go.mod h1:GwrjFmJcFw6At/Gs6z4yjiIwzuJ1/+UwLxMQDVQXShQ=
6171
github.com/xeipuuv/gojsonschema v1.2.0 h1:LhYJRs+L4fBtjZUfuSZIKGeVu0QRy8e5Xi7D17UxZ74=
6272
github.com/xeipuuv/gojsonschema v1.2.0/go.mod h1:anYRn/JVcOK2ZgGU+IjEV4nwlhoK5sQluxsYJ78Id3Y=
73+
golang.org/x/mod v0.24.0 h1:ZfthKaKaT4NrhGVZHO1/WDTwGES4De8KtWO0SIbNJMU=
74+
golang.org/x/mod v0.24.0/go.mod h1:IXM97Txy2VM4PJ3gI61r1YEk/gAj6zAHN3AdZt6S9Ww=
6375
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
64-
golang.org/x/sys v0.25.0 h1:r+8e+loiHxRqhXVl6ML1nO3l1+oFoWbnlu2Ehimmi34=
65-
golang.org/x/sys v0.25.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
66-
golang.org/x/time v0.10.0 h1:3usCWA8tQn0L8+hFJQNgzpWbd89begxN66o1Ojdn5L4=
67-
golang.org/x/time v0.10.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM=
68-
google.golang.org/protobuf v1.35.1 h1:m3LfL6/Ca+fqnjnlqQXNpFPABW1UD7mjh8KO2mKFytA=
69-
google.golang.org/protobuf v1.35.1/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE=
76+
golang.org/x/sys v0.32.0 h1:s77OFDvIQeibCmezSnk/q6iAfkdiQaJi4VzroCFrN20=
77+
golang.org/x/sys v0.32.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
78+
golang.org/x/time v0.11.0 h1:/bpjEDfN9tkoN/ryeYHnv5hcMlc8ncjMcM4XBk5NWV0=
79+
golang.org/x/time v0.11.0/go.mod h1:CDIdPxbZBQxdj6cxyCIdrNogrJKMJ7pr37NYpMcMDSg=
80+
google.golang.org/protobuf v1.36.6 h1:z1NpPI8ku2WgiWnf+t9wTPsn6eP1L7ksHUlkfLvd9xY=
81+
google.golang.org/protobuf v1.36.6/go.mod h1:jduwjTPXsFjZGTmRluh+L6NjiWu7pchiJ2/5YcXBHnY=
7082
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
7183
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
7284
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
7385
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
74-
sigs.k8s.io/release-utils v0.8.4 h1:4QVr3UgbyY/d9p74LBhg0njSVQofUsAZqYOzVZBhdBw=
75-
sigs.k8s.io/release-utils v0.8.4/go.mod h1:m1bHfscTemQp+z+pLCZnkXih9n0+WukIUU70n6nFnU0=
86+
sigs.k8s.io/release-utils v0.11.1 h1:hzvXGpHgHJfLOJB6TRuu14bzWc3XEglHmXHJqwClSZE=
87+
sigs.k8s.io/release-utils v0.11.1/go.mod h1:ybR2V/uQAOGxYfzYtBenSYeXWkBGNP2qnEiX77ACtpc=
7688
sigs.k8s.io/yaml v1.4.0/go.mod h1:Ejl7/uTz7PSA4eKMyQCUTnhZYNmLIl+5c2lQPGR2BPY=

pkg/enhance/enhance.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ func init() {
4646
// updates are printed to stdout. TODO: Update to use a provided io.Writer or
4747
// logger, also to use provided http client/transport and context.
4848
func Do(ctx context.Context, s *sbom.Document) error {
49-
coords := coordList(s)
49+
coords := CoordList(s)
5050
defs, err := getDefs(ctx, coords)
5151
if err != nil {
5252
return err
@@ -57,7 +57,7 @@ func Do(ctx context.Context, s *sbom.Document) error {
5757

5858
// CoordList takes an SBOM document and returns a slice of all ClearlyDefined
5959
// Coordinates found in that document.
60-
func coordList(s *sbom.Document) []string {
60+
func CoordList(s *sbom.Document) []string {
6161
nodes := s.GetNodeList().GetNodes()
6262
coords := make(map[string]bool)
6363
for _, node := range nodes {

pkg/enhance/notice.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ type NoticeRsp struct {
3737
// Notice takes an SBOM document and queries ClearlyDefined for a NOTICE file
3838
// for all the recognized components in the SBOM.
3939
func Notice(ctx context.Context, s *sbom.Document) (string, error) {
40-
c := coordList(s)
40+
c := CoordList(s)
4141
return request(ctx, c)
4242
}
4343

sbomcoords/main.go

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
//
2+
// Copyright (c) Jeff Mendoza <jlm@jlm.name>
3+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
4+
// SPDX-License-Identifier: MIT
5+
//
6+
7+
package main
8+
9+
import (
10+
"encoding/json"
11+
"flag"
12+
"fmt"
13+
"os"
14+
15+
"github.com/protobom/protobom/pkg/reader"
16+
"github.com/protobom/protobom/pkg/sbom"
17+
18+
"github.com/jeffmendoza/cdsbom/pkg/enhance"
19+
)
20+
21+
func main() {
22+
inFile, outFile := flags()
23+
24+
document := read(inFile)
25+
26+
coords := enhance.CoordList(document)
27+
bts, err := json.Marshal(coords)
28+
if err != nil {
29+
fmt.Printf("Error marshaling coordinates: %v\n", err)
30+
os.Exit(1)
31+
}
32+
33+
write(bts, outFile)
34+
fmt.Println("Complete")
35+
}
36+
37+
// flags sets up and parses flags. Return values are input file and output file
38+
// respecively.
39+
func flags() (string, string) {
40+
o := flag.String("out", "coords.json", "Name of output file")
41+
42+
flag.Usage = func() {
43+
fmt.Printf("Usage of %s:\n", os.Args[0])
44+
fmt.Printf("\tThis program generates a list of ClearlyDefined Coordinates from an SBOM\n")
45+
fmt.Printf("%s [options] <in-SBOM-file>\n", os.Args[0])
46+
fmt.Printf("Options:\n")
47+
flag.PrintDefaults()
48+
}
49+
50+
flag.Parse()
51+
52+
r := flag.Args()
53+
if len(r) != 1 {
54+
flag.Usage()
55+
os.Exit(1)
56+
}
57+
i := r[0]
58+
59+
return i, *o
60+
}
61+
62+
// read reads in the sbom document and also returns the format.
63+
func read(i string) *sbom.Document {
64+
reader := reader.New()
65+
d, err := reader.ParseFile(i)
66+
if err != nil {
67+
fmt.Printf("Error reading input SBOM: %v\n", err)
68+
os.Exit(1)
69+
}
70+
return d
71+
}
72+
73+
// write writes the document to a file
74+
func write(data []byte, of string) {
75+
err := os.WriteFile(of, data, 0666)
76+
if err != nil {
77+
fmt.Printf("Error writing outout: %v\n", err)
78+
os.Exit(1)
79+
}
80+
}

0 commit comments

Comments
 (0)