Skip to content

Commit

Permalink
fix(services): allow tilde and env in config validator home path (bac…
Browse files Browse the repository at this point in the history
…kport #4532) (#4539)

* fix(services): allow tilde and env in config validator home path (#4532)

* fix(services): allow tilde and env in config validator home path

* updates

* up

(cherry picked from commit ff663c9)

# Conflicts:
#	ignite/config/chain/v1/validator.go
#	ignite/services/chain/chain.go
#	ignite/templates/app/files/go.mod.plush
#	ignite/templates/typed/simulation.go

* conflicts

---------

Co-authored-by: Julien Robert <julien@rbrt.fr>
  • Loading branch information
mergify[bot] and julienrbrt authored Feb 24, 2025
1 parent f10bf3c commit e4be28c
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
4 changes: 4 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

### Bug Fixe

- [#4532](https://github.com/ignite/cli/pull/4532) Fix non working _shortcuts_ in validator home config

## [`v28.8.0`](https://github.com/ignite/cli/releases/tag/v28.8.0)

### Features
Expand Down
3 changes: 0 additions & 3 deletions ignite/config/chain/v1/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,6 @@ type Gentx struct {
// Moniker is the validator's (optional) moniker.
Moniker string `yaml:"moniker"`

// Home is directory for config and data.
Home string `yaml:"home"`

// KeyringBackend is keyring's backend.
KeyringBackend string `yaml:"keyring-backend"`

Expand Down
19 changes: 19 additions & 0 deletions ignite/services/chain/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"os"
"path/filepath"
"strings"

"github.com/go-git/go-git/v5"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -358,6 +359,11 @@ func (c *Chain) DefaultHome() (string, error) {
}
validator, _ := chainconfig.FirstValidator(cfg)
if validator.Home != "" {
expandedHome, err := expandHome(validator.Home)
if err != nil {
return "", err
}
validator.Home = expandedHome
return validator.Home, nil
}

Expand Down Expand Up @@ -531,3 +537,16 @@ func (c *Chain) Commands(ctx context.Context) (chaincmdrunner.Runner, error) {

return chaincmdrunner.New(ctx, cc, ccrOptions...)
}

// expandHome expands a path that may start with "~" and may contain environment variables.
func expandHome(path string) (string, error) {
if strings.HasPrefix(path, "~") {
home, err := os.UserHomeDir()
if err != nil {
return "", err
}
// Only replace the first occurrence at the start.
path = home + strings.TrimPrefix(path, "~")
}
return os.ExpandEnv(path), nil
}

0 comments on commit e4be28c

Please sign in to comment.