Skip to content

Commit 2b5515f

Browse files
authored
Merge pull request #27 from jagsta/master
allow insecure https connections
2 parents 1230c65 + b30f172 commit 2b5515f

File tree

4 files changed

+25
-11
lines changed

4 files changed

+25
-11
lines changed

README.mkd

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -187,18 +187,21 @@ Usage:
187187
188188
Options:
189189
-u, --ungron Reverse the operation (turn assignments back into JSON)
190+
-c, --colorize Colorize output (default on tty)
190191
-m, --monochrome Monochrome (don't colorize output)
192+
-s, --stream Treat each line of input as a separate JSON object
193+
-k, --insecure Disable certificate validation
191194
--no-sort Don't sort output (faster)
192195
--version Print version information
193196
194197
Exit Codes:
195-
0 OK
196-
1 Failed to open file
197-
2 Failed to read input
198-
3 Failed to form statements
199-
4 Failed to fetch URL
200-
5 Failed to parse statements
201-
6 Failed to encode JSON
198+
0 OK
199+
1 Failed to open file
200+
2 Failed to read input
201+
3 Failed to form statements
202+
4 Failed to fetch URL
203+
5 Failed to parse statements
204+
6 Failed to encode JSON
202205
203206
Examples:
204207
gron /tmp/apiresponse.json

main.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ func init() {
5757
h += " -c, --colorize Colorize output (default on tty)\n"
5858
h += " -m, --monochrome Monochrome (don't colorize output)\n"
5959
h += " -s, --stream Treat each line of input as a separate JSON object\n"
60+
h += " -k, --insecure Disable certificate validation\n"
6061
h += " --no-sort Don't sort output (faster)\n"
6162
h += " --version Print version information\n\n"
6263

@@ -88,6 +89,7 @@ func main() {
8889
streamFlag bool
8990
noSortFlag bool
9091
versionFlag bool
92+
insecureFlag bool
9193
)
9294

9395
flag.BoolVar(&ungronFlag, "ungron", false, "")
@@ -100,6 +102,8 @@ func main() {
100102
flag.BoolVar(&streamFlag, "stream", false, "")
101103
flag.BoolVar(&noSortFlag, "no-sort", false, "")
102104
flag.BoolVar(&versionFlag, "version", false, "")
105+
flag.BoolVar(&insecureFlag, "k", false, "")
106+
flag.BoolVar(&insecureFlag, "insecure", false, "")
103107

104108
flag.Parse()
105109

@@ -123,7 +127,7 @@ func main() {
123127
}
124128
rawInput = r
125129
} else {
126-
r, err := getURL(filename)
130+
r, err := getURL(filename, insecureFlag)
127131
if err != nil {
128132
fatal(exitFetchURL, err)
129133
}

script/lint

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,6 @@ fi
1212

1313
# dupl is disabled because it has a habbit of identifying tests as duplicated code.
1414
# in its defence: it's right. gocyclo is disabled because I'm a terrible programmer.
15-
gometalinter --disable=gocyclo --disable=dupl --enable=mispell --enable=goimports
15+
# gas is disabled because it doesn't like InsecureSkipVerify set to true for HTTP
16+
# requests - but we only do that if the user asks for it.
17+
gometalinter --disable=gocyclo --disable=dupl --enable=goimports --disable=gas

url.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package main
22

33
import (
44
"bufio"
5+
"crypto/tls"
56
"fmt"
67
"io"
78
"net/http"
@@ -14,9 +15,13 @@ func validURL(url string) bool {
1415
return r.MatchString(url)
1516
}
1617

17-
func getURL(url string) (io.Reader, error) {
18+
func getURL(url string, insecure bool) (io.Reader, error) {
19+
tr := &http.Transport{
20+
TLSClientConfig: &tls.Config{InsecureSkipVerify: insecure},
21+
}
1822
client := http.Client{
19-
Timeout: 20 * time.Second,
23+
Transport: tr,
24+
Timeout: 20 * time.Second,
2025
}
2126

2227
req, err := http.NewRequest("GET", url, nil)

0 commit comments

Comments
 (0)