Skip to content

Commit

Permalink
Merge pull request #70 from easy-up/main
Browse files Browse the repository at this point in the history
fix: crash bug when adding a bundle file with no tag
  • Loading branch information
BacchusJackson authored Dec 11, 2024
2 parents 010a2e4 + bc048e0 commit b0d7a99
Show file tree
Hide file tree
Showing 16 changed files with 306 additions and 74 deletions.
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,22 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [UNRELEASED]

## [0.8.0] - 2024-10-23

* Fixed a bug where validation failures were not resulting in a non-zero exit code
* Renamed the --file / -f CLI argument to --config / -f for consistency with other tools
* improvements to validate output
These "improvements" are short term hacks. There is a need for a fundamental
overhaul of how output is generated to improve usability
* Implemented code coverage support.
* Updated the docs to reflect the removal of the --all flag

## [0.7.6] - 2024-09-08

### Fixed

- Crash when running `gatecheck bundle add` with no tags

## [0.7.5] - 2024-06-18

### Fixed
Expand Down
4 changes: 2 additions & 2 deletions cmd/cli-config.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ var RuntimeConfig = metaConfig{
BundleTag: configkit.MetaField{
FieldName: "BundleTag",
EnvKey: "GATECHECK_BUNDLE_TAG",
DefaultValue: "",
DefaultValue: []string{},
FlagValueP: new([]string),
EnvToValueFunc: func(s string) any {
return strings.Split(s, ",")
Expand Down Expand Up @@ -165,7 +165,7 @@ var RuntimeConfig = metaConfig{
CobraSetupFunc: func(f configkit.MetaField, cmd *cobra.Command) {
valueP := f.FlagValueP.(*string)
usage := f.Metadata[metadataFlagUsage]
cmd.PersistentFlags().StringVarP(valueP, "file", "f", "", usage)
cmd.PersistentFlags().StringVarP(valueP, "config", "f", "", usage)
},
Metadata: map[string]string{
metadataFlagUsage: "a validation configuration file",
Expand Down
2 changes: 1 addition & 1 deletion cmd/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ var validateCmd = &cobra.Command{
return nil
}

return nil
return err
},
}

Expand Down
2 changes: 1 addition & 1 deletion demos/bundle.tape
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Set Width 1800

Output dist/gatecheck-bundle.gif

Type "gatecheck ls --all grype-report.json | less"
Type "gatecheck ls grype-report.json | less"
Sleep 1
Enter
Sleep 5
Expand Down
2 changes: 1 addition & 1 deletion demos/list.tape
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Set Width 1600

Output dist/gatecheck-list.gif

Type "grype ubuntu:latest -o json | gatecheck ls --all -i grype | less"
Type "grype ubuntu:latest -o json | gatecheck ls -i grype | less"
Sleep 1
Enter

Expand Down
2 changes: 1 addition & 1 deletion demos/validate.tape
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Set Width 1700

Output dist/gatecheck-validate.gif

Type "gatecheck ls --all grype-report.json | less"
Type "gatecheck ls grype-report.json | less"
Sleep 1
Enter
Sleep 5
Expand Down
Binary file removed docs/assets/screenshot-grype-list-all.png
Binary file not shown.
8 changes: 0 additions & 8 deletions docs/list-reports.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,3 @@ gatecheck ls grype-scan-report.json
```

![Screenshot Example List](assets/screenshot-grype-list.png)

Using the `--all` or `-a` flag will do a full listing, cross-referencing with FIRST EPSS API

```shell
grype bkimminich/juice-shop:latest -o json | gatecheck ls --all -i grype
```

![Screenshot Example List All](assets/screenshot-grype-list-all.png)
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ require (
)

require (
github.com/easy-up/go-coverage v0.0.0-20241018034313-3de592d59a78 // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY=
github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto=
github.com/easy-up/go-coverage v0.0.0-20241018034313-3de592d59a78 h1:e2x+TfIgebN3zfr8wGqAYI9lK4ql7Rut6OTEhBmJr5k=
github.com/easy-up/go-coverage v0.0.0-20241018034313-3de592d59a78/go.mod h1:fsSINOc273zPnsBaKNjNffZXZpicAArpv/cTiFYgPys=
github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8=
github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0=
github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA=
Expand Down
6 changes: 5 additions & 1 deletion pkg/archive/bundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"encoding/json"
"errors"
"fmt"
"github.com/olekukonko/tablewriter"
"io"
"log/slog"
"os"
Expand Down Expand Up @@ -159,7 +160,10 @@ func (b *Bundle) Content() string {
sort.Sort(matrix)
buf := new(bytes.Buffer)
header := []string{"Label", "Digest", "Tags", "Size"}
matrix.Table(buf, header).Render()
table := tablewriter.NewWriter(buf)
table.SetHeader(header)
matrix.Table(table)
table.Render()
return buf.String()
}

Expand Down
42 changes: 42 additions & 0 deletions pkg/artifacts/lcov.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package artifacts

import (
"errors"
"github.com/easy-up/go-coverage"
"log/slog"
"strings"
)

func example() (coverage.Report, error) {
lcovParser := coverage.New(coverage.LCOV)
report, err := lcovParser.Parse("./path/to/lcov.info")
if err != nil {
// Handle error
return coverage.Report{}, err
}
// Use the parsed report
return report, nil
}

func IsCoverageReport(inputFilename string) bool {
return strings.Contains(inputFilename, "lcov") ||
strings.HasSuffix(inputFilename, ".info") ||
strings.Contains(inputFilename, "clover") ||
strings.Contains(inputFilename, "cobertura") ||
strings.Contains(inputFilename, "coverage")
}

func GetCoverageMode(inputFilename string) (coverage.CoverageMode, error) {
var coverageFormat coverage.CoverageMode
if strings.Contains(inputFilename, "lcov") || strings.HasSuffix(inputFilename, ".info") {
coverageFormat = coverage.LCOV
} else if strings.Contains(inputFilename, "clover") {
coverageFormat = coverage.CLOVER
} else if strings.HasSuffix(inputFilename, ".xml") {
coverageFormat = coverage.COBERTURA
} else {
slog.Error("unsupported coverage file type, cannot be determined from filename", "filename", inputFilename)
return "", errors.New("failed to list coverage content")
}
return coverageFormat, nil
}
7 changes: 1 addition & 6 deletions pkg/format/matrix.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package format

import (
"io"

"github.com/olekukonko/tablewriter"
)

Expand All @@ -28,11 +26,8 @@ func (m *SortableMatrix) Matrix() [][]string {
return m.data
}

func (m *SortableMatrix) Table(w io.Writer, header []string) *tablewriter.Table {
table := tablewriter.NewWriter(w)
table.SetHeader(header)
func (m *SortableMatrix) Table(table *tablewriter.Table) {
table.AppendBulk(m.data)
return table
}

func (m *SortableMatrix) Len() int {
Expand Down
12 changes: 12 additions & 0 deletions pkg/gatecheck/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ type Config struct {
Cyclonedx reportWithCVEs `json:"cyclonedx" toml:"cyclonedx" yaml:"cyclonedx"`
Semgrep configSemgrepReport `json:"semgrep" toml:"semgrep" yaml:"semgrep"`
Gitleaks configGitleaksReport `json:"gitleaks" toml:"gitleaks" yaml:"gitleaks"`
Coverage configCoverageReport `json:"coverage" toml:"coverage" yaml:"coverage"`
}

func (c *Config) String() string {
Expand All @@ -48,6 +49,12 @@ func (c *Config) String() string {
return contentBuf.String()
}

type configCoverageReport struct {
LineThreshold float32 `json:"lineThreshold" toml:"lineThreshold" yaml:"lineThreshold"`
FunctionThreshold float32 `json:"functionThreshold" toml:"functionThreshold" yaml:"functionThreshold"`
BranchThreshold float32 `json:"branchThreshold" toml:"branchThreshold" yaml:"branchThreshold"`
}

type configGitleaksReport struct {
LimitEnabled bool `json:"limitEnabled" toml:"limitEnabled" yaml:"limitEnabled"`
}
Expand Down Expand Up @@ -225,6 +232,11 @@ func NewDefaultConfig() *Config {
Gitleaks: configGitleaksReport{
LimitEnabled: false,
},
Coverage: configCoverageReport{
LineThreshold: 0,
FunctionThreshold: 0,
BranchThreshold: 0,
},
}
}

Expand Down
Loading

0 comments on commit b0d7a99

Please sign in to comment.