mirror of
https://github.com/distribution/distribution.git
synced 2025-09-24 12:37:00 +00:00
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:
@@ -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
|
||||
|
Reference in New Issue
Block a user