feat(cmd): Support plugin host catalog worker filter
This commit is contained in:
1 parent
b8046a3ef3
commit
c3d03f69d8
4 files changed
+70
No files matched your search
@@ -111,6 +111,11 @@ func (c *Command) printListTable(items []*hostcatalogs.HostCatalog) string {
|
||||
fmt.Sprintf(" Description: %s", m.Description),
|
||||
)
|
||||
}
|
||||
if m.WorkerFilter != "" {
|
||||
output = append(output,
|
||||
fmt.Sprintf(" Worker Filter: %s", m.WorkerFilter),
|
||||
)
|
||||
}
|
||||
if len(m.AuthorizedActions) > 0 {
|
||||
output = append(output,
|
||||
" Authorized Actions:",
|
||||
@@ -151,6 +156,9 @@ func printItemTable(item *hostcatalogs.HostCatalog, resp *api.Response) string {
|
||||
if item.SecretsHmac != "" {
|
||||
nonAttributeMap["Secrets HMAC"] = item.SecretsHmac
|
||||
}
|
||||
if item.WorkerFilter != "" {
|
||||
nonAttributeMap["Worker Filter"] = item.WorkerFilter
|
||||
}
|
||||
|
||||
maxLength := base.MaxAttributesLength(nonAttributeMap, item.Attributes, keySubstMap)
|
||||
|
||||
|
||||
@@ -4,9 +4,68 @@
|
||||
package hostcatalogscmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/hashicorp/boundary/api/hostcatalogs"
|
||||
"github.com/hashicorp/boundary/internal/cmd/base"
|
||||
"github.com/hashicorp/go-bexpr"
|
||||
)
|
||||
|
||||
func init() {
|
||||
extraPluginFlagsFunc = extraPluginFlagsFuncImpl
|
||||
extraPluginActionsFlagsMapFunc = extraPluginActionsFlagsMapFuncImpl
|
||||
extraPluginFlagsHandlingFunc = extraPluginFlagHandlingFuncImpl
|
||||
}
|
||||
|
||||
const (
|
||||
workerFilterFlagName = "worker-filter"
|
||||
)
|
||||
|
||||
type extraPluginCmdVars struct {
|
||||
flagWorkerFilter string
|
||||
}
|
||||
|
||||
func extraPluginActionsFlagsMapFuncImpl() map[string][]string {
|
||||
flags := map[string][]string{
|
||||
"create": {
|
||||
workerFilterFlagName,
|
||||
},
|
||||
}
|
||||
flags["update"] = flags["create"]
|
||||
return flags
|
||||
}
|
||||
|
||||
func extraPluginFlagsFuncImpl(c *PluginCommand, set *base.FlagSets, _ *base.FlagSet) {
|
||||
f := set.NewFlagSet("Plugin Host Catalog Options")
|
||||
|
||||
for _, name := range flagsPluginMap[c.Func] {
|
||||
switch name {
|
||||
case workerFilterFlagName:
|
||||
f.StringVar(&base.StringVar{
|
||||
Name: workerFilterFlagName,
|
||||
Target: &c.flagWorkerFilter,
|
||||
Usage: `A boolean expression to filter which workers can handle dynamic host catalog commands for this host catalog.`,
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func extraPluginFlagHandlingFuncImpl(c *PluginCommand, f *base.FlagSets, opts *[]hostcatalogs.Option) bool {
|
||||
switch c.flagWorkerFilter {
|
||||
case "":
|
||||
case "null":
|
||||
*opts = append(*opts, hostcatalogs.DefaultWorkerFilter())
|
||||
default:
|
||||
if _, err := bexpr.CreateEvaluator(c.flagWorkerFilter); err != nil {
|
||||
c.UI.Error(fmt.Sprintf("Unable to successfully parse filter expression: %s", err))
|
||||
return false
|
||||
}
|
||||
*opts = append(*opts, hostcatalogs.WithWorkerFilter(c.flagWorkerFilter))
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
func (c *PluginCommand) extraPluginHelpFunc(helpMap map[string]func() string) string {
|
||||
var helpStr string
|
||||
switch c.Func {
|
||||
|
||||
@@ -37,6 +37,8 @@ type PluginCommand struct {
|
||||
Func string
|
||||
|
||||
plural string
|
||||
|
||||
extraPluginCmdVars
|
||||
}
|
||||
|
||||
func (c *PluginCommand) AutocompleteArgs() complete.Predictor {
|
||||
|
||||
@@ -460,6 +460,7 @@ var inputStructs = map[string][]*cmdInfo{
|
||||
SubActionPrefix: "plugin",
|
||||
SkipNormalHelp: true,
|
||||
HasExtraHelpFunc: true,
|
||||
HasExtraCommandVars: true,
|
||||
HasId: true,
|
||||
HasName: true,
|
||||
HasDescription: true,
|
||||
|
||||
Reference in new issue
Block a user