Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for using socks proxy #130

Merged
merged 1 commit into from
Nov 2, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions jiracli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ type GlobalOptions struct {
PasswordSource figtree.StringOption `yaml:"password-source,omitempty" json:"password-source,omitempty"`
Quiet figtree.BoolOption `yaml:"quiet,omitempty" json:"quiet,omitempty"`
UnixProxy figtree.StringOption `yaml:"unixproxy,omitempty" json:"unixproxy,omitempty"`
SocksProxy figtree.StringOption `yaml:"socksproxy,omitempty" json:"socksproxy,omitempty"`
User figtree.StringOption `yaml:"user,omitempty" json:"user,omitempty"`
}

Expand Down Expand Up @@ -73,6 +74,7 @@ func Register(app *kingpin.Application, o *oreo.Client, fig *figtree.FigTree, re
app.Flag("insecure", "Disable TLS certificate verification").Short('k').SetValue(&globals.Insecure)
app.Flag("quiet", "Suppress output to console").Short('Q').SetValue(&globals.Quiet)
app.Flag("unixproxy", "Path for a unix-socket proxy").SetValue(&globals.UnixProxy)
app.Flag("socksproxy", "Address for a socks proxy").SetValue(&globals.SocksProxy)
app.Flag("user", "Login name used for authentication with Jira service").Short('u').SetValue(&globals.User)

app.PreAction(func(_ *kingpin.ParseContext) error {
Expand All @@ -87,6 +89,8 @@ func Register(app *kingpin.Application, o *oreo.Client, fig *figtree.FigTree, re
}
if globals.UnixProxy.Value != "" {
o = o.WithTransport(unixProxy(globals.UnixProxy.Value))
} else if globals.SocksProxy.Value != "" {
o = o.WithTransport(socksProxy(globals.SocksProxy.Value))
}
return nil
})
Expand Down
31 changes: 31 additions & 0 deletions jiracli/socksproxy.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package jiracli

import (
"net"
"net/http"
"time"

"golang.org/x/net/proxy"
)

func socksProxy(address string) *http.Transport {
return newSocksProxyTransport(address)
}

func newSocksProxyTransport(address string) *http.Transport {
dialer, err := proxy.SOCKS5("tcp", address, nil, proxy.Direct)
if err != nil {
// TODO: whoops, return error?
panic(err)
}
dial := func(network, addr string) (net.Conn, error) {
return dialer.Dial(network, addr)
}

return &http.Transport{
Dial: dial,
DisableKeepAlives: true,
ResponseHeaderTimeout: 30 * time.Second,
ExpectContinueTimeout: 10 * time.Second,
}
}