Skip to content

Commit

Permalink
Removed proxy parameters. Instead, the environment variables should b…
Browse files Browse the repository at this point in the history
…e used. HTTP_PROXY, HTTPS_PROXY and NO_PROXY
  • Loading branch information
smtakeda committed Dec 1, 2017
1 parent af9bc19 commit 6a62f5a
Show file tree
Hide file tree
Showing 7 changed files with 3 additions and 127 deletions.
14 changes: 3 additions & 11 deletions doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,22 +83,14 @@ The following connection parameters are supported:
Security Certified Professional (OSCP) certificate revocation check.
IMPORTANT: Change the default value for testing or emergency situations only.
*proxyHost: Specifies the host name for the proxy server. The proxy
must be accessible via the URL http://proxyHost:proxyPort/. The
proxyUser and proxyPassword parameters are optional. Note that SSL
proxy configuration is not supported.
* proxyPort: Specifies the port number for the proxy server.
* proxyUser: Specifies the name of the user used to connect to the proxy server.
* proxyPassword: Specifies the password for the user account used to connect to the proxy server.
All other parameters are taken as session parameters. For example, TIMESTAMP_OUTPUT_FORMAT session parameter can be
set by adding:
...&TIMESTAMP_OUTPUT_FORMAT=MM-DD-YYYY...
Proxy
The Go Snowflake Driver honors the environment variables HTTP_PROXY, HTTPS_PROXY and NO_PROXY for the forward proxy setting.
Logging
Expand Down
6 changes: 0 additions & 6 deletions driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,9 @@ func (d SnowflakeDriver) Open(dsn string) (driver.Conn, error) {
// no revocation check with OCSP. Think twice when you want to enable this option.
st = snowflakeInsecureTransport
}
proxyURL, err := proxyURL(proxyHost, proxyPort, proxyUser, proxyPassword)
if err != nil {
return nil, err
}
if proxyURL != nil {
st.Proxy = http.ProxyURL(proxyURL)
glog.V(2).Infof("proxy: %v, %v, %v, %v",
proxyURL.Scheme, proxyURL.Host, proxyURL.Port, proxyURL.User)
}
// authenticate
sc.rest = &snowflakeRestful{
Host: sc.cfg.Host,
Expand Down
13 changes: 0 additions & 13 deletions dsn.go
Original file line number Diff line number Diff line change
Expand Up @@ -409,19 +409,6 @@ func parseDSNParams(cfg *Config, params string) (err error) {
return
}
cfg.InsecureMode = vv
case "proxyHost":
proxyHost = value
case "proxyPort":
var vv int64
vv, err = strconv.ParseInt(value, 10, 64)
if err != nil {
return
}
proxyPort = int(vv)
case "proxyUser":
proxyUser = value
case "proxyPassword":
proxyPassword = value
default:
if cfg.Params == nil {
cfg.Params = make(map[string]*string)
Expand Down
6 changes: 0 additions & 6 deletions ocsp.go
Original file line number Diff line number Diff line change
Expand Up @@ -370,13 +370,7 @@ func getRevocationStatus(wg *sync.WaitGroup, ocspStatusChan chan<- *ocspStatus,
}
glog.V(2).Infof("cache missed: %v\n", ocspValidatedWithCache.err)

proxyURL, _ := proxyURL(proxyHost, proxyPort, proxyUser, proxyPassword)
st := snowflakeInsecureTransport
if proxyURL != nil {
st.Proxy = http.ProxyURL(proxyURL)
glog.V(2).Infof("proxy: %v, %v, %v, %v",
proxyURL.Scheme, proxyURL.Host, proxyURL.Port, proxyURL.User)
}
ocspClient := &http.Client{
Timeout: 30 * time.Second,
Transport: st,
Expand Down
7 changes: 0 additions & 7 deletions restful.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,6 @@ const (
queryInProgressAsyncCode = "333334"
)

var (
proxyHost string
proxyPort int
proxyUser string
proxyPassword string
)

type snowflakeRestful struct {
Host string
Port int
Expand Down
14 changes: 0 additions & 14 deletions util.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ package gosnowflake

import (
"database/sql/driver"
"fmt"
"net/url"
"time"
)

Expand Down Expand Up @@ -49,15 +47,3 @@ func toNamedValues(values []driver.Value) []driver.NamedValue {
}
return namedValues
}

//proxyURL constructs a URL string including proxy info. No https proxy is supported.
func proxyURL(host string, port int, user string, password string) (*url.URL, error) {
if host != "" && port != 0 {
proxyAuth := ""
if user != "" || password != "" {
proxyAuth = fmt.Sprintf("%s:%s@", user, password)
}
return url.Parse(fmt.Sprintf("http://%v%v:%v", proxyAuth, host, port))
}
return nil, nil
}
70 changes: 0 additions & 70 deletions util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ package gosnowflake

import (
"database/sql/driver"
"fmt"
"net/url"
"testing"
"time"
)
Expand Down Expand Up @@ -131,71 +129,3 @@ func TestToNamedValues(t *testing.T) {
}
}
}

type tcProxyURL struct {
proxyHost string
proxyPort int
proxyUser string
proxyPassword string
output *url.URL
err error
}

func TestProxyURL(t *testing.T) {
var genProxyURL = func(urlStr string) *url.URL {
ret, err := url.Parse(urlStr)
if err != nil {
panic(fmt.Sprintf("failed to parse URL: %v", urlStr))
}
return ret
}
testcases := []tcProxyURL{
{
proxyHost: "proxy.host.com",
proxyPort: 123,
output: genProxyURL("http://proxy.host.com:123"),
},
{
proxyHost: "proxy.host.com",
proxyPort: 123,
proxyUser: "u",
proxyPassword: "p",
output: genProxyURL("http://u:[email protected]:123"),
},
{
proxyHost: "proxy.host.com",
proxyPort: 123,
proxyUser: "u",
output: genProxyURL("http://u:@proxy.host.com:123"),
},
{
proxyHost: "proxy.host.com",
output: nil,
},
{
proxyPort: 456,
output: nil,
},
{
output: nil,
},
}
for _, test := range testcases {
a, err := proxyURL(test.proxyHost, test.proxyPort, test.proxyUser, test.proxyPassword)
if err != nil && test.err == nil {
t.Errorf("unexpected error. err: %v, input: %v", err, test)
}
if err == nil && test.err != nil {
t.Errorf("error is expected. err: %v, input: %v", test.err, test)
}
if a == nil && test.output != nil || a != nil && test.output == nil {
t.Errorf("failed to get proxy URL. host: %v, port: %v, user: %v, password: %v, expected: %v, got: %v",
test.proxyHost, test.proxyPort, test.proxyUser, test.proxyPassword, test.output, a)
}

if a != nil && test.output != nil && test.output.String() != a.String() {
t.Errorf("failed to get proxy URL. host: %v, port: %v, user: %v, password: %v, expected: %v, got: %v",
test.proxyHost, test.proxyPort, test.proxyUser, test.proxyPassword, test.output, a)
}
}
}

0 comments on commit 6a62f5a

Please sign in to comment.