add extra RPM file record fields (user, group, flags)

Signed-off-by: Alex Goodman <alex.goodman@anchore.com>
This commit is contained in:
Alex Goodman
2021-04-16 10:25:46 -04:00
parent 11866ab69e
commit 0c7706f254
6 changed files with 34 additions and 976 deletions
+12 -4
View File
@@ -6,6 +6,8 @@ import (
"io/ioutil"
"os"
"github.com/anchore/syft/syft/file"
rpmdb "github.com/anchore/go-rpmdb/pkg"
"github.com/anchore/syft/internal"
"github.com/anchore/syft/internal/log"
@@ -79,10 +81,16 @@ func extractRpmdbFileRecords(resolver source.FilePathResolver, entry *rpmdb.Pack
//only persist RPMDB file records which exist in the image/directory, otherwise ignore them
if resolver.HasPath(record.Path) {
records = append(records, pkg.RpmdbFileRecord{
Path: record.Path,
Mode: pkg.RpmdbFileMode(record.Mode),
Size: int(record.Size),
SHA256: record.SHA256,
Path: record.Path,
Mode: pkg.RpmdbFileMode(record.Mode),
Size: int(record.Size),
Digest: file.Digest{
Value: record.Digest,
Algorithm: entry.DigestAlgorithm.String(),
},
UserName: record.Username,
GroupName: record.Groupname,
Flags: record.Flags.String(),
})
}
}
+10 -4
View File
@@ -5,6 +5,8 @@ import (
"os"
"testing"
"github.com/anchore/syft/syft/file"
"github.com/anchore/syft/syft/source"
"github.com/anchore/syft/syft/pkg"
@@ -105,10 +107,14 @@ func TestParseRpmDB(t *testing.T) {
Vendor: "",
Files: []pkg.RpmdbFileRecord{
{
Path: "/usr/local/bin/dive",
Mode: 33261,
Size: 12406784,
SHA256: "81d29f327ba23096b3c52ff6fe1c425641e618bc87b5c05ee377edc650afaa55",
Path: "/usr/local/bin/dive",
Mode: 33261,
Size: 12406784,
Digest: file.Digest{
Algorithm: "sha256",
Value: "81d29f327ba23096b3c52ff6fe1c425641e618bc87b5c05ee377edc650afaa55",
},
// note: there is no username, groupname, or flags for this RPM
},
},
},
+9 -4
View File
@@ -4,6 +4,8 @@ import (
"fmt"
"sort"
"github.com/anchore/syft/syft/file"
"github.com/scylladb/go-set/strset"
"github.com/anchore/syft/syft/distro"
@@ -30,10 +32,13 @@ type RpmdbMetadata struct {
// RpmdbFileRecord represents the file metadata for a single file attributed to a RPM package.
type RpmdbFileRecord struct {
Path string `json:"path"`
Mode RpmdbFileMode `json:"mode"`
Size int `json:"size"`
SHA256 string `json:"sha256"`
Path string `json:"path"`
Mode RpmdbFileMode `json:"mode"`
Size int `json:"size"`
Digest file.Digest `json:"digest"`
UserName string `json:"userName"`
GroupName string `json:"groupName"`
Flags string `json:"flags"`
}
// RpmdbFileMode is the raw file mode for a single file. This can be interpreted as the linux stat.h mode (see https://pubs.opengroup.org/onlinepubs/007908799/xsh/sysstat.h.html)