Skip to content

Commit 55cf742

Browse files
committed
fix: support proxy env vars
Signed-off-by: gnu letik <[email protected]>
1 parent 790834e commit 55cf742

File tree

1 file changed

+23
-9
lines changed

1 file changed

+23
-9
lines changed

provider/provider.go

+23-9
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,11 @@ const (
3737
Default = 2
3838
)
3939

40-
var awsUrlRegexp = regexp.MustCompile(`([a-z0-9-]+).es.amazonaws.com$`)
41-
var awsOpensearchServerlessUrlRegexp = regexp.MustCompile(`([a-z0-9-]+).aoss.amazonaws.com$`)
42-
var minimalOpensearchServerlessVersion = "2.0.0"
40+
var (
41+
awsUrlRegexp = regexp.MustCompile(`([a-z0-9-]+).es.amazonaws.com$`)
42+
awsOpensearchServerlessUrlRegexp = regexp.MustCompile(`([a-z0-9-]+).aoss.amazonaws.com$`)
43+
minimalOpensearchServerlessVersion = "2.0.0"
44+
)
4345

4446
type ProviderConf struct {
4547
rawUrl string
@@ -487,7 +489,9 @@ func awsSession(region string, conf *ProviderConf, endpoint string) *awssession.
487489
sessOpts.Profile = conf.awsProfile
488490
}
489491

490-
transport := http.Transport{}
492+
transport := http.Transport{
493+
Proxy: http.ProxyFromEnvironment,
494+
}
491495
// If configured as insecure, turn off SSL verification
492496
if conf.insecure {
493497
transport.TLSClientConfig = &tls.Config{InsecureSkipVerify: true}
@@ -514,12 +518,13 @@ func awsHttpClient(region string, conf *ProviderConf, headers map[string]string)
514518
// Set the proxy URL after configuring AWS credentials since the proxy
515519
// should be not used for credential sources that call a URL like ECS Task
516520
// Roles or EC2 Instance Roles.
521+
transport, _ := session.Config.HTTPClient.Transport.(*http.Transport)
522+
transport.Proxy = http.ProxyFromEnvironment
517523
if conf.proxy != "" {
518524
proxyURL, _ := url.Parse(conf.proxy)
519-
transport, _ := session.Config.HTTPClient.Transport.(*http.Transport)
520525
transport.Proxy = http.ProxyURL(proxyURL)
521-
session.Config.HTTPClient.Transport = transport
522526
}
527+
session.Config.HTTPClient.Transport = transport
523528

524529
signer := awssigv4.NewSigner(session.Config.Credentials)
525530
client, err := aws_signing_client.New(signer, session.Config.HTTPClient, conf.awsSig4Service, region)
@@ -547,7 +552,10 @@ func tokenHttpClient(conf *ProviderConf, headers map[string]string) *http.Client
547552
}
548553

549554
// Wrapper to inject headers as needed
550-
transport := &http.Transport{TLSClientConfig: tlsConfig}
555+
transport := &http.Transport{
556+
TLSClientConfig: tlsConfig,
557+
Proxy: http.ProxyFromEnvironment,
558+
}
551559
// Configure a proxy URL if one is provided.
552560
if conf.proxy != "" {
553561
proxyURL, _ := url.Parse(conf.proxy)
@@ -601,7 +609,10 @@ func tlsHttpClient(conf *ProviderConf, headers map[string]string) *http.Client {
601609
tlsConfig.ServerName = conf.hostOverride
602610
}
603611

604-
transport := &http.Transport{TLSClientConfig: tlsConfig}
612+
transport := &http.Transport{
613+
TLSClientConfig: tlsConfig,
614+
Proxy: http.ProxyFromEnvironment,
615+
}
605616
// Configure a proxy URL if one is provided.
606617
if conf.proxy != "" {
607618
proxyURL, _ := url.Parse(conf.proxy)
@@ -628,7 +639,10 @@ func defaultHttpClient(conf *ProviderConf, headers map[string]string) *http.Clie
628639
tlsConfig.ServerName = conf.hostOverride
629640
}
630641

631-
transport := &http.Transport{TLSClientConfig: tlsConfig}
642+
transport := &http.Transport{
643+
TLSClientConfig: tlsConfig,
644+
Proxy: http.ProxyFromEnvironment,
645+
}
632646
// Configure a proxy URL if one is provided.
633647
if conf.proxy != "" {
634648
proxyURL, _ := url.Parse(conf.proxy)

0 commit comments

Comments
 (0)