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:
Aliaksandr Valialkin 2024-03-17 23:19:30 +02:00
parent f45f39d80e
commit 729b263670
No known key found for this signature in database
GPG Key ID: 52C003EE2BCDB9EB

View File

@ -11,12 +11,12 @@ import (
// Transport creates http.Transport object based on provided URL.
// 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()
if !strings.HasPrefix(URL, "https") {
return t, nil
}
tlsCfg, err := TLSConfig(certFile, keyFile, CAFile, serverName, insecureSkipVerify)
tlsCfg, err := TLSConfig(certFile, keyFile, caFile, serverName, insecureSkipVerify)
if err != nil {
return nil, err
}
@ -25,7 +25,7 @@ func Transport(URL, certFile, keyFile, CAFile, serverName string, insecureSkipVe
}
// 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
if certFile != "" {
cert, err := tls.LoadX509KeyPair(certFile, keyFile)
@ -37,15 +37,15 @@ func TLSConfig(certFile, keyFile, CAFile, serverName string, insecureSkipVerify
}
var rootCAs *x509.CertPool
if CAFile != "" {
pem, err := os.ReadFile(CAFile)
if caFile != "" {
pem, err := os.ReadFile(caFile)
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()
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)
}
}