From 14298bfa52baca319f27e19e9d8949fa01bbf082 Mon Sep 17 00:00:00 2001 From: Jay Shirley Date: Thu, 25 Aug 2016 10:27:42 -0700 Subject: [PATCH 1/3] Adding a unixproxy mechanism --- cli.go | 29 +++++++++++++++++++---------- unixproxy.go | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+), 10 deletions(-) create mode 100644 unixproxy.go diff --git a/cli.go b/cli.go index 88f3ef2..fedaeed 100644 --- a/cli.go +++ b/cli.go @@ -43,26 +43,35 @@ func New(opts map[string]interface{}) *Cli { endpoint, _ := opts["endpoint"].(string) url, _ := url.Parse(strings.TrimRight(endpoint, "/")) - transport := &http.Transport{ - TLSClientConfig: &tls.Config{}, - } - if project, ok := opts["project"].(string); ok { opts["project"] = strings.ToUpper(project) } - if insecureSkipVerify, ok := opts["insecure"].(bool); ok { - transport.TLSClientConfig.InsecureSkipVerify = insecureSkipVerify + var ua *http.Client + if unixProxyPath, ok := opts["unixproxy"].(string); ok { + ua = &http.Client{ + Jar: cookieJar, + Transport: UnixProxy(unixProxyPath), + } + } else { + transport := &http.Transport{ + TLSClientConfig: &tls.Config{}, + } + if insecureSkipVerify, ok := opts["insecure"].(bool); ok { + transport.TLSClientConfig.InsecureSkipVerify = insecureSkipVerify + } + + ua = &http.Client{ + Jar: cookieJar, + Transport: transport, + } } cli := &Cli{ endpoint: url, opts: opts, cookieFile: filepath.Join(homedir, ".jira.d", "cookies.js"), - ua: &http.Client{ - Jar: cookieJar, - Transport: transport, - }, + ua: ua, } cli.ua.Jar.SetCookies(url, cli.loadCookies()) diff --git a/unixproxy.go b/unixproxy.go new file mode 100644 index 0000000..1873b8d --- /dev/null +++ b/unixproxy.go @@ -0,0 +1,41 @@ +package jira + +import ( + "fmt" + "net" + "net/http" + "os" + "time" +) + +type Transport struct { + shadow http.Transport +} + +func NewUnixProxyTransport(path string) *Transport { + dial := func(network, addr string) (net.Conn, error) { + return net.Dial("unix", path) + } + + shadow := http.Transport{ + Dial: dial, + DialTLS: dial, + DisableKeepAlives: true, + ResponseHeaderTimeout: 30 * time.Second, + ExpectContinueTimeout: 10 * time.Second, + } + + return &Transport{shadow} +} + +func UnixProxy(path string) *Transport { + return NewUnixProxyTransport(os.ExpandEnv(path)) +} + +func (t *Transport) RoundTrip(req *http.Request) (*http.Response, error) { + req2 := *req + url2 := *req.URL + req2.URL = &url2 + req2.URL.Opaque = fmt.Sprintf("//%s%s", req.URL.Host, req.URL.EscapedPath()) + return t.shadow.RoundTrip(&req2) +} From 8b174625d90628ca7cae1b3e8c05fd186667689e Mon Sep 17 00:00:00 2001 From: Jay Shirley Date: Tue, 20 Sep 2016 06:46:04 -0700 Subject: [PATCH 2/3] Update usage --- main/main.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/main/main.go b/main/main.go index f99e36f..fed6520 100644 --- a/main/main.go +++ b/main/main.go @@ -103,6 +103,7 @@ General Options: -t --template=FILE Template file to use for output/editing -u --user=USER Username to use for authenticaion (default: %s) -v --verbose Increase output logging + --unixproxy=PATH Path for a local unix proxy (for client certificate injection) --version Print version Query Options: @@ -239,6 +240,7 @@ Command Options: "S|saveFile=s": setopt, "T|time-spent=s": setopt, "Q|quiet": setopt, + "unixproxy": setopt, "down": setopt, }) From 01067e859ce8e772019fa9eb3722476bf2d83989 Mon Sep 17 00:00:00 2001 From: Jay Shirley Date: Thu, 22 Sep 2016 18:54:52 -0700 Subject: [PATCH 3/3] Cleaning up usage --- main/main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main/main.go b/main/main.go index fed6520..9014b50 100644 --- a/main/main.go +++ b/main/main.go @@ -103,7 +103,7 @@ General Options: -t --template=FILE Template file to use for output/editing -u --user=USER Username to use for authenticaion (default: %s) -v --verbose Increase output logging - --unixproxy=PATH Path for a local unix proxy (for client certificate injection) + --unixproxy=PATH Path for a unix-socket proxy (eg., --unixproxy /tmp/proxy.sock) --version Print version Query Options: