mirror of
https://github.com/containers/podman.git
synced 2025-06-21 01:19:15 +08:00
Merge pull request #6621 from vrothberg/bz-1846629
search: allow wildcards
This commit is contained in:
@ -64,13 +64,16 @@ type SearchFilter struct {
|
|||||||
// SearchImages searches images based on term and the specified SearchOptions
|
// SearchImages searches images based on term and the specified SearchOptions
|
||||||
// in all registries.
|
// in all registries.
|
||||||
func SearchImages(term string, options SearchOptions) ([]SearchResult, error) {
|
func SearchImages(term string, options SearchOptions) ([]SearchResult, error) {
|
||||||
// Check if search term has a registry in it
|
registry := ""
|
||||||
registry, err := sysreg.GetRegistry(term)
|
|
||||||
if err != nil {
|
// Try to extract a registry from the specified search term. We
|
||||||
return nil, errors.Wrapf(err, "error getting registry from %q", term)
|
// consider everything before the first slash to be the registry. Note
|
||||||
}
|
// that we cannot use the reference parser from the containers/image
|
||||||
if registry != "" {
|
// library as the search term may container arbitrary input such as
|
||||||
term = term[len(registry)+1:]
|
// wildcards. See bugzilla.redhat.com/show_bug.cgi?id=1846629.
|
||||||
|
if spl := strings.SplitN(term, "/", 2); len(spl) > 1 {
|
||||||
|
registry = spl[0]
|
||||||
|
term = spl[1]
|
||||||
}
|
}
|
||||||
|
|
||||||
registries, err := getRegistries(registry)
|
registries, err := getRegistries(registry)
|
||||||
|
@ -3,12 +3,10 @@ package registries
|
|||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/containers/image/v5/pkg/sysregistriesv2"
|
"github.com/containers/image/v5/pkg/sysregistriesv2"
|
||||||
"github.com/containers/image/v5/types"
|
"github.com/containers/image/v5/types"
|
||||||
"github.com/containers/libpod/pkg/rootless"
|
"github.com/containers/libpod/pkg/rootless"
|
||||||
"github.com/docker/distribution/reference"
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -77,17 +75,3 @@ func GetInsecureRegistries() ([]string, error) {
|
|||||||
}
|
}
|
||||||
return insecureRegistries, nil
|
return insecureRegistries, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetRegistry returns the registry name from a string if specified
|
|
||||||
func GetRegistry(image string) (string, error) {
|
|
||||||
// It is possible to only have the registry name in the format "myregistry/"
|
|
||||||
// if so, just trim the "/" from the end and return the registry name
|
|
||||||
if strings.HasSuffix(image, "/") {
|
|
||||||
return strings.TrimSuffix(image, "/"), nil
|
|
||||||
}
|
|
||||||
imgRef, err := reference.Parse(image)
|
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
return reference.Domain(imgRef.(reference.Named)), nil
|
|
||||||
}
|
|
||||||
|
@ -400,4 +400,16 @@ registries = ['{{.Host}}:{{.Port}}']`
|
|||||||
search.WaitWithDefaultTimeout()
|
search.WaitWithDefaultTimeout()
|
||||||
Expect(search.ExitCode()).To(Not(Equal(0)))
|
Expect(search.ExitCode()).To(Not(Equal(0)))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
It("podman search with wildcards", func() {
|
||||||
|
search := podmanTest.Podman([]string{"search", "--limit", "30", "registry.redhat.io/*"})
|
||||||
|
search.WaitWithDefaultTimeout()
|
||||||
|
Expect(search.ExitCode()).To(Equal(0))
|
||||||
|
Expect(len(search.OutputToStringArray())).To(Equal(31))
|
||||||
|
|
||||||
|
search = podmanTest.Podman([]string{"search", "registry.redhat.io/*openshift*"})
|
||||||
|
search.WaitWithDefaultTimeout()
|
||||||
|
Expect(search.ExitCode()).To(Equal(0))
|
||||||
|
Expect(len(search.OutputToStringArray()) > 1).To(BeTrue())
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
Reference in New Issue
Block a user