2020-07-14 14:32:47 -07:00
|
|
|
package scopes
|
|
|
|
|
|
|
|
|
|
import (
|
2021-01-20 10:53:01 -05:00
|
|
|
"fmt"
|
|
|
|
|
"sort"
|
2020-07-14 14:32:47 -07:00
|
|
|
"time"
|
|
|
|
|
|
2020-08-10 17:15:02 -04:00
|
|
|
"github.com/hashicorp/boundary/api/scopes"
|
|
|
|
|
"github.com/hashicorp/boundary/internal/cmd/base"
|
2020-07-14 14:32:47 -07:00
|
|
|
)
|
|
|
|
|
|
2020-08-13 11:20:22 -04:00
|
|
|
func generateScopeTableOutput(in *scopes.Scope) string {
|
2020-08-28 01:28:26 -04:00
|
|
|
nonAttributeMap := map[string]interface{}{
|
|
|
|
|
"ID": in.Id,
|
|
|
|
|
"Version": in.Version,
|
2020-09-23 03:01:39 -04:00
|
|
|
"Created Time": in.CreatedTime.Local().Format(time.RFC1123),
|
|
|
|
|
"Updated Time": in.UpdatedTime.Local().Format(time.RFC1123),
|
2020-07-14 14:32:47 -07:00
|
|
|
}
|
2020-08-28 01:28:26 -04:00
|
|
|
|
2020-08-07 12:55:02 -04:00
|
|
|
if in.Name != "" {
|
2020-08-28 01:28:26 -04:00
|
|
|
nonAttributeMap["Name"] = in.Name
|
2020-07-14 14:32:47 -07:00
|
|
|
}
|
2020-08-07 12:55:02 -04:00
|
|
|
if in.Description != "" {
|
2020-08-28 01:28:26 -04:00
|
|
|
nonAttributeMap["Description"] = in.Description
|
2020-07-14 14:32:47 -07:00
|
|
|
}
|
|
|
|
|
|
2020-09-23 03:01:39 -04:00
|
|
|
maxLength := base.MaxAttributesLength(nonAttributeMap, nil, nil)
|
2020-08-28 01:28:26 -04:00
|
|
|
|
2020-09-23 03:01:39 -04:00
|
|
|
ret := []string{
|
|
|
|
|
"",
|
|
|
|
|
"Scope information:",
|
|
|
|
|
base.WrapMap(2, maxLength+2, nonAttributeMap),
|
|
|
|
|
"",
|
|
|
|
|
" Scope (parent):",
|
|
|
|
|
base.ScopeInfoForOutput(in.Scope, maxLength),
|
|
|
|
|
}
|
2020-08-28 01:28:26 -04:00
|
|
|
|
2021-01-20 10:53:01 -05:00
|
|
|
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,
|
2021-02-05 09:41:48 -08:00
|
|
|
fmt.Sprintf(" %s:", key),
|
2021-01-20 10:53:01 -05:00
|
|
|
base.WrapSlice(6, in.AuthorizedCollectionActions[key]),
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-14 14:32:47 -07:00
|
|
|
return base.WrapForHelpText(ret)
|
|
|
|
|
}
|