ExtractDigestFromImageRef extracts the digest from an image reference
(imageRef string)
| 938 | |
| 939 | // ExtractDigestFromImageRef extracts the digest from an image reference |
| 940 | func ExtractDigestFromImageRef(imageRef string) (string, error) { |
| 941 | // Parse the image reference |
| 942 | ref, err := name.ParseReference(imageRef) |
| 943 | if err != nil { |
| 944 | return "", fmt.Errorf("failed to parse image reference %s: %w", imageRef, err) |
| 945 | } |
| 946 | |
| 947 | // Check if it's already a digest reference |
| 948 | if digestRef, ok := ref.(name.Digest); ok { |
| 949 | return digestRef.DigestStr(), nil |
| 950 | } |
| 951 | |
| 952 | // For tag references, we need to resolve to digest |
| 953 | // For now, return the image reference as-is and let the retriever handle it |
| 954 | // In a full implementation, this would resolve the tag to a digest |
| 955 | return imageRef, nil |
| 956 | } |
| 957 | |
| 958 | // isFilePathLike checks if an identifier looks like a file path |
| 959 | // This handles the case where name.ParseReference incorrectly accepts file paths as valid image references |