diff options
author | OpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com> | 2019-02-18 13:32:54 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-02-18 13:32:54 +0100 |
commit | e738ef16225395f5f5e4b93ba1a43ae9449ae11b (patch) | |
tree | 00c7d016a064a6efdf96d7fbcf5deb5e56ddf9ee | |
parent | f2139a651706b10824a1641a360020d932798827 (diff) | |
parent | b75dcd445848abad89e19f78193046a8de86c641 (diff) | |
download | podman-e738ef16225395f5f5e4b93ba1a43ae9449ae11b.tar.gz podman-e738ef16225395f5f5e4b93ba1a43ae9449ae11b.tar.bz2 podman-e738ef16225395f5f5e4b93ba1a43ae9449ae11b.zip |
Merge pull request #2354 from rhatdan/varlink
Add registry name to fields returned by varlink image search
-rwxr-xr-x | API.md | 9 | ||||
-rw-r--r-- | cmd/podman/search.go | 16 | ||||
-rw-r--r-- | cmd/podman/varlink/io.podman.varlink | 6 | ||||
-rw-r--r-- | pkg/registries/registries.go | 16 | ||||
-rw-r--r-- | pkg/varlinkapi/images.go | 17 |
5 files changed, 42 insertions, 22 deletions
@@ -107,7 +107,7 @@ in the [API.md](https://github.com/containers/libpod/blob/master/API.md) file in [func RestartPod(name: string) string](#RestartPod) -[func SearchImages(quety: string, limit: int, tlsVerify: ?bool) ImageSearchResult](#SearchImages) +[func SearchImages(query: string, limit: int, tlsVerify: ?bool) ImageSearchResult](#SearchImages) [func SendFile(type: string, length: int) string](#SendFile) @@ -780,8 +780,9 @@ ReceiveFile allows the host to send a remote client a file <div style="background-color: #E8E8E8; padding: 15px; margin: 10px; border-radius: 10px;"> method RemoveContainer(name: [string](https://godoc.org/builtin#string), force: [bool](https://godoc.org/builtin#bool), removeVolumes: [bool](https://godoc.org/builtin#bool)) [string](https://godoc.org/builtin#string)</div> -RemoveContainer takes requires the name or ID of container as well a boolean representing whether a running -container can be stopped and removed. It also takes a flag on whether or not to remove builtin volumes. Upon successful removal of the container, its ID is returned. If the +RemoveContainer requires the name or ID of container as well a boolean representing whether a running container can be stopped and removed, and a boolean +indicating whether to remove builtin volumes. Upon successful removal of the +container, its ID is returned. If the container cannot be found by name or ID, a [ContainerNotFound](#ContainerNotFound) error will be returned. #### Example ~~~ @@ -1423,6 +1424,8 @@ is_official [bool](https://godoc.org/builtin#bool) is_automated [bool](https://godoc.org/builtin#bool) +registry [string](https://godoc.org/builtin#string) + name [string](https://godoc.org/builtin#string) star_count [int](https://godoc.org/builtin#int) diff --git a/cmd/podman/search.go b/cmd/podman/search.go index 2febee689..858addff6 100644 --- a/cmd/podman/search.go +++ b/cmd/podman/search.go @@ -12,7 +12,6 @@ import ( "github.com/containers/libpod/cmd/podman/formats" "github.com/containers/libpod/libpod/common" sysreg "github.com/containers/libpod/pkg/registries" - "github.com/docker/distribution/reference" "github.com/pkg/errors" "github.com/sirupsen/logrus" "github.com/spf13/cobra" @@ -88,7 +87,7 @@ func searchCmd(c *cliconfig.SearchValues) error { term := args[0] // Check if search term has a registry in it - registry, err := getRegistry(term) + registry, err := sysreg.GetRegistry(term) if err != nil { return errors.Wrapf(err, "error getting registry from %q", term) } @@ -301,16 +300,3 @@ func matchesOfficialFilter(filter searchFilterParams, result docker.SearchResult } return true } - -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 -} diff --git a/cmd/podman/varlink/io.podman.varlink b/cmd/podman/varlink/io.podman.varlink index 697d9ed90..90cadf2b4 100644 --- a/cmd/podman/varlink/io.podman.varlink +++ b/cmd/podman/varlink/io.podman.varlink @@ -67,6 +67,7 @@ type ImageSearchResult ( description: string, is_official: bool, is_automated: bool, + registry: string, name: string, star_count: int ) @@ -600,8 +601,9 @@ method GetAttachSockets(name: string) -> (sockets: Sockets) # a [ContainerNotFound](#ContainerNotFound) error is returned. method WaitContainer(name: string) -> (exitcode: int) -# RemoveContainer takes requires the name or ID of container as well a boolean representing whether a running and a boolean indicating whether to remove builtin volumes -# container can be stopped and removed. Upon successful removal of the container, its ID is returned. If the +# RemoveContainer requires the name or ID of container as well a boolean representing whether a running container can be stopped and removed, and a boolean +# indicating whether to remove builtin volumes. Upon successful removal of the +# container, its ID is returned. If the # container cannot be found by name or ID, a [ContainerNotFound](#ContainerNotFound) error will be returned. # #### Example # ~~~ diff --git a/pkg/registries/registries.go b/pkg/registries/registries.go index cbb8b730c..9f4c94533 100644 --- a/pkg/registries/registries.go +++ b/pkg/registries/registries.go @@ -3,10 +3,12 @@ package registries import ( "os" "path/filepath" + "strings" "github.com/containers/image/pkg/sysregistries" "github.com/containers/image/types" "github.com/containers/libpod/pkg/rootless" + "github.com/docker/distribution/reference" "github.com/pkg/errors" ) @@ -49,3 +51,17 @@ func GetInsecureRegistries() ([]string, error) { } return registries, 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 +} diff --git a/pkg/varlinkapi/images.go b/pkg/varlinkapi/images.go index b3090d2dd..8deb4cbe2 100644 --- a/pkg/varlinkapi/images.go +++ b/pkg/varlinkapi/images.go @@ -446,9 +446,21 @@ func (i *LibpodAPI) SearchImages(call iopodman.VarlinkCall, query string, limit if tlsVerify != nil { sc.DockerInsecureSkipTLSVerify = types.NewOptionalBool(!*tlsVerify) } - registries, err := sysreg.GetRegistries() + var registries []string + + // Check if search query has a registry in it + registry, err := sysreg.GetRegistry(query) if err != nil { - return call.ReplyErrorOccurred(fmt.Sprintf("unable to get system registries: %q", err)) + return call.ReplyErrorOccurred(fmt.Sprintf("error getting registry from %q: %q", query, err)) + } + if registry != "" { + registries = append(registries, registry) + query = query[len(registry)+1:] + } else { + registries, err = sysreg.GetRegistries() + if err != nil { + return call.ReplyErrorOccurred(fmt.Sprintf("unable to get system registries: %q", err)) + } } var imageResults []iopodman.ImageSearchResult for _, reg := range registries { @@ -468,6 +480,7 @@ func (i *LibpodAPI) SearchImages(call iopodman.VarlinkCall, query string, limit } for _, result := range results { i := iopodman.ImageSearchResult{ + Registry: reg, Description: result.Description, Is_official: result.IsOfficial, Is_automated: result.IsAutomated, |