define SOCKS_PROXY in the environment to use socks.

e.g. SOCKS_PROXY=127.0.0.1:6969
This commit is contained in:
Veg (Martin Wellard) 2016-12-15 14:59:49 -05:00
parent 24ea9db99a
commit 64c6b2d7d0
2 changed files with 19 additions and 3 deletions

View file

@ -17,6 +17,7 @@ deps_frontend:
deps_backend: deps_backend:
go get -u golang.org/x/tools/cmd/cover go get -u golang.org/x/tools/cmd/cover
go get -u golang.org/x/net/proxy
go get -u github.com/jteeuwen/go-bindata/... go get -u github.com/jteeuwen/go-bindata/...
go get -u github.com/elazarl/go-bindata-assetfs/... go get -u github.com/elazarl/go-bindata-assetfs/...
go get -u github.com/drone/mq/... go get -u github.com/drone/mq/...

View file

@ -9,9 +9,11 @@ import (
"io/ioutil" "io/ioutil"
"net/http" "net/http"
"net/url" "net/url"
"os"
"strconv" "strconv"
"github.com/drone/drone/model" "github.com/drone/drone/model"
"golang.org/x/net/proxy"
"golang.org/x/oauth2" "golang.org/x/oauth2"
) )
@ -76,9 +78,22 @@ func NewClientTokenTLS(uri, token string, c *tls.Config) Client {
auther := config.Client(oauth2.NoContext, &oauth2.Token{AccessToken: token}) auther := config.Client(oauth2.NoContext, &oauth2.Token{AccessToken: token})
if c != nil { if c != nil {
if trans, ok := auther.Transport.(*oauth2.Transport); ok { if trans, ok := auther.Transport.(*oauth2.Transport); ok {
if os.Getenv("SOCKS_PROXY") != "" {
dialer, err := proxy.SOCKS5("tcp", os.Getenv("SOCKS_PROXY"), nil, proxy.Direct)
if err != nil {
fmt.Fprintln(os.Stderr, "can't connect to the proxy:", err)
os.Exit(1)
}
trans.Base = &http.Transport{ trans.Base = &http.Transport{
TLSClientConfig: c, TLSClientConfig: c,
Proxy: http.ProxyFromEnvironment, Proxy: http.ProxyFromEnvironment,
Dial: dialer.Dial,
}
} else {
trans.Base = &http.Transport{
TLSClientConfig: c,
Proxy: http.ProxyFromEnvironment,
}
} }
} }
} }