From 53344ffe216de39847314b44ff64ad32318e98e0 Mon Sep 17 00:00:00 2001 From: Prarit Bhargava Date: Thu, 13 Jul 2023 13:43:50 -0400 Subject: [PATCH] internal/config/config.go: Do not save config when LAB_CORE_TOKEN is used @doronbehar reported a bug in lab where they specified LAB_CORE_TOKEN on the command line and then value was saved in the config file. Using LAB_CORE_TOKEN or LAB_CORE_HOST should not overwrite the config file. Do not save the config when LAB_CORE_TOKEN or LAB_CORE_HOST is specified. Closes #868 Signed-off-by: Prarit Bhargava --- internal/config/config.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/internal/config/config.go b/internal/config/config.go index bed1d31f..e034c57d 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -73,9 +73,12 @@ func New(confpath string, r io.Reader) error { MainConfig.Set("core.load_token", loadToken) } - if err := MainConfig.WriteConfigAs(confpath); err != nil { - return err + if strings.TrimSpace(os.Getenv("LAB_CORE_TOKEN")) == "" && strings.TrimSpace(os.Getenv("LAB_CORE_HOST")) == "" { + if err := MainConfig.WriteConfigAs(confpath); err != nil { + return err + } } + fmt.Printf("\nConfig saved to %s\n", confpath) err = MainConfig.ReadInConfig() if err != nil {