Skip to content

Commit

Permalink
Merge pull request letsencrypt#15 from rtreffer/master
Browse files Browse the repository at this point in the history
Make TLS configuration optional
  • Loading branch information
BartVerc authored Jun 30, 2020
2 parents 1739a33 + f86048b commit 9fe40f5
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions unbound_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ func CollectFromSocket(socketFamily string, host string, tlsConfig *tls.Config,
err error
)

if socketFamily == "unix" {
if socketFamily == "unix" || tlsConfig == nil {
conn, err = net.Dial(socketFamily, host)
} else {
conn, err = tls.Dial(socketFamily, host, tlsConfig)
Expand All @@ -383,7 +383,7 @@ func CollectFromSocket(socketFamily string, host string, tlsConfig *tls.Config,
type UnboundExporter struct {
socketFamily string
host string
tlsConfig tls.Config
tlsConfig *tls.Config
}

func NewUnboundExporter(host string, ca string, cert string, key string) (*UnboundExporter, error) {
Expand All @@ -396,7 +396,13 @@ func NewUnboundExporter(host string, ca string, cert string, key string) (*Unbou
return &UnboundExporter{
socketFamily: u.Scheme,
host: u.Path,
tlsConfig: tls.Config{},
}, nil
}

if ca == "" && cert == "" {
return &UnboundExporter{
socketFamily: u.Scheme,
host: u.Host,
}, nil
}

Expand Down Expand Up @@ -426,8 +432,8 @@ func NewUnboundExporter(host string, ca string, cert string, key string) (*Unbou

return &UnboundExporter{
socketFamily: u.Scheme,
host: u.Host,
tlsConfig: tls.Config{
host: u.Host,
tlsConfig: &tls.Config{
Certificates: []tls.Certificate{keyPair},
RootCAs: roots,
ServerName: "unbound",
Expand All @@ -443,7 +449,7 @@ func (e *UnboundExporter) Describe(ch chan<- *prometheus.Desc) {
}

func (e *UnboundExporter) Collect(ch chan<- prometheus.Metric) {
err := CollectFromSocket(e.socketFamily, e.host, &e.tlsConfig, ch)
err := CollectFromSocket(e.socketFamily, e.host, e.tlsConfig, ch)
if err == nil {
ch <- prometheus.MustNewConstMetric(
unboundUpDesc,
Expand Down

0 comments on commit 9fe40f5

Please sign in to comment.