Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

keep original file order #258

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions commands/enrich/enrich.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package enrich

import (
"encoding/json"
"encoding/xml"
"errors"
"fmt"
"github.com/jfrog/jfrog-cli-security/utils/results/output"
"os"
"os/exec"
"path/filepath"
Expand All @@ -17,7 +17,6 @@ import (
"github.com/jfrog/jfrog-cli-security/commands/enrich/enrichgraph"
"github.com/jfrog/jfrog-cli-security/utils"
"github.com/jfrog/jfrog-cli-security/utils/results"
"github.com/jfrog/jfrog-cli-security/utils/results/output"
"github.com/jfrog/jfrog-cli-security/utils/techutils"
"github.com/jfrog/jfrog-cli-security/utils/xray"
"github.com/jfrog/jfrog-client-go/artifactory/services/fspatterns"
Expand All @@ -27,6 +26,7 @@ import (
"github.com/jfrog/jfrog-client-go/utils/io/fileutils"
"github.com/jfrog/jfrog-client-go/utils/log"
"github.com/jfrog/jfrog-client-go/xray/services"
orderedJson "github.com/virtuald/go-ordered-json"
)

type FileContext func(string) parallel.TaskFunc
Expand Down Expand Up @@ -75,8 +75,8 @@ func AppendVulnsToJson(cmdResults *results.SecurityCommandResults) error {
if err != nil {
return fmt.Errorf("error reading file: %s", err.Error())
}
var data map[string]interface{}
err = json.Unmarshal(fileContent, &data)
var data orderedJson.OrderedObject
err = orderedJson.Unmarshal(fileContent, &data)
if err != nil {
return fmt.Errorf("error parsing JSON: %s", err.Error())
}
Expand All @@ -93,7 +93,7 @@ func AppendVulnsToJson(cmdResults *results.SecurityCommandResults) error {
vulnerabilities = append(vulnerabilities, vulnerability)
}
}
data["vulnerabilities"] = vulnerabilities
data = append(data, orderedJson.Member{Key: "vulnerabilities", Value: vulnerabilities})
return output.PrintJson(data)
}

Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ require (
github.com/owenrumney/go-sarif/v2 v2.3.0
github.com/stretchr/testify v1.9.0
github.com/urfave/cli v1.22.16
github.com/virtuald/go-ordered-json v0.0.0-20170621173500-b18e6e673d74
golang.org/x/exp v0.0.0-20241108190413-2d47ceb2692f
golang.org/x/sync v0.9.0
golang.org/x/text v0.20.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,8 @@ github.com/urfave/cli v1.22.16 h1:MH0k6uJxdwdeWQTwhSO42Pwr4YLrNLwBtg1MRgTqPdQ=
github.com/urfave/cli v1.22.16/go.mod h1:EeJR6BKodywf4zciqrdw6hpCPk68JO9z5LazXZMn5Po=
github.com/vbauerster/mpb/v8 v8.8.3 h1:dTOByGoqwaTJYPubhVz3lO5O6MK553XVgUo33LdnNsQ=
github.com/vbauerster/mpb/v8 v8.8.3/go.mod h1:JfCCrtcMsJwP6ZwMn9e5LMnNyp3TVNpUWWkN+nd4EWk=
github.com/virtuald/go-ordered-json v0.0.0-20170621173500-b18e6e673d74 h1:JwtAtbp7r/7QSyGz8mKUbYJBg2+6Cd7OjM8o/GNOcVo=
github.com/virtuald/go-ordered-json v0.0.0-20170621173500-b18e6e673d74/go.mod h1:RmMWU37GKR2s6pgrIEB4ixgpVCt/cf7dnJv3fuH1J1c=
github.com/vmihailenco/msgpack/v4 v4.3.12/go.mod h1:gborTTJjAo/GWTqqRjrLCn9pgNN+NXzzngzBKDPIqw4=
github.com/vmihailenco/tagparser v0.1.1/go.mod h1:OeAg3pn3UbLjkWt+rN9oFYB6u/cQgqMEUPoW2WPyhdI=
github.com/xanzy/go-gitlab v0.110.0 h1:hsFIFp01v/0D0sdUXoZfRk6CROzZbHQplk6NzKSFKhc=
Expand Down
3 changes: 2 additions & 1 deletion utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"encoding/hex"
"encoding/json"
"fmt"
orderedJson "github.com/virtuald/go-ordered-json"
"os"
"path/filepath"
"strings"
Expand Down Expand Up @@ -112,7 +113,7 @@ func UniqueUnion[T comparable](arr []T, elements ...T) []T {

func GetAsJsonBytes(output interface{}, escapeValues, indent bool) (results []byte, err error) {
if escapeValues {
if results, err = json.Marshal(output); errorutils.CheckError(err) != nil {
if results, err = orderedJson.Marshal(output); errorutils.CheckError(err) != nil {
return
}
} else {
Expand Down
Loading