From 090ce6b6ef47baf9f25c20e7e6f50fb0c252b990 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 | 9 +++++++++ pkg/types/config_types.go | 1 + 2 files changed, 10 insertions(+) diff --git a/pkg/cmd/root/root.go b/pkg/cmd/root/root.go index d23b7e8f..788aaae6 100644 --- a/pkg/cmd/root/root.go +++ b/pkg/cmd/root/root.go @@ -110,6 +110,15 @@ func initConfig() { caCertPool := x509.NewCertPool() caCertPool.AppendCertsFromPEM(caCert) http.DefaultTransport.(*http.Transport).TLSClientConfig = &tls.Config{RootCAs: caCertPool} + } else if config2.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 {