Add implicit-scopes resource type to cache (#5053)

This allows getting a list of scope IDs known by the cache via cached
targets and sessions. It is not refreshed from the controller. The name
contains `implicit` in case we ever want e.g. `scopes`.

(cherry picked from commit c0a318c58367d8ec55365447f41cf007eab64ce3)
This commit is contained in:
Jeff Mitchell authored and Timothy Messier committed 2024-09-24 14:18:53 +00:00
1 parent 4d8a7dd39a
commit b04de5ac4b
5 files changed
+318 -10

No files matched your search

+37 -3
View File
@@ -15,6 +15,7 @@ import (
"github.com/hashicorp/boundary/api"
"github.com/hashicorp/boundary/api/aliases"
"github.com/hashicorp/boundary/api/scopes"
"github.com/hashicorp/boundary/api/sessions"
"github.com/hashicorp/boundary/api/targets"
cachecmd "github.com/hashicorp/boundary/internal/clientcache/cmd/cache"
@@ -34,6 +35,7 @@ var (
"resolvable-aliases",
"targets",
"sessions",
"implicit-scopes",
}
errCacheNotRunning = stderrors.New("The cache process is not running.")
@@ -181,9 +183,6 @@ func (c *SearchCommand) Run(args []string) int {
return base.CommandCliError
}
default:
if result.Incomplete {
c.UI.Warn("The maximum result set size was reached and the search results are incomplete. Please narrow your search or adjust the -max-result-set-size parameter.")
}
switch {
case len(result.ResolvableAliases) > 0:
c.UI.Output(printAliasListTable(result.ResolvableAliases))
@@ -191,9 +190,17 @@ func (c *SearchCommand) Run(args []string) int {
c.UI.Output(printTargetListTable(result.Targets))
case len(result.Sessions) > 0:
c.UI.Output(printSessionListTable(result.Sessions))
case len(result.ImplicitScopes) > 0:
c.UI.Output(printImplicitScopesListTable(result.ImplicitScopes))
default:
c.UI.Output("No items found")
}
// Put this at the end or people may not see it as they may not scroll
// all the way up.
if result.Incomplete {
c.UI.Warn("The maximum result set size was reached and the search results are incomplete. Please narrow your search or adjust the -max-result-set-size parameter.")
}
}
return base.CommandSuccess
}
@@ -449,6 +456,33 @@ func printSessionListTable(items []*sessions.Session) string {
return base.WrapForHelpText(output)
}
func printImplicitScopesListTable(items []*scopes.Scope) string {
if len(items) == 0 {
return "No implicit scopes found"
}
var output []string
output = []string{
"",
"Scope information:",
}
for i, item := range items {
if i > 0 {
output = append(output, "")
}
if item.Id != "" {
output = append(output,
fmt.Sprintf(" ID: %s", item.Id),
)
} else {
output = append(output,
fmt.Sprintf(" ID: %s", "(not available)"),
)
}
}
return base.WrapForHelpText(output)
}
type filterBy struct {
flagFilter string
flagQuery string