summaryrefslogtreecommitdiff
path: root/libpod/image/utils.go
diff options
context:
space:
mode:
authorQi Wang <qiwan@redhat.com>2018-11-29 09:55:15 -0500
committerQi Wang <qiwan@redhat.com>2018-12-19 13:36:11 -0500
commit31edf47285ca9d56cd838aaaf5dae2f5403f7ea1 (patch)
tree75e00b199c7ef41f96a54cdbc8e6419f0bebc1f9 /libpod/image/utils.go
parent68414c5ee3066538903d04d55f135202ca4d333f (diff)
downloadpodman-31edf47285ca9d56cd838aaaf5dae2f5403f7ea1.tar.gz
podman-31edf47285ca9d56cd838aaaf5dae2f5403f7ea1.tar.bz2
podman-31edf47285ca9d56cd838aaaf5dae2f5403f7ea1.zip
Support podman image trust command
Display the trust policy of the host system. The trust policy is stored in the /etc/containers/policy.json file and defines a scope of registries or repositories. Signed-off-by: Qi Wang <qiwan@redhat.com>
Diffstat (limited to 'libpod/image/utils.go')
-rw-r--r--libpod/image/utils.go22
1 files changed, 22 insertions, 0 deletions
diff --git a/libpod/image/utils.go b/libpod/image/utils.go
index 9a75ca6dc..b944de1bb 100644
--- a/libpod/image/utils.go
+++ b/libpod/image/utils.go
@@ -2,6 +2,8 @@ package image
import (
"io"
+ "net/url"
+ "regexp"
"strings"
cp "github.com/containers/image/copy"
@@ -117,3 +119,23 @@ func GetAdditionalTags(images []string) ([]reference.NamedTagged, error) {
}
return allTags, nil
}
+
+// IsValidImageURI checks if image name has valid format
+func IsValidImageURI(imguri string) (bool, error) {
+ uri := "http://" + imguri
+ u, err := url.Parse(uri)
+ if err != nil {
+ return false, errors.Wrapf(err, "invalid image uri: %s", imguri)
+ }
+ reg := regexp.MustCompile(`^[a-zA-Z0-9-_\.]+\/?:?[0-9]*[a-z0-9-\/:]*$`)
+ ret := reg.FindAllString(u.Host, -1)
+ if len(ret) == 0 {
+ return false, errors.Wrapf(err, "invalid image uri: %s", imguri)
+ }
+ reg = regexp.MustCompile(`^[a-z0-9-:\./]*$`)
+ ret = reg.FindAllString(u.Fragment, -1)
+ if len(ret) == 0 {
+ return false, errors.Wrapf(err, "invalid image uri: %s", imguri)
+ }
+ return true, nil
+}