deb-bootc-image-builder/bib/internal/debian-patch/images_wrapper.go
2025-08-11 08:59:41 -07:00

85 lines
2.7 KiB
Go

package debianpatch
import (
"strings"
)
// BootcImageInfo contains the validation logic for bootc images
type BootcImageInfo struct {
Labels map[string]string `json:"Labels"`
}
// ContainerImage represents a container image with labels
type ContainerImage struct {
Labels map[string]string
Ref string
}
// ValidateImage checks if an image is a valid bootc image using our Debian-aware validation
func ValidateImage(imageRef string) error {
// This function will be called before the upstream images library validation
// In practice, you'd need to:
// 1. Inspect the container image to get labels
// 2. Call ValidateBootcImage(labels, imageRef)
// For now, this is a placeholder that demonstrates the integration point
// The actual implementation would need to integrate with the container inspection logic
return nil
}
// PreValidateImage performs validation before the upstream images library processes the image
func PreValidateImage(imageRef string) error {
// This is called before the upstream validation
// We can add Debian-specific pre-validation here
// Check if the image reference looks like a Debian image
if strings.Contains(imageRef, "debian") || strings.Contains(imageRef, "particle-os") {
// This is a hint that we might be dealing with a Debian image
// We could add additional validation here
}
return nil
}
// PostValidateImage performs validation after the upstream images library processes the image
func PostValidateImage(imageRef string, labels map[string]string) error {
// This is called after the upstream validation
// We can add Debian-specific post-validation here
// Check if this is a Debian bootc image
if GetBootcType(labels) == "debian" {
// Perform Debian-specific validations
return ValidateDebianBootcImage(labels, imageRef)
}
return nil
}
// GetImageLabels extracts labels from a container image
// This is a placeholder - in practice, you'd integrate with the actual container inspection
func GetImageLabels(imageRef string) (map[string]string, error) {
// This would integrate with the actual container inspection logic
// For now, return an empty map as a placeholder
return make(map[string]string), nil
}
// IsDebianImage checks if an image is specifically a Debian image
func IsDebianImage(labels map[string]string) bool {
return GetBootcType(labels) == "debian"
}
// GetDebianVersion extracts Debian version information from labels
func GetDebianVersion(labels map[string]string) string {
// Check for Debian-specific version labels
if version, exists := labels["org.debian.version"]; exists {
return version
}
// Check for general version labels
if version, exists := labels["version"]; exists {
return version
}
return "unknown"
}