Skip to content

Commit

Permalink
pkg: replace utils/strings/InSlice func with slices.Contains (#413)
Browse files Browse the repository at this point in the history
Signed-off-by: Mohamed Awnallah <[email protected]>
Co-authored-by: knqyf263 <[email protected]>
  • Loading branch information
mohamedawnallah and knqyf263 committed Jul 1, 2024
1 parent ceb50ae commit 5d13607
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 20 deletions.
9 changes: 0 additions & 9 deletions pkg/utils/strings/strings.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,6 @@ func IsInt(s string) bool {
return err == nil
}

func InSlice(a string, list []string) bool {
for _, b := range list {
if b == a {
return true
}
}
return false
}

func Merge(a, b []string) []string {
uniq := map[string]struct{}{}
for _, v := range append(a, b...) {
Expand Down
4 changes: 2 additions & 2 deletions pkg/vulnsrc/amazon/amazon.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"io"
"log"
"path/filepath"
"slices"
"strings"

bolt "go.etcd.io/bbolt"
Expand All @@ -14,7 +15,6 @@ import (
"github.com/aquasecurity/trivy-db/pkg/db"
"github.com/aquasecurity/trivy-db/pkg/types"
"github.com/aquasecurity/trivy-db/pkg/utils"
ustrings "github.com/aquasecurity/trivy-db/pkg/utils/strings"
"github.com/aquasecurity/trivy-db/pkg/vulnsrc/vulnerability"
)

Expand Down Expand Up @@ -95,7 +95,7 @@ func (vs *VulnSrc) walkFunc(r io.Reader, path string) error {
return nil
}
version := paths[len(paths)-2]
if !ustrings.InSlice(version, targetVersions) {
if !slices.Contains(targetVersions, version) {
log.Printf("unsupported Amazon version: %s\n", version)
return nil
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/vulnsrc/debian/debian.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"log"
"os"
"path/filepath"
"slices"
"strings"

debver "github.com/knqyf263/go-deb-version"
Expand All @@ -16,7 +17,6 @@ import (
"github.com/aquasecurity/trivy-db/pkg/db"
"github.com/aquasecurity/trivy-db/pkg/types"
"github.com/aquasecurity/trivy-db/pkg/utils"
ustrings "github.com/aquasecurity/trivy-db/pkg/utils/strings"
"github.com/aquasecurity/trivy-db/pkg/vulnsrc/vulnerability"
)

Expand Down Expand Up @@ -204,7 +204,7 @@ func (vs VulnSrc) parseCVE(dir string) error {
}

// Skip not-affected, removed or undetermined advisories
if ustrings.InSlice(ann.Kind, skipStatuses) {
if slices.Contains(skipStatuses, ann.Kind) {
vs.notAffected[bkt] = struct{}{}
continue
}
Expand Down Expand Up @@ -310,7 +310,7 @@ func (vs VulnSrc) parseAdvisory(dir string) error {
}

// Skip not-affected, removed or undetermined advisories
if ustrings.InSlice(ann.Kind, skipStatuses) {
if slices.Contains(skipStatuses, ann.Kind) {
vs.notAffected[bkt] = struct{}{}
continue
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/vulnsrc/oracle-oval/oracle-oval.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"io"
"log"
"path/filepath"
"slices"
"strings"

version "github.com/knqyf263/go-rpm-version"
Expand Down Expand Up @@ -129,7 +130,7 @@ func (vs *VulnSrc) commit(tx *bolt.Tx, ovals []OracleOVAL) error {
}

platformName := affectedPkg.PlatformName()
if !ustrings.InSlice(platformName, targetPlatforms) {
if !slices.Contains(targetPlatforms, platformName) {
continue
}

Expand Down
5 changes: 2 additions & 3 deletions pkg/vulnsrc/rocky/rocky.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
"github.com/aquasecurity/trivy-db/pkg/db"
"github.com/aquasecurity/trivy-db/pkg/types"
"github.com/aquasecurity/trivy-db/pkg/utils"
ustrings "github.com/aquasecurity/trivy-db/pkg/utils/strings"
"github.com/aquasecurity/trivy-db/pkg/vulnsrc/vulnerability"
)

Expand Down Expand Up @@ -110,12 +109,12 @@ func (vs *VulnSrc) parse(rootDir string) (map[string][]RLSA, error) {
majorVer = dirs[0][:strings.Index(dirs[0], ".")]
}
repo, arch := dirs[1], dirs[2]
if !ustrings.InSlice(repo, targetRepos) {
if !slices.Contains(targetRepos, repo) {
log.Printf("Unsupported Rocky repo: %s", repo)
return nil
}

if !ustrings.InSlice(arch, targetArches) {
if !slices.Contains(targetArches, arch) {
log.Printf("Unsupported Rocky arch: %s", arch)
return nil
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/vulnsrc/ubuntu/ubuntu.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ import (
"io"
"log"
"path/filepath"
"slices"

bolt "go.etcd.io/bbolt"
"golang.org/x/xerrors"

"github.com/aquasecurity/trivy-db/pkg/db"
"github.com/aquasecurity/trivy-db/pkg/types"
"github.com/aquasecurity/trivy-db/pkg/utils"
"github.com/aquasecurity/trivy-db/pkg/utils/strings"
"github.com/aquasecurity/trivy-db/pkg/vulnsrc/vulnerability"
)

Expand Down Expand Up @@ -157,7 +157,7 @@ func defaultPut(dbc db.Operation, tx *bolt.Tx, advisory interface{}) error {
for packageName, patch := range cve.Patches {
pkgName := string(packageName)
for release, status := range patch {
if !strings.InSlice(status.Status, targetStatuses) {
if !slices.Contains(targetStatuses, status.Status) {
continue
}
osVersion, ok := UbuntuReleasesMapping[string(release)]
Expand Down

0 comments on commit 5d13607

Please sign in to comment.