|
|
|
|
@ -46,19 +46,16 @@ func (ds *DataSource) GetHttpTransport() (*http.Transport, error) { |
|
|
|
|
return t.Transport, nil |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
var tlsSkipVerify, tlsClientAuth, tlsAuthWithCACert bool |
|
|
|
|
if ds.JsonData != nil { |
|
|
|
|
tlsClientAuth = ds.JsonData.Get("tlsAuth").MustBool(false) |
|
|
|
|
tlsAuthWithCACert = ds.JsonData.Get("tlsAuthWithCACert").MustBool(false) |
|
|
|
|
tlsSkipVerify = ds.JsonData.Get("tlsSkipVerify").MustBool(false) |
|
|
|
|
tlsConfig, err := ds.GetTLSConfig() |
|
|
|
|
if err != nil { |
|
|
|
|
return nil, err |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
tlsConfig.Renegotiation = tls.RenegotiateFreelyAsClient |
|
|
|
|
|
|
|
|
|
transport := &http.Transport{ |
|
|
|
|
TLSClientConfig: &tls.Config{ |
|
|
|
|
InsecureSkipVerify: tlsSkipVerify, |
|
|
|
|
Renegotiation: tls.RenegotiateFreelyAsClient, |
|
|
|
|
}, |
|
|
|
|
Proxy: http.ProxyFromEnvironment, |
|
|
|
|
TLSClientConfig: tlsConfig, |
|
|
|
|
Proxy: http.ProxyFromEnvironment, |
|
|
|
|
Dial: (&net.Dialer{ |
|
|
|
|
Timeout: 30 * time.Second, |
|
|
|
|
KeepAlive: 30 * time.Second, |
|
|
|
|
@ -70,6 +67,26 @@ func (ds *DataSource) GetHttpTransport() (*http.Transport, error) { |
|
|
|
|
IdleConnTimeout: 90 * time.Second, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
ptc.cache[ds.Id] = cachedTransport{ |
|
|
|
|
Transport: transport, |
|
|
|
|
updated: ds.Updated, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return transport, nil |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func (ds *DataSource) GetTLSConfig() (*tls.Config, error) { |
|
|
|
|
var tlsSkipVerify, tlsClientAuth, tlsAuthWithCACert bool |
|
|
|
|
if ds.JsonData != nil { |
|
|
|
|
tlsClientAuth = ds.JsonData.Get("tlsAuth").MustBool(false) |
|
|
|
|
tlsAuthWithCACert = ds.JsonData.Get("tlsAuthWithCACert").MustBool(false) |
|
|
|
|
tlsSkipVerify = ds.JsonData.Get("tlsSkipVerify").MustBool(false) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
tlsConfig := &tls.Config{ |
|
|
|
|
InsecureSkipVerify: tlsSkipVerify, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if tlsClientAuth || tlsAuthWithCACert { |
|
|
|
|
decrypted := ds.SecureJsonData.Decrypt() |
|
|
|
|
if tlsAuthWithCACert && len(decrypted["tlsCACert"]) > 0 { |
|
|
|
|
@ -78,7 +95,7 @@ func (ds *DataSource) GetHttpTransport() (*http.Transport, error) { |
|
|
|
|
if !ok { |
|
|
|
|
return nil, errors.New("Failed to parse TLS CA PEM certificate") |
|
|
|
|
} |
|
|
|
|
transport.TLSClientConfig.RootCAs = caPool |
|
|
|
|
tlsConfig.RootCAs = caPool |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if tlsClientAuth { |
|
|
|
|
@ -86,14 +103,9 @@ func (ds *DataSource) GetHttpTransport() (*http.Transport, error) { |
|
|
|
|
if err != nil { |
|
|
|
|
return nil, err |
|
|
|
|
} |
|
|
|
|
transport.TLSClientConfig.Certificates = []tls.Certificate{cert} |
|
|
|
|
tlsConfig.Certificates = []tls.Certificate{cert} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
ptc.cache[ds.Id] = cachedTransport{ |
|
|
|
|
Transport: transport, |
|
|
|
|
updated: ds.Updated, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return transport, nil |
|
|
|
|
return tlsConfig, nil |
|
|
|
|
} |
|
|
|
|
|