Skip to content

Commit

Permalink
Add portage support for Gentoo Linux (#1076)
Browse files Browse the repository at this point in the history
Co-authored-by: Christopher Phillips <christopher.phillips@anchore.com>
  • Loading branch information
zmedico and spiffcs committed Jul 6, 2022
1 parent ba685ea commit 4c55c62
Show file tree
Hide file tree
Showing 27 changed files with 1,836 additions and 23 deletions.
2 changes: 1 addition & 1 deletion internal/constants.go
Expand Up @@ -6,5 +6,5 @@ const (

// JSONSchemaVersion is the current schema version output by the JSON encoder
// This is roughly following the "SchemaVer" guidelines for versioning the JSON schema. Please see schema/json/README.md for details on how to increment.
JSONSchemaVersion = "3.3.0"
JSONSchemaVersion = "3.3.1"
)
2 changes: 2 additions & 0 deletions internal/formats/common/spdxhelpers/source_info.go
Expand Up @@ -37,6 +37,8 @@ func SourceInfo(p pkg.Package) string {
answer = "acquired package info from PHP composer manifest"
case pkg.ConanPkg:
answer = "acquired package info from conan manifest"
case pkg.PortagePkg:
answer = "acquired package info from portage DB"
default:
answer = "acquired package info from the following paths"
}
Expand Down
8 changes: 8 additions & 0 deletions internal/formats/common/spdxhelpers/source_info_test.go
Expand Up @@ -158,6 +158,14 @@ func Test_SourceInfo(t *testing.T) {
"from conan manifest",
},
},
{
input: pkg.Package{
Type: pkg.PortagePkg,
},
expected: []string{
"from portage DB",
},
},
}
var pkgTypes []pkg.Type
for _, test := range tests {
Expand Down
6 changes: 6 additions & 0 deletions internal/formats/syftjson/model/package.go
Expand Up @@ -157,6 +157,12 @@ func unpackMetadata(p *Package, unpacker packageMetadataUnpacker) error {
return err
}
p.Metadata = payload
case pkg.PortageMetadataType:
var payload pkg.PortageMetadata
if err := json.Unmarshal(unpacker.Metadata, &payload); err != nil {
return err
}
p.Metadata = payload
default:
log.Warnf("unknown package metadata type=%q for packageID=%q", p.MetadataType, p.ID)
}
Expand Down
Expand Up @@ -88,7 +88,7 @@
}
},
"schema": {
"version": "3.3.0",
"url": "https://raw.githubusercontent.com/anchore/syft/main/schema/json/schema-3.3.0.json"
"version": "3.3.1",
"url": "https://raw.githubusercontent.com/anchore/syft/main/schema/json/schema-3.3.1.json"
}
}
Expand Up @@ -184,7 +184,7 @@
}
},
"schema": {
"version": "3.3.0",
"url": "https://raw.githubusercontent.com/anchore/syft/main/schema/json/schema-3.3.0.json"
"version": "3.3.1",
"url": "https://raw.githubusercontent.com/anchore/syft/main/schema/json/schema-3.3.1.json"
}
}
Expand Up @@ -111,7 +111,7 @@
}
},
"schema": {
"version": "3.3.0",
"url": "https://raw.githubusercontent.com/anchore/syft/main/schema/json/schema-3.3.0.json"
"version": "3.3.1",
"url": "https://raw.githubusercontent.com/anchore/syft/main/schema/json/schema-3.3.1.json"
}
}
4 changes: 2 additions & 2 deletions schema/json/README.md
Expand Up @@ -25,7 +25,7 @@ Given a version number format `MODEL.REVISION.ADDITION`:
When adding a new `pkg.*Metadata` that is assigned to the `pkg.Package.Metadata` struct field it is important that a few things
are done:

- a new integration test case is added to `test/integration/pkg_cases_test.go` that exercises the new package type with the new metadata
- a new integration test case is added to `test/integration/catalog_packages_cases_test.go` that exercises the new package type with the new metadata
- the new metadata struct is added to the `artifactMetadataContainer` struct within `schema/json/generate.go`

## Generating a New Schema
Expand All @@ -36,4 +36,4 @@ Create the new schema by running `cd schema/json && go run generate.go` (note yo
- If there is an existing schema for the given version and the new schema matches the existing schema, no action is taken
- If there is an existing schema for the given version and the new schema **does not** match the existing schema, an error is shown indicating to increment the version appropriately (see the "Versioning" section)

***Note: never delete a JSON schema and never change an existing JSON schema once it has been published in a release!*** Only add new schemas with a newly incremented version. All previous schema files must be stored in the `schema/json/` directory.
***Note: never delete a JSON schema and never change an existing JSON schema once it has been published in a release!*** Only add new schemas with a newly incremented version. All previous schema files must be stored in the `schema/json/` directory.
27 changes: 14 additions & 13 deletions schema/json/generate.go
Expand Up @@ -27,19 +27,20 @@ can be extended to include specific package metadata struct shapes in the future
// When a new package metadata definition is created it will need to be manually added here. The variable name does
// not matter as long as it is exported.
type artifactMetadataContainer struct {
Apk pkg.ApkMetadata
Alpm pkg.AlpmMetadata
Dpkg pkg.DpkgMetadata
Gem pkg.GemMetadata
Java pkg.JavaMetadata
Npm pkg.NpmPackageJSONMetadata
Python pkg.PythonPackageMetadata
Rpm pkg.RpmdbMetadata
Cargo pkg.CargoPackageMetadata
Go pkg.GolangBinMetadata
Php pkg.PhpComposerJSONMetadata
Dart pkg.DartPubMetadata
Dotnet pkg.DotnetDepsMetadata
Apk pkg.ApkMetadata
Alpm pkg.AlpmMetadata
Dpkg pkg.DpkgMetadata
Gem pkg.GemMetadata
Java pkg.JavaMetadata
Npm pkg.NpmPackageJSONMetadata
Python pkg.PythonPackageMetadata
Rpm pkg.RpmdbMetadata
Cargo pkg.CargoPackageMetadata
Go pkg.GolangBinMetadata
Php pkg.PhpComposerJSONMetadata
Dart pkg.DartPubMetadata
Dotnet pkg.DotnetDepsMetadata
Portage pkg.PortageMetadata
}

func main() {
Expand Down

0 comments on commit 4c55c62

Please sign in to comment.