Skip to content

Commit

Permalink
⭐️ Add Purl to Macos and Windows systems
Browse files Browse the repository at this point in the history
Fixes #4957

Signed-off-by: Salim Afiune Maya <[email protected]>
  • Loading branch information
afiune committed Dec 16, 2024
1 parent fee2739 commit 27f9d70
Show file tree
Hide file tree
Showing 21 changed files with 171 additions and 57 deletions.
4 changes: 2 additions & 2 deletions cli/reporter/cnquery_report.pb.go

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

2 changes: 1 addition & 1 deletion explorer/cnquery_explorer.pb.go

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

4 changes: 2 additions & 2 deletions explorer/resources/cnquery_resources_explorer.pb.go

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

4 changes: 2 additions & 2 deletions explorer/scan/cnquery_explorer_scan.pb.go

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

4 changes: 2 additions & 2 deletions llx/llx.pb.go

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

44 changes: 33 additions & 11 deletions providers-sdk/v1/plugin/plugin_grpc.pb.go

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

4 changes: 2 additions & 2 deletions providers-sdk/v1/upstream/health/errors.pb.go

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

4 changes: 2 additions & 2 deletions providers-sdk/v1/upstream/health/health.pb.go

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

4 changes: 2 additions & 2 deletions providers-sdk/v1/upstream/mvd/cvss/cvss.pb.go

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

4 changes: 2 additions & 2 deletions providers-sdk/v1/upstream/mvd/mvd.pb.go

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

4 changes: 2 additions & 2 deletions providers-sdk/v1/upstream/upstream.pb.go

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

12 changes: 9 additions & 3 deletions providers/os/resources/packages/macos_packages.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ import (
"strings"

"github.com/cockroachdb/errors"
"go.mondoo.com/cnquery/v11/providers-sdk/v1/inventory"
"go.mondoo.com/cnquery/v11/providers/os/connection/shared"
"go.mondoo.com/cnquery/v11/providers/os/resources/purl"
plist "howett.net/plist"
)

Expand All @@ -18,7 +20,7 @@ const (
)

// parse macos system version property list
func ParseMacOSPackages(input io.Reader) ([]Package, error) {
func ParseMacOSPackages(platform *inventory.Platform, input io.Reader) ([]Package, error) {
var r io.ReadSeeker
r, ok := input.(io.ReadSeeker)

Expand Down Expand Up @@ -58,6 +60,9 @@ func ParseMacOSPackages(input io.Reader) ([]Package, error) {
pkgs[i].Version = entry.Version
pkgs[i].Format = MacosPkgFormat
pkgs[i].FilesAvailable = PkgFilesIncluded
pkgs[i].PUrl = purl.NewPackageUrl(
platform, entry.Name, entry.Version, platform.Arch, "", purl.TypeMacos,
)
if entry.Path != "" {
pkgs[i].Files = []FileRecord{
{
Expand All @@ -72,7 +77,8 @@ func ParseMacOSPackages(input io.Reader) ([]Package, error) {

// MacOS
type MacOSPkgManager struct {
conn shared.Connection
conn shared.Connection
platform *inventory.Platform
}

func (mpm *MacOSPkgManager) Name() string {
Expand All @@ -89,7 +95,7 @@ func (mpm *MacOSPkgManager) List() ([]Package, error) {
return nil, fmt.Errorf("could not read package list")
}

return ParseMacOSPackages(cmd.Stdout)
return ParseMacOSPackages(mpm.platform, cmd.Stdout)
}

func (mpm *MacOSPkgManager) Available() (map[string]PackageUpdate, error) {
Expand Down
10 changes: 9 additions & 1 deletion providers/os/resources/packages/macos_packages_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,27 @@ func TestMacOsXPackageParser(t *testing.T) {
}
assert.Nil(t, err)

m, err := packages.ParseMacOSPackages(c.Stdout)
pf := &inventory.Platform{
Name: "macos",
Version: "15.2",
Arch: "x86_64",
Family: []string{"darwin", "bsd", "unix", "os"},
}
m, err := packages.ParseMacOSPackages(pf, c.Stdout)
assert.Nil(t, err)
assert.Equal(t, 2, len(m), "detected the right amount of packages")

assert.Equal(t, "Preview", m[0].Name, "pkg name detected")
assert.Equal(t, "10.0", m[0].Version, "pkg version detected")
assert.Equal(t, packages.MacosPkgFormat, m[0].Format, "pkg format detected")
assert.Equal(t, packages.PkgFilesIncluded, m[0].FilesAvailable)
assert.Equal(t, "pkg:macos/[email protected]?arch=x86_64&distro=macos-15.2", m[0].PUrl)
assert.Equal(t, []packages.FileRecord{{Path: "/Applications/Preview.app"}}, m[0].Files)

assert.Equal(t, "Contacts", m[1].Name, "pkg name detected")
assert.Equal(t, "11.0", m[1].Version, "pkg version detected")
assert.Equal(t, packages.MacosPkgFormat, m[1].Format, "pkg format detected")
assert.Equal(t, packages.PkgFilesIncluded, m[1].FilesAvailable)
assert.Equal(t, "pkg:macos/[email protected]?arch=x86_64&distro=macos-15.2", m[1].PUrl)
assert.Equal(t, []packages.FileRecord{{Path: "/Applications/Contacts.app"}}, m[1].Files)
}
2 changes: 1 addition & 1 deletion providers/os/resources/packages/packages.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func ResolveSystemPkgManager(conn shared.Connection) (OperatingSystemPkgManager,
case asset.Platform.Name == "alpine" || asset.Platform.Name == "wolfi": // alpine & wolfi share apk
pm = &AlpinePkgManager{conn: conn, platform: asset.Platform}
case asset.Platform.Name == "macos": // mac os family
pm = &MacOSPkgManager{conn: conn}
pm = &MacOSPkgManager{conn: conn, platform: asset.Platform}
case asset.Platform.Name == "windows":
pm = &WinPkgManager{conn: conn, platform: asset.Platform}
case asset.Platform.Name == "scratch" || asset.Platform.Name == "coreos":
Expand Down
Loading

0 comments on commit 27f9d70

Please sign in to comment.