mirror of https://github.com/portainer/portainer
fix(registry): sync config on change [EE-5460] (#8955)
parent
d803d5f821
commit
61b568a738
|
@ -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)
|
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 {
|
if payload.Authentication {
|
||||||
registry.ManagementConfiguration.Authentication = true
|
registry.Authentication = true
|
||||||
registry.ManagementConfiguration.Username = payload.Username
|
|
||||||
if payload.Username == registry.Username && payload.Password == "" {
|
registry.Username = payload.Username
|
||||||
registry.ManagementConfiguration.Password = registry.Password
|
|
||||||
} else {
|
if payload.Password != "" {
|
||||||
registry.ManagementConfiguration.Password = payload.Password
|
registry.Password = payload.Password
|
||||||
}
|
}
|
||||||
|
|
||||||
if payload.Region != "" {
|
if payload.Region != "" {
|
||||||
registry.ManagementConfiguration.Ecr.Region = payload.Region
|
registry.Ecr.Region = payload.Region
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var tlsConfig portainer.TLSConfiguration
|
||||||
if payload.TLS {
|
if payload.TLS {
|
||||||
registry.ManagementConfiguration.TLSConfig = portainer.TLSConfiguration{
|
tlsConfig = portainer.TLSConfiguration{
|
||||||
TLS: true,
|
TLS: true,
|
||||||
TLSSkipVerify: payload.TLSSkipVerify,
|
TLSSkipVerify: payload.TLSSkipVerify,
|
||||||
}
|
}
|
||||||
|
@ -156,22 +153,25 @@ func (handler *Handler) registryConfigure(w http.ResponseWriter, r *http.Request
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return httperror.InternalServerError("Unable to persist TLS certificate file on disk", err)
|
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)
|
keyPath, err := handler.FileService.StoreRegistryManagementFileFromBytes(folder, "key.pem", payload.TLSKeyFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return httperror.InternalServerError("Unable to persist TLS key file on disk", err)
|
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)
|
cacertPath, err := handler.FileService.StoreRegistryManagementFileFromBytes(folder, "ca.pem", payload.TLSCACertFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return httperror.InternalServerError("Unable to persist TLS CA certificate file on disk", err)
|
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)
|
err = handler.DataStore.Registry().UpdateRegistry(registry.ID, registry)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return httperror.InternalServerError("Unable to persist registry changes inside the database", err)
|
return httperror.InternalServerError("Unable to persist registry changes inside the database", err)
|
||||||
|
|
|
@ -119,6 +119,8 @@ func (handler *Handler) registryCreate(w http.ResponseWriter, r *http.Request) *
|
||||||
Ecr: payload.Ecr,
|
Ecr: payload.Ecr,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
registry.ManagementConfiguration = syncConfig(registry)
|
||||||
|
|
||||||
registries, err := handler.DataStore.Registry().Registries()
|
registries, err := handler.DataStore.Registry().Registries()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return httperror.InternalServerError("Unable to retrieve registries from the database", err)
|
return httperror.InternalServerError("Unable to retrieve registries from the database", err)
|
||||||
|
|
|
@ -140,6 +140,8 @@ func (handler *Handler) registryUpdate(w http.ResponseWriter, r *http.Request) *
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
registry.ManagementConfiguration = syncConfig(registry)
|
||||||
|
|
||||||
if payload.URL != nil {
|
if payload.URL != nil {
|
||||||
shouldUpdateSecrets = shouldUpdateSecrets || (*payload.URL != registry.URL)
|
shouldUpdateSecrets = shouldUpdateSecrets || (*payload.URL != registry.URL)
|
||||||
|
|
||||||
|
@ -183,6 +185,21 @@ func (handler *Handler) registryUpdate(w http.ResponseWriter, r *http.Request) *
|
||||||
return response.JSON(w, registry)
|
return response.JSON(w, registry)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func syncConfig(registry *portainer.Registry) *portainer.RegistryManagementConfiguration {
|
||||||
|
config := registry.ManagementConfiguration
|
||||||
|
if config == nil {
|
||||||
|
config = &portainer.RegistryManagementConfiguration{}
|
||||||
|
}
|
||||||
|
|
||||||
|
config.Authentication = registry.Authentication
|
||||||
|
config.Username = registry.Username
|
||||||
|
config.Password = registry.Password
|
||||||
|
config.Ecr = registry.Ecr
|
||||||
|
config.Type = registry.Type
|
||||||
|
|
||||||
|
return config
|
||||||
|
}
|
||||||
|
|
||||||
func (handler *Handler) updateEndpointRegistryAccess(endpoint *portainer.Endpoint, registry *portainer.Registry, endpointAccess portainer.RegistryAccessPolicies) error {
|
func (handler *Handler) updateEndpointRegistryAccess(endpoint *portainer.Endpoint, registry *portainer.Registry, endpointAccess portainer.RegistryAccessPolicies) error {
|
||||||
|
|
||||||
cli, err := handler.K8sClientFactory.GetKubeClient(endpoint)
|
cli, err := handler.K8sClientFactory.GetKubeClient(endpoint)
|
||||||
|
|
|
@ -18,7 +18,8 @@ export function RegistryViewModel(data) {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function RegistryManagementConfigurationDefaultModel(registry) {
|
export function RegistryManagementConfigurationDefaultModel(registry) {
|
||||||
this.Authentication = false;
|
this.Authentication = registry.Authentication;
|
||||||
|
this.Username = registry.Username;
|
||||||
this.Password = '';
|
this.Password = '';
|
||||||
this.TLS = false;
|
this.TLS = false;
|
||||||
this.TLSSkipVerify = false;
|
this.TLSSkipVerify = false;
|
||||||
|
|
Loading…
Reference in New Issue