Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ Include version in origin field for debian packages #3426

Merged
merged 4 commits into from
Feb 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion providers/os/resources/os.lr
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,7 @@ package @defaults("name version") {
// Common Platform Enumeration (CPE) for the package
cpes []core.cpe

// Package origin (optional)
// Package origin, may includes version if available (optional)
origin() string

// Available version
Expand Down
2 changes: 1 addition & 1 deletion providers/os/resources/packages.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package resources

import (
"errors"
"go.mondoo.com/cnquery/v10/types"
"regexp"
"sync"

Expand All @@ -14,6 +13,7 @@ import (
"go.mondoo.com/cnquery/v10/providers-sdk/v1/plugin"
"go.mondoo.com/cnquery/v10/providers/os/connection/shared"
"go.mondoo.com/cnquery/v10/providers/os/resources/packages"
"go.mondoo.com/cnquery/v10/types"
"go.mondoo.com/cnquery/v10/utils/multierr"
)

Expand Down
18 changes: 7 additions & 11 deletions providers/os/resources/packages/dpkg_packages.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,27 @@ package packages
import (
"bufio"
"fmt"
"github.com/package-url/packageurl-go"
"go.mondoo.com/cnquery/v10/providers-sdk/v1/inventory"
"go.mondoo.com/cnquery/v10/providers/os/resources/cpe"
"go.mondoo.com/cnquery/v10/providers/os/resources/purl"
"io"
"os"
"regexp"
"strings"

"github.com/package-url/packageurl-go"
"github.com/rs/zerolog/log"
"github.com/spf13/afero"
"go.mondoo.com/cnquery/v10/providers-sdk/v1/inventory"
"go.mondoo.com/cnquery/v10/providers/os/connection/shared"
"go.mondoo.com/cnquery/v10/providers/os/resources/cpe"
"go.mondoo.com/cnquery/v10/providers/os/resources/purl"
)

const (
DpkgPkgFormat = "deb"
)

var (
DPKG_REGEX = regexp.MustCompile(`^(.+):\s(.+)$`)
DPKG_REGEX = regexp.MustCompile(`^(.+):\s(.+)$`)
// e.g. source with version: samba (2:4.17.12+dfsg-0+deb12u1)
DPKG_ORIGIN_REGEX = regexp.MustCompile(`^\s*([^\(]*)(?:\((.*)\))?\s*$`)
)

Expand Down Expand Up @@ -79,12 +80,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 o != nil && len(o) >= 1 {
pkg.Origin = strings.TrimSpace(o[1])
} else {
log.Error().Str("origin", m[2]).Msg("cannot parse dpkg origin")
}
pkg.Origin = strings.TrimSpace(m[2])
// description supports multi-line statements, start desc
case key == "Description":
pkg.Description = strings.TrimSpace(m[2])
Expand Down
4 changes: 2 additions & 2 deletions providers/os/resources/packages/dpkg_packages_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ The sfdisk utility is mostly for automation and scripting uses.`,
Version: "1:2.4-1+b1",
Arch: "amd64",
Status: "install ok installed",
Origin: "audit",
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 All @@ -71,7 +71,7 @@ security related events.`,
Format: "deb",
FilesAvailable: PkgFilesAsync,
}
assert.Equal(t, findPkg(m, p.Name), p, p.Name)
assert.Equal(t, p, findPkg(m, p.Name), p.Name)

p = Package{
Name: "libss2",
Expand Down
Loading