2023-04-14 20:01:14 -04:00
|
|
|
// Copyright (c) HashiCorp, Inc.
|
|
|
|
|
|
|
|
|
|
package config
|
|
|
|
|
|
2023-05-24 23:33:51 -04:00
|
|
|
import (
|
|
|
|
|
"os"
|
|
|
|
|
"testing"
|
|
|
|
|
)
|
2023-04-14 20:01:14 -04:00
|
|
|
|
|
|
|
|
// getOpts - iterate the inbound Options and return a struct
|
|
|
|
|
func getOpts(opt ...Option) options {
|
|
|
|
|
opts := getDefaultOptions()
|
|
|
|
|
for _, o := range opt {
|
|
|
|
|
o(&opts)
|
|
|
|
|
}
|
|
|
|
|
return opts
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Option - how Options are passed as arguments
|
|
|
|
|
type Option func(*options)
|
|
|
|
|
|
|
|
|
|
// options = how options are represented
|
|
|
|
|
type options struct {
|
|
|
|
|
withSysEventsEnabled bool
|
|
|
|
|
withAuditEventsEnabled bool
|
|
|
|
|
withObservationsEnabled bool
|
|
|
|
|
testWithErrorEventsEnabled bool
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func getDefaultOptions() options {
|
2023-05-24 23:33:51 -04:00
|
|
|
opts := options{}
|
|
|
|
|
|
|
|
|
|
if os.Getenv("BOUNDARY_ENABLE_TEST_SYS_EVENTS") != "" {
|
|
|
|
|
opts.withSysEventsEnabled = true
|
|
|
|
|
}
|
|
|
|
|
if os.Getenv("BOUNDARY_ENABLE_TEST_AUDIT_EVENTS") != "" {
|
|
|
|
|
opts.withAuditEventsEnabled = true
|
|
|
|
|
}
|
|
|
|
|
if os.Getenv("BOUNDARY_ENABLE_TEST_OBSERVATIONS") != "" {
|
|
|
|
|
opts.withObservationsEnabled = true
|
|
|
|
|
}
|
|
|
|
|
if os.Getenv("BOUNDARY_ENABLE_TEST_ERROR_EVENTS") != "" {
|
|
|
|
|
opts.testWithErrorEventsEnabled = true
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return opts
|
2023-04-14 20:01:14 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// WithSysEventsEnabled provides an option for enabling system events
|
|
|
|
|
func WithSysEventsEnabled(enable bool) Option {
|
|
|
|
|
return func(o *options) {
|
|
|
|
|
o.withSysEventsEnabled = enable
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// WithAuditEventsEnabled provides an option for enabling audit events
|
|
|
|
|
func WithAuditEventsEnabled(enable bool) Option {
|
|
|
|
|
return func(o *options) {
|
|
|
|
|
o.withAuditEventsEnabled = enable
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// WithObservationsEnabled provides an option for enabling observation events
|
|
|
|
|
func WithObservationsEnabled(enable bool) Option {
|
|
|
|
|
return func(o *options) {
|
|
|
|
|
o.withObservationsEnabled = enable
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// TestWithErrorEventsEnabled provides an option for enabling error events
|
|
|
|
|
// during tests.
|
|
|
|
|
func TestWithErrorEventsEnabled(_ testing.TB, enable bool) Option {
|
|
|
|
|
return func(o *options) {
|
|
|
|
|
o.testWithErrorEventsEnabled = enable
|
|
|
|
|
}
|
|
|
|
|
}
|