trim http https prefix when matching hostname
This commit is contained in:
@@ -5,6 +5,7 @@
|
|||||||
package image
|
package image
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"net/url"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/docker/distribution/reference"
|
"github.com/docker/distribution/reference"
|
||||||
@@ -71,6 +72,16 @@ func MatchHostname(image, hostname string) bool {
|
|||||||
if hostname == "index.docker.io" {
|
if hostname == "index.docker.io" {
|
||||||
hostname = "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
|
return reference.Domain(named) == hostname
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -250,6 +250,11 @@ func Test_matchHostname(t *testing.T) {
|
|||||||
hostname: "012345678910.dkr.ecr.us-east-1.amazonaws.com",
|
hostname: "012345678910.dkr.ecr.us-east-1.amazonaws.com",
|
||||||
want: true,
|
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: "*&^%",
|
image: "*&^%",
|
||||||
hostname: "1.2.3.4:8000",
|
hostname: "1.2.3.4:8000",
|
||||||
|
|||||||
Reference in New Issue
Block a user