mirror of
https://github.com/anchore/syft.git
synced 2025-11-17 16:33:21 +01:00
rename json artifact to package + update resolver integrity checks
Signed-off-by: Alex Goodman <alex.goodman@anchore.com>
This commit is contained in:
parent
569a598df7
commit
030427bb33
@ -8,12 +8,14 @@ import (
|
||||
"github.com/anchore/syft/syft/source"
|
||||
)
|
||||
|
||||
type Artifact struct {
|
||||
artifactBasicMetadata
|
||||
artifactCustomMetadata
|
||||
// Package represents a pkg.Package object specialized for JSON marshaling and unmarshaling.
|
||||
type Package struct {
|
||||
packageBasicMetadata
|
||||
packageCustomMetadata
|
||||
}
|
||||
|
||||
type artifactBasicMetadata struct {
|
||||
// packageBasicMetadata contains non-ambiguous values (type-wise) from pkg.Package.
|
||||
type packageBasicMetadata struct {
|
||||
Name string `json:"name"`
|
||||
Version string `json:"version"`
|
||||
Type pkg.Type `json:"type"`
|
||||
@ -23,19 +25,22 @@ type artifactBasicMetadata struct {
|
||||
Language pkg.Language `json:"language"`
|
||||
}
|
||||
|
||||
type artifactCustomMetadata struct {
|
||||
// packageCustomMetadata contains ambiguous values (type-wise) from pkg.Package.
|
||||
type packageCustomMetadata struct {
|
||||
MetadataType pkg.MetadataType `json:"metadataType"`
|
||||
Metadata interface{} `json:"metadata,omitempty"`
|
||||
}
|
||||
|
||||
type artifactMetadataUnpacker struct {
|
||||
// packageMetadataUnpacker is all values needed from Package to disambiguate ambiguous fields during json unmarshaling.
|
||||
type packageMetadataUnpacker struct {
|
||||
MetadataType string `json:"metadataType"`
|
||||
Metadata json.RawMessage `json:"metadata"`
|
||||
}
|
||||
|
||||
func NewArtifact(p *pkg.Package) (Artifact, error) {
|
||||
return Artifact{
|
||||
artifactBasicMetadata: artifactBasicMetadata{
|
||||
// NewPackage crates a new Package from the given pkg.Package.
|
||||
func NewPackage(p *pkg.Package) (Package, error) {
|
||||
return Package{
|
||||
packageBasicMetadata: packageBasicMetadata{
|
||||
Name: p.Name,
|
||||
Version: p.Version,
|
||||
Type: p.Type,
|
||||
@ -44,14 +49,15 @@ func NewArtifact(p *pkg.Package) (Artifact, error) {
|
||||
Licenses: p.Licenses,
|
||||
Language: p.Language,
|
||||
},
|
||||
artifactCustomMetadata: artifactCustomMetadata{
|
||||
packageCustomMetadata: packageCustomMetadata{
|
||||
MetadataType: p.MetadataType,
|
||||
Metadata: p.Metadata,
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (a Artifact) ToPackage() pkg.Package {
|
||||
// ToPackage generates a pkg.Package from the current Package.
|
||||
func (a Package) ToPackage() pkg.Package {
|
||||
return pkg.Package{
|
||||
// does not include found-by and locations
|
||||
Name: a.Name,
|
||||
@ -66,15 +72,16 @@ func (a Artifact) ToPackage() pkg.Package {
|
||||
}
|
||||
}
|
||||
|
||||
// UnmarshalJSON is a custom unmarshaller for handling basic values and values with ambiguous types.
|
||||
// nolint:funlen
|
||||
func (a *Artifact) UnmarshalJSON(b []byte) error {
|
||||
var basic artifactBasicMetadata
|
||||
func (a *Package) UnmarshalJSON(b []byte) error {
|
||||
var basic packageBasicMetadata
|
||||
if err := json.Unmarshal(b, &basic); err != nil {
|
||||
return err
|
||||
}
|
||||
a.artifactBasicMetadata = basic
|
||||
a.packageBasicMetadata = basic
|
||||
|
||||
var unpacker artifactMetadataUnpacker
|
||||
var unpacker packageMetadataUnpacker
|
||||
if err := json.Unmarshal(b, &unpacker); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@ -10,7 +10,7 @@ import (
|
||||
|
||||
// Document represents the syft cataloging findings as a JSON document
|
||||
type Document struct {
|
||||
Artifacts []Artifact `json:"artifacts"` // Artifacts is the list of packages discovered and placed into the catalog
|
||||
Artifacts []Package `json:"artifacts"` // Artifacts is the list of packages discovered and placed into the catalog
|
||||
Source Source `json:"source"` // Source represents the original object that was cataloged
|
||||
Distro Distribution `json:"distro"` // Distro represents the Linux distribution that was detected from the source
|
||||
Descriptor Descriptor `json:"descriptor"` // Descriptor is a block containing self-describing information about syft
|
||||
@ -24,7 +24,7 @@ func NewDocument(catalog *pkg.Catalog, srcMetadata source.Metadata, d distro.Dis
|
||||
}
|
||||
|
||||
doc := Document{
|
||||
Artifacts: make([]Artifact, 0),
|
||||
Artifacts: make([]Package, 0),
|
||||
Source: src,
|
||||
Distro: NewDistribution(d),
|
||||
Descriptor: Descriptor{
|
||||
@ -34,7 +34,7 @@ func NewDocument(catalog *pkg.Catalog, srcMetadata source.Metadata, d distro.Dis
|
||||
}
|
||||
|
||||
for _, p := range catalog.Sorted() {
|
||||
art, err := NewArtifact(p)
|
||||
art, err := NewPackage(p)
|
||||
if err != nil {
|
||||
return Document{}, err
|
||||
}
|
||||
|
||||
@ -8,7 +8,7 @@ import (
|
||||
"github.com/anchore/stereoscope/pkg/image"
|
||||
)
|
||||
|
||||
var _ Resolver = &AllLayersResolver{}
|
||||
var _ Resolver = (*AllLayersResolver)(nil)
|
||||
|
||||
// AllLayersResolver implements path and content access for the AllLayers source option for container image data sources.
|
||||
type AllLayersResolver struct {
|
||||
|
||||
@ -11,7 +11,7 @@ import (
|
||||
"github.com/bmatcuk/doublestar"
|
||||
)
|
||||
|
||||
var _ Resolver = &DirectoryResolver{}
|
||||
var _ Resolver = (*DirectoryResolver)(nil)
|
||||
|
||||
// DirectoryResolver implements path and content access for the directory data source.
|
||||
type DirectoryResolver struct {
|
||||
|
||||
@ -7,7 +7,7 @@ import (
|
||||
"github.com/anchore/stereoscope/pkg/image"
|
||||
)
|
||||
|
||||
var _ Resolver = &ImageSquashResolver{}
|
||||
var _ Resolver = (*ImageSquashResolver)(nil)
|
||||
|
||||
// ImageSquashResolver implements path and content access for the Squashed source option for container image data sources.
|
||||
type ImageSquashResolver struct {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user