Set wrapper on client, not token, so it doesn't fail KMS recovery on update calls
This commit is contained in:
1 parent
d52fb81e68
commit
d3606e14b6
2 files changed
+22
-21
No files matched your search
+9
-9
@@ -615,7 +615,6 @@ func (c *Client) NewRequest(ctx context.Context, method, requestPath string, bod
|
||||
addr := c.config.Addr
|
||||
srvLookup := c.config.SRVLookup
|
||||
token := c.config.Token
|
||||
recoveryKmsWrapper := c.config.RecoveryKmsWrapper
|
||||
httpClient := c.config.HttpClient
|
||||
headers := copyHeaders(c.config.Headers)
|
||||
c.modifyLock.RUnlock()
|
||||
@@ -658,13 +657,6 @@ func (c *Client) NewRequest(ctx context.Context, method, requestPath string, bod
|
||||
}
|
||||
}
|
||||
|
||||
if recoveryKmsWrapper != nil {
|
||||
token, err = recovery.GenerateRecoveryToken(ctx, recoveryKmsWrapper)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error generating recovery KMS workflow token: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
req := &http.Request{
|
||||
Method: method,
|
||||
URL: &url.URL{
|
||||
@@ -737,12 +729,20 @@ func (c *Client) Do(r *retryablehttp.Request) (*Response, error) {
|
||||
backoff = retryablehttp.LinearJitterBackoff
|
||||
}
|
||||
|
||||
if recoveryKmsWrapper != nil {
|
||||
token, err := recovery.GenerateRecoveryToken(ctx, recoveryKmsWrapper)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error generating recovery KMS workflow token: %w", err)
|
||||
}
|
||||
r.Header.Set("authorization", "Bearer "+token)
|
||||
}
|
||||
|
||||
if checkRetry == nil {
|
||||
checkRetry = func(ctx context.Context, resp *http.Response, err error) (bool, error) {
|
||||
if recoveryKmsWrapper != nil &&
|
||||
resp != nil &&
|
||||
resp.Request != nil {
|
||||
token, err = recovery.GenerateRecoveryToken(ctx, recoveryKmsWrapper)
|
||||
token, err := recovery.GenerateRecoveryToken(ctx, recoveryKmsWrapper)
|
||||
if err != nil {
|
||||
return false, fmt.Errorf("error generating recovery KMS workflow token: %w", err)
|
||||
}
|
||||
|
||||
+13
-12
@@ -18,7 +18,6 @@ import (
|
||||
"github.com/btcsuite/btcutil/base58"
|
||||
"github.com/hashicorp/boundary/api"
|
||||
"github.com/hashicorp/boundary/api/authtokens"
|
||||
"github.com/hashicorp/boundary/sdk/recovery"
|
||||
"github.com/hashicorp/boundary/sdk/wrapper"
|
||||
"github.com/mitchellh/cli"
|
||||
"github.com/pkg/errors"
|
||||
@@ -194,17 +193,19 @@ func (c *Command) Client(opt ...Option) (*api.Client, error) {
|
||||
if err := wrapper.Init(c.Context); err != nil {
|
||||
return nil, fmt.Errorf("Error initializing kms: %w", err)
|
||||
}
|
||||
defer func() {
|
||||
if err := wrapper.Finalize(c.Context); err != nil {
|
||||
c.UI.Error(fmt.Errorf("An error was encountered finalizing the kms: %w", err).Error())
|
||||
}
|
||||
}()
|
||||
|
||||
token, err := recovery.GenerateRecoveryToken(c.Context, wrapper)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Error generating recovery config: %w", err)
|
||||
}
|
||||
c.client.SetToken(token)
|
||||
/*
|
||||
// NOTE: ideally we should call this but at the same time we want to
|
||||
give a wrapper to the client, not a token, so it doesn't try to use
|
||||
it for two subsequent calls. This then becomes a question of
|
||||
how/when to finalize the wrapper. Probably it needs to be stored in
|
||||
the base and then at the end of the command run we finalize it if it
|
||||
exists. defer func() {if err := wrapper.Finalize(c.Context); err !=
|
||||
nil {c.UI.Error(fmt.Errorf("An error was encountered finalizing the
|
||||
kms: %w", err).Error())
|
||||
}
|
||||
}()
|
||||
*/
|
||||
c.client.SetRecoveryKmsWrapper(wrapper)
|
||||
|
||||
case c.FlagToken != "":
|
||||
c.client.SetToken(c.FlagToken)
|
||||
|
||||
Reference in new issue
Block a user