mirror of
https://github.com/aquasecurity/trivy.git
synced 2025-12-12 15:50:15 -08:00
chore: Fix linting issues in fanal
This commit is contained in:
@@ -91,6 +91,7 @@ func (a alpineCmdAnalyzer) fetchApkIndexArchive(targetOS types.OS) (*apkIndex, e
|
||||
return nil, xerrors.Errorf("failed to read APKINDEX archive file: %w", err)
|
||||
}
|
||||
} else {
|
||||
// nolint
|
||||
resp, err := http.Get(url)
|
||||
if err != nil {
|
||||
return nil, xerrors.Errorf("failed to fetch APKINDEX archive: %w", err)
|
||||
|
||||
@@ -5,9 +5,10 @@ import (
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
"github.com/aquasecurity/trivy/pkg/fanal/analyzer/config/helm"
|
||||
"golang.org/x/xerrors"
|
||||
|
||||
"github.com/aquasecurity/trivy/pkg/fanal/analyzer/config/helm"
|
||||
|
||||
"github.com/aquasecurity/trivy/pkg/fanal/analyzer"
|
||||
"github.com/aquasecurity/trivy/pkg/fanal/analyzer/config/dockerfile"
|
||||
"github.com/aquasecurity/trivy/pkg/fanal/analyzer/config/json"
|
||||
|
||||
@@ -11,10 +11,11 @@ import (
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
"golang.org/x/xerrors"
|
||||
|
||||
dio "github.com/aquasecurity/go-dep-parser/pkg/io"
|
||||
"github.com/aquasecurity/trivy/pkg/fanal/analyzer"
|
||||
"github.com/aquasecurity/trivy/pkg/fanal/types"
|
||||
"golang.org/x/xerrors"
|
||||
)
|
||||
|
||||
const version = 1
|
||||
|
||||
@@ -6,10 +6,11 @@ import (
|
||||
"regexp"
|
||||
"testing"
|
||||
|
||||
"github.com/aquasecurity/trivy/pkg/fanal/analyzer"
|
||||
"github.com/aquasecurity/trivy/pkg/fanal/types"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/aquasecurity/trivy/pkg/fanal/analyzer"
|
||||
"github.com/aquasecurity/trivy/pkg/fanal/types"
|
||||
)
|
||||
|
||||
func Test_helmConfigAnalyzer_Analyze(t *testing.T) {
|
||||
|
||||
@@ -5,10 +5,11 @@ import (
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"github.com/aquasecurity/trivy/pkg/fanal/types"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/aquasecurity/trivy/pkg/fanal/types"
|
||||
|
||||
"github.com/aquasecurity/trivy/pkg/fanal/analyzer"
|
||||
)
|
||||
|
||||
|
||||
@@ -5,10 +5,11 @@ import (
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/aquasecurity/trivy/pkg/fanal/analyzer"
|
||||
"github.com/aquasecurity/trivy/pkg/fanal/types"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/aquasecurity/trivy/pkg/fanal/analyzer"
|
||||
"github.com/aquasecurity/trivy/pkg/fanal/types"
|
||||
)
|
||||
|
||||
func Test_packagingAnalyzer_Analyze(t *testing.T) {
|
||||
|
||||
@@ -5,11 +5,12 @@ import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"golang.org/x/xerrors"
|
||||
|
||||
"github.com/aquasecurity/go-dep-parser/pkg/python/pip"
|
||||
"github.com/aquasecurity/trivy/pkg/fanal/analyzer"
|
||||
"github.com/aquasecurity/trivy/pkg/fanal/analyzer/language"
|
||||
"github.com/aquasecurity/trivy/pkg/fanal/types"
|
||||
"golang.org/x/xerrors"
|
||||
)
|
||||
|
||||
func init() {
|
||||
|
||||
@@ -6,11 +6,12 @@ import (
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
|
||||
"golang.org/x/xerrors"
|
||||
|
||||
"github.com/aquasecurity/go-dep-parser/pkg/ruby/gemspec"
|
||||
"github.com/aquasecurity/trivy/pkg/fanal/analyzer"
|
||||
"github.com/aquasecurity/trivy/pkg/fanal/analyzer/language"
|
||||
"github.com/aquasecurity/trivy/pkg/fanal/types"
|
||||
"golang.org/x/xerrors"
|
||||
)
|
||||
|
||||
func init() {
|
||||
|
||||
@@ -5,10 +5,11 @@ import (
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/aquasecurity/trivy/pkg/fanal/analyzer"
|
||||
"github.com/aquasecurity/trivy/pkg/fanal/types"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/aquasecurity/trivy/pkg/fanal/analyzer"
|
||||
"github.com/aquasecurity/trivy/pkg/fanal/types"
|
||||
)
|
||||
|
||||
func Test_gemspecLibraryAnalyzer_Analyze(t *testing.T) {
|
||||
|
||||
@@ -5,10 +5,11 @@ import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"github.com/aquasecurity/trivy/pkg/fanal/analyzer"
|
||||
aos "github.com/aquasecurity/trivy/pkg/fanal/analyzer/os"
|
||||
"github.com/aquasecurity/trivy/pkg/fanal/types"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestAlpineReleaseOSAnalyzer_Required(t *testing.T) {
|
||||
|
||||
@@ -5,9 +5,10 @@ import (
|
||||
"context"
|
||||
"os"
|
||||
|
||||
"golang.org/x/xerrors"
|
||||
|
||||
"github.com/aquasecurity/trivy/pkg/fanal/analyzer"
|
||||
aos "github.com/aquasecurity/trivy/pkg/fanal/analyzer/os"
|
||||
"golang.org/x/xerrors"
|
||||
|
||||
"github.com/aquasecurity/trivy/pkg/fanal/types"
|
||||
"github.com/aquasecurity/trivy/pkg/fanal/utils"
|
||||
|
||||
@@ -8,9 +8,10 @@ import (
|
||||
aos "github.com/aquasecurity/trivy/pkg/fanal/analyzer/os"
|
||||
"github.com/aquasecurity/trivy/pkg/fanal/types"
|
||||
|
||||
"github.com/aquasecurity/trivy/pkg/fanal/analyzer"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/aquasecurity/trivy/pkg/fanal/analyzer"
|
||||
)
|
||||
|
||||
func Test_debianOSAnalyzer_Analyze(t *testing.T) {
|
||||
|
||||
@@ -5,11 +5,12 @@ import (
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/aquasecurity/trivy/pkg/fanal/analyzer"
|
||||
aos "github.com/aquasecurity/trivy/pkg/fanal/analyzer/os"
|
||||
"github.com/aquasecurity/trivy/pkg/fanal/types"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func Test_marinerOSAnalyzer_Analyze(t *testing.T) {
|
||||
|
||||
@@ -8,10 +8,11 @@ import (
|
||||
|
||||
"github.com/aquasecurity/trivy/pkg/fanal/analyzer"
|
||||
|
||||
"golang.org/x/xerrors"
|
||||
|
||||
aos "github.com/aquasecurity/trivy/pkg/fanal/analyzer/os"
|
||||
"github.com/aquasecurity/trivy/pkg/fanal/types"
|
||||
"github.com/aquasecurity/trivy/pkg/fanal/utils"
|
||||
"golang.org/x/xerrors"
|
||||
)
|
||||
|
||||
const almaAnalyzerVersion = 1
|
||||
|
||||
@@ -5,10 +5,11 @@ import (
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/aquasecurity/trivy/pkg/fanal/analyzer"
|
||||
"github.com/aquasecurity/trivy/pkg/fanal/types"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/aquasecurity/trivy/pkg/fanal/analyzer"
|
||||
"github.com/aquasecurity/trivy/pkg/fanal/types"
|
||||
)
|
||||
|
||||
func Test_almaOSAnalyzer_Analyze(t *testing.T) {
|
||||
|
||||
@@ -8,10 +8,11 @@ import (
|
||||
|
||||
"github.com/aquasecurity/trivy/pkg/fanal/analyzer"
|
||||
|
||||
"golang.org/x/xerrors"
|
||||
|
||||
aos "github.com/aquasecurity/trivy/pkg/fanal/analyzer/os"
|
||||
"github.com/aquasecurity/trivy/pkg/fanal/types"
|
||||
"github.com/aquasecurity/trivy/pkg/fanal/utils"
|
||||
"golang.org/x/xerrors"
|
||||
)
|
||||
|
||||
const centosAnalyzerVersion = 1
|
||||
|
||||
@@ -5,10 +5,11 @@ import (
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/aquasecurity/trivy/pkg/fanal/analyzer"
|
||||
"github.com/aquasecurity/trivy/pkg/fanal/types"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/aquasecurity/trivy/pkg/fanal/analyzer"
|
||||
"github.com/aquasecurity/trivy/pkg/fanal/types"
|
||||
)
|
||||
|
||||
func Test_centosOSAnalyzer_Analyze(t *testing.T) {
|
||||
|
||||
@@ -8,10 +8,11 @@ import (
|
||||
|
||||
"github.com/aquasecurity/trivy/pkg/fanal/analyzer"
|
||||
|
||||
"golang.org/x/xerrors"
|
||||
|
||||
aos "github.com/aquasecurity/trivy/pkg/fanal/analyzer/os"
|
||||
"github.com/aquasecurity/trivy/pkg/fanal/types"
|
||||
"github.com/aquasecurity/trivy/pkg/fanal/utils"
|
||||
"golang.org/x/xerrors"
|
||||
)
|
||||
|
||||
const fedoraAnalyzerVersion = 1
|
||||
|
||||
@@ -5,10 +5,11 @@ import (
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/aquasecurity/trivy/pkg/fanal/analyzer"
|
||||
"github.com/aquasecurity/trivy/pkg/fanal/types"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/aquasecurity/trivy/pkg/fanal/analyzer"
|
||||
"github.com/aquasecurity/trivy/pkg/fanal/types"
|
||||
)
|
||||
|
||||
func Test_fedoraOSAnalyzer_Analyze(t *testing.T) {
|
||||
|
||||
@@ -10,9 +10,10 @@ import (
|
||||
|
||||
"github.com/aquasecurity/trivy/pkg/fanal/utils"
|
||||
|
||||
"golang.org/x/xerrors"
|
||||
|
||||
aos "github.com/aquasecurity/trivy/pkg/fanal/analyzer/os"
|
||||
"github.com/aquasecurity/trivy/pkg/fanal/types"
|
||||
"golang.org/x/xerrors"
|
||||
)
|
||||
|
||||
const oracleAnalyzerVersion = 1
|
||||
|
||||
@@ -5,10 +5,11 @@ import (
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/aquasecurity/trivy/pkg/fanal/analyzer"
|
||||
"github.com/aquasecurity/trivy/pkg/fanal/types"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/aquasecurity/trivy/pkg/fanal/analyzer"
|
||||
"github.com/aquasecurity/trivy/pkg/fanal/types"
|
||||
)
|
||||
|
||||
func Test_oracleOSAnalyzer_Analyze(t *testing.T) {
|
||||
|
||||
@@ -5,10 +5,11 @@ import (
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/aquasecurity/trivy/pkg/fanal/analyzer"
|
||||
"github.com/aquasecurity/trivy/pkg/fanal/types"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/aquasecurity/trivy/pkg/fanal/analyzer"
|
||||
"github.com/aquasecurity/trivy/pkg/fanal/types"
|
||||
)
|
||||
|
||||
func Test_redhatOSAnalyzer_Analyze(t *testing.T) {
|
||||
|
||||
@@ -8,10 +8,11 @@ import (
|
||||
|
||||
"github.com/aquasecurity/trivy/pkg/fanal/analyzer"
|
||||
|
||||
"golang.org/x/xerrors"
|
||||
|
||||
aos "github.com/aquasecurity/trivy/pkg/fanal/analyzer/os"
|
||||
"github.com/aquasecurity/trivy/pkg/fanal/types"
|
||||
"github.com/aquasecurity/trivy/pkg/fanal/utils"
|
||||
"golang.org/x/xerrors"
|
||||
)
|
||||
|
||||
const rockyAnalyzerVersion = 1
|
||||
|
||||
@@ -5,10 +5,11 @@ import (
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/aquasecurity/trivy/pkg/fanal/analyzer"
|
||||
"github.com/aquasecurity/trivy/pkg/fanal/types"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/aquasecurity/trivy/pkg/fanal/analyzer"
|
||||
"github.com/aquasecurity/trivy/pkg/fanal/types"
|
||||
)
|
||||
|
||||
func Test_rockyOSAnalyzer_Analyze(t *testing.T) {
|
||||
|
||||
@@ -7,9 +7,10 @@ import (
|
||||
|
||||
"github.com/aquasecurity/trivy/pkg/fanal/types"
|
||||
|
||||
"github.com/aquasecurity/trivy/pkg/fanal/analyzer"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/aquasecurity/trivy/pkg/fanal/analyzer"
|
||||
)
|
||||
|
||||
func Test_ubuntuOSAnalyzer_Analyze(t *testing.T) {
|
||||
|
||||
@@ -7,10 +7,11 @@ import (
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/aquasecurity/trivy/pkg/fanal/log"
|
||||
rpmdb "github.com/knqyf263/go-rpmdb/pkg"
|
||||
"golang.org/x/xerrors"
|
||||
|
||||
"github.com/aquasecurity/trivy/pkg/fanal/log"
|
||||
|
||||
"github.com/aquasecurity/trivy/pkg/fanal/analyzer"
|
||||
"github.com/aquasecurity/trivy/pkg/fanal/types"
|
||||
"github.com/aquasecurity/trivy/pkg/fanal/utils"
|
||||
|
||||
@@ -6,11 +6,12 @@ import (
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"golang.org/x/exp/slices"
|
||||
"golang.org/x/xerrors"
|
||||
|
||||
"github.com/aquasecurity/go-dep-parser/pkg/io"
|
||||
"github.com/aquasecurity/trivy/pkg/fanal/analyzer"
|
||||
"github.com/aquasecurity/trivy/pkg/fanal/types"
|
||||
"golang.org/x/exp/slices"
|
||||
"golang.org/x/xerrors"
|
||||
)
|
||||
|
||||
func init() {
|
||||
|
||||
@@ -4,8 +4,9 @@ import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/aquasecurity/trivy/pkg/fanal/types"
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"github.com/aquasecurity/trivy/pkg/fanal/types"
|
||||
)
|
||||
|
||||
func TestParseMarinerDistrolessManifest(t *testing.T) {
|
||||
|
||||
@@ -20,6 +20,7 @@ func init() {
|
||||
}
|
||||
|
||||
const version = 1
|
||||
const edgeVersion = "edge"
|
||||
|
||||
var (
|
||||
requiredFiles = []string{"etc/apk/repositories"}
|
||||
@@ -52,8 +53,8 @@ func (a apkRepoAnalyzer) Analyze(_ context.Context, input analyzer.AnalysisInput
|
||||
switch {
|
||||
case repoVer == "":
|
||||
repoVer = newVersion
|
||||
case repoVer == "edge" || newVersion == "edge":
|
||||
repoVer = "edge"
|
||||
case repoVer == edgeVersion || newVersion == edgeVersion:
|
||||
repoVer = edgeVersion
|
||||
default:
|
||||
oldVer, err := ver.Parse(repoVer)
|
||||
if err != nil {
|
||||
|
||||
@@ -5,10 +5,11 @@ import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"github.com/aquasecurity/trivy/pkg/fanal/analyzer"
|
||||
aos "github.com/aquasecurity/trivy/pkg/fanal/analyzer/os"
|
||||
"github.com/aquasecurity/trivy/pkg/fanal/types"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func Test_apkRepoAnalyzer_Analyze(t *testing.T) {
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
package applier
|
||||
|
||||
import (
|
||||
"golang.org/x/xerrors"
|
||||
|
||||
"github.com/aquasecurity/trivy/pkg/fanal/analyzer"
|
||||
"github.com/aquasecurity/trivy/pkg/fanal/cache"
|
||||
"github.com/aquasecurity/trivy/pkg/fanal/types"
|
||||
"golang.org/x/xerrors"
|
||||
)
|
||||
|
||||
type Applier struct {
|
||||
@@ -18,7 +19,7 @@ func NewApplier(c cache.LocalArtifactCache) Applier {
|
||||
func (a Applier) ApplyLayers(imageID string, layerKeys []string) (types.ArtifactDetail, error) {
|
||||
var layers []types.BlobInfo
|
||||
for _, key := range layerKeys {
|
||||
blob, _ := a.cache.GetBlob(key)
|
||||
blob, _ := a.cache.GetBlob(key) // nolint
|
||||
if blob.SchemaVersion == 0 {
|
||||
return types.ArtifactDetail{}, xerrors.Errorf("layer cache missing: %s", key)
|
||||
}
|
||||
@@ -32,7 +33,7 @@ func (a Applier) ApplyLayers(imageID string, layerKeys []string) (types.Artifact
|
||||
return mergedLayer, analyzer.ErrNoPkgsDetected // send back package and apps info regardless
|
||||
}
|
||||
|
||||
imageInfo, _ := a.cache.GetArtifact(imageID)
|
||||
imageInfo, _ := a.cache.GetArtifact(imageID) // nolint
|
||||
mergedLayer.HistoryPackages = imageInfo.HistoryPackages
|
||||
|
||||
return mergedLayer, nil
|
||||
|
||||
@@ -5,8 +5,9 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/aquasecurity/trivy/pkg/fanal/types"
|
||||
"github.com/knqyf263/nested"
|
||||
|
||||
"github.com/aquasecurity/trivy/pkg/fanal/types"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
@@ -89,11 +90,11 @@ func ApplyLayers(layers []types.BlobInfo) types.ArtifactDetail {
|
||||
|
||||
for _, layer := range layers {
|
||||
for _, opqDir := range layer.OpaqueDirs {
|
||||
opqDir = strings.TrimSuffix(opqDir, sep) //this is necessary so that an empty element is not contribute into the array of the DeleteByString function
|
||||
_ = nestedMap.DeleteByString(opqDir, sep)
|
||||
opqDir = strings.TrimSuffix(opqDir, sep) //this is necessary so that an empty element is not contribute into the array of the DeleteByString function
|
||||
_ = nestedMap.DeleteByString(opqDir, sep) // nolint
|
||||
}
|
||||
for _, whFile := range layer.WhiteoutFiles {
|
||||
_ = nestedMap.DeleteByString(whFile, sep)
|
||||
_ = nestedMap.DeleteByString(whFile, sep) // nolint
|
||||
}
|
||||
|
||||
if layer.OS != nil {
|
||||
@@ -138,6 +139,7 @@ func ApplyLayers(layers []types.BlobInfo) types.ArtifactDetail {
|
||||
}
|
||||
}
|
||||
|
||||
// nolint
|
||||
_ = nestedMap.Walk(func(keys []string, value interface{}) error {
|
||||
switch v := value.(type) {
|
||||
case types.PackageInfo:
|
||||
|
||||
@@ -5,8 +5,9 @@ package artifact
|
||||
import (
|
||||
context "context"
|
||||
|
||||
types "github.com/aquasecurity/trivy/pkg/fanal/types"
|
||||
mock "github.com/stretchr/testify/mock"
|
||||
|
||||
types "github.com/aquasecurity/trivy/pkg/fanal/types"
|
||||
)
|
||||
|
||||
// MockArtifact is an autogenerated mock type for the Artifact type
|
||||
|
||||
3
pkg/fanal/cache/mock_artifact_cache.go
vendored
3
pkg/fanal/cache/mock_artifact_cache.go
vendored
@@ -3,8 +3,9 @@
|
||||
package cache
|
||||
|
||||
import (
|
||||
types "github.com/aquasecurity/trivy/pkg/fanal/types"
|
||||
mock "github.com/stretchr/testify/mock"
|
||||
|
||||
types "github.com/aquasecurity/trivy/pkg/fanal/types"
|
||||
)
|
||||
|
||||
// MockArtifactCache is an autogenerated mock type for the ArtifactCache type
|
||||
|
||||
3
pkg/fanal/cache/mock_cache.go
vendored
3
pkg/fanal/cache/mock_cache.go
vendored
@@ -3,8 +3,9 @@
|
||||
package cache
|
||||
|
||||
import (
|
||||
types "github.com/aquasecurity/trivy/pkg/fanal/types"
|
||||
mock "github.com/stretchr/testify/mock"
|
||||
|
||||
types "github.com/aquasecurity/trivy/pkg/fanal/types"
|
||||
)
|
||||
|
||||
// MockCache is an autogenerated mock type for the Cache type
|
||||
|
||||
3
pkg/fanal/cache/mock_local_artifact_cache.go
vendored
3
pkg/fanal/cache/mock_local_artifact_cache.go
vendored
@@ -3,8 +3,9 @@
|
||||
package cache
|
||||
|
||||
import (
|
||||
types "github.com/aquasecurity/trivy/pkg/fanal/types"
|
||||
mock "github.com/stretchr/testify/mock"
|
||||
|
||||
types "github.com/aquasecurity/trivy/pkg/fanal/types"
|
||||
)
|
||||
|
||||
// MockLocalArtifactCache is an autogenerated mock type for the LocalArtifactCache type
|
||||
|
||||
3
pkg/fanal/cache/s3_test.go
vendored
3
pkg/fanal/cache/s3_test.go
vendored
@@ -6,11 +6,12 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/aquasecurity/trivy/pkg/fanal/types"
|
||||
"github.com/aws/aws-sdk-go/service/s3"
|
||||
"github.com/aws/aws-sdk-go/service/s3/s3iface"
|
||||
"github.com/aws/aws-sdk-go/service/s3/s3manager"
|
||||
"golang.org/x/xerrors"
|
||||
|
||||
"github.com/aquasecurity/trivy/pkg/fanal/types"
|
||||
)
|
||||
|
||||
type mockS3Client struct {
|
||||
|
||||
@@ -41,7 +41,8 @@ func (h gomodMergeHook) Handle(_ context.Context, _ *analyzer.AnalysisResult, bl
|
||||
// e.g. /app/go.mod => /app/go.sum
|
||||
gosumFile := filepath.Join(dir, types.GoSum)
|
||||
if gosum := findGoSum(gosumFile, blob.Applications); gosum != nil {
|
||||
mergeGoSum(&app, gosum)
|
||||
application := app
|
||||
mergeGoSum(&application, gosum)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
package image
|
||||
|
||||
import (
|
||||
"github.com/aquasecurity/trivy/pkg/fanal/types"
|
||||
v1 "github.com/google/go-containerregistry/pkg/v1"
|
||||
"github.com/hashicorp/go-multierror"
|
||||
|
||||
"github.com/aquasecurity/trivy/pkg/fanal/types"
|
||||
)
|
||||
|
||||
func NewArchiveImage(fileName string) (types.Image, error) {
|
||||
|
||||
@@ -20,7 +20,7 @@ func DockerImage(ref name.Reference) (Image, func(), error) {
|
||||
}
|
||||
defer func() {
|
||||
if err != nil {
|
||||
c.Close()
|
||||
_ = c.Close()
|
||||
}
|
||||
}()
|
||||
|
||||
@@ -48,8 +48,8 @@ func DockerImage(ref name.Reference) (Image, func(), error) {
|
||||
}
|
||||
|
||||
cleanup = func() {
|
||||
c.Close()
|
||||
f.Close()
|
||||
_ = c.Close()
|
||||
_ = f.Close()
|
||||
_ = os.Remove(f.Name())
|
||||
}
|
||||
|
||||
|
||||
@@ -7,10 +7,11 @@ import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
|
||||
"github.com/aquasecurity/trivy/pkg/fanal/utils"
|
||||
v1 "github.com/google/go-containerregistry/pkg/v1"
|
||||
"github.com/google/go-containerregistry/pkg/v1/tarball"
|
||||
"golang.org/x/xerrors"
|
||||
|
||||
"github.com/aquasecurity/trivy/pkg/fanal/utils"
|
||||
)
|
||||
|
||||
func tryDockerArchive(fileName string) (v1.Image, error) {
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
package image
|
||||
|
||||
import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestTryOCI(t *testing.T) {
|
||||
|
||||
@@ -4,9 +4,10 @@ import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/aquasecurity/trivy/pkg/fanal/types"
|
||||
"golang.org/x/xerrors"
|
||||
|
||||
"github.com/aquasecurity/trivy/pkg/fanal/types"
|
||||
|
||||
"github.com/aws/aws-sdk-go/aws/request"
|
||||
|
||||
"github.com/aws/aws-sdk-go/aws"
|
||||
|
||||
@@ -6,8 +6,9 @@ import (
|
||||
|
||||
"github.com/google/go-containerregistry/pkg/authn"
|
||||
|
||||
"github.com/aquasecurity/trivy/pkg/fanal/types"
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"github.com/aquasecurity/trivy/pkg/fanal/types"
|
||||
)
|
||||
|
||||
func TestGetToken(t *testing.T) {
|
||||
|
||||
@@ -7,8 +7,9 @@ import (
|
||||
var Logger *zap.SugaredLogger
|
||||
|
||||
func init() {
|
||||
logger, _ := zap.NewProduction()
|
||||
Logger = logger.Sugar()
|
||||
if logger, err := zap.NewProduction(); err == nil {
|
||||
Logger = logger.Sugar()
|
||||
}
|
||||
}
|
||||
|
||||
func SetLogger(l *zap.SugaredLogger) {
|
||||
|
||||
@@ -13,12 +13,13 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
_ "github.com/aquasecurity/trivy/pkg/fanal/analyzer/all"
|
||||
"github.com/aquasecurity/trivy/pkg/fanal/cache"
|
||||
"github.com/aquasecurity/trivy/pkg/fanal/types"
|
||||
dtypes "github.com/docker/docker/api/types"
|
||||
"github.com/docker/docker/client"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
_ "github.com/aquasecurity/trivy/pkg/fanal/analyzer/all"
|
||||
"github.com/aquasecurity/trivy/pkg/fanal/cache"
|
||||
"github.com/aquasecurity/trivy/pkg/fanal/types"
|
||||
)
|
||||
|
||||
type testCase struct {
|
||||
|
||||
@@ -15,6 +15,11 @@ import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
dtypes "github.com/docker/docker/api/types"
|
||||
"github.com/docker/docker/client"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
_ "github.com/aquasecurity/trivy/pkg/fanal/analyzer/all"
|
||||
"github.com/aquasecurity/trivy/pkg/fanal/applier"
|
||||
"github.com/aquasecurity/trivy/pkg/fanal/artifact"
|
||||
@@ -23,10 +28,6 @@ import (
|
||||
_ "github.com/aquasecurity/trivy/pkg/fanal/handler/all"
|
||||
"github.com/aquasecurity/trivy/pkg/fanal/image"
|
||||
"github.com/aquasecurity/trivy/pkg/fanal/types"
|
||||
dtypes "github.com/docker/docker/api/types"
|
||||
"github.com/docker/docker/client"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
var update = flag.Bool("update", false, "update golden files")
|
||||
|
||||
@@ -36,7 +36,6 @@ func IsCommandAvailable(name string) bool {
|
||||
}
|
||||
|
||||
func IsGzip(f *bufio.Reader) bool {
|
||||
buf := make([]byte, 3)
|
||||
buf, err := f.Peek(3)
|
||||
if err != nil {
|
||||
return false
|
||||
|
||||
@@ -86,7 +86,10 @@ func (w LayerTar) Walk(layer io.Reader, analyzeFn WalkFunc) ([]string, []string,
|
||||
|
||||
func (w LayerTar) processFile(filePath string, tr *tar.Reader, fi fs.FileInfo, analyzeFn WalkFunc) error {
|
||||
tf := newTarFile(fi.Size(), tr)
|
||||
defer tf.Clean()
|
||||
defer func() {
|
||||
// nolint
|
||||
_ = tf.Clean()
|
||||
}()
|
||||
|
||||
if err := analyzeFn(filePath, fi, tf.Open); err != nil {
|
||||
return xerrors.Errorf("failed to analyze file: %w", err)
|
||||
|
||||
@@ -10,8 +10,9 @@ import (
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"github.com/aquasecurity/trivy/pkg/fanal/walker"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/aquasecurity/trivy/pkg/fanal/walker"
|
||||
)
|
||||
|
||||
func TestLayerTar_Walk(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user