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

FIX: Adding metadata template #415

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
5 changes: 5 additions & 0 deletions binary/proto/proto.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import (
"github.com/google/osv-scalibr/extractor/filesystem/os/cos"
"github.com/google/osv-scalibr/extractor/filesystem/os/dpkg"
"github.com/google/osv-scalibr/extractor/filesystem/os/flatpak"
"github.com/google/osv-scalibr/extractor/filesystem/os/homebrew"
"github.com/google/osv-scalibr/extractor/filesystem/os/kernel/module"
"github.com/google/osv-scalibr/extractor/filesystem/os/kernel/vmlinuz"
"github.com/google/osv-scalibr/extractor/filesystem/os/macapps"
Expand Down Expand Up @@ -384,6 +385,10 @@ func setProtoMetadata(meta any, i *spb.Inventory) {
UpdateUrl: m.KSUpdateURL,
},
}
case *homebrew.Metadata:
i.Metadata = &spb.Inventory_HomebrewMetadata{
HomebrewMetadata: &spb.HomebrewPackageMetadata{},
}
case *module.Metadata:
i.Metadata = &spb.Inventory_KernelModuleMetadata{
KernelModuleMetadata: &spb.KernelModuleMetadata{
Expand Down
56 changes: 56 additions & 0 deletions binary/proto/proto_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import (
"github.com/google/osv-scalibr/extractor/filesystem/language/python/requirements"
"github.com/google/osv-scalibr/extractor/filesystem/language/python/wheelegg"
"github.com/google/osv-scalibr/extractor/filesystem/os/dpkg"
"github.com/google/osv-scalibr/extractor/filesystem/os/homebrew"
"github.com/google/osv-scalibr/extractor/filesystem/os/nix"
"github.com/google/osv-scalibr/extractor/filesystem/os/pacman"
"github.com/google/osv-scalibr/extractor/filesystem/os/portage"
Expand Down Expand Up @@ -587,6 +588,26 @@ func TestScanResultToProto(t *testing.T) {
Locations: []string{"/file1"},
Extractor: "os/nix",
}
purlHomebrewInventory := &extractor.Inventory{
Name: "rclone",
Version: "1.67.0",
Metadata: &homebrew.Metadata{},
Locations: []string{"/file1"},
Extractor: homebrew.Extractor{},
}
purlHomebrewInventoryProto := &spb.Inventory{
Name: "rclone",
Version: "1.67.0",
Purl: &spb.Purl{
Purl: "pkg:brew/[email protected]",
Type: purl.TypeBrew,
Name: "rclone",
Version: "1.67.0",
},
Metadata: &spb.Inventory_HomebrewMetadata{},
Locations: []string{"/file1"},
Extractor: "os/homebrew",
}
containerdInventory := &extractor.Inventory{
Name: "gcr.io/google-samples/hello-app:1.0",
Version: "sha256:b1455e1c4fcc5ea1023c9e3b584cd84b64eb920e332feff690a2829696e379e7",
Expand Down Expand Up @@ -760,6 +781,7 @@ func TestScanResultToProto(t *testing.T) {
cdxInventory,
windowsInventory,
purlPythonInventoryWithLayerDetails,
purlHomebrewInventory,
},
Findings: []*detector.Finding{
{
Expand Down Expand Up @@ -813,6 +835,7 @@ func TestScanResultToProto(t *testing.T) {
cdxInventoryProto,
windowsInventoryProto,
purlPythonInventoryWithLayerDetailsProto,
purlHomebrewInventoryProto,
},
Findings: []*spb.Finding{
{
Expand Down Expand Up @@ -972,6 +995,39 @@ func TestScanResultToProto(t *testing.T) {
},
excludeForOS: []string{"windows", "darwin"},
},
{
desc: "Successful Homebrew scan darwin-only",
res: &scalibr.ScanResult{
Version: "1.0.0",
StartTime: startTime,
EndTime: endTime,
Status: success,
PluginStatus: []*plugin.Status{
{
Name: "ext",
Version: 2,
Status: success,
},
},
Inventories: []*extractor.Inventory{purlHomebrewInventory},
},
want: &spb.ScanResult{
Version: "1.0.0",
StartTime: timestamppb.New(startTime),
EndTime: timestamppb.New(endTime),
Status: successProto,
PluginStatus: []*spb.PluginStatus{
{
Name: "ext",
Version: 2,
Status: successProto,
},
},
Inventories: []*spb.Inventory{purlHomebrewInventoryProto},
Findings: []*spb.Finding{},
},
excludeForOS: []string{"windows", "linux"},
},
{
desc: "Successful containerd scan linux-only",
res: &scalibr.ScanResult{
Expand Down
4 changes: 4 additions & 0 deletions binary/proto/scan_result.proto
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ message Inventory {
25;
CDXPackageMetadata cdx_metadata = 30;
WindowsOSVersion windows_os_version_metadata = 33;
HomebrewPackageMetadata homebrew_metadata = 42;
}

repeated AnnotationEnum annotations = 28;
Expand Down Expand Up @@ -455,3 +456,6 @@ message WindowsOSVersion {
string product = 1;
string full_version = 2;
}

// The additional data found in Homebrew packages.
message HomebrewPackageMetadata {}
Loading