From 033a4000914124ab4711cb4e1ae9b7e18450897b Mon Sep 17 00:00:00 2001 From: Kartikay <120778728+kartikaysaxena@users.noreply.github.com> Date: Fri, 10 May 2024 07:24:02 +0000 Subject: [PATCH] added cacert to .litmusconfig Signed-off-by: Kartikay <120778728+kartikaysaxena@users.noreply.github.com> --- pkg/cmd/root/root.go | 15 +++++++++++++++ pkg/types/config_types.go | 1 + 2 files changed, 16 insertions(+) diff --git a/pkg/cmd/root/root.go b/pkg/cmd/root/root.go index d23b7e8f..216f633d 100644 --- a/pkg/cmd/root/root.go +++ b/pkg/cmd/root/root.go @@ -110,6 +110,21 @@ func initConfig() { caCertPool := x509.NewCertPool() caCertPool.AppendCertsFromPEM(caCert) http.DefaultTransport.(*http.Transport).TLSClientConfig = &tls.Config{RootCAs: caCertPool} + } else { + configFilePath := utils.GetLitmusConfigPath(rootCmd) + obj, err := config2.YamltoObject(configFilePath) + cobra.CheckErr(err) + // Check if CACert file string is present in the config file + if obj.CACert != "" { + configFilePath := utils.GetLitmusConfigPath(rootCmd) + obj, err := config2.YamltoObject(configFilePath) + cobra.CheckErr(err) + caCertFile, err := os.ReadFile(obj.CACert) + cobra.CheckErr(err) + caCertPool := x509.NewCertPool() + caCertPool.AppendCertsFromPEM(caCertFile) + http.DefaultTransport.(*http.Transport).TLSClientConfig = &tls.Config{RootCAs: caCertPool} + } } // If a config file is found, read it in. diff --git a/pkg/types/config_types.go b/pkg/types/config_types.go index b1fff53a..b87631d1 100644 --- a/pkg/types/config_types.go +++ b/pkg/types/config_types.go @@ -33,6 +33,7 @@ type LitmuCtlConfig struct { CurrentAccount string `yaml:"current-account" json:"current-account"` CurrentUser string `yaml:"current-user" json:"current-user"` Kind string `yaml:"kind" json:"kind"` + CACert string `yaml:"cacert" json:"cacert"` } type Current struct {