mirror of
https://github.com/anchore/syft.git
synced 2025-11-17 08:23:15 +01:00
51 lines
1.3 KiB
Go
51 lines
1.3 KiB
Go
package poweruser
|
|
|
|
import (
|
|
"fmt"
|
|
"strconv"
|
|
|
|
"github.com/anchore/syft/syft/file"
|
|
|
|
"github.com/anchore/syft/syft/source"
|
|
)
|
|
|
|
type JSONFileMetadata struct {
|
|
Location source.Location `json:"location"`
|
|
Metadata JSONFileMetadataEntry `json:"metadata"`
|
|
}
|
|
|
|
type JSONFileMetadataEntry struct {
|
|
Mode int `json:"mode"`
|
|
Type source.FileType `json:"type"`
|
|
UserID int `json:"userID"`
|
|
GroupID int `json:"groupID"`
|
|
Digests []file.Digest `json:"digests"`
|
|
}
|
|
|
|
func NewJSONFileMetadata(data map[source.Location]source.FileMetadata, digests map[source.Location][]file.Digest) ([]JSONFileMetadata, error) {
|
|
results := make([]JSONFileMetadata, 0)
|
|
for location, metadata := range data {
|
|
mode, err := strconv.Atoi(fmt.Sprintf("%o", metadata.Mode))
|
|
if err != nil {
|
|
return nil, fmt.Errorf("invalid mode found in file catalog @ location=%+v mode=%q: %w", location, metadata.Mode, err)
|
|
}
|
|
|
|
digestResults := make([]file.Digest, 0)
|
|
if digestsForLocation, exists := digests[location]; exists {
|
|
digestResults = digestsForLocation
|
|
}
|
|
|
|
results = append(results, JSONFileMetadata{
|
|
Location: location,
|
|
Metadata: JSONFileMetadataEntry{
|
|
Mode: mode,
|
|
Type: metadata.Type,
|
|
UserID: metadata.UserID,
|
|
GroupID: metadata.GroupID,
|
|
Digests: digestResults,
|
|
},
|
|
})
|
|
}
|
|
return results, nil
|
|
}
|