Skip to content

Commit

Permalink
Merge pull request #22 from devtron-labs/invalid-json-fix
Browse files Browse the repository at this point in the history
Fix: scanning failed due to invalid json output.
  • Loading branch information
Shivam-nagar23 authored Dec 8, 2023
2 parents abb1e03 + 5f001aa commit 4cec7d9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
8 changes: 8 additions & 0 deletions common/bean.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package common
import (
"github.com/optiopay/klar/clair"
"github.com/quay/claircore"
"strings"
"time"
)

Expand Down Expand Up @@ -124,3 +125,10 @@ type SeverityCount struct {
Moderate int `json:"moderate"`
Low int `json:"low"`
}

func RemoveTrailingComma(jsonString string) string {
if strings.HasSuffix(jsonString, ",]") {
return jsonString[:len(jsonString)-2] + jsonString[len(jsonString)-1:]
}
return jsonString
}
1 change: 1 addition & 0 deletions pkg/security/ImageScanService.go
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,7 @@ func (impl *ImageScanServiceImpl) ConvertEndStepOutputAndSaveVulnerabilities(ste
impl.logger.Errorw("error in parsing template to get vulnerabilities", "err", err)
return err
}
renderedTemplate = common.RemoveTrailingComma(renderedTemplate)
var vulnerabilities []*bean.ImageScanOutputObject
err = json.Unmarshal([]byte(renderedTemplate), &vulnerabilities)
if err != nil {
Expand Down

0 comments on commit 4cec7d9

Please sign in to comment.