From f9dab52cd578729a55e978e2ed8239c9fd7807ba Mon Sep 17 00:00:00 2001 From: Alex Gartner Date: Fri, 1 Nov 2024 02:48:48 -0700 Subject: [PATCH] chore(e2e): use 2 spaces for yaml (#3070) * e2e: use 2 spaces for yaml * fixes * address feedback --- cmd/zetae2e/init.go | 20 +++++++++++--------- e2e/config/config.go | 15 +++++++++++---- 2 files changed, 22 insertions(+), 13 deletions(-) diff --git a/cmd/zetae2e/init.go b/cmd/zetae2e/init.go index d8dbfd379f..6f98c24102 100644 --- a/cmd/zetae2e/init.go +++ b/cmd/zetae2e/init.go @@ -9,7 +9,7 @@ import ( "github.com/zeta-chain/node/e2e/config" ) -var initConf = config.Config{} +var initConf = config.DefaultConfig() var configFile = "" func NewInitCmd() *cobra.Command { @@ -19,18 +19,20 @@ func NewInitCmd() *cobra.Command { RunE: initConfig, } - InitCmd.Flags().StringVar(&initConf.RPCs.EVM, "ethURL", "http://eth:8545", "--ethURL http://eth:8545") - InitCmd.Flags().StringVar(&initConf.RPCs.ZetaCoreGRPC, "grpcURL", "zetacore0:9090", "--grpcURL zetacore0:9090") + InitCmd.Flags().StringVar(&initConf.RPCs.EVM, "ethURL", initConf.RPCs.EVM, "--ethURL http://eth:8545") InitCmd.Flags(). - StringVar(&initConf.RPCs.ZetaCoreRPC, "rpcURL", "http://zetacore0:26657", "--rpcURL http://zetacore0:26657") + StringVar(&initConf.RPCs.ZetaCoreGRPC, "grpcURL", initConf.RPCs.ZetaCoreGRPC, "--grpcURL zetacore0:9090") InitCmd.Flags(). - StringVar(&initConf.RPCs.Zevm, "zevmURL", "http://zetacore0:8545", "--zevmURL http://zetacore0:8545") - InitCmd.Flags().StringVar(&initConf.RPCs.Bitcoin.Host, "btcURL", "bitcoin:18443", "--grpcURL bitcoin:18443") + StringVar(&initConf.RPCs.ZetaCoreRPC, "rpcURL", initConf.RPCs.ZetaCoreRPC, "--rpcURL http://zetacore0:26657") InitCmd.Flags(). - StringVar(&initConf.RPCs.Solana, "solanaURL", "http://solana:8899", "--solanaURL http://solana:8899") + StringVar(&initConf.RPCs.Zevm, "zevmURL", initConf.RPCs.Zevm, "--zevmURL http://zetacore0:8545") InitCmd.Flags(). - StringVar(&initConf.RPCs.TONSidecarURL, "tonSidecarURL", "http://ton:8000", "--tonSidecarURL http://ton:8000") - InitCmd.Flags().StringVar(&initConf.ZetaChainID, "chainID", "athens_101-1", "--chainID athens_101-1") + StringVar(&initConf.RPCs.Bitcoin.Host, "btcURL", initConf.RPCs.Bitcoin.Host, "--btcURL bitcoin:18443") + InitCmd.Flags(). + StringVar(&initConf.RPCs.Solana, "solanaURL", initConf.RPCs.Solana, "--solanaURL http://solana:8899") + InitCmd.Flags(). + StringVar(&initConf.RPCs.TONSidecarURL, "tonSidecarURL", initConf.RPCs.TONSidecarURL, "--tonSidecarURL http://ton:8000") + InitCmd.Flags().StringVar(&initConf.ZetaChainID, "chainID", initConf.ZetaChainID, "--chainID athens_101-1") InitCmd.Flags().StringVar(&configFile, local.FlagConfigFile, "e2e.config", "--cfg ./e2e.config") return InitCmd diff --git a/e2e/config/config.go b/e2e/config/config.go index 32a799c027..67685b0dd3 100644 --- a/e2e/config/config.go +++ b/e2e/config/config.go @@ -208,13 +208,20 @@ func WriteConfig(file string, config Config) error { return errors.New("file name cannot be empty") } - b, err := yaml.Marshal(config) + // #nosec G304 -- the variable is expected to be controlled by the user + fHandle, err := os.OpenFile(file, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0600) if err != nil { - return err + return fmt.Errorf("open file: %w", err) } - err = os.WriteFile(file, b, 0600) + defer fHandle.Close() + + // use a custom encoder so we can set the indentation level + encoder := yaml.NewEncoder(fHandle) + defer encoder.Close() + encoder.SetIndent(2) + err = encoder.Encode(config) if err != nil { - return err + return fmt.Errorf("encode config: %w", err) } return nil }