Skip to content

Commit 0aa6429

Browse files
committed
Use AddFlagsTLS from helm to add tls cmd options.
1 parent 3ea07d4 commit 0aa6429

File tree

1 file changed

+9
-28
lines changed

1 file changed

+9
-28
lines changed

cmd/helpers.go

Lines changed: 9 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -21,41 +21,22 @@ const (
2121
var (
2222
settings helm_env.EnvSettings
2323
DefaultHelmHome = filepath.Join(homedir.HomeDir(), ".helm")
24-
25-
tlsCaCertFile string // path to TLS CA certificate file
26-
tlsCertFile string // path to TLS certificate file
27-
tlsKeyFile string // path to TLS key file
28-
tlsVerify bool // enable TLS and verify remote certificates
29-
tlsEnable bool // enable TLS
3024
)
3125

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

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

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

45-
if tlsVerify || tlsEnable {
46-
if tlsCaCertFile == "" {
47-
tlsCaCertFile = settings.Home.TLSCaCert()
48-
}
49-
if tlsCertFile == "" {
50-
tlsCertFile = settings.Home.TLSCert()
51-
}
52-
if tlsKeyFile == "" {
53-
tlsKeyFile = settings.Home.TLSKey()
54-
}
55-
56-
tlsopts := tlsutil.Options{KeyFile: tlsKeyFile, CertFile: tlsCertFile, InsecureSkipVerify: true}
57-
if tlsVerify {
58-
tlsopts.CaCertFile = tlsCaCertFile
36+
if settings.TLSVerify || settings.TLSEnable {
37+
tlsopts := tlsutil.Options{KeyFile: settings.TLSKeyFile, CertFile: settings.TLSCertFile, InsecureSkipVerify: true}
38+
if settings.TLSVerify {
39+
tlsopts.CaCertFile = settings.TLSCaCertFile
5940
tlsopts.InsecureSkipVerify = false
6041
}
6142

@@ -72,7 +53,7 @@ func createHelmClient() helm.Interface {
7253
}
7354

7455
func expandTLSPaths() {
75-
tlsCaCertFile = os.ExpandEnv(tlsCaCertFile)
76-
tlsCertFile = os.ExpandEnv(tlsCertFile)
77-
tlsKeyFile = os.ExpandEnv(tlsKeyFile)
56+
settings.TLSCaCertFile = os.ExpandEnv(settings.TLSCaCertFile)
57+
settings.TLSCertFile = os.ExpandEnv(settings.TLSCertFile)
58+
settings.TLSKeyFile = os.ExpandEnv(settings.TLSKeyFile)
7859
}

0 commit comments

Comments
 (0)