mirror of
https://github.com/portainer/portainer.git
synced 2025-07-21 06:19:41 +02:00
import libhelm into portainer (#8128)
This commit is contained in:
parent
241440a474
commit
d2f6d1e415
32 changed files with 1305 additions and 5 deletions
47
api/pkg/libhelm/validate_repo.go
Normal file
47
api/pkg/libhelm/validate_repo.go
Normal file
|
@ -0,0 +1,47 @@
|
|||
package libhelm
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"path"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
const invalidChartRepo = "%q is not a valid chart repository or cannot be reached"
|
||||
|
||||
func ValidateHelmRepositoryURL(repoUrl string) error {
|
||||
if repoUrl == "" {
|
||||
return errors.New("URL is required")
|
||||
}
|
||||
|
||||
url, err := url.ParseRequestURI(repoUrl)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, fmt.Sprintf("invalid helm chart URL: %s", repoUrl))
|
||||
}
|
||||
|
||||
if !strings.EqualFold(url.Scheme, "http") && !strings.EqualFold(url.Scheme, "https") {
|
||||
return errors.New(fmt.Sprintf("invalid helm chart URL: %s", repoUrl))
|
||||
}
|
||||
|
||||
url.Path = path.Join(url.Path, "index.yaml")
|
||||
|
||||
var client = &http.Client{
|
||||
Timeout: time.Second * 10,
|
||||
}
|
||||
response, err := client.Head(url.String())
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, invalidChartRepo, repoUrl)
|
||||
}
|
||||
|
||||
// Success is indicated with 2xx status codes
|
||||
statusOK := response.StatusCode >= 200 && response.StatusCode < 300
|
||||
if !statusOK {
|
||||
return errors.Errorf(invalidChartRepo, repoUrl)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue