fix(helm) allow settings to be saved offline EE-1907 (#5907)

* allow settings to be saved offline.  Due to helm repo validation not working for bitnami when offline!

* @hookenz
dont validate the helm repo if the repo hasn't changed or is the default
pull/5919/head
Matt Hook 3 years ago committed by GitHub
parent ba1f0f4018
commit 3cde10bcac
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -54,11 +54,8 @@ func (payload *settingsUpdatePayload) Validate(r *http.Request) error {
if payload.TemplatesURL != nil && *payload.TemplatesURL != "" && !govalidator.IsURL(*payload.TemplatesURL) { if payload.TemplatesURL != nil && *payload.TemplatesURL != "" && !govalidator.IsURL(*payload.TemplatesURL) {
return errors.New("Invalid external templates URL. Must correspond to a valid URL format") return errors.New("Invalid external templates URL. Must correspond to a valid URL format")
} }
if payload.HelmRepositoryURL != nil && *payload.HelmRepositoryURL != "" { if payload.HelmRepositoryURL != nil && *payload.HelmRepositoryURL != "" && !govalidator.IsURL(*payload.HelmRepositoryURL) {
err := libhelm.ValidateHelmRepositoryURL(*payload.HelmRepositoryURL) return errors.New("Invalid Helm repository URL. Must correspond to a valid URL format")
if err != nil {
return errors.Wrap(err, "Invalid Helm repository URL. Must correspond to a valid URL format")
}
} }
if payload.UserSessionTimeout != nil { if payload.UserSessionTimeout != nil {
_, err := time.ParseDuration(*payload.UserSessionTimeout) _, err := time.ParseDuration(*payload.UserSessionTimeout)
@ -114,7 +111,16 @@ func (handler *Handler) settingsUpdate(w http.ResponseWriter, r *http.Request) *
} }
if payload.HelmRepositoryURL != nil { if payload.HelmRepositoryURL != nil {
settings.HelmRepositoryURL = strings.TrimSuffix(strings.ToLower(*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}
}
}
settings.HelmRepositoryURL = newHelmRepo
} }
if payload.BlackListedLabels != nil { if payload.BlackListedLabels != nil {

Loading…
Cancel
Save