@@ -11,10 +11,11 @@ import (
1111 "os"
1212 "time"
1313
14+ "github.com/hashicorp/vault/sdk/logical"
15+
1416 "github.com/Venafi/vcert/v5"
1517 "github.com/Venafi/vcert/v5/pkg/endpoint"
1618 "github.com/Venafi/vcert/v5/pkg/verror"
17- "github.com/hashicorp/vault/sdk/logical"
1819)
1920
2021func (b * backend ) ClientVenafi (ctx context.Context , req * logical.Request , role * roleEntry ) (
@@ -67,6 +68,18 @@ func (b *backend) getConfig(ctx context.Context, req *logical.Request, role *rol
6768 zone = venafiSecret .Zone
6869 }
6970
71+ var netTransport = & http.Transport {
72+ Proxy : http .ProxyFromEnvironment ,
73+ DialContext : (& net.Dialer {
74+ Timeout : role .ServerTimeout ,
75+ KeepAlive : role .ServerTimeout ,
76+ }).DialContext ,
77+ MaxIdleConns : 100 ,
78+ IdleConnTimeout : 90 * time .Second ,
79+ TLSHandshakeTimeout : 10 * time .Second ,
80+ ExpectContinueTimeout : 1 * time .Second ,
81+ }
82+
7083 cfg = & vcert.Config {}
7184 cfg .BaseUrl = venafiSecret .URL
7285 cfg .Zone = zone
@@ -115,37 +128,25 @@ func (b *backend) getConfig(ctx context.Context, req *logical.Request, role *rol
115128 }
116129
117130 if role .ServerTimeout > 0 {
118- var netTransport = & http.Transport {
119- Proxy : http .ProxyFromEnvironment ,
120- DialContext : (& net.Dialer {
121- Timeout : role .ServerTimeout ,
122- KeepAlive : role .ServerTimeout ,
123- }).DialContext ,
124- MaxIdleConns : 100 ,
125- IdleConnTimeout : 90 * time .Second ,
126- TLSHandshakeTimeout : 10 * time .Second ,
127- ExpectContinueTimeout : 1 * time .Second ,
128- }
129-
130131 cfg .Client = & http.Client {
131132 Timeout : role .ServerTimeout ,
132133 Transport : netTransport ,
133134 }
135+ }
134136
135- var connectionTrustBundle * x509.CertPool
136-
137- if cfg .ConnectionTrust != "" {
138- log .Println ("Using trust bundle in custom http client" )
139- connectionTrustBundle = x509 .NewCertPool ()
140- if ! connectionTrustBundle .AppendCertsFromPEM ([]byte (cfg .ConnectionTrust )) {
141- return nil , fmt .Errorf ("%w: failed to parse PEM trust bundle" , verror .UserDataError )
142- }
143- netTransport .TLSClientConfig = & tls.Config {
144- RootCAs : connectionTrustBundle ,
145- MinVersion : tls .VersionTLS12 ,
146- }
147- cfg .Client .Transport = netTransport
137+ var connectionTrustBundle * x509.CertPool
138+
139+ if cfg .ConnectionTrust != "" {
140+ log .Println ("Using trust bundle in custom http client" )
141+ connectionTrustBundle = x509 .NewCertPool ()
142+ if ! connectionTrustBundle .AppendCertsFromPEM ([]byte (cfg .ConnectionTrust )) {
143+ return nil , fmt .Errorf ("%w: failed to parse PEM trust bundle" , verror .UserDataError )
144+ }
145+ netTransport .TLSClientConfig = & tls.Config {
146+ RootCAs : connectionTrustBundle ,
147+ MinVersion : tls .VersionTLS12 ,
148148 }
149+ cfg .Client .Transport = netTransport
149150 }
150151
151152 return cfg , nil
0 commit comments