Add recursive listing to roles (#881)

This also lays the framework for adding recursive listing to the rest of the resources.
This commit is contained in:
Jeff Mitchell authored and GitHub committed 2021-01-23 13:39:04 -05:00
1 parent 0629526319
commit 6b58a3317d
18 files changed
+430 -511

No files matched your search

+1
View File
@@ -76,6 +76,7 @@ type Command struct {
FlagAuthMethodId string
FlagHostCatalogId string
FlagVersion int
FlagRecursive bool
client *api.Client
}
+14 -2
View File
@@ -24,7 +24,6 @@ type Command struct {
Func string
flagScope string
flagGrantScopeId string
flagPrincipals []string
flagGrants []string
@@ -58,7 +57,7 @@ var flagsMap = map[string][]string{
"update": {"id", "name", "description", "grantscopeid", "version"},
"read": {"id"},
"delete": {"id"},
"list": {"scope-id"},
"list": {"scope-id", "recursive"},
"add-principals": {"id", "principal", "version"},
"set-principals": {"id", "principal", "version"},
"remove-principals": {"id", "principal", "version"},
@@ -141,6 +140,10 @@ func (c *Command) Run(args []string) int {
default:
opts = append(opts, roles.WithGrantScopeId(c.flagGrantScopeId))
}
switch c.FlagRecursive {
case true:
opts = append(opts, roles.WithRecursive(true))
}
principals := c.flagPrincipals
grants := c.flagGrants
@@ -301,6 +304,15 @@ func (c *Command) Run(args []string) int {
if true {
output = append(output,
fmt.Sprintf(" ID: %s", r.Id),
)
}
if c.FlagRecursive {
output = append(output,
fmt.Sprintf(" Scope ID: %s", r.Scope.Id),
)
}
if true {
output = append(output,
fmt.Sprintf(" Version: %d", r.Version),
)
}
+6
View File
@@ -65,6 +65,12 @@ func PopulateCommonFlags(c *base.Command, f *base.FlagSet, resourceType string,
Target: &c.FlagHostCatalogId,
Usage: "The host-catalog resource to use for the operation.",
})
case "recursive":
f.BoolVar(&base.BoolVar{
Name: "recursive",
Target: &c.FlagRecursive,
Usage: "If set, the list operation will be applied recursively into child scopes, if supported by the type.",
})
}
}
}