Skip to content

Commit

Permalink
Allow trusting self-signed certificates
Browse files Browse the repository at this point in the history
  • Loading branch information
andig committed May 2, 2020
1 parent 60c4610 commit eeef3f1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -353,6 +353,7 @@ uri: https://volkszaehler/api/data/<uuid>.json?from=now
method: GET # default HTTP method
headers:
- content-type: application/json
insecure: false # set to true to trust self-signed certificates
jq: .data.tuples[0][1] # parse response json
scale: 0.001 # floating point factor applied to result, e.g. for kW to W conversion
```
Expand Down
9 changes: 9 additions & 0 deletions provider/http.go
@@ -1,6 +1,7 @@
package provider

import (
"crypto/tls"
"fmt"
"io"
"math"
Expand Down Expand Up @@ -32,6 +33,7 @@ func NewHTTPProviderFromConfig(log *util.Logger, other map[string]interface{}) *
Body string
Jq string
Scale float64
Insecure bool
}{}
util.DecodeOther(log, other, &cc)

Expand All @@ -47,6 +49,13 @@ func NewHTTPProviderFromConfig(log *util.Logger, other map[string]interface{}) *
scale: cc.Scale,
}

// ignore the self signed certificate
if cc.Insecure {
customTransport := http.DefaultTransport.(*http.Transport).Clone()
customTransport.TLSClientConfig = &tls.Config{InsecureSkipVerify: true}
p.HTTPHelper.Client.Transport = customTransport
}

if cc.Jq != "" {
op, err := gojq.Parse(cc.Jq)
if err != nil {
Expand Down

0 comments on commit eeef3f1

Please sign in to comment.