Files
threshold/internal/cmd/commands/scopes/funcs.go
T

64 lines
1.4 KiB
Go

package scopes
import (
"fmt"
"sort"
"time"
"github.com/hashicorp/boundary/api/scopes"
"github.com/hashicorp/boundary/internal/cmd/base"
)
func generateScopeTableOutput(in *scopes.Scope) string {
nonAttributeMap := map[string]interface{}{
"ID": in.Id,
"Version": in.Version,
"Created Time": in.CreatedTime.Local().Format(time.RFC1123),
"Updated Time": in.UpdatedTime.Local().Format(time.RFC1123),
}
if in.Name != "" {
nonAttributeMap["Name"] = in.Name
}
if in.Description != "" {
nonAttributeMap["Description"] = in.Description
}
maxLength := base.MaxAttributesLength(nonAttributeMap, nil, nil)
ret := []string{
"",
"Scope information:",
base.WrapMap(2, maxLength+2, nonAttributeMap),
"",
" Scope (parent):",
base.ScopeInfoForOutput(in.Scope, maxLength),
}
if len(in.AuthorizedActions) > 0 {
ret = append(ret,
"",
" Authorized Actions:",
base.WrapSlice(4, in.AuthorizedActions),
"",
)
}
if len(in.AuthorizedCollectionActions) > 0 {
keys := make([]string, 0, len(in.AuthorizedCollectionActions))
for k := range in.AuthorizedCollectionActions {
keys = append(keys, k)
}
sort.Strings(keys)
ret = append(ret, " Authorized Actions on Scope's Collections:")
for _, key := range keys {
ret = append(ret,
fmt.Sprintf(" %ss:", key),
base.WrapSlice(6, in.AuthorizedCollectionActions[key]),
)
}
}
return base.WrapForHelpText(ret)
}