use zero value for nils in ID generation

Signed-off-by: Alex Goodman <alex.goodman@anchore.com>
This commit is contained in:
Alex Goodman 2021-11-09 17:26:38 -05:00
parent 1537e73083
commit 2356539ebe
No known key found for this signature in database
GPG Key ID: 5CB45AE22BAB7EA7
2 changed files with 13 additions and 14 deletions

View File

@ -1,7 +1,7 @@
{ {
"artifacts": [ "artifacts": [
{ {
"id": "810333194629225077", "id": "14696638697550896878",
"name": "package-1", "name": "package-1",
"version": "1.0.1", "version": "1.0.1",
"type": "python", "type": "python",

View File

@ -15,18 +15,17 @@ import (
// Package represents an application or library that has been bundled into a distributable format. // Package represents an application or library that has been bundled into a distributable format.
// TODO: if we ignore FoundBy for ID generation should we merge the field to show it was found in two places? // TODO: if we ignore FoundBy for ID generation should we merge the field to show it was found in two places?
type Package struct { type Package struct {
Name string // the package name Name string // the package name
Version string // the version of the package Version string // the version of the package
FoundBy string // the specific cataloger that discovered this package FoundBy string // the specific cataloger that discovered this package
Locations []source.Location // the locations that lead to the discovery of this package (note: this is not necessarily the locations that make up this package) Locations []source.Location // the locations that lead to the discovery of this package (note: this is not necessarily the locations that make up this package)
// TODO: should we move licenses into metadata? Licenses []string // licenses discovered with the package metadata
Licenses []string // licenses discovered with the package metadata Language Language // the language ecosystem this package belongs to (e.g. JavaScript, Python, etc)
Language Language // the language ecosystem this package belongs to (e.g. JavaScript, Python, etc) Type Type // the package type (e.g. Npm, Yarn, Python, Rpm, Deb, etc)
Type Type // the package type (e.g. Npm, Yarn, Python, Rpm, Deb, etc) CPEs []CPE // all possible Common Platform Enumerators
CPEs []CPE // all possible Common Platform Enumerators PURL string // the Package URL (see https://github.com/package-url/purl-spec)
PURL string // the Package URL (see https://github.com/package-url/purl-spec) MetadataType MetadataType // the shape of the additional data in the "metadata" field
MetadataType MetadataType // the shape of the additional data in the "metadata" field Metadata interface{} // additional data found while parsing the package source
Metadata interface{} // additional data found while parsing the package source
} }
func (p Package) ID() artifact.ID { func (p Package) ID() artifact.ID {
@ -47,7 +46,7 @@ func (p Package) String() string {
func (p Package) Fingerprint() (string, error) { func (p Package) Fingerprint() (string, error) {
f, err := hashstructure.Hash(p, hashstructure.FormatV2, &hashstructure.HashOptions{ f, err := hashstructure.Hash(p, hashstructure.FormatV2, &hashstructure.HashOptions{
//ZeroNil: true, ZeroNil: true,
SlicesAsSets: true, SlicesAsSets: true,
}) })
if err != nil { if err != nil {