Skip to content

Commit

Permalink
support envconfig and insecure
Browse files Browse the repository at this point in the history
  • Loading branch information
rybit committed Sep 28, 2017
1 parent 438f166 commit d02f6eb
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions tls/tls.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,35 @@ import (
)

type Config struct {
CAFiles []string `mapstructure:"ca_files"`
KeyFile string `mapstructure:"key_file"`
CertFile string `mapstructure:"cert_file"`
CAFiles []string `mapstructure:"ca_files" envconfig:"ca_files"`
KeyFile string `mapstructure:"key_file" split_words:"true"`
CertFile string `mapstructure:"cert_file" split_words:"true"`

Cert string `mapstructure:"cert"`
Key string `mapstructure:"key"`
CA string `mapstructure:"ca"`

Insecure bool `default:"false"`
}

func (cfg Config) TLSConfig() (*tls.Config, error) {
var tlsconf *tls.Config
var err error
if cfg.Cert != "" && cfg.Key != "" {
return LoadFromValues(cfg.Cert, cfg.Key, cfg.CA)
tlsconf, err = LoadFromValues(cfg.Cert, cfg.Key, cfg.CA)
} else if cfg.CertFile != "" && cfg.KeyFile != "" {
tlsconf, err = LoadFromFiles(cfg.CertFile, cfg.KeyFile, cfg.CAFiles)
}

if err != nil {
return nil, err
}

if cfg.CertFile != "" && cfg.KeyFile != "" {
return LoadFromFiles(cfg.CertFile, cfg.KeyFile, cfg.CAFiles)
if tlsconf != nil {
tlsconf.InsecureSkipVerify = cfg.Insecure
}

return nil, nil
return tlsconf, nil
}

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

0 comments on commit d02f6eb

Please sign in to comment.