mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2025-02-09 15:27:11 +00:00
lib/httputils: rename CAFile -> caFile in order to be consistent with local var naming in Go
This is a follow-up for 83e55456e2
This commit is contained in:
parent
f45f39d80e
commit
729b263670
1 changed files with 7 additions and 7 deletions
|
@ -11,12 +11,12 @@ import (
|
||||||
|
|
||||||
// Transport creates http.Transport object based on provided URL.
|
// Transport creates http.Transport object based on provided URL.
|
||||||
// Returns Transport with TLS configuration if URL contains `https` prefix
|
// Returns Transport with TLS configuration if URL contains `https` prefix
|
||||||
func Transport(URL, certFile, keyFile, CAFile, serverName string, insecureSkipVerify bool) (*http.Transport, error) {
|
func Transport(URL, certFile, keyFile, caFile, serverName string, insecureSkipVerify bool) (*http.Transport, error) {
|
||||||
t := http.DefaultTransport.(*http.Transport).Clone()
|
t := http.DefaultTransport.(*http.Transport).Clone()
|
||||||
if !strings.HasPrefix(URL, "https") {
|
if !strings.HasPrefix(URL, "https") {
|
||||||
return t, nil
|
return t, nil
|
||||||
}
|
}
|
||||||
tlsCfg, err := TLSConfig(certFile, keyFile, CAFile, serverName, insecureSkipVerify)
|
tlsCfg, err := TLSConfig(certFile, keyFile, caFile, serverName, insecureSkipVerify)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -25,7 +25,7 @@ func Transport(URL, certFile, keyFile, CAFile, serverName string, insecureSkipVe
|
||||||
}
|
}
|
||||||
|
|
||||||
// TLSConfig creates tls.Config object from provided arguments
|
// TLSConfig creates tls.Config object from provided arguments
|
||||||
func TLSConfig(certFile, keyFile, CAFile, serverName string, insecureSkipVerify bool) (*tls.Config, error) {
|
func TLSConfig(certFile, keyFile, caFile, serverName string, insecureSkipVerify bool) (*tls.Config, error) {
|
||||||
var certs []tls.Certificate
|
var certs []tls.Certificate
|
||||||
if certFile != "" {
|
if certFile != "" {
|
||||||
cert, err := tls.LoadX509KeyPair(certFile, keyFile)
|
cert, err := tls.LoadX509KeyPair(certFile, keyFile)
|
||||||
|
@ -37,15 +37,15 @@ func TLSConfig(certFile, keyFile, CAFile, serverName string, insecureSkipVerify
|
||||||
}
|
}
|
||||||
|
|
||||||
var rootCAs *x509.CertPool
|
var rootCAs *x509.CertPool
|
||||||
if CAFile != "" {
|
if caFile != "" {
|
||||||
pem, err := os.ReadFile(CAFile)
|
pem, err := os.ReadFile(caFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("cannot read `ca_file` %q: %w", CAFile, err)
|
return nil, fmt.Errorf("cannot read `ca_file` %q: %w", caFile, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
rootCAs = x509.NewCertPool()
|
rootCAs = x509.NewCertPool()
|
||||||
if !rootCAs.AppendCertsFromPEM(pem) {
|
if !rootCAs.AppendCertsFromPEM(pem) {
|
||||||
return nil, fmt.Errorf("cannot parse data from `ca_file` %q", CAFile)
|
return nil, fmt.Errorf("cannot parse data from `ca_file` %q", caFile)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue