Add support of HTTP_PROXY, HTTPS_PROXY and NO_PROXY (#51)

This commit is contained in:
Hidetake Iwata
2019-04-09 13:17:12 +09:00
committed by GitHub
parent e465c4852b
commit 000711f52e
2 changed files with 12 additions and 18 deletions
+6
View File
@@ -128,6 +128,12 @@ kubectl config set-credentials keycloak \
If kubelogin could not parse the certificate, it shows a warning and skips it.
### HTTP Proxy
You can set the following environment variables if you are behind a proxy: `HTTP_PROXY`, `HTTPS_PROXY` and `NO_PROXY`.
See also [net/http#ProxyFromEnvironment](https://golang.org/pkg/net/http/#ProxyFromEnvironment).
## Contributions
This is an open source software licensed under Apache License 2.0.
+6 -18
View File
@@ -5,10 +5,7 @@ import (
"crypto/x509"
"encoding/base64"
"io/ioutil"
"log"
"net/http"
"net/url"
"os"
"github.com/int128/kubelogin/adaptors/interfaces"
"github.com/pkg/errors"
@@ -27,21 +24,12 @@ func (*HTTP) NewClientConfig() adaptors.HTTPClientConfig {
}
func (*HTTP) NewClient(config adaptors.HTTPClientConfig) (*http.Client, error) {
transport := &http.Transport{}
//TODO: replace with http.ProxyFromEnvironmentURL or go-ieproxy
// https://github.com/int128/kubelogin/issues/31
val, ok := os.LookupEnv("HTTPS_PROXY")
if ok {
proxyURL, err := url.Parse(val)
if err != nil {
log.Printf("HTTPS_PROXY %s cannot be parsed into a URL\n", val)
} else {
transport.Proxy = http.ProxyURL(proxyURL)
}
}
//
transport.TLSClientConfig = config.TLSConfig()
return &http.Client{Transport: transport}, nil
return &http.Client{
Transport: &http.Transport{
TLSClientConfig: config.TLSConfig(),
Proxy: http.ProxyFromEnvironment,
},
}, nil
}
type httpClientConfig struct {