mirror of
https://github.com/portainer/portainer.git
synced 2025-07-24 15:59:41 +02:00
feat(registry): enforce name uniqueness for registries (#6709)
* feat(app/registries): add name uniqueness validation on registry creation * feat(api/registry): enforce name uniqueness on registry creation * feat(api/registry): enforce name uniqueness on registry update * feat(app/registry): enforce name uniqueness on registry update
This commit is contained in:
parent
9ffaf47741
commit
298e3d263e
18 changed files with 265 additions and 143 deletions
|
@ -77,6 +77,11 @@ func (handler *Handler) registryUpdate(w http.ResponseWriter, r *http.Request) *
|
|||
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to find a registry with the specified identifier inside the database", err}
|
||||
}
|
||||
|
||||
registries, err := handler.DataStore.Registry().Registries()
|
||||
if err != nil {
|
||||
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to retrieve registries from the database", err}
|
||||
}
|
||||
|
||||
var payload registryUpdatePayload
|
||||
err = request.DecodeAndValidateJSONPayload(r, &payload)
|
||||
if err != nil {
|
||||
|
@ -86,6 +91,15 @@ func (handler *Handler) registryUpdate(w http.ResponseWriter, r *http.Request) *
|
|||
if payload.Name != nil {
|
||||
registry.Name = *payload.Name
|
||||
}
|
||||
// enforce name uniqueness across registries
|
||||
// check is performed even if Name didn't change (Name not in payload) as we need
|
||||
// to enforce this rule on updates not performed with frontend (e.g. on direct API requests)
|
||||
// see https://portainer.atlassian.net/browse/EE-2706 for more details
|
||||
for _, r := range registries {
|
||||
if r.ID != registry.ID && r.Name == registry.Name {
|
||||
return &httperror.HandlerError{http.StatusConflict, "Another registry with the same name already exists", errors.New("A registry is already defined with this name")}
|
||||
}
|
||||
}
|
||||
|
||||
if registry.Type == portainer.ProGetRegistry && payload.BaseURL != nil {
|
||||
registry.BaseURL = *payload.BaseURL
|
||||
|
@ -129,10 +143,6 @@ func (handler *Handler) registryUpdate(w http.ResponseWriter, r *http.Request) *
|
|||
shouldUpdateSecrets = shouldUpdateSecrets || (*payload.URL != registry.URL)
|
||||
|
||||
registry.URL = *payload.URL
|
||||
registries, err := handler.DataStore.Registry().Registries()
|
||||
if err != nil {
|
||||
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to retrieve registries from the database", err}
|
||||
}
|
||||
|
||||
for _, r := range registries {
|
||||
if r.ID != registry.ID && handler.registriesHaveSameURLAndCredentials(&r, registry) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue