fix: expand home directory for credentials file
The documentation does not specify that the `credentials-file` field in `config.yaml` needs to be an absolute path. If you add a relative path with a `~`, it throw as error that the file is not found. However, this iis a confusing error for the user as the file at the path exists, it is just that `os.Stat` failed because it could not expand the `~`. This commit fixes the above issue by running a `homedir.Expand` on the `credentials-file` path in the `credentialFinder` function.
This commit is contained in:
parent
a4105e8708
commit
179af699a9
|
@ -9,6 +9,7 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
|
"github.com/mitchellh/go-homedir"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/rs/zerolog"
|
"github.com/rs/zerolog"
|
||||||
"github.com/urfave/cli/v2"
|
"github.com/urfave/cli/v2"
|
||||||
|
@ -54,7 +55,12 @@ func newSubcommandContext(c *cli.Context) (*subcommandContext, error) {
|
||||||
// Returns something that can find the given tunnel's credentials file.
|
// Returns something that can find the given tunnel's credentials file.
|
||||||
func (sc *subcommandContext) credentialFinder(tunnelID uuid.UUID) CredFinder {
|
func (sc *subcommandContext) credentialFinder(tunnelID uuid.UUID) CredFinder {
|
||||||
if path := sc.c.String(CredFileFlag); path != "" {
|
if path := sc.c.String(CredFileFlag); path != "" {
|
||||||
return newStaticPath(path, sc.fs)
|
// Expand path if CredFileFlag contains `~`
|
||||||
|
absPath, err := homedir.Expand(path)
|
||||||
|
if err != nil {
|
||||||
|
return newStaticPath(path, sc.fs)
|
||||||
|
}
|
||||||
|
return newStaticPath(absPath, sc.fs)
|
||||||
}
|
}
|
||||||
return newSearchByID(tunnelID, sc.c, sc.log, sc.fs)
|
return newSearchByID(tunnelID, sc.c, sc.log, sc.fs)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue