mirror of
https://github.com/anchore/syft.git
synced 2025-11-17 16:33:21 +01:00
chore: lint-fix
Signed-off-by: Christopher Phillips <32073428+spiffcs@users.noreply.github.com>
This commit is contained in:
parent
3f117a3eb5
commit
746f00ad68
@ -5,8 +5,9 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/anchore/syft/internal/packagemetadata"
|
|
||||||
"github.com/dave/jennifer/jen"
|
"github.com/dave/jennifer/jen"
|
||||||
|
|
||||||
|
"github.com/anchore/syft/internal/packagemetadata"
|
||||||
)
|
)
|
||||||
|
|
||||||
// This program is invoked from syft/internal and generates packagemetadata/generated.go
|
// This program is invoked from syft/internal and generates packagemetadata/generated.go
|
||||||
|
|||||||
@ -4,8 +4,9 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/anchore/syft/internal/sourcemetadata"
|
|
||||||
"github.com/dave/jennifer/jen"
|
"github.com/dave/jennifer/jen"
|
||||||
|
|
||||||
|
"github.com/anchore/syft/internal/sourcemetadata"
|
||||||
)
|
)
|
||||||
|
|
||||||
// This program is invoked from syft/internal and generates sourcemetadata/generated.go
|
// This program is invoked from syft/internal and generates sourcemetadata/generated.go
|
||||||
|
|||||||
@ -3,6 +3,7 @@ package task
|
|||||||
import (
|
import (
|
||||||
"github.com/anchore/syft/syft/cataloging/pkgcataloging"
|
"github.com/anchore/syft/syft/cataloging/pkgcataloging"
|
||||||
"github.com/anchore/syft/syft/pkg"
|
"github.com/anchore/syft/syft/pkg"
|
||||||
|
"github.com/anchore/syft/syft/pkg/cataloger/aiartifact"
|
||||||
"github.com/anchore/syft/syft/pkg/cataloger/alpine"
|
"github.com/anchore/syft/syft/pkg/cataloger/alpine"
|
||||||
"github.com/anchore/syft/syft/pkg/cataloger/arch"
|
"github.com/anchore/syft/syft/pkg/cataloger/arch"
|
||||||
"github.com/anchore/syft/syft/pkg/cataloger/binary"
|
"github.com/anchore/syft/syft/pkg/cataloger/binary"
|
||||||
@ -37,7 +38,6 @@ import (
|
|||||||
"github.com/anchore/syft/syft/pkg/cataloger/swipl"
|
"github.com/anchore/syft/syft/pkg/cataloger/swipl"
|
||||||
"github.com/anchore/syft/syft/pkg/cataloger/terraform"
|
"github.com/anchore/syft/syft/pkg/cataloger/terraform"
|
||||||
"github.com/anchore/syft/syft/pkg/cataloger/wordpress"
|
"github.com/anchore/syft/syft/pkg/cataloger/wordpress"
|
||||||
"github.com/anchore/syft/syft/pkg/cataloger/aiartifact"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|||||||
@ -7,7 +7,6 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/anchore/syft/internal/sourcemetadata"
|
|
||||||
"github.com/google/go-cmp/cmp"
|
"github.com/google/go-cmp/cmp"
|
||||||
"github.com/google/go-cmp/cmp/cmpopts"
|
"github.com/google/go-cmp/cmp/cmpopts"
|
||||||
"github.com/spdx/tools-golang/spdx"
|
"github.com/spdx/tools-golang/spdx"
|
||||||
@ -16,6 +15,7 @@ import (
|
|||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
"github.com/anchore/syft/internal/relationship"
|
"github.com/anchore/syft/internal/relationship"
|
||||||
|
"github.com/anchore/syft/internal/sourcemetadata"
|
||||||
"github.com/anchore/syft/syft/artifact"
|
"github.com/anchore/syft/syft/artifact"
|
||||||
"github.com/anchore/syft/syft/file"
|
"github.com/anchore/syft/syft/file"
|
||||||
"github.com/anchore/syft/syft/format/internal/spdxutil/helpers"
|
"github.com/anchore/syft/syft/format/internal/spdxutil/helpers"
|
||||||
|
|||||||
@ -3,12 +3,12 @@ package model
|
|||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/anchore/syft/internal/sourcemetadata"
|
|
||||||
"github.com/google/go-cmp/cmp"
|
"github.com/google/go-cmp/cmp"
|
||||||
"github.com/google/go-cmp/cmp/cmpopts"
|
"github.com/google/go-cmp/cmp/cmpopts"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
|
||||||
"github.com/anchore/packageurl-go"
|
"github.com/anchore/packageurl-go"
|
||||||
|
"github.com/anchore/syft/internal/sourcemetadata"
|
||||||
"github.com/anchore/syft/syft/file"
|
"github.com/anchore/syft/syft/file"
|
||||||
"github.com/anchore/syft/syft/linux"
|
"github.com/anchore/syft/syft/linux"
|
||||||
"github.com/anchore/syft/syft/pkg"
|
"github.com/anchore/syft/syft/pkg"
|
||||||
|
|||||||
@ -6,9 +6,9 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/CycloneDX/cyclonedx-go"
|
"github.com/CycloneDX/cyclonedx-go"
|
||||||
"github.com/anchore/syft/internal/packagemetadata"
|
|
||||||
|
|
||||||
"github.com/anchore/packageurl-go"
|
"github.com/anchore/packageurl-go"
|
||||||
|
"github.com/anchore/syft/internal/packagemetadata"
|
||||||
"github.com/anchore/syft/syft/file"
|
"github.com/anchore/syft/syft/file"
|
||||||
"github.com/anchore/syft/syft/format/internal"
|
"github.com/anchore/syft/syft/format/internal"
|
||||||
"github.com/anchore/syft/syft/pkg"
|
"github.com/anchore/syft/syft/pkg"
|
||||||
@ -40,9 +40,10 @@ func EncodeComponent(p pkg.Package, supplier string, locationSorter func(a, b fi
|
|||||||
}
|
}
|
||||||
|
|
||||||
componentType := cyclonedx.ComponentTypeLibrary
|
componentType := cyclonedx.ComponentTypeLibrary
|
||||||
if p.Type == pkg.BinaryPkg {
|
switch p.Type {
|
||||||
|
case pkg.BinaryPkg:
|
||||||
componentType = cyclonedx.ComponentTypeApplication
|
componentType = cyclonedx.ComponentTypeApplication
|
||||||
} else if p.Type == pkg.ModelPkg {
|
case pkg.ModelPkg:
|
||||||
componentType = cyclonedx.ComponentTypeMachineLearningModel
|
componentType = cyclonedx.ComponentTypeMachineLearningModel
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -5,9 +5,9 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/anchore/syft/internal/sourcemetadata"
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
|
||||||
|
"github.com/anchore/syft/internal/sourcemetadata"
|
||||||
"github.com/anchore/syft/syft/source"
|
"github.com/anchore/syft/syft/source"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@ -5,9 +5,9 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/anchore/syft/internal/sourcemetadata"
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
|
||||||
|
"github.com/anchore/syft/internal/sourcemetadata"
|
||||||
"github.com/anchore/syft/syft/sbom"
|
"github.com/anchore/syft/syft/sbom"
|
||||||
"github.com/anchore/syft/syft/source"
|
"github.com/anchore/syft/syft/source"
|
||||||
)
|
)
|
||||||
|
|||||||
@ -3,9 +3,9 @@ package helpers
|
|||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/anchore/syft/internal/packagemetadata"
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
|
||||||
|
"github.com/anchore/syft/internal/packagemetadata"
|
||||||
"github.com/anchore/syft/syft/pkg"
|
"github.com/anchore/syft/syft/pkg"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@ -4,11 +4,11 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/anchore/syft/internal/sourcemetadata"
|
|
||||||
"github.com/google/go-cmp/cmp"
|
"github.com/google/go-cmp/cmp"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
|
"github.com/anchore/syft/internal/sourcemetadata"
|
||||||
"github.com/anchore/syft/syft/file"
|
"github.com/anchore/syft/syft/file"
|
||||||
"github.com/anchore/syft/syft/source"
|
"github.com/anchore/syft/syft/source"
|
||||||
)
|
)
|
||||||
|
|||||||
@ -6,9 +6,10 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/anchore/syft/internal/packagemetadata"
|
|
||||||
"github.com/iancoleman/strcase"
|
"github.com/iancoleman/strcase"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
|
"github.com/anchore/syft/internal/packagemetadata"
|
||||||
)
|
)
|
||||||
|
|
||||||
type schema struct {
|
type schema struct {
|
||||||
|
|||||||
@ -4,13 +4,13 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/anchore/syft/internal/sourcemetadata"
|
|
||||||
"github.com/google/go-cmp/cmp"
|
"github.com/google/go-cmp/cmp"
|
||||||
"github.com/google/go-cmp/cmp/cmpopts"
|
"github.com/google/go-cmp/cmp/cmpopts"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
stereoscopeFile "github.com/anchore/stereoscope/pkg/file"
|
stereoscopeFile "github.com/anchore/stereoscope/pkg/file"
|
||||||
|
"github.com/anchore/syft/internal/sourcemetadata"
|
||||||
"github.com/anchore/syft/syft/file"
|
"github.com/anchore/syft/syft/file"
|
||||||
"github.com/anchore/syft/syft/format/syftjson/model"
|
"github.com/anchore/syft/syft/format/syftjson/model"
|
||||||
"github.com/anchore/syft/syft/pkg"
|
"github.com/anchore/syft/syft/pkg"
|
||||||
|
|||||||
@ -7,11 +7,11 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/anchore/syft/internal/sourcemetadata"
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
stereoFile "github.com/anchore/stereoscope/pkg/file"
|
stereoFile "github.com/anchore/stereoscope/pkg/file"
|
||||||
|
"github.com/anchore/syft/internal/sourcemetadata"
|
||||||
"github.com/anchore/syft/syft/artifact"
|
"github.com/anchore/syft/syft/artifact"
|
||||||
"github.com/anchore/syft/syft/file"
|
"github.com/anchore/syft/syft/file"
|
||||||
"github.com/anchore/syft/syft/format/syftjson/model"
|
"github.com/anchore/syft/syft/format/syftjson/model"
|
||||||
|
|||||||
@ -3,10 +3,10 @@ package syft
|
|||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/anchore/syft/internal/sourcemetadata"
|
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
"github.com/anchore/stereoscope/pkg/image"
|
"github.com/anchore/stereoscope/pkg/image"
|
||||||
|
"github.com/anchore/syft/internal/sourcemetadata"
|
||||||
"github.com/anchore/syft/syft/source"
|
"github.com/anchore/syft/syft/source"
|
||||||
"github.com/anchore/syft/syft/source/sourceproviders"
|
"github.com/anchore/syft/syft/source/sourceproviders"
|
||||||
)
|
)
|
||||||
|
|||||||
@ -41,7 +41,9 @@ const (
|
|||||||
ggufTypeArray = 12
|
ggufTypeArray = 12
|
||||||
)
|
)
|
||||||
|
|
||||||
// parseGGUFHeader parses the header of a GGUF file from raw bytes and extracts metadata
|
const unkownGGUFData = "unknown"
|
||||||
|
|
||||||
|
//nolint:funlen
|
||||||
func parseGGUFHeader(data []byte, location string) (*pkg.GGUFFileMetadata, error) {
|
func parseGGUFHeader(data []byte, location string) (*pkg.GGUFFileMetadata, error) {
|
||||||
reader := bytes.NewReader(data)
|
reader := bytes.NewReader(data)
|
||||||
// Read magic number
|
// Read magic number
|
||||||
@ -83,7 +85,7 @@ func parseGGUFHeader(data []byte, location string) (*pkg.GGUFFileMetadata, error
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Parse metadata key-value pairs
|
// Parse metadata key-value pairs
|
||||||
kvMap := make(map[string]interface{})
|
kvMap := make(map[string]any)
|
||||||
truncated := false
|
truncated := false
|
||||||
|
|
||||||
for i := uint64(0); i < kvCount; i++ {
|
for i := uint64(0); i < kvCount; i++ {
|
||||||
@ -133,7 +135,7 @@ func parseGGUFHeader(data []byte, location string) (*pkg.GGUFFileMetadata, error
|
|||||||
metadata.ModelVersion = version
|
metadata.ModelVersion = version
|
||||||
delete(kvMap, "general.version")
|
delete(kvMap, "general.version")
|
||||||
} else {
|
} else {
|
||||||
metadata.ModelVersion = "unknown"
|
metadata.ModelVersion = unkownGGUFData
|
||||||
}
|
}
|
||||||
|
|
||||||
// Extract parameters count if present
|
// Extract parameters count if present
|
||||||
@ -151,7 +153,7 @@ func parseGGUFHeader(data []byte, location string) (*pkg.GGUFFileMetadata, error
|
|||||||
metadata.Quantization = inferQuantizationFromFilename(location)
|
metadata.Quantization = inferQuantizationFromFilename(location)
|
||||||
// Note: we keep general.quantized_by in Header since it's not directly mapped to a field
|
// Note: we keep general.quantized_by in Header since it's not directly mapped to a field
|
||||||
} else {
|
} else {
|
||||||
metadata.Quantization = "unknown"
|
metadata.Quantization = unkownGGUFData
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compute hash of metadata for stable identifier
|
// Compute hash of metadata for stable identifier
|
||||||
@ -194,8 +196,8 @@ func readKVPair(reader io.Reader) (string, interface{}, error) {
|
|||||||
return key, value, nil
|
return key, value, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// readValue reads a value based on its type
|
//nolint:funlen
|
||||||
func readValue(reader io.Reader, valueType uint32) (interface{}, error) {
|
func readValue(reader io.Reader, valueType uint32) (any, error) {
|
||||||
switch valueType {
|
switch valueType {
|
||||||
case ggufTypeUint8:
|
case ggufTypeUint8:
|
||||||
var v uint8
|
var v uint8
|
||||||
@ -308,7 +310,7 @@ func inferQuantizationFromFilename(filename string) string {
|
|||||||
if match := quantPattern.FindString(filename); match != "" {
|
if match := quantPattern.FindString(filename); match != "" {
|
||||||
return match
|
return match
|
||||||
}
|
}
|
||||||
return "unknown"
|
return unkownGGUFData
|
||||||
}
|
}
|
||||||
|
|
||||||
// computeMetadataHash computes a stable hash of the metadata for use as a global identifier
|
// computeMetadataHash computes a stable hash of the metadata for use as a global identifier
|
||||||
@ -341,4 +343,3 @@ func computeMetadataHash(metadata *pkg.GGUFFileMetadata) string {
|
|||||||
hash := sha256.Sum256(jsonBytes)
|
hash := sha256.Sum256(jsonBytes)
|
||||||
return fmt.Sprintf("%x", hash[:8]) // Use first 8 bytes (16 hex chars)
|
return fmt.Sprintf("%x", hash[:8]) // Use first 8 bytes (16 hex chars)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -16,7 +16,7 @@ import (
|
|||||||
|
|
||||||
// parseGGUFModel parses a GGUF model file and returns the discovered package.
|
// parseGGUFModel parses a GGUF model file and returns the discovered package.
|
||||||
func parseGGUFModel(_ context.Context, _ file.Resolver, _ *generic.Environment, reader file.LocationReadCloser) ([]pkg.Package, []artifact.Relationship, error) {
|
func parseGGUFModel(_ context.Context, _ file.Resolver, _ *generic.Environment, reader file.LocationReadCloser) ([]pkg.Package, []artifact.Relationship, error) {
|
||||||
defer internal.CloseAndLogError(reader, reader.Location.Path())
|
defer internal.CloseAndLogError(reader, reader.Path())
|
||||||
|
|
||||||
// Read header (we'll read a reasonable amount to parse the header without reading entire file)
|
// Read header (we'll read a reasonable amount to parse the header without reading entire file)
|
||||||
// GGUF headers are typically < 1MB, but we'll use a 10MB limit to be safe
|
// GGUF headers are typically < 1MB, but we'll use a 10MB limit to be safe
|
||||||
@ -39,7 +39,7 @@ func parseGGUFModel(_ context.Context, _ file.Resolver, _ *generic.Environment,
|
|||||||
}
|
}
|
||||||
// Stop if we've read enough for a reasonable header
|
// Stop if we've read enough for a reasonable header
|
||||||
if len(headerData) > maxHeaderSize {
|
if len(headerData) > maxHeaderSize {
|
||||||
log.Warnf("GGUF header at %s exceeds max size, truncating", reader.Location.Path())
|
log.Warnf("GGUF header at %s exceeds max size, truncating", reader.Path())
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -50,7 +50,7 @@ func parseGGUFModel(_ context.Context, _ file.Resolver, _ *generic.Environment,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Parse the GGUF header
|
// Parse the GGUF header
|
||||||
metadata, err := parseGGUFHeader(headerData, reader.Location.Path())
|
metadata, err := parseGGUFHeader(headerData, reader.Path())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, fmt.Errorf("failed to parse GGUF file: %w", err)
|
return nil, nil, fmt.Errorf("failed to parse GGUF file: %w", err)
|
||||||
}
|
}
|
||||||
@ -58,7 +58,7 @@ func parseGGUFModel(_ context.Context, _ file.Resolver, _ *generic.Environment,
|
|||||||
// Create package from metadata
|
// Create package from metadata
|
||||||
p := newGGUFPackage(
|
p := newGGUFPackage(
|
||||||
metadata,
|
metadata,
|
||||||
reader.Location.WithAnnotation(pkg.EvidenceAnnotationKey, pkg.PrimaryEvidenceAnnotation),
|
reader.WithAnnotation(pkg.EvidenceAnnotationKey, pkg.PrimaryEvidenceAnnotation),
|
||||||
)
|
)
|
||||||
|
|
||||||
return []pkg.Package{p}, nil, unknown.IfEmptyf([]pkg.Package{p}, "unable to parse GGUF file")
|
return []pkg.Package{p}, nil, unknown.IfEmptyf([]pkg.Package{p}, "unable to parse GGUF file")
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user