trim http https prefix when matching hostname
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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",
|
||||
|
||||
Reference in New Issue
Block a user