Files
threshold/internal/target/options.go
T
Jeff MitchellandJim Lambert 62baef1b7e Add multi connection parameters through targets and into session creation (#375)
* Update protos and gen

* Add new values to targets CLI command

* Lots more plumbing of new parameters through everything

* allow fields to be set to zero value.

* Disallow set but empty name/description strings in create/update verifiers

Co-authored-by: Jim Lambert <jlambert@hashicorp.com>
2020-09-19 10:31:49 -04:00

123 lines
3.1 KiB
Go

package target
import "time"
// 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 {
withName string
withDescription string
withDefaultPort uint32
withLimit int
withScopeId string
withUserId string
withTargetType *TargetType
withHostSets []string
withSessionMaxDuration uint32
withSessionConnectionLimit uint32
withConnectionIdleTimeoutDuration uint32
}
func getDefaultOptions() options {
return options{
withName: "",
withDescription: "",
withLimit: 0,
withDefaultPort: 0,
withScopeId: "",
withUserId: "",
withTargetType: nil,
withHostSets: nil,
withSessionMaxDuration: uint32((8 * time.Hour).Seconds()),
withSessionConnectionLimit: 1,
withConnectionIdleTimeoutDuration: uint32((1 * time.Hour).Seconds()),
}
}
// WithDescription provides an optional description
func WithDescription(desc string) Option {
return func(o *options) {
o.withDescription = desc
}
}
// WithName provides an option to search by a friendly name
func WithName(name string) Option {
return func(o *options) {
o.withName = name
}
}
// WithLimit provides an option to provide a limit. Intentionally allowing
// negative integers. If WithLimit < 0, then unlimited results are returned.
// If WithLimit == 0, then default limits are used for results.
func WithLimit(limit int) Option {
return func(o *options) {
o.withLimit = limit
}
}
// WithDefaultPort provides an option to specify the default target port.
func WithDefaultPort(p uint32) Option {
return func(o *options) {
o.withDefaultPort = p
}
}
// WithScopeId provides an option to search by a scope id
func WithScopeId(scopeId string) Option {
return func(o *options) {
o.withScopeId = scopeId
}
}
// WithUserId provides an option to search by a user public id
func WithUserId(userId string) Option {
return func(o *options) {
o.withUserId = userId
}
}
// WithTargetType provides an option to search by a target type
func WithTargetType(t TargetType) Option {
return func(o *options) {
o.withTargetType = &t
}
}
// WithHostSets provides an option for providing a list of host set ids
func WithHostSets(hs []string) Option {
return func(o *options) {
o.withHostSets = hs
}
}
func WithSessionMaxDuration(dur uint32) Option {
return func(o *options) {
o.withSessionMaxDuration = dur
}
}
func WithSessionConnectionLimit(limit uint32) Option {
return func(o *options) {
o.withSessionConnectionLimit = limit
}
}
func WithConnectionIdleTimeoutDuration(dur uint32) Option {
return func(o *options) {
o.withConnectionIdleTimeoutDuration = dur
}
}