@@ -8,25 +8,35 @@ import (
8
8
)
9
9
10
10
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" `
14
14
15
15
Cert string `mapstructure:"cert"`
16
16
Key string `mapstructure:"key"`
17
17
CA string `mapstructure:"ca"`
18
+
19
+ Insecure bool `default:"false"`
18
20
}
19
21
20
22
func (cfg Config ) TLSConfig () (* tls.Config , error ) {
23
+ var tlsconf * tls.Config
24
+ var err error
21
25
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
23
33
}
24
34
25
- if cfg . CertFile != "" && cfg . KeyFile != "" {
26
- return LoadFromFiles ( cfg . CertFile , cfg . KeyFile , cfg .CAFiles )
35
+ if tlsconf != nil {
36
+ tlsconf . InsecureSkipVerify = cfg .Insecure
27
37
}
28
38
29
- return nil , nil
39
+ return tlsconf , nil
30
40
}
31
41
32
42
func LoadFromValues (certPEM , keyPEM , ca string ) (* tls.Config , error ) {
0 commit comments