Skip to content

Commit

Permalink
FIX: Adding metadata template
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 720795333
  • Loading branch information
SCALIBR Team authored and copybara-github committed Jan 30, 2025
1 parent 358fcf5 commit 930becd
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 0 deletions.
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{

Check failure on line 389 in binary/proto/proto.go

View workflow job for this annotation

GitHub Actions / lint

undefined: spb.Inventory_HomebrewMetadata

Check failure on line 389 in binary/proto/proto.go

View workflow job for this annotation

GitHub Actions / lint

undefined: spb.Inventory_HomebrewMetadata

Check failure on line 389 in binary/proto/proto.go

View workflow job for this annotation

GitHub Actions / lint

undefined: spb.Inventory_HomebrewMetadata

Check failure on line 389 in binary/proto/proto.go

View workflow job for this annotation

GitHub Actions / lint-just-new

undefined: spb.Inventory_HomebrewMetadata

Check failure on line 389 in binary/proto/proto.go

View workflow job for this annotation

GitHub Actions / lint-just-new

undefined: spb.Inventory_HomebrewMetadata

Check failure on line 389 in binary/proto/proto.go

View workflow job for this annotation

GitHub Actions / lint-just-new

undefined: spb.Inventory_HomebrewMetadata

Check failure on line 389 in binary/proto/proto.go

View workflow job for this annotation

GitHub Actions / tests (ubuntu-latest)

undefined: spb.Inventory_HomebrewMetadata

Check failure on line 389 in binary/proto/proto.go

View workflow job for this annotation

GitHub Actions / tests (macos-latest)

undefined: spb.Inventory_HomebrewMetadata

Check failure on line 389 in binary/proto/proto.go

View workflow job for this annotation

GitHub Actions / tests (windows-latest)

undefined: spb.Inventory_HomebrewMetadata
HomebrewMetadata: &spb.HomebrewPackageMetadata{},

Check failure on line 390 in binary/proto/proto.go

View workflow job for this annotation

GitHub Actions / lint

undefined: spb.HomebrewPackageMetadata) (typecheck)

Check failure on line 390 in binary/proto/proto.go

View workflow job for this annotation

GitHub Actions / lint

undefined: spb.HomebrewPackageMetadata (typecheck)

Check failure on line 390 in binary/proto/proto.go

View workflow job for this annotation

GitHub Actions / lint

undefined: spb.HomebrewPackageMetadata) (typecheck)

Check failure on line 390 in binary/proto/proto.go

View workflow job for this annotation

GitHub Actions / lint-just-new

undefined: spb.HomebrewPackageMetadata) (typecheck)

Check failure on line 390 in binary/proto/proto.go

View workflow job for this annotation

GitHub Actions / lint-just-new

undefined: spb.HomebrewPackageMetadata (typecheck)

Check failure on line 390 in binary/proto/proto.go

View workflow job for this annotation

GitHub Actions / lint-just-new

undefined: spb.HomebrewPackageMetadata) (typecheck)

Check failure on line 390 in binary/proto/proto.go

View workflow job for this annotation

GitHub Actions / tests (ubuntu-latest)

undefined: spb.HomebrewPackageMetadata

Check failure on line 390 in binary/proto/proto.go

View workflow job for this annotation

GitHub Actions / tests (macos-latest)

undefined: spb.HomebrewPackageMetadata

Check failure on line 390 in binary/proto/proto.go

View workflow job for this annotation

GitHub Actions / tests (windows-latest)

undefined: spb.HomebrewPackageMetadata
}
case *module.Metadata:
i.Metadata = &spb.Inventory_KernelModuleMetadata{
KernelModuleMetadata: &spb.KernelModuleMetadata{
Expand Down
55 changes: 55 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,27 @@ 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",
},
Ecosystem: "brew",
Metadata: &spb.Inventory_HomebrewMetadata{},

Check failure on line 608 in binary/proto/proto_test.go

View workflow job for this annotation

GitHub Actions / lint

undefined: spb.Inventory_HomebrewMetadata (typecheck)

Check failure on line 608 in binary/proto/proto_test.go

View workflow job for this annotation

GitHub Actions / lint-just-new

undefined: spb.Inventory_HomebrewMetadata (typecheck)
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 @@ -972,6 +994,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 {}
1 change: 1 addition & 0 deletions extractor/filesystem/os/homebrew/homebrew.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ func (e Extractor) Extract(ctx context.Context, input *filesystem.ScanInput) ([]
Name: p.AppName,
Version: p.AppVersion,
Locations: []string{input.Path},
Metadata: &Metadata{},
},
}, nil
}
Expand Down
3 changes: 3 additions & 0 deletions extractor/filesystem/os/homebrew/homebrew_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ func TestExtract(t *testing.T) {
Name: "rclone",
Version: "1.67.0",
Locations: []string{"testdata/Cellar/rclone/1.67.0/INSTALL_RECEIPT.json"},
Metadata: &homebrew.Metadata{},
},
},
},
Expand All @@ -135,6 +136,7 @@ func TestExtract(t *testing.T) {
Name: "testapp",
Version: "1.1.1",
Locations: []string{"testdata/Caskroom/testapp/1.1.1/testapp.wrapper.sh"},
Metadata: &homebrew.Metadata{},
},
},
},
Expand All @@ -151,6 +153,7 @@ func TestExtract(t *testing.T) {
Name: "android-platform-tools",
Version: "35.0.2",
Locations: []string{"testdata/Caskroom/android-platform-tools/35.0.2/platform-tools/source.properties"},
Metadata: &homebrew.Metadata{},
},
},
},
Expand Down
18 changes: 18 additions & 0 deletions extractor/filesystem/os/homebrew/metadata.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright 2025 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package homebrew

// Metadata is the metadata struct for information relating to the homebrew package.
type Metadata struct{}

0 comments on commit 930becd

Please sign in to comment.