1
0
mirror of https://github.com/rancher/norman.git synced 2025-09-12 13:26:13 +00:00

Introduce proxy support

This commit is contained in:
Jordan JEAN
2020-01-07 12:49:15 +01:00
parent 5b9227fe32
commit 39e54730f9

View File

@@ -185,6 +185,9 @@ func NewAPIClient(opts *ClientOpts) (APIBaseClient, error) {
client.Timeout = opts.Timeout client.Timeout = opts.Timeout
if opts.CACerts != "" { if opts.CACerts != "" {
if Debug {
fmt.Println("Some CAcerts are provided.")
}
roots := x509.NewCertPool() roots := x509.NewCertPool()
ok := roots.AppendCertsFromPEM([]byte(opts.CACerts)) ok := roots.AppendCertsFromPEM([]byte(opts.CACerts))
if !ok { if !ok {
@@ -194,15 +197,30 @@ func NewAPIClient(opts *ClientOpts) (APIBaseClient, error) {
TLSClientConfig: &tls.Config{ TLSClientConfig: &tls.Config{
RootCAs: roots, RootCAs: roots,
}, },
Proxy: http.ProxyFromEnvironment,
} }
client.Transport = tr client.Transport = tr
} }
if opts.Insecure { if opts.Insecure {
if Debug {
fmt.Println("Insecure TLS set.")
}
tr := &http.Transport{ tr := &http.Transport{
TLSClientConfig: &tls.Config{ TLSClientConfig: &tls.Config{
InsecureSkipVerify: opts.Insecure, InsecureSkipVerify: opts.Insecure,
}, },
Proxy: http.ProxyFromEnvironment,
}
client.Transport = tr
}
if !(opts.Insecure) && (opts.CACerts == "") {
if Debug {
fmt.Println("Insecure TLS not set and no CAcerts is provided.")
}
tr := &http.Transport{
Proxy: http.ProxyFromEnvironment,
} }
client.Transport = tr client.Transport = tr
} }