1
0
Fork 0
mirror of https://github.com/portainer/portainer.git synced 2025-07-26 00:39:41 +02:00
portainer/pkg/libhelm/validate_repo.go
andres-portainer bfa27d9103
Some checks are pending
ci / build_images (map[arch:ppc64le platform:linux version:]) (push) Waiting to run
ci / build_images (map[arch:s390x platform:linux version:]) (push) Waiting to run
ci / build_images (map[arch:amd64 platform:linux version:]) (push) Waiting to run
ci / build_images (map[arch:amd64 platform:windows version:1809]) (push) Waiting to run
ci / build_images (map[arch:amd64 platform:windows version:ltsc2022]) (push) Waiting to run
ci / build_images (map[arch:arm platform:linux version:]) (push) Waiting to run
ci / build_images (map[arch:arm64 platform:linux version:]) (push) Waiting to run
ci / build_manifests (push) Blocked by required conditions
/ triage (push) Waiting to run
Lint / Run linters (push) Waiting to run
Test / test-server (map[arch:amd64 platform:windows version:ltsc2022]) (push) Waiting to run
Test / test-server (map[arch:arm64 platform:linux]) (push) Waiting to run
Test / test-client (push) Waiting to run
Test / test-server (map[arch:amd64 platform:linux]) (push) Waiting to run
Test / test-server (map[arch:amd64 platform:windows version:1809]) (push) Waiting to run
chore(code): clean up the code EE-7251 (#11948)
2024-06-18 15:59:12 -03:00

48 lines
1.1 KiB
Go

package libhelm
import (
"errors"
"fmt"
"net/http"
"net/url"
"path"
"strings"
"time"
)
func ValidateHelmRepositoryURL(repoUrl string, client *http.Client) error {
if repoUrl == "" {
return errors.New("URL is required")
}
url, err := url.ParseRequestURI(repoUrl)
if err != nil {
return fmt.Errorf("invalid helm repository URL '%s': %w", repoUrl, err)
}
if !strings.EqualFold(url.Scheme, "http") && !strings.EqualFold(url.Scheme, "https") {
return fmt.Errorf("invalid helm repository URL '%s'", repoUrl)
}
url.Path = path.Join(url.Path, "index.yaml")
if client == nil {
client = &http.Client{
Timeout: 120 * time.Second,
Transport: http.DefaultTransport,
}
}
response, err := client.Head(url.String())
if err != nil {
return fmt.Errorf("%s is not a valid chart repository or cannot be reached: %w", repoUrl, err)
}
// Success is indicated with 2xx status codes. 3xx status codes indicate a redirect.
statusOK := response.StatusCode >= 200 && response.StatusCode < 300
if !statusOK {
return fmt.Errorf("%s is not a valid chart repository or cannot be reached", repoUrl)
}
return nil
}