mirror of
https://github.com/portainer/portainer.git
synced 2025-07-19 13:29:41 +02:00
feat(libhelm) import libhelm into CE pkg directory [EE-4650] (#8138)
* import libhelm and update some paths * remove file * update readme
This commit is contained in:
parent
9cdc0da615
commit
4fee359247
29 changed files with 1328 additions and 0 deletions
47
pkg/libhelm/validate_repo.go
Normal file
47
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