From a66d3fe3f034d020d3ce4e47baef4ce3a6f26ef8 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sun, 25 Dec 2022 12:39:26 +0200 Subject: [PATCH] chore(deps): bump github.com/hashicorp/golang-lru from 0.5.4 to 2.0.1 (#3265) Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: masahiro331 --- go.mod | 10 +++++----- go.sum | 20 ++++++++++---------- pkg/fanal/artifact/vm/ebs.go | 4 ++-- pkg/fanal/artifact/vm/file.go | 4 ++-- pkg/fanal/vm/disk/disk.go | 9 +++++---- pkg/fanal/vm/disk/disk_test.go | 2 +- pkg/fanal/vm/disk/vmdk.go | 2 +- pkg/fanal/vm/filesystem/ext4.go | 2 +- pkg/fanal/vm/filesystem/filesystem.go | 11 +++++------ pkg/fanal/vm/filesystem/xfs.go | 2 +- pkg/fanal/vm/vm.go | 6 +++--- 11 files changed, 36 insertions(+), 36 deletions(-) diff --git a/go.mod b/go.mod index e99a567c54..77113a84de 100644 --- a/go.mod +++ b/go.mod @@ -43,7 +43,7 @@ require ( github.com/google/uuid v1.3.0 github.com/google/wire v0.5.0 github.com/hashicorp/go-getter v1.6.2 - github.com/hashicorp/golang-lru v0.5.4 + github.com/hashicorp/golang-lru/v2 v2.0.1 github.com/in-toto/in-toto-golang v0.5.0 github.com/knqyf263/go-apk-version v0.0.0-20200609155635-041fdbb8563f github.com/knqyf263/go-deb-version v0.0.0-20190517075300-09fca494f03d @@ -51,11 +51,11 @@ require ( github.com/kylelemons/godebug v1.1.0 github.com/mailru/easyjson v0.7.7 github.com/masahiro331/go-disk v0.0.0-20220919035250-c8da316f91ac - github.com/masahiro331/go-ebs-file v0.0.0-20221125181850-09c63351e38c - github.com/masahiro331/go-ext4-filesystem v0.0.0-20221016160854-4b40d7ee6193 + github.com/masahiro331/go-ebs-file v0.0.0-20221225061409-5ef263bb2cc3 + github.com/masahiro331/go-ext4-filesystem v0.0.0-20221225060520-c150f5eacfe1 github.com/masahiro331/go-mvn-version v0.0.0-20210429150710-d3157d602a08 - github.com/masahiro331/go-vmdk-parser v0.0.0-20221124162251-5eeffd974e5a - github.com/masahiro331/go-xfs-filesystem v0.0.0-20221127135739-051c25f1becd + github.com/masahiro331/go-vmdk-parser v0.0.0-20221225061455-612096e4bbbd + github.com/masahiro331/go-xfs-filesystem v0.0.0-20221225060805-c02764233454 github.com/mitchellh/hashstructure/v2 v2.0.2 github.com/open-policy-agent/opa v0.44.1-0.20220927105354-00e835a7cc15 github.com/owenrumney/go-sarif/v2 v2.1.2 diff --git a/go.sum b/go.sum index 0782d53136..9fbf629ead 100644 --- a/go.sum +++ b/go.sum @@ -978,8 +978,8 @@ github.com/hashicorp/go-version v1.6.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09 github.com/hashicorp/go.net v0.0.1/go.mod h1:hjKkEWcCURg++eb33jQU7oqQcI9XDCnUzHA0oac0k90= github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= -github.com/hashicorp/golang-lru v0.5.4 h1:YDjusn29QI/Das2iO9M0BHnIbxPeyuCHsjMW+lJfyTc= -github.com/hashicorp/golang-lru v0.5.4/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uGBxy+E8yxSoD4= +github.com/hashicorp/golang-lru/v2 v2.0.1 h1:5pv5N1lT1fjLg2VQ5KWc7kmucp2x/kvFOnxuVTqZ6x4= +github.com/hashicorp/golang-lru/v2 v2.0.1/go.mod h1:QeFd9opnmA6QUJc5vARoKUSoFhyfM2/ZepoAG6RGpeM= github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4= github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= github.com/hashicorp/hcl/v2 v2.14.1 h1:x0BpjfZ+CYdbiz+8yZTQ+gdLO7IXvOut7Da+XJayx34= @@ -1125,16 +1125,16 @@ github.com/markbates/safe v1.0.1/go.mod h1:nAqgmRi7cY2nqMc92/bSEeQA+R4OheNU2T1kN github.com/marstr/guid v1.1.0/go.mod h1:74gB1z2wpxxInTG6yaqA7KrtM0NZ+RbrcqDvYHefzho= github.com/masahiro331/go-disk v0.0.0-20220919035250-c8da316f91ac h1:QyRucnGOLHJag1eB9CtuZwZk+/LpvTSYr5mnFLLFlgA= github.com/masahiro331/go-disk v0.0.0-20220919035250-c8da316f91ac/go.mod h1:J7Vb0sf0JzOhT0uHTeCqO6dqP/ELVcQvQ6yQ/56ZRGw= -github.com/masahiro331/go-ebs-file v0.0.0-20221125181850-09c63351e38c h1:sBVxQbdRxqMoczqQYPxUwe3V3msmAUj9KPuPZRpD13k= -github.com/masahiro331/go-ebs-file v0.0.0-20221125181850-09c63351e38c/go.mod h1:5NOkqebMwu8UiOTSjwqam1Ykdr7fci52TVE2xDQnIiM= -github.com/masahiro331/go-ext4-filesystem v0.0.0-20221016160854-4b40d7ee6193 h1:1005OfmUUdBL4540DpkovaDrV+lkiEda7Nb/t792LEg= -github.com/masahiro331/go-ext4-filesystem v0.0.0-20221016160854-4b40d7ee6193/go.mod h1:X08d9nmB+eg7Gj2XWAOkiG8lbMFbgGXPsDKEvkFwyF8= +github.com/masahiro331/go-ebs-file v0.0.0-20221225061409-5ef263bb2cc3 h1:CCX8exCYIPHrMKba1KDhM37PxC3/amBUZXH8yoJOAMQ= +github.com/masahiro331/go-ebs-file v0.0.0-20221225061409-5ef263bb2cc3/go.mod h1:5NOkqebMwu8UiOTSjwqam1Ykdr7fci52TVE2xDQnIiM= +github.com/masahiro331/go-ext4-filesystem v0.0.0-20221225060520-c150f5eacfe1 h1:GBZZSY8xEoAf76ZOlxqKi/OMufpZnTxpTf7ectT1eNM= +github.com/masahiro331/go-ext4-filesystem v0.0.0-20221225060520-c150f5eacfe1/go.mod h1:X08d9nmB+eg7Gj2XWAOkiG8lbMFbgGXPsDKEvkFwyF8= github.com/masahiro331/go-mvn-version v0.0.0-20210429150710-d3157d602a08 h1:AevUBW4cc99rAF8q8vmddIP8qd/0J5s/UyltGbp66dg= github.com/masahiro331/go-mvn-version v0.0.0-20210429150710-d3157d602a08/go.mod h1:JOkBRrE1HvgTyjk6diFtNGgr8XJMtIfiBzkL5krqzVk= -github.com/masahiro331/go-vmdk-parser v0.0.0-20221124162251-5eeffd974e5a h1:R2wjAgJt2IwTqKfSDc4mJ0SIz66lIslqmAjW/Dmi5fE= -github.com/masahiro331/go-vmdk-parser v0.0.0-20221124162251-5eeffd974e5a/go.mod h1:5f7mCJGW9cJb8SDn3z8qodGxpMCOo8d/2nls/tiwRrw= -github.com/masahiro331/go-xfs-filesystem v0.0.0-20221127135739-051c25f1becd h1:jOFGJ9IFmR9jbm06nZzSR9xdd5clVbRcK55yGNhqMYM= -github.com/masahiro331/go-xfs-filesystem v0.0.0-20221127135739-051c25f1becd/go.mod h1:QKBZqdn6teT0LK3QhAf3K6xakItd1LonOShOEC44idQ= +github.com/masahiro331/go-vmdk-parser v0.0.0-20221225061455-612096e4bbbd h1:Y30EzvuoVp97b0unb/GOFXzBUKRXZXUN2e0wYmvC+ic= +github.com/masahiro331/go-vmdk-parser v0.0.0-20221225061455-612096e4bbbd/go.mod h1:5f7mCJGW9cJb8SDn3z8qodGxpMCOo8d/2nls/tiwRrw= +github.com/masahiro331/go-xfs-filesystem v0.0.0-20221225060805-c02764233454 h1:XHFL/6QXvGlsBZ6xZvLPSsQW5QIzrOnNUKgkjRo7KWo= +github.com/masahiro331/go-xfs-filesystem v0.0.0-20221225060805-c02764233454/go.mod h1:QKBZqdn6teT0LK3QhAf3K6xakItd1LonOShOEC44idQ= github.com/matryer/is v1.2.0 h1:92UTHpy8CDwaJ08GqLDzhhuixiBUUD1p3AU6PHddz4A= github.com/matryer/is v1.2.0/go.mod h1:2fLPjFQM9rhQ15aVEtbuwhJinnOqrmgXPNdZsdwlWXA= github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU= diff --git a/pkg/fanal/artifact/vm/ebs.go b/pkg/fanal/artifact/vm/ebs.go index 2515c66e6c..3111a61efd 100644 --- a/pkg/fanal/artifact/vm/ebs.go +++ b/pkg/fanal/artifact/vm/ebs.go @@ -4,7 +4,7 @@ import ( "context" "io" - lru "github.com/hashicorp/golang-lru" + lru "github.com/hashicorp/golang-lru/v2" ebsfile "github.com/masahiro331/go-ebs-file" "golang.org/x/xerrors" @@ -77,7 +77,7 @@ func (a *EBS) Inspect(ctx context.Context) (types.ArtifactReference, error) { } func (a *EBS) openEBS(ctx context.Context) (*io.SectionReader, error) { - c, err := lru.New(storageEBSCacheSize) + c, err := lru.New[string, []byte](storageEBSCacheSize) if err != nil { return nil, xerrors.Errorf("lru cache error: %w", err) } diff --git a/pkg/fanal/artifact/vm/file.go b/pkg/fanal/artifact/vm/file.go index 262f3ac210..cecddf57e4 100644 --- a/pkg/fanal/artifact/vm/file.go +++ b/pkg/fanal/artifact/vm/file.go @@ -8,7 +8,7 @@ import ( "io" "os" - lru "github.com/hashicorp/golang-lru" + lru "github.com/hashicorp/golang-lru/v2" "github.com/opencontainers/go-digest" "golang.org/x/xerrors" @@ -38,7 +38,7 @@ func newFile(filePath string, storage Storage) (*ImageFile, error) { return nil, xerrors.Errorf("file open error: %w", err) } - c, err := lru.New(storageFILECacheSize) + c, err := lru.New[string, []byte](storageFILECacheSize) if err != nil { return nil, xerrors.Errorf("failed to create new lru cache: %w", err) } diff --git a/pkg/fanal/vm/disk/disk.go b/pkg/fanal/vm/disk/disk.go index ac07ca3613..bf39707e2e 100644 --- a/pkg/fanal/vm/disk/disk.go +++ b/pkg/fanal/vm/disk/disk.go @@ -17,12 +17,13 @@ var ( // Disk defines virtual machine disk images like VMDK, VDI and VHD. type Disk interface { - NewReader(rs io.ReadSeeker, cache vm.Cache) (*io.SectionReader, error) + NewReader(io.ReadSeeker, vm.Cache[string, []byte]) (*io.SectionReader, error) } -func New(rs io.ReadSeeker, cache vm.Cache) (*io.SectionReader, error) { - for _, disk := range vmDisks { - vreader, err := disk.NewReader(rs, cache) +func New(rs io.ReadSeeker, cache vm.Cache[string, []byte]) (*io.SectionReader, error) { + + for _, vmdisk := range vmDisks { + var vreader, err = vmdisk.NewReader(rs, cache) if err != nil { if errors.Is(err, vm.ErrInvalidSignature) { continue diff --git a/pkg/fanal/vm/disk/disk_test.go b/pkg/fanal/vm/disk/disk_test.go index 669b46e646..df6f906bf8 100644 --- a/pkg/fanal/vm/disk/disk_test.go +++ b/pkg/fanal/vm/disk/disk_test.go @@ -15,7 +15,7 @@ import ( func TestNew(t *testing.T) { type args struct { rs io.ReadSeeker - cache vm.Cache + cache vm.Cache[string, []byte] } tests := []struct { name string diff --git a/pkg/fanal/vm/disk/vmdk.go b/pkg/fanal/vm/disk/vmdk.go index 26861e249b..62bebecdac 100644 --- a/pkg/fanal/vm/disk/vmdk.go +++ b/pkg/fanal/vm/disk/vmdk.go @@ -12,7 +12,7 @@ import ( type VMDK struct{} -func (V VMDK) NewReader(rs io.ReadSeeker, cache vm.Cache) (*io.SectionReader, error) { +func (V VMDK) NewReader(rs io.ReadSeeker, cache vm.Cache[string, []byte]) (*io.SectionReader, error) { if _, err := rs.Seek(0, io.SeekStart); err != nil { return nil, xerrors.Errorf("seek error: %w", err) } diff --git a/pkg/fanal/vm/filesystem/ext4.go b/pkg/fanal/vm/filesystem/ext4.go index f9b20dfa0a..f247698845 100644 --- a/pkg/fanal/vm/filesystem/ext4.go +++ b/pkg/fanal/vm/filesystem/ext4.go @@ -12,7 +12,7 @@ import ( type EXT4 struct{} -func (e EXT4) New(sr io.SectionReader, cache vm.Cache) (fs.FS, error) { +func (e EXT4) New(sr io.SectionReader, cache vm.Cache[string, any]) (fs.FS, error) { _, err := sr.Seek(0, io.SeekStart) if err != nil { return nil, xerrors.Errorf("failed to seek offset error: %w", err) diff --git a/pkg/fanal/vm/filesystem/filesystem.go b/pkg/fanal/vm/filesystem/filesystem.go index 9ba23ad93f..ae77610579 100644 --- a/pkg/fanal/vm/filesystem/filesystem.go +++ b/pkg/fanal/vm/filesystem/filesystem.go @@ -5,7 +5,7 @@ import ( "io" "io/fs" - lru "github.com/hashicorp/golang-lru" + lru "github.com/hashicorp/golang-lru/v2" "golang.org/x/xerrors" "github.com/aquasecurity/trivy/pkg/fanal/vm" @@ -14,23 +14,22 @@ import ( const cacheSize = 2048 var ( - filesystems = []Filesystem{ + ErrInvalidHeader = xerrors.New("invalid Header error") + filesystems = []Filesystem{ EXT4{}, XFS{}, } - - ErrInvalidHeader = xerrors.New("invalid Header error") ) type Filesystem interface { - New(sr io.SectionReader, cache vm.Cache) (fs.FS, error) + New(io.SectionReader, vm.Cache[string, any]) (fs.FS, error) } func New(sr io.SectionReader) (fs.FS, func(), error) { var clean func() // Initialize LRU cache for filesystem walking - lruCache, err := lru.New(cacheSize) + lruCache, err := lru.New[string, any](cacheSize) if err != nil { return nil, clean, xerrors.Errorf("failed to create a LRU cache: %w", err) } diff --git a/pkg/fanal/vm/filesystem/xfs.go b/pkg/fanal/vm/filesystem/xfs.go index d7d57021d0..d1344e8463 100644 --- a/pkg/fanal/vm/filesystem/xfs.go +++ b/pkg/fanal/vm/filesystem/xfs.go @@ -12,7 +12,7 @@ import ( type XFS struct{} -func (x XFS) New(sr io.SectionReader, cache vm.Cache) (fs.FS, error) { +func (x XFS) New(sr io.SectionReader, cache vm.Cache[string, any]) (fs.FS, error) { _, err := sr.Seek(0, io.SeekStart) if err != nil { return nil, xerrors.Errorf("failed to seek offset error: %w", err) diff --git a/pkg/fanal/vm/vm.go b/pkg/fanal/vm/vm.go index 998588f3d9..bfb4142637 100644 --- a/pkg/fanal/vm/vm.go +++ b/pkg/fanal/vm/vm.go @@ -9,10 +9,10 @@ var ( ErrUnsupportedType = xerrors.New("unsupported type error") ) -type Cache interface { +type Cache[K comparable, V any] interface { // Add stores data in the cache - Add(key, value interface{}) bool + Add(key K, value V) (evicted bool) // Get returns key's value from the cache - Get(key interface{}) (value interface{}, ok bool) + Get(key K) (value V, ok bool) }