mirror of
https://github.com/aquasecurity/trivy.git
synced 2025-12-05 20:40:16 -08:00
refactor: migrate from go-json-experiment to encoding/json/v2 (#9422)
Co-authored-by: knqyf263 <knqyf263@users.noreply.github.com> Co-authored-by: nikpivkin <nikita.pivkin@smartforce.io>
This commit is contained in:
4
.github/workflows/cache-test-assets.yaml
vendored
4
.github/workflows/cache-test-assets.yaml
vendored
@@ -92,5 +92,7 @@ jobs:
|
|||||||
- name: Run golangci-lint for caching
|
- name: Run golangci-lint for caching
|
||||||
uses: golangci/golangci-lint-action@4afd733a84b1f43292c63897423277bb7f4313a9 # v8.0.0
|
uses: golangci/golangci-lint-action@4afd733a84b1f43292c63897423277bb7f4313a9 # v8.0.0
|
||||||
with:
|
with:
|
||||||
version: v2.1
|
version: v2.4
|
||||||
args: --verbose
|
args: --verbose
|
||||||
|
env:
|
||||||
|
GOEXPERIMENT: jsonv2
|
||||||
|
|||||||
4
.github/workflows/test.yaml
vendored
4
.github/workflows/test.yaml
vendored
@@ -40,9 +40,11 @@ jobs:
|
|||||||
id: lint
|
id: lint
|
||||||
uses: golangci/golangci-lint-action@4afd733a84b1f43292c63897423277bb7f4313a9 # v8.0.0
|
uses: golangci/golangci-lint-action@4afd733a84b1f43292c63897423277bb7f4313a9 # v8.0.0
|
||||||
with:
|
with:
|
||||||
version: v2.1
|
version: v2.4
|
||||||
args: --verbose
|
args: --verbose
|
||||||
skip-save-cache: true # Restore cache from main branch but don't save new cache
|
skip-save-cache: true # Restore cache from main branch but don't save new cache
|
||||||
|
env:
|
||||||
|
GOEXPERIMENT: jsonv2
|
||||||
if: matrix.operating-system == 'ubuntu-latest'
|
if: matrix.operating-system == 'ubuntu-latest'
|
||||||
|
|
||||||
- name: Check if linter failed
|
- name: Check if linter failed
|
||||||
|
|||||||
@@ -193,7 +193,7 @@ linters:
|
|||||||
warn-unused: true
|
warn-unused: true
|
||||||
|
|
||||||
run:
|
run:
|
||||||
go: '1.24'
|
go: '1.25'
|
||||||
timeout: 30m
|
timeout: 30m
|
||||||
|
|
||||||
formatters:
|
formatters:
|
||||||
|
|||||||
3
go.mod
3
go.mod
@@ -1,6 +1,6 @@
|
|||||||
module github.com/aquasecurity/trivy
|
module github.com/aquasecurity/trivy
|
||||||
|
|
||||||
go 1.24.7
|
go 1.25
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.19.0
|
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.19.0
|
||||||
@@ -47,7 +47,6 @@ require (
|
|||||||
github.com/docker/go-units v0.5.0
|
github.com/docker/go-units v0.5.0
|
||||||
github.com/fatih/color v1.18.0
|
github.com/fatih/color v1.18.0
|
||||||
github.com/go-git/go-git/v5 v5.16.2
|
github.com/go-git/go-git/v5 v5.16.2
|
||||||
github.com/go-json-experiment/json v0.0.0-20250223041408-d3c622f1b874 // Replace with encoding/json/v2 when proposal is accepted. Track https://github.com/golang/go/issues/71497
|
|
||||||
github.com/go-redis/redis/v8 v8.11.5
|
github.com/go-redis/redis/v8 v8.11.5
|
||||||
github.com/gocsaf/csaf/v3 v3.3.0
|
github.com/gocsaf/csaf/v3 v3.3.0
|
||||||
github.com/golang-jwt/jwt/v5 v5.3.0
|
github.com/golang-jwt/jwt/v5 v5.3.0
|
||||||
|
|||||||
2
go.sum
2
go.sum
@@ -1176,8 +1176,6 @@ github.com/go-jose/go-jose/v3 v3.0.3 h1:fFKWeig/irsp7XD2zBxvnmA/XaRWp5V3CBsZXJF7
|
|||||||
github.com/go-jose/go-jose/v3 v3.0.3/go.mod h1:5b+7YgP7ZICgJDBdfjZaIt+H/9L9T/YQrVfLAMboGkQ=
|
github.com/go-jose/go-jose/v3 v3.0.3/go.mod h1:5b+7YgP7ZICgJDBdfjZaIt+H/9L9T/YQrVfLAMboGkQ=
|
||||||
github.com/go-jose/go-jose/v4 v4.0.5 h1:M6T8+mKZl/+fNNuFHvGIzDz7BTLQPIounk/b9dw3AaE=
|
github.com/go-jose/go-jose/v4 v4.0.5 h1:M6T8+mKZl/+fNNuFHvGIzDz7BTLQPIounk/b9dw3AaE=
|
||||||
github.com/go-jose/go-jose/v4 v4.0.5/go.mod h1:s3P1lRrkT8igV8D9OjyL4WRyHvjB6a4JSllnOrmmBOA=
|
github.com/go-jose/go-jose/v4 v4.0.5/go.mod h1:s3P1lRrkT8igV8D9OjyL4WRyHvjB6a4JSllnOrmmBOA=
|
||||||
github.com/go-json-experiment/json v0.0.0-20250223041408-d3c622f1b874 h1:F8d1AJ6M9UQCavhwmO6ZsrYLfG8zVFWfEfMS2MXPkSY=
|
|
||||||
github.com/go-json-experiment/json v0.0.0-20250223041408-d3c622f1b874/go.mod h1:TiCD2a1pcmjd7YnhGH0f/zKNcCD06B029pHhzV23c2M=
|
|
||||||
github.com/go-latex/latex v0.0.0-20210118124228-b3d85cf34e07/go.mod h1:CO1AlKB2CSIqUrmQPqA0gdRIlnLEY0gK5JGjh37zN5U=
|
github.com/go-latex/latex v0.0.0-20210118124228-b3d85cf34e07/go.mod h1:CO1AlKB2CSIqUrmQPqA0gdRIlnLEY0gK5JGjh37zN5U=
|
||||||
github.com/go-latex/latex v0.0.0-20210823091927-c0d11ff05a81/go.mod h1:SX0U8uGpxhq9o2S/CELCSUxEWWAuoCUcVCQWv7G2OCk=
|
github.com/go-latex/latex v0.0.0-20210823091927-c0d11ff05a81/go.mod h1:SX0U8uGpxhq9o2S/CELCSUxEWWAuoCUcVCQWv7G2OCk=
|
||||||
github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
|
github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ builds:
|
|||||||
- -X github.com/aquasecurity/trivy/pkg/version/app.ver={{.Version}}
|
- -X github.com/aquasecurity/trivy/pkg/version/app.ver={{.Version}}
|
||||||
env:
|
env:
|
||||||
- CGO_ENABLED=0
|
- CGO_ENABLED=0
|
||||||
|
- GOEXPERIMENT=jsonv2
|
||||||
goos:
|
goos:
|
||||||
- darwin
|
- darwin
|
||||||
- linux
|
- linux
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ builds:
|
|||||||
- -X github.com/aquasecurity/trivy/pkg/version/app.ver={{.Version}}
|
- -X github.com/aquasecurity/trivy/pkg/version/app.ver={{.Version}}
|
||||||
env:
|
env:
|
||||||
- CGO_ENABLED=0
|
- CGO_ENABLED=0
|
||||||
|
- GOEXPERIMENT=jsonv2
|
||||||
goos:
|
goos:
|
||||||
- linux
|
- linux
|
||||||
goarch:
|
goarch:
|
||||||
@@ -31,6 +32,7 @@ builds:
|
|||||||
- -X github.com/aquasecurity/trivy/pkg/version/app.ver={{.Version}}
|
- -X github.com/aquasecurity/trivy/pkg/version/app.ver={{.Version}}
|
||||||
env:
|
env:
|
||||||
- CGO_ENABLED=0
|
- CGO_ENABLED=0
|
||||||
|
- GOEXPERIMENT=jsonv2
|
||||||
goos:
|
goos:
|
||||||
- freebsd
|
- freebsd
|
||||||
goarch:
|
goarch:
|
||||||
@@ -47,6 +49,7 @@ builds:
|
|||||||
- -X github.com/aquasecurity/trivy/pkg/version/app.ver={{.Version}}
|
- -X github.com/aquasecurity/trivy/pkg/version/app.ver={{.Version}}
|
||||||
env:
|
env:
|
||||||
- CGO_ENABLED=0
|
- CGO_ENABLED=0
|
||||||
|
- GOEXPERIMENT=jsonv2
|
||||||
goos:
|
goos:
|
||||||
- darwin
|
- darwin
|
||||||
goarch:
|
goarch:
|
||||||
@@ -63,6 +66,7 @@ builds:
|
|||||||
- -X github.com/aquasecurity/trivy/pkg/version/app.ver={{.Version}}
|
- -X github.com/aquasecurity/trivy/pkg/version/app.ver={{.Version}}
|
||||||
env:
|
env:
|
||||||
- CGO_ENABLED=0
|
- CGO_ENABLED=0
|
||||||
|
- GOEXPERIMENT=jsonv2
|
||||||
goos:
|
goos:
|
||||||
- windows
|
- windows
|
||||||
goarch:
|
goarch:
|
||||||
|
|||||||
@@ -28,7 +28,8 @@ var (
|
|||||||
GOBIN = filepath.Join(GOPATH, "bin")
|
GOBIN = filepath.Join(GOPATH, "bin")
|
||||||
|
|
||||||
ENV = map[string]string{
|
ENV = map[string]string{
|
||||||
"CGO_ENABLED": "0",
|
"CGO_ENABLED": "0",
|
||||||
|
"GOEXPERIMENT": "jsonv2",
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -73,7 +74,7 @@ func (Tool) PipTools() error {
|
|||||||
|
|
||||||
// GolangciLint installs golangci-lint
|
// GolangciLint installs golangci-lint
|
||||||
func (t Tool) GolangciLint() error {
|
func (t Tool) GolangciLint() error {
|
||||||
const version = "v2.1.2"
|
const version = "v2.4.0"
|
||||||
bin := filepath.Join(GOBIN, "golangci-lint")
|
bin := filepath.Join(GOBIN, "golangci-lint")
|
||||||
if exists(bin) && t.matchGolangciLintVersion(bin, version) {
|
if exists(bin) && t.matchGolangciLintVersion(bin, version) {
|
||||||
return nil
|
return nil
|
||||||
@@ -341,19 +342,19 @@ type Lint mg.Namespace
|
|||||||
// Run runs linters
|
// Run runs linters
|
||||||
func (l Lint) Run() error {
|
func (l Lint) Run() error {
|
||||||
mg.Deps(Tool{}.GolangciLint, Tool{}.Install)
|
mg.Deps(Tool{}.GolangciLint, Tool{}.Install)
|
||||||
if err := sh.RunV("golangci-lint", "run", "--build-tags=integration"); err != nil {
|
if err := sh.RunWithV(ENV, "golangci-lint", "run", "--build-tags=integration"); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return sh.RunV("modernize", "./...")
|
return sh.RunWithV(ENV, "modernize", "./...")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fix auto fixes linters
|
// Fix auto fixes linters
|
||||||
func (l Lint) Fix() error {
|
func (l Lint) Fix() error {
|
||||||
mg.Deps(Tool{}.GolangciLint, Tool{}.Install)
|
mg.Deps(Tool{}.GolangciLint, Tool{}.Install)
|
||||||
if err := sh.RunV("golangci-lint", "run", "--fix", "--build-tags=integration"); err != nil {
|
if err := sh.RunWithV(ENV, "golangci-lint", "run", "--fix", "--build-tags=integration"); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return sh.RunV("modernize", "-fix", "./...")
|
return sh.RunWithV(ENV, "modernize", "-fix", "./...")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fmt formats Go code
|
// Fmt formats Go code
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
package conan
|
package conan
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json/jsontext"
|
||||||
|
"encoding/json/v2"
|
||||||
"slices"
|
"slices"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/go-json-experiment/json"
|
|
||||||
"github.com/go-json-experiment/json/jsontext"
|
|
||||||
"github.com/samber/lo"
|
"github.com/samber/lo"
|
||||||
"golang.org/x/xerrors"
|
"golang.org/x/xerrors"
|
||||||
|
|
||||||
|
|||||||
@@ -1,13 +1,13 @@
|
|||||||
package bun
|
package bun
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json/jsontext"
|
||||||
|
"encoding/json/v2"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/go-json-experiment/json"
|
|
||||||
"github.com/go-json-experiment/json/jsontext"
|
|
||||||
"github.com/samber/lo"
|
"github.com/samber/lo"
|
||||||
"golang.org/x/xerrors"
|
"golang.org/x/xerrors"
|
||||||
|
|
||||||
|
|||||||
@@ -2,15 +2,14 @@ package parser
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"encoding/json/jsontext"
|
||||||
|
"encoding/json/v2"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/fs"
|
"io/fs"
|
||||||
"iter"
|
"iter"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/go-json-experiment/json"
|
|
||||||
"github.com/go-json-experiment/json/jsontext"
|
|
||||||
|
|
||||||
ftypes "github.com/aquasecurity/trivy/pkg/fanal/types"
|
ftypes "github.com/aquasecurity/trivy/pkg/fanal/types"
|
||||||
"github.com/aquasecurity/trivy/pkg/iac/scanners/azure"
|
"github.com/aquasecurity/trivy/pkg/iac/scanners/azure"
|
||||||
"github.com/aquasecurity/trivy/pkg/iac/scanners/azure/resolver"
|
"github.com/aquasecurity/trivy/pkg/iac/scanners/azure/resolver"
|
||||||
|
|||||||
@@ -1,14 +1,14 @@
|
|||||||
package azure
|
package azure
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json/jsontext"
|
||||||
|
"encoding/json/v2"
|
||||||
"fmt"
|
"fmt"
|
||||||
"maps"
|
"maps"
|
||||||
"slices"
|
"slices"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/go-json-experiment/json"
|
|
||||||
"github.com/go-json-experiment/json/jsontext"
|
|
||||||
"github.com/samber/lo"
|
"github.com/samber/lo"
|
||||||
|
|
||||||
"github.com/aquasecurity/trivy/pkg/iac/types"
|
"github.com/aquasecurity/trivy/pkg/iac/types"
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
package parser
|
package parser
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json/jsontext"
|
||||||
|
"encoding/json/v2"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
@@ -8,8 +10,6 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/go-json-experiment/json"
|
|
||||||
"github.com/go-json-experiment/json/jsontext"
|
|
||||||
"gopkg.in/yaml.v3"
|
"gopkg.in/yaml.v3"
|
||||||
|
|
||||||
"github.com/aquasecurity/trivy/pkg/iac/scanners/cloudformation/cftypes"
|
"github.com/aquasecurity/trivy/pkg/iac/scanners/cloudformation/cftypes"
|
||||||
|
|||||||
@@ -1,14 +1,14 @@
|
|||||||
package parser
|
package parser
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json/jsontext"
|
||||||
|
"encoding/json/v2"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/fs"
|
"io/fs"
|
||||||
"reflect"
|
"reflect"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/go-json-experiment/json"
|
|
||||||
"github.com/go-json-experiment/json/jsontext"
|
|
||||||
"gopkg.in/yaml.v3"
|
"gopkg.in/yaml.v3"
|
||||||
|
|
||||||
"github.com/aquasecurity/trivy/pkg/iac/scanners/cloudformation/cftypes"
|
"github.com/aquasecurity/trivy/pkg/iac/scanners/cloudformation/cftypes"
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
package parser
|
package parser
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json/jsontext"
|
||||||
|
"encoding/json/v2"
|
||||||
"io/fs"
|
"io/fs"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/go-json-experiment/json"
|
|
||||||
"github.com/go-json-experiment/json/jsontext"
|
|
||||||
"gopkg.in/yaml.v3"
|
"gopkg.in/yaml.v3"
|
||||||
|
|
||||||
iacTypes "github.com/aquasecurity/trivy/pkg/iac/types"
|
iacTypes "github.com/aquasecurity/trivy/pkg/iac/types"
|
||||||
|
|||||||
@@ -2,13 +2,13 @@ package parser
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
|
"encoding/json/jsontext"
|
||||||
|
"encoding/json/v2"
|
||||||
"fmt"
|
"fmt"
|
||||||
"reflect"
|
"reflect"
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/go-json-experiment/json"
|
|
||||||
"github.com/go-json-experiment/json/jsontext"
|
|
||||||
"gopkg.in/yaml.v3"
|
"gopkg.in/yaml.v3"
|
||||||
|
|
||||||
"github.com/aquasecurity/trivy/pkg/log"
|
"github.com/aquasecurity/trivy/pkg/log"
|
||||||
|
|||||||
@@ -2,10 +2,10 @@ package json
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"encoding/json/jsontext"
|
||||||
|
"encoding/json/v2"
|
||||||
"io"
|
"io"
|
||||||
|
|
||||||
"github.com/go-json-experiment/json"
|
|
||||||
"github.com/go-json-experiment/json/jsontext"
|
|
||||||
"golang.org/x/xerrors"
|
"golang.org/x/xerrors"
|
||||||
|
|
||||||
"github.com/aquasecurity/trivy/pkg/fanal/types"
|
"github.com/aquasecurity/trivy/pkg/fanal/types"
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
package json_test
|
package json_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json/jsontext"
|
||||||
|
"encoding/json/v2"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/go-json-experiment/json"
|
|
||||||
"github.com/go-json-experiment/json/jsontext"
|
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
xjson "github.com/aquasecurity/trivy/pkg/x/json"
|
xjson "github.com/aquasecurity/trivy/pkg/x/json"
|
||||||
|
|||||||
Reference in New Issue
Block a user