2020-08-26 13:58:46 -04:00
|
|
|
package target
|
|
|
|
|
|
2021-10-20 08:35:33 -04:00
|
|
|
import (
|
|
|
|
|
"time"
|
|
|
|
|
|
|
|
|
|
"github.com/hashicorp/boundary/internal/types/subtypes"
|
|
|
|
|
)
|
2020-09-19 10:31:49 -04:00
|
|
|
|
2021-09-29 13:13:49 -04:00
|
|
|
// GetOpts - iterate the inbound Options and return a struct
|
|
|
|
|
func GetOpts(opt ...Option) options {
|
2020-08-26 13:58:46 -04:00
|
|
|
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 {
|
2021-09-29 13:13:49 -04:00
|
|
|
WithName string
|
|
|
|
|
WithDescription string
|
|
|
|
|
WithDefaultPort uint32
|
|
|
|
|
WithLimit int
|
|
|
|
|
WithScopeId string
|
|
|
|
|
WithScopeIds []string
|
|
|
|
|
WithScopeName string
|
|
|
|
|
WithUserId string
|
2021-10-20 08:35:33 -04:00
|
|
|
WithType subtypes.Subtype
|
2021-09-29 13:13:49 -04:00
|
|
|
WithHostSources []string
|
2021-10-26 09:57:22 -04:00
|
|
|
WithCredentialLibraries []*CredentialLibrary
|
2021-09-29 13:13:49 -04:00
|
|
|
WithSessionMaxSeconds uint32
|
|
|
|
|
WithSessionConnectionLimit int32
|
|
|
|
|
WithPublicId string
|
|
|
|
|
WithWorkerFilter string
|
2022-04-29 15:55:27 -04:00
|
|
|
WithTargetIds []string
|
2020-08-26 13:58:46 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func getDefaultOptions() options {
|
|
|
|
|
return options{
|
2021-09-29 13:13:49 -04:00
|
|
|
WithName: "",
|
|
|
|
|
WithDescription: "",
|
|
|
|
|
WithLimit: 0,
|
|
|
|
|
WithDefaultPort: 0,
|
|
|
|
|
WithScopeId: "",
|
|
|
|
|
WithScopeIds: nil,
|
|
|
|
|
WithScopeName: "",
|
|
|
|
|
WithUserId: "",
|
2021-10-20 08:35:33 -04:00
|
|
|
WithType: "",
|
2021-09-29 13:13:49 -04:00
|
|
|
WithHostSources: nil,
|
2021-10-26 09:57:22 -04:00
|
|
|
WithCredentialLibraries: nil,
|
2021-09-29 13:13:49 -04:00
|
|
|
WithSessionMaxSeconds: uint32((8 * time.Hour).Seconds()),
|
|
|
|
|
WithSessionConnectionLimit: 1,
|
|
|
|
|
WithPublicId: "",
|
|
|
|
|
WithWorkerFilter: "",
|
2020-08-26 13:58:46 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// WithDescription provides an optional description
|
|
|
|
|
func WithDescription(desc string) Option {
|
|
|
|
|
return func(o *options) {
|
2021-09-29 13:13:49 -04:00
|
|
|
o.WithDescription = desc
|
2020-08-26 13:58:46 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// WithName provides an option to search by a friendly name
|
|
|
|
|
func WithName(name string) Option {
|
|
|
|
|
return func(o *options) {
|
2021-09-29 13:13:49 -04:00
|
|
|
o.WithName = name
|
2020-08-26 13:58:46 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 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) {
|
2021-09-29 13:13:49 -04:00
|
|
|
o.WithLimit = limit
|
2020-08-26 13:58:46 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// WithDefaultPort provides an option to specify the default target port.
|
|
|
|
|
func WithDefaultPort(p uint32) Option {
|
|
|
|
|
return func(o *options) {
|
2021-09-29 13:13:49 -04:00
|
|
|
o.WithDefaultPort = p
|
2020-08-26 13:58:46 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// WithScopeId provides an option to search by a scope id
|
|
|
|
|
func WithScopeId(scopeId string) Option {
|
|
|
|
|
return func(o *options) {
|
2021-09-29 13:13:49 -04:00
|
|
|
o.WithScopeId = scopeId
|
2020-08-26 13:58:46 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-25 19:37:40 -05:00
|
|
|
// WithScopeId provides an option to search by multiple scope id
|
|
|
|
|
func WithScopeIds(scopeIds []string) Option {
|
|
|
|
|
return func(o *options) {
|
2021-09-29 13:13:49 -04:00
|
|
|
o.WithScopeIds = scopeIds
|
2021-01-25 19:37:40 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-22 08:40:00 -04:00
|
|
|
// WithScopeId provides an option to search by a scope name
|
|
|
|
|
func WithScopeName(scopeName string) Option {
|
|
|
|
|
return func(o *options) {
|
2021-09-29 13:13:49 -04:00
|
|
|
o.WithScopeName = scopeName
|
2020-10-22 08:40:00 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-26 13:58:46 -04:00
|
|
|
// WithUserId provides an option to search by a user public id
|
|
|
|
|
func WithUserId(userId string) Option {
|
|
|
|
|
return func(o *options) {
|
2021-09-29 13:13:49 -04:00
|
|
|
o.WithUserId = userId
|
2020-08-26 13:58:46 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-20 08:35:33 -04:00
|
|
|
// WithType provides an option to search by a target type
|
|
|
|
|
func WithType(t subtypes.Subtype) Option {
|
2020-08-26 13:58:46 -04:00
|
|
|
return func(o *options) {
|
2021-10-20 08:35:33 -04:00
|
|
|
o.WithType = t
|
2020-08-26 13:58:46 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-30 08:48:03 -04:00
|
|
|
// WithHostSources provides an option for providing a list of host source ids
|
|
|
|
|
func WithHostSources(hs []string) Option {
|
2020-08-26 13:58:46 -04:00
|
|
|
return func(o *options) {
|
2021-09-29 13:13:49 -04:00
|
|
|
o.WithHostSources = hs
|
2020-08-26 13:58:46 -04:00
|
|
|
}
|
|
|
|
|
}
|
2020-09-19 10:31:49 -04:00
|
|
|
|
2021-10-26 09:57:22 -04:00
|
|
|
// WithCredentialLibraries provides an option for providing a list of credential libraries.
|
|
|
|
|
func WithCredentialLibraries(cl []*CredentialLibrary) Option {
|
2021-06-22 22:26:26 -04:00
|
|
|
return func(o *options) {
|
2021-10-26 09:57:22 -04:00
|
|
|
o.WithCredentialLibraries = cl
|
2021-06-22 22:26:26 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-19 11:32:38 -04:00
|
|
|
func WithSessionMaxSeconds(dur uint32) Option {
|
2020-09-19 10:31:49 -04:00
|
|
|
return func(o *options) {
|
2021-09-29 13:13:49 -04:00
|
|
|
o.WithSessionMaxSeconds = dur
|
2020-09-19 10:31:49 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-20 15:53:49 -04:00
|
|
|
func WithSessionConnectionLimit(limit int32) Option {
|
2020-09-19 10:31:49 -04:00
|
|
|
return func(o *options) {
|
2021-09-29 13:13:49 -04:00
|
|
|
o.WithSessionConnectionLimit = limit
|
2020-09-19 10:31:49 -04:00
|
|
|
}
|
|
|
|
|
}
|
2020-09-24 03:31:26 -04:00
|
|
|
|
|
|
|
|
// WithPublicId provides an optional public id
|
|
|
|
|
func WithPublicId(id string) Option {
|
|
|
|
|
return func(o *options) {
|
2021-09-29 13:13:49 -04:00
|
|
|
o.WithPublicId = id
|
2020-09-24 03:31:26 -04:00
|
|
|
}
|
|
|
|
|
}
|
2021-01-21 16:27:20 -05:00
|
|
|
|
|
|
|
|
// WithWorkerFilter provides an optional worker filter
|
|
|
|
|
func WithWorkerFilter(filter string) Option {
|
|
|
|
|
return func(o *options) {
|
2021-09-29 13:13:49 -04:00
|
|
|
o.WithWorkerFilter = filter
|
2021-01-21 16:27:20 -05:00
|
|
|
}
|
|
|
|
|
}
|
2022-04-29 15:55:27 -04:00
|
|
|
|
|
|
|
|
// WithTargetIds provides an option to search by specific target IDs
|
|
|
|
|
func WithTargetIds(with []string) Option {
|
|
|
|
|
return func(o *options) {
|
|
|
|
|
o.WithTargetIds = with
|
|
|
|
|
}
|
|
|
|
|
}
|