Add support for recursive listing (#885)

This commit is contained in:
Jeff Mitchell authored and GitHub committed 2021-01-25 19:37:40 -05:00
1 parent 1f9fcad1cd
commit 6cd97a4a6e
77 files changed
+2244 -1448

No files matched your search

@@ -32,7 +32,7 @@ func (c *Command) Synopsis() string {
var flagsMap = map[string][]string{
"read": {"id"},
"delete": {"id"},
"list": {"scope-id"},
"list": {"scope-id", "recursive"},
}
func (c *Command) Help() string {
@@ -138,7 +138,6 @@ func (c *Command) Run(args []string) int {
default:
opts = append(opts, authmethods.WithName(c.FlagName))
}
switch c.FlagDescription {
case "":
case "null":
@@ -146,6 +145,10 @@ func (c *Command) Run(args []string) int {
default:
opts = append(opts, authmethods.WithDescription(c.FlagDescription))
}
switch c.FlagRecursive {
case true:
opts = append(opts, authmethods.WithRecursive(true))
}
authmethodClient := authmethods.NewClient(client)
@@ -230,9 +233,14 @@ func (c *Command) Run(args []string) int {
fmt.Sprintf(" ID: %s", m.Id),
)
}
if m.Description != "" {
if c.FlagRecursive {
output = append(output,
fmt.Sprintf(" Description: %s", m.Description),
fmt.Sprintf(" Scope ID: %s", m.Scope.Id),
)
}
if true {
output = append(output,
fmt.Sprintf(" Version: %d", m.Version),
)
}
if m.Name != "" {
@@ -240,6 +248,11 @@ func (c *Command) Run(args []string) int {
fmt.Sprintf(" Name: %s", m.Name),
)
}
if m.Description != "" {
output = append(output,
fmt.Sprintf(" Description: %s", m.Description),
)
}
if true {
output = append(output,
fmt.Sprintf(" Type: %s", m.Type),
+31 -13
View File
@@ -33,7 +33,7 @@ func (c *Command) Synopsis() string {
var flagsMap = map[string][]string{
"read": {"id"},
"delete": {"id"},
"list": {"scope-id"},
"list": {"scope-id", "recursive"},
}
func (c *Command) Help() string {
@@ -92,21 +92,28 @@ func (c *Command) Run(args []string) int {
authtokenClient := authtokens.NewClient(client)
var opts []authtokens.Option
switch c.FlagRecursive {
case true:
opts = append(opts, authtokens.WithRecursive(true))
}
existed := true
var result api.GenericResult
var listResult api.GenericListResult
switch c.Func {
case "read":
result, err = authtokenClient.Read(c.Context, c.FlagId)
result, err = authtokenClient.Read(c.Context, c.FlagId, opts...)
case "delete":
_, err = authtokenClient.Delete(c.Context, c.FlagId)
_, err = authtokenClient.Delete(c.Context, c.FlagId, opts...)
if apiErr := api.AsServerError(err); apiErr != nil && apiErr.ResponseStatus() == http.StatusNotFound {
existed = false
err = nil
}
case "list":
listResult, err = authtokenClient.List(c.Context, c.FlagScopeId)
listResult, err = authtokenClient.List(c.Context, c.FlagScopeId, opts...)
}
plural := "auth token"
@@ -168,15 +175,26 @@ func (c *Command) Run(args []string) int {
if i > 0 {
output = append(output, "")
}
output = append(output,
fmt.Sprintf(" ID: %s", t.Id),
fmt.Sprintf(" Approximate Last Used Time: %s", t.ApproximateLastUsedTime.Local().Format(time.RFC1123)),
fmt.Sprintf(" Auth Method ID: %s", t.AuthMethodId),
fmt.Sprintf(" Created Time: %s", t.CreatedTime.Local().Format(time.RFC1123)),
fmt.Sprintf(" Expiration Time: %s", t.ExpirationTime.Local().Format(time.RFC1123)),
fmt.Sprintf(" Updated Time: %s", t.UpdatedTime.Local().Format(time.RFC1123)),
fmt.Sprintf(" User ID: %s", t.UserId),
)
if true {
output = append(output,
fmt.Sprintf(" ID: %s", t.Id),
)
}
if c.FlagRecursive {
output = append(output,
fmt.Sprintf(" Scope ID: %s", t.Scope.Id),
)
}
if true {
output = append(output,
fmt.Sprintf(" Approximate Last Used Time: %s", t.ApproximateLastUsedTime.Local().Format(time.RFC1123)),
fmt.Sprintf(" Auth Method ID: %s", t.AuthMethodId),
fmt.Sprintf(" Created Time: %s", t.CreatedTime.Local().Format(time.RFC1123)),
fmt.Sprintf(" Expiration Time: %s", t.ExpirationTime.Local().Format(time.RFC1123)),
fmt.Sprintf(" Updated Time: %s", t.UpdatedTime.Local().Format(time.RFC1123)),
fmt.Sprintf(" User ID: %s", t.UserId),
)
}
if len(t.AuthorizedActions) > 0 {
output = append(output,
" Authorized Actions:",
+14 -2
View File
@@ -48,7 +48,7 @@ var flagsMap = map[string][]string{
"update": {"id", "name", "description", "version"},
"read": {"id"},
"delete": {"id"},
"list": {"scope-id"},
"list": {"scope-id", "recursive"},
"add-members": {"id", "member", "version"},
"set-members": {"id", "member", "version"},
"remove-members": {"id", "member", "version"},
@@ -114,7 +114,6 @@ func (c *Command) Run(args []string) int {
default:
opts = append(opts, groups.WithName(c.FlagName))
}
switch c.FlagDescription {
case "":
case "null":
@@ -122,6 +121,10 @@ func (c *Command) Run(args []string) int {
default:
opts = append(opts, groups.WithDescription(c.FlagDescription))
}
switch c.FlagRecursive {
case true:
opts = append(opts, groups.WithRecursive(true))
}
members := c.flagMembers
switch c.Func {
@@ -248,6 +251,15 @@ func (c *Command) Run(args []string) int {
if true {
output = append(output,
fmt.Sprintf(" ID: %s", g.Id),
)
}
if c.FlagRecursive {
output = append(output,
fmt.Sprintf(" Scope ID: %s", g.Scope.Id),
)
}
if true {
output = append(output,
fmt.Sprintf(" Version: %d", g.Version),
)
}
@@ -32,7 +32,7 @@ func (c *Command) Synopsis() string {
var flagsMap = map[string][]string{
"read": {"id"},
"delete": {"id"},
"list": {"scope-id"},
"list": {"scope-id", "recursive"},
}
func (c *Command) Help() string {
@@ -139,7 +139,6 @@ func (c *Command) Run(args []string) int {
default:
opts = append(opts, hostcatalogs.WithName(c.FlagName))
}
switch c.FlagDescription {
case "":
case "null":
@@ -147,6 +146,10 @@ func (c *Command) Run(args []string) int {
default:
opts = append(opts, hostcatalogs.WithDescription(c.FlagDescription))
}
switch c.FlagRecursive {
case true:
opts = append(opts, hostcatalogs.WithRecursive(true))
}
hostcatalogClient := hostcatalogs.NewClient(client)
@@ -229,6 +232,15 @@ func (c *Command) Run(args []string) int {
if true {
output = append(output,
fmt.Sprintf(" ID: %s", m.Id),
)
}
if c.FlagRecursive {
output = append(output,
fmt.Sprintf(" Scope ID: %s", m.Scope.Id),
)
}
if true {
output = append(output,
fmt.Sprintf(" Version: %d", m.Version),
fmt.Sprintf(" Type: %s", m.Type),
)
+5 -4
View File
@@ -133,6 +133,11 @@ func (c *Command) Run(args []string) int {
default:
opts = append(opts, roles.WithDescription(c.FlagDescription))
}
switch c.FlagRecursive {
case true:
opts = append(opts, roles.WithRecursive(true))
}
switch c.flagGrantScopeId {
case "":
case "null":
@@ -140,10 +145,6 @@ 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
+14 -2
View File
@@ -37,7 +37,7 @@ var flagsMap = map[string][]string{
"update": {"id", "name", "description", "version"},
"read": {"id"},
"delete": {"id"},
"list": {"scope-id"},
"list": {"scope-id", "recursive"},
}
func (c *Command) Help() string {
@@ -113,7 +113,6 @@ func (c *Command) Run(args []string) int {
default:
opts = append(opts, scopes.WithName(c.FlagName))
}
switch c.FlagDescription {
case "":
case "null":
@@ -121,6 +120,10 @@ func (c *Command) Run(args []string) int {
default:
opts = append(opts, scopes.WithDescription(c.FlagDescription))
}
switch c.FlagRecursive {
case true:
opts = append(opts, scopes.WithRecursive(true))
}
if c.flagSkipAdminRoleCreation {
opts = append(opts, scopes.WithSkipAdminRoleCreation(c.flagSkipAdminRoleCreation))
@@ -228,6 +231,15 @@ func (c *Command) Run(args []string) int {
if true {
output = append(output,
fmt.Sprintf(" ID: %s", s.Id),
)
}
if c.FlagRecursive {
output = append(output,
fmt.Sprintf(" Scope ID: %s", s.Scope.Id),
)
}
if true {
output = append(output,
fmt.Sprintf(" Version: %d", s.Version),
)
}
+31 -13
View File
@@ -32,7 +32,7 @@ func (c *Command) Synopsis() string {
var flagsMap = map[string][]string{
"read": {"id"},
"cancel": {"id"},
"list": {"scope-id"},
"list": {"scope-id", "recursive"},
}
func (c *Command) Help() string {
@@ -112,16 +112,23 @@ func (c *Command) Run(args []string) int {
sessionClient := sessions.NewClient(client)
var opts []sessions.Option
switch c.FlagRecursive {
case true:
opts = append(opts, sessions.WithRecursive(true))
}
var result api.GenericResult
var listResult api.GenericListResult
switch c.Func {
case "read":
result, err = sessionClient.Read(c.Context, c.FlagId)
result, err = sessionClient.Read(c.Context, c.FlagId, opts...)
case "cancel":
result, err = sessionClient.Cancel(c.Context, c.FlagId, 0, sessions.WithAutomaticVersioning(true))
result, err = sessionClient.Cancel(c.Context, c.FlagId, 0, append(opts, sessions.WithAutomaticVersioning(true))...)
case "list":
listResult, err = sessionClient.List(c.Context, c.FlagScopeId)
listResult, err = sessionClient.List(c.Context, c.FlagScopeId, opts...)
}
plural := "session"
@@ -167,15 +174,26 @@ func (c *Command) Run(args []string) int {
if i > 0 {
output = append(output, "")
}
output = append(output,
fmt.Sprintf(" ID: %s", t.Id),
fmt.Sprintf(" Status: %s", t.Status),
fmt.Sprintf(" Created Time: %s", t.CreatedTime.Local().Format(time.RFC1123)),
fmt.Sprintf(" Expiration Time: %s", t.ExpirationTime.Local().Format(time.RFC1123)),
fmt.Sprintf(" Updated Time: %s", t.UpdatedTime.Local().Format(time.RFC1123)),
fmt.Sprintf(" User ID: %s", t.UserId),
fmt.Sprintf(" Target ID: %s", t.TargetId),
)
if true {
output = append(output,
fmt.Sprintf(" ID: %s", t.Id),
)
}
if c.FlagRecursive {
output = append(output,
fmt.Sprintf(" Scope ID: %s", t.Scope.Id),
)
}
if true {
output = append(output,
fmt.Sprintf(" Status: %s", t.Status),
fmt.Sprintf(" Created Time: %s", t.CreatedTime.Local().Format(time.RFC1123)),
fmt.Sprintf(" Expiration Time: %s", t.ExpirationTime.Local().Format(time.RFC1123)),
fmt.Sprintf(" Updated Time: %s", t.UpdatedTime.Local().Format(time.RFC1123)),
fmt.Sprintf(" User ID: %s", t.UserId),
fmt.Sprintf(" Target ID: %s", t.TargetId),
)
}
if len(t.AuthorizedActions) > 0 {
output = append(output,
" Authorized Actions:",
+20 -8
View File
@@ -44,7 +44,7 @@ var flagsMap = map[string][]string{
"authorize-session": {"id", "host-id"},
"read": {"id"},
"delete": {"id"},
"list": {"scope-id"},
"list": {"scope-id", "recursive"},
"add-host-sets": {"id", "host-set", "version"},
"remove-host-sets": {"id", "host-set", "version"},
"set-host-sets": {"id", "host-set", "version"},
@@ -281,13 +281,6 @@ func (c *Command) Run(args []string) int {
default:
opts = append(opts, targets.WithName(c.FlagName))
}
switch c.FlagScopeName {
case "":
default:
opts = append(opts, targets.WithScopeName(c.FlagScopeName))
}
switch c.FlagDescription {
case "":
case "null":
@@ -295,6 +288,16 @@ func (c *Command) Run(args []string) int {
default:
opts = append(opts, targets.WithDescription(c.FlagDescription))
}
switch c.FlagRecursive {
case true:
opts = append(opts, targets.WithRecursive(true))
}
switch c.FlagScopeName {
case "":
default:
opts = append(opts, targets.WithScopeName(c.FlagScopeName))
}
hostSets := c.flagHostSets
switch c.Func {
@@ -428,6 +431,15 @@ func (c *Command) Run(args []string) int {
if true {
output = append(output,
fmt.Sprintf(" ID: %s", m.Id),
)
}
if c.FlagRecursive {
output = append(output,
fmt.Sprintf(" Scope ID: %s", m.Scope.Id),
)
}
if true {
output = append(output,
fmt.Sprintf(" Version: %d", m.Version),
fmt.Sprintf(" Type: %s", m.Type),
)
+14 -2
View File
@@ -48,7 +48,7 @@ var flagsMap = map[string][]string{
"update": {"id", "name", "description", "version"},
"read": {"id"},
"delete": {"id"},
"list": {"scope-id"},
"list": {"scope-id", "recursive"},
"add-accounts": {"id", "account", "version"},
"set-accounts": {"id", "account", "version"},
"remove-accounts": {"id", "account", "version"},
@@ -114,7 +114,6 @@ func (c *Command) Run(args []string) int {
default:
opts = append(opts, users.WithName(c.FlagName))
}
switch c.FlagDescription {
case "":
case "null":
@@ -122,6 +121,10 @@ func (c *Command) Run(args []string) int {
default:
opts = append(opts, users.WithDescription(c.FlagDescription))
}
switch c.FlagRecursive {
case true:
opts = append(opts, users.WithRecursive(true))
}
accounts := c.flagAccounts
switch c.Func {
@@ -248,6 +251,15 @@ func (c *Command) Run(args []string) int {
if true {
output = append(output,
fmt.Sprintf(" ID: %s", u.Id),
)
}
if c.FlagRecursive {
output = append(output,
fmt.Sprintf(" Scope ID: %s", u.Scope.Id),
)
}
if true {
output = append(output,
fmt.Sprintf(" Version: %d", u.Version),
)
}