mirror of
https://github.com/weaveworks/scope.git
synced 2026-03-06 11:41:28 +00:00
Merge pull request #596 from weaveworks/ssl-hostname-verify
pass the hostname through to xfer.HttpPublisher, so we can verify ssl certs
This commit is contained in:
@@ -23,7 +23,7 @@ func main() {
|
||||
)
|
||||
flag.Parse()
|
||||
|
||||
_, publisher, err := xfer.NewHTTPPublisher(*publish, "demoprobe", "demoprobe", false)
|
||||
_, publisher, err := xfer.NewHTTPPublisher(*publish, *publish, "demoprobe", "demoprobe", false)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ func main() {
|
||||
}
|
||||
f.Close()
|
||||
|
||||
_, publisher, err := xfer.NewHTTPPublisher(*publish, "fixprobe", "fixprobe", false)
|
||||
_, publisher, err := xfer.NewHTTPPublisher(*publish, *publish, "fixprobe", "fixprobe", false)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
@@ -90,8 +90,8 @@ func main() {
|
||||
}
|
||||
log.Printf("publishing to: %s", strings.Join(targets, ", "))
|
||||
|
||||
factory := func(endpoint string) (string, xfer.Publisher, error) {
|
||||
id, publisher, err := xfer.NewHTTPPublisher(endpoint, *token, probeID, *insecure)
|
||||
factory := func(hostname, endpoint string) (string, xfer.Publisher, error) {
|
||||
id, publisher, err := xfer.NewHTTPPublisher(hostname, endpoint, *token, probeID, *insecure)
|
||||
if err != nil {
|
||||
return "", nil, err
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"net"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
@@ -21,27 +22,33 @@ type HTTPPublisher struct {
|
||||
client *http.Client
|
||||
}
|
||||
|
||||
func getHTTPTransport(insecure bool) (*http.Transport, error) {
|
||||
func getHTTPTransport(hostname string, insecure bool) (*http.Transport, error) {
|
||||
if insecure {
|
||||
return &http.Transport{
|
||||
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
|
||||
}, nil
|
||||
}
|
||||
|
||||
host, _, err := net.SplitHostPort(hostname)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
certPool, err := gocertifi.CACerts()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &http.Transport{
|
||||
TLSClientConfig: &tls.Config{
|
||||
RootCAs: certPool,
|
||||
RootCAs: certPool,
|
||||
ServerName: host,
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
|
||||
// NewHTTPPublisher returns an HTTPPublisher ready for use.
|
||||
func NewHTTPPublisher(target, token, probeID string, insecure bool) (string, *HTTPPublisher, error) {
|
||||
httpTransport, err := getHTTPTransport(insecure)
|
||||
func NewHTTPPublisher(hostname, target, token, probeID string, insecure bool) (string, *HTTPPublisher, error) {
|
||||
httpTransport, err := getHTTPTransport(hostname, insecure)
|
||||
if err != nil {
|
||||
return "", nil, err
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"net/url"
|
||||
"reflect"
|
||||
"strings"
|
||||
"testing"
|
||||
@@ -67,7 +68,11 @@ func TestHTTPPublisher(t *testing.T) {
|
||||
s := httptest.NewServer(handlers.CompressHandler(handler))
|
||||
defer s.Close()
|
||||
|
||||
_, p, err := xfer.NewHTTPPublisher(s.URL, token, id, false)
|
||||
u, err := url.Parse(s.URL)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
_, p, err := xfer.NewHTTPPublisher(u.Host, s.URL, token, id, false)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
@@ -14,13 +14,13 @@ import (
|
||||
// targets. See documentation of each method to understand the semantics.
|
||||
type MultiPublisher struct {
|
||||
mtx sync.Mutex
|
||||
factory func(endpoint string) (string, Publisher, error)
|
||||
factory func(hostname, endpoint string) (string, Publisher, error)
|
||||
sema semaphore
|
||||
list []tuple
|
||||
}
|
||||
|
||||
// NewMultiPublisher returns a new MultiPublisher ready for use.
|
||||
func NewMultiPublisher(factory func(endpoint string) (string, Publisher, error)) *MultiPublisher {
|
||||
func NewMultiPublisher(factory func(hostname, endpoint string) (string, Publisher, error)) *MultiPublisher {
|
||||
return &MultiPublisher{
|
||||
factory: factory,
|
||||
sema: newSemaphore(maxConcurrentGET),
|
||||
@@ -49,7 +49,7 @@ func (p *MultiPublisher) Set(target string, endpoints []string) {
|
||||
go func(endpoint string) {
|
||||
p.sema.p()
|
||||
defer p.sema.v()
|
||||
id, publisher, err := p.factory(endpoint)
|
||||
id, publisher, err := p.factory(target, endpoint)
|
||||
c <- tuple{publisher, target, endpoint, id, err}
|
||||
}(endpoint)
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ func TestMultiPublisher(t *testing.T) {
|
||||
|
||||
sum := func() int { return a1.count + a2.count + b2.count + b3.count }
|
||||
|
||||
mp := xfer.NewMultiPublisher(func(endpoint string) (string, xfer.Publisher, error) {
|
||||
mp := xfer.NewMultiPublisher(func(hostname, endpoint string) (string, xfer.Publisher, error) {
|
||||
switch endpoint {
|
||||
case "a1":
|
||||
return "1", a1, nil
|
||||
|
||||
Reference in New Issue
Block a user