-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.go
41 lines (36 loc) · 939 Bytes
/
client.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package gotenable
import (
"crypto/tls"
"crypto/x509"
"io/ioutil"
"net/http"
"net/url"
)
func HTTPTransportConfig(proxy string, cert string, insecureSkipVerify bool) *http.Transport {
// Create a new HTTP transport
transport := &http.Transport{}
// Set proxy
if proxy != `` {
proxyURL, err := url.Parse(proxy)
if err != nil {
Log.Logger.Fatalln(`[FATAL]`, err)
}
transport.Proxy = http.ProxyURL(proxyURL)
}
// Set cert
if cert != `` {
caCert, err := ioutil.ReadFile(cert)
if err != nil {
Log.Logger.Fatalln(`[FATAL]`, err)
}
caCertPool, _ := x509.SystemCertPool()
caCertPool.AppendCertsFromPEM(caCert)
transport.TLSClientConfig = &tls.Config{RootCAs: caCertPool}
}
// Set TLS verification
if insecureSkipVerify == true {
transport.TLSClientConfig = &tls.Config{InsecureSkipVerify: insecureSkipVerify}
Log.Logger.Println(`[WARN] TLS verification has been disabled!`)
}
return transport
}