Skip to content

Commit 60fa094

Browse files
Merge pull request shipwright-io#1628 from shipwright-io/add/legacy-endpoints
Add legacy endpoints to registry detection
2 parents 61ed927 + c9a1b55 commit 60fa094

File tree

1 file changed

+21
-5
lines changed

1 file changed

+21
-5
lines changed

pkg/image/delete.go

+21-5
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,9 @@ import (
4949
// Other registries:
5050
// Use standard spec delete API request to delete the provided tag.
5151
func Delete(ref name.Reference, options []remote.Option, auth authn.AuthConfig) error {
52+
var registry = ref.Context().RegistryStr()
5253
switch {
53-
case strings.Contains(ref.Context().RegistryStr(), "docker.io"):
54+
case isDockerHubEndpoint(registry):
5455
list, err := remote.List(ref.Context(), options...)
5556
if err != nil {
5657
return err
@@ -70,7 +71,7 @@ func Delete(ref name.Reference, options []remote.Option, auth authn.AuthConfig)
7071
return dockerHubRepoDelete(token, ref)
7172

7273
default:
73-
log.Printf("Removing a specific image tag is not supported on %q, the respective image tag will be overwritten with an empty image.\n", ref.Context().RegistryStr())
74+
log.Printf("Removing a specific image tag is not supported on %q, the respective image tag will be overwritten with an empty image.\n", registry)
7475

7576
// In case the input argument included a digest, the reference
7677
// needs to be updated to exclude the digest for the empty image
@@ -90,8 +91,8 @@ func Delete(ref name.Reference, options []remote.Option, auth authn.AuthConfig)
9091
)
9192
}
9293

93-
case strings.Contains(ref.Context().RegistryStr(), "icr.io"):
94-
token, accountID, err := icrLogin(ref.Context().RegistryStr(), auth.Username, auth.Password)
94+
case isIcrEndpoint(registry):
95+
token, accountID, err := icrLogin(registry, auth.Username, auth.Password)
9596
if err != nil {
9697
return err
9798
}
@@ -112,6 +113,21 @@ func httpClient() *http.Client {
112113
}
113114
}
114115

116+
func isDockerHubEndpoint(registry string) bool {
117+
return strings.Contains(registry, "docker.io") ||
118+
strings.Contains(registry, "registry.hub.docker.com")
119+
}
120+
121+
func isIcrEndpoint(registry string) bool {
122+
return strings.Contains(registry, "icr.io") ||
123+
strings.Contains(registry, "bluemix.net")
124+
}
125+
126+
func isIcrStageEndpoint(registry string) bool {
127+
return strings.Contains(registry, "stg.icr.io") ||
128+
strings.Contains(registry, "stage1.ng.bluemix.net")
129+
}
130+
115131
func dockerHubLogin(username string, password string) (string, error) {
116132
type LoginData struct {
117133
Username string `json:"username"`
@@ -201,7 +217,7 @@ func icrLogin(registry, username, apikey string) (string, string, error) {
201217
}
202218

203219
iamEndpoint := "https://iam.cloud.ibm.com/identity/token"
204-
if strings.Contains(registry, "stg.icr.io") {
220+
if isIcrStageEndpoint(registry) {
205221
iamEndpoint = "https://iam.test.cloud.ibm.com/identity/token"
206222
}
207223

0 commit comments

Comments
 (0)