Skip to content

Commit

Permalink
Use custom http client for cacrt or skipTLS check
Browse files Browse the repository at this point in the history
Signed-off-by: Tamal Saha <tamal@appscode.com>
  • Loading branch information
tamalsaha committed Sep 13, 2024
1 parent d63a2d1 commit 669afe6
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,19 +53,18 @@ func NewClient(baseURL, token, clusterUID string, caCert []byte, insecureSkipVer
url: u,
token: token,
clusterUID: clusterUID,
client: http.DefaultClient,
}
if len(caCert) == 0 {
c.client = http.DefaultClient
} else {
caCertPool := x509.NewCertPool()
caCertPool.AppendCertsFromPEM(caCert)

if len(caCert) > 0 || insecureSkipVerifyTLS {
tlsConfig := &tls.Config{
InsecureSkipVerify: insecureSkipVerifyTLS,
RootCAs: caCertPool,
}
transport := &http.Transport{TLSClientConfig: tlsConfig}
c.client = &http.Client{Transport: transport}
if len(c.caCert) > 0 {
caCertPool := x509.NewCertPool()
caCertPool.AppendCertsFromPEM(caCert)
tlsConfig.RootCAs = caCertPool
}
c.client = &http.Client{Transport: &http.Transport{TLSClientConfig: tlsConfig}}
}
return c, nil
}
Expand Down

0 comments on commit 669afe6

Please sign in to comment.