feat(helm) use libhelm url validator and improved path assembly EE-1554 (#5561)

This commit is contained in:
Matt Hook
2021-09-01 16:13:28 +12:00
committed by zees-dev
parent 3340ca3060
commit 90b43feda8
4 changed files with 12 additions and 18 deletions

View File

@@ -1,12 +1,13 @@
package settings
import (
"errors"
"net/http"
"strings"
"time"
"github.com/asaskevich/govalidator"
"github.com/pkg/errors"
"github.com/portainer/libhelm"
httperror "github.com/portainer/libhttp/error"
"github.com/portainer/libhttp/request"
"github.com/portainer/libhttp/response"
@@ -51,8 +52,11 @@ func (payload *settingsUpdatePayload) Validate(r *http.Request) error {
if payload.TemplatesURL != nil && *payload.TemplatesURL != "" && !govalidator.IsURL(*payload.TemplatesURL) {
return errors.New("Invalid external templates URL. Must correspond to a valid URL format")
}
if payload.HelmRepositoryURL != nil && *payload.HelmRepositoryURL != "" && !govalidator.IsURL(*payload.HelmRepositoryURL) {
return errors.New("Invalid Helm repository URL. Must correspond to a valid URL format")
if payload.HelmRepositoryURL != nil && *payload.HelmRepositoryURL != "" {
err := libhelm.ValidateHelmRepositoryURL(*payload.HelmRepositoryURL)
if err != nil {
return errors.Wrap(err, "Invalid Helm repository URL. Must correspond to a valid URL format")
}
}
if payload.UserSessionTimeout != nil {
_, err := time.ParseDuration(*payload.UserSessionTimeout)

View File

@@ -1,13 +1,12 @@
package users
import (
"fmt"
"net/http"
"net/url"
"strings"
"github.com/pkg/errors"
"github.com/portainer/libhelm"
errs "github.com/portainer/portainer/api/http/errors"
httperror "github.com/portainer/libhttp/error"
@@ -22,16 +21,7 @@ type addHelmRepoUrlPayload struct {
}
func (p *addHelmRepoUrlPayload) Validate(_ *http.Request) error {
p.URL = strings.TrimSuffix(p.URL, "/")
if p.URL == "" {
return errors.New("URL is required")
}
_, err := url.ParseRequestURI(p.URL)
if err != nil {
return errors.Wrap(err, fmt.Sprintf("provided URL %q is not valid", p.URL))
}
return nil
return libhelm.ValidateHelmRepositoryURL(p.URL)
}
// @id UserHelmRepositoryCreate