mirror of
https://github.com/hashicorp/vault.git
synced 2026-02-03 20:40:45 -05:00
cli: fixed HOME not set error (#26243)
* cli: fixed HOME not set error * changelog * changelog but better * Slightly better error handling
This commit is contained in:
parent
a942597971
commit
39499e6fba
4 changed files with 24 additions and 9 deletions
4
changelog/26243.txt
Normal file
4
changelog/26243.txt
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
```release-note:bug
|
||||
cli: fixed a bug where the Vault CLI would error out if
|
||||
HOME was not set.
|
||||
```
|
||||
|
|
@ -24,6 +24,7 @@ import (
|
|||
"github.com/hashicorp/vault/command/config"
|
||||
"github.com/hashicorp/vault/helper/namespace"
|
||||
"github.com/mattn/go-isatty"
|
||||
"github.com/mitchellh/go-homedir"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/posener/complete"
|
||||
)
|
||||
|
|
@ -84,8 +85,13 @@ type BaseCommand struct {
|
|||
func (c *BaseCommand) Client() (*api.Client, error) {
|
||||
// Read the test client if present
|
||||
if c.client != nil {
|
||||
if err := c.applyHCPConfig(); err != nil {
|
||||
return nil, err
|
||||
// Ignoring homedir errors here and moving on to avoid
|
||||
// spamming user with warnings/errors that homedir isn't set.
|
||||
path, err := homedir.Dir()
|
||||
if err == nil {
|
||||
if err := c.applyHCPConfig(path); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
return c.client, nil
|
||||
|
|
@ -196,8 +202,13 @@ func (c *BaseCommand) Client() (*api.Client, error) {
|
|||
|
||||
c.client = client
|
||||
|
||||
if err := c.applyHCPConfig(); err != nil {
|
||||
return nil, err
|
||||
// Ignoring homedir errors here and moving on to avoid
|
||||
// spamming user with warnings/errors that homedir isn't set.
|
||||
path, err := homedir.Dir()
|
||||
if err == nil {
|
||||
if err := c.applyHCPConfig(path); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
if c.addrWarning != "" && c.UI != nil {
|
||||
|
|
@ -211,12 +222,12 @@ func (c *BaseCommand) Client() (*api.Client, error) {
|
|||
return client, nil
|
||||
}
|
||||
|
||||
func (c *BaseCommand) applyHCPConfig() error {
|
||||
func (c *BaseCommand) applyHCPConfig(path string) error {
|
||||
if c.hcpTokenHelper == nil {
|
||||
c.hcpTokenHelper = c.HCPTokenHelper()
|
||||
}
|
||||
|
||||
hcpToken, err := c.hcpTokenHelper.GetHCPToken()
|
||||
hcpToken, err := c.hcpTokenHelper.GetHCPToken(path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
|||
2
go.mod
2
go.mod
|
|
@ -135,7 +135,7 @@ require (
|
|||
github.com/hashicorp/raft-boltdb/v2 v2.3.0
|
||||
github.com/hashicorp/raft-snapshot v1.0.4
|
||||
github.com/hashicorp/raft-wal v0.4.0
|
||||
github.com/hashicorp/vault-hcp-lib v0.0.0-20240126195955-473e9a48e7b7
|
||||
github.com/hashicorp/vault-hcp-lib v0.0.0-20240402205111-2312b38227ab
|
||||
github.com/hashicorp/vault-plugin-auth-alicloud v0.17.0
|
||||
github.com/hashicorp/vault-plugin-auth-azure v0.17.0
|
||||
github.com/hashicorp/vault-plugin-auth-centrify v0.15.1
|
||||
|
|
|
|||
4
go.sum
4
go.sum
|
|
@ -2520,8 +2520,8 @@ github.com/hashicorp/raft-wal v0.4.0/go.mod h1:A6vP5o8hGOs1LHfC1Okh9xPwWDcmb6Vvu
|
|||
github.com/hashicorp/serf v0.8.2/go.mod h1:6hOLApaqBFA1NXqRQAsxw9QxuDEvNxSQRwA/JwenrHc=
|
||||
github.com/hashicorp/serf v0.10.1 h1:Z1H2J60yRKvfDYAOZLd2MU0ND4AH/WDz7xYHDWQsIPY=
|
||||
github.com/hashicorp/serf v0.10.1/go.mod h1:yL2t6BqATOLGc5HF7qbFkTfXoPIY0WZdWHfEvMqbG+4=
|
||||
github.com/hashicorp/vault-hcp-lib v0.0.0-20240126195955-473e9a48e7b7 h1:D9XTgYgpQgdZHToRpJQ6fZwWyOOSpLX3Y+D2aMlxQh4=
|
||||
github.com/hashicorp/vault-hcp-lib v0.0.0-20240126195955-473e9a48e7b7/go.mod h1:KpSNItDH9ojFPf4UkGCB0vv3cAAwvVxBU2On4EZ0f7c=
|
||||
github.com/hashicorp/vault-hcp-lib v0.0.0-20240402205111-2312b38227ab h1:n1GzFf7LwpVebVIjh5XKW2IQa/BqI/zPlFg2mmB26dQ=
|
||||
github.com/hashicorp/vault-hcp-lib v0.0.0-20240402205111-2312b38227ab/go.mod h1:Nb41BTPvmFbKB73D/+XpxIw6Nf2Rt+AOUvLzlDxwAGQ=
|
||||
github.com/hashicorp/vault-plugin-auth-alicloud v0.17.0 h1:0SOkYxjMjph3Tbtv37+pANJQnYDvlAdjKpdEbK6zzZs=
|
||||
github.com/hashicorp/vault-plugin-auth-alicloud v0.17.0/go.mod h1:79KUWOxY6Ftoad7b+vEmyCmY6eYKdHiADTP0w0TunsE=
|
||||
github.com/hashicorp/vault-plugin-auth-azure v0.17.0 h1:nFsWQV+sMEdJCvKpVODNeTPP36n5bi6yiQpBOdBsQWw=
|
||||
|
|
|
|||
Loading…
Reference in a new issue