Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: support proxy env vars #217

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 23 additions & 9 deletions provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,11 @@ const (
Default = 2
)

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

type ProviderConf struct {
rawUrl string
Expand Down Expand Up @@ -487,7 +489,9 @@ func awsSession(region string, conf *ProviderConf, endpoint string) *awssession.
sessOpts.Profile = conf.awsProfile
}

transport := http.Transport{}
transport := http.Transport{
Proxy: http.ProxyFromEnvironment,
}
// If configured as insecure, turn off SSL verification
if conf.insecure {
transport.TLSClientConfig = &tls.Config{InsecureSkipVerify: true}
Expand All @@ -514,12 +518,13 @@ func awsHttpClient(region string, conf *ProviderConf, headers map[string]string)
// Set the proxy URL after configuring AWS credentials since the proxy
// should be not used for credential sources that call a URL like ECS Task
// Roles or EC2 Instance Roles.
transport, _ := session.Config.HTTPClient.Transport.(*http.Transport)
transport.Proxy = http.ProxyFromEnvironment
if conf.proxy != "" {
proxyURL, _ := url.Parse(conf.proxy)
transport, _ := session.Config.HTTPClient.Transport.(*http.Transport)
transport.Proxy = http.ProxyURL(proxyURL)
session.Config.HTTPClient.Transport = transport
}
session.Config.HTTPClient.Transport = transport

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

// Wrapper to inject headers as needed
transport := &http.Transport{TLSClientConfig: tlsConfig}
transport := &http.Transport{
TLSClientConfig: tlsConfig,
Proxy: http.ProxyFromEnvironment,
}
// Configure a proxy URL if one is provided.
if conf.proxy != "" {
proxyURL, _ := url.Parse(conf.proxy)
Expand Down Expand Up @@ -601,7 +609,10 @@ func tlsHttpClient(conf *ProviderConf, headers map[string]string) *http.Client {
tlsConfig.ServerName = conf.hostOverride
}

transport := &http.Transport{TLSClientConfig: tlsConfig}
transport := &http.Transport{
TLSClientConfig: tlsConfig,
Proxy: http.ProxyFromEnvironment,
}
// Configure a proxy URL if one is provided.
if conf.proxy != "" {
proxyURL, _ := url.Parse(conf.proxy)
Expand All @@ -628,7 +639,10 @@ func defaultHttpClient(conf *ProviderConf, headers map[string]string) *http.Clie
tlsConfig.ServerName = conf.hostOverride
}

transport := &http.Transport{TLSClientConfig: tlsConfig}
transport := &http.Transport{
TLSClientConfig: tlsConfig,
Proxy: http.ProxyFromEnvironment,
}
// Configure a proxy URL if one is provided.
if conf.proxy != "" {
proxyURL, _ := url.Parse(conf.proxy)
Expand Down
Loading