Skip to content

Commit

Permalink
Merge pull request #27 from jagsta/master
Browse files Browse the repository at this point in the history
allow insecure https connections
  • Loading branch information
tomnomnom authored Feb 22, 2017
2 parents 1230c65 + b30f172 commit 2b5515f
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 11 deletions.
17 changes: 10 additions & 7 deletions README.mkd
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -88,6 +89,7 @@ func main() {
streamFlag bool
noSortFlag bool
versionFlag bool
insecureFlag bool
)

flag.BoolVar(&ungronFlag, "ungron", false, "")
Expand All @@ -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()

Expand All @@ -123,7 +127,7 @@ func main() {
}
rawInput = r
} else {
r, err := getURL(filename)
r, err := getURL(filename, insecureFlag)
if err != nil {
fatal(exitFetchURL, err)
}
Expand Down
4 changes: 3 additions & 1 deletion script/lint
Original file line number Diff line number Diff line change
Expand Up @@ -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
9 changes: 7 additions & 2 deletions url.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"bufio"
"crypto/tls"
"fmt"
"io"
"net/http"
Expand All @@ -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)
Expand Down

0 comments on commit 2b5515f

Please sign in to comment.