Files
threshold/internal/cmd/config/options.go
T
Jeff Mitchell feb3aea38f Support multiple IDs in grants (#3263)
This allows specifying multiple IDs in grants via an `ids` field, which
will eventually become the normal way to specify IDs. Internally, each
grant with multiple IDs turns into multiple ACL grants each with a
single ID; to make this distinction clearer and allow for better
separation of concerns an AclGrant type has been introduced, so really
multiple IDs in a Grant turn into multiple AclGrants.

The nice thing about doing it this way is that it becomes purely a
parsing concern; no actual validation logic has changed.

For backwards compatibility with grants already stored in roles, we do
not error out if `id` is specified. However, eventually we will simply
not support grants with `id` coming via the API; they will fail API
validation, such that new grants will require the use of the updated
`ids` field.

A follow-on PR will plumb this through the service handlers/API/CLI, but
I decided to do it in separate chunks to make reviewing easier, given
that they are easily separable into the internal and external aspects of
the change.

* Add CLI/API checks around using ID in grants (#3264)

* Plumb through some contexts to remove a lot of deprecated errors (#3268)
2023-06-14 21:55:24 -04:00

103 lines
2.3 KiB
Go

// Copyright (c) HashiCorp, Inc.
package config
import (
"os"
"testing"
"github.com/hashicorp/go-secure-stdlib/parseutil"
)
// getOpts - iterate the inbound Options and return a struct
func getOpts(opt ...Option) (options, error) {
opts, err := getDefaultOptions()
if err != nil {
return opts, err
}
for _, o := range opt {
if o == nil {
continue
}
err = o(&opts)
if err != nil {
return opts, err
}
}
return opts, nil
}
// Option - how Options are passed as arguments
type Option func(*options) error
// options = how options are represented
type options struct {
withSysEventsEnabled bool
withAuditEventsEnabled bool
withObservationsEnabled bool
testWithErrorEventsEnabled bool
}
func getDefaultOptions() (options, error) {
opts := options{}
sysEvents, err := parseutil.ParseBool(os.Getenv("BOUNDARY_ENABLE_TEST_SYS_EVENTS"))
if err != nil {
return opts, err
}
opts.withSysEventsEnabled = sysEvents
auditEvents, err := parseutil.ParseBool(os.Getenv("BOUNDARY_ENABLE_TEST_AUDIT_EVENTS"))
if err != nil {
return opts, err
}
opts.withAuditEventsEnabled = auditEvents
obs, err := parseutil.ParseBool(os.Getenv("BOUNDARY_ENABLE_TEST_OBSERVATIONS"))
if err != nil {
return opts, err
}
opts.withObservationsEnabled = obs
errEvents, err := parseutil.ParseBool(os.Getenv("BOUNDARY_ENABLE_TEST_ERROR_EVENTS"))
if err != nil {
return opts, err
}
opts.testWithErrorEventsEnabled = errEvents
return opts, nil
}
// WithSysEventsEnabled provides an option for enabling system events
func WithSysEventsEnabled(enable bool) Option {
return func(o *options) error {
o.withSysEventsEnabled = enable
return nil
}
}
// WithAuditEventsEnabled provides an option for enabling audit events
func WithAuditEventsEnabled(enable bool) Option {
return func(o *options) error {
o.withAuditEventsEnabled = enable
return nil
}
}
// WithObservationsEnabled provides an option for enabling observation events
func WithObservationsEnabled(enable bool) Option {
return func(o *options) error {
o.withObservationsEnabled = enable
return nil
}
}
// TestWithErrorEventsEnabled provides an option for enabling error events
// during tests.
func TestWithErrorEventsEnabled(_ testing.TB, enable bool) Option {
return func(o *options) error {
o.testWithErrorEventsEnabled = enable
return nil
}
}