Merge pull request #2039 from vdemeester/add-match-support-to-reference
Add a new Match method to the reference package
This commit is contained in:
commit
26c9a77535
2 changed files with 89 additions and 0 deletions
|
@ -24,6 +24,7 @@ package reference
|
|||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"path"
|
||||
"strings"
|
||||
|
||||
"github.com/docker/distribution/digest"
|
||||
|
@ -250,6 +251,16 @@ func WithDigest(name Named, digest digest.Digest) (Canonical, error) {
|
|||
}, nil
|
||||
}
|
||||
|
||||
// Match reports whether ref matches the specified pattern.
|
||||
// See https://godoc.org/path#Match for supported patterns.
|
||||
func Match(pattern string, ref Reference) (bool, error) {
|
||||
matched, err := path.Match(pattern, ref.String())
|
||||
if namedRef, isNamed := ref.(Named); isNamed && !matched {
|
||||
matched, _ = path.Match(pattern, namedRef.Name())
|
||||
}
|
||||
return matched, err
|
||||
}
|
||||
|
||||
func getBestReferenceType(ref reference) Reference {
|
||||
if ref.name == "" {
|
||||
// Allow digest only references
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue