mirror of
https://github.com/anchore/syft.git
synced 2025-11-17 08:23:15 +01:00
dont export structs used for unmarshaling
Signed-off-by: Alex Goodman <alex.goodman@anchore.com>
This commit is contained in:
parent
4b45c42f5a
commit
62b03f3a91
@ -9,11 +9,11 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type Artifact struct {
|
type Artifact struct {
|
||||||
ArtifactBasicMetadata
|
artifactBasicMetadata
|
||||||
ArtifactCustomMetadata
|
artifactCustomMetadata
|
||||||
}
|
}
|
||||||
|
|
||||||
type ArtifactBasicMetadata struct {
|
type artifactBasicMetadata struct {
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Version string `json:"version"`
|
Version string `json:"version"`
|
||||||
Type pkg.Type `json:"type"`
|
Type pkg.Type `json:"type"`
|
||||||
@ -23,12 +23,12 @@ type ArtifactBasicMetadata struct {
|
|||||||
Language pkg.Language `json:"language"`
|
Language pkg.Language `json:"language"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type ArtifactCustomMetadata struct {
|
type artifactCustomMetadata struct {
|
||||||
MetadataType pkg.MetadataType `json:"metadataType"`
|
MetadataType pkg.MetadataType `json:"metadataType"`
|
||||||
Metadata interface{} `json:"metadata,omitempty"`
|
Metadata interface{} `json:"metadata,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type ArtifactMetadataUnpacker struct {
|
type artifactMetadataUnpacker struct {
|
||||||
MetadataType string `json:"metadataType"`
|
MetadataType string `json:"metadataType"`
|
||||||
Metadata json.RawMessage `json:"metadata"`
|
Metadata json.RawMessage `json:"metadata"`
|
||||||
}
|
}
|
||||||
@ -36,7 +36,7 @@ type ArtifactMetadataUnpacker struct {
|
|||||||
func NewArtifact(p *pkg.Package) (Artifact, error) {
|
func NewArtifact(p *pkg.Package) (Artifact, error) {
|
||||||
|
|
||||||
return Artifact{
|
return Artifact{
|
||||||
ArtifactBasicMetadata: ArtifactBasicMetadata{
|
artifactBasicMetadata: artifactBasicMetadata{
|
||||||
Name: p.Name,
|
Name: p.Name,
|
||||||
Version: p.Version,
|
Version: p.Version,
|
||||||
Type: p.Type,
|
Type: p.Type,
|
||||||
@ -45,7 +45,7 @@ func NewArtifact(p *pkg.Package) (Artifact, error) {
|
|||||||
Licenses: p.Licenses,
|
Licenses: p.Licenses,
|
||||||
Language: p.Language,
|
Language: p.Language,
|
||||||
},
|
},
|
||||||
ArtifactCustomMetadata: ArtifactCustomMetadata{
|
artifactCustomMetadata: artifactCustomMetadata{
|
||||||
MetadataType: p.MetadataType,
|
MetadataType: p.MetadataType,
|
||||||
Metadata: p.Metadata,
|
Metadata: p.Metadata,
|
||||||
},
|
},
|
||||||
@ -68,13 +68,13 @@ func (a Artifact) ToPackage() pkg.Package {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (a *Artifact) UnmarshalJSON(b []byte) error {
|
func (a *Artifact) UnmarshalJSON(b []byte) error {
|
||||||
var basic ArtifactBasicMetadata
|
var basic artifactBasicMetadata
|
||||||
if err := json.Unmarshal(b, &basic); err != nil {
|
if err := json.Unmarshal(b, &basic); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
a.ArtifactBasicMetadata = basic
|
a.artifactBasicMetadata = basic
|
||||||
|
|
||||||
var unpacker ArtifactMetadataUnpacker
|
var unpacker artifactMetadataUnpacker
|
||||||
if err := json.Unmarshal(b, &unpacker); err != nil {
|
if err := json.Unmarshal(b, &unpacker); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,13 +2,14 @@ package json
|
|||||||
|
|
||||||
import "github.com/anchore/syft/syft/distro"
|
import "github.com/anchore/syft/syft/distro"
|
||||||
|
|
||||||
// Distribution provides information about a detected Linux Distribution
|
// Distribution provides information about a detected Linux Distribution.
|
||||||
type Distribution struct {
|
type Distribution struct {
|
||||||
Name string `json:"name"`
|
Name string `json:"name"` // Name of the Linux distribution
|
||||||
Version string `json:"version"`
|
Version string `json:"version"` // Version of the Linux distribution (major or major.minor version)
|
||||||
IDLike string `json:"idLike"`
|
IDLike string `json:"idLike"` // the ID_LIKE field found within the /etc/os-release file
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewDistribution creates a struct with the Linux distribution to be represented in JSON.
|
||||||
func NewDistribution(d distro.Distro) Distribution {
|
func NewDistribution(d distro.Distro) Distribution {
|
||||||
distroName := d.Name()
|
distroName := d.Name()
|
||||||
if distroName == "UnknownDistroType" {
|
if distroName == "UnknownDistroType" {
|
||||||
|
|||||||
@ -8,13 +8,15 @@ import (
|
|||||||
"github.com/anchore/syft/syft/source"
|
"github.com/anchore/syft/syft/source"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Document represents the syft cataloging findings as a JSON document
|
||||||
type Document struct {
|
type Document struct {
|
||||||
Artifacts []Artifact `json:"artifacts"`
|
Artifacts []Artifact `json:"artifacts"` // Artifacts is the list of packages discovered and placed into the catalog
|
||||||
Source Source `json:"source"`
|
Source Source `json:"source"` // Source represents the original object that was cataloged
|
||||||
Distro Distribution `json:"distro"`
|
Distro Distribution `json:"distro"` // Distro represents the Linux distribution that was detected from the source
|
||||||
Descriptor Descriptor `json:"descriptor"`
|
Descriptor Descriptor `json:"descriptor"` // Descriptor is a block containing self-describing information about syft
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewDocument creates and populates a new JSON document struct from the given cataloging results.
|
||||||
func NewDocument(catalog *pkg.Catalog, srcMetadata source.Metadata, d distro.Distro) (Document, error) {
|
func NewDocument(catalog *pkg.Catalog, srcMetadata source.Metadata, d distro.Distro) (Document, error) {
|
||||||
src, err := NewSource(srcMetadata)
|
src, err := NewSource(srcMetadata)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@ -9,12 +9,14 @@ import (
|
|||||||
"github.com/anchore/syft/syft/source"
|
"github.com/anchore/syft/syft/source"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Presenter is a JSON presentation object for the syft results
|
||||||
type Presenter struct {
|
type Presenter struct {
|
||||||
catalog *pkg.Catalog
|
catalog *pkg.Catalog
|
||||||
srcMetadata source.Metadata
|
srcMetadata source.Metadata
|
||||||
distro distro.Distro
|
distro distro.Distro
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewPresenter creates a new JSON presenter object for the given cataloging results.
|
||||||
func NewPresenter(catalog *pkg.Catalog, s source.Metadata, d distro.Distro) *Presenter {
|
func NewPresenter(catalog *pkg.Catalog, s source.Metadata, d distro.Distro) *Presenter {
|
||||||
return &Presenter{
|
return &Presenter{
|
||||||
catalog: catalog,
|
catalog: catalog,
|
||||||
@ -23,6 +25,7 @@ func NewPresenter(catalog *pkg.Catalog, s source.Metadata, d distro.Distro) *Pre
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Present the catalog results to the given writer.
|
||||||
func (pres *Presenter) Present(output io.Writer) error {
|
func (pres *Presenter) Present(output io.Writer) error {
|
||||||
doc, err := NewDocument(pres.catalog, pres.srcMetadata, pres.distro)
|
doc, err := NewDocument(pres.catalog, pres.srcMetadata, pres.distro)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@ -7,16 +7,19 @@ import (
|
|||||||
"github.com/anchore/syft/syft/source"
|
"github.com/anchore/syft/syft/source"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Source object represents the thing that was cataloged
|
||||||
type Source struct {
|
type Source struct {
|
||||||
Type string `json:"type"`
|
Type string `json:"type"`
|
||||||
Target interface{} `json:"target"`
|
Target interface{} `json:"target"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type SourceUnpacker struct {
|
// sourceUnpacker is used to unmarshal Source objects
|
||||||
|
type sourceUnpacker struct {
|
||||||
Type string `json:"type"`
|
Type string `json:"type"`
|
||||||
Target json.RawMessage `json:"target"`
|
Target json.RawMessage `json:"target"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewSource creates a new source object to be represented into JSON.
|
||||||
func NewSource(src source.Metadata) (Source, error) {
|
func NewSource(src source.Metadata) (Source, error) {
|
||||||
switch src.Scheme {
|
switch src.Scheme {
|
||||||
case source.ImageScheme:
|
case source.ImageScheme:
|
||||||
@ -34,8 +37,9 @@ func NewSource(src source.Metadata) (Source, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// UnmarshalJSON populates a source object from JSON bytes.
|
||||||
func (s *Source) UnmarshalJSON(b []byte) error {
|
func (s *Source) UnmarshalJSON(b []byte) error {
|
||||||
var unpacker SourceUnpacker
|
var unpacker sourceUnpacker
|
||||||
if err := json.Unmarshal(b, &unpacker); err != nil {
|
if err := json.Unmarshal(b, &unpacker); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -57,6 +61,7 @@ func (s *Source) UnmarshalJSON(b []byte) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ToSourceMetadata takes a source object represented from JSON and creates a source.Metadata object.
|
||||||
func (s *Source) ToSourceMetadata() source.Metadata {
|
func (s *Source) ToSourceMetadata() source.Metadata {
|
||||||
var metadata source.Metadata
|
var metadata source.Metadata
|
||||||
switch s.Type {
|
switch s.Type {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user