chore: fix gosimple issues
Signed-off-by: Yves Brissaud <yves.brissaud@docker.com>
This commit is contained in:
Родитель
7fcd084fe3
Коммит
66cf5ccc26
|
@ -102,6 +102,6 @@ func Cves(cve string, cves *[]types.Cve, sb *types.Sbom, remediate bool, dockerC
|
|||
Remediation(remediation)
|
||||
}
|
||||
} else {
|
||||
fmt.Println(fmt.Sprintf("%s not detected", cve))
|
||||
fmt.Printf("%s not detected\n", cve)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -174,19 +174,19 @@ func Cve(sb *types.Sbom, c *types.Cve) {
|
|||
sourceId = c.Cve.SourceId
|
||||
}
|
||||
fmt.Println("")
|
||||
fmt.Println(defaultColors.underline.Sprintf(fmt.Sprintf("Detected %s %s", sourceId, ColorizeSeverity(ToSeverity(*c)))))
|
||||
fmt.Println(fmt.Sprintf("https://dso.docker.com/cve/%s", sourceId))
|
||||
defaultColors.underline.Printf("Detected %s %s\n", sourceId, ColorizeSeverity(ToSeverity(*c)))
|
||||
fmt.Printf("https://dso.docker.com/cve/%s\n", sourceId)
|
||||
fmt.Println("")
|
||||
purl := c.Purl
|
||||
for _, p := range sb.Artifacts {
|
||||
if p.Purl == purl {
|
||||
fmt.Println(defaultColors.cyan.Sprintf(p.Purl))
|
||||
defaultColors.cyan.Println(p.Purl)
|
||||
loc := p.Locations[0]
|
||||
for i, l := range sb.Source.Image.Config.RootFS.DiffIDs {
|
||||
if l.String() == loc.DiffId {
|
||||
h := sb.Source.Image.Config.History[i]
|
||||
fmt.Println(formatCreatedBy(h.CreatedBy))
|
||||
fmt.Println(fmt.Sprintf("%d: %s", i, loc.Digest))
|
||||
fmt.Printf("%d: %s\n", i, loc.Digest)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -196,9 +196,9 @@ func Cve(sb *types.Sbom, c *types.Cve) {
|
|||
func Remediation(remediation []string) {
|
||||
if len(remediation) > 0 {
|
||||
fmt.Println("")
|
||||
fmt.Println(defaultColors.underline.Sprintf("Suggested remediation"))
|
||||
defaultColors.underline.Println("Suggested remediation")
|
||||
for i, r := range remediation {
|
||||
fmt.Println(fmt.Sprintf("\n%d. %s", i+1, r))
|
||||
fmt.Printf("\n%d. %s\n", i+1, r)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -295,7 +295,7 @@ func ForImageInGraphQL(sb *types.Sbom) (*types.ImageByDigestQuery, error) {
|
|||
}
|
||||
|
||||
func normalizeRepository(image *types.BaseImage) *types.BaseImage {
|
||||
if image.Repository.Host == "hub.docker.com" && strings.Index(image.Repository.Repo, "/") < 0 {
|
||||
if image.Repository.Host == "hub.docker.com" && strings.Contains(image.Repository.Repo, "/") {
|
||||
image.Repository.Badge = "OFFICIAL"
|
||||
}
|
||||
if image.Repository.Badge != "" {
|
||||
|
|
|
@ -111,7 +111,7 @@ func (c *ImageCache) StoreImage() error {
|
|||
spinner.Stop()
|
||||
} else if format == "tar" {
|
||||
if c.remote {
|
||||
u := make(chan v1.Update, 0)
|
||||
u := make(chan v1.Update)
|
||||
errchan := make(chan error)
|
||||
go func() {
|
||||
if err := tarball.WriteToFile(c.ImagePath, *c.Ref, *c.Image, tarball.WithProgress(u)); err != nil {
|
||||
|
|
|
@ -23,7 +23,7 @@ import (
|
|||
)
|
||||
|
||||
func nodePackageDetector() PackageDetector {
|
||||
expr := regexp.MustCompile("node\\.js/v(.*)")
|
||||
expr := regexp.MustCompile(`node\.js/v(.*)`)
|
||||
pkg := types.Package{
|
||||
Type: "github",
|
||||
Namespace: "nodejs",
|
||||
|
|
|
@ -100,12 +100,8 @@ func toPackageName(pkg packageurl.PackageURL) string {
|
|||
|
||||
func toImageName(result ImageIndexResult) string {
|
||||
imageName := result.Sbom.Source.Image.Name
|
||||
if strings.HasPrefix(imageName, "index.docker.io/") {
|
||||
imageName = imageName[len("index.docker.io/"):]
|
||||
}
|
||||
if strings.HasPrefix(imageName, "library/") {
|
||||
imageName = imageName[len("library/"):]
|
||||
}
|
||||
imageName = strings.TrimPrefix(imageName, "index.docker.io/")
|
||||
imageName = strings.TrimPrefix(imageName, "library/")
|
||||
return imageName
|
||||
}
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@ func init() {
|
|||
}
|
||||
|
||||
func WatchImages(cli command.Cli) error {
|
||||
indexJobs := make(chan types.ImageSummary, 0)
|
||||
indexJobs := make(chan types.ImageSummary)
|
||||
for w := 1; w <= maxIndexWorkers; w++ {
|
||||
go indexImageWorker(cli, indexJobs)
|
||||
}
|
||||
|
|
|
@ -326,9 +326,7 @@ func parseReference(sb *types.Sbom) (string, string, error) {
|
|||
host = "hub.docker.com"
|
||||
}
|
||||
name := ref.Context().RepositoryStr()
|
||||
if strings.HasPrefix(name, "library/") {
|
||||
name = name[len("library/"):]
|
||||
}
|
||||
name = strings.TrimPrefix(name, "library/")
|
||||
return host, name, nil
|
||||
}
|
||||
|
||||
|
|
|
@ -41,10 +41,8 @@ func NormalizePackages(pkgs []Package) ([]Package, error) {
|
|||
}
|
||||
purl.Namespace = toNamespace(purl)
|
||||
|
||||
// some versions strings (e.g. such of Go) have a v prefix that we drop
|
||||
if strings.HasPrefix(purl.Version, "v") {
|
||||
purl.Version = purl.Version[1:]
|
||||
}
|
||||
// some version strings (e.g. such of Go) have a v prefix that we drop
|
||||
purl.Version = strings.TrimPrefix(purl.Version, "v")
|
||||
if purl.Version == "" {
|
||||
purl.Version = "0.0.0"
|
||||
}
|
||||
|
@ -94,9 +92,7 @@ func NormalizePackages(pkgs []Package) ([]Package, error) {
|
|||
}
|
||||
|
||||
func ToPackageUrl(url string) (packageurl.PackageURL, error) {
|
||||
if strings.HasSuffix(url, "/") {
|
||||
url = url[0 : len(url)-1]
|
||||
}
|
||||
url = strings.TrimSuffix(url, "/")
|
||||
purl, err := packageurl.FromString(url)
|
||||
return purl, err
|
||||
}
|
||||
|
|
|
@ -80,13 +80,8 @@ type Image struct {
|
|||
}
|
||||
|
||||
func ImageTags(image *Image) []string {
|
||||
tags := make([]string, 0)
|
||||
for _, tag := range image.Tags {
|
||||
tags = append(tags, tag)
|
||||
}
|
||||
sort.Slice(tags, func(i, j int) bool {
|
||||
return len(tags[i]) < len(tags[j])
|
||||
})
|
||||
tags := append([]string{}, image.Tags...)
|
||||
sort.Strings(tags)
|
||||
return tags
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче