Fixed issue with shelly self signed certificate.
This commit is contained in:
+13
-1
@@ -3,6 +3,7 @@ package shelly
|
||||
|
||||
import (
|
||||
"context"
|
||||
"crypto/tls"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
@@ -39,11 +40,22 @@ func NewClient(rawURL, username, password string, timeout time.Duration) (*Clien
|
||||
username: username,
|
||||
password: password,
|
||||
httpClient: &http.Client{
|
||||
Timeout: timeout,
|
||||
Timeout: timeout,
|
||||
Transport: insecureTLSTransport(),
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
|
||||
// insecureTLSTransport retains the standard HTTP transport behavior but accepts
|
||||
// certificates that are expired, self-signed, or issued for another hostname.
|
||||
func insecureTLSTransport() *http.Transport {
|
||||
transport := http.DefaultTransport.(*http.Transport).Clone()
|
||||
transport.TLSClientConfig = &tls.Config{
|
||||
InsecureSkipVerify: true, // #nosec G402 -- Shelly device certificates are intentionally not verified.
|
||||
}
|
||||
return transport
|
||||
}
|
||||
|
||||
// GetStatus decodes the /status response into destination.
|
||||
func (c *Client) GetStatus(ctx context.Context, destination any) error {
|
||||
statusURL := *c.baseURL
|
||||
|
||||
Reference in New Issue
Block a user