diff --git a/README.mkd b/README.mkd index fb0749b..fdfed80 100644 --- a/README.mkd +++ b/README.mkd @@ -187,18 +187,21 @@ Usage: Options: -u, --ungron Reverse the operation (turn assignments back into JSON) + -c, --colorize Colorize output (default on tty) -m, --monochrome Monochrome (don't colorize output) + -s, --stream Treat each line of input as a separate JSON object + -k, --insecure Disable certificate validation --no-sort Don't sort output (faster) --version Print version information Exit Codes: - 0 OK - 1 Failed to open file - 2 Failed to read input - 3 Failed to form statements - 4 Failed to fetch URL - 5 Failed to parse statements - 6 Failed to encode JSON + 0 OK + 1 Failed to open file + 2 Failed to read input + 3 Failed to form statements + 4 Failed to fetch URL + 5 Failed to parse statements + 6 Failed to encode JSON Examples: gron /tmp/apiresponse.json diff --git a/main.go b/main.go index b44f29a..7a5dfb0 100644 --- a/main.go +++ b/main.go @@ -57,6 +57,7 @@ func init() { h += " -c, --colorize Colorize output (default on tty)\n" h += " -m, --monochrome Monochrome (don't colorize output)\n" h += " -s, --stream Treat each line of input as a separate JSON object\n" + h += " -k, --insecure Disable certificate validation\n" h += " --no-sort Don't sort output (faster)\n" h += " --version Print version information\n\n" @@ -88,6 +89,7 @@ func main() { streamFlag bool noSortFlag bool versionFlag bool + insecureFlag bool ) flag.BoolVar(&ungronFlag, "ungron", false, "") @@ -100,6 +102,8 @@ func main() { flag.BoolVar(&streamFlag, "stream", false, "") flag.BoolVar(&noSortFlag, "no-sort", false, "") flag.BoolVar(&versionFlag, "version", false, "") + flag.BoolVar(&insecureFlag, "k", false, "") + flag.BoolVar(&insecureFlag, "insecure", false, "") flag.Parse() @@ -123,7 +127,7 @@ func main() { } rawInput = r } else { - r, err := getURL(filename) + r, err := getURL(filename, insecureFlag) if err != nil { fatal(exitFetchURL, err) } diff --git a/script/lint b/script/lint index f3fad8d..700198b 100755 --- a/script/lint +++ b/script/lint @@ -12,4 +12,6 @@ fi # dupl is disabled because it has a habbit of identifying tests as duplicated code. # in its defence: it's right. gocyclo is disabled because I'm a terrible programmer. -gometalinter --disable=gocyclo --disable=dupl --enable=mispell --enable=goimports +# gas is disabled because it doesn't like InsecureSkipVerify set to true for HTTP +# requests - but we only do that if the user asks for it. +gometalinter --disable=gocyclo --disable=dupl --enable=goimports --disable=gas diff --git a/url.go b/url.go index 90d7b8e..a2e10f9 100644 --- a/url.go +++ b/url.go @@ -2,6 +2,7 @@ package main import ( "bufio" + "crypto/tls" "fmt" "io" "net/http" @@ -14,9 +15,13 @@ func validURL(url string) bool { return r.MatchString(url) } -func getURL(url string) (io.Reader, error) { +func getURL(url string, insecure bool) (io.Reader, error) { + tr := &http.Transport{ + TLSClientConfig: &tls.Config{InsecureSkipVerify: insecure}, + } client := http.Client{ - Timeout: 20 * time.Second, + Transport: tr, + Timeout: 20 * time.Second, } req, err := http.NewRequest("GET", url, nil)