MCPcopy Create free account
hub / github.com/conforma/cli / IsImageReference

Function IsImageReference

internal/validate/vsa/vsa.go:793–847  ·  view source on GitHub ↗

IsImageReference checks if the identifier is an image reference

(identifier string)

Source from the content-addressed store, hash-verified

791
792// IsImageReference checks if the identifier is an image reference
793func IsImageReference(identifier string) bool {
794 // First check if it's an image digest (more specific)
795 if DetectIdentifierType(identifier) == IdentifierImageDigest {
796 return false
797 }
798
799 // First check if it's clearly not an image reference
800 if filepath.IsAbs(identifier) || strings.HasPrefix(identifier, "./") || strings.HasPrefix(identifier, "../") {
801 return false
802 }
803
804 // Check if it has a file extension (likely a file, not an image)
805 if filepath.Ext(identifier) != "" {
806 return false
807 }
808
809 // Check if it looks like a digest (starts with sha)
810 if strings.HasPrefix(identifier, "sha") {
811 return false
812 }
813
814 // Try to parse as a container registry reference
815 _, err := name.ParseReference(identifier)
816 if err != nil {
817 return false
818 }
819
820 // Additional validation: make sure it's not just a single word with a colon
821 // (like "invalid:" or "sha128:abc123") but allow Docker Hub references
822 if !strings.Contains(identifier, "/") && strings.Contains(identifier, ":") {
823 // Check if it starts with "sha" (invalid digest format)
824 if strings.HasPrefix(identifier, "sha") {
825 return false
826 }
827 // Check if it's just a single word with colon (like "invalid:")
828 parts := strings.Split(identifier, ":")
829 if len(parts) == 2 && len(parts[0]) > 0 && len(parts[1]) > 0 {
830 // This could be a valid Docker Hub reference like "nginx:latest"
831 return true
832 }
833 // Single word with colon but no value after colon is invalid
834 return false
835 }
836
837 // Additional validation: reject identifiers that look like digests but aren't valid
838 // This catches cases like "sha128:abc123" that pass ParseReference but aren't valid
839 if strings.HasPrefix(identifier, "sha") && strings.Contains(identifier, ":") {
840 // Check if it's a valid digest format
841 if DetectIdentifierType(identifier) != IdentifierImageDigest {
842 return false
843 }
844 }
845
846 return true
847}
848
849// IsValidVSAIdentifier validates VSA identifier format
850func IsValidVSAIdentifier(identifier string) bool {

Callers 2

TestIsImageReferenceFunction · 0.92
TestIsImageReferenceFunction · 0.85

Calls 1

DetectIdentifierTypeFunction · 0.85

Tested by 2

TestIsImageReferenceFunction · 0.74
TestIsImageReferenceFunction · 0.68