trim http https prefix when matching hostname

This commit is contained in:
Brad Rydzewski
2020-01-31 08:53:41 -08:00
parent 8ad796ad1e
commit b4bb1f4a4d
2 changed files with 16 additions and 0 deletions

View File

@@ -5,6 +5,7 @@
package image
import (
"net/url"
"strings"
"github.com/docker/distribution/reference"
@@ -71,6 +72,16 @@ func MatchHostname(image, hostname string) bool {
if hostname == "index.docker.io" {
hostname = "docker.io"
}
// the auth address could be a fully qualified
// url in which case, we should parse so we can
// extract the domain name.
if strings.HasPrefix(hostname, "http://") ||
strings.HasPrefix(hostname, "https://") {
parsed, err := url.Parse(hostname)
if err != nil {
hostname = parsed.Host
}
}
return reference.Domain(named) == hostname
}

View File

@@ -250,6 +250,11 @@ func Test_matchHostname(t *testing.T) {
hostname: "012345678910.dkr.ecr.us-east-1.amazonaws.com",
want: true,
},
{
image: "012345678910.dkr.ecr.us-east-1.amazonaws.com/foo:latest",
hostname: "https://012345678910.dkr.ecr.us-east-1.amazonaws.com",
want: true,
},
{
image: "*&^%",
hostname: "1.2.3.4:8000",