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 {