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:
1 parent
2f7459fa40
commit
3a7ea64a31
27 files changed
+429
-419
No files matched your search
@@ -64,10 +64,11 @@ const (
|
||||
// maxLineLength is the maximum width of any line.
|
||||
maxLineLength int = 78
|
||||
|
||||
envToken = "BOUNDARY_TOKEN"
|
||||
EnvTokenName = "BOUNDARY_TOKEN_NAME"
|
||||
EnvKeyringType = "BOUNDARY_KEYRING_TYPE"
|
||||
envRecoveryConfig = "BOUNDARY_RECOVERY_CONFIG"
|
||||
envToken = "BOUNDARY_TOKEN"
|
||||
EnvTokenName = "BOUNDARY_TOKEN_NAME"
|
||||
EnvKeyringType = "BOUNDARY_KEYRING_TYPE"
|
||||
envRecoveryConfig = "BOUNDARY_RECOVERY_CONFIG"
|
||||
envSkipCacheDaemon = "BOUNDARY_SKIP_CACHE_DAEMON"
|
||||
|
||||
StoredTokenName = "HashiCorp Boundary Auth Token"
|
||||
)
|
||||
@@ -84,6 +85,8 @@ type Command struct {
|
||||
UI cli.Ui
|
||||
ShutdownCh chan struct{}
|
||||
|
||||
Opts []Option
|
||||
|
||||
flags *FlagSets
|
||||
flagsOnce sync.Once
|
||||
|
||||
@@ -103,6 +106,7 @@ type Command struct {
|
||||
FlagKeyringType string
|
||||
FlagRecoveryConfig string
|
||||
FlagOutputCurlString bool
|
||||
FlagSkipCacheDaemon bool
|
||||
|
||||
FlagScopeId string
|
||||
FlagScopeName string
|
||||
@@ -189,6 +193,10 @@ func MakeShutdownCh() chan struct{} {
|
||||
return resultCh
|
||||
}
|
||||
|
||||
func (c *Command) BaseCommand() *Command {
|
||||
return c
|
||||
}
|
||||
|
||||
// Client returns the HTTP API client. The client is cached on the command to
|
||||
// save performance on future calls.
|
||||
func (c *Command) Client(opt ...Option) (*api.Client, error) {
|
||||
@@ -197,7 +205,7 @@ func (c *Command) Client(opt ...Option) (*api.Client, error) {
|
||||
return c.client, nil
|
||||
}
|
||||
|
||||
opts := getOpts(opt...)
|
||||
opts := GetOpts(opt...)
|
||||
|
||||
config, err := api.DefaultConfig()
|
||||
if err != nil {
|
||||
@@ -455,6 +463,14 @@ func (c *Command) FlagSet(bit FlagSetBit) *FlagSets {
|
||||
Target: &c.FlagOutputCurlString,
|
||||
Usage: "Instead of executing the request, print an equivalent cURL command string and exit.",
|
||||
})
|
||||
|
||||
f.BoolVar(&BoolVar{
|
||||
Name: "skip-cache-daemon",
|
||||
Target: &c.FlagSkipCacheDaemon,
|
||||
Default: false,
|
||||
EnvVar: envSkipCacheDaemon,
|
||||
Usage: "Skips starting the caching daemon or sending the current used/retrieved token to the caching daemon.",
|
||||
})
|
||||
}
|
||||
|
||||
if bit&FlagSetOutputFormat != 0 {
|
||||
|
||||
@@ -35,7 +35,7 @@ func (b *Server) CreateDevDatabase(ctx context.Context, opt ...Option) error {
|
||||
var err error
|
||||
var c func() error
|
||||
|
||||
opts := getOpts(opt...)
|
||||
opts := GetOpts(opt...)
|
||||
|
||||
// We should only get back postgres for now, but laying the foundation for non-postgres
|
||||
switch opts.withDialect {
|
||||
|
||||
@@ -182,7 +182,7 @@ func WrapMap(prefixSpaces, maxLengthOverride int, input map[string]any) string {
|
||||
// information, to the UI in the appropriate format. WithAttributeFieldPrefix is
|
||||
// used, all other options are ignored.
|
||||
func (c *Command) PrintApiError(in *api.Error, contextStr string, opt ...Option) {
|
||||
opts := getOpts(opt...)
|
||||
opts := GetOpts(opt...)
|
||||
switch Format(c.UI) {
|
||||
case "json":
|
||||
var b []byte
|
||||
@@ -310,7 +310,7 @@ func (c *Command) PrintJsonItem(resp *api.Response, opt ...Option) bool {
|
||||
|
||||
// PrintJson prints the given raw JSON in our common format
|
||||
func (c *Command) PrintJson(input json.RawMessage, opt ...Option) bool {
|
||||
opts := getOpts(opt...)
|
||||
opts := GetOpts(opt...)
|
||||
output := struct {
|
||||
StatusCode int `json:"status_code,omitempty"`
|
||||
Item json.RawMessage `json:"item,omitempty"`
|
||||
|
||||
@@ -9,8 +9,8 @@ import (
|
||||
wrapping "github.com/hashicorp/go-kms-wrapping/v2"
|
||||
)
|
||||
|
||||
// getOpts - iterate the inbound Options and return a struct.
|
||||
func getOpts(opt ...Option) Options {
|
||||
// GetOpts - iterate the inbound Options and return a struct.
|
||||
func GetOpts(opt ...Option) Options {
|
||||
opts := getDefaultOptions()
|
||||
for _, o := range opt {
|
||||
if o != nil {
|
||||
@@ -45,6 +45,8 @@ type Options struct {
|
||||
withHostPlugin func() (string, plugin.HostPluginServiceClient)
|
||||
withEventGating bool
|
||||
withImplicitId string
|
||||
WithSkipScopeIdFlag bool
|
||||
WithInterceptedToken *string
|
||||
}
|
||||
|
||||
func getDefaultOptions() Options {
|
||||
@@ -209,3 +211,19 @@ func WithImplicitId(with string) Option {
|
||||
o.withImplicitId = with
|
||||
}
|
||||
}
|
||||
|
||||
// WithSkipScopeIdFlag tells a command to not create a scope ID flag (usually
|
||||
// because it's already been defined)
|
||||
func WithSkipScopeIdFlag(with bool) Option {
|
||||
return func(o *Options) {
|
||||
o.WithSkipScopeIdFlag = with
|
||||
}
|
||||
}
|
||||
|
||||
// WithInterceptedToken provides a string pointer that will have the token
|
||||
// assigned to it when performing an authenticate command.
|
||||
func WithInterceptedToken(s *string) Option {
|
||||
return func(o *Options) {
|
||||
o.WithInterceptedToken = s
|
||||
}
|
||||
}
|
||||
@@ -15,7 +15,7 @@ func Test_GetOpts(t *testing.T) {
|
||||
t.Parallel()
|
||||
t.Run("nil-options", func(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
opts := getOpts(nil, nil)
|
||||
opts := GetOpts(nil, nil)
|
||||
testOpts := getDefaultOptions()
|
||||
assert.Equal(opts, testOpts)
|
||||
})
|
||||
@@ -28,7 +28,7 @@ func Test_GetOpts(t *testing.T) {
|
||||
ObservationsEnabled: &isTrue,
|
||||
SysEventsEnabled: &isTrue,
|
||||
}
|
||||
opts := getOpts(WithEventFlags(&f))
|
||||
opts := GetOpts(WithEventFlags(&f))
|
||||
testOpts := getDefaultOptions()
|
||||
testOpts.withEventFlags = &f
|
||||
assert.Equal(opts, testOpts)
|
||||
@@ -45,84 +45,84 @@ func Test_GetOpts(t *testing.T) {
|
||||
},
|
||||
},
|
||||
}
|
||||
opts := getOpts(WithEventerConfig(&c))
|
||||
opts := GetOpts(WithEventerConfig(&c))
|
||||
testOpts := getDefaultOptions()
|
||||
testOpts.withEventerConfig = &c
|
||||
assert.Equal(opts, testOpts)
|
||||
})
|
||||
t.Run("WithNoTokenScope", func(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
opts := getOpts(WithNoTokenScope())
|
||||
opts := GetOpts(WithNoTokenScope())
|
||||
testOpts := getDefaultOptions()
|
||||
testOpts.withNoTokenScope = true
|
||||
assert.Equal(opts, testOpts)
|
||||
})
|
||||
t.Run("WithSkipDatabaseDestruction", func(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
opts := getOpts(WithSkipDatabaseDestruction())
|
||||
opts := GetOpts(WithSkipDatabaseDestruction())
|
||||
testOpts := getDefaultOptions()
|
||||
testOpts.withSkipDatabaseDestruction = true
|
||||
assert.Equal(opts, testOpts)
|
||||
})
|
||||
t.Run("WithNoTokenValue", func(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
opts := getOpts(WithNoTokenValue())
|
||||
opts := GetOpts(WithNoTokenValue())
|
||||
testOpts := getDefaultOptions()
|
||||
testOpts.withNoTokenValue = true
|
||||
assert.Equal(opts, testOpts)
|
||||
})
|
||||
t.Run("WithSkipAuthMethodCreation", func(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
opts := getOpts(WithSkipAuthMethodCreation())
|
||||
opts := GetOpts(WithSkipAuthMethodCreation())
|
||||
testOpts := getDefaultOptions()
|
||||
testOpts.withSkipAuthMethodCreation = true
|
||||
assert.Equal(opts, testOpts)
|
||||
})
|
||||
t.Run("WithSkipOidcAuthMethodCreation", func(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
opts := getOpts(WithSkipOidcAuthMethodCreation())
|
||||
opts := GetOpts(WithSkipOidcAuthMethodCreation())
|
||||
testOpts := getDefaultOptions()
|
||||
testOpts.withSkipOidcAuthMethodCreation = true
|
||||
assert.Equal(opts, testOpts)
|
||||
})
|
||||
t.Run("WithSkipLdapAuthMethodCreation", func(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
opts := getOpts(WithSkipLdapAuthMethodCreation())
|
||||
opts := GetOpts(WithSkipLdapAuthMethodCreation())
|
||||
testOpts := getDefaultOptions()
|
||||
testOpts.withSkipLdapAuthMethodCreation = true
|
||||
assert.Equal(opts, testOpts)
|
||||
})
|
||||
t.Run("WithSkipScopesCreation", func(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
opts := getOpts(WithSkipScopesCreation())
|
||||
opts := GetOpts(WithSkipScopesCreation())
|
||||
testOpts := getDefaultOptions()
|
||||
testOpts.withSkipScopesCreation = true
|
||||
assert.Equal(opts, testOpts)
|
||||
})
|
||||
t.Run("WithSkipHostResourcesCreation", func(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
opts := getOpts(WithSkipHostResourcesCreation())
|
||||
opts := GetOpts(WithSkipHostResourcesCreation())
|
||||
testOpts := getDefaultOptions()
|
||||
testOpts.withSkipHostResourcesCreation = true
|
||||
assert.Equal(opts, testOpts)
|
||||
})
|
||||
t.Run("WithSkipTargetCreation", func(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
opts := getOpts(WithSkipTargetCreation())
|
||||
opts := GetOpts(WithSkipTargetCreation())
|
||||
testOpts := getDefaultOptions()
|
||||
testOpts.withSkipTargetCreation = true
|
||||
assert.Equal(opts, testOpts)
|
||||
})
|
||||
t.Run("WithContainerImage", func(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
opts := getOpts(WithContainerImage("test-container"))
|
||||
opts := GetOpts(WithContainerImage("test-container"))
|
||||
testOpts := getDefaultOptions()
|
||||
testOpts.withContainerImage = "test-container"
|
||||
assert.Equal(opts, testOpts)
|
||||
})
|
||||
t.Run("withDialect", func(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
opts := getOpts(withDialect("test-dialect"))
|
||||
opts := GetOpts(withDialect("test-dialect"))
|
||||
testOpts := getDefaultOptions()
|
||||
testOpts.withDialect = "test-dialect"
|
||||
assert.Equal(opts, testOpts)
|
||||
@@ -131,7 +131,24 @@ func Test_GetOpts(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
testOpts := getDefaultOptions()
|
||||
assert.False(testOpts.withEventGating)
|
||||
opts := getOpts(WithEventGating(true))
|
||||
opts := GetOpts(WithEventGating(true))
|
||||
assert.True(opts.withEventGating)
|
||||
})
|
||||
|
||||
t.Run("WithSkipScopeIdFlag", func(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
opts := GetOpts(WithSkipScopeIdFlag(true))
|
||||
testOpts := getDefaultOptions()
|
||||
testOpts.WithSkipScopeIdFlag = true
|
||||
assert.Equal(opts, testOpts)
|
||||
})
|
||||
|
||||
t.Run("WithSkipScopeIdFlag", func(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
var s string
|
||||
opts := GetOpts(WithInterceptedToken(&s))
|
||||
testOpts := getDefaultOptions()
|
||||
testOpts.WithInterceptedToken = &s
|
||||
assert.Equal(opts, testOpts)
|
||||
})
|
||||
}
|
||||
@@ -175,7 +175,7 @@ func (b *Server) SetupEventing(ctx context.Context, logger hclog.Logger, seriali
|
||||
if serverName == "" {
|
||||
return berrors.New(ctx, berrors.InvalidParameter, op, "missing server name")
|
||||
}
|
||||
opts := getOpts(opt...)
|
||||
opts := GetOpts(opt...)
|
||||
if opts.withEventerConfig != nil {
|
||||
if err := opts.withEventerConfig.Validate(); err != nil {
|
||||
return berrors.Wrap(ctx, err, op, berrors.WithMsg("invalid eventer config"))
|
||||
|
||||
Reference in new issue
Block a user