Add skip daemon flag and send recently authed tokens to daemon (#3883)

* Add skip daemon flag and send recently authed tokens to daemon

* Rename flag skip-daemon to skip-cache-daemon

* adding option test

* move common.Options to base.Option

* SocketAddress returns *url.URL, fix search test
This commit is contained in:
Todd authored and Johan Brandhorst-Satzkorn committed 2024-01-05 07:43:20 -08:00
1 parent 2f7459fa40
commit 3a7ea64a31
27 files changed
+429 -419

No files matched your search

@@ -11,7 +11,6 @@ import (
"github.com/hashicorp/boundary/api/authmethods"
"github.com/hashicorp/boundary/globals"
"github.com/hashicorp/boundary/internal/cmd/base"
"github.com/hashicorp/boundary/internal/cmd/common"
"github.com/hashicorp/boundary/internal/types/scope"
"github.com/mitchellh/cli"
"github.com/mitchellh/go-wordwrap"
@@ -104,15 +103,18 @@ func (c *Command) Run(args []string) int {
switch {
case strings.HasPrefix(c.FlagAuthMethodId, globals.PasswordAuthMethodPrefix):
cmd := PasswordCommand{Command: c.Command, Opts: []common.Option{common.WithSkipScopeIdFlag(true)}}
cmd := PasswordCommand{Command: c.Command}
cmd.Opts = append(c.Opts, base.WithSkipScopeIdFlag(true))
cmd.Run([]string{})
case strings.HasPrefix(c.FlagAuthMethodId, globals.OidcAuthMethodPrefix):
cmd := OidcCommand{Command: c.Command, Opts: []common.Option{common.WithSkipScopeIdFlag(true)}}
cmd := OidcCommand{Command: c.Command}
cmd.Opts = append(c.Opts, base.WithSkipScopeIdFlag(true))
cmd.Run([]string{})
case strings.HasPrefix(c.FlagAuthMethodId, globals.LdapAuthMethodPrefix):
cmd := LdapCommand{Command: c.Command, Opts: []common.Option{common.WithSkipScopeIdFlag(true)}}
cmd := LdapCommand{Command: c.Command}
cmd.Opts = append(c.Opts, base.WithSkipScopeIdFlag(true))
cmd.Run([]string{})
default:
+6 -1
View File
@@ -18,12 +18,13 @@ import (
zkeyring "github.com/zalando/go-keyring"
)
func saveAndOrPrintToken(c *base.Command, result *authmethods.AuthenticateResult) int {
func saveAndOrPrintToken(c *base.Command, result *authmethods.AuthenticateResult, opt ...base.Option) int {
token := new(authtokens.AuthToken)
if err := json.Unmarshal(result.GetRawAttributes(), token); err != nil {
c.PrintCliError(fmt.Errorf("Error trying to decode response as an auth token: %w", err))
return base.CommandCliError
}
opts := base.GetOpts(opt...)
switch base.Format(c.UI) {
case "table":
@@ -101,6 +102,10 @@ func saveAndOrPrintToken(c *base.Command, result *authmethods.AuthenticateResult
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
+4 -11
View File
@@ -13,7 +13,6 @@ import (
"github.com/hashicorp/boundary/api/authmethods"
"github.com/hashicorp/boundary/globals"
"github.com/hashicorp/boundary/internal/cmd/base"
"github.com/hashicorp/boundary/internal/cmd/common"
"github.com/hashicorp/boundary/internal/types/scope"
"github.com/hashicorp/go-secure-stdlib/parseutil"
"github.com/hashicorp/go-secure-stdlib/password"
@@ -32,8 +31,7 @@ type LdapCommand struct {
flagLoginName string
flagPassword string
Opts []common.Option
parsedOpts *common.Options
parsedOpts base.Options
}
func (c *LdapCommand) Synopsis() string {
@@ -77,7 +75,7 @@ func (c *LdapCommand) Flags() *base.FlagSets {
Usage: "The auth-method resource to use for the operation.",
})
if c.parsedOpts == nil || !c.parsedOpts.WithSkipScopeIdFlag {
if !c.parsedOpts.WithSkipScopeIdFlag {
f.StringVar(&base.StringVar{
Name: "scope-id",
EnvVar: "BOUNDARY_SCOPE_ID",
@@ -98,12 +96,7 @@ func (c *LdapCommand) AutocompleteFlags() complete.Flags {
}
func (c *LdapCommand) Run(args []string) int {
opts, err := common.GetOpts(c.Opts...)
if err != nil {
c.PrintCliError(err)
return base.CommandCliError
}
c.parsedOpts = opts
c.parsedOpts = base.GetOpts(c.Opts...)
f := c.Flags()
if err := f.Parse(args); err != nil {
@@ -193,5 +186,5 @@ func (c *LdapCommand) Run(args []string) int {
return base.CommandCliError
}
return saveAndOrPrintToken(c.Command, result)
return saveAndOrPrintToken(c.Command, result, c.Opts...)
}
+4 -12
View File
@@ -14,7 +14,6 @@ import (
"github.com/hashicorp/boundary/api"
"github.com/hashicorp/boundary/api/authmethods"
"github.com/hashicorp/boundary/internal/cmd/base"
"github.com/hashicorp/boundary/internal/cmd/common"
"github.com/hashicorp/boundary/internal/types/scope"
"github.com/hashicorp/cap/util"
"github.com/mitchellh/cli"
@@ -30,8 +29,7 @@ var (
type OidcCommand struct {
*base.Command
Opts []common.Option
parsedOpts *common.Options
parsedOpts base.Options
}
func (c *OidcCommand) Synopsis() string {
@@ -61,7 +59,7 @@ func (c *OidcCommand) Flags() *base.FlagSets {
Usage: "The auth-method resource to use for the operation",
})
if c.parsedOpts == nil || !c.parsedOpts.WithSkipScopeIdFlag {
if !c.parsedOpts.WithSkipScopeIdFlag {
f.StringVar(&base.StringVar{
Name: "scope-id",
EnvVar: "BOUNDARY_SCOPE_ID",
@@ -81,13 +79,7 @@ func (c *OidcCommand) AutocompleteFlags() complete.Flags {
}
func (c *OidcCommand) Run(args []string) int {
opts, err := common.GetOpts(c.Opts...)
if err != nil {
c.PrintCliError(err)
return base.CommandCliError
}
c.parsedOpts = opts
c.parsedOpts = base.GetOpts(c.Opts...)
f := c.Flags()
if err := f.Parse(args); err != nil {
@@ -196,5 +188,5 @@ func (c *OidcCommand) Run(args []string) int {
return base.CommandCliError
}
return saveAndOrPrintToken(c.Command, result)
return saveAndOrPrintToken(c.Command, result, c.Opts...)
}
+4 -11
View File
@@ -13,7 +13,6 @@ import (
"github.com/hashicorp/boundary/api/authmethods"
"github.com/hashicorp/boundary/globals"
"github.com/hashicorp/boundary/internal/cmd/base"
"github.com/hashicorp/boundary/internal/cmd/common"
"github.com/hashicorp/go-secure-stdlib/parseutil"
"github.com/hashicorp/go-secure-stdlib/password"
"github.com/mitchellh/cli"
@@ -37,8 +36,7 @@ type PasswordCommand struct {
flagLoginName string
flagPassword string
Opts []common.Option
parsedOpts *common.Options
parsedOpts base.Options
}
func (c *PasswordCommand) Synopsis() string {
@@ -82,7 +80,7 @@ func (c *PasswordCommand) Flags() *base.FlagSets {
Usage: "The auth-method resource to use for the operation.",
})
if c.parsedOpts == nil || !c.parsedOpts.WithSkipScopeIdFlag {
if !c.parsedOpts.WithSkipScopeIdFlag {
f.StringVar(&base.StringVar{
Name: "scope-id",
EnvVar: "BOUNDARY_SCOPE_ID",
@@ -103,12 +101,7 @@ func (c *PasswordCommand) AutocompleteFlags() complete.Flags {
}
func (c *PasswordCommand) Run(args []string) int {
opts, err := common.GetOpts(c.Opts...)
if err != nil {
c.PrintCliError(err)
return base.CommandCliError
}
c.parsedOpts = opts
c.parsedOpts = base.GetOpts(c.Opts...)
f := c.Flags()
@@ -199,5 +192,5 @@ func (c *PasswordCommand) Run(args []string) int {
return base.CommandCliError
}
return saveAndOrPrintToken(c.Command, result)
return saveAndOrPrintToken(c.Command, result, c.Opts...)
}