Skip to content

Commit

Permalink
Set user agent in http requests
Browse files Browse the repository at this point in the history
  • Loading branch information
liggitt committed Sep 12, 2017
1 parent ca32ecd commit 13474f8
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion cmd/audit2rbac/audit2rbac.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"net/http"
"os"
"regexp"
goruntime "runtime"
"strings"
"sync"

Expand Down Expand Up @@ -250,7 +251,15 @@ func openStreams(sources []string) ([]io.ReadCloser, []error) {
client := &http.Client{Transport: &http.Transport{TLSClientConfig: &tls.Config{InsecureSkipVerify: true}}}
for _, source := range sources {
if strings.HasPrefix(source, "http://") || strings.HasPrefix(source, "https://") {
resp, err := client.Get(source)
req, err := http.NewRequest("GET", source, nil)
if err != nil {
errors = append(errors, err)
continue
}

req.Header.Set("User-Agent", "audit2rbac/"+pkg.Version+" "+goruntime.GOOS+"/"+goruntime.GOARCH)

resp, err := client.Do(req)
if err != nil {
errors = append(errors, err)
} else if resp.StatusCode != http.StatusOK {
Expand Down

0 comments on commit 13474f8

Please sign in to comment.