Use the intercepted token always. If the keyring matches, use it from there (#4355)

* Use the intercepted token if present, use it through the keyring if keyring contains it

* fixup! Use the intercepted token if present, use it through the keyring if keyring contains it

* Apply suggestions from code review

Co-authored-by: Jim <jlambert@hashicorp.com>

---------

Co-authored-by: Jim <jlambert@hashicorp.com>
This commit is contained in:
ToddandJim committed 2024-02-06 11:46:28 -08:00
1 parent 66c7f274bb
commit eb6d0dbd6a
4 files changed
+79 -50

No files matched your search

+3 -8
View File
@@ -25,6 +25,9 @@ func saveAndOrPrintToken(c *base.Command, result *authmethods.AuthenticateResult
return base.CommandCliError
}
opts := base.GetOpts(opt...)
if opts.WithInterceptedToken != nil {
*opts.WithInterceptedToken = token.Token
}
switch base.Format(c.UI) {
case "table":
@@ -98,18 +101,10 @@ func saveAndOrPrintToken(c *base.Command, result *authmethods.AuthenticateResult
switch {
case gotErr:
c.UI.Warn(fmt.Sprintf("The token was not successfully saved to a system keyring. The token is:\n\n%s\n\nIt must be manually passed in via the BOUNDARY_TOKEN env var or -token flag. Storing the token can also be disabled via -keyring-type=none.", token.Token))
if opts.WithInterceptedToken != nil {
*opts.WithInterceptedToken = token.Token
}
case c.FlagKeyringType == "none":
c.UI.Warn("\nStoring the token in a keyring was disabled. The token is:")
c.UI.Output(token.Token)
c.UI.Warn("Please be sure to store it safely!")
if opts.WithInterceptedToken != nil {
*opts.WithInterceptedToken = token.Token
}
}
return base.CommandSuccess