2020-09-02 12:31:30 -07:00
|
|
|
package targets
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"github.com/hashicorp/boundary/api"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// Option is a func that sets optional attributes for a call. This does not need
|
|
|
|
|
// to be used directly, but instead option arguments are built from the
|
|
|
|
|
// functions in this package. WithX options set a value to that given in the
|
|
|
|
|
// argument; DefaultX options indicate that the value should be set to its
|
|
|
|
|
// default. When an API call is made options are processed in ther order they
|
|
|
|
|
// appear in the function call, so for a given argument X, a succession of WithX
|
|
|
|
|
// or DefaultX calls will result in the last call taking effect.
|
|
|
|
|
type Option func(*options)
|
|
|
|
|
|
|
|
|
|
type options struct {
|
|
|
|
|
postMap map[string]interface{}
|
|
|
|
|
queryMap map[string]string
|
|
|
|
|
withAutomaticVersioning bool
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func getDefaultOptions() options {
|
|
|
|
|
return options{
|
|
|
|
|
postMap: make(map[string]interface{}),
|
|
|
|
|
queryMap: make(map[string]string),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func getOpts(opt ...Option) (options, []api.Option) {
|
|
|
|
|
opts := getDefaultOptions()
|
|
|
|
|
for _, o := range opt {
|
|
|
|
|
o(&opts)
|
|
|
|
|
}
|
|
|
|
|
var apiOpts []api.Option
|
|
|
|
|
return opts, apiOpts
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// If set, and if the version is zero during an update, the API will perform a
|
|
|
|
|
// fetch to get the current version of the resource and populate it during the
|
|
|
|
|
// update call. This is convenient but opens up the possibility for subtle
|
|
|
|
|
// order-of-modification issues, so use carefully.
|
2020-09-08 13:27:51 -07:00
|
|
|
func WithAutomaticVersioning(enable bool) Option {
|
2020-09-02 12:31:30 -07:00
|
|
|
return func(o *options) {
|
2020-09-08 13:27:51 -07:00
|
|
|
o.withAutomaticVersioning = enable
|
2020-09-02 12:31:30 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-15 15:20:49 -04:00
|
|
|
func WithAttributes(inAttributes map[string]interface{}) Option {
|
2020-09-02 12:31:30 -07:00
|
|
|
return func(o *options) {
|
2020-09-15 15:20:49 -04:00
|
|
|
o.postMap["attributes"] = inAttributes
|
2020-09-02 12:31:30 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-15 15:20:49 -04:00
|
|
|
func DefaultAttributes() Option {
|
2020-09-02 12:31:30 -07:00
|
|
|
return func(o *options) {
|
2020-09-15 15:20:49 -04:00
|
|
|
o.postMap["attributes"] = nil
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-19 10:31:49 -04:00
|
|
|
func WithConnectionIdleTimeoutDuration(inConnectionIdleTimeoutDuration uint32) Option {
|
|
|
|
|
return func(o *options) {
|
|
|
|
|
o.postMap["connection_idle_timeout_duration"] = inConnectionIdleTimeoutDuration
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func DefaultConnectionIdleTimeoutDuration() Option {
|
|
|
|
|
return func(o *options) {
|
|
|
|
|
o.postMap["connection_idle_timeout_duration"] = nil
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-15 15:20:49 -04:00
|
|
|
func WithTcpTargetDefaultPort(inDefaultPort uint32) Option {
|
|
|
|
|
return func(o *options) {
|
|
|
|
|
raw, ok := o.postMap["attributes"]
|
|
|
|
|
if !ok {
|
|
|
|
|
raw = interface{}(map[string]interface{}{})
|
|
|
|
|
}
|
|
|
|
|
val := raw.(map[string]interface{})
|
|
|
|
|
val["default_port"] = inDefaultPort
|
|
|
|
|
o.postMap["attributes"] = val
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func DefaultTcpTargetDefaultPort() Option {
|
|
|
|
|
return func(o *options) {
|
|
|
|
|
raw, ok := o.postMap["attributes"]
|
|
|
|
|
if !ok {
|
|
|
|
|
raw = interface{}(map[string]interface{}{})
|
|
|
|
|
}
|
|
|
|
|
val := raw.(map[string]interface{})
|
|
|
|
|
val["default_port"] = nil
|
|
|
|
|
o.postMap["attributes"] = val
|
2020-09-02 12:31:30 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func WithDescription(inDescription string) Option {
|
|
|
|
|
return func(o *options) {
|
|
|
|
|
o.postMap["description"] = inDescription
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func DefaultDescription() Option {
|
|
|
|
|
return func(o *options) {
|
|
|
|
|
o.postMap["description"] = nil
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-19 00:18:17 -04:00
|
|
|
func WithHostId(inHostId string) Option {
|
|
|
|
|
return func(o *options) {
|
|
|
|
|
o.postMap["host_id"] = inHostId
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-02 12:31:30 -07:00
|
|
|
func WithName(inName string) Option {
|
|
|
|
|
return func(o *options) {
|
|
|
|
|
o.postMap["name"] = inName
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func DefaultName() Option {
|
|
|
|
|
return func(o *options) {
|
|
|
|
|
o.postMap["name"] = nil
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-09-19 10:31:49 -04:00
|
|
|
|
|
|
|
|
func WithSessionConnectionLimit(inSessionConnectionLimit uint32) Option {
|
|
|
|
|
return func(o *options) {
|
|
|
|
|
o.postMap["session_connection_limit"] = inSessionConnectionLimit
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func DefaultSessionConnectionLimit() Option {
|
|
|
|
|
return func(o *options) {
|
|
|
|
|
o.postMap["session_connection_limit"] = nil
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func WithSessionMaxDuration(inSessionMaxDuration uint32) Option {
|
|
|
|
|
return func(o *options) {
|
|
|
|
|
o.postMap["session_max_duration"] = inSessionMaxDuration
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func DefaultSessionMaxDuration() Option {
|
|
|
|
|
return func(o *options) {
|
|
|
|
|
o.postMap["session_max_duration"] = nil
|
|
|
|
|
}
|
|
|
|
|
}
|