From 3165d354b5542d77e729cf5e338ee5dbff46d4fa Mon Sep 17 00:00:00 2001 From: Chaim Lev-Ari Date: Thu, 10 Feb 2022 06:03:46 +0200 Subject: [PATCH] fix(settings): clear helm url if requested [EE-2494] (#6526) * fix(settings): clear helm url if requested [EE-2494] fix [EE-2494] before this PR, helm url would clear when updating settings, if the helm url key wasn't provided. in this PR, it will be changed only if required * fix(settings): allow empty helm repo * chore(deps): run yarn * fix(settings): set helm repo url --- api/http/handler/settings/settings_update.go | 22 ++++++++++++-------- app/portainer/views/settings/settings.html | 2 +- yarn.lock | 1 + 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/api/http/handler/settings/settings_update.go b/api/http/handler/settings/settings_update.go index 75f1870ce..6a5d5553a 100644 --- a/api/http/handler/settings/settings_update.go +++ b/api/http/handler/settings/settings_update.go @@ -116,18 +116,22 @@ func (handler *Handler) settingsUpdate(w http.ResponseWriter, r *http.Request) * } if payload.HelmRepositoryURL != nil { - newHelmRepo := strings.TrimSuffix(strings.ToLower(*payload.HelmRepositoryURL), "/") + if *payload.HelmRepositoryURL != "" { + + newHelmRepo := strings.TrimSuffix(strings.ToLower(*payload.HelmRepositoryURL), "/") + + if newHelmRepo != settings.HelmRepositoryURL && newHelmRepo != portainer.DefaultHelmRepositoryURL { + err := libhelm.ValidateHelmRepositoryURL(*payload.HelmRepositoryURL) + if err != nil { + return &httperror.HandlerError{http.StatusBadRequest, "Invalid Helm repository URL. Must correspond to a valid URL format", err} + } - if newHelmRepo != settings.HelmRepositoryURL && newHelmRepo != portainer.DefaultHelmRepositoryURL { - err := libhelm.ValidateHelmRepositoryURL(*payload.HelmRepositoryURL) - if err != nil { - return &httperror.HandlerError{http.StatusBadRequest, "Invalid Helm repository URL. Must correspond to a valid URL format", err} } - } - settings.HelmRepositoryURL = newHelmRepo - } else { - settings.HelmRepositoryURL = "" + settings.HelmRepositoryURL = newHelmRepo + } else { + settings.HelmRepositoryURL = "" + } } if payload.BlackListedLabels != nil { diff --git a/app/portainer/views/settings/settings.html b/app/portainer/views/settings/settings.html index 7d6ab50fa..e311b817e 100644 --- a/app/portainer/views/settings/settings.html +++ b/app/portainer/views/settings/settings.html @@ -85,7 +85,7 @@
- +
diff --git a/yarn.lock b/yarn.lock index 935082d60..9321c5f4c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4547,6 +4547,7 @@ angular-moment-picker@^0.10.2: dependencies: angular-mocks "1.6.1" angular-sanitize "1.6.1" + lodash-es "^4.17.15" angular-resource@1.8.2: version "1.8.2"