From a0ba531fedfd2abd2c6c1587dd47bcbf5803832e Mon Sep 17 00:00:00 2001 From: Chaim Lev-Ari Date: Thu, 4 Jun 2020 09:50:02 +0300 Subject: [PATCH] fix(registries): check same url for gitlab (#3870) --- api/http/handler/registries/registry_update.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/api/http/handler/registries/registry_update.go b/api/http/handler/registries/registry_update.go index cd4255140..1ba467199 100644 --- a/api/http/handler/registries/registry_update.go +++ b/api/http/handler/registries/registry_update.go @@ -53,7 +53,7 @@ func (handler *Handler) registryUpdate(w http.ResponseWriter, r *http.Request) * return &httperror.HandlerError{http.StatusInternalServerError, "Unable to retrieve registries from the database", err} } for _, r := range registries { - if r.URL == *payload.URL && r.ID != registry.ID { + if r.ID != registry.ID && hasSameURL(&r, registry) { return &httperror.HandlerError{http.StatusConflict, "Another registry with the same URL already exists", portainer.ErrRegistryAlreadyExists} } } @@ -95,3 +95,11 @@ func (handler *Handler) registryUpdate(w http.ResponseWriter, r *http.Request) * return response.JSON(w, registry) } + +func hasSameURL(r1, r2 *portainer.Registry) bool { + if r1.Type != portainer.GitlabRegistry || r2.Type != portainer.GitlabRegistry { + return r1.URL == r2.URL + } + + return r1.URL == r2.URL && r1.Gitlab.ProjectPath == r2.Gitlab.ProjectPath +}