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

@@ -30,7 +30,7 @@ require (
github.com/portainer/docker-compose-wrapper v0.0.0-20210810234209-d01bc85eb481
github.com/portainer/libcompose v0.5.3
github.com/portainer/libcrypto v0.0.0-20210422035235-c652195c5c3a
github.com/portainer/libhelm v0.0.0-20210827003723-50899dcffbec
github.com/portainer/libhelm v0.0.0-20210901032115-ad822f351174
github.com/portainer/libhttp v0.0.0-20190806161843-ba068f58be33
github.com/robfig/cron/v3 v3.0.1
github.com/sirupsen/logrus v1.8.1

View File

@@ -247,8 +247,8 @@ github.com/portainer/libcompose v0.5.3 h1:tE4WcPuGvo+NKeDkDWpwNavNLZ5GHIJ4RvuZXs
github.com/portainer/libcompose v0.5.3/go.mod h1:7SKd/ho69rRKHDFSDUwkbMcol2TMKU5OslDsajr8Ro8=
github.com/portainer/libcrypto v0.0.0-20210422035235-c652195c5c3a h1:qY8TbocN75n5PDl16o0uVr5MevtM5IhdwSelXEd4nFM=
github.com/portainer/libcrypto v0.0.0-20210422035235-c652195c5c3a/go.mod h1:n54EEIq+MM0NNtqLeCby8ljL+l275VpolXO0ibHegLE=
github.com/portainer/libhelm v0.0.0-20210827003723-50899dcffbec h1:L3o94L7VYLjAt4gKGKpgKFIkzpUYPh/UiEVSyjNGYGE=
github.com/portainer/libhelm v0.0.0-20210827003723-50899dcffbec/go.mod h1:dL39owjMIeGKuSsSbbTrLCzZQfoB1zORhq0TAet7D5E=
github.com/portainer/libhelm v0.0.0-20210901032115-ad822f351174 h1:6iMxTpjyp/AHW2qCavLzwsE+BgVZVpjOAsRZEi1lFGs=
github.com/portainer/libhelm v0.0.0-20210901032115-ad822f351174/go.mod h1:YvYAk7krKTzB+rFwDr0jQ3sQu2BtiXK1AR0sZH7nhJA=
github.com/portainer/libhttp v0.0.0-20190806161843-ba068f58be33 h1:H8HR2dHdBf8HANSkUyVw4o8+4tegGcd+zyKZ3e599II=
github.com/portainer/libhttp v0.0.0-20190806161843-ba068f58be33/go.mod h1:Y2TfgviWI4rT2qaOTHr+hq6MdKIE5YjgQAu7qwptTV0=
github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw=

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