Skip to content

Commit d02f6eb

Browse files
committed
support envconfig and insecure
1 parent 438f166 commit d02f6eb

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

tls/tls.go

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,35 @@ import (
88
)
99

1010
type Config struct {
11-
CAFiles []string `mapstructure:"ca_files"`
12-
KeyFile string `mapstructure:"key_file"`
13-
CertFile string `mapstructure:"cert_file"`
11+
CAFiles []string `mapstructure:"ca_files" envconfig:"ca_files"`
12+
KeyFile string `mapstructure:"key_file" split_words:"true"`
13+
CertFile string `mapstructure:"cert_file" split_words:"true"`
1414

1515
Cert string `mapstructure:"cert"`
1616
Key string `mapstructure:"key"`
1717
CA string `mapstructure:"ca"`
18+
19+
Insecure bool `default:"false"`
1820
}
1921

2022
func (cfg Config) TLSConfig() (*tls.Config, error) {
23+
var tlsconf *tls.Config
24+
var err error
2125
if cfg.Cert != "" && cfg.Key != "" {
22-
return LoadFromValues(cfg.Cert, cfg.Key, cfg.CA)
26+
tlsconf, err = LoadFromValues(cfg.Cert, cfg.Key, cfg.CA)
27+
} else if cfg.CertFile != "" && cfg.KeyFile != "" {
28+
tlsconf, err = LoadFromFiles(cfg.CertFile, cfg.KeyFile, cfg.CAFiles)
29+
}
30+
31+
if err != nil {
32+
return nil, err
2333
}
2434

25-
if cfg.CertFile != "" && cfg.KeyFile != "" {
26-
return LoadFromFiles(cfg.CertFile, cfg.KeyFile, cfg.CAFiles)
35+
if tlsconf != nil {
36+
tlsconf.InsecureSkipVerify = cfg.Insecure
2737
}
2838

29-
return nil, nil
39+
return tlsconf, nil
3040
}
3141

3242
func LoadFromValues(certPEM, keyPEM, ca string) (*tls.Config, error) {

0 commit comments

Comments
 (0)