Add a new Match method to the reference package
The Match method allows to see if a reference matches a specified patterns. Signed-off-by: Vincent Demeester <vincent@sbr.pm>
This commit is contained in:
parent
fbe6e8d212
commit
353e3a4c9d
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"
|
||||
|
@ -236,6 +237,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