summaryrefslogtreecommitdiff
path: root/pkg/registries
diff options
context:
space:
mode:
authorDaniel J Walsh <dwalsh@redhat.com>2019-02-15 14:49:12 -0500
committerDaniel J Walsh <dwalsh@redhat.com>2019-02-15 15:30:09 -0500
commitb75dcd445848abad89e19f78193046a8de86c641 (patch)
treed9eec5056be5e240d49286f1d4894aedb252e407 /pkg/registries
parent9c1b08fd79012c12d478edb13f6057a0414762db (diff)
downloadpodman-b75dcd445848abad89e19f78193046a8de86c641.tar.gz
podman-b75dcd445848abad89e19f78193046a8de86c641.tar.bz2
podman-b75dcd445848abad89e19f78193046a8de86c641.zip
Add registry name to fields returned by varlink image search
Cockpit team wants to list the registry name where the image was found. Also fix up SearchImages code to check if the user specified a registry in his call to use that rather then all the registries, This matches podman search command. Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
Diffstat (limited to 'pkg/registries')
-rw-r--r--pkg/registries/registries.go16
1 files changed, 16 insertions, 0 deletions
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
+}