Skip to content

Commit 889d662

Browse files
committed
feat: implement default transport in all http clients
1 parent 733f853 commit 889d662

File tree

4 files changed

+44
-11
lines changed

4 files changed

+44
-11
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7+
## [0.4.26](https://github.com/Altinity/terraform-provider-altinitycloud/compare/v0.4.25...v0.4.26)
8+
### Changed
9+
- Implement default transport configuration for all SDK HTTP client [1de625f](https://github.com/Altinity/terraform-provider-altinitycloud/commit/1de625f).
10+
711
## [0.4.25](https://github.com/Altinity/terraform-provider-altinitycloud/compare/v0.4.24...v0.4.25)
812
### Changed
913
- Bump github.com/hashicorp/terraform-plugin-log to `0.10.0` [#192](https://github.com/Altinity/terraform-provider-altinitycloud/pull/192).

internal/provider/provider.go

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"crypto/x509"
77
"errors"
88
"fmt"
9-
"net"
109
"net/http"
1110
"os"
1211
"runtime"
@@ -129,19 +128,25 @@ func (p *altinityCloudProvider) Configure(ctx context.Context, req provider.Conf
129128
}
130129
}
131130

131+
defaultTransport, ok := http.DefaultTransport.(*http.Transport)
132+
if !ok {
133+
resp.Diagnostics.AddError(
134+
"Failed to configure HTTP client",
135+
"Unable to get default HTTP transport",
136+
)
137+
return
138+
}
139+
132140
client := client.NewClient(
133141
&http.Client{
134142
Transport: &http.Transport{
135-
Proxy: http.ProxyFromEnvironment,
136-
DialContext: (&net.Dialer{
137-
Timeout: 30 * time.Second,
138-
KeepAlive: 30 * time.Second,
139-
}).DialContext,
140-
ForceAttemptHTTP2: true,
141-
MaxIdleConns: 16,
142-
IdleConnTimeout: 45 * time.Second,
143-
TLSHandshakeTimeout: 10 * time.Second,
144-
ExpectContinueTimeout: 1 * time.Second,
143+
Proxy: defaultTransport.Proxy,
144+
DialContext: defaultTransport.DialContext,
145+
ForceAttemptHTTP2: defaultTransport.ForceAttemptHTTP2,
146+
MaxIdleConns: defaultTransport.MaxIdleConns,
147+
IdleConnTimeout: defaultTransport.IdleConnTimeout,
148+
TLSHandshakeTimeout: defaultTransport.TLSHandshakeTimeout,
149+
ExpectContinueTimeout: defaultTransport.ExpectContinueTimeout,
145150
TLSClientConfig: &tls.Config{
146151
RootCAs: rootCAs,
147152
},

internal/sdk/auth/auth.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,20 @@ func (a *Auth) GenerateCertificate(ctx context.Context, envName string) (string,
5353
}
5454

5555
func (a *Auth) signCertificateRequest(ctx context.Context, csrPEM []byte) ([]byte, error) {
56+
defaultTransport, ok := http.DefaultTransport.(*http.Transport)
57+
if !ok {
58+
return nil, fmt.Errorf("failed to get default HTTP transport")
59+
}
60+
5661
httpClient := &http.Client{
5762
Transport: &http.Transport{
63+
Proxy: defaultTransport.Proxy,
64+
DialContext: defaultTransport.DialContext,
65+
ForceAttemptHTTP2: defaultTransport.ForceAttemptHTTP2,
66+
MaxIdleConns: defaultTransport.MaxIdleConns,
67+
IdleConnTimeout: defaultTransport.IdleConnTimeout,
68+
TLSHandshakeTimeout: defaultTransport.TLSHandshakeTimeout,
69+
ExpectContinueTimeout: defaultTransport.ExpectContinueTimeout,
5870
TLSClientConfig: &tls.Config{
5971
RootCAs: a.RootCAs,
6072
},

internal/sdk/crypto/crypto.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,20 @@ func (c *Crypto) Decrypt(pkPem string, value string) (string, error) {
8383
}
8484

8585
func (c *Crypto) fetchPublicKey(ctx context.Context, tlsCert tls.Certificate) (pem []byte, err error) {
86+
defaultTransport, ok := http.DefaultTransport.(*http.Transport)
87+
if !ok {
88+
return nil, fmt.Errorf("failed to get default HTTP transport")
89+
}
90+
8691
httpClient := &http.Client{
8792
Transport: &http.Transport{
93+
Proxy: defaultTransport.Proxy,
94+
DialContext: defaultTransport.DialContext,
95+
ForceAttemptHTTP2: defaultTransport.ForceAttemptHTTP2,
96+
MaxIdleConns: defaultTransport.MaxIdleConns,
97+
IdleConnTimeout: defaultTransport.IdleConnTimeout,
98+
TLSHandshakeTimeout: defaultTransport.TLSHandshakeTimeout,
99+
ExpectContinueTimeout: defaultTransport.ExpectContinueTimeout,
88100
TLSClientConfig: &tls.Config{
89101
RootCAs: c.RootCAs,
90102
Certificates: []tls.Certificate{

0 commit comments

Comments
 (0)