1
0
Fork 0
mirror of https://github.com/portainer/portainer.git synced 2025-07-25 00:09:40 +02:00

fix(registry): sync config on change [EE-5460] (#8955)

This commit is contained in:
Chaim Lev-Ari 2023-05-30 10:47:44 +07:00 committed by GitHub
parent d803d5f821
commit 61b568a738
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 36 additions and 16 deletions

View file

@ -125,26 +125,23 @@ func (handler *Handler) registryConfigure(w http.ResponseWriter, r *http.Request
return httperror.InternalServerError("Unable to find a registry with the specified identifier inside the database", err)
}
registry.ManagementConfiguration = &portainer.RegistryManagementConfiguration{
Type: registry.Type,
}
if payload.Authentication {
registry.ManagementConfiguration.Authentication = true
registry.ManagementConfiguration.Username = payload.Username
if payload.Username == registry.Username && payload.Password == "" {
registry.ManagementConfiguration.Password = registry.Password
} else {
registry.ManagementConfiguration.Password = payload.Password
registry.Authentication = true
registry.Username = payload.Username
if payload.Password != "" {
registry.Password = payload.Password
}
if payload.Region != "" {
registry.ManagementConfiguration.Ecr.Region = payload.Region
registry.Ecr.Region = payload.Region
}
}
var tlsConfig portainer.TLSConfiguration
if payload.TLS {
registry.ManagementConfiguration.TLSConfig = portainer.TLSConfiguration{
tlsConfig = portainer.TLSConfiguration{
TLS: true,
TLSSkipVerify: payload.TLSSkipVerify,
}
@ -156,22 +153,25 @@ func (handler *Handler) registryConfigure(w http.ResponseWriter, r *http.Request
if err != nil {
return httperror.InternalServerError("Unable to persist TLS certificate file on disk", err)
}
registry.ManagementConfiguration.TLSConfig.TLSCertPath = certPath
tlsConfig.TLSCertPath = certPath
keyPath, err := handler.FileService.StoreRegistryManagementFileFromBytes(folder, "key.pem", payload.TLSKeyFile)
if err != nil {
return httperror.InternalServerError("Unable to persist TLS key file on disk", err)
}
registry.ManagementConfiguration.TLSConfig.TLSKeyPath = keyPath
tlsConfig.TLSKeyPath = keyPath
cacertPath, err := handler.FileService.StoreRegistryManagementFileFromBytes(folder, "ca.pem", payload.TLSCACertFile)
if err != nil {
return httperror.InternalServerError("Unable to persist TLS CA certificate file on disk", err)
}
registry.ManagementConfiguration.TLSConfig.TLSCACertPath = cacertPath
tlsConfig.TLSCACertPath = cacertPath
}
}
registry.ManagementConfiguration = syncConfig(registry)
registry.ManagementConfiguration.TLSConfig = tlsConfig
err = handler.DataStore.Registry().UpdateRegistry(registry.ID, registry)
if err != nil {
return httperror.InternalServerError("Unable to persist registry changes inside the database", err)