From f194ad59146555582c212cfa808c004acf548f8e Mon Sep 17 00:00:00 2001 From: "Veg (Martin Wellard)" Date: Thu, 15 Dec 2016 14:59:49 -0500 Subject: [PATCH] define SOCKS_PROXY in the environment to use socks. e.g. SOCKS_PROXY=127.0.0.1:6969 --- Makefile | 1 + client/client_impl.go | 21 ++++++++++++++++++--- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index f40359b2..5d4e1bce 100644 --- a/Makefile +++ b/Makefile @@ -17,6 +17,7 @@ deps_frontend: deps_backend: 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/elazarl/go-bindata-assetfs/... go get -u github.com/drone/mq/... diff --git a/client/client_impl.go b/client/client_impl.go index 5f093528..96a16a50 100644 --- a/client/client_impl.go +++ b/client/client_impl.go @@ -9,9 +9,11 @@ import ( "io/ioutil" "net/http" "net/url" + "os" "strconv" "github.com/drone/drone/model" + "golang.org/x/net/proxy" "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}) if c != nil { if trans, ok := auther.Transport.(*oauth2.Transport); ok { - trans.Base = &http.Transport{ - TLSClientConfig: c, - Proxy: http.ProxyFromEnvironment, + 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{ + TLSClientConfig: c, + Proxy: http.ProxyFromEnvironment, + Dial: dialer.Dial, + } + } else { + trans.Base = &http.Transport{ + TLSClientConfig: c, + Proxy: http.ProxyFromEnvironment, + } } } }