mirror of
https://github.com/anchore/syft.git
synced 2025-11-17 16:33:21 +01:00
* add new format pattern Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * add syftjson format Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * add internal formats helper Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * add SBOM encode/decode to lib API Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * remove json presenter + update presenter tests to use common utils Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * remove presenter format enum type + add formats shim in presenter helper Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * add MustCPE helper for tests Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * update usage of format enum Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * add test fixtures for encode/decode tests Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * fix integration test Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * migrate format detection to use reader Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * address review comments Signed-off-by: Alex Goodman <alex.goodman@anchore.com>
35 lines
1.8 KiB
Go
35 lines
1.8 KiB
Go
package poweruser
|
|
|
|
import (
|
|
"github.com/anchore/syft/internal/formats/syftjson"
|
|
"github.com/anchore/syft/internal/formats/syftjson/model"
|
|
)
|
|
|
|
type JSONDocument struct {
|
|
// note: poweruser.JSONDocument is meant to always be a superset of packages.JSONDocument, any additional fields
|
|
// here should be optional by supplying "omitempty" on these fields hint to the jsonschema generator to not
|
|
// require these fields. As an accepted rule in this repo all collections should still be initialized in the
|
|
// context of being used in a JSON document.
|
|
FileClassifications []JSONFileClassifications `json:"fileClassifications,omitempty"` // note: must have omitempty
|
|
FileContents []JSONFileContents `json:"fileContents,omitempty"` // note: must have omitempty
|
|
FileMetadata []JSONFileMetadata `json:"fileMetadata,omitempty"` // note: must have omitempty
|
|
Secrets []JSONSecrets `json:"secrets,omitempty"` // note: must have omitempty
|
|
model.Document
|
|
}
|
|
|
|
// NewJSONDocument creates and populates a new JSON document struct from the given cataloging results.
|
|
func NewJSONDocument(config JSONDocumentConfig) (JSONDocument, error) {
|
|
fileMetadata, err := NewJSONFileMetadata(config.FileMetadata, config.FileDigests)
|
|
if err != nil {
|
|
return JSONDocument{}, err
|
|
}
|
|
|
|
return JSONDocument{
|
|
FileClassifications: NewJSONFileClassifications(config.FileClassifications),
|
|
FileContents: NewJSONFileContents(config.FileContents),
|
|
FileMetadata: fileMetadata,
|
|
Secrets: NewJSONSecrets(config.Secrets),
|
|
Document: syftjson.ToFormatModel(config.PackageCatalog, &config.SourceMetadata, config.Distro, config.ApplicationConfig.Package.Cataloger.ScopeOpt, config.ApplicationConfig),
|
|
}, nil
|
|
}
|