feat: Add support for scanning GGUF models from OCI registries (#4335)

---------
Signed-off-by: Christopher Phillips <32073428+spiffcs@users.noreply.github.com>
Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>
Co-authored-by: Alex Goodman <wagoodman@users.noreply.github.com>
This commit is contained in:
Christopher Angelo Phillips
2026-02-09 16:05:52 -05:00
committed by GitHub
co-authored by Alex Goodman
parent 3a23cfff1d
commit 2c5e193f7a
51 changed files with 6127 additions and 238 deletions
+21 -13
View File
@@ -94,25 +94,33 @@ func findMetadataDefinitionNamesInFile(path string) ([]string, []string, error)
// loop over all types declared in the type declaration
for _, typ := range spec.Specs {
// check if the type is a struct type
spec, ok := typ.(*ast.TypeSpec)
if !ok || spec.Type == nil {
typeSpec, ok := typ.(*ast.TypeSpec)
if !ok || typeSpec.Type == nil {
continue
}
structType, ok := spec.Type.(*ast.StructType)
if !ok {
continue
}
// check if the struct type ends with "Metadata"
name := spec.Name.String()
name := typeSpec.Name.String()
// only look for exported types that end with "Metadata"
if isMetadataTypeCandidate(name) {
// print the full declaration of the struct type
metadataDefinitions = append(metadataDefinitions, name)
if !isMetadataTypeCandidate(name) {
continue
}
metadataDefinitions = append(metadataDefinitions, name)
// handle struct types (e.g., "type FooMetadata struct {...}")
if structType, ok := typeSpec.Type.(*ast.StructType); ok {
usedTypeNames = append(usedTypeNames, typeNamesUsedInStruct(structType)...)
continue
}
// handle type definitions from another type (e.g., "type FooMetadata BarMetadata")
// if the base type is NOT a metadata candidate, track it as used
// (e.g., we want both ImageMetadata and OCIModelMetadata which is an alias to it)
if ident, ok := typeSpec.Type.(*ast.Ident); ok {
if !isMetadataTypeCandidate(ident.Name) {
usedTypeNames = append(usedTypeNames, ident.Name)
}
}
}
}
+1 -1
View File
@@ -6,5 +6,5 @@ import "github.com/anchore/syft/syft/source"
// AllTypes returns a list of all source metadata types that syft supports (that are represented in the source.Description.Metadata field).
func AllTypes() []any {
return []any{source.DirectoryMetadata{}, source.FileMetadata{}, source.ImageMetadata{}, source.SnapMetadata{}}
return []any{source.DirectoryMetadata{}, source.FileMetadata{}, source.ImageMetadata{}, source.OCIModelMetadata{}, source.SnapMetadata{}}
}
+1
View File
@@ -12,6 +12,7 @@ var jsonNameFromType = map[reflect.Type][]string{
reflect.TypeOf(source.FileMetadata{}): {"file"},
reflect.TypeOf(source.ImageMetadata{}): {"image"},
reflect.TypeOf(source.SnapMetadata{}): {"snap"},
reflect.TypeOf(source.OCIModelMetadata{}): {"oci-model"},
}
func AllTypeNames() []string {