github.com/anchore/syft@v1.38.2/syft/format/syftjson/model/document.go (about)

     1  package model
     2  
     3  import (
     4  	"encoding/json"
     5  	"fmt"
     6  )
     7  
     8  // Document represents the syft cataloging findings as a JSON document
     9  type Document struct {
    10  	Artifacts             []Package      `json:"artifacts"` // Artifacts is the list of packages discovered and placed into the catalog
    11  	ArtifactRelationships []Relationship `json:"artifactRelationships"`
    12  	Files                 []File         `json:"files,omitempty"` // note: must have omitempty
    13  	Source                Source         `json:"source"`          // Source represents the original object that was cataloged
    14  	Distro                LinuxRelease   `json:"distro"`          // Distro represents the Linux distribution that was detected from the source
    15  	Descriptor            Descriptor     `json:"descriptor"`      // Descriptor is a block containing self-describing information about syft
    16  	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
    17  }
    18  
    19  func (d *Document) UnmarshalJSON(data []byte) error {
    20  	type Alias *Document
    21  	aux := Alias(d)
    22  
    23  	if err := json.Unmarshal(data, aux); err != nil {
    24  		return fmt.Errorf("could not unmarshal syft JSON document: %w", err)
    25  	}
    26  
    27  	// in previous versions of anchorectl, the file modes were stored as decimal values instead of octal.
    28  	if d.Schema.Version == "1.0.0" && d.Descriptor.Name == "anchorectl" {
    29  		// convert all file modes from decimal to octal
    30  		for i := range d.Files {
    31  			d.Files[i].Metadata.Mode = convertBase10ToBase8(d.Files[i].Metadata.Mode)
    32  		}
    33  	}
    34  
    35  	return nil
    36  }
    37  
    38  // Descriptor identifies the tool that generated this SBOM document, including its name, version, and configuration used during catalog generation.
    39  type Descriptor struct {
    40  	// Name is the name of the tool that generated this SBOM (e.g., "syft").
    41  	Name string `json:"name"`
    42  
    43  	// Version is the version of the tool that generated this SBOM.
    44  	Version string `json:"version"`
    45  
    46  	// Configuration contains the tool configuration used during SBOM generation.
    47  	Configuration interface{} `json:"configuration,omitempty"`
    48  }
    49  
    50  // Schema specifies the JSON schema version and URL reference that defines the structure and validation rules for this document format.
    51  type Schema struct {
    52  	// Version is the JSON schema version for this document format.
    53  	Version string `json:"version"`
    54  
    55  	// URL is the URL to the JSON schema definition document.
    56  	URL string `json:"url"`
    57  }