Skip to content

Commit

Permalink
Merge pull request #109 from cgroschupp/feature/use_helm_tls_flags
Browse files Browse the repository at this point in the history
Use AddFlagsTLS from helm to add tls cmd options.
  • Loading branch information
databus23 authored Jan 14, 2019
2 parents 3ea07d4 + 4865b31 commit cf19eeb
Showing 1 changed file with 13 additions and 26 deletions.
39 changes: 13 additions & 26 deletions cmd/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,41 +21,28 @@ const (
var (
settings helm_env.EnvSettings
DefaultHelmHome = filepath.Join(homedir.HomeDir(), ".helm")

tlsCaCertFile string // path to TLS CA certificate file
tlsCertFile string // path to TLS certificate file
tlsKeyFile string // path to TLS key file
tlsVerify bool // enable TLS and verify remote certificates
tlsEnable bool // enable TLS
)

func addCommonCmdOptions(f *flag.FlagSet) {
f.StringVar(&tlsCaCertFile, "tls-ca-cert", tlsCaCertDefault, "path to TLS CA certificate file")
f.StringVar(&tlsCertFile, "tls-cert", tlsCertDefault, "path to TLS certificate file")
f.StringVar(&tlsKeyFile, "tls-key", tlsKeyDefault, "path to TLS key file")
f.BoolVar(&tlsVerify, "tls-verify", false, "enable TLS for request and verify remote")
f.BoolVar(&tlsEnable, "tls", false, "enable TLS for request")
settings.AddFlagsTLS(f)
settings.InitTLS(f)

f.StringVar((*string)(&settings.Home), "home", DefaultHelmHome, "location of your Helm config. Overrides $HELM_HOME")
}

func createHelmClient() helm.Interface {
options := []helm.Option{helm.Host(os.Getenv("TILLER_HOST")), helm.ConnectTimeout(int64(30))}

if tlsVerify || tlsEnable {
if tlsCaCertFile == "" {
tlsCaCertFile = settings.Home.TLSCaCert()
}
if tlsCertFile == "" {
tlsCertFile = settings.Home.TLSCert()
}
if tlsKeyFile == "" {
tlsKeyFile = settings.Home.TLSKey()
if settings.TLSVerify || settings.TLSEnable {
tlsopts := tlsutil.Options{
ServerName: settings.TLSServerName,
KeyFile: settings.TLSKeyFile,
CertFile: settings.TLSCertFile,
InsecureSkipVerify: true,
}

tlsopts := tlsutil.Options{KeyFile: tlsKeyFile, CertFile: tlsCertFile, InsecureSkipVerify: true}
if tlsVerify {
tlsopts.CaCertFile = tlsCaCertFile
if settings.TLSVerify {
tlsopts.CaCertFile = settings.TLSCaCertFile
tlsopts.InsecureSkipVerify = false
}

Expand All @@ -72,7 +59,7 @@ func createHelmClient() helm.Interface {
}

func expandTLSPaths() {
tlsCaCertFile = os.ExpandEnv(tlsCaCertFile)
tlsCertFile = os.ExpandEnv(tlsCertFile)
tlsKeyFile = os.ExpandEnv(tlsKeyFile)
settings.TLSCaCertFile = os.ExpandEnv(settings.TLSCaCertFile)
settings.TLSCertFile = os.ExpandEnv(settings.TLSCertFile)
settings.TLSKeyFile = os.ExpandEnv(settings.TLSKeyFile)
}

0 comments on commit cf19eeb

Please sign in to comment.