-
Notifications
You must be signed in to change notification settings - Fork 289
/
Copy pathplugin_funcs.go
124 lines (110 loc) · 4.08 KB
/
plugin_funcs.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
package hostsetscmd
import (
"fmt"
"github.com/hashicorp/boundary/api/hostsets"
"github.com/hashicorp/boundary/internal/cmd/base"
"github.com/hashicorp/boundary/internal/libs/endpoint"
"github.com/hashicorp/go-secure-stdlib/parseutil"
)
func init() {
extraPluginActionsFlagsMapFunc = extraPluginActionsFlagsMapFuncImpl
extraPluginFlagsFunc = extraPluginFlagsFuncImpl
extraPluginFlagsHandlingFunc = extraPluginFlagsHandlingFuncImpl
}
type extraPluginCmdVars struct {
flagPreferredEndpoints []string
flagSyncInterval string
}
func extraPluginActionsFlagsMapFuncImpl() map[string][]string {
return map[string][]string{
"create": {"preferred-endpoint", "sync-interval"},
"update": {"preferred-endpoint", "sync-interval"},
}
}
func (c *PluginCommand) extraPluginHelpFunc(helpMap map[string]func() string) string {
var helpStr string
switch c.Func {
case "create":
helpStr = base.WrapForHelpText([]string{
"Usage: boundary host-sets create plugin [options] [args]",
"",
" Create a host set of a type provided by a plugin. Example:",
"",
` $ boundary host-sets create plugin -plugin-id plg_1234567890 -name prodops -description "Plugin host-set for ProdOps"`,
"",
"",
})
case "update":
helpStr = base.WrapForHelpText([]string{
"Usage: boundary host-sets update plugin [options] [args]",
"",
" Update a host set of a type provided by a plugin given its ID. Example:",
"",
` $ boundary host-sets update plugin -id hsplg_1234567890 -name "devops" -description "Plugin host-set for DevOps"`,
"",
"",
})
default:
helpStr = helpMap[c.Func]()
}
return helpStr + c.Flags().Help()
}
func extraPluginFlagsFuncImpl(c *PluginCommand, set *base.FlagSets, f *base.FlagSet) {
fs := set.NewFlagSet("Plugin Host-Set Options")
for _, name := range flagsPluginMap[c.Func] {
switch name {
case "preferred-endpoint":
fs.StringSliceVar(&base.StringSliceVar{
Name: "preferred-endpoint",
Target: &c.flagPreferredEndpoints,
Usage: `An endpoint preference, specified by "cidr:<valid IPv4/6 CIDR>" ` +
`or "dns:<globbed name>", specifying which IP address or DNS name out ` +
`of a host's available possibilities should be preferred. May be specified ` +
`multiple times, which will build up an in-order set of preferences. ` +
`If no preferences are specified, a value will be chosen from among all ` +
`available values using a built-in priority order. May not be valid ` +
`for all plugin types.`,
})
case "sync-interval":
fs.StringVar(&base.StringVar{
Name: "sync-interval",
Target: &c.flagSyncInterval,
Usage: `An interger number of seconds, or a string such as "400s", "5m", or "6h", ` +
"indicating the amount of time that should elapse between syncs of the host set. " +
"The interval will be applied to the end of the previous sync operation, not the start. " +
"Setting to any negative value will disable syncing for that host set; setting to null " +
"will cause the set to use Boundary's default. The default may change between releases.",
})
}
}
}
func extraPluginFlagsHandlingFuncImpl(c *PluginCommand, _ *base.FlagSets, opts *[]hostsets.Option) bool {
switch len(c.flagPreferredEndpoints) {
case 0:
case 1:
if c.flagPreferredEndpoints[0] == "null" {
*opts = append(*opts, hostsets.DefaultPreferredEndpoints())
break
}
fallthrough
default:
if _, err := endpoint.NewPreferencer(c.Context, endpoint.WithPreferenceOrder(c.flagPreferredEndpoints)); err != nil {
c.UI.Error(fmt.Sprintf("Unable to successfully validate preferred endpoints: %s", err))
return false
}
*opts = append(*opts, hostsets.WithPreferredEndpoints(c.flagPreferredEndpoints))
}
switch c.flagSyncInterval {
case "":
case "null":
*opts = append(*opts, hostsets.DefaultSyncIntervalSeconds())
default:
interval, err := parseutil.ParseDurationSecond(c.flagSyncInterval)
if err != nil {
c.UI.Error(fmt.Sprintf("Unable to successfully parse given sync interval: %s", err))
return false
}
*opts = append(*opts, hostsets.WithSyncIntervalSeconds(int32(interval.Seconds())))
}
return true
}