예제 #1
0
// NewReference returns a Docker reference for a named reference. The reference must satisfy !reference.IsNameOnly().
func NewReference(ref reference.Named) (types.ImageReference, error) {
	if reference.IsNameOnly(ref) {
		return nil, errors.Errorf("Docker reference %s has neither a tag nor a digest", ref.String())
	}
	// A github.com/distribution/reference value can have a tag and a digest at the same time!
	// docker/reference does not handle that, so fail.
	// (Even if it were supported, the semantics of policy namespaces are unclear - should we drop
	// the tag or the digest first?)
	_, isTagged := ref.(reference.NamedTagged)
	_, isDigested := ref.(reference.Canonical)
	if isTagged && isDigested {
		return nil, errors.Errorf("Docker references with both a tag and digest are currently not supported")
	}
	return dockerReference{
		ref: ref,
	}, nil
}
예제 #2
0
파일: naming.go 프로젝트: containers/image
// DockerReferenceIdentity returns a string representation of the reference, suitable for policy lookup,
// as a backend for ImageReference.PolicyConfigurationIdentity.
// The reference must satisfy !reference.IsNameOnly().
func DockerReferenceIdentity(ref reference.Named) (string, error) {
	res := ref.FullName()
	tagged, isTagged := ref.(reference.NamedTagged)
	digested, isDigested := ref.(reference.Canonical)
	switch {
	case isTagged && isDigested: // This should not happen, docker/reference.ParseNamed drops the tag.
		return "", errors.Errorf("Unexpected Docker reference %s with both a name and a digest", ref.String())
	case !isTagged && !isDigested: // This should not happen, the caller is expected to ensure !reference.IsNameOnly()
		return "", errors.Errorf("Internal inconsistency: Docker reference %s with neither a tag nor a digest", ref.String())
	case isTagged:
		res = res + ":" + tagged.Tag()
	case isDigested:
		res = res + "@" + digested.Digest().String()
	default: // Coverage: The above was supposed to be exhaustive.
		return "", errors.New("Internal inconsistency, unexpected default branch")
	}
	return res, nil
}