Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add license resolution support for bin command #52

Merged
merged 11 commits into from
Aug 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Binaries for programs and plugins
bin/
*.exe
*.exe~
*.dll
Expand Down
9 changes: 5 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
LDFLAGS="-s -w -X github.com/CycloneDX/cyclonedx-gomod/internal/version.Version=v0.0.0-$(shell git show -s --date=format:'%Y%m%d%H%M%S' --format=%cd HEAD)-$(shell git rev-parse HEAD | head -c 12)"

build:
go build -v -ldflags=${LDFLAGS}
mkdir -p ./bin
go build -v -ldflags=${LDFLAGS} -o ./bin/cyclonedx-gomod
.PHONY: build

install:
Expand All @@ -28,9 +29,9 @@ docker:
docker build -t cyclonedx/cyclonedx-gomod -f Dockerfile .
.PHONY: docker

bom:
go run main.go -licenses -std -output bom.xml
cyclonedx validate --input-file bom.xml --input-format xml --fail-on-errors
bom: build
./bin/cyclonedx-gomod mod -licenses -std -json -output bom.json
cyclonedx validate --input-file bom.json --fail-on-errors
.PHONY: bom

goreleaser-dryrun:
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ USAGE
Generate SBOM for a binary.
When license resolution is enabled, all modules (including the main module)
will be downloaded to the module cache using "go mod download".
Please note that data embedded in binaries shouldn't be trusted,
unless there's solid evidence that the binaries haven't been modified
since they've been built.
Expand All @@ -61,6 +64,7 @@ Example:
FLAGS
-json=false Output in JSON
-licenses=false Resolve module licenses
-noserial=false Omit serial number
-novprefix=false Omit "v" prefix from versions
-output - Output file path (or - for STDOUT)
Expand Down
5 changes: 3 additions & 2 deletions e2e/cmd_bin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ import (
func TestBinCmdSimple(t *testing.T) {
binOptions := bincmd.BinOptions{
SBOMOptions: options.SBOMOptions{
Reproducible: true,
SerialNumber: zeroUUID.String(),
Reproducible: true,
ResolveLicenses: true,
SerialNumber: zeroUUID.String(),
},
BinaryPath: "./testdata/bincmd/simple",
Version: "v1.0.0",
Expand Down
50 changes: 25 additions & 25 deletions e2e/cmd_mod_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ func TestModCmdSimple(t *testing.T) {

modOptions := modcmd.ModOptions{
SBOMOptions: options.SBOMOptions{
Reproducible: true,
SerialNumber: zeroUUID.String(),
Reproducible: true,
ResolveLicenses: true,
SerialNumber: zeroUUID.String(),
},
ComponentType: string(cdx.ComponentTypeLibrary),
ModuleDir: fixturePath,
ResolveLicenses: true,
ComponentType: string(cdx.ComponentTypeLibrary),
ModuleDir: fixturePath,
}

runSnapshotIT(t, &modOptions.OutputOptions, func() error { return modcmd.Exec(modOptions) })
Expand All @@ -54,12 +54,12 @@ func TestModCmdLocal(t *testing.T) {

modOptions := modcmd.ModOptions{
SBOMOptions: options.SBOMOptions{
Reproducible: true,
SerialNumber: zeroUUID.String(),
Reproducible: true,
ResolveLicenses: true,
SerialNumber: zeroUUID.String(),
},
ComponentType: string(cdx.ComponentTypeLibrary),
ModuleDir: filepath.Join(fixturePath, "local"),
ResolveLicenses: true,
ComponentType: string(cdx.ComponentTypeLibrary),
ModuleDir: filepath.Join(fixturePath, "local"),
}

runSnapshotIT(t, &modOptions.OutputOptions, func() error { return modcmd.Exec(modOptions) })
Expand All @@ -72,12 +72,12 @@ func TestModCmdNoDependencies(t *testing.T) {

modOptions := modcmd.ModOptions{
SBOMOptions: options.SBOMOptions{
Reproducible: true,
SerialNumber: zeroUUID.String(),
Reproducible: true,
ResolveLicenses: true,
SerialNumber: zeroUUID.String(),
},
ComponentType: string(cdx.ComponentTypeLibrary),
ModuleDir: fixturePath,
ResolveLicenses: true,
ComponentType: string(cdx.ComponentTypeLibrary),
ModuleDir: fixturePath,
}

runSnapshotIT(t, &modOptions.OutputOptions, func() error { return modcmd.Exec(modOptions) })
Expand All @@ -91,12 +91,12 @@ func TestModCmdVendored(t *testing.T) {

modOptions := modcmd.ModOptions{
SBOMOptions: options.SBOMOptions{
Reproducible: true,
SerialNumber: zeroUUID.String(),
Reproducible: true,
ResolveLicenses: true,
SerialNumber: zeroUUID.String(),
},
ComponentType: string(cdx.ComponentTypeLibrary),
ModuleDir: fixturePath,
ResolveLicenses: true,
ComponentType: string(cdx.ComponentTypeLibrary),
ModuleDir: fixturePath,
}

runSnapshotIT(t, &modOptions.OutputOptions, func() error { return modcmd.Exec(modOptions) })
Expand All @@ -118,12 +118,12 @@ func TestModCmdNested(t *testing.T) {

modOptions := modcmd.ModOptions{
SBOMOptions: options.SBOMOptions{
Reproducible: true,
SerialNumber: zeroUUID.String(),
Reproducible: true,
ResolveLicenses: true,
SerialNumber: zeroUUID.String(),
},
ComponentType: string(cdx.ComponentTypeLibrary),
ModuleDir: filepath.Join(fixturePath, "simple"),
ResolveLicenses: true,
ComponentType: string(cdx.ComponentTypeLibrary),
ModuleDir: filepath.Join(fixturePath, "simple"),
}

runSnapshotIT(t, &modOptions.OutputOptions, func() error { return modcmd.Exec(modOptions) })
Expand Down
7 changes: 7 additions & 0 deletions e2e/testdata/snapshots/TestBinCmdSimple
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@
<url>https:/google/uuid</url>
</reference>
</externalReferences>
<evidence>
<licenses>
<license>
<id>BSD-3-Clause</id>
</license>
</licenses>
</evidence>
</component>
</components>
<dependencies>
Expand Down
Loading