Add insecure option for TLS endpoints

This gives the option of disabling TLS certificate verification for
the server.

Closes #25
This commit is contained in:
Brian Lalor
2016-01-21 12:30:23 -05:00
parent 6734532719
commit 6a88bb9c00
2 changed files with 15 additions and 1 deletions
+13 -1
View File
@@ -11,6 +11,7 @@ import (
"net/http" "net/http"
"net/http/cookiejar" "net/http/cookiejar"
"net/url" "net/url"
"crypto/tls"
"os" "os"
"os/exec" "os/exec"
"runtime" "runtime"
@@ -36,15 +37,26 @@ func New(opts map[string]interface{}) *Cli {
endpoint, _ := opts["endpoint"].(string) endpoint, _ := opts["endpoint"].(string)
url, _ := url.Parse(strings.TrimRight(endpoint, "/")) url, _ := url.Parse(strings.TrimRight(endpoint, "/"))
transport := &http.Transport{
TLSClientConfig: &tls.Config{},
}
if project, ok := opts["project"].(string); ok { if project, ok := opts["project"].(string); ok {
opts["project"] = strings.ToUpper(project) opts["project"] = strings.ToUpper(project)
} }
if insecureSkipVerify, ok := opts["insecure"].(bool); ok {
transport.TLSClientConfig.InsecureSkipVerify = insecureSkipVerify
}
cli := &Cli{ cli := &Cli{
endpoint: url, endpoint: url,
opts: opts, opts: opts,
cookieFile: fmt.Sprintf("%s/.jira.d/cookies.js", homedir), 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()) cli.ua.Jar.SetCookies(url, cli.loadCookies())
+2
View File
@@ -84,6 +84,7 @@ Usage:
General Options: General Options:
-b --browse Open your browser to the Jira issue -b --browse Open your browser to the Jira issue
-e --endpoint=URI URI to use for jira -e --endpoint=URI URI to use for jira
-k --insecure disable TLS certificate verification
-h --help Show this usage -h --help Show this usage
-t --template=FILE Template file to use for output/editing -t --template=FILE Template file to use for output/editing
-u --user=USER Username to use for authenticaion (default: %s) -u --user=USER Username to use for authenticaion (default: %s)
@@ -185,6 +186,7 @@ Command Options:
"editor=s": setopt, "editor=s": setopt,
"u|user=s": setopt, "u|user=s": setopt,
"endpoint=s": setopt, "endpoint=s": setopt,
"k|insecure": setopt,
"t|template=s": setopt, "t|template=s": setopt,
"q|query=s": setopt, "q|query=s": setopt,
"p|project=s": setopt, "p|project=s": setopt,