mirror of
https://github.com/anchore/syft.git
synced 2026-11-02 23:46:35 +01:00
Replace distro type (#742)
* remove strong distro type Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * bump json schema to v3 (breaking distro shape) Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * fix linting Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * allow for v2 decoding of distro idLikes field in v3 json decoder Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * fix casing in simple linux release name Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * use discovered name as pretty name in simple linux release Signed-off-by: Alex Goodman <alex.goodman@anchore.com>
This commit is contained in:
@@ -8,7 +8,7 @@ import (
|
||||
)
|
||||
|
||||
func encoder(output io.Writer, s sbom.SBOM) error {
|
||||
doc := toFormatModel(s)
|
||||
doc := ToFormatModel(s)
|
||||
|
||||
enc := json.NewEncoder(output)
|
||||
// prevent > and < from being escaped in the payload
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
|
||||
"github.com/anchore/syft/syft/artifact"
|
||||
|
||||
"github.com/anchore/syft/syft/distro"
|
||||
"github.com/anchore/syft/syft/linux"
|
||||
"github.com/anchore/syft/syft/pkg"
|
||||
"github.com/anchore/syft/syft/sbom"
|
||||
"github.com/anchore/syft/syft/source"
|
||||
@@ -139,10 +139,13 @@ func TestEncodeFullJSONDocument(t *testing.T) {
|
||||
FileContents: map[source.Coordinates]string{
|
||||
source.NewLocation("/a/place/a").Coordinates: "the-contents",
|
||||
},
|
||||
Distro: &distro.Distro{
|
||||
Type: distro.RedHat,
|
||||
RawVersion: "7",
|
||||
IDLike: "rhel",
|
||||
LinuxDistribution: &linux.Release{
|
||||
ID: "redhat",
|
||||
Version: "7",
|
||||
VersionID: "7",
|
||||
IDLike: []string{
|
||||
"rhel",
|
||||
},
|
||||
},
|
||||
},
|
||||
Relationships: []artifact.Relationship{
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
package model
|
||||
|
||||
// Distro provides information about a detected Linux Distro.
|
||||
type Distro struct {
|
||||
Name string `json:"name"` // Name of the Linux distribution
|
||||
Version string `json:"version"` // Version of the Linux distribution (major or major.minor version)
|
||||
IDLike string `json:"idLike"` // the ID_LIKE field found within the /etc/os-release file
|
||||
}
|
||||
@@ -7,7 +7,7 @@ type Document struct {
|
||||
Files []File `json:"files,omitempty"` // note: must have omitempty
|
||||
Secrets []Secrets `json:"secrets,omitempty"` // note: must have omitempty
|
||||
Source Source `json:"source"` // Source represents the original object that was cataloged
|
||||
Distro Distro `json:"distro"` // Distro represents the Linux distribution that was detected from the source
|
||||
Distro LinuxRelease `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
|
||||
Schema Schema `json:"schema"` // Schema is a block reserved for defining the version for the shape of this JSON document and where to find the schema document to validate the shape
|
||||
}
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
)
|
||||
|
||||
type IDLikes []string
|
||||
|
||||
type LinuxRelease struct {
|
||||
PrettyName string `json:"prettyName,omitempty"`
|
||||
Name string `json:"name,omitempty"`
|
||||
ID string `json:"id,omitempty"`
|
||||
IDLike IDLikes `json:"idLike,omitempty"`
|
||||
Version string `json:"version,omitempty"`
|
||||
VersionID string `json:"versionID,omitempty"`
|
||||
Variant string `json:"variant,omitempty"`
|
||||
VariantID string `json:"variantID,omitempty"`
|
||||
HomeURL string `json:"homeURL,omitempty"`
|
||||
SupportURL string `json:"supportURL,omitempty"`
|
||||
BugReportURL string `json:"bugReportURL,omitempty"`
|
||||
PrivacyPolicyURL string `json:"privacyPolicyURL,omitempty"`
|
||||
CPEName string `json:"cpeName,omitempty"`
|
||||
}
|
||||
|
||||
func (s *IDLikes) UnmarshalJSON(data []byte) error {
|
||||
var str string
|
||||
var strSlice []string
|
||||
|
||||
// we support unmarshalling from a single value to support syft json schema v2
|
||||
if err := json.Unmarshal(data, &str); err == nil {
|
||||
*s = []string{str}
|
||||
} else if err := json.Unmarshal(data, &strSlice); err == nil {
|
||||
*s = strSlice
|
||||
} else {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestIDLikes_UnmarshalJSON(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
data interface{}
|
||||
expected IDLikes
|
||||
}{
|
||||
{
|
||||
name: "single string",
|
||||
data: "well hello there!",
|
||||
expected: IDLikes{
|
||||
"well hello there!",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "multiple strings",
|
||||
data: []string{
|
||||
"well hello there!",
|
||||
"...hello there, john!",
|
||||
},
|
||||
expected: IDLikes{
|
||||
"well hello there!",
|
||||
"...hello there, john!",
|
||||
},
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
data, err := json.Marshal(&tt.data)
|
||||
require.NoError(t, err)
|
||||
|
||||
var obj IDLikes
|
||||
require.NoError(t, json.Unmarshal(data, &obj))
|
||||
|
||||
assert.Equal(t, tt.expected, obj)
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -71,9 +71,14 @@
|
||||
"target": "/some/path"
|
||||
},
|
||||
"distro": {
|
||||
"prettyName": "debian",
|
||||
"name": "debian",
|
||||
"id": "debian",
|
||||
"idLike": [
|
||||
"like!"
|
||||
],
|
||||
"version": "1.2.3",
|
||||
"idLike": "like!"
|
||||
"versionID": "1.2.3"
|
||||
},
|
||||
"descriptor": {
|
||||
"name": "syft",
|
||||
@@ -83,7 +88,7 @@
|
||||
}
|
||||
},
|
||||
"schema": {
|
||||
"version": "2.0.2",
|
||||
"url": "https://raw.githubusercontent.com/anchore/syft/main/schema/json/schema-2.0.2.json"
|
||||
"version": "3.0.0",
|
||||
"url": "https://raw.githubusercontent.com/anchore/syft/main/schema/json/schema-3.0.0.json"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -167,9 +167,12 @@
|
||||
}
|
||||
},
|
||||
"distro": {
|
||||
"name": "redhat",
|
||||
"id": "redhat",
|
||||
"idLike": [
|
||||
"rhel"
|
||||
],
|
||||
"version": "7",
|
||||
"idLike": "rhel"
|
||||
"versionID": "7"
|
||||
},
|
||||
"descriptor": {
|
||||
"name": "syft",
|
||||
@@ -179,7 +182,7 @@
|
||||
}
|
||||
},
|
||||
"schema": {
|
||||
"version": "2.0.2",
|
||||
"url": "https://raw.githubusercontent.com/anchore/syft/main/schema/json/schema-2.0.2.json"
|
||||
"version": "3.0.0",
|
||||
"url": "https://raw.githubusercontent.com/anchore/syft/main/schema/json/schema-3.0.0.json"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"artifacts": [
|
||||
{
|
||||
"id": "d16127444133b5c1",
|
||||
"id": "d9527e708c11f8b9",
|
||||
"name": "package-1",
|
||||
"version": "1.0.1",
|
||||
"type": "python",
|
||||
@@ -9,7 +9,7 @@
|
||||
"locations": [
|
||||
{
|
||||
"path": "/somefile-1.txt",
|
||||
"layerID": "sha256:16e64541f2ddf59a90391ce7bb8af90313f7d373f2105d88f3d3267b72e0ebab"
|
||||
"layerID": "sha256:fb6beecb75b39f4bb813dbf177e501edd5ddb3e69bb45cedeb78c676ee1b7a59"
|
||||
}
|
||||
],
|
||||
"licenses": [
|
||||
@@ -32,7 +32,7 @@
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "24907357f3705420",
|
||||
"id": "73f796c846875b9e",
|
||||
"name": "package-2",
|
||||
"version": "2.0.1",
|
||||
"type": "deb",
|
||||
@@ -40,7 +40,7 @@
|
||||
"locations": [
|
||||
{
|
||||
"path": "/somefile-2.txt",
|
||||
"layerID": "sha256:de6c235f76ea24c8503ec08891445b5d6a8bdf8249117ed8d8b0b6fb3ebe4f67"
|
||||
"layerID": "sha256:319b588ce64253a87b533c8ed01cf0025e0eac98e7b516e12532957e1244fdec"
|
||||
}
|
||||
],
|
||||
"licenses": [],
|
||||
@@ -67,7 +67,7 @@
|
||||
"type": "image",
|
||||
"target": {
|
||||
"userInput": "user-image-input",
|
||||
"imageID": "sha256:9624b89704d23fa5f61b427379d172dac91dc7a508c4d7dea7aed0e04a4cf39e",
|
||||
"imageID": "sha256:2480160b55bec40c44d3b145c7b2c1c47160db8575c3dcae086d76b9370ae7ca",
|
||||
"manifestDigest": "sha256:2731251dc34951c0e50fcc643b4c5f74922dad1a5d98f302b504cf46cd5d9368",
|
||||
"mediaType": "application/vnd.docker.distribution.manifest.v2+json",
|
||||
"tags": [
|
||||
@@ -77,24 +77,29 @@
|
||||
"layers": [
|
||||
{
|
||||
"mediaType": "application/vnd.docker.image.rootfs.diff.tar.gzip",
|
||||
"digest": "sha256:16e64541f2ddf59a90391ce7bb8af90313f7d373f2105d88f3d3267b72e0ebab",
|
||||
"digest": "sha256:fb6beecb75b39f4bb813dbf177e501edd5ddb3e69bb45cedeb78c676ee1b7a59",
|
||||
"size": 22
|
||||
},
|
||||
{
|
||||
"mediaType": "application/vnd.docker.image.rootfs.diff.tar.gzip",
|
||||
"digest": "sha256:de6c235f76ea24c8503ec08891445b5d6a8bdf8249117ed8d8b0b6fb3ebe4f67",
|
||||
"digest": "sha256:319b588ce64253a87b533c8ed01cf0025e0eac98e7b516e12532957e1244fdec",
|
||||
"size": 16
|
||||
}
|
||||
],
|
||||
"manifest": "eyJzY2hlbWFWZXJzaW9uIjoyLCJtZWRpYVR5cGUiOiJhcHBsaWNhdGlvbi92bmQuZG9ja2VyLmRpc3RyaWJ1dGlvbi5tYW5pZmVzdC52Mitqc29uIiwiY29uZmlnIjp7Im1lZGlhVHlwZSI6ImFwcGxpY2F0aW9uL3ZuZC5kb2NrZXIuY29udGFpbmVyLmltYWdlLnYxK2pzb24iLCJzaXplIjo2NjcsImRpZ2VzdCI6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oDigests": []
|
||||
}
|
||||
},
|
||||
"distro": {
|
||||
"prettyName": "debian",
|
||||
"name": "debian",
|
||||
"id": "debian",
|
||||
"idLike": [
|
||||
"like!"
|
||||
],
|
||||
"version": "1.2.3",
|
||||
"idLike": "like!"
|
||||
"versionID": "1.2.3"
|
||||
},
|
||||
"descriptor": {
|
||||
"name": "syft",
|
||||
@@ -104,7 +109,7 @@
|
||||
}
|
||||
},
|
||||
"schema": {
|
||||
"version": "2.0.2",
|
||||
"url": "https://raw.githubusercontent.com/anchore/syft/main/schema/json/schema-2.0.2.json"
|
||||
"version": "3.0.0",
|
||||
"url": "https://raw.githubusercontent.com/anchore/syft/main/schema/json/schema-3.0.0.json"
|
||||
}
|
||||
}
|
||||
|
||||
BIN
Binary file not shown.
@@ -5,6 +5,8 @@ import (
|
||||
"sort"
|
||||
"strconv"
|
||||
|
||||
"github.com/anchore/syft/syft/linux"
|
||||
|
||||
"github.com/anchore/syft/syft/file"
|
||||
|
||||
"github.com/anchore/syft/syft/artifact"
|
||||
@@ -14,12 +16,14 @@ import (
|
||||
"github.com/anchore/syft/internal"
|
||||
"github.com/anchore/syft/internal/formats/syftjson/model"
|
||||
"github.com/anchore/syft/internal/log"
|
||||
"github.com/anchore/syft/syft/distro"
|
||||
"github.com/anchore/syft/syft/pkg"
|
||||
"github.com/anchore/syft/syft/source"
|
||||
)
|
||||
|
||||
func toFormatModel(s sbom.SBOM) model.Document {
|
||||
// ToFormatModel transforms the sbom import a format-specific model.
|
||||
// note: this is needed for anchore import functionality
|
||||
// TODO: unexport this when/if anchore import functionality is removed
|
||||
func ToFormatModel(s sbom.SBOM) model.Document {
|
||||
src, err := toSourceModel(s.Source)
|
||||
if err != nil {
|
||||
log.Warnf("unable to create syft-json source object: %+v", err)
|
||||
@@ -31,7 +35,7 @@ func toFormatModel(s sbom.SBOM) model.Document {
|
||||
Files: toFile(s),
|
||||
Secrets: toSecrets(s.Artifacts.Secrets),
|
||||
Source: src,
|
||||
Distro: toDistroModel(s.Artifacts.Distro),
|
||||
Distro: toLinuxReleaser(s.Artifacts.LinuxDistribution),
|
||||
Descriptor: toDescriptor(s.Descriptor),
|
||||
Schema: model.Schema{
|
||||
Version: internal.JSONSchemaVersion,
|
||||
@@ -40,6 +44,27 @@ func toFormatModel(s sbom.SBOM) model.Document {
|
||||
}
|
||||
}
|
||||
|
||||
func toLinuxReleaser(d *linux.Release) model.LinuxRelease {
|
||||
if d == nil {
|
||||
return model.LinuxRelease{}
|
||||
}
|
||||
return model.LinuxRelease{
|
||||
PrettyName: d.PrettyName,
|
||||
Name: d.Name,
|
||||
ID: d.ID,
|
||||
IDLike: d.IDLike,
|
||||
Version: d.Version,
|
||||
VersionID: d.VersionID,
|
||||
Variant: d.Variant,
|
||||
VariantID: d.VariantID,
|
||||
HomeURL: d.HomeURL,
|
||||
SupportURL: d.SupportURL,
|
||||
BugReportURL: d.BugReportURL,
|
||||
PrivacyPolicyURL: d.PrivacyPolicyURL,
|
||||
CPEName: d.CPEName,
|
||||
}
|
||||
}
|
||||
|
||||
func toDescriptor(d sbom.Descriptor) model.Descriptor {
|
||||
return model.Descriptor{
|
||||
Name: d.Name,
|
||||
@@ -210,16 +235,3 @@ func toSourceModel(src source.Metadata) (model.Source, error) {
|
||||
return model.Source{}, fmt.Errorf("unsupported source: %q", src.Scheme)
|
||||
}
|
||||
}
|
||||
|
||||
// toDistroModel creates a struct with the Linux distribution to be represented in JSON.
|
||||
func toDistroModel(d *distro.Distro) model.Distro {
|
||||
if d == nil {
|
||||
return model.Distro{}
|
||||
}
|
||||
|
||||
return model.Distro{
|
||||
Name: d.Name(),
|
||||
Version: d.FullVersion(),
|
||||
IDLike: d.IDLike,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,28 +3,45 @@ package syftjson
|
||||
import (
|
||||
"github.com/anchore/syft/internal/formats/syftjson/model"
|
||||
"github.com/anchore/syft/internal/log"
|
||||
"github.com/anchore/syft/syft/distro"
|
||||
"github.com/anchore/syft/syft/linux"
|
||||
"github.com/anchore/syft/syft/pkg"
|
||||
"github.com/anchore/syft/syft/sbom"
|
||||
"github.com/anchore/syft/syft/source"
|
||||
"github.com/google/go-cmp/cmp"
|
||||
)
|
||||
|
||||
func toSyftModel(doc model.Document) (*sbom.SBOM, error) {
|
||||
dist, err := distro.NewDistro(distro.Type(doc.Distro.Name), doc.Distro.Version, doc.Distro.IDLike)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &sbom.SBOM{
|
||||
Artifacts: sbom.Artifacts{
|
||||
PackageCatalog: toSyftCatalog(doc.Artifacts),
|
||||
Distro: &dist,
|
||||
PackageCatalog: toSyftCatalog(doc.Artifacts),
|
||||
LinuxDistribution: toSyftLinuxRelease(doc.Distro),
|
||||
},
|
||||
Source: *toSyftSourceData(doc.Source),
|
||||
Descriptor: toSyftDescriptor(doc.Descriptor),
|
||||
}, nil
|
||||
}
|
||||
|
||||
func toSyftLinuxRelease(d model.LinuxRelease) *linux.Release {
|
||||
if cmp.Equal(d, model.LinuxRelease{}) {
|
||||
return nil
|
||||
}
|
||||
return &linux.Release{
|
||||
PrettyName: d.PrettyName,
|
||||
Name: d.Name,
|
||||
ID: d.ID,
|
||||
IDLike: d.IDLike,
|
||||
Version: d.Version,
|
||||
VersionID: d.VersionID,
|
||||
Variant: d.Variant,
|
||||
VariantID: d.VariantID,
|
||||
HomeURL: d.HomeURL,
|
||||
SupportURL: d.SupportURL,
|
||||
BugReportURL: d.BugReportURL,
|
||||
PrivacyPolicyURL: d.PrivacyPolicyURL,
|
||||
CPEName: d.CPEName,
|
||||
}
|
||||
}
|
||||
|
||||
func toSyftDescriptor(d model.Descriptor) sbom.Descriptor {
|
||||
return sbom.Descriptor{
|
||||
Name: d.Name,
|
||||
|
||||
Reference in New Issue
Block a user