mirror of
https://github.com/anchore/syft
synced 2024-11-13 23:57:07 +00:00
add file classifications to power-user json presenter
Signed-off-by: Alex Goodman <alex.goodman@anchore.com>
This commit is contained in:
parent
870a676a5d
commit
080057b217
3 changed files with 49 additions and 12 deletions
|
@ -9,6 +9,7 @@ type JSONDocument struct {
|
||||||
// here should be optional by supplying "omitempty" on these fields hint to the jsonschema generator to not
|
// here should be optional by supplying "omitempty" on these fields hint to the jsonschema generator to not
|
||||||
// require these fields. As an accepted rule in this repo all collections should still be initialized in the
|
// require these fields. As an accepted rule in this repo all collections should still be initialized in the
|
||||||
// context of being used in a JSON document.
|
// context of being used in a JSON document.
|
||||||
|
FileClassifications []JSONFileClassifications `json:"fileClassifications,omitempty"` // note: must have omitempty
|
||||||
FileMetadata []JSONFileMetadata `json:"fileMetadata,omitempty"` // note: must have omitempty
|
FileMetadata []JSONFileMetadata `json:"fileMetadata,omitempty"` // note: must have omitempty
|
||||||
Secrets []JSONSecrets `json:"secrets,omitempty"` // note: must have omitempty
|
Secrets []JSONSecrets `json:"secrets,omitempty"` // note: must have omitempty
|
||||||
packages.JSONDocument
|
packages.JSONDocument
|
||||||
|
@ -27,6 +28,7 @@ func NewJSONDocument(config JSONDocumentConfig) (JSONDocument, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
return JSONDocument{
|
return JSONDocument{
|
||||||
|
FileClassifications: NewJSONFileClassifications(config.FileClassifications),
|
||||||
FileMetadata: fileMetadata,
|
FileMetadata: fileMetadata,
|
||||||
Secrets: NewJSONSecrets(config.Secrets),
|
Secrets: NewJSONSecrets(config.Secrets),
|
||||||
JSONDocument: pkgsDoc,
|
JSONDocument: pkgsDoc,
|
||||||
|
|
|
@ -13,6 +13,7 @@ type JSONDocumentConfig struct {
|
||||||
PackageCatalog *pkg.Catalog
|
PackageCatalog *pkg.Catalog
|
||||||
FileMetadata map[source.Location]source.FileMetadata
|
FileMetadata map[source.Location]source.FileMetadata
|
||||||
FileDigests map[source.Location][]file.Digest
|
FileDigests map[source.Location][]file.Digest
|
||||||
|
FileClassifications map[source.Location][]file.Classification
|
||||||
Secrets map[source.Location][]file.SearchResult
|
Secrets map[source.Location][]file.SearchResult
|
||||||
Distro *distro.Distro
|
Distro *distro.Distro
|
||||||
SourceMetadata source.Metadata
|
SourceMetadata source.Metadata
|
||||||
|
|
34
internal/presenter/poweruser/json_file_classifications.go
Normal file
34
internal/presenter/poweruser/json_file_classifications.go
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
package poweruser
|
||||||
|
|
||||||
|
import (
|
||||||
|
"sort"
|
||||||
|
|
||||||
|
"github.com/anchore/syft/syft/file"
|
||||||
|
"github.com/anchore/syft/syft/source"
|
||||||
|
)
|
||||||
|
|
||||||
|
type JSONFileClassifications struct {
|
||||||
|
Location source.Location `json:"location"`
|
||||||
|
Classification file.Classification `json:"classification"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewJSONFileClassifications(data map[source.Location][]file.Classification) []JSONFileClassifications {
|
||||||
|
results := make([]JSONFileClassifications, 0)
|
||||||
|
for location, classifications := range data {
|
||||||
|
for _, classification := range classifications {
|
||||||
|
results = append(results, JSONFileClassifications{
|
||||||
|
Location: location,
|
||||||
|
Classification: classification,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// sort by real path then virtual path to ensure the result is stable across multiple runs
|
||||||
|
sort.SliceStable(results, func(i, j int) bool {
|
||||||
|
if results[i].Location.RealPath == results[j].Location.RealPath {
|
||||||
|
return results[i].Location.VirtualPath < results[j].Location.VirtualPath
|
||||||
|
}
|
||||||
|
return results[i].Location.RealPath < results[j].Location.RealPath
|
||||||
|
})
|
||||||
|
return results
|
||||||
|
}
|
Loading…
Reference in a new issue