Ignore cert option

This commit is contained in:
Daniel Ponte 2023-02-27 19:06:25 -05:00
parent ae28c4911f
commit a4c37eab08
3 changed files with 19 additions and 4 deletions

5
energyd.yaml.example Normal file
View file

@ -0,0 +1,5 @@
iso:
user: example@example.com
password: fluffy123
# noVerifyCert: false

View file

@ -6,8 +6,9 @@ import (
)
type Conf struct {
ISOUser string
ISOPassword string
ISOUser string
ISOPassword string
NoVerifyCert bool
}
func Config() *Conf {
@ -19,8 +20,13 @@ func Config() *Conf {
panic(fmt.Errorf("fatal error config file: %w", err))
}
noVerifyCert := false
if nVC, exists := viper.Get("iso.noVerifyCert").(bool); exists {
noVerifyCert = nVC
}
return &Conf{
ISOUser: viper.Get("iso.user").(string),
ISOPassword: viper.Get("iso.password").(string),
ISOUser: viper.Get("iso.user").(string),
ISOPassword: viper.Get("iso.password").(string),
NoVerifyCert: noVerifyCert,
}
}

View file

@ -1,6 +1,7 @@
package isoclient
import (
"crypto/tls"
"encoding/json"
"errors"
"fmt"
@ -32,6 +33,9 @@ func New(cfg *config.Conf) Client {
passwd: cfg.ISOPassword,
Debug: os.Getenv("DEBUG") == "true",
}
if cfg.NoVerifyCert {
http.DefaultTransport.(*http.Transport).TLSClientConfig = &tls.Config{InsecureSkipVerify: true}
}
return c
}