Skip to content

Commit

Permalink
Integrate version into present origin field
Browse files Browse the repository at this point in the history
Signed-off-by: Christian Zunker <[email protected]>
  • Loading branch information
czunker committed Feb 28, 2024
1 parent 357468d commit 1843f11
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 57 deletions.
5 changes: 1 addition & 4 deletions providers/os/resources/os.lr
Original file line number Diff line number Diff line change
Expand Up @@ -614,11 +614,8 @@ package @defaults("name version") {
// Common Platform Enumeration (CPE) for the package
cpes []core.cpe

// Package origin (optional)
// Package origin (optional) (This includes the version when present)
origin() string
// Package origin version (optional)
originVersion() string


// Available version
available string
Expand Down
14 changes: 0 additions & 14 deletions providers/os/resources/os.lr.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions providers/os/resources/os.lr.manifest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -587,8 +587,6 @@ resources:
installed: {}
name: {}
origin: {}
originVersion:
min_mondoo_version: latest
outdated: {}
purl:
min_mondoo_version: latest
Expand Down
30 changes: 12 additions & 18 deletions providers/os/resources/packages.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ func initPackage(runtime *plugin.Runtime, args map[string]*llx.RawData) (map[str
res.Arch.State = plugin.StateIsSet | plugin.StateIsNull
res.Format.State = plugin.StateIsSet | plugin.StateIsNull
res.Origin.State = plugin.StateIsSet | plugin.StateIsNull
res.OriginVersion.State = plugin.StateIsSet | plugin.StateIsNull
res.Status.State = plugin.StateIsSet | plugin.StateIsNull
res.Files.State = plugin.StateIsSet | plugin.StateIsNull
return nil, res, nil
Expand All @@ -96,10 +95,6 @@ func (p *mqlPackage) origin() (string, error) {
return "", nil
}

func (p *mqlPackage) originVersion() (string, error) {
return "", nil
}

func (p *mqlPackage) files() ([]interface{}, error) {
if p.filesState == packages.PkgFilesNotAvailable {
return nil, nil
Expand Down Expand Up @@ -195,19 +190,18 @@ func (x *mqlPackages) list() ([]interface{}, error) {
}

pkg, err := CreateResource(x.MqlRuntime, "package", map[string]*llx.RawData{
"name": llx.StringData(osPkg.Name),
"version": llx.StringData(osPkg.Version),
"available": llx.StringData(available),
"arch": llx.StringData(osPkg.Arch),
"status": llx.StringData(osPkg.Status),
"description": llx.StringData(osPkg.Description),
"format": llx.StringData(osPkg.Format),
"installed": llx.BoolData(true),
"origin": llx.StringData(osPkg.Origin),
"originVersion": llx.StringData(osPkg.OriginVersion),
"epoch": llx.StringData(osPkg.Epoch),
"purl": llx.StringData(osPkg.PUrl),
"cpes": llx.ArrayData(cpes, types.Resource("cpe")),
"name": llx.StringData(osPkg.Name),
"version": llx.StringData(osPkg.Version),
"available": llx.StringData(available),
"arch": llx.StringData(osPkg.Arch),
"status": llx.StringData(osPkg.Status),
"description": llx.StringData(osPkg.Description),
"format": llx.StringData(osPkg.Format),
"installed": llx.BoolData(true),
"origin": llx.StringData(osPkg.Origin),
"epoch": llx.StringData(osPkg.Epoch),
"purl": llx.StringData(osPkg.PUrl),
"cpes": llx.ArrayData(cpes, types.Resource("cpe")),
})
if err != nil {
return nil, err
Expand Down
11 changes: 1 addition & 10 deletions providers/os/resources/packages/dpkg_packages.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,16 +81,7 @@ func ParseDpkgPackages(pf *inventory.Platform, input io.Reader) ([]Package, erro
case key == "Status":
pkg.Status = strings.TrimSpace(m[2])
case key == "Source":
o := DPKG_ORIGIN_REGEX.FindStringSubmatch(m[2])
if len(o) >= 1 {
pkg.Origin = strings.TrimSpace(o[1])
} else {
log.Error().Str("origin", m[2]).Msg("cannot parse dpkg origin")
}
// Some packages also have a version as part of the Source field
if len(o) >= 2 {
pkg.OriginVersion = strings.TrimSpace(o[2])
}
pkg.Origin = strings.TrimSpace(m[2])
// description supports multi-line statements, start desc
case key == "Description":
pkg.Description = strings.TrimSpace(m[2])
Expand Down
11 changes: 5 additions & 6 deletions providers/os/resources/packages/dpkg_packages_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,11 @@ The sfdisk utility is mostly for automation and scripting uses.`,
assert.Equal(t, findPkg(m, p.Name), p, p.Name)

p = Package{
Name: "libaudit1",
Version: "1:2.4-1+b1",
Arch: "amd64",
Status: "install ok installed",
Origin: "audit",
OriginVersion: "1:2.4-1",
Name: "libaudit1",
Version: "1:2.4-1+b1",
Arch: "amd64",
Status: "install ok installed",
Origin: "audit (1:2.4-1)",
Description: `Dynamic library for security auditing
The audit-libs package contains the dynamic libraries needed for
applications to use the audit framework. It is used to monitor systems for
Expand Down
5 changes: 2 additions & 3 deletions providers/os/resources/packages/packages.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,8 @@ type Package struct {
// this may be the source package or an origin
// e.g. on alpine it is used for parent packages
// o Package Origin - https://wiki.alpinelinux.org/wiki/Apk_spec
Origin string `json:"origin"`
OriginVersion string `json:"originVersion"`
Format string `json:"format"`
Origin string `json:"origin"`
Format string `json:"format"`

// Package Url follows https://github.com/package-url/purl-spec
PUrl string `json:"purl,omitempty"`
Expand Down

0 comments on commit 1843f11

Please sign in to comment.