From 6a88bb9c008fda37f8a986af6da0af35a89c60ea Mon Sep 17 00:00:00 2001 From: Brian Lalor Date: Thu, 21 Jan 2016 12:30:23 -0500 Subject: [PATCH] Add insecure option for TLS endpoints This gives the option of disabling TLS certificate verification for the server. Closes #25 --- cli.go | 14 +++++++++++++- main/main.go | 2 ++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/cli.go b/cli.go index 54d0fb76..2c988641 100644 --- a/cli.go +++ b/cli.go @@ -11,6 +11,7 @@ import ( "net/http" "net/http/cookiejar" "net/url" + "crypto/tls" "os" "os/exec" "runtime" @@ -36,15 +37,26 @@ 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 + } cli := &Cli{ endpoint: url, opts: opts, cookieFile: fmt.Sprintf("%s/.jira.d/cookies.js", homedir), - ua: &http.Client{Jar: cookieJar}, + ua: &http.Client{ + Jar: cookieJar, + Transport: transport, + }, } cli.ua.Jar.SetCookies(url, cli.loadCookies()) diff --git a/main/main.go b/main/main.go index 4821320b..bc5504f8 100644 --- a/main/main.go +++ b/main/main.go @@ -84,6 +84,7 @@ Usage: General Options: -b --browse Open your browser to the Jira issue -e --endpoint=URI URI to use for jira + -k --insecure disable TLS certificate verification -h --help Show this usage -t --template=FILE Template file to use for output/editing -u --user=USER Username to use for authenticaion (default: %s) @@ -185,6 +186,7 @@ Command Options: "editor=s": setopt, "u|user=s": setopt, "endpoint=s": setopt, + "k|insecure": setopt, "t|template=s": setopt, "q|query=s": setopt, "p|project=s": setopt,