Update CLI output functions to show scope info and cleanup (#416)

This commit is contained in:
Jeff Mitchell authored and GitHub committed 2020-09-23 03:01:39 -04:00
1 parent 38ce9d9eac
commit 03436a73de
15 files changed
+222 -295

No files matched your search

+44
View File
@@ -9,6 +9,7 @@ import (
"unicode"
"unicode/utf8"
"github.com/hashicorp/boundary/api/scopes"
"github.com/mitchellh/cli"
"github.com/mitchellh/go-wordwrap"
)
@@ -16,6 +17,46 @@ import (
// This is adapted from the code in the strings package for TrimSpace
var asciiSpace = [256]uint8{'\t': 1, '\n': 1, '\v': 1, '\f': 1, '\r': 1, ' ': 1}
func ScopeInfoForOutput(scp *scopes.ScopeInfo, maxLength int) string {
vals := map[string]interface{}{
"ID": scp.Id,
"Type": scp.Type,
"Name": scp.Name,
}
if scp.ParentScopeId != "" {
vals["Parent Scope ID"] = scp.ParentScopeId
}
return WrapMap(4, maxLength, vals)
}
func MaxAttributesLength(nonAttributesMap, attributesMap map[string]interface{}, keySubstMap map[string]string) int {
// We always print a scope ID and in some cases this particular key ends up
// being the longest key, so start with it as a baseline. It's always
// indented by 2 in addition to the normal offset so take that into account.
maxLength := len("Parent Scope ID") + 2
for k := range nonAttributesMap {
if len(k) > maxLength {
maxLength = len(k)
}
}
if len(attributesMap) > 0 {
for k, v := range attributesMap {
if keySubstMap != nil {
if keySubstMap[k] != "" {
attributesMap[keySubstMap[k]] = v
delete(attributesMap, k)
}
}
}
for k := range attributesMap {
if len(k) > maxLength {
maxLength = len(k)
}
}
}
return maxLength
}
func trimSpaceRight(in string) string {
for stop := len(in); stop > 0; stop-- {
c := in[stop-1]
@@ -78,6 +119,9 @@ func WrapMap(prefixSpaces, maxLengthOverride int, input map[string]interface{})
for _, k := range sortedKeys {
v := input[k]
spaces := maxKeyLength - len(k)
if spaces < 0 {
spaces = 0
}
ret = append(ret, fmt.Sprintf("%s%s%s%s",
strings.Repeat(" ", prefixSpaces),
fmt.Sprintf("%s: ", k),
+12 -36
View File
@@ -1,7 +1,6 @@
package accounts
import (
"fmt"
"time"
"github.com/hashicorp/boundary/api/accounts"
@@ -9,15 +8,12 @@ import (
)
func generateAccountTableOutput(in *accounts.Account) string {
var ret []string
nonAttributeMap := map[string]interface{}{
"ID": in.Id,
"Scope ID": in.Scope.Id,
"Version": in.Version,
"Type": in.Type,
"Created Time": in.CreatedTime.Local().Format(time.RFC3339),
"Updated Time": in.UpdatedTime.Local().Format(time.RFC3339),
"Created Time": in.CreatedTime.Local().Format(time.RFC1123),
"Updated Time": in.UpdatedTime.Local().Format(time.RFC1123),
"Auth Method ID": in.AuthMethodId,
}
@@ -28,40 +24,20 @@ func generateAccountTableOutput(in *accounts.Account) string {
nonAttributeMap["Description"] = in.Description
}
maxLength := 0
for k := range nonAttributeMap {
if len(k) > maxLength {
maxLength = len(k)
}
}
if len(in.Attributes) > 0 {
for k, v := range in.Attributes {
if attributeMap[k] != "" {
in.Attributes[attributeMap[k]] = v
delete(in.Attributes, k)
}
}
for k := range in.Attributes {
if len(k) > maxLength {
maxLength = len(k)
}
}
}
maxLength := base.MaxAttributesLength(nonAttributeMap, in.Attributes, keySubstMap)
ret = append(ret, "", "Account information:")
ret = append(ret,
// We do +2 because there is another +2 offset for attributes below
ret := []string{
"",
"Account information:",
base.WrapMap(2, maxLength+2, nonAttributeMap),
)
" Scope:",
base.ScopeInfoForOutput(in.Scope, maxLength),
}
if len(in.Attributes) > 0 {
if true {
ret = append(ret,
fmt.Sprintf(" Attributes: %s", ""),
)
}
ret = append(ret,
"",
" Attributes:",
base.WrapMap(4, maxLength, in.Attributes),
)
}
@@ -69,6 +45,6 @@ func generateAccountTableOutput(in *accounts.Account) string {
return base.WrapForHelpText(ret)
}
var attributeMap = map[string]string{
var keySubstMap = map[string]string{
"login_name": "Login Name",
}
@@ -141,7 +141,7 @@ func (c *PasswordCommand) Run(args []string) int {
c.UI.Output(base.WrapForHelpText([]string{
"",
"Authentication information:",
fmt.Sprintf(" Expiration Time: %s", token.ExpirationTime.Local().Format(time.RFC3339)),
fmt.Sprintf(" Expiration Time: %s", token.ExpirationTime.Local().Format(time.RFC1123)),
fmt.Sprintf(" Token: %s", token.Token),
fmt.Sprintf(" User ID: %s", token.UserId),
}))
+12 -36
View File
@@ -1,7 +1,6 @@
package authmethods
import (
"fmt"
"time"
"github.com/hashicorp/boundary/api/authmethods"
@@ -22,15 +21,12 @@ func addPasswordFlags(c *PasswordCommand, f *base.FlagSet) {
}
func generateAuthMethodTableOutput(in *authmethods.AuthMethod) string {
var ret []string
nonAttributeMap := map[string]interface{}{
"ID": in.Id,
"Scope ID": in.Scope.Id,
"Version": in.Version,
"Type": in.Type,
"Created Time": in.CreatedTime.Local().Format(time.RFC3339),
"Updated Time": in.UpdatedTime.Local().Format(time.RFC3339),
"Created Time": in.CreatedTime.Local().Format(time.RFC1123),
"Updated Time": in.UpdatedTime.Local().Format(time.RFC1123),
}
if in.Name != "" {
@@ -40,40 +36,20 @@ func generateAuthMethodTableOutput(in *authmethods.AuthMethod) string {
nonAttributeMap["Description"] = in.Description
}
maxLength := 0
for k := range nonAttributeMap {
if len(k) > maxLength {
maxLength = len(k)
}
}
if len(in.Attributes) > 0 {
for k, v := range in.Attributes {
if attributeMap[k] != "" {
in.Attributes[attributeMap[k]] = v
delete(in.Attributes, k)
}
}
for k := range in.Attributes {
if len(k) > maxLength {
maxLength = len(k)
}
}
}
maxLength := base.MaxAttributesLength(nonAttributeMap, in.Attributes, keySubstMap)
ret = append(ret, "", "Auth method information:")
ret = append(ret,
// We do +2 because there is another +2 offset for attributes below
ret := []string{
"",
"Auth Method information:",
base.WrapMap(2, maxLength+2, nonAttributeMap),
)
"",
" Scope:",
base.ScopeInfoForOutput(in.Scope, maxLength),
}
if len(in.Attributes) > 0 {
if true {
ret = append(ret,
fmt.Sprintf(" Attributes: %s", ""),
)
}
ret = append(ret,
" Attributes:",
base.WrapMap(4, maxLength, in.Attributes),
)
}
@@ -81,7 +57,7 @@ func generateAuthMethodTableOutput(in *authmethods.AuthMethod) string {
return base.WrapForHelpText(ret)
}
var attributeMap = map[string]string{
var keySubstMap = map[string]string{
"min_login_name_length": "Minimum Login Name Length",
"min_password_length": "Minimum Password Length",
}
+12 -16
View File
@@ -10,28 +10,24 @@ import (
func generateAuthTokenTableOutput(in *authtokens.AuthToken) string {
nonAttributeMap := map[string]interface{}{
"ID": in.Id,
"Scope ID": in.Scope.Id,
"Auth Method ID": in.AuthMethodId,
"User ID": in.UserId,
"Created Time": in.CreatedTime.Local().Format(time.RFC3339),
"Updated Time": in.UpdatedTime.Local().Format(time.RFC3339),
"Expiration Time": in.ExpirationTime.Local().Format(time.RFC3339),
"Approximate Last Used Time": in.ApproximateLastUsedTime.Local().Format(time.RFC3339),
"Created Time": in.CreatedTime.Local().Format(time.RFC1123),
"Updated Time": in.UpdatedTime.Local().Format(time.RFC1123),
"Expiration Time": in.ExpirationTime.Local().Format(time.RFC1123),
"Approximate Last Used Time": in.ApproximateLastUsedTime.Local().Format(time.RFC1123),
}
maxLength := 0
for k := range nonAttributeMap {
if len(k) > maxLength {
maxLength = len(k)
}
}
maxLength := base.MaxAttributesLength(nonAttributeMap, nil, nil)
ret := []string{"", "Auth Token information:"}
ret = append(ret,
// We do +2 because there is another +2 offset for host sets below
ret := []string{
"",
"Auth Token information:",
base.WrapMap(2, maxLength+2, nonAttributeMap),
)
"",
" Scope:",
base.ScopeInfoForOutput(in.Scope, maxLength),
}
return base.WrapForHelpText(ret)
}
+32 -16
View File
@@ -71,14 +71,11 @@ func populateFlags(c *Command, f *base.FlagSet, flagNames []string) {
}
func generateGroupTableOutput(in *groups.Group) string {
var ret []string
nonAttributeMap := map[string]interface{}{
"ID": in.Id,
"Scope ID": in.Scope.Id,
"Version": in.Version,
"Created Time": in.CreatedTime.Local().Format(time.RFC3339),
"Updated Time": in.UpdatedTime.Local().Format(time.RFC3339),
"Created Time": in.CreatedTime.Local().Format(time.RFC1123),
"Updated Time": in.UpdatedTime.Local().Format(time.RFC1123),
}
if in.Name != "" {
@@ -88,22 +85,41 @@ func generateGroupTableOutput(in *groups.Group) string {
nonAttributeMap["Description"] = in.Description
}
ret = append(ret, "", "Group information:")
maxLength := base.MaxAttributesLength(nonAttributeMap, nil, nil)
ret = append(ret,
base.WrapMap(2, 0, nonAttributeMap),
)
var groupMaps []map[string]interface{}
if len(in.Members) > 0 {
for _, member := range in.Members {
m := map[string]interface{}{
"ID": member.Id,
"Scope ID": member.ScopeId,
}
groupMaps = append(groupMaps, m)
}
if l := len("Scope ID"); l > maxLength {
maxLength = l
}
}
ret := []string{
"",
"Group information:",
base.WrapMap(2, maxLength+2, nonAttributeMap),
" Scope:",
base.ScopeInfoForOutput(in.Scope, maxLength),
}
if len(in.Members) > 0 {
ret = append(ret,
fmt.Sprintf(" Members: %s", ""),
)
}
for _, member := range in.Members {
ret = append(ret,
fmt.Sprintf(" ID: %s", member.Id),
fmt.Sprintf(" Scope ID: %s", member.ScopeId),
"",
" Members:",
)
for _, m := range groupMaps {
ret = append(ret,
base.WrapMap(4, maxLength, m),
"",
)
}
}
return base.WrapForHelpText(ret)
}
+13 -32
View File
@@ -1,7 +1,6 @@
package hostcatalogs
import (
"fmt"
"time"
"github.com/hashicorp/boundary/api/hostcatalogs"
@@ -9,15 +8,12 @@ import (
)
func generateHostCatalogTableOutput(in *hostcatalogs.HostCatalog) string {
var ret []string
nonAttributeMap := map[string]interface{}{
"ID": in.Id,
"Scope ID": in.Scope.Id,
"Version": in.Version,
"Type": in.Type,
"Created Time": in.CreatedTime.Local().Format(time.RFC3339),
"Updated Time": in.UpdatedTime.Local().Format(time.RFC3339),
"Created Time": in.CreatedTime.Local().Format(time.RFC1123),
"Updated Time": in.UpdatedTime.Local().Format(time.RFC1123),
}
if in.Name != "" {
@@ -27,36 +23,21 @@ func generateHostCatalogTableOutput(in *hostcatalogs.HostCatalog) string {
nonAttributeMap["Description"] = in.Description
}
maxLength := 0
for k := range nonAttributeMap {
if len(k) > maxLength {
maxLength = len(k)
}
}
if len(in.Attributes) > 0 {
for k, v := range in.Attributes {
if attributeMap[k] != "" {
in.Attributes[attributeMap[k]] = v
delete(in.Attributes, k)
}
}
for k := range in.Attributes {
if len(k) > maxLength {
maxLength = len(k)
}
}
}
maxLength := base.MaxAttributesLength(nonAttributeMap, in.Attributes, keySubstMap)
ret = append(ret, "", "Host catalog information:")
ret = append(ret,
// We do +2 because there is another +2 offset for attributes below
ret := []string{
"",
"Host Catalog information:",
base.WrapMap(2, maxLength+2, nonAttributeMap),
)
"",
" Scope:",
base.ScopeInfoForOutput(in.Scope, maxLength),
}
if len(in.Attributes) > 0 {
ret = append(ret,
fmt.Sprintf(" Attributes: %s", ""),
"",
" Attributes:",
base.WrapMap(4, maxLength, in.Attributes),
)
}
@@ -64,6 +45,6 @@ func generateHostCatalogTableOutput(in *hostcatalogs.HostCatalog) string {
return base.WrapForHelpText(ret)
}
var attributeMap = map[string]string{
var keySubstMap = map[string]string{
"address": "Address",
}
+14 -32
View File
@@ -1,7 +1,6 @@
package hosts
import (
"fmt"
"time"
"github.com/hashicorp/boundary/api/hosts"
@@ -9,15 +8,12 @@ import (
)
func generateHostTableOutput(in *hosts.Host) string {
var ret []string
nonAttributeMap := map[string]interface{}{
"ID": in.Id,
"Scope ID": in.Scope.Id,
"Version": in.Version,
"Type": in.Type,
"Created Time": in.CreatedTime.Local().Format(time.RFC3339),
"Updated Time": in.UpdatedTime.Local().Format(time.RFC3339),
"Created Time": in.CreatedTime.Local().Format(time.RFC1123),
"Updated Time": in.UpdatedTime.Local().Format(time.RFC1123),
"Host Catalog ID": in.HostCatalogId,
}
@@ -28,35 +24,20 @@ func generateHostTableOutput(in *hosts.Host) string {
nonAttributeMap["Description"] = in.Description
}
maxLength := 0
for k := range nonAttributeMap {
if len(k) > maxLength {
maxLength = len(k)
}
}
if len(in.Attributes) > 0 {
for k, v := range in.Attributes {
if attributeMap[k] != "" {
in.Attributes[attributeMap[k]] = v
delete(in.Attributes, k)
}
}
for k := range in.Attributes {
if len(k) > maxLength {
maxLength = len(k)
}
}
}
maxLength := base.MaxAttributesLength(nonAttributeMap, in.Attributes, keySubstMap)
ret = append(ret, "", "Host information:")
ret = append(ret,
// We do +2 because there is another +2 offset for attributes below
ret := []string{
"",
"Host information:",
base.WrapMap(2, maxLength+2, nonAttributeMap),
)
"",
" Scope:",
base.ScopeInfoForOutput(in.Scope, maxLength),
}
if len(in.HostSetIds) > 0 {
ret = append(ret,
"",
" Host Set IDs:",
base.WrapSlice(4, in.HostSetIds),
)
@@ -64,7 +45,8 @@ func generateHostTableOutput(in *hosts.Host) string {
if len(in.Attributes) > 0 {
ret = append(ret,
fmt.Sprintf(" Attributes: %s", ""),
"",
" Attributes:",
base.WrapMap(4, maxLength, in.Attributes),
)
}
@@ -72,4 +54,4 @@ func generateHostTableOutput(in *hosts.Host) string {
return base.WrapForHelpText(ret)
}
var attributeMap = map[string]string{}
var keySubstMap = map[string]string{}
+14 -32
View File
@@ -1,7 +1,6 @@
package hostsets
import (
"fmt"
"time"
"github.com/hashicorp/boundary/api/hostsets"
@@ -9,15 +8,12 @@ import (
)
func generateHostSetTableOutput(in *hostsets.HostSet) string {
var ret []string
nonAttributeMap := map[string]interface{}{
"ID": in.Id,
"Scope ID": in.Scope.Id,
"Version": in.Version,
"Type": in.Type,
"Created Time": in.CreatedTime.Local().Format(time.RFC3339),
"Updated Time": in.UpdatedTime.Local().Format(time.RFC3339),
"Created Time": in.CreatedTime.Local().Format(time.RFC1123),
"Updated Time": in.UpdatedTime.Local().Format(time.RFC1123),
"Host Catalog ID": in.HostCatalogId,
}
@@ -28,35 +24,20 @@ func generateHostSetTableOutput(in *hostsets.HostSet) string {
nonAttributeMap["Description"] = in.Description
}
maxLength := 0
for k := range nonAttributeMap {
if len(k) > maxLength {
maxLength = len(k)
}
}
if len(in.Attributes) > 0 {
for k, v := range in.Attributes {
if attributeMap[k] != "" {
in.Attributes[attributeMap[k]] = v
delete(in.Attributes, k)
}
}
for k := range in.Attributes {
if len(k) > maxLength {
maxLength = len(k)
}
}
}
maxLength := base.MaxAttributesLength(nonAttributeMap, in.Attributes, keySubstMap)
ret = append(ret, "", "Host set information:")
ret = append(ret,
// We do +2 because there is another +2 offset for attributes below
ret := []string{
"",
"Host Set information:",
base.WrapMap(2, maxLength+2, nonAttributeMap),
)
"",
" Scope:",
base.ScopeInfoForOutput(in.Scope, maxLength),
}
if len(in.HostIds) > 0 {
ret = append(ret,
"",
" Host IDs:",
base.WrapSlice(4, in.HostIds),
)
@@ -64,7 +45,8 @@ func generateHostSetTableOutput(in *hostsets.HostSet) string {
if len(in.Attributes) > 0 {
ret = append(ret,
fmt.Sprintf(" Attributes: %s", ""),
"",
" Attributes:",
base.WrapMap(4, maxLength, in.Attributes),
)
}
@@ -72,4 +54,4 @@ func generateHostSetTableOutput(in *hostsets.HostSet) string {
return base.WrapForHelpText(ret)
}
var attributeMap = map[string]string{}
var keySubstMap = map[string]string{}
+5 -13
View File
@@ -7,8 +7,6 @@ import (
)
func generateSessionInfoTableOutput(in SessionInfo) string {
var ret []string
nonAttributeMap := map[string]interface{}{
"Session ID": in.SessionId,
"Protocol": in.Protocol,
@@ -18,19 +16,13 @@ func generateSessionInfoTableOutput(in SessionInfo) string {
"Connection Limit": in.ConnectionLimit,
}
maxLength := 0
for k := range nonAttributeMap {
if len(k) > maxLength {
maxLength = len(k)
}
}
maxLength := base.MaxAttributesLength(nonAttributeMap, nil, nil)
ret = append(ret, "", "Proxy listening information:")
ret = append(ret,
// We do +2 because there is another +2 offset for host sets below
ret := []string{
"",
"Proxy listening information:",
base.WrapMap(2, maxLength+2, nonAttributeMap),
)
}
return base.WrapForHelpText(ret)
}
+11 -9
View File
@@ -87,14 +87,11 @@ func populateFlags(c *Command, f *base.FlagSet, flagNames []string) {
}
func generateRoleTableOutput(in *roles.Role) string {
var ret []string
nonAttributeMap := map[string]interface{}{
"ID": in.Id,
"Scope ID": in.Scope.Id,
"Version": in.Version,
"Created Time": in.CreatedTime.Local().Format(time.RFC3339),
"Updated Time": in.UpdatedTime.Local().Format(time.RFC3339),
"Created Time": in.CreatedTime.Local().Format(time.RFC1123),
"Updated Time": in.UpdatedTime.Local().Format(time.RFC1123),
}
if in.Name != "" {
@@ -107,11 +104,16 @@ func generateRoleTableOutput(in *roles.Role) string {
nonAttributeMap["Grant Scope ID"] = in.GrantScopeId
}
ret = append(ret, "", "Role information:")
maxLength := base.MaxAttributesLength(nonAttributeMap, nil, nil)
ret = append(ret,
base.WrapMap(2, 0, nonAttributeMap),
)
ret := []string{
"",
"Role information:",
base.WrapMap(2, maxLength+2, nonAttributeMap),
"",
" Scope:",
base.ScopeInfoForOutput(in.Scope, maxLength),
}
if len(in.Principals) > 0 {
ret = append(ret,
+11 -9
View File
@@ -8,14 +8,11 @@ import (
)
func generateScopeTableOutput(in *scopes.Scope) string {
var ret []string
nonAttributeMap := map[string]interface{}{
"ID": in.Id,
"Scope ID": in.Scope.Id,
"Version": in.Version,
"Created Time": in.CreatedTime.Local().Format(time.RFC3339),
"Updated Time": in.UpdatedTime.Local().Format(time.RFC3339),
"Created Time": in.CreatedTime.Local().Format(time.RFC1123),
"Updated Time": in.UpdatedTime.Local().Format(time.RFC1123),
}
if in.Name != "" {
@@ -25,11 +22,16 @@ func generateScopeTableOutput(in *scopes.Scope) string {
nonAttributeMap["Description"] = in.Description
}
ret = append(ret, "", "Scope information:")
maxLength := base.MaxAttributesLength(nonAttributeMap, nil, nil)
ret = append(ret,
base.WrapMap(2, 0, nonAttributeMap),
)
ret := []string{
"",
"Scope information:",
base.WrapMap(2, maxLength+2, nonAttributeMap),
"",
" Scope (parent):",
base.ScopeInfoForOutput(in.Scope, maxLength),
}
return base.WrapForHelpText(ret)
}
+15 -18
View File
@@ -12,10 +12,9 @@ func generateSessionTableOutput(in *sessions.Session) string {
nonAttributeMap := map[string]interface{}{
"ID": in.Id,
"Target ID": in.TargetId,
"Scope ID": in.Scope.Id,
"Created Time": in.CreatedTime.Local().Format(time.RFC3339),
"Updated Time": in.UpdatedTime.Local().Format(time.RFC3339),
"Expiration Time": in.ExpirationTime.Local().Format(time.RFC3339),
"Created Time": in.CreatedTime.Local().Format(time.RFC1123),
"Updated Time": in.UpdatedTime.Local().Format(time.RFC1123),
"Expiration Time": in.ExpirationTime.Local().Format(time.RFC1123),
"Version": in.Version,
"Type": in.Type,
"Auth Token ID": in.AuthTokenId,
@@ -26,20 +25,15 @@ func generateSessionTableOutput(in *sessions.Session) string {
"Status": in.Status,
}
maxLength := 0
for k := range nonAttributeMap {
if len(k) > maxLength {
maxLength = len(k)
}
}
maxLength := base.MaxAttributesLength(nonAttributeMap, nil, nil)
var statesMaps []map[string]interface{}
if len(in.States) > 0 {
for _, state := range in.States {
m := map[string]interface{}{
"Status": state.Status,
"Start Time": state.StartTime.Local().Format(time.RFC3339),
"End Time": state.EndTime.Local().Format(time.RFC3339),
"Start Time": state.StartTime.Local().Format(time.RFC1123),
"End Time": state.EndTime.Local().Format(time.RFC1123),
}
statesMaps = append(statesMaps, m)
}
@@ -61,16 +55,19 @@ func generateSessionTableOutput(in *sessions.Session) string {
}
}
ret := []string{"", "Session information:"}
ret = append(ret,
// We do +2 because there is another +2 offset for host sets below
ret := []string{
"",
"Session information:",
base.WrapMap(2, maxLength+2, nonAttributeMap),
)
"",
" Scope:",
base.ScopeInfoForOutput(in.Scope, maxLength),
}
if len(in.States) > 0 {
ret = append(ret,
fmt.Sprintf(" States: %s", ""),
"",
" States:",
)
for _, m := range statesMaps {
ret = append(ret,
+15 -36
View File
@@ -1,7 +1,6 @@
package targets
import (
"fmt"
"time"
"github.com/hashicorp/boundary/api/scopes"
@@ -10,15 +9,12 @@ import (
)
func generateTargetTableOutput(in *targets.Target) string {
var ret []string
nonAttributeMap := map[string]interface{}{
"ID": in.Id,
"Scope ID": in.Scope.Id,
"Version": in.Version,
"Type": in.Type,
"Created Time": in.CreatedTime.Local().Format(time.RFC3339),
"Updated Time": in.UpdatedTime.Local().Format(time.RFC3339),
"Created Time": in.CreatedTime.Local().Format(time.RFC1123),
"Updated Time": in.UpdatedTime.Local().Format(time.RFC1123),
"Session Connection Limit": in.SessionConnectionLimit,
"Session Max Seconds": in.SessionMaxSeconds,
}
@@ -30,25 +26,7 @@ func generateTargetTableOutput(in *targets.Target) string {
nonAttributeMap["Description"] = in.Description
}
maxLength := 0
for k := range nonAttributeMap {
if len(k) > maxLength {
maxLength = len(k)
}
}
if len(in.Attributes) > 0 {
for k, v := range in.Attributes {
if attributeMap[k] != "" {
in.Attributes[attributeMap[k]] = v
delete(in.Attributes, k)
}
}
for k := range in.Attributes {
if len(k) > maxLength {
maxLength = len(k)
}
}
}
maxLength := base.MaxAttributesLength(nonAttributeMap, in.Attributes, keySubstMap)
var hostSetMaps []map[string]interface{}
if len(in.HostSets) > 0 {
@@ -63,16 +41,20 @@ func generateTargetTableOutput(in *targets.Target) string {
maxLength = l
}
}
ret = append(ret, "", "Target information:")
ret = append(ret,
// We do +2 because there is another +2 offset for host sets below
ret := []string{
"",
"Target information:",
base.WrapMap(2, maxLength+2, nonAttributeMap),
)
"",
" Scope:",
base.ScopeInfoForOutput(in.Scope, maxLength),
}
if len(in.HostSets) > 0 {
ret = append(ret,
fmt.Sprintf(" Host Sets: %s", ""),
"",
" Host Sets:",
)
for _, m := range hostSetMaps {
ret = append(ret,
@@ -83,12 +65,9 @@ func generateTargetTableOutput(in *targets.Target) string {
}
if len(in.Attributes) > 0 {
if true {
ret = append(ret,
fmt.Sprintf(" Attributes: %s", ""),
)
}
ret = append(ret,
"",
" Attributes:",
base.WrapMap(4, maxLength, in.Attributes),
)
}
@@ -125,7 +104,7 @@ func generateAuthorizationTableOutput(in *targets.SessionAuthorization) string {
return base.WrapForHelpText(ret)
}
var attributeMap = map[string]string{
var keySubstMap = map[string]string{
"default_port": "Default Port",
}
+11 -9
View File
@@ -8,14 +8,11 @@ import (
)
func generateUserTableOutput(in *users.User) string {
var ret []string
nonAttributeMap := map[string]interface{}{
"ID": in.Id,
"Scope ID": in.Scope.Id,
"Version": in.Version,
"Created Time": in.CreatedTime.Local().Format(time.RFC3339),
"Updated Time": in.UpdatedTime.Local().Format(time.RFC3339),
"Created Time": in.CreatedTime.Local().Format(time.RFC1123),
"Updated Time": in.UpdatedTime.Local().Format(time.RFC1123),
}
if in.Name != "" {
@@ -25,11 +22,16 @@ func generateUserTableOutput(in *users.User) string {
nonAttributeMap["Description"] = in.Description
}
ret = append(ret, "", "User information:")
maxLength := base.MaxAttributesLength(nonAttributeMap, nil, nil)
ret = append(ret,
base.WrapMap(2, 0, nonAttributeMap),
)
ret := []string{
"",
"User information:",
base.WrapMap(2, maxLength+2, nonAttributeMap),
"",
" Scope:",
base.ScopeInfoForOutput(in.Scope, maxLength),
}
return base.WrapForHelpText(ret)
}