mirror of
https://github.com/anchore/syft.git
synced 2025-11-18 08:53:15 +01:00
* split source.Location and create source.Coordinates for minimal path addressing Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * move coordinates into separate file Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * Update syft/source/coordinates.go Co-authored-by: Dan Luhring <luhring@users.noreply.github.com>
30 lines
732 B
Go
30 lines
732 B
Go
package poweruser
|
|
|
|
import (
|
|
"sort"
|
|
|
|
"github.com/anchore/syft/syft/file"
|
|
"github.com/anchore/syft/syft/source"
|
|
)
|
|
|
|
type JSONSecrets struct {
|
|
Location source.Coordinates `json:"location"`
|
|
Secrets []file.SearchResult `json:"secrets"`
|
|
}
|
|
|
|
func NewJSONSecrets(data map[source.Coordinates][]file.SearchResult) []JSONSecrets {
|
|
results := make([]JSONSecrets, 0)
|
|
for coordinates, secrets := range data {
|
|
results = append(results, JSONSecrets{
|
|
Location: coordinates,
|
|
Secrets: secrets,
|
|
})
|
|
}
|
|
|
|
// sort by real path then virtual path to ensure the result is stable across multiple runs
|
|
sort.SliceStable(results, func(i, j int) bool {
|
|
return results[i].Location.RealPath < results[j].Location.RealPath
|
|
})
|
|
return results
|
|
}
|