make http part of registry class

This commit is contained in:
Yann Hamon 2020-11-08 16:25:45 +01:00
parent 45040c3fe2
commit 49ad2fc375

View file

@ -5,9 +5,11 @@ import (
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"net/http" "net/http"
"time"
) )
type KubernetesRegistry struct { type KubernetesRegistry struct {
http *http.Transport
schemaPathTemplate string schemaPathTemplate string
strict bool strict bool
} }
@ -22,11 +24,17 @@ func newNetFoundError(err error) *NotFoundError {
func (e *NotFoundError) Error() string { return e.err.Error() } func (e *NotFoundError) Error() string { return e.err.Error() }
func newHTTPRegistry(schemaPathTemplate string, strict bool, skipTLS bool) *KubernetesRegistry { func newHTTPRegistry(schemaPathTemplate string, strict bool, skipTLS bool) *KubernetesRegistry {
reghttp := &http.Transport{
MaxIdleConns: 100,
IdleConnTimeout: 3 * time.Second,
DisableCompression: true,
}
if skipTLS { if skipTLS {
http.DefaultTransport.(*http.Transport).TLSClientConfig = &tls.Config{InsecureSkipVerify: true} reghttp.TLSClientConfig = &tls.Config{InsecureSkipVerify: true}
} }
return &KubernetesRegistry{ return &KubernetesRegistry{
http: reghttp,
schemaPathTemplate: schemaPathTemplate, schemaPathTemplate: schemaPathTemplate,
strict: strict, strict: strict,
} }
@ -38,7 +46,8 @@ func (r KubernetesRegistry) DownloadSchema(resourceKind, resourceAPIVersion, k8s
return nil, err return nil, err
} }
resp, err := http.Get(url) client := &http.Client{Transport: r.http}
resp, err := client.Get(url)
if err != nil { if err != nil {
return nil, fmt.Errorf("failed downloading schema at %s: %s", url, err) return nil, fmt.Errorf("failed downloading schema at %s: %s", url, err)
} }