Improve struct and field comments and incorporate into json schema (#4252)

* improve struct and field comments and incorporate into json schema

Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>

* address review feedback

Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>

---------

Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>
This commit is contained in:
Alex Goodman 2025-10-03 13:01:56 -04:00 committed by GitHub
parent b96d3d20af
commit a77d24e379
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
57 changed files with 4241 additions and 1676 deletions

2
go.mod
View File

@ -177,7 +177,7 @@ require (
github.com/hashicorp/go-version v1.6.0 // indirect github.com/hashicorp/go-version v1.6.0 // indirect
github.com/hashicorp/golang-lru/v2 v2.0.7 // indirect github.com/hashicorp/golang-lru/v2 v2.0.7 // indirect
github.com/huandu/xstrings v1.5.0 // indirect github.com/huandu/xstrings v1.5.0 // indirect
github.com/iancoleman/orderedmap v0.0.0-20190318233801-ac98e3ecb4b0 // indirect github.com/iancoleman/orderedmap v0.0.0-20190318233801-ac98e3ecb4b0
github.com/inconshreveable/mousetrap v1.1.0 // indirect github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect
github.com/kevinburke/ssh_config v1.2.0 // indirect github.com/kevinburke/ssh_config v1.2.0 // indirect

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -7,6 +7,7 @@ import (
"github.com/scylladb/go-set/strset" "github.com/scylladb/go-set/strset"
) )
// CoordinateSet provides a unique collection of Coordinates with set operations.
type CoordinateSet struct { type CoordinateSet struct {
set map[Coordinates]struct{} set map[Coordinates]struct{}
} }

View File

@ -9,8 +9,11 @@ import (
// Coordinates contains the minimal information needed to describe how to find a file within any possible source object (e.g. image and directory sources) // Coordinates contains the minimal information needed to describe how to find a file within any possible source object (e.g. image and directory sources)
type Coordinates struct { type Coordinates struct {
RealPath string `json:"path" cyclonedx:"path"` // The path where all path ancestors have no hardlinks / symlinks // RealPath is the canonical absolute form of the path accessed (all symbolic links have been followed and relative path components like '.' and '..' have been removed).
FileSystemID string `json:"layerID,omitempty" cyclonedx:"layerID"` // An ID representing the filesystem. For container images, this is a layer digest. For directories or a root filesystem, this is blank. RealPath string `json:"path" cyclonedx:"path"`
// FileSystemID is an ID representing and entire filesystem. For container images, this is a layer digest. For directories or a root filesystem, this is blank.
FileSystemID string `json:"layerID,omitempty" cyclonedx:"layerID"`
} }
func NewCoordinates(realPath, fsID string) Coordinates { func NewCoordinates(realPath, fsID string) Coordinates {

View File

@ -1,6 +1,10 @@
package file package file
// Digest represents a cryptographic hash of file contents.
type Digest struct { type Digest struct {
// Algorithm specifies the hash algorithm used (e.g., "sha256", "md5").
Algorithm string `json:"algorithm"` Algorithm string `json:"algorithm"`
// Value is the hexadecimal string representation of the hash.
Value string `json:"value"` Value string `json:"value"`
} }

View File

@ -1,39 +1,59 @@
package file package file
type ( type (
// ExecutableFormat represents the binary executable format type.
ExecutableFormat string ExecutableFormat string
// RelocationReadOnly indicates the RELRO security protection level applied to an ELF binary.
RelocationReadOnly string RelocationReadOnly string
) )
const ( const (
ELF ExecutableFormat = "elf" ELF ExecutableFormat = "elf" // Executable and Linkable Format used on Unix-like systems
MachO ExecutableFormat = "macho" MachO ExecutableFormat = "macho" // Mach object file format used on macOS and iOS
PE ExecutableFormat = "pe" PE ExecutableFormat = "pe" // Portable Executable format used on Windows
RelocationReadOnlyNone RelocationReadOnly = "none" RelocationReadOnlyNone RelocationReadOnly = "none" // no RELRO protection
RelocationReadOnlyPartial RelocationReadOnly = "partial" RelocationReadOnlyPartial RelocationReadOnly = "partial" // partial RELRO protection
RelocationReadOnlyFull RelocationReadOnly = "full" RelocationReadOnlyFull RelocationReadOnly = "full" // full RELRO protection
) )
// Executable contains metadata about binary files and their security features.
type Executable struct { type Executable struct {
// Format denotes either ELF, Mach-O, or PE // Format denotes either ELF, Mach-O, or PE
Format ExecutableFormat `json:"format" yaml:"format" mapstructure:"format"` Format ExecutableFormat `json:"format" yaml:"format" mapstructure:"format"`
// HasExports indicates whether the binary exports symbols.
HasExports bool `json:"hasExports" yaml:"hasExports" mapstructure:"hasExports"` HasExports bool `json:"hasExports" yaml:"hasExports" mapstructure:"hasExports"`
// HasEntrypoint indicates whether the binary has an entry point function.
HasEntrypoint bool `json:"hasEntrypoint" yaml:"hasEntrypoint" mapstructure:"hasEntrypoint"` HasEntrypoint bool `json:"hasEntrypoint" yaml:"hasEntrypoint" mapstructure:"hasEntrypoint"`
// ImportedLibraries lists the shared libraries required by this executable.
ImportedLibraries []string `json:"importedLibraries" yaml:"importedLibraries" mapstructure:"importedLibraries"` ImportedLibraries []string `json:"importedLibraries" yaml:"importedLibraries" mapstructure:"importedLibraries"`
// ELFSecurityFeatures contains ELF-specific security hardening information when Format is ELF.
ELFSecurityFeatures *ELFSecurityFeatures `json:"elfSecurityFeatures,omitempty" yaml:"elfSecurityFeatures" mapstructure:"elfSecurityFeatures"` ELFSecurityFeatures *ELFSecurityFeatures `json:"elfSecurityFeatures,omitempty" yaml:"elfSecurityFeatures" mapstructure:"elfSecurityFeatures"`
} }
// ELFSecurityFeatures captures security hardening and protection mechanisms in ELF binaries.
type ELFSecurityFeatures struct { type ELFSecurityFeatures struct {
// SymbolTableStripped indicates whether debugging symbols have been removed.
SymbolTableStripped bool `json:"symbolTableStripped" yaml:"symbolTableStripped" mapstructure:"symbolTableStripped"` SymbolTableStripped bool `json:"symbolTableStripped" yaml:"symbolTableStripped" mapstructure:"symbolTableStripped"`
// classic protections // StackCanary indicates whether stack smashing protection is enabled.
StackCanary *bool `json:"stackCanary,omitempty" yaml:"stackCanary" mapstructure:"stackCanary"` StackCanary *bool `json:"stackCanary,omitempty" yaml:"stackCanary" mapstructure:"stackCanary"`
// NoExecutable indicates whether NX (no-execute) protection is enabled for the stack.
NoExecutable bool `json:"nx" yaml:"nx" mapstructure:"nx"` NoExecutable bool `json:"nx" yaml:"nx" mapstructure:"nx"`
// RelocationReadOnly indicates the RELRO protection level.
RelocationReadOnly RelocationReadOnly `json:"relRO" yaml:"relRO" mapstructure:"relRO"` RelocationReadOnly RelocationReadOnly `json:"relRO" yaml:"relRO" mapstructure:"relRO"`
// PositionIndependentExecutable indicates whether the binary is compiled as PIE.
PositionIndependentExecutable bool `json:"pie" yaml:"pie" mapstructure:"pie"` PositionIndependentExecutable bool `json:"pie" yaml:"pie" mapstructure:"pie"`
// DynamicSharedObject indicates whether the binary is a shared library.
DynamicSharedObject bool `json:"dso" yaml:"dso" mapstructure:"dso"` DynamicSharedObject bool `json:"dso" yaml:"dso" mapstructure:"dso"`
// LlvmSafeStack represents a compiler-based security mechanism that separates the stack into a safe stack for storing return addresses and other critical data, and an unsafe stack for everything else, to mitigate stack-based memory corruption errors // LlvmSafeStack represents a compiler-based security mechanism that separates the stack into a safe stack for storing return addresses and other critical data, and an unsafe stack for everything else, to mitigate stack-based memory corruption errors

View File

@ -5,17 +5,32 @@ import (
"github.com/anchore/syft/syft/license" "github.com/anchore/syft/syft/license"
) )
// License represents license information discovered within a file.
type License struct { type License struct {
// Value is the raw license string as found in the file.
Value string Value string
// SPDXExpression is the parsed SPDX license expression if available.
SPDXExpression string SPDXExpression string
// Type categorizes how the license was determined (e.g., declared, concluded -- following the same semantics as SPDX).
Type license.Type Type license.Type
LicenseEvidence *LicenseEvidence // evidence from license classifier
LicenseEvidence *LicenseEvidence
// Contents optionally stores the full license text.
Contents string `hash:"ignore"` Contents string `hash:"ignore"`
} }
// LicenseEvidence contains details from license classifier analysis.
type LicenseEvidence struct { type LicenseEvidence struct {
// Confidence is a score indicating certainty of the license match.
Confidence int Confidence int
// Offset is the byte position where the license text begins in the file.
Offset int Offset int
// Extent is the length in bytes of the matched license text.
Extent int Extent int
} }

View File

@ -27,18 +27,24 @@ type Location struct {
LocationMetadata `cyclonedx:""` LocationMetadata `cyclonedx:""`
} }
// LocationData contains the core identifying information for a file location.
type LocationData struct { type LocationData struct {
Coordinates `cyclonedx:""` // Empty string here means there is no intermediate property name, e.g. syft:locations:0:path without "coordinates" Coordinates `cyclonedx:""` // Empty string here means there is no intermediate property name, e.g. syft:locations:0:path without "coordinates"
// note: it is IMPORTANT to ignore anything but the coordinates for a Location when considering the ID (hash value) // note: it is IMPORTANT to ignore anything but the coordinates for a Location when considering the ID (hash value)
// since the coordinates are the minimally correct ID for a location (symlinks should not come into play) // since the coordinates are the minimally correct ID for a location (symlinks should not come into play)
AccessPath string `hash:"ignore" json:"accessPath"` // The path to the file which may or may not have hardlinks / symlinks
ref file.Reference `hash:"ignore"` // The file reference relative to the stereoscope.FileCatalog that has more information about this location. // AccessPath is the path used to retrieve file contents (which may or may not have hardlinks / symlinks in the path)
AccessPath string `hash:"ignore" json:"accessPath"`
// ref is the stereoscope file reference relative to the stereoscope.FileCatalog that has more information about this location.
ref file.Reference `hash:"ignore"`
} }
func (l LocationData) Reference() file.Reference { func (l LocationData) Reference() file.Reference {
return l.ref return l.ref
} }
// LocationMetadata provides additional contextual information about a file location.
type LocationMetadata struct { type LocationMetadata struct {
Annotations map[string]string `json:"annotations,omitempty"` // Arbitrary key-value pairs that can be used to annotate a location Annotations map[string]string `json:"annotations,omitempty"` // Arbitrary key-value pairs that can be used to annotate a location
} }

View File

@ -2,6 +2,7 @@ package file
import "io" import "io"
// LocationReadCloser combines a Location with a ReadCloser for accessing file content with location metadata.
type LocationReadCloser struct { type LocationReadCloser struct {
Location Location
io.ReadCloser io.ReadCloser

View File

@ -9,6 +9,7 @@ import (
"github.com/anchore/syft/internal/log" "github.com/anchore/syft/internal/log"
) )
// LocationSet provides a unique collection of Locations with metadata and set operations.
type LocationSet struct { type LocationSet struct {
set map[LocationData]LocationMetadata set map[LocationData]LocationMetadata
} }

View File

@ -8,6 +8,7 @@ import (
var locationSorterWithoutLayers = LocationSorter(nil) var locationSorterWithoutLayers = LocationSorter(nil)
// Locations is a sortable slice of Location values.
type Locations []Location type Locations []Location
func (l Locations) Len() int { func (l Locations) Len() int {

View File

@ -18,6 +18,7 @@ type ContentResolver interface {
FileContentsByLocation(Location) (io.ReadCloser, error) FileContentsByLocation(Location) (io.ReadCloser, error)
} }
// MetadataResolver provides file metadata lookup by location.
type MetadataResolver interface { type MetadataResolver interface {
FileMetadataByLocation(Location) (Metadata, error) FileMetadataByLocation(Location) (Metadata, error)
} }
@ -51,6 +52,7 @@ type PathResolver interface {
RelativeFileByPath(_ Location, path string) *Location RelativeFileByPath(_ Location, path string) *Location
} }
// LocationResolver provides iteration over all file locations in a source.
type LocationResolver interface { type LocationResolver interface {
// AllLocations returns a channel of all file references from the underlying source. // AllLocations returns a channel of all file references from the underlying source.
// The implementation for this may vary, however, generally the following considerations should be made: // The implementation for this may vary, however, generally the following considerations should be made:
@ -59,6 +61,7 @@ type LocationResolver interface {
AllLocations(ctx context.Context) <-chan Location AllLocations(ctx context.Context) <-chan Location
} }
// WritableResolver extends Resolver with the ability to write file content.
type WritableResolver interface { type WritableResolver interface {
Resolver Resolver

View File

@ -4,12 +4,24 @@ import (
"fmt" "fmt"
) )
// SearchResult represents a match found during content scanning, such as secret detection.
type SearchResult struct { type SearchResult struct {
// Classification identifies the type or category of the matched content.
Classification string `json:"classification"` Classification string `json:"classification"`
// LineNumber is the 1-indexed line number where the match was found.
LineNumber int64 `json:"lineNumber"` LineNumber int64 `json:"lineNumber"`
// LineOffset is the character offset from the start of the line where the match begins.
LineOffset int64 `json:"lineOffset"` LineOffset int64 `json:"lineOffset"`
// SeekPosition is the absolute byte offset from the start of the file.
SeekPosition int64 `json:"seekPosition"` SeekPosition int64 `json:"seekPosition"`
// Length is the size in bytes of the matched content.
Length int64 `json:"length"` Length int64 `json:"length"`
// Value optionally contains the actual matched content.
Value string `json:"value,omitempty"` Value string `json:"value,omitempty"`
} }

View File

@ -1,9 +1,10 @@
package file package file
const ( const (
NoFilesSelection Selection = "none" NoFilesSelection Selection = "none" // no files are selected
FilesOwnedByPackageSelection Selection = "owned-by-package" FilesOwnedByPackageSelection Selection = "owned-by-package" // only files owned by packages are selected
AllFilesSelection Selection = "all" AllFilesSelection Selection = "all" // all files are selected
) )
// Selection defines which files should be included during cataloging operations.
type Selection string type Selection string

View File

@ -0,0 +1,159 @@
package main
import (
"fmt"
"go/ast"
"go/parser"
"go/token"
"os"
"path/filepath"
"strings"
"github.com/invopop/jsonschema"
)
func copyAliasFieldComments(commentMap map[string]string, repoRoot string) {
// find all type aliases by parsing Go source files
aliases := findTypeAliases(repoRoot)
// for each alias, copy field comments from the source type
for aliasName, sourceName := range aliases {
// find all field comments for the source type
for key, comment := range commentMap {
// check if this is a field comment for the source type
// format: "github.com/anchore/syft/syft/pkg.SourceType.FieldName"
if strings.Contains(key, "."+sourceName+".") {
// create the corresponding key for the alias
aliasKey := strings.Replace(key, "."+sourceName+".", "."+aliasName+".", 1)
commentMap[aliasKey] = comment
}
}
}
}
func findTypeAliases(repoRoot string) map[string]string {
aliases := make(map[string]string)
fset := token.NewFileSet()
// walk through all Go files in the repo
err := filepath.Walk(repoRoot, func(path string, info os.FileInfo, err error) error {
if err != nil || info.IsDir() || !strings.HasSuffix(path, ".go") {
return nil
}
// parse the file
file, err := parser.ParseFile(fset, path, nil, parser.ParseComments)
if err != nil {
return nil
}
// look for type alias declarations
ast.Inspect(file, func(n ast.Node) bool {
typeSpec, ok := n.(*ast.TypeSpec)
if !ok {
return true
}
// check if this is a type alias (e.g., type A B where B is an identifier)
ident, ok := typeSpec.Type.(*ast.Ident)
if !ok {
return true
}
// store the alias mapping: aliasName -> sourceName
aliases[typeSpec.Name.Name] = ident.Name
return true
})
return nil
})
if err != nil {
fmt.Fprintf(os.Stderr, "error: failed to find type aliases: %v\n", err)
panic(err)
}
return aliases
}
func hasDescriptionInAlternatives(schema *jsonschema.Schema) bool {
// check oneOf alternatives
for _, alt := range schema.OneOf {
if alt.Description != "" {
return true
}
}
// check anyOf alternatives
for _, alt := range schema.AnyOf {
if alt.Description != "" {
return true
}
}
return false
}
func warnMissingDescriptions(schema *jsonschema.Schema, metadataNames []string) { //nolint:gocognit
var missingTypeDescriptions []string
var missingFieldDescriptions []string
// check metadata types for missing descriptions
for _, name := range metadataNames {
def, ok := schema.Definitions[name]
if !ok {
continue
}
// check if type has a description
if def.Description == "" {
missingTypeDescriptions = append(missingTypeDescriptions, name)
}
// check if fields have descriptions
if def.Properties != nil {
for _, fieldName := range def.Properties.Keys() {
fieldSchemaRaw, _ := def.Properties.Get(fieldName)
fieldSchema, ok := fieldSchemaRaw.(*jsonschema.Schema)
if !ok {
continue
}
// skip if field has a description
if fieldSchema.Description != "" {
continue
}
// skip if field is a reference (descriptions come from the referenced type)
if fieldSchema.Ref != "" {
continue
}
// skip if field is an array/object with items that are references
if fieldSchema.Items != nil && fieldSchema.Items.Ref != "" {
continue
}
// skip if field uses oneOf/anyOf with descriptions in the alternatives
if hasDescriptionInAlternatives(fieldSchema) {
continue
}
missingFieldDescriptions = append(missingFieldDescriptions, fmt.Sprintf("%s.%s", name, fieldName))
}
}
}
// report findings
if len(missingTypeDescriptions) > 0 {
fmt.Fprintf(os.Stderr, "\nwarning: %d metadata types are missing descriptions:\n", len(missingTypeDescriptions))
for _, name := range missingTypeDescriptions {
fmt.Fprintf(os.Stderr, " - %s\n", name)
}
}
if len(missingFieldDescriptions) > 0 {
fmt.Fprintf(os.Stderr, "\nwarning: %d fields are missing descriptions:\n", len(missingFieldDescriptions))
for _, field := range missingFieldDescriptions {
fmt.Fprintf(os.Stderr, " - %s\n", field)
}
}
}

View File

@ -0,0 +1,382 @@
package main
import (
"os"
"path/filepath"
"testing"
"github.com/iancoleman/orderedmap"
"github.com/invopop/jsonschema"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
// TestCopyAliasFieldComments verifies that field comments from source types are correctly copied to alias types.
// This is important for type aliases like `type RpmArchive RpmDBEntry` where the alias should inherit all field descriptions.
func TestCopyAliasFieldComments(t *testing.T) {
tests := []struct {
name string
commentMap map[string]string
aliases map[string]string
wantComments map[string]string
}{
{
name: "copies field comments from source type to alias",
commentMap: map[string]string{
"github.com/anchore/syft/syft/pkg.RpmDBEntry": "RpmDBEntry represents all captured data from a RPM DB package entry.",
"github.com/anchore/syft/syft/pkg.RpmDBEntry.Name": "Name is the RPM package name.",
"github.com/anchore/syft/syft/pkg.RpmDBEntry.Epoch": "Epoch is the version epoch.",
},
aliases: map[string]string{
"RpmArchive": "RpmDBEntry",
},
wantComments: map[string]string{
"github.com/anchore/syft/syft/pkg.RpmDBEntry": "RpmDBEntry represents all captured data from a RPM DB package entry.",
"github.com/anchore/syft/syft/pkg.RpmDBEntry.Name": "Name is the RPM package name.",
"github.com/anchore/syft/syft/pkg.RpmDBEntry.Epoch": "Epoch is the version epoch.",
"github.com/anchore/syft/syft/pkg.RpmArchive.Name": "Name is the RPM package name.",
"github.com/anchore/syft/syft/pkg.RpmArchive.Epoch": "Epoch is the version epoch.",
},
},
{
name: "handles multiple aliases",
commentMap: map[string]string{
"github.com/anchore/syft/syft/pkg.DpkgDBEntry": "DpkgDBEntry represents data from dpkg.",
"github.com/anchore/syft/syft/pkg.DpkgDBEntry.Package": "Package is the package name.",
"github.com/anchore/syft/syft/pkg.DpkgDBEntry.Architecture": "Architecture is the target arch.",
},
aliases: map[string]string{
"DpkgArchiveEntry": "DpkgDBEntry",
"DpkgSnapshot": "DpkgDBEntry",
},
wantComments: map[string]string{
"github.com/anchore/syft/syft/pkg.DpkgDBEntry": "DpkgDBEntry represents data from dpkg.",
"github.com/anchore/syft/syft/pkg.DpkgDBEntry.Package": "Package is the package name.",
"github.com/anchore/syft/syft/pkg.DpkgDBEntry.Architecture": "Architecture is the target arch.",
"github.com/anchore/syft/syft/pkg.DpkgArchiveEntry.Package": "Package is the package name.",
"github.com/anchore/syft/syft/pkg.DpkgArchiveEntry.Architecture": "Architecture is the target arch.",
"github.com/anchore/syft/syft/pkg.DpkgSnapshot.Package": "Package is the package name.",
"github.com/anchore/syft/syft/pkg.DpkgSnapshot.Architecture": "Architecture is the target arch.",
},
},
{
name: "does not copy non-field comments",
commentMap: map[string]string{
"github.com/anchore/syft/syft/pkg.SomeType": "SomeType struct comment.",
"github.com/anchore/syft/syft/pkg.SomeType.Field": "Field comment.",
},
aliases: map[string]string{
"AliasType": "SomeType",
},
wantComments: map[string]string{
"github.com/anchore/syft/syft/pkg.SomeType": "SomeType struct comment.",
"github.com/anchore/syft/syft/pkg.SomeType.Field": "Field comment.",
"github.com/anchore/syft/syft/pkg.AliasType.Field": "Field comment.",
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
// create temp dir for testing
tmpDir := t.TempDir()
// create a test go file with type aliases
testFile := filepath.Join(tmpDir, "test.go")
content := "package test\n\n"
for alias, source := range tt.aliases {
content += "type " + alias + " " + source + "\n"
}
err := os.WriteFile(testFile, []byte(content), 0644)
require.NoError(t, err)
// make a copy of the comment map since the function modifies it
commentMap := make(map[string]string)
for k, v := range tt.commentMap {
commentMap[k] = v
}
// run the function
copyAliasFieldComments(commentMap, tmpDir)
// verify results
assert.Equal(t, tt.wantComments, commentMap)
})
}
}
func TestFindTypeAliases(t *testing.T) {
tests := []struct {
name string
fileContent string
wantAliases map[string]string
}{
{
name: "finds simple type alias",
fileContent: `package test
type RpmArchive RpmDBEntry
type DpkgArchiveEntry DpkgDBEntry
`,
wantAliases: map[string]string{
"RpmArchive": "RpmDBEntry",
"DpkgArchiveEntry": "DpkgDBEntry",
},
},
{
name: "ignores struct definitions",
fileContent: `package test
type MyStruct struct {
Field string
}
type AliasType BaseType
`,
wantAliases: map[string]string{
"AliasType": "BaseType",
},
},
{
name: "ignores interface definitions",
fileContent: `package test
type MyInterface interface {
Method()
}
type AliasType BaseType
`,
wantAliases: map[string]string{
"AliasType": "BaseType",
},
},
{
name: "handles multiple files",
fileContent: `package test
type Alias1 Base1
type Alias2 Base2
`,
wantAliases: map[string]string{
"Alias1": "Base1",
"Alias2": "Base2",
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
// create temp dir
tmpDir := t.TempDir()
// write test file
testFile := filepath.Join(tmpDir, "test.go")
err := os.WriteFile(testFile, []byte(tt.fileContent), 0644)
require.NoError(t, err)
// run function
aliases := findTypeAliases(tmpDir)
// verify
assert.Equal(t, tt.wantAliases, aliases)
})
}
}
func TestHasDescriptionInAlternatives(t *testing.T) {
tests := []struct {
name string
schema *jsonschema.Schema
want bool
}{
{
name: "returns true when oneOf has description",
schema: &jsonschema.Schema{
OneOf: []*jsonschema.Schema{
{Description: "First alternative"},
{Type: "null"},
},
},
want: true,
},
{
name: "returns true when anyOf has description",
schema: &jsonschema.Schema{
AnyOf: []*jsonschema.Schema{
{Description: "First alternative"},
{Type: "null"},
},
},
want: true,
},
{
name: "returns false when no alternatives have descriptions",
schema: &jsonschema.Schema{
OneOf: []*jsonschema.Schema{
{Type: "integer"},
{Type: "null"},
},
},
want: false,
},
{
name: "returns false when no oneOf or anyOf",
schema: &jsonschema.Schema{
Type: "string",
},
want: false,
},
{
name: "returns true when any alternative in oneOf has description",
schema: &jsonschema.Schema{
OneOf: []*jsonschema.Schema{
{Type: "integer"},
{Type: "string", Description: "Second alternative"},
{Type: "null"},
},
},
want: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := hasDescriptionInAlternatives(tt.schema)
assert.Equal(t, tt.want, got)
})
}
}
func TestWarnMissingDescriptions(t *testing.T) {
tests := []struct {
name string
schema *jsonschema.Schema
metadataNames []string
wantTypeWarnings int
wantFieldWarnings int
}{
{
name: "no warnings when all types have descriptions",
schema: &jsonschema.Schema{
Definitions: map[string]*jsonschema.Schema{
"TypeA": {
Description: "Type A description",
Properties: newOrderedMap(map[string]*jsonschema.Schema{
"field1": {Type: "string", Description: "Field 1"},
}),
},
},
},
metadataNames: []string{"TypeA"},
wantTypeWarnings: 0,
wantFieldWarnings: 0,
},
{
name: "warns about missing type description",
schema: &jsonschema.Schema{
Definitions: map[string]*jsonschema.Schema{
"TypeA": {
Properties: newOrderedMap(map[string]*jsonschema.Schema{
"field1": {Type: "string", Description: "Field 1"},
}),
},
},
},
metadataNames: []string{"TypeA"},
wantTypeWarnings: 1,
wantFieldWarnings: 0,
},
{
name: "warns about missing field description",
schema: &jsonschema.Schema{
Definitions: map[string]*jsonschema.Schema{
"TypeA": {
Description: "Type A description",
Properties: newOrderedMap(map[string]*jsonschema.Schema{
"field1": {Type: "string"},
}),
},
},
},
metadataNames: []string{"TypeA"},
wantTypeWarnings: 0,
wantFieldWarnings: 1,
},
{
name: "skips fields with references",
schema: &jsonschema.Schema{
Definitions: map[string]*jsonschema.Schema{
"TypeA": {
Description: "Type A description",
Properties: newOrderedMap(map[string]*jsonschema.Schema{
"field1": {Ref: "#/$defs/OtherType"},
}),
},
},
},
metadataNames: []string{"TypeA"},
wantTypeWarnings: 0,
wantFieldWarnings: 0,
},
{
name: "skips fields with items that are references",
schema: &jsonschema.Schema{
Definitions: map[string]*jsonschema.Schema{
"TypeA": {
Description: "Type A description",
Properties: newOrderedMap(map[string]*jsonschema.Schema{
"field1": {
Type: "array",
Items: &jsonschema.Schema{Ref: "#/$defs/OtherType"},
},
}),
},
},
},
metadataNames: []string{"TypeA"},
wantTypeWarnings: 0,
wantFieldWarnings: 0,
},
{
name: "skips fields with oneOf containing descriptions",
schema: &jsonschema.Schema{
Definitions: map[string]*jsonschema.Schema{
"TypeA": {
Description: "Type A description",
Properties: newOrderedMap(map[string]*jsonschema.Schema{
"field1": {
OneOf: []*jsonschema.Schema{
{Type: "integer", Description: "Integer value"},
{Type: "null"},
},
},
}),
},
},
},
metadataNames: []string{"TypeA"},
wantTypeWarnings: 0,
wantFieldWarnings: 0,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
// capture stderr output would require more complex testing
// for now, just verify the function runs without panicking
require.NotPanics(t, func() {
warnMissingDescriptions(tt.schema, tt.metadataNames)
})
})
}
}
// helper to create an ordered map from a regular map
func newOrderedMap(m map[string]*jsonschema.Schema) *orderedmap.OrderedMap {
om := orderedmap.New()
for k, v := range m {
om.Set(k, v)
}
return om
}

View File

@ -78,6 +78,33 @@ func build() *jsonschema.Schema {
Namer: func(r reflect.Type) string { Namer: func(r reflect.Type) string {
return strings.TrimPrefix(r.Name(), "JSON") return strings.TrimPrefix(r.Name(), "JSON")
}, },
CommentMap: make(map[string]string),
}
// extract comments from Go source files to enrich schema descriptions
//
// note: AddGoComments parses from the module root and creates keys like "syft/pkg.TypeName",
// but the reflector expects fully qualified paths like "github.com/anchore/syft/syft/pkg.TypeName".
// We fix up the keys after extraction to match the expected format.
if err := reflector.AddGoComments("github.com/anchore/syft", "../../.."); err != nil {
fmt.Fprintf(os.Stderr, "warning: failed to extract Go comments: %v\n", err)
} else {
// fix up comment map keys to use fully qualified import paths
fixedMap := make(map[string]string)
for k, v := range reflector.CommentMap {
newKey := k
if !strings.HasPrefix(k, "github.com/") {
newKey = "github.com/anchore/syft/" + k
}
fixedMap[newKey] = v
}
reflector.CommentMap = fixedMap
// copy field comments for type aliases (e.g., type RpmArchive RpmDBEntry)
repoRoot, err := packagemetadata.RepoRoot()
if err == nil {
copyAliasFieldComments(reflector.CommentMap, repoRoot)
}
} }
pkgMetadataContainer, pkgMetadataMapping := assembleTypeContainer(packagemetadata.AllTypes()) pkgMetadataContainer, pkgMetadataMapping := assembleTypeContainer(packagemetadata.AllTypes())
@ -130,6 +157,9 @@ func build() *jsonschema.Schema {
"anyOf": metadataTypes, "anyOf": metadataTypes,
}) })
// warn about missing descriptions
warnMissingDescriptions(documentSchema, metadataNames)
return documentSchema return documentSchema
} }

View File

@ -24,7 +24,7 @@ var knownNonMetadataTypeNames = strset.New(
// these are names that would be removed due to common convention (e.g. used within another metadata type) but are // these are names that would be removed due to common convention (e.g. used within another metadata type) but are
// known to be metadata types themselves. Adding to this list will prevent the removal of the type from the schema. // known to be metadata types themselves. Adding to this list will prevent the removal of the type from the schema.
var knownMetadaTypeNames = strset.New( var knownMetadataTypeNames = strset.New(
"DotnetPortableExecutableEntry", "DotnetPortableExecutableEntry",
) )
@ -72,7 +72,7 @@ func findMetadataDefinitionNames(paths ...string) ([]string, error) {
} }
// any definition that is used within another struct should not be considered a top-level metadata definition // any definition that is used within another struct should not be considered a top-level metadata definition
removeNames := strset.Difference(usedNames, knownMetadaTypeNames) removeNames := strset.Difference(usedNames, knownMetadataTypeNames)
names.Remove(removeNames.List()...) names.Remove(removeNames.List()...)
// remove known exceptions, that is, types exported in the pkg Package that are not used // remove known exceptions, that is, types exported in the pkg Package that are not used

View File

@ -13,32 +13,74 @@ var _ FileOwner = (*AlpmDBEntry)(nil)
const AlpmDBGlob = "**/var/lib/pacman/local/**/desc" const AlpmDBGlob = "**/var/lib/pacman/local/**/desc"
// AlpmDBEntry is a struct that represents the package data stored in the pacman fla-filet stores for arch linux. // AlpmDBEntry is a struct that represents the package data stored in the pacman flat-file stores for arch linux.
type AlpmDBEntry struct { type AlpmDBEntry struct {
// BasePackage is the base package name this package was built from (source package in Arch build system)
BasePackage string `mapstructure:"base" json:"basepackage" cyclonedx:"basepackage"` BasePackage string `mapstructure:"base" json:"basepackage" cyclonedx:"basepackage"`
// Package is the package name as found in the desc file
Package string `mapstructure:"name" json:"package" cyclonedx:"package"` Package string `mapstructure:"name" json:"package" cyclonedx:"package"`
// Version is the package version as found in the desc file
Version string `mapstructure:"version" json:"version" cyclonedx:"version"` Version string `mapstructure:"version" json:"version" cyclonedx:"version"`
// Description is a human-readable package description
Description string `mapstructure:"desc" json:"description" cyclonedx:"description"` Description string `mapstructure:"desc" json:"description" cyclonedx:"description"`
// Architecture is the target CPU architecture as defined in Arch architecture spec (e.g. x86_64, aarch64, or "any" for arch-independent packages)
Architecture string `mapstructure:"arch" json:"architecture" cyclonedx:"architecture"` Architecture string `mapstructure:"arch" json:"architecture" cyclonedx:"architecture"`
// Size is the installed size in bytes
Size int `mapstructure:"size" json:"size" cyclonedx:"size"` Size int `mapstructure:"size" json:"size" cyclonedx:"size"`
// Packager is the name and email of the person who packaged this (RFC822 format)
Packager string `mapstructure:"packager" json:"packager"` Packager string `mapstructure:"packager" json:"packager"`
// URL is the upstream project URL
URL string `mapstructure:"url" json:"url"` URL string `mapstructure:"url" json:"url"`
// Validation is the validation method used for package integrity (e.g. pgp signature, sha256 checksum)
Validation string `mapstructure:"validation" json:"validation"` Validation string `mapstructure:"validation" json:"validation"`
// Reason is the installation reason tracked by pacman (0=explicitly installed by user, 1=installed as dependency)
Reason int `mapstructure:"reason" json:"reason"` Reason int `mapstructure:"reason" json:"reason"`
// Files are the files installed by this package
Files []AlpmFileRecord `mapstructure:"files" json:"files"` Files []AlpmFileRecord `mapstructure:"files" json:"files"`
// Backup is the list of configuration files that pacman backs up before upgrades
Backup []AlpmFileRecord `mapstructure:"backup" json:"backup"` Backup []AlpmFileRecord `mapstructure:"backup" json:"backup"`
// Provides are virtual packages provided by this package (allows other packages to depend on capabilities rather than specific packages)
Provides []string `mapstructure:"provides" json:"provides,omitempty"` Provides []string `mapstructure:"provides" json:"provides,omitempty"`
// Depends are the runtime dependencies required by this package
Depends []string `mapstructure:"depends" json:"depends,omitempty"` Depends []string `mapstructure:"depends" json:"depends,omitempty"`
} }
type AlpmFileRecord struct { type AlpmFileRecord struct {
// Path is the file path relative to the filesystem root
Path string `mapstruture:"path" json:"path,omitempty"` Path string `mapstruture:"path" json:"path,omitempty"`
// Type is the file type (e.g. regular file, directory, symlink)
Type string `mapstructure:"type" json:"type,omitempty"` Type string `mapstructure:"type" json:"type,omitempty"`
// UID is the file owner user ID as recorded by pacman
UID string `mapstructure:"uid" json:"uid,omitempty"` UID string `mapstructure:"uid" json:"uid,omitempty"`
// GID is the file owner group ID as recorded by pacman
GID string `mapstructure:"gid" json:"gid,omitempty"` GID string `mapstructure:"gid" json:"gid,omitempty"`
// Time is the file modification timestamp
Time time.Time `mapstructure:"time" json:"time,omitempty"` Time time.Time `mapstructure:"time" json:"time,omitempty"`
// Size is the file size in bytes
Size string `mapstructure:"size" json:"size,omitempty"` Size string `mapstructure:"size" json:"size,omitempty"`
// Link is the symlink target path if this is a symlink
Link string `mapstructure:"link" json:"link,omitempty"` Link string `mapstructure:"link" json:"link,omitempty"`
// Digests contains file content hashes for integrity verification
Digests []file.Digest `mapstructure:"digests" json:"digest,omitempty"` Digests []file.Digest `mapstructure:"digests" json:"digest,omitempty"`
} }

View File

@ -23,22 +23,50 @@ var _ FileOwner = (*ApkDBEntry)(nil)
// - https://git.alpinelinux.org/apk-tools/tree/src/package.c // - https://git.alpinelinux.org/apk-tools/tree/src/package.c
// - https://git.alpinelinux.org/apk-tools/tree/src/database.c // - https://git.alpinelinux.org/apk-tools/tree/src/database.c
type ApkDBEntry struct { type ApkDBEntry struct {
// Package is the package name as found in the installed file
Package string `mapstructure:"P" json:"package"` Package string `mapstructure:"P" json:"package"`
// OriginPackage is the original source package name this binary was built from (used to track which aport/source built this)
OriginPackage string `mapstructure:"o" json:"originPackage" cyclonedx:"originPackage"` OriginPackage string `mapstructure:"o" json:"originPackage" cyclonedx:"originPackage"`
// Maintainer is the package maintainer name and email
Maintainer string `mapstructure:"m" json:"maintainer"` Maintainer string `mapstructure:"m" json:"maintainer"`
// Version is the package version as found in the installed file
Version string `mapstructure:"V" json:"version"` Version string `mapstructure:"V" json:"version"`
// Architecture is the target CPU architecture
Architecture string `mapstructure:"A" json:"architecture"` Architecture string `mapstructure:"A" json:"architecture"`
// URL is the upstream project URL
URL string `mapstructure:"U" json:"url"` URL string `mapstructure:"U" json:"url"`
// Description is a human-readable package description
Description string `mapstructure:"T" json:"description"` Description string `mapstructure:"T" json:"description"`
// Size is the package archive size in bytes (.apk file size)
Size int `mapstructure:"S" json:"size" cyclonedx:"size"` Size int `mapstructure:"S" json:"size" cyclonedx:"size"`
// InstalledSize is the total size of installed files in bytes
InstalledSize int `mapstructure:"I" json:"installedSize" cyclonedx:"installedSize"` InstalledSize int `mapstructure:"I" json:"installedSize" cyclonedx:"installedSize"`
// Dependencies are the runtime dependencies required by this package
Dependencies []string `mapstructure:"D" json:"pullDependencies" cyclonedx:"pullDependencies"` Dependencies []string `mapstructure:"D" json:"pullDependencies" cyclonedx:"pullDependencies"`
// Provides are virtual packages provided by this package (for capability-based dependencies)
Provides []string `mapstructure:"p" json:"provides" cyclonedx:"provides"` Provides []string `mapstructure:"p" json:"provides" cyclonedx:"provides"`
// Checksum is the package content checksum for integrity verification
Checksum string `mapstructure:"C" json:"pullChecksum" cyclonedx:"pullChecksum"` Checksum string `mapstructure:"C" json:"pullChecksum" cyclonedx:"pullChecksum"`
// GitCommit is the git commit hash of the APK port definition in Alpine's aports repository
GitCommit string `mapstructure:"c" json:"gitCommitOfApkPort" cyclonedx:"gitCommitOfApkPort"` GitCommit string `mapstructure:"c" json:"gitCommitOfApkPort" cyclonedx:"gitCommitOfApkPort"`
// Files are the files installed by this package
Files []ApkFileRecord `json:"files"` Files []ApkFileRecord `json:"files"`
} }
// spaceDelimitedStringSlice is an internal helper type for unmarshaling space-delimited strings from JSON into a string slice.
type spaceDelimitedStringSlice []string type spaceDelimitedStringSlice []string
func (m *ApkDBEntry) UnmarshalJSON(data []byte) error { func (m *ApkDBEntry) UnmarshalJSON(data []byte) error {
@ -95,10 +123,19 @@ func (a *spaceDelimitedStringSlice) UnmarshalJSON(data []byte) error {
// ApkFileRecord represents a single file listing and metadata from a APK DB entry (which may have many of these file records). // ApkFileRecord represents a single file listing and metadata from a APK DB entry (which may have many of these file records).
type ApkFileRecord struct { type ApkFileRecord struct {
// Path is the file path relative to the filesystem root
Path string `json:"path"` Path string `json:"path"`
// OwnerUID is the file owner user ID
OwnerUID string `json:"ownerUid,omitempty"` OwnerUID string `json:"ownerUid,omitempty"`
// OwnerGID is the file owner group ID
OwnerGID string `json:"ownerGid,omitempty"` OwnerGID string `json:"ownerGid,omitempty"`
// Permissions is the file permission mode string (e.g. "0755", "0644")
Permissions string `json:"permissions,omitempty"` Permissions string `json:"permissions,omitempty"`
// Digest is the file content hash for integrity verification
Digest *file.Digest `json:"digest,omitempty"` Digest *file.Digest `json:"digest,omitempty"`
} }

View File

@ -13,9 +13,9 @@ type ClassifierMatch struct {
Location file.Location `mapstructure:"Location" json:"location"` Location file.Location `mapstructure:"Location" json:"location"`
} }
// ELFBinaryPackageNoteJSONPayload Represents metadata captured from the .note.package section of the binary // ELFBinaryPackageNoteJSONPayload Represents metadata captured from the .note.package section of an ELF-formatted binary
type ELFBinaryPackageNoteJSONPayload struct { type ELFBinaryPackageNoteJSONPayload struct {
// these are well-known fields as defined by systemd ELF package metadata "spec" https://systemd.io/ELF_PACKAGE_METADATA/ // (these are well-known fields as defined by systemd ELF package metadata "spec" https://systemd.io/ELF_PACKAGE_METADATA/)
// Type is the type of the package (e.g. "rpm", "deb", "apk", etc.) // Type is the type of the package (e.g. "rpm", "deb", "apk", etc.)
Type string `json:"type,omitempty"` Type string `json:"type,omitempty"`
@ -32,7 +32,8 @@ type ELFBinaryPackageNoteJSONPayload struct {
// osVersion is the version of the OS, typically corresponding to VERSION_ID in os-release (e.g. "33") // osVersion is the version of the OS, typically corresponding to VERSION_ID in os-release (e.g. "33")
OSVersion string `json:"osVersion,omitempty"` OSVersion string `json:"osVersion,omitempty"`
// these are additional fields that are not part of the systemd spec /////////////////////////////////////////////////////////////////////////////////
// (these are additional fields that are not part of the systemd spec)
// System is a context-specific name for the system that the binary package is intended to run on or a part of // System is a context-specific name for the system that the binary package is intended to run on or a part of
System string `json:"system,omitempty"` System string `json:"system,omitempty"`
@ -49,5 +50,6 @@ type ELFBinaryPackageNoteJSONPayload struct {
// PEBinary represents metadata captured from a Portable Executable formatted binary (dll, exe, etc.) // PEBinary represents metadata captured from a Portable Executable formatted binary (dll, exe, etc.)
type PEBinary struct { type PEBinary struct {
// VersionResources contains key-value pairs extracted from the PE file's version resource section (e.g., FileVersion, ProductName, CompanyName).
VersionResources KeyValues VersionResources KeyValues
} }

View File

@ -3,12 +3,25 @@ package pkg
// BitnamiSBOMEntry represents all captured data from Bitnami packages // BitnamiSBOMEntry represents all captured data from Bitnami packages
// described in Bitnami' SPDX files. // described in Bitnami' SPDX files.
type BitnamiSBOMEntry struct { type BitnamiSBOMEntry struct {
// Name is the package name as found in the Bitnami SPDX file
Name string `mapstructure:"name" json:"name"` Name string `mapstructure:"name" json:"name"`
// Architecture is the target CPU architecture (amd64 or arm64 in Bitnami images)
Architecture string `mapstructure:"arch" json:"arch"` Architecture string `mapstructure:"arch" json:"arch"`
// Distro is the distribution name this package is for (base OS like debian, ubuntu, etc.)
Distro string `mapstructure:"distro" json:"distro"` Distro string `mapstructure:"distro" json:"distro"`
// Revision is the Bitnami-specific package revision number (incremented for Bitnami rebuilds of same upstream version)
Revision string `mapstructure:"revision" json:"revision"` Revision string `mapstructure:"revision" json:"revision"`
// Version is the package version as found in the Bitnami SPDX file
Version string `mapstructure:"version" json:"version"` Version string `mapstructure:"version" json:"version"`
// Path is the installation path in the filesystem where the package is located
Path string `mapstructure:"path" json:"path"` Path string `mapstructure:"path" json:"path"`
// Files are the file paths owned by this package (tracked via SPDX relationships)
Files []string `mapstructure:"files" json:"files"` Files []string `mapstructure:"files" json:"files"`
} }

View File

@ -2,5 +2,6 @@ package pkg
// CocoaPodfileLockEntry represents a single entry from the "Pods" section of a Podfile.lock file. // CocoaPodfileLockEntry represents a single entry from the "Pods" section of a Podfile.lock file.
type CocoaPodfileLockEntry struct { type CocoaPodfileLockEntry struct {
// Checksum is the SHA-1 hash of the podspec file for integrity verification (generated via `pod ipc spec ... | openssl sha1`), ensuring all team members use the same pod specification version
Checksum string `mapstructure:"checksum" json:"checksum"` Checksum string `mapstructure:"checksum" json:"checksum"`
} }

View File

@ -2,35 +2,69 @@ package pkg
// ConanV1LockEntry represents a single "node" entry from a conan.lock V1 file. // ConanV1LockEntry represents a single "node" entry from a conan.lock V1 file.
type ConanV1LockEntry struct { type ConanV1LockEntry struct {
// Ref is the package reference string in format name/version@user/channel
Ref string `json:"ref"` Ref string `json:"ref"`
// PackageID is a unique package variant identifier computed from settings/options (static hash in Conan 1.x, can have collisions with complex dependency graphs)
PackageID string `json:"package_id,omitempty"` PackageID string `json:"package_id,omitempty"`
// Prev is the previous lock entry reference for versioning
Prev string `json:"prev,omitempty"` Prev string `json:"prev,omitempty"`
// Requires are the runtime package dependencies
Requires []string `json:"requires,omitempty"` Requires []string `json:"requires,omitempty"`
// BuildRequires are the build-time dependencies (e.g. cmake, compilers)
BuildRequires []string `json:"build_requires,omitempty"` BuildRequires []string `json:"build_requires,omitempty"`
// PythonRequires are the Python dependencies needed for Conan recipes
PythonRequires []string `json:"py_requires,omitempty"` PythonRequires []string `json:"py_requires,omitempty"`
// Options are package configuration options as key-value pairs (e.g. shared=True, fPIC=True)
Options KeyValues `json:"options,omitempty"` Options KeyValues `json:"options,omitempty"`
// Path is the filesystem path to the package in Conan cache
Path string `json:"path,omitempty"` Path string `json:"path,omitempty"`
// Context is the build context information
Context string `json:"context,omitempty"` Context string `json:"context,omitempty"`
} }
// ConanV2LockEntry represents a single "node" entry from a conan.lock V2 file. // ConanV2LockEntry represents a single "node" entry from a conan.lock V2 file.
type ConanV2LockEntry struct { type ConanV2LockEntry struct {
// Ref is the package reference string in format name/version@user/channel
Ref string `json:"ref"` Ref string `json:"ref"`
// PackageID is a unique package variant identifier (dynamic in Conan 2.0, more accurate than V1)
PackageID string `json:"packageID,omitempty"` PackageID string `json:"packageID,omitempty"`
// Username is the Conan user/organization name
Username string `json:"username,omitempty"` Username string `json:"username,omitempty"`
// Channel is the Conan channel name indicating stability/purpose (e.g. stable, testing, experimental)
Channel string `json:"channel,omitempty"` Channel string `json:"channel,omitempty"`
// RecipeRevision is a git-like revision hash (RREV) of the recipe
RecipeRevision string `json:"recipeRevision,omitempty"` RecipeRevision string `json:"recipeRevision,omitempty"`
// PackageRevision is a git-like revision hash of the built binary package
PackageRevision string `json:"packageRevision,omitempty"` PackageRevision string `json:"packageRevision,omitempty"`
// TimeStamp is when this package was built/locked
TimeStamp string `json:"timestamp,omitempty"` TimeStamp string `json:"timestamp,omitempty"`
} }
// ConanfileEntry represents a single "Requires" entry from a conanfile.txt. // ConanfileEntry represents a single "Requires" entry from a conanfile.txt.
type ConanfileEntry struct { type ConanfileEntry struct {
// Ref is the package reference string in format name/version@user/channel
Ref string `mapstructure:"ref" json:"ref"` Ref string `mapstructure:"ref" json:"ref"`
} }
// ConaninfoEntry represents a single "full_requires" entry from a conaninfo.txt. // ConaninfoEntry represents a single "full_requires" entry from a conaninfo.txt.
type ConaninfoEntry struct { type ConaninfoEntry struct {
// Ref is the package reference string in format name/version@user/channel
Ref string `json:"ref"` Ref string `json:"ref"`
// PackageID is a unique package variant identifier
PackageID string `json:"package_id,omitempty"` PackageID string `json:"package_id,omitempty"`
} }

View File

@ -6,45 +6,105 @@ import (
"github.com/scylladb/go-set/strset" "github.com/scylladb/go-set/strset"
) )
// CondaPathData represents metadata for a single file within a Conda package from the paths.json file.
type CondaPathData struct { type CondaPathData struct {
// Path is the file path relative to the Conda environment root.
Path string `json:"_path"` Path string `json:"_path"`
// PathType indicates the link type for the file (e.g., "hardlink", "softlink", "directory").
PathType string `json:"path_type"` PathType string `json:"path_type"`
// SHA256 is the SHA-256 hash of the file contents.
SHA256 string `json:"sha256"` SHA256 string `json:"sha256"`
// SHA256InPrefix is the SHA-256 hash of the file after prefix replacement during installation.
SHA256InPrefix string `json:"sha256_in_prefix"` SHA256InPrefix string `json:"sha256_in_prefix"`
// SizeInBytes is the file size in bytes.
SizeInBytes int64 `json:"size_in_bytes"` SizeInBytes int64 `json:"size_in_bytes"`
} }
// CondaPathsData represents the paths.json file structure from a Conda package containing file metadata.
type CondaPathsData struct { type CondaPathsData struct {
// PathsVersion is the schema version of the paths data format.
PathsVersion int `json:"paths_version"` PathsVersion int `json:"paths_version"`
// Paths is the list of file metadata entries for all files in the package.
Paths []CondaPathData `json:"paths"` Paths []CondaPathData `json:"paths"`
} }
// CondaLink represents link metadata from a Conda package's link.json file describing package installation source.
type CondaLink struct { type CondaLink struct {
// Source is the original path where the package was extracted from cache.
Source string `json:"source"` Source string `json:"source"`
// Type indicates the link type (1 for hard link, 2 for soft link, 3 for copy).
Type int `json:"type"` Type int `json:"type"`
} }
// CondaMetaPackage represents metadata for a Conda package extracted from the conda-meta/*.json files.
type CondaMetaPackage struct { type CondaMetaPackage struct {
// Arch is the target CPU architecture for the package (e.g., "arm64", "x86_64").
Arch string `json:"arch,omitempty"` Arch string `json:"arch,omitempty"`
// Name is the package name as found in the conda-meta JSON file.
Name string `json:"name"` Name string `json:"name"`
// Version is the package version as found in the conda-meta JSON file.
Version string `json:"version"` Version string `json:"version"`
// Build is the build string identifier (e.g., "h90dfc92_1014").
Build string `json:"build"` Build string `json:"build"`
// BuildNumber is the sequential build number for this version.
BuildNumber int `json:"build_number"` BuildNumber int `json:"build_number"`
// Channel is the Conda channel URL where the package was retrieved from.
Channel string `json:"channel,omitempty"` Channel string `json:"channel,omitempty"`
// Subdir is the subdirectory within the channel (e.g., "osx-arm64", "linux-64").
Subdir string `json:"subdir,omitempty"` Subdir string `json:"subdir,omitempty"`
// Noarch indicates if the package is platform-independent (e.g., "python", "generic").
Noarch string `json:"noarch,omitempty"` Noarch string `json:"noarch,omitempty"`
// License is the package license identifier.
License string `json:"license,omitempty"` License string `json:"license,omitempty"`
// LicenseFamily is the general license category (e.g., "MIT", "Apache", "GPL").
LicenseFamily string `json:"license_family,omitempty"` LicenseFamily string `json:"license_family,omitempty"`
// MD5 is the MD5 hash of the package archive.
MD5 string `json:"md5,omitempty"` MD5 string `json:"md5,omitempty"`
// SHA256 is the SHA-256 hash of the package archive.
SHA256 string `json:"sha256,omitempty"` SHA256 string `json:"sha256,omitempty"`
// Size is the package archive size in bytes.
Size int64 `json:"size,omitempty"` Size int64 `json:"size,omitempty"`
// Timestamp is the Unix timestamp when the package was built.
Timestamp int64 `json:"timestamp,omitempty"` Timestamp int64 `json:"timestamp,omitempty"`
// Filename is the original package archive filename (e.g., "zlib-1.2.11-h90dfc92_1014.tar.bz2").
Filename string `json:"fn,omitempty"` Filename string `json:"fn,omitempty"`
// URL is the full download URL for the package archive.
URL string `json:"url,omitempty"` URL string `json:"url,omitempty"`
// ExtractedPackageDir is the local cache directory where the package was extracted.
ExtractedPackageDir string `json:"extracted_package_dir,omitempty"` ExtractedPackageDir string `json:"extracted_package_dir,omitempty"`
// Depends is the list of runtime dependencies with version constraints.
Depends []string `json:"depends,omitempty"` Depends []string `json:"depends,omitempty"`
// Files is the list of files installed by this package.
Files []string `json:"files,omitempty"` Files []string `json:"files,omitempty"`
// PathsData contains detailed file metadata from the paths.json file.
PathsData *CondaPathsData `json:"paths_data,omitempty"` PathsData *CondaPathsData `json:"paths_data,omitempty"`
// Link contains installation source metadata from the link.json file.
Link *CondaLink `json:"link,omitempty"` Link *CondaLink `json:"link,omitempty"`
} }

View File

@ -2,24 +2,48 @@ package pkg
// DartPubspecLockEntry is a struct that represents a single entry found in the "packages" section in a Dart pubspec.lock file. // DartPubspecLockEntry is a struct that represents a single entry found in the "packages" section in a Dart pubspec.lock file.
type DartPubspecLockEntry struct { type DartPubspecLockEntry struct {
// Name is the package name as found in the pubspec.lock file
Name string `mapstructure:"name" json:"name"` Name string `mapstructure:"name" json:"name"`
// Version is the package version as found in the pubspec.lock file
Version string `mapstructure:"version" json:"version"` Version string `mapstructure:"version" json:"version"`
// HostedURL is the URL of the package repository for hosted packages (typically pub.dev, but can be custom repository identified by hosted-url). When PUB_HOSTED_URL environment variable changes, lockfile tracks the source.
HostedURL string `mapstructure:"hosted_url" json:"hosted_url,omitempty"` HostedURL string `mapstructure:"hosted_url" json:"hosted_url,omitempty"`
// VcsURL is the URL of the VCS repository for git/path dependencies (for packages fetched from version control systems like Git)
VcsURL string `mapstructure:"vcs_url" json:"vcs_url,omitempty"` VcsURL string `mapstructure:"vcs_url" json:"vcs_url,omitempty"`
} }
// DartPubspec is a struct that represents a package described in a pubspec.yaml file // DartPubspec is a struct that represents a package described in a pubspec.yaml file
type DartPubspec struct { type DartPubspec struct {
// Homepage is the package homepage URL
Homepage string `mapstructure:"homepage" json:"homepage,omitempty"` Homepage string `mapstructure:"homepage" json:"homepage,omitempty"`
// Repository is the source code repository URL
Repository string `mapstructure:"repository" json:"repository,omitempty"` Repository string `mapstructure:"repository" json:"repository,omitempty"`
// Documentation is the documentation site URL
Documentation string `mapstructure:"documentation" json:"documentation,omitempty"` Documentation string `mapstructure:"documentation" json:"documentation,omitempty"`
// PublishTo is the package repository to publish to, or "none" to prevent accidental publishing
PublishTo string `mapstructure:"publish_to" json:"publish_to,omitempty"` PublishTo string `mapstructure:"publish_to" json:"publish_to,omitempty"`
// Environment is SDK version constraints for Dart and Flutter
Environment *DartPubspecEnvironment `mapstructure:"environment" json:"environment,omitempty"` Environment *DartPubspecEnvironment `mapstructure:"environment" json:"environment,omitempty"`
// Platforms are the supported platforms (Android, iOS, web, etc.)
Platforms []string `mapstructure:"platforms" json:"platforms,omitempty"` Platforms []string `mapstructure:"platforms" json:"platforms,omitempty"`
// IgnoredAdvisories are the security advisories to explicitly ignore for this package
IgnoredAdvisories []string `mapstructure:"ignored_advisories" json:"ignored_advisories,omitempty"` IgnoredAdvisories []string `mapstructure:"ignored_advisories" json:"ignored_advisories,omitempty"`
} }
// DartPubspecEnvironment represents SDK version constraints from the environment section of pubspec.yaml.
type DartPubspecEnvironment struct { type DartPubspecEnvironment struct {
// SDK is the Dart SDK version constraint (e.g. ">=2.12.0 <3.0.0")
SDK string `mapstructure:"sdk" json:"sdk,omitempty"` SDK string `mapstructure:"sdk" json:"sdk,omitempty"`
// Flutter is the Flutter SDK version constraint if this is a Flutter package
Flutter string `mapstructure:"flutter" json:"flutter,omitempty"` Flutter string `mapstructure:"flutter" json:"flutter,omitempty"`
} }

View File

@ -2,30 +2,60 @@ package pkg
// DotnetDepsEntry is a struct that represents a single entry found in the "libraries" section in a .NET [*.]deps.json file. // DotnetDepsEntry is a struct that represents a single entry found in the "libraries" section in a .NET [*.]deps.json file.
type DotnetDepsEntry struct { type DotnetDepsEntry struct {
// Name is the package name as found in the deps.json file
Name string `mapstructure:"name" json:"name"` Name string `mapstructure:"name" json:"name"`
// Version is the package version as found in the deps.json file
Version string `mapstructure:"version" json:"version"` Version string `mapstructure:"version" json:"version"`
// Path is the relative path to the package within the deps structure (e.g. "app.metrics/3.0.0")
Path string `mapstructure:"path" json:"path"` Path string `mapstructure:"path" json:"path"`
// Sha512 is the SHA-512 hash of the NuGet package content WITHOUT the signed content for verification (won't match hash from NuGet API or manual calculation of .nupkg file)
Sha512 string `mapstructure:"sha512" json:"sha512"` Sha512 string `mapstructure:"sha512" json:"sha512"`
// HashPath is the relative path to the .nupkg.sha512 hash file (e.g. "app.metrics.3.0.0.nupkg.sha512")
HashPath string `mapstructure:"hashPath" json:"hashPath"` HashPath string `mapstructure:"hashPath" json:"hashPath"`
// Executables are the map of .NET Portable Executable files within this package with their version resources
Executables map[string]DotnetPortableExecutableEntry `json:"executables,omitempty"` Executables map[string]DotnetPortableExecutableEntry `json:"executables,omitempty"`
} }
// DotnetPackagesLockEntry is a struct that represents a single entry found in the "dependencies" section in a .NET packages.lock.json file. // DotnetPackagesLockEntry is a struct that represents a single entry found in the "dependencies" section in a .NET packages.lock.json file.
type DotnetPackagesLockEntry struct { type DotnetPackagesLockEntry struct {
// Name is the package name as found in the packages.lock.json file
Name string `mapstructure:"name" json:"name"` Name string `mapstructure:"name" json:"name"`
// Version is the package version as found in the packages.lock.json file
Version string `mapstructure:"version" json:"version"` Version string `mapstructure:"version" json:"version"`
// ContentHash is the hash of the package content for verification
ContentHash string `mapstructure:"contentHash" json:"contentHash"` ContentHash string `mapstructure:"contentHash" json:"contentHash"`
// Type is the dependency type indicating how this dependency was added (Direct=explicit in project file, Transitive=pulled in by another package, Project=project reference)
Type string `mapstructure:"type" json:"type"` Type string `mapstructure:"type" json:"type"`
} }
// DotnetPortableExecutableEntry is a struct that represents a single entry found within "VersionResources" section of a .NET Portable Executable binary file. // DotnetPortableExecutableEntry is a struct that represents a single entry found within "VersionResources" section of a .NET Portable Executable binary file.
type DotnetPortableExecutableEntry struct { type DotnetPortableExecutableEntry struct {
// AssemblyVersion is the .NET assembly version number (strong-named version)
AssemblyVersion string `json:"assemblyVersion"` AssemblyVersion string `json:"assemblyVersion"`
// LegalCopyright is the copyright notice string
LegalCopyright string `json:"legalCopyright"` LegalCopyright string `json:"legalCopyright"`
// Comments are additional comments or description embedded in PE resources
Comments string `json:"comments,omitempty"` Comments string `json:"comments,omitempty"`
// InternalName is the internal name of the file
InternalName string `json:"internalName,omitempty"` InternalName string `json:"internalName,omitempty"`
// CompanyName is the company that produced the file
CompanyName string `json:"companyName"` CompanyName string `json:"companyName"`
// ProductName is the name of the product this file is part of
ProductName string `json:"productName"` ProductName string `json:"productName"`
// ProductVersion is the version of the product (may differ from AssemblyVersion)
ProductVersion string `json:"productVersion"` ProductVersion string `json:"productVersion"`
} }

View File

@ -12,6 +12,7 @@ const DpkgDBGlob = "**/var/lib/dpkg/{status,status.d/**}"
var _ FileOwner = (*DpkgDBEntry)(nil) var _ FileOwner = (*DpkgDBEntry)(nil)
// DpkgArchiveEntry represents package metadata extracted from a .deb archive file.
type DpkgArchiveEntry DpkgDBEntry type DpkgArchiveEntry DpkgDBEntry
// DpkgDBEntry represents all captured data for a Debian package DB entry; available fields are described // DpkgDBEntry represents all captured data for a Debian package DB entry; available fields are described
@ -22,48 +23,52 @@ type DpkgArchiveEntry DpkgDBEntry
// - https://www.debian.org/doc/debian-policy/ch-binary.html#s-virtual-pkg // - https://www.debian.org/doc/debian-policy/ch-binary.html#s-virtual-pkg
// - https://www.debian.org/doc/debian-policy/ch-relationships.html#s-virtual // - https://www.debian.org/doc/debian-policy/ch-relationships.html#s-virtual
type DpkgDBEntry struct { type DpkgDBEntry struct {
// Package is the package name as found in the status file
Package string `json:"package"` Package string `json:"package"`
// Source is the source package name this binary was built from (one source can produce multiple binary packages)
Source string `json:"source" cyclonedx:"source"` Source string `json:"source" cyclonedx:"source"`
// Version is the binary package version as found in the status file
Version string `json:"version"` Version string `json:"version"`
// SourceVersion is the source package version (may differ from binary version when binNMU rebuilds occur)
SourceVersion string `json:"sourceVersion" cyclonedx:"sourceVersion"` SourceVersion string `json:"sourceVersion" cyclonedx:"sourceVersion"`
// Architecture can include the following sets of values depending on context and the control file used: // Architecture is the target architecture per Debian spec (specific arch like amd64/arm64, wildcard like any, architecture-independent "all", or "source" for source packages)
// - a unique single word identifying a Debian machine architecture as described in Architecture specification string (https://www.debian.org/doc/debian-policy/ch-customized-programs.html#s-arch-spec) .
// - an architecture wildcard identifying a set of Debian machine architectures, see Architecture wildcards (https://www.debian.org/doc/debian-policy/ch-customized-programs.html#s-arch-wildcard-spec). any matches all Debian machine architectures and is the most frequently used.
// - "all", which indicates an architecture-independent package.
// - "source", which indicates a source package.
Architecture string `json:"architecture"` Architecture string `json:"architecture"`
// Maintainer is the package maintainers name and email address. The name must come first, then the email // Maintainer is the package maintainer's name and email in RFC822 format (name must come first, then email in angle brackets)
// address inside angle brackets <> (in RFC822 format).
Maintainer string `json:"maintainer"` Maintainer string `json:"maintainer"`
// InstalledSize is the total size of installed files in kilobytes
InstalledSize int `json:"installedSize" cyclonedx:"installedSize"` InstalledSize int `json:"installedSize" cyclonedx:"installedSize"`
// Description contains a description of the binary package, consisting of two parts, the synopsis or the short // Description is a human-readable package description with synopsis (first line) and long description (multiline format)
// description, and the long description (in a multiline format).
Description string `hash:"ignore" json:"-"` Description string `hash:"ignore" json:"-"`
// Provides is a virtual package that is provided by one or more packages. A virtual package is one which appears // Provides are the virtual packages provided by this package (allows other packages to depend on capabilities. Can include versioned provides like "libdigest-md5-perl (= 2.55.01)")
// in the Provides control field of another package. The effect is as if the package(s) which provide a particular
// virtual package name had been listed by name everywhere the virtual package name appears. (See also Virtual packages)
Provides []string `json:"provides,omitempty"` Provides []string `json:"provides,omitempty"`
// Depends This declares an absolute dependency. A package will not be configured unless all of the packages listed in // Depends are the packages required for this package to function (will not be installed unless these requirements are met, creates strict ordering constraint)
// its Depends field have been correctly configured (unless there is a circular dependency).
Depends []string `json:"depends,omitempty"` Depends []string `json:"depends,omitempty"`
// PreDepends is like Depends, except that it also forces dpkg to complete installation of the packages named // PreDepends are the packages that must be installed and configured BEFORE even starting installation of this package (stronger than Depends, discouraged unless absolutely necessary as it adds strict constraints for apt)
// before even starting the installation of the package which declares the pre-dependency.
PreDepends []string `json:"preDepends,omitempty"` PreDepends []string `json:"preDepends,omitempty"`
// Files are the files installed by this package
Files []DpkgFileRecord `json:"files"` Files []DpkgFileRecord `json:"files"`
} }
// DpkgFileRecord represents a single file attributed to a debian package. // DpkgFileRecord represents a single file attributed to a debian package.
type DpkgFileRecord struct { type DpkgFileRecord struct {
// Path is the file path relative to the filesystem root
Path string `json:"path"` Path string `json:"path"`
// Digest is the file content hash (typically MD5 for dpkg compatibility with legacy systems)
Digest *file.Digest `json:"digest,omitempty"` Digest *file.Digest `json:"digest,omitempty"`
// IsConfigFile is whether this file is marked as a configuration file (dpkg will preserve user modifications during upgrades)
IsConfigFile bool `json:"isConfigFile"` IsConfigFile bool `json:"isConfigFile"`
} }

View File

@ -2,8 +2,15 @@ package pkg
// ElixirMixLockEntry is a struct that represents a single entry in a mix.lock file // ElixirMixLockEntry is a struct that represents a single entry in a mix.lock file
type ElixirMixLockEntry struct { type ElixirMixLockEntry struct {
// Name is the package name as found in the mix.lock file
Name string `mapstructure:"name" json:"name"` Name string `mapstructure:"name" json:"name"`
// Version is the package version as found in the mix.lock file
Version string `mapstructure:"version" json:"version"` Version string `mapstructure:"version" json:"version"`
// PkgHash is the outer checksum (SHA-256) of the entire Hex package tarball for integrity verification (preferred method, replaces deprecated inner checksum)
PkgHash string `mapstructure:"pkgHash" json:"pkgHash"` PkgHash string `mapstructure:"pkgHash" json:"pkgHash"`
// PkgHashExt is the extended package hash format (inner checksum is deprecated - SHA-256 of concatenated file contents excluding CHECKSUM file, now replaced by outer checksum)
PkgHashExt string `mapstructure:"pkgHashExt" json:"pkgHashExt"` PkgHashExt string `mapstructure:"pkgHashExt" json:"pkgHashExt"`
} }

View File

@ -2,8 +2,15 @@ package pkg
// ErlangRebarLockEntry represents a single package entry from the "deps" section within an Erlang rebar.lock file. // ErlangRebarLockEntry represents a single package entry from the "deps" section within an Erlang rebar.lock file.
type ErlangRebarLockEntry struct { type ErlangRebarLockEntry struct {
// Name is the package name as found in the rebar.lock file
Name string `mapstructure:"name" json:"name"` Name string `mapstructure:"name" json:"name"`
// Version is the package version as found in the rebar.lock file
Version string `mapstructure:"version" json:"version"` Version string `mapstructure:"version" json:"version"`
// PkgHash is the outer checksum (SHA-256) of the entire Hex package tarball for integrity verification (preferred method over deprecated inner checksum)
PkgHash string `mapstructure:"pkgHash" json:"pkgHash"` PkgHash string `mapstructure:"pkgHash" json:"pkgHash"`
// PkgHashExt is the extended package hash format (inner checksum deprecated - was SHA-256 of concatenated file contents)
PkgHashExt string `mapstructure:"pkgHashExt" json:"pkgHashExt"` PkgHashExt string `mapstructure:"pkgHashExt" json:"pkgHashExt"`
} }

View File

@ -1,6 +1,10 @@
package pkg package pkg
// GitHubActionsUseStatement represents a single 'uses' statement in a GitHub Actions workflow file referencing an action or reusable workflow.
type GitHubActionsUseStatement struct { type GitHubActionsUseStatement struct {
// Value is the action reference (e.g. "actions/checkout@v3")
Value string `json:"value"` Value string `json:"value"`
// Comment is the inline comment associated with this uses statement
Comment string `json:"comment,omitempty"` Comment string `json:"comment,omitempty"`
} }

View File

@ -2,25 +2,48 @@ package pkg
// GolangBinaryBuildinfoEntry represents all captured data for a Golang binary // GolangBinaryBuildinfoEntry represents all captured data for a Golang binary
type GolangBinaryBuildinfoEntry struct { type GolangBinaryBuildinfoEntry struct {
// BuildSettings contains the Go build settings and flags used to compile the binary (e.g., GOARCH, GOOS, CGO_ENABLED).
BuildSettings KeyValues `json:"goBuildSettings,omitempty" cyclonedx:"goBuildSettings"` BuildSettings KeyValues `json:"goBuildSettings,omitempty" cyclonedx:"goBuildSettings"`
// GoCompiledVersion is the version of Go used to compile the binary.
GoCompiledVersion string `json:"goCompiledVersion" cyclonedx:"goCompiledVersion"` GoCompiledVersion string `json:"goCompiledVersion" cyclonedx:"goCompiledVersion"`
// Architecture is the target CPU architecture for the binary (extracted from GOARCH build setting).
Architecture string `json:"architecture" cyclonedx:"architecture"` Architecture string `json:"architecture" cyclonedx:"architecture"`
// H1Digest is the Go module hash in h1: format for the main module from go.sum.
H1Digest string `json:"h1Digest,omitempty" cyclonedx:"h1Digest"` H1Digest string `json:"h1Digest,omitempty" cyclonedx:"h1Digest"`
// MainModule is the main module path for the binary (e.g., "github.com/anchore/syft").
MainModule string `json:"mainModule,omitempty" cyclonedx:"mainModule"` MainModule string `json:"mainModule,omitempty" cyclonedx:"mainModule"`
// GoCryptoSettings contains FIPS and cryptographic configuration settings if present.
GoCryptoSettings []string `json:"goCryptoSettings,omitempty" cyclonedx:"goCryptoSettings"` GoCryptoSettings []string `json:"goCryptoSettings,omitempty" cyclonedx:"goCryptoSettings"`
// GoExperiments lists experimental Go features enabled during compilation (e.g., "arenas", "cgocheck2").
GoExperiments []string `json:"goExperiments,omitempty" cyclonedx:"goExperiments"` GoExperiments []string `json:"goExperiments,omitempty" cyclonedx:"goExperiments"`
} }
// GolangModuleEntry represents all captured data for a Golang source scan with go.mod/go.sum // GolangModuleEntry represents all captured data for a Golang source scan with go.mod/go.sum
type GolangModuleEntry struct { type GolangModuleEntry struct {
// H1Digest is the Go module hash in h1: format from go.sum for verifying module contents.
H1Digest string `json:"h1Digest,omitempty" cyclonedx:"h1Digest"` H1Digest string `json:"h1Digest,omitempty" cyclonedx:"h1Digest"`
} }
// GolangSourceEntry represents all captured data for a Golang package found through source analysis // GolangSourceEntry represents all captured data for a Golang package found through source analysis
type GolangSourceEntry struct { type GolangSourceEntry struct {
// H1Digest is the Go module hash in h1: format from go.sum for verifying module contents.
H1Digest string `json:"h1Digest,omitempty" cyclonedx:"h1Digest"` H1Digest string `json:"h1Digest,omitempty" cyclonedx:"h1Digest"`
// OperatingSystem is the target OS for build constraints (e.g., "linux", "darwin", "windows").
OperatingSystem string `json:"os,omitempty" cyclonedx:"os"` OperatingSystem string `json:"os,omitempty" cyclonedx:"os"`
// Architecture is the target CPU architecture for build constraints (e.g., "amd64", "arm64").
Architecture string `json:"architecture,omitempty" cyclonedx:"architecture"` Architecture string `json:"architecture,omitempty" cyclonedx:"architecture"`
// BuildTags are the build tags used to conditionally compile code (e.g., "integration,debug").
BuildTags string `json:"buildTags,omitempty" cyclonedx:"buildTags"` BuildTags string `json:"buildTags,omitempty" cyclonedx:"buildTags"`
// CgoEnabled indicates whether CGO was enabled for this package.
CgoEnabled bool `json:"cgoEnabled" cyclonedx:"cgoEnabled"` CgoEnabled bool `json:"cgoEnabled" cyclonedx:"cgoEnabled"`
} }

View File

@ -2,11 +2,15 @@ package pkg
// HackageStackYamlLockEntry represents a single entry from the "packages" section of a stack.yaml.lock file. // HackageStackYamlLockEntry represents a single entry from the "packages" section of a stack.yaml.lock file.
type HackageStackYamlLockEntry struct { type HackageStackYamlLockEntry struct {
// PkgHash is the package content hash for verification
PkgHash string `mapstructure:"pkgHash" json:"pkgHash,omitempty"` PkgHash string `mapstructure:"pkgHash" json:"pkgHash,omitempty"`
// SnapshotURL is the URL to the Stack snapshot this package came from
SnapshotURL string `mapstructure:"snapshotURL" json:"snapshotURL,omitempty"` SnapshotURL string `mapstructure:"snapshotURL" json:"snapshotURL,omitempty"`
} }
// HackageStackYamlEntry represents a single entry from the "extra-deps" section of a stack.yaml file. // HackageStackYamlEntry represents a single entry from the "extra-deps" section of a stack.yaml file.
type HackageStackYamlEntry struct { type HackageStackYamlEntry struct {
// PkgHash is the package content hash for verification
PkgHash string `mapstructure:"pkgHash" json:"pkgHash,omitempty"` PkgHash string `mapstructure:"pkgHash" json:"pkgHash,omitempty"`
} }

View File

@ -1,7 +1,13 @@
package pkg package pkg
// HomebrewFormula represents metadata about a Homebrew formula package extracted from formula JSON files.
type HomebrewFormula struct { type HomebrewFormula struct {
// Tap is Homebrew tap this formula belongs to (e.g. "homebrew/core")
Tap string `json:"tap,omitempty"` Tap string `json:"tap,omitempty"`
// Homepage is the upstream project homepage URL
Homepage string `json:"homepage,omitempty"` Homepage string `json:"homepage,omitempty"`
// Description is a human-readable formula description
Description string `json:"description,omitempty"` Description string `json:"description,omitempty"`
} }

View File

@ -18,8 +18,12 @@ var jenkinsPluginPomPropertiesGroupIDs = []string{
"com.cloudbees.jenkins.plugins", "com.cloudbees.jenkins.plugins",
} }
// JavaVMInstallation represents a Java Virtual Machine installation discovered on the system with its release information and file list.
type JavaVMInstallation struct { type JavaVMInstallation struct {
// Release is JVM release information and version details
Release JavaVMRelease `json:"release"` Release JavaVMRelease `json:"release"`
// Files are the list of files that are part of this JVM installation
Files []string `json:"files"` Files []string `json:"files"`
} }
@ -27,6 +31,7 @@ func (m JavaVMInstallation) OwnedFiles() []string {
return m.Files return m.Files
} }
// JavaVMRelease represents JVM version and build information extracted from the release file in a Java installation.
type JavaVMRelease struct { type JavaVMRelease struct {
// Implementor is extracted with the `java.vendor` JVM property // Implementor is extracted with the `java.vendor` JVM property
Implementor string `mapstructure:"IMPLEMENTOR,omitempty" json:"implementor,omitempty"` Implementor string `mapstructure:"IMPLEMENTOR,omitempty" json:"implementor,omitempty"`
@ -94,41 +99,85 @@ type JavaVMRelease struct {
// JavaArchive encapsulates all Java ecosystem metadata for a package as well as an (optional) parent relationship. // JavaArchive encapsulates all Java ecosystem metadata for a package as well as an (optional) parent relationship.
type JavaArchive struct { type JavaArchive struct {
VirtualPath string `json:"virtualPath" cyclonedx:"virtualPath"` // we need to include the virtual path in cyclonedx documents to prevent deduplication of jars within jars // VirtualPath is path within the archive hierarchy, where nested entries are delimited with ':' (for nested JARs)
VirtualPath string `json:"virtualPath" cyclonedx:"virtualPath"`
// Manifest is parsed META-INF/MANIFEST.MF contents
Manifest *JavaManifest `mapstructure:"Manifest" json:"manifest,omitempty"` Manifest *JavaManifest `mapstructure:"Manifest" json:"manifest,omitempty"`
// PomProperties is parsed pom.properties file contents
PomProperties *JavaPomProperties `mapstructure:"PomProperties" json:"pomProperties,omitempty" cyclonedx:"-"` PomProperties *JavaPomProperties `mapstructure:"PomProperties" json:"pomProperties,omitempty" cyclonedx:"-"`
// PomProject is parsed pom.xml file contents
PomProject *JavaPomProject `mapstructure:"PomProject" json:"pomProject,omitempty"` PomProject *JavaPomProject `mapstructure:"PomProject" json:"pomProject,omitempty"`
// ArchiveDigests is cryptographic hashes of the archive file
ArchiveDigests []file.Digest `hash:"ignore" json:"digest,omitempty"` ArchiveDigests []file.Digest `hash:"ignore" json:"digest,omitempty"`
Parent *Package `hash:"ignore" json:"-"` // note: the parent cannot be included in the minimal definition of uniqueness since this field is not reproducible in an encode-decode cycle (is lossy).
// Parent is reference to parent package (for nested archives)
Parent *Package `hash:"ignore" json:"-"`
} }
// JavaPomProperties represents the fields of interest extracted from a Java archive's pom.properties file. // JavaPomProperties represents the fields of interest extracted from a Java archive's pom.properties file.
type JavaPomProperties struct { type JavaPomProperties struct {
// Path is path to the pom.properties file within the archive
Path string `mapstructure:"path" json:"path"` Path string `mapstructure:"path" json:"path"`
// Name is the project name
Name string `mapstructure:"name" json:"name"` Name string `mapstructure:"name" json:"name"`
// GroupID is Maven group identifier uniquely identifying the project across all projects (follows reversed domain name convention like com.company.project)
GroupID string `mapstructure:"groupId" json:"groupId" cyclonedx:"groupID"` GroupID string `mapstructure:"groupId" json:"groupId" cyclonedx:"groupID"`
// ArtifactID is Maven artifact identifier, the name of the jar/artifact (unique within the groupId scope)
ArtifactID string `mapstructure:"artifactId" json:"artifactId" cyclonedx:"artifactID"` ArtifactID string `mapstructure:"artifactId" json:"artifactId" cyclonedx:"artifactID"`
// Version is artifact version
Version string `mapstructure:"version" json:"version"` Version string `mapstructure:"version" json:"version"`
// Scope is dependency scope determining when dependency is available (compile=default all phases, test=test compilation/execution only, runtime=runtime and test not compile, provided=expected from JDK or container)
Scope string `mapstructure:"scope" json:"scope,omitempty"` Scope string `mapstructure:"scope" json:"scope,omitempty"`
// Extra is additional custom properties not in standard Maven coordinates
Extra map[string]string `mapstructure:",remain" json:"extraFields,omitempty"` Extra map[string]string `mapstructure:",remain" json:"extraFields,omitempty"`
} }
// JavaPomProject represents fields of interest extracted from a Java archive's pom.xml file. See https://maven.apache.org/ref/3.6.3/maven-model/maven.html for more details. // JavaPomProject represents fields of interest extracted from a Java archive's pom.xml file. See https://maven.apache.org/ref/3.6.3/maven-model/maven.html for more details.
type JavaPomProject struct { type JavaPomProject struct {
// Path is path to the pom.xml file within the archive
Path string `json:"path"` Path string `json:"path"`
// Parent is the parent POM reference for inheritance (child POMs inherit configuration from parent)
Parent *JavaPomParent `json:"parent,omitempty"` Parent *JavaPomParent `json:"parent,omitempty"`
// GroupID is Maven group identifier (reversed domain name like org.apache.maven)
GroupID string `json:"groupId"` GroupID string `json:"groupId"`
// ArtifactID is Maven artifact identifier (project name)
ArtifactID string `json:"artifactId"` ArtifactID string `json:"artifactId"`
// Version is project version (together with groupId and artifactId forms Maven coordinates groupId:artifactId:version)
Version string `json:"version"` Version string `json:"version"`
// Name is a human-readable project name (displayed in Maven-generated documentation)
Name string `json:"name"` Name string `json:"name"`
// Description is detailed project description
Description string `json:"description,omitempty"` Description string `json:"description,omitempty"`
// URL is the project URL (typically project website or repository)
URL string `json:"url,omitempty"` URL string `json:"url,omitempty"`
} }
// JavaPomParent contains the fields within the <parent> tag in a pom.xml file // JavaPomParent contains the fields within the <parent> tag in a pom.xml file
type JavaPomParent struct { type JavaPomParent struct {
// GroupID is the parent Maven group identifier
GroupID string `json:"groupId"` GroupID string `json:"groupId"`
// ArtifactID is the parent Maven artifact identifier
ArtifactID string `json:"artifactId"` ArtifactID string `json:"artifactId"`
// Version is the parent version (child inherits configuration from this specific version of parent POM)
Version string `json:"version"` Version string `json:"version"`
} }
@ -143,7 +192,10 @@ func (p JavaPomProperties) PkgTypeIndicated() Type {
// JavaManifest represents the fields of interest extracted from a Java archive's META-INF/MANIFEST.MF file. // JavaManifest represents the fields of interest extracted from a Java archive's META-INF/MANIFEST.MF file.
type JavaManifest struct { type JavaManifest struct {
// Main is main manifest attributes as key-value pairs
Main KeyValues `json:"main,omitempty"` Main KeyValues `json:"main,omitempty"`
// Sections are the named sections from the manifest (e.g. per-entry attributes)
Sections []KeyValues `json:"sections,omitempty"` Sections []KeyValues `json:"sections,omitempty"`
} }

View File

@ -6,11 +6,16 @@ import (
"sort" "sort"
) )
// KeyValue represents a single key-value pair.
type KeyValue struct { type KeyValue struct {
// Key is the key name
Key string `json:"key"` Key string `json:"key"`
// Value is the value associated with the key
Value string `json:"value"` Value string `json:"value"`
} }
// KeyValues represents an ordered collection of key-value pairs that preserves insertion order.
type KeyValues []KeyValue type KeyValues []KeyValue
func (k KeyValues) Get(key string) (string, bool) { func (k KeyValues) Get(key string) (string, bool) {

View File

@ -22,28 +22,38 @@ import (
var _ sort.Interface = (*Licenses)(nil) var _ sort.Interface = (*Licenses)(nil)
// License represents an SPDX Expression or license value extracted from a package's metadata // License represents an SPDX Expression or license value extracted from a package's metadata.
// We want to ignore URLs and Location since we merge these fields across equal licenses. // A License is a unique combination of value, expression and type, where its sources are always
// A License is a unique combination of value, expression and type, where // considered merged and additions to the evidence of where it was found and how it was sourced.
// its sources are always considered merged and additions to the evidence // This is different from how we treat a package since we consider package paths in order to
// of where it was found and how it was sourced. // distinguish if packages should be kept separate. This is different for licenses since we're
// This is different from how we treat a package since we consider package paths // only looking for evidence of where a license was declared/concluded for a given package.
// in order to distinguish if packages should be kept separate
// this is different for licenses since we're only looking for evidence
// of where a license was declared/concluded for a given package.
// If a license is given as it's full text in the metadata rather than it's value or SPDX expression.
// The Contents field is used to represent this data.
// A Concluded License type is the license the SBOM creator believes governs the package (human crafted or altered SBOM).
// The Declared License is what the authors of a project believe govern the package. This is the default type syft declares.
type License struct { type License struct {
// SPDXExpression is parsed SPDX license expression (e.g. "MIT OR Apache-2.0")
SPDXExpression string SPDXExpression string
// Value is original raw license string as found in metadata (e.g. "mit or apache-2")
Value string Value string
// Type is classification of how this license was discovered (declared, concluded, etc.).
// A Concluded License type is the license the SBOM creator believes governs the package (human crafted or altered SBOM).
// The Declared License is what the authors of a project believe govern the package (this is the default type syft uses).
Type license.Type Type license.Type
Contents string `hash:"ignore"` // we want to ignore the contents here so we can drop contents in the post-processing step
URLs []string `hash:"ignore"` // TODO: there is such thing as a url-only license, but we aren't hashing on this, which means overwriting could occur in the license set // Contents is full license text if available. If a license is given as its full text in the
// metadata rather than its value or SPDX expression, this field is used to represent that data.
Contents string `hash:"ignore"`
// URLs are the list of URLs where license information was found. These are ignored for uniqueness
// since we merge these fields across equal licenses.
URLs []string `hash:"ignore"`
// Locations are the file locations where this license was discovered. These are ignored for uniqueness
// since we merge these fields across equal licenses.
Locations file.LocationSet `hash:"ignore"` Locations file.LocationSet `hash:"ignore"`
} }
// Licenses is a sortable collection of License objects implementing sort.Interface.
type Licenses []License type Licenses []License
func (l Licenses) Len() int { func (l Licenses) Len() int {
@ -190,11 +200,17 @@ func (s License) Merge(l License) (*License, error) {
return &s, nil return &s, nil
} }
// licenseBuilder is an internal builder for constructing License objects with validation and normalization.
type licenseBuilder struct { type licenseBuilder struct {
// values are raw license strings or SPDX expressions to process.
values []string values []string
// contents are readers for full license text content.
contents []io.ReadCloser contents []io.ReadCloser
// locations are file locations where license information was discovered.
locations []file.Location locations []file.Location
// urls are web URLs where license information can be found.
urls []string urls []string
// tp is the license type classification (declared, concluded, etc.).
tp license.Type tp license.Type
} }

View File

@ -2,33 +2,78 @@ package pkg
// LinuxKernel represents all captured data for a Linux kernel // LinuxKernel represents all captured data for a Linux kernel
type LinuxKernel struct { type LinuxKernel struct {
// Name is kernel name (typically "Linux")
Name string `mapstructure:"name" json:"name" cyclonedx:"name"` Name string `mapstructure:"name" json:"name" cyclonedx:"name"`
// Architecture is the target CPU architecture
Architecture string `mapstructure:"architecture" json:"architecture" cyclonedx:"architecture"` Architecture string `mapstructure:"architecture" json:"architecture" cyclonedx:"architecture"`
// Version is kernel version string
Version string `mapstructure:"version" json:"version" cyclonedx:"version"` Version string `mapstructure:"version" json:"version" cyclonedx:"version"`
// ExtendedVersion is additional version information
ExtendedVersion string `mapstructure:"extendedVersion" json:"extendedVersion,omitempty" cyclonedx:"extendedVersion"` ExtendedVersion string `mapstructure:"extendedVersion" json:"extendedVersion,omitempty" cyclonedx:"extendedVersion"`
// BuildTime is when the kernel was built
BuildTime string `mapstructure:"buildTime" json:"buildTime,omitempty" cyclonedx:"buildTime"` BuildTime string `mapstructure:"buildTime" json:"buildTime,omitempty" cyclonedx:"buildTime"`
// Author is who built the kernel
Author string `mapstructure:"author" json:"author,omitempty" cyclonedx:"author"` Author string `mapstructure:"author" json:"author,omitempty" cyclonedx:"author"`
// Format is kernel image format (e.g. bzImage, zImage)
Format string `mapstructure:"format" json:"format,omitempty" cyclonedx:"format"` Format string `mapstructure:"format" json:"format,omitempty" cyclonedx:"format"`
// RWRootFS is whether root filesystem is mounted read-write
RWRootFS bool `mapstructure:"rwRootFS" json:"rwRootFS,omitempty" cyclonedx:"rwRootFS"` RWRootFS bool `mapstructure:"rwRootFS" json:"rwRootFS,omitempty" cyclonedx:"rwRootFS"`
// SwapDevice is swap device number
SwapDevice int `mapstructure:"swapDevice" json:"swapDevice,omitempty" cyclonedx:"swapDevice"` SwapDevice int `mapstructure:"swapDevice" json:"swapDevice,omitempty" cyclonedx:"swapDevice"`
// RootDevice is root device number
RootDevice int `mapstructure:"rootDevice" json:"rootDevice,omitempty" cyclonedx:"rootDevice"` RootDevice int `mapstructure:"rootDevice" json:"rootDevice,omitempty" cyclonedx:"rootDevice"`
// VideoMode is default video mode setting
VideoMode string `mapstructure:"videoMode" json:"videoMode,omitempty" cyclonedx:"videoMode"` VideoMode string `mapstructure:"videoMode" json:"videoMode,omitempty" cyclonedx:"videoMode"`
} }
// LinuxKernelModule represents a loadable kernel module (.ko file) with its metadata, parameters, and dependencies.
type LinuxKernelModule struct { type LinuxKernelModule struct {
// Name is module name
Name string `mapstructure:"name" json:"name,omitempty" cyclonedx:"name"` Name string `mapstructure:"name" json:"name,omitempty" cyclonedx:"name"`
// Version is module version string
Version string `mapstructure:"version" json:"version,omitempty" cyclonedx:"version"` Version string `mapstructure:"version" json:"version,omitempty" cyclonedx:"version"`
// SourceVersion is the source code version identifier
SourceVersion string `mapstructure:"sourceVersion" json:"sourceVersion,omitempty" cyclonedx:"sourceVersion"` SourceVersion string `mapstructure:"sourceVersion" json:"sourceVersion,omitempty" cyclonedx:"sourceVersion"`
// Path is the filesystem path to the .ko kernel object file (absolute path)
Path string `mapstructure:"path" json:"path,omitempty" cyclonedx:"path"` Path string `mapstructure:"path" json:"path,omitempty" cyclonedx:"path"`
// Description is a human-readable module description
Description string `mapstructure:"description" json:"description,omitempty" cyclonedx:"description"` Description string `mapstructure:"description" json:"description,omitempty" cyclonedx:"description"`
// Author is module author name and email
Author string `mapstructure:"author" json:"author,omitempty" cyclonedx:"author"` Author string `mapstructure:"author" json:"author,omitempty" cyclonedx:"author"`
// License is module license (e.g. GPL, BSD) which must be compatible with kernel
License string `mapstructure:"license" json:"license,omitempty" cyclonedx:"license"` License string `mapstructure:"license" json:"license,omitempty" cyclonedx:"license"`
// KernelVersion is kernel version this module was built for
KernelVersion string `mapstructure:"kernelVersion" json:"kernelVersion,omitempty" cyclonedx:"kernelVersion"` KernelVersion string `mapstructure:"kernelVersion" json:"kernelVersion,omitempty" cyclonedx:"kernelVersion"`
// VersionMagic is version magic string for compatibility checking (includes kernel version, SMP status, module loading capabilities like "3.17.4-302.fc21.x86_64 SMP mod_unload modversions"). Module will NOT load if vermagic doesn't match running kernel.
VersionMagic string `mapstructure:"versionMagic" json:"versionMagic,omitempty" cyclonedx:"versionMagic"` VersionMagic string `mapstructure:"versionMagic" json:"versionMagic,omitempty" cyclonedx:"versionMagic"`
// Parameters are the module parameters that can be configured at load time (user-settable values like module options)
Parameters map[string]LinuxKernelModuleParameter `mapstructure:"parameters" json:"parameters,omitempty" cyclonedx:"parameters"` Parameters map[string]LinuxKernelModuleParameter `mapstructure:"parameters" json:"parameters,omitempty" cyclonedx:"parameters"`
} }
// LinuxKernelModuleParameter represents a configurable parameter for a kernel module with its type and description.
type LinuxKernelModuleParameter struct { type LinuxKernelModuleParameter struct {
// Type is parameter data type (e.g. int, string, bool, array types)
Type string `mapstructure:"type" json:"type,omitempty" cyclonedx:"type"` Type string `mapstructure:"type" json:"type,omitempty" cyclonedx:"type"`
// Description is a human-readable parameter description explaining what the parameter controls
Description string `mapstructure:"description" json:"description,omitempty" cyclonedx:"description"` Description string `mapstructure:"description" json:"description,omitempty" cyclonedx:"description"`
} }

View File

@ -6,6 +6,9 @@ package pkg
// "Windows 10 Version 1703 for 32-bit Systems". // "Windows 10 Version 1703 for 32-bit Systems".
// `Kb` is expected to be the actual KB number, for example "5001028" // `Kb` is expected to be the actual KB number, for example "5001028"
type MicrosoftKbPatch struct { type MicrosoftKbPatch struct {
// ProductID is MSRC Product ID (e.g. "Windows 10 Version 1703 for 32-bit Systems")
ProductID string `toml:"product_id" json:"product_id"` ProductID string `toml:"product_id" json:"product_id"`
// Kb is Knowledge Base article number (e.g. "5001028")
Kb string `toml:"kb" json:"kb"` Kb string `toml:"kb" json:"kb"`
} }

View File

@ -6,43 +6,45 @@ import (
"github.com/scylladb/go-set/strset" "github.com/scylladb/go-set/strset"
) )
// NixStoreEntry represents a package in the Nix store (/nix/store) with its derivation information and metadata.
type NixStoreEntry struct { type NixStoreEntry struct {
// Path is the store path for this output // Path is full store path for this output (e.g. /nix/store/abc123...-package-1.0)
Path string `mapstructure:"path" json:"path,omitempty"` Path string `mapstructure:"path" json:"path,omitempty"`
// Output allows for optionally specifying the specific nix package output this package represents (for packages that support multiple outputs). // Output is the specific output name for multi-output packages (empty string for default "out" output, can be "bin", "dev", "doc", etc.)
// Note: the default output for a package is an empty string, so will not be present in the output.
Output string `mapstructure:"output" json:"output,omitempty"` Output string `mapstructure:"output" json:"output,omitempty"`
// OutputHash is the prefix of the nix store basename path // OutputHash is hash prefix of the store path basename (first part before the dash)
OutputHash string `mapstructure:"outputHash" json:"outputHash"` OutputHash string `mapstructure:"outputHash" json:"outputHash"`
// Derivation is any information about the derivation file that was used to build this package // Derivation is information about the .drv file that describes how this package was built
Derivation NixDerivation `mapstructure:"derivation" json:"derivation,omitempty"` Derivation NixDerivation `mapstructure:"derivation" json:"derivation,omitempty"`
// Files is a listing a files that are under the nix/store path for this package // Files are the list of files under the nix/store path for this package
Files []string `mapstructure:"files" json:"files,omitempty"` Files []string `mapstructure:"files" json:"files,omitempty"`
} }
// NixDerivation represents a Nix .drv file that describes how to build a package including inputs, outputs, and build instructions.
type NixDerivation struct { type NixDerivation struct {
// Path is the path to the derivation file // Path is path to the .drv file in Nix store
Path string `mapstructure:"path" json:"path,omitempty"` Path string `mapstructure:"path" json:"path,omitempty"`
// System is the nix system string that this derivation was built for // System is target system string indicating where derivation can be built (e.g. "x86_64-linux", "aarch64-darwin"). Must match current system for local builds.
System string `mapstructure:"system" json:"system,omitempty"` System string `mapstructure:"system" json:"system,omitempty"`
// InputDerivations is a list of derivation paths that were used to build this package // InputDerivations are the list of other derivations that were inputs to this build (dependencies)
InputDerivations []NixDerivationReference `mapstructure:"inputDerivations" json:"inputDerivations,omitempty"` InputDerivations []NixDerivationReference `mapstructure:"inputDerivations" json:"inputDerivations,omitempty"`
// InputSources is a list of source paths that were used to build this package // InputSources are the list of source file paths that were inputs to this build
InputSources []string `mapstructure:"inputSources" json:"inputSources,omitempty"` InputSources []string `mapstructure:"inputSources" json:"inputSources,omitempty"`
} }
// NixDerivationReference represents a reference to another derivation used as a build input or runtime dependency.
type NixDerivationReference struct { type NixDerivationReference struct {
// Path is the path to the derivation file // Path is path to the referenced .drv file
Path string `mapstructure:"path" json:"path,omitempty"` Path string `mapstructure:"path" json:"path,omitempty"`
// Outputs is a list of output names that were used to build this package // Outputs are which outputs of the referenced derivation were used (e.g. ["out"], ["bin", "dev"])
Outputs []string `mapstructure:"outputs" json:"outputs,omitempty"` Outputs []string `mapstructure:"outputs" json:"outputs,omitempty"`
} }

View File

@ -2,23 +2,42 @@ package pkg
// NpmPackage represents the contents of a javascript package.json file. // NpmPackage represents the contents of a javascript package.json file.
type NpmPackage struct { type NpmPackage struct {
// Name is the package name as found in package.json
Name string `mapstructure:"name" json:"name"` Name string `mapstructure:"name" json:"name"`
// Version is the package version as found in package.json
Version string `mapstructure:"version" json:"version"` Version string `mapstructure:"version" json:"version"`
// Author is package author name
Author string `mapstructure:"author" json:"author"` Author string `mapstructure:"author" json:"author"`
// Homepage is project homepage URL
Homepage string `mapstructure:"homepage" json:"homepage"` Homepage string `mapstructure:"homepage" json:"homepage"`
// Description is a human-readable package description
Description string `mapstructure:"description" json:"description"` Description string `mapstructure:"description" json:"description"`
// URL is repository or project URL
URL string `mapstructure:"url" json:"url"` URL string `mapstructure:"url" json:"url"`
// Private is whether this is a private package
Private bool `mapstructure:"private" json:"private"` Private bool `mapstructure:"private" json:"private"`
} }
// NpmPackageLockEntry represents a single entry within the "packages" section of a package-lock.json file. // NpmPackageLockEntry represents a single entry within the "packages" section of a package-lock.json file.
type NpmPackageLockEntry struct { type NpmPackageLockEntry struct {
// Resolved is URL where this package was downloaded from (registry source)
Resolved string `mapstructure:"resolved" json:"resolved"` Resolved string `mapstructure:"resolved" json:"resolved"`
// Integrity is Subresource Integrity hash for verification using standard SRI format (sha512-... or sha1-...). npm changed from SHA-1 to SHA-512 in newer versions. For registry sources this is the integrity from registry, for remote tarballs it's SHA-512 of the file. npm verifies tarball matches this hash before unpacking, throwing EINTEGRITY error if mismatch detected.
Integrity string `mapstructure:"integrity" json:"integrity"` Integrity string `mapstructure:"integrity" json:"integrity"`
} }
// YarnLockEntry represents a single entry section of a yarn.lock file. // YarnLockEntry represents a single entry section of a yarn.lock file.
type YarnLockEntry struct { type YarnLockEntry struct {
// Resolved is URL where this package was downloaded from
Resolved string `mapstructure:"resolved" json:"resolved"` Resolved string `mapstructure:"resolved" json:"resolved"`
// Integrity is Subresource Integrity hash for verification (SRI format)
Integrity string `mapstructure:"integrity" json:"integrity"` Integrity string `mapstructure:"integrity" json:"integrity"`
} }

View File

@ -1,11 +1,25 @@
package pkg package pkg
// OpamPackage represents an OCaml package managed by the OPAM package manager with metadata from .opam files.
type OpamPackage struct { type OpamPackage struct {
// Name is the package name as found in the .opam file
Name string `toml:"name" json:"name"` Name string `toml:"name" json:"name"`
// Version is the package version as found in the .opam file
Version string `toml:"version" json:"version"` Version string `toml:"version" json:"version"`
// Licenses are the list of applicable licenses
Licenses []string `mapstructure:"licenses" json:"licenses"` Licenses []string `mapstructure:"licenses" json:"licenses"`
// URL is download URL for the package source
URL string `mapstructure:"url" json:"url"` URL string `mapstructure:"url" json:"url"`
// Checksums are the list of checksums for verification
Checksums []string `mapstructure:"checksums" json:"checksum"` Checksums []string `mapstructure:"checksums" json:"checksum"`
// Homepage is project homepage URL
Homepage string `json:"homepage"` Homepage string `json:"homepage"`
// Dependencies are the list of required dependencies
Dependencies []string `toml:"dependencies" json:"dependencies"` Dependencies []string `toml:"dependencies" json:"dependencies"`
} }

View File

@ -17,17 +17,38 @@ import (
// Package represents an application or library that has been bundled into a distributable format. // Package represents an application or library that has been bundled into a distributable format.
// TODO: if we ignore FoundBy for ID generation should we merge the field to show it was found in two places? // TODO: if we ignore FoundBy for ID generation should we merge the field to show it was found in two places?
type Package struct { type Package struct {
// id is a content-addressable identifier for this package, computed from most attribute values (applied recursively)
id artifact.ID `hash:"ignore"` id artifact.ID `hash:"ignore"`
Name string // the package name
Version string // the version of the package // Name is the package name
FoundBy string `hash:"ignore" cyclonedx:"foundBy"` // the specific cataloger that discovered this package Name string
Locations file.LocationSet // the locations that lead to the discovery of this package (note: this is not necessarily the locations that make up this package)
Licenses LicenseSet // licenses discovered with the package metadata // Version is the package version
Language Language `hash:"ignore" cyclonedx:"language"` // the language ecosystem this package belongs to (e.g. JavaScript, Python, etc) Version string
Type Type `cyclonedx:"type"` // the package type (e.g. Npm, Yarn, Python, Rpm, Deb, etc)
CPEs []cpe.CPE `hash:"ignore"` // all possible Common Platform Enumerators (note: this is NOT included in the definition of the ID since all fields on a CPE are derived from other fields) // FoundBy is the specific cataloger that discovered this package
PURL string `hash:"ignore"` // the Package URL (see https://github.com/package-url/purl-spec) FoundBy string `hash:"ignore" cyclonedx:"foundBy"`
Metadata any // additional data found while parsing the package source
// Locations are the locations that lead to the discovery of this package (note: not necessarily the locations that make up the package)
Locations file.LocationSet
// Licenses are the licenses discovered from the package metadata
Licenses LicenseSet
// Language is the language this package was written in (e.g. JavaScript, Python, etc)
Language Language `hash:"ignore" cyclonedx:"language"`
// Type is the ecosystem the package belongs to (e.g. Npm, Yarn, Python, Rpm, Deb, etc)
Type Type `cyclonedx:"type"`
// CPEs are all possible Common Platform Enumerators (note: NOT included in ID since derived from other fields)
CPEs []cpe.CPE `hash:"ignore"`
// PURL is the Package URL (see https://github.com/package-url/purl-spec)
PURL string `hash:"ignore"`
// Metadata is additional data found while parsing the package source
Metadata any
} }
func (p *Package) OverrideID(id artifact.ID) { func (p *Package) OverrideID(id artifact.ID) {

View File

@ -5,35 +5,82 @@ type PhpComposerInstalledEntry PhpComposerLockEntry
// PhpComposerLockEntry represents a single package entry found from a composer.lock file. // PhpComposerLockEntry represents a single package entry found from a composer.lock file.
type PhpComposerLockEntry struct { type PhpComposerLockEntry struct {
// Name is package name in vendor/package format (e.g. symfony/console)
Name string `json:"name"` Name string `json:"name"`
// Version is the package version
Version string `json:"version"` Version string `json:"version"`
// Source is the source repository information for development (typically git repo, used when passing --prefer-source). Originates from source code repository.
Source PhpComposerExternalReference `json:"source"` Source PhpComposerExternalReference `json:"source"`
// Dist is distribution archive information for production (typically zip/tar, default install method). Packaged version of released code.
Dist PhpComposerExternalReference `json:"dist"` Dist PhpComposerExternalReference `json:"dist"`
// Require is runtime dependencies with version constraints (package will not install unless these requirements can be met)
Require map[string]string `json:"require,omitempty"` Require map[string]string `json:"require,omitempty"`
// Provide is virtual packages/functionality provided by this package (allows other packages to depend on capabilities)
Provide map[string]string `json:"provide,omitempty"` Provide map[string]string `json:"provide,omitempty"`
// RequireDev is development-only dependencies (not installed in production, only when developing this package or running tests)
RequireDev map[string]string `json:"require-dev,omitempty"` RequireDev map[string]string `json:"require-dev,omitempty"`
// Suggest is optional but recommended dependencies (suggestions for packages that would extend functionality)
Suggest map[string]string `json:"suggest,omitempty"` Suggest map[string]string `json:"suggest,omitempty"`
// License is the list of license identifiers (SPDX format)
License []string `json:"license,omitempty"` License []string `json:"license,omitempty"`
// Type is package type indicating purpose (library=reusable code, project=application, metapackage=aggregates dependencies, etc.)
Type string `json:"type,omitempty"` Type string `json:"type,omitempty"`
// NotificationURL is the URL to notify when package is installed (for tracking/statistics)
NotificationURL string `json:"notification-url,omitempty"` NotificationURL string `json:"notification-url,omitempty"`
// Bin is the list of binary/executable files that should be added to PATH
Bin []string `json:"bin,omitempty"` Bin []string `json:"bin,omitempty"`
// Authors are the list of package authors with name/email/homepage
Authors []PhpComposerAuthors `json:"authors,omitempty"` Authors []PhpComposerAuthors `json:"authors,omitempty"`
// Description is a human-readable package description
Description string `json:"description,omitempty"` Description string `json:"description,omitempty"`
// Homepage is project homepage URL
Homepage string `json:"homepage,omitempty"` Homepage string `json:"homepage,omitempty"`
// Keywords are the list of keywords for package discovery/search
Keywords []string `json:"keywords,omitempty"` Keywords []string `json:"keywords,omitempty"`
// Time is timestamp when this package version was released
Time string `json:"time,omitempty"` Time string `json:"time,omitempty"`
} }
// PhpComposerExternalReference represents source or distribution information for a PHP package, indicating where the package code is retrieved from.
type PhpComposerExternalReference struct { type PhpComposerExternalReference struct {
// Type is reference type (git for source VCS, zip/tar for dist archives)
Type string `json:"type"` Type string `json:"type"`
// URL is the URL to the resource (git repository URL or archive download URL)
URL string `json:"url"` URL string `json:"url"`
// Reference is git commit hash or version tag for source, or archive version for dist
Reference string `json:"reference"` Reference string `json:"reference"`
// Shasum is SHA hash of the archive file for integrity verification (dist only)
Shasum string `json:"shasum,omitempty"` Shasum string `json:"shasum,omitempty"`
} }
// PhpComposerAuthors represents author information for a PHP Composer package from the authors field in composer.json.
type PhpComposerAuthors struct { type PhpComposerAuthors struct {
// Name is author's full name
Name string `json:"name"` Name string `json:"name"`
// Email is author's email address
Email string `json:"email,omitempty"` Email string `json:"email,omitempty"`
// Homepage is author's personal or company website
Homepage string `json:"homepage,omitempty"` Homepage string `json:"homepage,omitempty"`
} }
@ -43,8 +90,15 @@ type PhpPeclEntry PhpPearEntry
// PhpPearEntry represents a single package entry found within php pear metadata files. // PhpPearEntry represents a single package entry found within php pear metadata files.
type PhpPearEntry struct { type PhpPearEntry struct {
// Name is the package name
Name string `json:"name"` Name string `json:"name"`
// Channel is PEAR channel this package is from
Channel string `json:"channel,omitempty"` Channel string `json:"channel,omitempty"`
// Version is the package version
Version string `json:"version"` Version string `json:"version"`
// License is the list of applicable licenses
License []string `json:"license,omitempty"` License []string `json:"license,omitempty"`
} }

View File

@ -12,14 +12,22 @@ var _ FileOwner = (*PortageEntry)(nil)
// PortageEntry represents a single package entry in the portage DB flat-file store. // PortageEntry represents a single package entry in the portage DB flat-file store.
type PortageEntry struct { type PortageEntry struct {
// InstalledSize is total size of installed files in bytes
InstalledSize int `json:"installedSize" cyclonedx:"installedSize"` InstalledSize int `json:"installedSize" cyclonedx:"installedSize"`
// Licenses is license string which may be an expression (e.g. "GPL-2 OR Apache-2.0")
Licenses string `json:"licenses,omitempty"` Licenses string `json:"licenses,omitempty"`
// Files are the files installed by this package (tracked in CONTENTS file)
Files []PortageFileRecord `json:"files"` Files []PortageFileRecord `json:"files"`
} }
// PortageFileRecord represents a single file attributed to a portage package. // PortageFileRecord represents a single file attributed to a portage package.
type PortageFileRecord struct { type PortageFileRecord struct {
// Path is the file path relative to the filesystem root
Path string `json:"path"` Path string `json:"path"`
// Digest is file content hash (MD5 for regular files in CONTENTS format: "obj filename md5hash mtime")
Digest *file.Digest `json:"digest,omitempty"` Digest *file.Digest `json:"digest,omitempty"`
} }

View File

@ -13,36 +13,57 @@ var _ FileOwner = (*PythonPackage)(nil)
// Historically these were defined in PEPs 345, 314, and 241, but have been superseded by PEP 566. This means that this // Historically these were defined in PEPs 345, 314, and 241, but have been superseded by PEP 566. This means that this
// struct can (partially) express at least versions 1.0, 1.1, 1.2, 2.1, 2.2, and 2.3 of the metadata format. // struct can (partially) express at least versions 1.0, 1.1, 1.2, 2.1, 2.2, and 2.3 of the metadata format.
type PythonPackage struct { type PythonPackage struct {
// Name is the package name from the Name field in PKG-INFO or METADATA.
Name string `json:"name" mapstructure:"Name"` Name string `json:"name" mapstructure:"Name"`
// Version is the package version from the Version field in PKG-INFO or METADATA.
Version string `json:"version" mapstructure:"Version"` Version string `json:"version" mapstructure:"Version"`
// Author is the package author name from the Author field.
Author string `json:"author" mapstructure:"Author"` Author string `json:"author" mapstructure:"Author"`
// AuthorEmail is the package author's email address from the Author-Email field.
AuthorEmail string `json:"authorEmail" mapstructure:"AuthorEmail"` AuthorEmail string `json:"authorEmail" mapstructure:"AuthorEmail"`
// Platform indicates the target platform for the package (e.g., "any", "linux", "win32").
Platform string `json:"platform" mapstructure:"Platform"` Platform string `json:"platform" mapstructure:"Platform"`
// Files are the installed files listed in the RECORD file for wheels or installed-files.txt for eggs.
Files []PythonFileRecord `json:"files,omitempty"` Files []PythonFileRecord `json:"files,omitempty"`
// SitePackagesRootPath is the root directory path containing the package (e.g., "/usr/lib/python3.9/site-packages").
SitePackagesRootPath string `json:"sitePackagesRootPath"` SitePackagesRootPath string `json:"sitePackagesRootPath"`
// TopLevelPackages are the top-level Python module names from top_level.txt file.
TopLevelPackages []string `json:"topLevelPackages,omitempty"` TopLevelPackages []string `json:"topLevelPackages,omitempty"`
// DirectURLOrigin contains VCS or direct URL installation information from direct_url.json.
DirectURLOrigin *PythonDirectURLOriginInfo `json:"directUrlOrigin,omitempty"` DirectURLOrigin *PythonDirectURLOriginInfo `json:"directUrlOrigin,omitempty"`
// RequiresPython specifies the Python version requirement (e.g., ">=3.6").
RequiresPython string `json:"requiresPython,omitempty" mapstructure:"RequiresPython"` RequiresPython string `json:"requiresPython,omitempty" mapstructure:"RequiresPython"`
// RequiresDist lists the package dependencies with version specifiers from Requires-Dist fields.
RequiresDist []string `json:"requiresDist,omitempty" mapstructure:"RequiresDist"` RequiresDist []string `json:"requiresDist,omitempty" mapstructure:"RequiresDist"`
// ProvidesExtra lists optional feature names that can be installed via extras (e.g., "dev", "test").
ProvidesExtra []string `json:"providesExtra,omitempty" mapstructure:"ProvidesExtra"` ProvidesExtra []string `json:"providesExtra,omitempty" mapstructure:"ProvidesExtra"`
} }
// PythonFileDigest represents the file metadata for a single file attributed to a python package. // PythonFileDigest represents the file metadata for a single file attributed to a python package.
type PythonFileDigest struct { type PythonFileDigest struct {
// Algorithm is the hash algorithm used (e.g., "sha256").
Algorithm string `json:"algorithm"` Algorithm string `json:"algorithm"`
// Value is the hex-encoded hash digest value.
Value string `json:"value"` Value string `json:"value"`
} }
// PythonFileRecord represents a single entry within a RECORD file for a python wheel or egg package // PythonFileRecord represents a single entry within a RECORD file for a python wheel or egg package
type PythonFileRecord struct { type PythonFileRecord struct {
// Path is the installed file path from the RECORD file.
Path string `json:"path"` Path string `json:"path"`
// Digest contains the hash algorithm and value for file integrity verification.
Digest *PythonFileDigest `json:"digest,omitempty"` Digest *PythonFileDigest `json:"digest,omitempty"`
// Size is the file size in bytes as a string.
Size string `json:"size,omitempty"` Size string `json:"size,omitempty"`
} }
// PythonDirectURLOriginInfo represents installation source metadata from direct_url.json for packages installed from VCS or direct URLs.
type PythonDirectURLOriginInfo struct { type PythonDirectURLOriginInfo struct {
// URL is the source URL from which the package was installed.
URL string `json:"url"` URL string `json:"url"`
// CommitID is the VCS commit hash if installed from version control.
CommitID string `json:"commitId,omitempty"` CommitID string `json:"commitId,omitempty"`
// VCS is the version control system type (e.g., "git", "hg").
VCS string `json:"vcs,omitempty"` VCS string `json:"vcs,omitempty"`
} }
@ -60,53 +81,84 @@ func (m PythonPackage) OwnedFiles() (result []string) {
// PythonPipfileLockEntry represents a single package entry within a Pipfile.lock file. // PythonPipfileLockEntry represents a single package entry within a Pipfile.lock file.
type PythonPipfileLockEntry struct { type PythonPipfileLockEntry struct {
// Hashes are the package file hash values in the format "algorithm:digest" for integrity verification.
Hashes []string `mapstructure:"hashes" json:"hashes"` Hashes []string `mapstructure:"hashes" json:"hashes"`
// Index is the PyPI index name where the package should be fetched from.
Index string `mapstructure:"index" json:"index"` Index string `mapstructure:"index" json:"index"`
} }
// PythonPoetryLockEntry represents a single package entry within a Pipfile.lock file. // PythonPoetryLockEntry represents a single package entry within a Pipfile.lock file.
type PythonPoetryLockEntry struct { type PythonPoetryLockEntry struct {
// Index is the package repository name where the package should be fetched from.
Index string `mapstructure:"index" json:"index"` Index string `mapstructure:"index" json:"index"`
// Dependencies are the package's runtime dependencies with version constraints.
Dependencies []PythonPoetryLockDependencyEntry `json:"dependencies"` Dependencies []PythonPoetryLockDependencyEntry `json:"dependencies"`
// Extras are optional feature groups that include additional dependencies.
Extras []PythonPoetryLockExtraEntry `json:"extras,omitempty"` Extras []PythonPoetryLockExtraEntry `json:"extras,omitempty"`
} }
// PythonPoetryLockDependencyEntry represents a single dependency entry within a Poetry lock file.
type PythonPoetryLockDependencyEntry struct { type PythonPoetryLockDependencyEntry struct {
// Name is the dependency package name.
Name string `json:"name"` Name string `json:"name"`
// Version is the locked version or version constraint for the dependency.
Version string `json:"version"` Version string `json:"version"`
// Optional indicates whether this dependency is optional (only needed for certain extras).
Optional bool `json:"optional"` Optional bool `json:"optional"`
// Markers are environment marker expressions that conditionally enable the dependency (e.g., "python_version >= '3.8'").
Markers string `json:"markers,omitempty"` Markers string `json:"markers,omitempty"`
// Extras are the optional feature names from the dependency that should be installed.
Extras []string `json:"extras,omitempty"` Extras []string `json:"extras,omitempty"`
} }
// PythonPoetryLockExtraEntry represents an optional feature group in a Poetry lock file.
type PythonPoetryLockExtraEntry struct { type PythonPoetryLockExtraEntry struct {
// Name is the optional feature name (e.g., "dev", "test").
Name string `json:"name"` Name string `json:"name"`
// Dependencies are the package names required when this extra is installed.
Dependencies []string `json:"dependencies"` Dependencies []string `json:"dependencies"`
} }
// PythonRequirementsEntry represents a single entry within a [*-]requirements.txt file. // PythonRequirementsEntry represents a single entry within a [*-]requirements.txt file.
type PythonRequirementsEntry struct { type PythonRequirementsEntry struct {
// Name is the package name from the requirements file.
Name string `json:"name" mapstructure:"Name"` Name string `json:"name" mapstructure:"Name"`
// Extras are the optional features to install from the package (e.g., package[dev,test]).
Extras []string `json:"extras,omitempty" mapstructure:"Extras"` Extras []string `json:"extras,omitempty" mapstructure:"Extras"`
// VersionConstraint specifies version requirements (e.g., ">=1.0,<2.0").
VersionConstraint string `json:"versionConstraint" mapstructure:"VersionConstraint"` VersionConstraint string `json:"versionConstraint" mapstructure:"VersionConstraint"`
// URL is the direct download URL or VCS URL if specified instead of a PyPI package.
URL string `json:"url,omitempty" mapstructure:"URL"` URL string `json:"url,omitempty" mapstructure:"URL"`
// Markers are environment marker expressions for conditional installation (e.g., "python_version >= '3.8'").
Markers string `json:"markers,omitempty" mapstructure:"Markers"` Markers string `json:"markers,omitempty" mapstructure:"Markers"`
} }
// PythonUvLockDependencyEntry represents a single dependency entry within a uv lock file.
type PythonUvLockDependencyEntry struct { type PythonUvLockDependencyEntry struct {
// Name is the dependency package name.
Name string `json:"name"` Name string `json:"name"`
// Optional indicates whether this dependency is optional (only needed for certain extras).
Optional bool `json:"optional"` Optional bool `json:"optional"`
// Markers are environment marker expressions that conditionally enable the dependency (e.g., "python_version >= '3.8'").
Markers string `json:"markers,omitempty"` Markers string `json:"markers,omitempty"`
// Extras are the optional feature names from the dependency that should be installed.
Extras []string `json:"extras,omitempty"` Extras []string `json:"extras,omitempty"`
} }
// PythonUvLockExtraEntry represents an optional feature group in a uv lock file.
type PythonUvLockExtraEntry struct { type PythonUvLockExtraEntry struct {
// Name is the optional feature name (e.g., "dev", "test").
Name string `json:"name"` Name string `json:"name"`
// Dependencies are the package names required when this extra is installed.
Dependencies []string `json:"dependencies"` Dependencies []string `json:"dependencies"`
} }
// PythonUvLockEntry represents a single package entry within a uv.lock file.
type PythonUvLockEntry struct { type PythonUvLockEntry struct {
// Index is the package repository name where the package should be fetched from.
Index string `mapstructure:"index" json:"index"` Index string `mapstructure:"index" json:"index"`
// Dependencies are the package's runtime dependencies with version constraints.
Dependencies []PythonUvLockDependencyEntry `json:"dependencies"` Dependencies []PythonUvLockDependencyEntry `json:"dependencies"`
// Extras are optional feature groups that include additional dependencies.
Extras []PythonUvLockExtraEntry `json:"extras,omitempty"` Extras []PythonUvLockExtraEntry `json:"extras,omitempty"`
} }

View File

@ -1,23 +1,44 @@
package pkg package pkg
type RDescription struct { // Fields chosen by:
/* // docker run --rm -it rocker/r-ver bash
Fields chosen by: // $ install2.r ggplot2 # has a lot of dependencies
docker run --rm -it rocker/r-ver bash // $ find /usr/local/lib/R -name DESCRIPTION | xargs cat | grep -v '^\s' | cut -d ':' -f 1 | sort | uniq -c | sort -nr
$ install2.r ggplot2 # has a lot of dependencies //
$ find /usr/local/lib/R -name DESCRIPTION | xargs cat | grep -v '^\s' | cut -d ':' -f 1 | sort | uniq -c | sort -nr // For more information on the DESCRIPTION file see https://r-pkgs.org/description.html
For more information on the DESCRIPTION file see https://r-pkgs.org/description.html // RDescription represents metadata from an R package DESCRIPTION file containing package information, dependencies, and author details.
*/ type RDescription struct {
// Title is short one-line package title
Title string `json:"title,omitempty"` Title string `json:"title,omitempty"`
// Description is detailed package description
Description string `json:"description,omitempty"` Description string `json:"description,omitempty"`
// Author is package author(s)
Author string `json:"author,omitempty"` Author string `json:"author,omitempty"`
// Maintainer is current package maintainer
Maintainer string `json:"maintainer,omitempty"` Maintainer string `json:"maintainer,omitempty"`
// URL is the list of related URLs
URL []string `json:"url,omitempty"` URL []string `json:"url,omitempty"`
// Repository is CRAN or other repository name
Repository string `json:"repository,omitempty"` Repository string `json:"repository,omitempty"`
// Built is R version and platform this was built with
Built string `json:"built,omitempty"` Built string `json:"built,omitempty"`
// NeedsCompilation is whether this package requires compilation
NeedsCompilation bool `json:"needsCompilation,omitempty"` NeedsCompilation bool `json:"needsCompilation,omitempty"`
// Imports are the packages imported in the NAMESPACE
Imports []string `json:"imports,omitempty"` Imports []string `json:"imports,omitempty"`
// Depends are the packages this package depends on
Depends []string `json:"depends,omitempty"` Depends []string `json:"depends,omitempty"`
// Suggests are the optional packages that extend functionality
Suggests []string `json:"suggests,omitempty"` Suggests []string `json:"suggests,omitempty"`
} }

View File

@ -1,11 +1,25 @@
package pkg package pkg
// LuaRocksPackage represents a Lua package managed by the LuaRocks package manager with metadata from .rockspec files.
type LuaRocksPackage struct { type LuaRocksPackage struct {
// Name is the package name as found in the .rockspec file
Name string `json:"name"` Name string `json:"name"`
// Version is the package version as found in the .rockspec file
Version string `json:"version"` Version string `json:"version"`
// License is license identifier
License string `json:"license"` License string `json:"license"`
// Homepage is project homepage URL
Homepage string `json:"homepage"` Homepage string `json:"homepage"`
// Description is a human-readable package description
Description string `json:"description"` Description string `json:"description"`
// URL is the source download URL
URL string `json:"url"` URL string `json:"url"`
// Dependencies are the map of dependency names to version constraints
Dependencies map[string]string `json:"dependencies"` Dependencies map[string]string `json:"dependencies"`
} }

View File

@ -22,30 +22,63 @@ const RpmManifestGlob = "**/var/lib/rpmmanifest/container-manifest-2"
var _ FileOwner = (*RpmDBEntry)(nil) var _ FileOwner = (*RpmDBEntry)(nil)
// RpmArchive represents all captured data from a RPM package archive. // RpmArchive represents package metadata extracted directly from a .rpm archive file, containing the same information as an RPM database entry.
type RpmArchive RpmDBEntry type RpmArchive RpmDBEntry
// RpmDBEntry represents all captured data from a RPM DB package entry. // RpmDBEntry represents all captured data from a RPM DB package entry.
type RpmDBEntry struct { type RpmDBEntry struct {
// Name is the RPM package name as found in the RPM database.
Name string `json:"name"` Name string `json:"name"`
// Version is the upstream version of the package.
Version string `json:"version"` Version string `json:"version"`
// Epoch is the version epoch used to force upgrade ordering (null if not set).
Epoch *int `json:"epoch" cyclonedx:"epoch" jsonschema:"nullable"` Epoch *int `json:"epoch" cyclonedx:"epoch" jsonschema:"nullable"`
// Arch is the target CPU architecture (e.g., "x86_64", "aarch64", "noarch").
Arch string `json:"architecture"` Arch string `json:"architecture"`
// Release is the package release number or distribution-specific version suffix.
Release string `json:"release" cyclonedx:"release"` Release string `json:"release" cyclonedx:"release"`
// SourceRpm is the source RPM filename that was used to build this package.
SourceRpm string `json:"sourceRpm" cyclonedx:"sourceRpm"` SourceRpm string `json:"sourceRpm" cyclonedx:"sourceRpm"`
// Signatures contains GPG signature metadata for package verification.
Signatures []RpmSignature `json:"signatures,omitempty" cyclonedx:"signatures"` Signatures []RpmSignature `json:"signatures,omitempty" cyclonedx:"signatures"`
// Size is the total installed size of the package in bytes.
Size int `json:"size" cyclonedx:"size"` Size int `json:"size" cyclonedx:"size"`
// Vendor is the organization that packaged the software.
Vendor string `json:"vendor"` Vendor string `json:"vendor"`
// ModularityLabel identifies the module stream for modular RPM packages (e.g., "nodejs:12:20200101").
ModularityLabel *string `json:"modularityLabel,omitempty" cyclonedx:"modularityLabel"` ModularityLabel *string `json:"modularityLabel,omitempty" cyclonedx:"modularityLabel"`
// Provides lists the virtual packages and capabilities this package provides.
Provides []string `json:"provides,omitempty"` Provides []string `json:"provides,omitempty"`
// Requires lists the dependencies required by this package.
Requires []string `json:"requires,omitempty"` Requires []string `json:"requires,omitempty"`
// Files are the file records for all files owned by this package.
Files []RpmFileRecord `json:"files"` Files []RpmFileRecord `json:"files"`
} }
// RpmSignature represents a GPG signature for an RPM package used for authenticity verification.
type RpmSignature struct { type RpmSignature struct {
// PublicKeyAlgorithm is the public key algorithm used for signing (e.g., "RSA").
PublicKeyAlgorithm string `json:"algo"` PublicKeyAlgorithm string `json:"algo"`
// HashAlgorithm is the hash algorithm used for the signature (e.g., "SHA256").
HashAlgorithm string `json:"hash"` HashAlgorithm string `json:"hash"`
// Created is the timestamp when the signature was created.
Created string `json:"created"` Created string `json:"created"`
// IssuerKeyID is the GPG key ID that created the signature.
IssuerKeyID string `json:"issuer"` IssuerKeyID string `json:"issuer"`
} }
@ -60,12 +93,25 @@ func (s RpmSignature) String() string {
// RpmFileRecord represents the file metadata for a single file attributed to a RPM package. // RpmFileRecord represents the file metadata for a single file attributed to a RPM package.
type RpmFileRecord struct { type RpmFileRecord struct {
// Path is the absolute file path where the file is installed.
Path string `json:"path"` Path string `json:"path"`
// Mode is the file permission mode bits following Unix stat.h conventions.
Mode RpmFileMode `json:"mode"` Mode RpmFileMode `json:"mode"`
// Size is the file size in bytes.
Size int `json:"size"` Size int `json:"size"`
// Digest contains the hash algorithm and value for file integrity verification.
Digest file.Digest `json:"digest"` Digest file.Digest `json:"digest"`
// UserName is the owner username for the file.
UserName string `json:"userName"` UserName string `json:"userName"`
// GroupName is the group name for the file.
GroupName string `json:"groupName"` GroupName string `json:"groupName"`
// Flags indicates the file type (e.g., "%config", "%doc", "%ghost").
Flags string `json:"flags"` Flags string `json:"flags"`
} }

View File

@ -2,24 +2,18 @@ package pkg
// RubyGemspec represents all metadata parsed from the *.gemspec file // RubyGemspec represents all metadata parsed from the *.gemspec file
type RubyGemspec struct { type RubyGemspec struct {
// Name is gem name as specified in the gemspec
Name string `mapstructure:"name" json:"name"` Name string `mapstructure:"name" json:"name"`
// Version is gem version as specified in the gemspec
Version string `mapstructure:"version" json:"version"` Version string `mapstructure:"version" json:"version"`
// note regarding if Files can contribute to GemMetadata being able to implement FileOwner: this list is a
// "logical" list of files, not a list of paths that can be used to find the files without additional processing. // Files is logical list of files in the gem (NOT directly usable as filesystem paths. Example: bundler gem lists "lib/bundler/vendor/uri/lib/uri/ldap.rb" but actual path is "/usr/local/lib/ruby/3.2.0/bundler/vendor/uri/lib/uri/ldap.rb". Would need gem installation path, ruby version, and env vars like GEM_HOME to resolve actual paths.)
//
// For example: The "bundler" gem has a file entry of:
// "lib/bundler/vendor/uri/lib/uri/ldap.rb"
// but the actual file is located at:
// "/usr/local/lib/ruby/3.2.0/bundler/vendor/uri/lib/uri/ldap.rb"
// which do not match (the "lib" prefix is missing even for relative processing).
//
// without additional information about:
// - the gem installation path
// - the ruby installation path
// - the ruby version
// - environment variables (e.g. GEM_HOME) that may affect the gem installation path
// ... we can't reliably determine the full path to the file on disk, thus cannot implement FileOwner (...yet...).
Files []string `mapstructure:"files" json:"files,omitempty"` Files []string `mapstructure:"files" json:"files,omitempty"`
// Authors are the list of gem authors (stored as array regardless of using `author` or `authors` method in gemspec)
Authors []string `mapstructure:"authors" json:"authors,omitempty"` Authors []string `mapstructure:"authors" json:"authors,omitempty"`
// Homepage is project homepage URL
Homepage string `mapstructure:"homepage" json:"homepage,omitempty"` Homepage string `mapstructure:"homepage" json:"homepage,omitempty"`
} }

View File

@ -1,15 +1,31 @@
package pkg package pkg
// RustCargoLockEntry represents a locked dependency from a Cargo.lock file with precise version and checksum information.
type RustCargoLockEntry struct { type RustCargoLockEntry struct {
// Name is crate name as specified in Cargo.toml
Name string `toml:"name" json:"name"` Name string `toml:"name" json:"name"`
// Version is crate version as specified in Cargo.toml
Version string `toml:"version" json:"version"` Version string `toml:"version" json:"version"`
// Source is the source registry or repository URL in format "registry+https://github.com/rust-lang/crates.io-index" for registry packages
Source string `toml:"source" json:"source"` Source string `toml:"source" json:"source"`
// Checksum is content checksum for registry packages only (hexadecimal string). Cargo doesn't require or include checksums for git dependencies. Used to detect MITM attacks by verifying downloaded crate matches lockfile checksum.
Checksum string `toml:"checksum" json:"checksum"` Checksum string `toml:"checksum" json:"checksum"`
// Dependencies are the list of dependencies with version constraints
Dependencies []string `toml:"dependencies" json:"dependencies"` Dependencies []string `toml:"dependencies" json:"dependencies"`
} }
// RustBinaryAuditEntry represents Rust crate metadata extracted from a compiled binary using cargo-auditable format.
type RustBinaryAuditEntry struct { type RustBinaryAuditEntry struct {
// Name is crate name as specified in audit section of the build binary
Name string `toml:"name" json:"name"` Name string `toml:"name" json:"name"`
// Version is crate version as specified in audit section of the build binary
Version string `toml:"version" json:"version"` Version string `toml:"version" json:"version"`
// Source is the source registry or repository where this crate came from
Source string `toml:"source" json:"source"` Source string `toml:"source" json:"source"`
} }

View File

@ -8,11 +8,21 @@ const (
SnapTypeSnapd = "snapd" SnapTypeSnapd = "snapd"
) )
// SnapEntry represents metadata for a Snap package extracted from snap.yaml or snapcraft.yaml files.
type SnapEntry struct { type SnapEntry struct {
// SnapType indicates the snap type (base, kernel, app, gadget, or snapd).
SnapType string `json:"snapType" yaml:"snapType"` // base, kernel, system, gadget, snapd SnapType string `json:"snapType" yaml:"snapType"` // base, kernel, system, gadget, snapd
// Base is the base snap name that this snap depends on (e.g., "core20", "core22").
Base string `json:"base" yaml:"base"` // base snap name (e.g., core20, core22) Base string `json:"base" yaml:"base"` // base snap name (e.g., core20, core22)
// SnapName is the snap package name.
SnapName string `json:"snapName" yaml:"snapName"` // name of the snap SnapName string `json:"snapName" yaml:"snapName"` // name of the snap
// SnapVersion is the snap package version.
SnapVersion string `json:"snapVersion" yaml:"snapVersion"` // version of the snap SnapVersion string `json:"snapVersion" yaml:"snapVersion"` // version of the snap
// Architecture is the target CPU architecture (e.g., "amd64", "arm64").
Architecture string `json:"architecture" yaml:"architecture"` // architecture (amd64, arm64, etc.) Architecture string `json:"architecture" yaml:"architecture"` // architecture (amd64, arm64, etc.)
} }

View File

@ -1,5 +1,7 @@
package pkg package pkg
// SwiftPackageManagerResolvedEntry represents a resolved dependency from a Package.resolved file with its locked version and source location.
type SwiftPackageManagerResolvedEntry struct { type SwiftPackageManagerResolvedEntry struct {
// Revision is git commit hash of the resolved package
Revision string `mapstructure:"revision" json:"revision"` Revision string `mapstructure:"revision" json:"revision"`
} }

View File

@ -1,12 +1,28 @@
package pkg package pkg
// SwiplPackEntry represents a SWI-Prolog package from the pack system with metadata about the package and its dependencies.
type SwiplPackEntry struct { type SwiplPackEntry struct {
// Name is the package name as found in the .toml file
Name string `toml:"name" json:"name"` Name string `toml:"name" json:"name"`
// Version is the package version as found in the .toml file
Version string `toml:"version" json:"version"` Version string `toml:"version" json:"version"`
// Author is author name
Author string `json:"author" mapstructure:"Author"` Author string `json:"author" mapstructure:"Author"`
// AuthorEmail is author email address
AuthorEmail string `json:"authorEmail" mapstructure:"AuthorEmail"` AuthorEmail string `json:"authorEmail" mapstructure:"AuthorEmail"`
// Packager is packager name (if different from author)
Packager string `json:"packager" mapstructure:"Packager"` Packager string `json:"packager" mapstructure:"Packager"`
// PackagerEmail is packager email address
PackagerEmail string `json:"packagerEmail" mapstructure:"PackagerEmail"` PackagerEmail string `json:"packagerEmail" mapstructure:"PackagerEmail"`
// Homepage is project homepage URL
Homepage string `json:"homepage"` Homepage string `json:"homepage"`
// Dependencies are the list of required dependencies
Dependencies []string `toml:"dependencies" json:"dependencies"` Dependencies []string `toml:"dependencies" json:"dependencies"`
} }

View File

@ -2,8 +2,12 @@ package pkg
// TerraformLockProviderEntry represents a single provider entry in a Terraform dependency lock file (.terraform.lock.hcl). // TerraformLockProviderEntry represents a single provider entry in a Terraform dependency lock file (.terraform.lock.hcl).
type TerraformLockProviderEntry struct { type TerraformLockProviderEntry struct {
// URL is the provider source address (e.g., "registry.terraform.io/hashicorp/aws").
URL string `hcl:",label" json:"url"` URL string `hcl:",label" json:"url"`
// Constraints specifies the version constraints for the provider (e.g., "~> 4.0").
Constraints string `hcl:"constraints,optional" json:"constraints"` Constraints string `hcl:"constraints,optional" json:"constraints"`
// Version is the locked provider version selected during terraform init.
Version string `hcl:"version" json:"version"` Version string `hcl:"version" json:"version"`
// Hashes are cryptographic checksums for the provider plugin archives across different platforms.
Hashes []string `hcl:"hashes" json:"hashes"` Hashes []string `hcl:"hashes" json:"hashes"`
} }

View File

@ -2,7 +2,12 @@ package pkg
// WordpressPluginEntry represents all metadata parsed from the wordpress plugin file // WordpressPluginEntry represents all metadata parsed from the wordpress plugin file
type WordpressPluginEntry struct { type WordpressPluginEntry struct {
// PluginInstallDirectory is directory name where the plugin is installed
PluginInstallDirectory string `mapstructure:"pluginInstallDirectory" json:"pluginInstallDirectory"` PluginInstallDirectory string `mapstructure:"pluginInstallDirectory" json:"pluginInstallDirectory"`
// Author is plugin author name
Author string `mapstructure:"author" json:"author,omitempty"` Author string `mapstructure:"author" json:"author,omitempty"`
// AuthorURI is author's website URL
AuthorURI string `mapstructure:"authorUri" json:"authorUri,omitempty"` AuthorURI string `mapstructure:"authorUri" json:"authorUri,omitempty"`
} }