Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions pkg/image/reference/reference.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package reference

import (
"fmt"
"net"
"net/url"
"strings"
Expand Down Expand Up @@ -62,6 +63,19 @@ func Parse(spec string) (DockerImageReference, error) {
return ref, nil
}

// GetSpecDigest returns the image digest from a DockerImageReference string.
// example 'sha:22204fa2...' in an image 'registry/ocp/release@sha:22204fa2...'
func GetSpecDigest(spec string) (string, error) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this is needed when we can use Parse and then read resulting ref.ID?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

correct, closing this lol

namedRef, err := reference.ParseNamed(spec)
if err != nil {
return "", err
}
if named, ok := namedRef.(reference.Digested); ok {
return named.Digest().String(), nil
}
return "", fmt.Errorf("could not parse digest for spec: %v", spec)
}

// Equal returns true if the other DockerImageReference is equivalent to the
// reference r. The comparison applies defaults to the Docker image reference,
// so that e.g., "foobar" equals "docker.io/library/foobar:latest".
Expand Down