From 451683bc83be81ab77613dcd3b65399379ad9a15 Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Wed, 17 Jul 2024 12:46:13 +0200 Subject: [PATCH] fix(client/v2): use (PREFIX)_HOME instead of NODE_HOME (backport #20964) (#20970) Co-authored-by: Julien Robert --- client/v2/CHANGELOG.md | 6 ++++++ client/v2/helpers/home.go | 18 +++++++++++++++--- docs/docs/learn/advanced/07-cli.md | 2 +- simapp/go.mod | 2 +- simapp/go.sum | 4 ++-- simapp/simd/main.go | 3 ++- tests/go.mod | 2 +- tests/go.sum | 4 ++-- 8 files changed, 30 insertions(+), 11 deletions(-) diff --git a/client/v2/CHANGELOG.md b/client/v2/CHANGELOG.md index d90d47e16157..ed2ef30195a8 100644 --- a/client/v2/CHANGELOG.md +++ b/client/v2/CHANGELOG.md @@ -36,6 +36,12 @@ Ref: https://keepachangelog.com/en/1.0.0/ ## [Unreleased] +## [v2.0.0-beta.4] - 2024-07-16 + +### Bug Fixes + +* [#20964](https://github.com/cosmos/cosmos-sdk/pull/20964) Fix `GetNodeHomeDirectory` helper in `client/v2/helpers` to respect the `(PREFIX)_HOME` environment variable. + ## [v2.0.0-beta.3] - 2024-07-15 ### Features diff --git a/client/v2/helpers/home.go b/client/v2/helpers/home.go index f62ff30490e9..af3fc2886673 100644 --- a/client/v2/helpers/home.go +++ b/client/v2/helpers/home.go @@ -6,8 +6,13 @@ import ( "strings" ) +// EnvPrefix is the prefix for environment variables that are used by the CLI. +// It should match the one used for viper in the CLI. +var EnvPrefix = "" + // GetNodeHomeDirectory gets the home directory of the node (where the config is located). -// It parses the home flag if set if the `NODE_HOME` environment variable if set (and ignores name). +// It parses the home flag if set if the `(PREFIX)_HOME` environment variable if set (and ignores name). +// When no prefix is set, it reads the `NODE_HOME` environment variable. // Otherwise, it returns the default home directory given its name. func GetNodeHomeDirectory(name string) (string, error) { // get the home directory from the flag @@ -21,12 +26,19 @@ func GetNodeHomeDirectory(name string) (string, error) { } // get the home directory from the environment variable - homeDir := os.Getenv("NODE_HOME") + // to not clash with the $HOME system variable, when no prefix is set + // we check the NODE_HOME environment variable + homeDir, envHome := "", "HOME" + if len(EnvPrefix) > 0 { + homeDir = os.Getenv(EnvPrefix + "_" + envHome) + } else { + homeDir = os.Getenv("NODE_" + envHome) + } if homeDir != "" { return filepath.Clean(homeDir), nil } - // return the default home directory + // get user home directory userHomeDir, err := os.UserHomeDir() if err != nil { return "", err diff --git a/docs/docs/learn/advanced/07-cli.md b/docs/docs/learn/advanced/07-cli.md index 3ee93c0524e0..1420f2e1abc4 100644 --- a/docs/docs/learn/advanced/07-cli.md +++ b/docs/docs/learn/advanced/07-cli.md @@ -163,7 +163,7 @@ this will be more convenient: ```shell # define env variables in .env, .envrc etc -NODE_HOME= +GAIA_HOME= GAIA_NODE= GAIA_CHAIN_ID="testchain-1" GAIA_KEYRING_BACKEND="test" diff --git a/simapp/go.mod b/simapp/go.mod index a0c7b9e852d7..4df33c0d30d2 100644 --- a/simapp/go.mod +++ b/simapp/go.mod @@ -4,7 +4,7 @@ go 1.21 require ( cosmossdk.io/api v0.7.5 - cosmossdk.io/client/v2 v2.0.0-beta.3 + cosmossdk.io/client/v2 v2.0.0-beta.3.0.20240716154125-8a925498285e cosmossdk.io/collections v0.4.0 // indirect cosmossdk.io/core v0.11.0 cosmossdk.io/depinject v1.0.0-alpha.4 diff --git a/simapp/go.sum b/simapp/go.sum index 029116fb2514..dae09fcd4661 100644 --- a/simapp/go.sum +++ b/simapp/go.sum @@ -186,8 +186,8 @@ cloud.google.com/go/workflows v1.6.0/go.mod h1:6t9F5h/unJz41YqfBmqSASJSXccBLtD1V cloud.google.com/go/workflows v1.7.0/go.mod h1:JhSrZuVZWuiDfKEFxU0/F1PQjmpnpcoISEXH2bcHC3M= cosmossdk.io/api v0.7.5 h1:eMPTReoNmGUm8DeiQL9DyM8sYDjEhWzL1+nLbI9DqtQ= cosmossdk.io/api v0.7.5/go.mod h1:IcxpYS5fMemZGqyYtErK7OqvdM0C8kdW3dq8Q/XIG38= -cosmossdk.io/client/v2 v2.0.0-beta.3 h1:+TTuH0DwQYsUq2JFAl3fDZzKq5gQG7nt3dAattkjFDU= -cosmossdk.io/client/v2 v2.0.0-beta.3/go.mod h1:CZcL41HpJPOOayTCO28j8weNBQprG+SRiKX39votypo= +cosmossdk.io/client/v2 v2.0.0-beta.3.0.20240716154125-8a925498285e h1:hgYQOnWslxL8xyk93aqPNdFauHt9nOpmp/aGyzJMcsQ= +cosmossdk.io/client/v2 v2.0.0-beta.3.0.20240716154125-8a925498285e/go.mod h1:c753d0sBv3AQRx6X+BOKL1aGpKjZMTZAHGiLPbVi5TE= cosmossdk.io/collections v0.4.0 h1:PFmwj2W8szgpD5nOd8GWH6AbYNi1f2J6akWXJ7P5t9s= cosmossdk.io/collections v0.4.0/go.mod h1:oa5lUING2dP+gdDquow+QjlF45eL1t4TJDypgGd+tv0= cosmossdk.io/core v0.11.0 h1:vtIafqUi+1ZNAE/oxLOQQ7Oek2n4S48SWLG8h/+wdbo= diff --git a/simapp/simd/main.go b/simapp/simd/main.go index 9643af43bc80..4e7549b21411 100644 --- a/simapp/simd/main.go +++ b/simapp/simd/main.go @@ -4,6 +4,7 @@ import ( "fmt" "os" + clientv2helpers "cosmossdk.io/client/v2/helpers" "cosmossdk.io/simapp" "cosmossdk.io/simapp/simd/cmd" @@ -12,7 +13,7 @@ import ( func main() { rootCmd := cmd.NewRootCmd() - if err := svrcmd.Execute(rootCmd, "", simapp.DefaultNodeHome); err != nil { + if err := svrcmd.Execute(rootCmd, clientv2helpers.EnvPrefix, simapp.DefaultNodeHome); err != nil { fmt.Fprintln(rootCmd.OutOrStderr(), err) os.Exit(1) } diff --git a/tests/go.mod b/tests/go.mod index 1d6840e3569c..1744542ef620 100644 --- a/tests/go.mod +++ b/tests/go.mod @@ -37,7 +37,7 @@ require ( cloud.google.com/go/compute/metadata v0.2.3 // indirect cloud.google.com/go/iam v1.1.6 // indirect cloud.google.com/go/storage v1.38.0 // indirect - cosmossdk.io/client/v2 v2.0.0-beta.3 // indirect + cosmossdk.io/client/v2 v2.0.0-beta.3.0.20240716154125-8a925498285e // indirect cosmossdk.io/collections v0.4.0 // indirect cosmossdk.io/x/circuit v0.1.1 // indirect filippo.io/edwards25519 v1.0.0 // indirect diff --git a/tests/go.sum b/tests/go.sum index bd7e57db7e8b..e9e89cb70781 100644 --- a/tests/go.sum +++ b/tests/go.sum @@ -186,8 +186,8 @@ cloud.google.com/go/workflows v1.6.0/go.mod h1:6t9F5h/unJz41YqfBmqSASJSXccBLtD1V cloud.google.com/go/workflows v1.7.0/go.mod h1:JhSrZuVZWuiDfKEFxU0/F1PQjmpnpcoISEXH2bcHC3M= cosmossdk.io/api v0.7.5 h1:eMPTReoNmGUm8DeiQL9DyM8sYDjEhWzL1+nLbI9DqtQ= cosmossdk.io/api v0.7.5/go.mod h1:IcxpYS5fMemZGqyYtErK7OqvdM0C8kdW3dq8Q/XIG38= -cosmossdk.io/client/v2 v2.0.0-beta.3 h1:+TTuH0DwQYsUq2JFAl3fDZzKq5gQG7nt3dAattkjFDU= -cosmossdk.io/client/v2 v2.0.0-beta.3/go.mod h1:CZcL41HpJPOOayTCO28j8weNBQprG+SRiKX39votypo= +cosmossdk.io/client/v2 v2.0.0-beta.3.0.20240716154125-8a925498285e h1:hgYQOnWslxL8xyk93aqPNdFauHt9nOpmp/aGyzJMcsQ= +cosmossdk.io/client/v2 v2.0.0-beta.3.0.20240716154125-8a925498285e/go.mod h1:c753d0sBv3AQRx6X+BOKL1aGpKjZMTZAHGiLPbVi5TE= cosmossdk.io/collections v0.4.0 h1:PFmwj2W8szgpD5nOd8GWH6AbYNi1f2J6akWXJ7P5t9s= cosmossdk.io/collections v0.4.0/go.mod h1:oa5lUING2dP+gdDquow+QjlF45eL1t4TJDypgGd+tv0= cosmossdk.io/core v0.11.0 h1:vtIafqUi+1ZNAE/oxLOQQ7Oek2n4S48SWLG8h/+wdbo=