Add Output Fields support (#1192)

This commit is contained in:
Jeff Mitchell authored and GitHub committed 2021-05-04 20:57:35 -04:00
1 parent 1948984ca2
commit 22d5c88a0b
84 files changed
+5688 -2122

No files matched your search

+3
View File
@@ -20,6 +20,9 @@ import (
var asciiSpace = [256]uint8{'\t': 1, '\n': 1, '\v': 1, '\f': 1, '\r': 1, ' ': 1}
func ScopeInfoForOutput(scp *scopes.ScopeInfo, maxLength int) string {
if scp == nil {
return " <not included in response>"
}
vals := map[string]interface{}{
"ID": scp.Id,
"Type": scp.Type,
@@ -275,8 +275,7 @@ func (c *Command) Run(args []string) int {
switch base.Format(c.UI) {
case "table":
item := result.GetItem().(*accounts.Account)
c.UI.Output(printItemTable(item))
c.UI.Output(printItemTable(result))
case "json":
if ok := c.PrintJsonItem(result); !ok {
+51 -23
View File
@@ -193,31 +193,43 @@ func (c *Command) printListTable(items []*accounts.Account) string {
"",
"Account information:",
}
for i, m := range items {
for i, item := range items {
if i > 0 {
output = append(output, "")
}
if true {
if item.Id != "" {
output = append(output,
fmt.Sprintf(" ID: %s", m.Id),
fmt.Sprintf(" Version: %d", m.Version),
fmt.Sprintf(" Type: %s", m.Type),
fmt.Sprintf(" ID: %s", item.Id),
)
} else {
output = append(output,
fmt.Sprintf(" ID: %s", "(not available)"),
)
}
if m.Name != "" {
if item.Version > 0 {
output = append(output,
fmt.Sprintf(" Name: %s", m.Name),
fmt.Sprintf(" Version: %d", item.Version),
)
}
if m.Description != "" {
if item.Type != "" {
output = append(output,
fmt.Sprintf(" Description: %s", m.Description),
fmt.Sprintf(" Type: %s", item.Type),
)
}
if len(m.AuthorizedActions) > 0 {
if item.Name != "" {
output = append(output,
fmt.Sprintf(" Name: %s", item.Name),
)
}
if item.Description != "" {
output = append(output,
fmt.Sprintf(" Description: %s", item.Description),
)
}
if len(item.AuthorizedActions) > 0 {
output = append(output,
" Authorized Actions:",
base.WrapSlice(6, m.AuthorizedActions),
base.WrapSlice(6, item.AuthorizedActions),
)
}
}
@@ -225,16 +237,27 @@ func (c *Command) printListTable(items []*accounts.Account) string {
return base.WrapForHelpText(output)
}
func printItemTable(item *accounts.Account) string {
nonAttributeMap := map[string]interface{}{
"ID": item.Id,
"Version": item.Version,
"Type": item.Type,
"Created Time": item.CreatedTime.Local().Format(time.RFC1123),
"Updated Time": item.UpdatedTime.Local().Format(time.RFC1123),
"Auth Method ID": item.AuthMethodId,
func printItemTable(result api.GenericResult) string {
item := result.GetItem().(*accounts.Account)
nonAttributeMap := map[string]interface{}{}
if item.Id != "" {
nonAttributeMap["ID"] = item.Id
}
if item.Version != 0 {
nonAttributeMap["Version"] = item.Version
}
if item.Type != "" {
nonAttributeMap["Type"] = item.Type
}
if !item.CreatedTime.IsZero() {
nonAttributeMap["Created Time"] = item.CreatedTime.Local().Format(time.RFC1123)
}
if !item.UpdatedTime.IsZero() {
nonAttributeMap["Updated Time"] = item.UpdatedTime.Local().Format(time.RFC1123)
}
if item.AuthMethodId != "" {
nonAttributeMap["Auth Method ID"] = item.AuthMethodId
}
if item.Name != "" {
nonAttributeMap["Name"] = item.Name
}
@@ -248,9 +271,14 @@ func printItemTable(item *accounts.Account) string {
"",
"Account information:",
base.WrapMap(2, maxLength+2, nonAttributeMap),
"",
" Scope:",
base.ScopeInfoForOutput(item.Scope, maxLength),
}
if item.Scope != nil {
ret = append(ret,
"",
" Scope:",
base.ScopeInfoForOutput(item.Scope, maxLength),
)
}
if len(item.AuthorizedActions) > 0 {
@@ -216,8 +216,7 @@ func (c *OidcCommand) Run(args []string) int {
switch base.Format(c.UI) {
case "table":
item := result.GetItem().(*accounts.Account)
c.UI.Output(printItemTable(item))
c.UI.Output(printItemTable(result))
case "json":
if ok := c.PrintJsonItem(result); !ok {
@@ -216,8 +216,7 @@ func (c *PasswordCommand) Run(args []string) int {
switch base.Format(c.UI) {
case "table":
item := result.GetItem().(*accounts.Account)
c.UI.Output(printItemTable(item))
c.UI.Output(printItemTable(result))
case "json":
if ok := c.PrintJsonItem(result); !ok {
@@ -242,8 +242,7 @@ func (c *Command) Run(args []string) int {
switch base.Format(c.UI) {
case "table":
item := result.GetItem().(*authmethods.AuthMethod)
c.UI.Output(printItemTable(item))
c.UI.Output(printItemTable(result))
case "json":
if ok := c.PrintJsonItem(result); !ok {
+72 -44
View File
@@ -5,7 +5,9 @@ import (
"sort"
"time"
"github.com/hashicorp/boundary/api"
"github.com/hashicorp/boundary/api/authmethods"
"github.com/hashicorp/boundary/globals"
"github.com/hashicorp/boundary/internal/cmd/base"
)
@@ -76,46 +78,54 @@ func (c *Command) printListTable(items []*authmethods.AuthMethod) string {
"",
"Auth Method information:",
}
for i, m := range items {
for i, item := range items {
if i > 0 {
output = append(output, "")
}
if true {
if item.Id != "" {
output = append(output,
fmt.Sprintf(" ID: %s", m.Id),
fmt.Sprintf(" ID: %s", item.Id),
)
} else {
output = append(output,
fmt.Sprintf(" ID: %s", "(not available)"),
)
}
if c.FlagRecursive {
if c.FlagRecursive && item.ScopeId != "" {
output = append(output,
fmt.Sprintf(" Scope ID: %s", m.Scope.Id),
fmt.Sprintf(" Scope ID: %s", item.ScopeId),
)
}
if true {
if item.Version > 0 {
output = append(output,
fmt.Sprintf(" Version: %d", m.Version),
fmt.Sprintf(" Type: %s", m.Type),
fmt.Sprintf(" Version: %d", item.Version),
)
}
if m.Name != "" {
if item.Type != "" {
output = append(output,
fmt.Sprintf(" Name: %s", m.Name),
fmt.Sprintf(" Type: %s", item.Type),
)
}
if m.Description != "" {
if item.Name != "" {
output = append(output,
fmt.Sprintf(" Description: %s", m.Description),
fmt.Sprintf(" Name: %s", item.Name),
)
}
if true {
if item.Description != "" {
output = append(output,
fmt.Sprintf(" Is Primary For Scope: %t", m.IsPrimary),
fmt.Sprintf(" Description: %s", item.Description),
)
}
if item.IsPrimary {
output = append(output,
fmt.Sprintf(" Is Primary For Scope: %t", item.IsPrimary),
)
}
if len(m.AuthorizedActions) > 0 {
if len(item.AuthorizedActions) > 0 {
output = append(output,
" Authorized Actions:",
base.WrapSlice(6, m.AuthorizedActions),
base.WrapSlice(6, item.AuthorizedActions),
)
}
}
@@ -123,45 +133,63 @@ func (c *Command) printListTable(items []*authmethods.AuthMethod) string {
return base.WrapForHelpText(output)
}
func printItemTable(in *authmethods.AuthMethod) string {
nonAttributeMap := map[string]interface{}{
"ID": in.Id,
"Version": in.Version,
"Type": in.Type,
"Created Time": in.CreatedTime.Local().Format(time.RFC1123),
"Updated Time": in.UpdatedTime.Local().Format(time.RFC1123),
"Is Primary For Scope": in.IsPrimary,
func printItemTable(result api.GenericResult) string {
item := result.GetItem().(*authmethods.AuthMethod)
nonAttributeMap := map[string]interface{}{}
if item.Id != "" {
nonAttributeMap["ID"] = item.Id
}
if item.Version != 0 {
nonAttributeMap["Version"] = item.Version
}
if item.Type != "" {
nonAttributeMap["Type"] = item.Type
}
if !item.CreatedTime.IsZero() {
nonAttributeMap["Created Time"] = item.CreatedTime.Local().Format(time.RFC1123)
}
if !item.UpdatedTime.IsZero() {
nonAttributeMap["Updated Time"] = item.UpdatedTime.Local().Format(time.RFC1123)
}
if item.Name != "" {
nonAttributeMap["Name"] = item.Name
}
if item.Description != "" {
nonAttributeMap["Description"] = item.Description
}
if result.GetResponse() != nil && result.GetResponse().Map != nil {
if result.GetResponse().Map[globals.IsPrimaryField] != nil {
nonAttributeMap["Is Primary For Scope"] = item.IsPrimary
}
}
if in.Name != "" {
nonAttributeMap["Name"] = in.Name
}
if in.Description != "" {
nonAttributeMap["Description"] = in.Description
}
maxLength := base.MaxAttributesLength(nonAttributeMap, in.Attributes, keySubstMap)
maxLength := base.MaxAttributesLength(nonAttributeMap, item.Attributes, keySubstMap)
ret := []string{
"",
"Auth Method information:",
base.WrapMap(2, maxLength+2, nonAttributeMap),
"",
" Scope:",
base.ScopeInfoForOutput(in.Scope, maxLength),
}
if len(in.AuthorizedActions) > 0 {
if item.Scope != nil {
ret = append(ret,
"",
" Authorized Actions:",
base.WrapSlice(4, in.AuthorizedActions),
" Scope:",
base.ScopeInfoForOutput(item.Scope, maxLength),
)
}
if len(in.AuthorizedCollectionActions) > 0 {
keys := make([]string, 0, len(in.AuthorizedCollectionActions))
for k := range in.AuthorizedCollectionActions {
if len(item.AuthorizedActions) > 0 {
ret = append(ret,
"",
" Authorized Actions:",
base.WrapSlice(4, item.AuthorizedActions),
)
}
if len(item.AuthorizedCollectionActions) > 0 {
keys := make([]string, 0, len(item.AuthorizedCollectionActions))
for k := range item.AuthorizedCollectionActions {
keys = append(keys, k)
}
sort.Strings(keys)
@@ -172,16 +200,16 @@ func printItemTable(in *authmethods.AuthMethod) string {
for _, key := range keys {
ret = append(ret,
fmt.Sprintf(" %s:", key),
base.WrapSlice(6, in.AuthorizedCollectionActions[key]),
base.WrapSlice(6, item.AuthorizedCollectionActions[key]),
)
}
}
if len(in.Attributes) > 0 {
if len(item.Attributes) > 0 {
ret = append(ret,
"",
" Attributes:",
base.WrapMap(4, maxLength, in.Attributes),
base.WrapMap(4, maxLength, item.Attributes),
)
}
@@ -231,8 +231,7 @@ func (c *OidcCommand) Run(args []string) int {
switch base.Format(c.UI) {
case "table":
item := result.GetItem().(*authmethods.AuthMethod)
c.UI.Output(printItemTable(item))
c.UI.Output(printItemTable(result))
case "json":
if ok := c.PrintJsonItem(result); !ok {
@@ -221,8 +221,7 @@ func (c *PasswordCommand) Run(args []string) int {
switch base.Format(c.UI) {
case "table":
item := result.GetItem().(*authmethods.AuthMethod)
c.UI.Output(printItemTable(item))
c.UI.Output(printItemTable(result))
case "json":
if ok := c.PrintJsonItem(result); !ok {
@@ -233,8 +233,7 @@ func (c *Command) Run(args []string) int {
switch base.Format(c.UI) {
case "table":
item := result.GetItem().(*authtokens.AuthToken)
c.UI.Output(printItemTable(item))
c.UI.Output(printItemTable(result))
case "json":
if ok := c.PrintJsonItem(result); !ok {
+37 -15
View File
@@ -5,6 +5,7 @@ import (
"fmt"
"time"
"github.com/hashicorp/boundary/api"
"github.com/hashicorp/boundary/api/authtokens"
"github.com/hashicorp/boundary/internal/cmd/base"
"github.com/hashicorp/boundary/sdk/strutil"
@@ -69,23 +70,43 @@ func (c *Command) printListTable(items []*authtokens.AuthToken) string {
if i > 0 {
output = append(output, "")
}
if true {
if t.Id != "" {
output = append(output,
fmt.Sprintf(" ID: %s", t.Id),
)
}
if c.FlagRecursive {
if c.FlagRecursive && t.ScopeId != "" {
output = append(output,
fmt.Sprintf(" Scope ID: %s", t.Scope.Id),
fmt.Sprintf(" Scope ID: %s", t.ScopeId),
)
}
if true {
if !t.ApproximateLastUsedTime.IsZero() {
output = append(output,
fmt.Sprintf(" Approximate Last Used Time: %s", t.ApproximateLastUsedTime.Local().Format(time.RFC1123)),
)
}
if t.AuthMethodId != "" {
output = append(output,
fmt.Sprintf(" Auth Method ID: %s", t.AuthMethodId),
)
}
if !t.CreatedTime.IsZero() {
output = append(output,
fmt.Sprintf(" Created Time: %s", t.CreatedTime.Local().Format(time.RFC1123)),
)
}
if !t.ExpirationTime.IsZero() {
output = append(output,
fmt.Sprintf(" Expiration Time: %s", t.ExpirationTime.Local().Format(time.RFC1123)),
)
}
if !t.UpdatedTime.IsZero() {
output = append(output,
fmt.Sprintf(" Updated Time: %s", t.UpdatedTime.Local().Format(time.RFC1123)),
)
}
if t.UserId != "" {
output = append(output,
fmt.Sprintf(" User ID: %s", t.UserId),
)
}
@@ -100,15 +121,16 @@ func (c *Command) printListTable(items []*authtokens.AuthToken) string {
return base.WrapForHelpText(output)
}
func printItemTable(in *authtokens.AuthToken) string {
func printItemTable(result api.GenericResult) string {
item := result.GetItem().(*authtokens.AuthToken)
nonAttributeMap := map[string]interface{}{
"ID": in.Id,
"Auth Method ID": in.AuthMethodId,
"User ID": in.UserId,
"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),
"ID": item.Id,
"Auth Method ID": item.AuthMethodId,
"User ID": item.UserId,
"Created Time": item.CreatedTime.Local().Format(time.RFC1123),
"Updated Time": item.UpdatedTime.Local().Format(time.RFC1123),
"Expiration Time": item.ExpirationTime.Local().Format(time.RFC1123),
"Approximate Last Used Time": item.ApproximateLastUsedTime.Local().Format(time.RFC1123),
}
maxLength := base.MaxAttributesLength(nonAttributeMap, nil, nil)
@@ -119,14 +141,14 @@ func printItemTable(in *authtokens.AuthToken) string {
base.WrapMap(2, maxLength+2, nonAttributeMap),
"",
" Scope:",
base.ScopeInfoForOutput(in.Scope, maxLength),
base.ScopeInfoForOutput(item.Scope, maxLength),
}
if len(in.AuthorizedActions) > 0 {
if len(item.AuthorizedActions) > 0 {
ret = append(ret,
"",
" Authorized Actions:",
base.WrapSlice(4, in.AuthorizedActions),
base.WrapSlice(4, item.AuthorizedActions),
)
}
+39 -23
View File
@@ -149,39 +149,43 @@ func (c *Command) printListTable(items []*groups.Group) string {
"",
"Group information:",
}
for i, g := range items {
for i, item := range items {
if i > 0 {
output = append(output, "")
}
if true {
if item.Id != "" {
output = append(output,
fmt.Sprintf(" ID: %s", g.Id),
fmt.Sprintf(" ID: %s", item.Id),
)
} else {
output = append(output,
fmt.Sprintf(" ID: %s", "(not available)"),
)
}
if c.FlagRecursive {
if c.FlagRecursive && item.ScopeId != "" {
output = append(output,
fmt.Sprintf(" Scope ID: %s", g.Scope.Id),
fmt.Sprintf(" Scope ID: %s", item.ScopeId),
)
}
if true {
if item.Version > 0 {
output = append(output,
fmt.Sprintf(" Version: %d", g.Version),
fmt.Sprintf(" Version: %d", item.Version),
)
}
if g.Name != "" {
if item.Name != "" {
output = append(output,
fmt.Sprintf(" Name: %s", g.Name),
fmt.Sprintf(" Name: %s", item.Name),
)
}
if g.Description != "" {
if item.Description != "" {
output = append(output,
fmt.Sprintf(" Description: %s", g.Description),
fmt.Sprintf(" Description: %s", item.Description),
)
}
if len(g.AuthorizedActions) > 0 {
if len(item.AuthorizedActions) > 0 {
output = append(output,
" Authorized Actions:",
base.WrapSlice(6, g.AuthorizedActions),
base.WrapSlice(6, item.AuthorizedActions),
)
}
}
@@ -189,14 +193,21 @@ func (c *Command) printListTable(items []*groups.Group) string {
return base.WrapForHelpText(output)
}
func printItemTable(item *groups.Group) string {
nonAttributeMap := map[string]interface{}{
"ID": item.Id,
"Version": item.Version,
"Created Time": item.CreatedTime.Local().Format(time.RFC1123),
"Updated Time": item.UpdatedTime.Local().Format(time.RFC1123),
func printItemTable(result api.GenericResult) string {
item := result.GetItem().(*groups.Group)
nonAttributeMap := map[string]interface{}{}
if item.Id != "" {
nonAttributeMap["ID"] = item.Id
}
if item.Version != 0 {
nonAttributeMap["Version"] = item.Version
}
if !item.CreatedTime.IsZero() {
nonAttributeMap["Created Time"] = item.CreatedTime.Local().Format(time.RFC1123)
}
if !item.UpdatedTime.IsZero() {
nonAttributeMap["Updated Time"] = item.UpdatedTime.Local().Format(time.RFC1123)
}
if item.Name != "" {
nonAttributeMap["Name"] = item.Name
}
@@ -224,9 +235,14 @@ func printItemTable(item *groups.Group) string {
"",
"Group information:",
base.WrapMap(2, maxLength+2, nonAttributeMap),
"",
" Scope:",
base.ScopeInfoForOutput(item.Scope, maxLength),
}
if item.Scope != nil {
ret = append(ret,
"",
" Scope:",
base.ScopeInfoForOutput(item.Scope, maxLength),
)
}
if len(item.AuthorizedActions) > 0 {
@@ -316,8 +316,7 @@ func (c *Command) Run(args []string) int {
switch base.Format(c.UI) {
case "table":
item := result.GetItem().(*groups.Group)
c.UI.Output(printItemTable(item))
c.UI.Output(printItemTable(result))
case "json":
if ok := c.PrintJsonItem(result); !ok {
+55 -32
View File
@@ -5,6 +5,7 @@ import (
"sort"
"time"
"github.com/hashicorp/boundary/api"
"github.com/hashicorp/boundary/api/hostcatalogs"
"github.com/hashicorp/boundary/internal/cmd/base"
)
@@ -68,19 +69,27 @@ func (c *Command) printListTable(items []*hostcatalogs.HostCatalog) string {
if i > 0 {
output = append(output, "")
}
if true {
if m.Id != "" {
output = append(output,
fmt.Sprintf(" ID: %s", m.Id),
)
}
if c.FlagRecursive {
} else {
output = append(output,
fmt.Sprintf(" Scope ID: %s", m.Scope.Id),
fmt.Sprintf(" ID: %s", "(not available)"),
)
}
if true {
if c.FlagRecursive && m.ScopeId != "" {
output = append(output,
fmt.Sprintf(" Scope ID: %s", m.ScopeId),
)
}
if m.Version > 0 {
output = append(output,
fmt.Sprintf(" Version: %d", m.Version),
)
}
if m.Type != "" {
output = append(output,
fmt.Sprintf(" Type: %s", m.Type),
)
}
@@ -105,44 +114,58 @@ func (c *Command) printListTable(items []*hostcatalogs.HostCatalog) string {
return base.WrapForHelpText(output)
}
func printItemTable(in *hostcatalogs.HostCatalog) string {
nonAttributeMap := map[string]interface{}{
"ID": in.Id,
"Version": in.Version,
"Type": in.Type,
"Created Time": in.CreatedTime.Local().Format(time.RFC1123),
"Updated Time": in.UpdatedTime.Local().Format(time.RFC1123),
func printItemTable(result api.GenericResult) string {
item := result.GetItem().(*hostcatalogs.HostCatalog)
nonAttributeMap := map[string]interface{}{}
if item.Id != "" {
nonAttributeMap["ID"] = item.Id
}
if item.Version != 0 {
nonAttributeMap["Version"] = item.Version
}
if !item.CreatedTime.IsZero() {
nonAttributeMap["Created Time"] = item.CreatedTime.Local().Format(time.RFC1123)
}
if !item.UpdatedTime.IsZero() {
nonAttributeMap["Updated Time"] = item.UpdatedTime.Local().Format(time.RFC1123)
}
if item.Name != "" {
nonAttributeMap["Name"] = item.Name
}
if item.Description != "" {
nonAttributeMap["Description"] = item.Description
}
if item.Type != "" {
nonAttributeMap["Type"] = item.Type
}
if in.Name != "" {
nonAttributeMap["Name"] = in.Name
}
if in.Description != "" {
nonAttributeMap["Description"] = in.Description
}
maxLength := base.MaxAttributesLength(nonAttributeMap, in.Attributes, keySubstMap)
maxLength := base.MaxAttributesLength(nonAttributeMap, item.Attributes, keySubstMap)
ret := []string{
"",
"Host Catalog information:",
base.WrapMap(2, maxLength+2, nonAttributeMap),
"",
" Scope:",
base.ScopeInfoForOutput(in.Scope, maxLength),
}
if len(in.AuthorizedActions) > 0 {
if item.Scope != nil {
ret = append(ret,
"",
" Authorized Actions:",
base.WrapSlice(4, in.AuthorizedActions),
" Scope:",
base.ScopeInfoForOutput(item.Scope, maxLength),
)
}
if len(in.AuthorizedCollectionActions) > 0 {
keys := make([]string, 0, len(in.AuthorizedCollectionActions))
for k := range in.AuthorizedCollectionActions {
if len(item.AuthorizedActions) > 0 {
ret = append(ret,
"",
" Authorized Actions:",
base.WrapSlice(4, item.AuthorizedActions),
)
}
if len(item.AuthorizedCollectionActions) > 0 {
keys := make([]string, 0, len(item.AuthorizedCollectionActions))
for k := range item.AuthorizedCollectionActions {
keys = append(keys, k)
}
sort.Strings(keys)
@@ -152,16 +175,16 @@ func printItemTable(in *hostcatalogs.HostCatalog) string {
for _, key := range keys {
ret = append(ret,
fmt.Sprintf(" %s:", key),
base.WrapSlice(6, in.AuthorizedCollectionActions[key]),
base.WrapSlice(6, item.AuthorizedCollectionActions[key]),
)
}
}
if len(in.Attributes) > 0 {
if len(item.Attributes) > 0 {
ret = append(ret,
"",
" Attributes:",
base.WrapMap(4, maxLength, in.Attributes),
base.WrapMap(4, maxLength, item.Attributes),
)
}
@@ -242,8 +242,7 @@ func (c *Command) Run(args []string) int {
switch base.Format(c.UI) {
case "table":
item := result.GetItem().(*hostcatalogs.HostCatalog)
c.UI.Output(printItemTable(item))
c.UI.Output(printItemTable(result))
case "json":
if ok := c.PrintJsonItem(result); !ok {
@@ -219,8 +219,7 @@ func (c *StaticCommand) Run(args []string) int {
switch base.Format(c.UI) {
case "table":
item := result.GetItem().(*hostcatalogs.HostCatalog)
c.UI.Output(printItemTable(item))
c.UI.Output(printItemTable(result))
case "json":
if ok := c.PrintJsonItem(result); !ok {
+55 -26
View File
@@ -4,6 +4,7 @@ import (
"fmt"
"time"
"github.com/hashicorp/boundary/api"
"github.com/hashicorp/boundary/api/hosts"
"github.com/hashicorp/boundary/internal/cmd/base"
)
@@ -67,10 +68,22 @@ func (c *Command) printListTable(items []*hosts.Host) string {
if i > 0 {
output = append(output, "")
}
if true {
if item.Id != "" {
output = append(output,
fmt.Sprintf(" ID: %s", item.Id),
)
} else {
output = append(output,
fmt.Sprintf(" ID: %s", "(not available)"),
)
}
if item.Version > 0 {
output = append(output,
fmt.Sprintf(" Version: %d", item.Version),
)
}
if item.Type != "" {
output = append(output,
fmt.Sprintf(" Type: %s", item.Type),
)
}
@@ -95,55 +108,71 @@ func (c *Command) printListTable(items []*hosts.Host) string {
return base.WrapForHelpText(output)
}
func printItemTable(in *hosts.Host) string {
nonAttributeMap := map[string]interface{}{
"ID": in.Id,
"Version": in.Version,
"Type": in.Type,
"Created Time": in.CreatedTime.Local().Format(time.RFC1123),
"Updated Time": in.UpdatedTime.Local().Format(time.RFC1123),
"Host Catalog ID": in.HostCatalogId,
func printItemTable(result api.GenericResult) string {
item := result.GetItem().(*hosts.Host)
nonAttributeMap := map[string]interface{}{}
if item.Id != "" {
nonAttributeMap["ID"] = item.Id
}
if item.Version != 0 {
nonAttributeMap["Version"] = item.Version
}
if item.Type != "" {
nonAttributeMap["Type"] = item.Type
}
if !item.CreatedTime.IsZero() {
nonAttributeMap["Created Time"] = item.CreatedTime.Local().Format(time.RFC1123)
}
if !item.UpdatedTime.IsZero() {
nonAttributeMap["Updated Time"] = item.UpdatedTime.Local().Format(time.RFC1123)
}
if item.Name != "" {
nonAttributeMap["Name"] = item.Name
}
if item.Description != "" {
nonAttributeMap["Description"] = item.Description
}
if item.HostCatalogId != "" {
nonAttributeMap["Host Catalog ID"] = item.HostCatalogId
}
if in.Name != "" {
nonAttributeMap["Name"] = in.Name
}
if in.Description != "" {
nonAttributeMap["Description"] = in.Description
}
maxLength := base.MaxAttributesLength(nonAttributeMap, in.Attributes, keySubstMap)
maxLength := base.MaxAttributesLength(nonAttributeMap, item.Attributes, keySubstMap)
ret := []string{
"",
"Host information:",
base.WrapMap(2, maxLength+2, nonAttributeMap),
"",
" Scope:",
base.ScopeInfoForOutput(in.Scope, maxLength),
}
if len(in.AuthorizedActions) > 0 {
if item.Scope != nil {
ret = append(ret,
"",
" Scope:",
base.ScopeInfoForOutput(item.Scope, maxLength),
)
}
if len(item.AuthorizedActions) > 0 {
ret = append(ret,
"",
" Authorized Actions:",
base.WrapSlice(4, in.AuthorizedActions),
base.WrapSlice(4, item.AuthorizedActions),
)
}
if len(in.HostSetIds) > 0 {
if len(item.HostSetIds) > 0 {
ret = append(ret,
"",
" Host Set IDs:",
base.WrapSlice(4, in.HostSetIds),
base.WrapSlice(4, item.HostSetIds),
)
}
if len(in.Attributes) > 0 {
if len(item.Attributes) > 0 {
ret = append(ret,
"",
" Attributes:",
base.WrapMap(4, maxLength, in.Attributes),
base.WrapMap(4, maxLength, item.Attributes),
)
}
+1 -2
View File
@@ -253,8 +253,7 @@ func (c *Command) Run(args []string) int {
switch base.Format(c.UI) {
case "table":
item := result.GetItem().(*hosts.Host)
c.UI.Output(printItemTable(item))
c.UI.Output(printItemTable(result))
case "json":
if ok := c.PrintJsonItem(result); !ok {
@@ -216,8 +216,7 @@ func (c *StaticCommand) Run(args []string) int {
switch base.Format(c.UI) {
case "table":
item := result.GetItem().(*hosts.Host)
c.UI.Output(printItemTable(item))
c.UI.Output(printItemTable(result))
case "json":
if ok := c.PrintJsonItem(result); !ok {
+64 -36
View File
@@ -182,31 +182,43 @@ func (c *Command) printListTable(items []*hostsets.HostSet) string {
"",
"Host Set information:",
}
for i, m := range items {
for i, item := range items {
if i > 0 {
output = append(output, "")
}
if true {
if item.Id != "" {
output = append(output,
fmt.Sprintf(" ID: %s", m.Id),
fmt.Sprintf(" Version: %d", m.Version),
fmt.Sprintf(" Type: %s", m.Type),
fmt.Sprintf(" ID: %s", item.Id),
)
} else {
output = append(output,
fmt.Sprintf(" ID: %s", "(not available)"),
)
}
if m.Name != "" {
if item.Version > 0 {
output = append(output,
fmt.Sprintf(" Name: %s", m.Name),
fmt.Sprintf(" Version: %d", item.Version),
)
}
if m.Description != "" {
if item.Type != "" {
output = append(output,
fmt.Sprintf(" Description: %s", m.Description),
fmt.Sprintf(" Type: %s", item.Type),
)
}
if len(m.AuthorizedActions) > 0 {
if item.Name != "" {
output = append(output,
fmt.Sprintf(" Name: %s", item.Name),
)
}
if item.Description != "" {
output = append(output,
fmt.Sprintf(" Description: %s", item.Description),
)
}
if len(item.AuthorizedActions) > 0 {
output = append(output,
" Authorized Actions:",
base.WrapSlice(6, m.AuthorizedActions),
base.WrapSlice(6, item.AuthorizedActions),
)
}
}
@@ -214,55 +226,71 @@ func (c *Command) printListTable(items []*hostsets.HostSet) string {
return base.WrapForHelpText(output)
}
func printItemTable(in *hostsets.HostSet) string {
nonAttributeMap := map[string]interface{}{
"ID": in.Id,
"Version": in.Version,
"Type": in.Type,
"Created Time": in.CreatedTime.Local().Format(time.RFC1123),
"Updated Time": in.UpdatedTime.Local().Format(time.RFC1123),
"Host Catalog ID": in.HostCatalogId,
func printItemTable(result api.GenericResult) string {
item := result.GetItem().(*hostsets.HostSet)
nonAttributeMap := map[string]interface{}{}
if item.Id != "" {
nonAttributeMap["ID"] = item.Id
}
if item.Version != 0 {
nonAttributeMap["Version"] = item.Version
}
if item.Type != "" {
nonAttributeMap["Type"] = item.Type
}
if !item.CreatedTime.IsZero() {
nonAttributeMap["Created Time"] = item.CreatedTime.Local().Format(time.RFC1123)
}
if !item.UpdatedTime.IsZero() {
nonAttributeMap["Updated Time"] = item.UpdatedTime.Local().Format(time.RFC1123)
}
if item.Name != "" {
nonAttributeMap["Name"] = item.Name
}
if item.Description != "" {
nonAttributeMap["Description"] = item.Description
}
if item.HostCatalogId != "" {
nonAttributeMap["Host Catalog ID"] = item.HostCatalogId
}
if in.Name != "" {
nonAttributeMap["Name"] = in.Name
}
if in.Description != "" {
nonAttributeMap["Description"] = in.Description
}
maxLength := base.MaxAttributesLength(nonAttributeMap, in.Attributes, keySubstMap)
maxLength := base.MaxAttributesLength(nonAttributeMap, item.Attributes, keySubstMap)
ret := []string{
"",
"Host Set information:",
base.WrapMap(2, maxLength+2, nonAttributeMap),
"",
" Scope:",
base.ScopeInfoForOutput(in.Scope, maxLength),
}
if len(in.AuthorizedActions) > 0 {
if item.Scope != nil {
ret = append(ret,
"",
" Scope:",
base.ScopeInfoForOutput(item.Scope, maxLength),
)
}
if len(item.AuthorizedActions) > 0 {
ret = append(ret,
"",
" Authorized Actions:",
base.WrapSlice(4, in.AuthorizedActions),
base.WrapSlice(4, item.AuthorizedActions),
)
}
if len(in.HostIds) > 0 {
if len(item.HostIds) > 0 {
ret = append(ret,
"",
" Host IDs:",
base.WrapSlice(4, in.HostIds),
base.WrapSlice(4, item.HostIds),
)
}
if len(in.Attributes) > 0 {
if len(item.Attributes) > 0 {
ret = append(ret,
"",
" Attributes:",
base.WrapMap(4, maxLength, in.Attributes),
base.WrapMap(4, maxLength, item.Attributes),
)
}
@@ -283,8 +283,7 @@ func (c *Command) Run(args []string) int {
switch base.Format(c.UI) {
case "table":
item := result.GetItem().(*hostsets.HostSet)
c.UI.Output(printItemTable(item))
c.UI.Output(printItemTable(result))
case "json":
if ok := c.PrintJsonItem(result); !ok {
@@ -214,8 +214,7 @@ func (c *StaticCommand) Run(args []string) int {
switch base.Format(c.UI) {
case "table":
item := result.GetItem().(*hostsets.HostSet)
c.UI.Output(printItemTable(item))
c.UI.Output(printItemTable(result))
case "json":
if ok := c.PrintJsonItem(result); !ok {
+44 -28
View File
@@ -257,17 +257,21 @@ func (c *Command) printListTable(items []*roles.Role) string {
if i > 0 {
output = append(output, "")
}
if true {
if item.Id != "" {
output = append(output,
fmt.Sprintf(" ID: %s", item.Id),
)
}
if c.FlagRecursive {
} else {
output = append(output,
fmt.Sprintf(" Scope ID: %s", item.Scope.Id),
fmt.Sprintf(" ID: %s", "(not available)"),
)
}
if true {
if c.FlagRecursive && item.ScopeId != "" {
output = append(output,
fmt.Sprintf(" Scope ID: %s", item.ScopeId),
)
}
if item.Version > 0 {
output = append(output,
fmt.Sprintf(" Version: %d", item.Version),
)
@@ -293,22 +297,29 @@ func (c *Command) printListTable(items []*roles.Role) string {
return base.WrapForHelpText(output)
}
func printItemTable(in *roles.Role) 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),
func printItemTable(result api.GenericResult) string {
item := result.GetItem().(*roles.Role)
nonAttributeMap := map[string]interface{}{}
if item.Id != "" {
nonAttributeMap["ID"] = item.Id
}
if in.Name != "" {
nonAttributeMap["Name"] = in.Name
if item.Version != 0 {
nonAttributeMap["Version"] = item.Version
}
if in.Description != "" {
nonAttributeMap["Description"] = in.Description
if !item.CreatedTime.IsZero() {
nonAttributeMap["Created Time"] = item.CreatedTime.Local().Format(time.RFC1123)
}
if in.GrantScopeId != "" {
nonAttributeMap["Grant Scope ID"] = in.GrantScopeId
if !item.UpdatedTime.IsZero() {
nonAttributeMap["Updated Time"] = item.UpdatedTime.Local().Format(time.RFC1123)
}
if item.Name != "" {
nonAttributeMap["Name"] = item.Name
}
if item.Description != "" {
nonAttributeMap["Description"] = item.Description
}
if item.GrantScopeId != "" {
nonAttributeMap["Grant Scope ID"] = item.GrantScopeId
}
maxLength := base.MaxAttributesLength(nonAttributeMap, nil, nil)
@@ -317,39 +328,44 @@ func printItemTable(in *roles.Role) string {
"",
"Role information:",
base.WrapMap(2, maxLength+2, nonAttributeMap),
"",
" Scope:",
base.ScopeInfoForOutput(in.Scope, maxLength),
}
if len(in.AuthorizedActions) > 0 {
if item.Scope != nil {
ret = append(ret,
"",
" Authorized Actions:",
base.WrapSlice(4, in.AuthorizedActions),
" Scope:",
base.ScopeInfoForOutput(item.Scope, maxLength),
)
}
if len(in.Principals) > 0 {
if len(item.AuthorizedActions) > 0 {
ret = append(ret,
"",
" Authorized Actions:",
base.WrapSlice(4, item.AuthorizedActions),
)
}
if len(item.Principals) > 0 {
ret = append(ret,
"",
fmt.Sprintf(" Principals: %s", ""),
)
}
for _, principal := range in.Principals {
for _, principal := range item.Principals {
ret = append(ret,
fmt.Sprintf(" ID: %s", principal.Id),
fmt.Sprintf(" Type: %s", principal.Type),
fmt.Sprintf(" Scope ID: %s", principal.ScopeId),
)
}
if len(in.Grants) > 0 {
if len(item.Grants) > 0 {
ret = append(ret,
"",
fmt.Sprintf(" Canonical Grants: %s", ""),
)
}
for _, grant := range in.Grants {
for _, grant := range item.Grants {
ret = append(ret,
fmt.Sprintf(" %s", grant.Canonical),
)
+1 -2
View File
@@ -340,8 +340,7 @@ func (c *Command) Run(args []string) int {
switch base.Format(c.UI) {
case "table":
item := result.GetItem().(*roles.Role)
c.UI.Output(printItemTable(item))
c.UI.Output(printItemTable(result))
case "json":
if ok := c.PrintJsonItem(result); !ok {
+36 -23
View File
@@ -5,6 +5,7 @@ import (
"sort"
"time"
"github.com/hashicorp/boundary/api"
"github.com/hashicorp/boundary/api/scopes"
"github.com/hashicorp/boundary/internal/cmd/base"
)
@@ -96,7 +97,7 @@ func (c *Command) printListTable(items []*scopes.Scope) string {
fmt.Sprintf(" Scope ID: %s", item.Scope.Id),
)
}
if true {
if item.Version > 0 {
output = append(output,
fmt.Sprintf(" Version: %d", item.Version),
)
@@ -127,22 +128,29 @@ func (c *Command) printListTable(items []*scopes.Scope) string {
return base.WrapForHelpText(output)
}
func printItemTable(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),
func printItemTable(result api.GenericResult) string {
item := result.GetItem().(*scopes.Scope)
nonAttributeMap := map[string]interface{}{}
if item.Id != "" {
nonAttributeMap["ID"] = item.Id
}
if in.Name != "" {
nonAttributeMap["Name"] = in.Name
if item.Version != 0 {
nonAttributeMap["Version"] = item.Version
}
if in.Description != "" {
nonAttributeMap["Description"] = in.Description
if !item.CreatedTime.IsZero() {
nonAttributeMap["Created Time"] = item.CreatedTime.Local().Format(time.RFC1123)
}
if in.PrimaryAuthMethodId != "" {
nonAttributeMap[flagPrimaryAuthMethodIdName] = in.PrimaryAuthMethodId
if !item.UpdatedTime.IsZero() {
nonAttributeMap["Updated Time"] = item.UpdatedTime.Local().Format(time.RFC1123)
}
if item.Name != "" {
nonAttributeMap["Name"] = item.Name
}
if item.Description != "" {
nonAttributeMap["Description"] = item.Description
}
if item.PrimaryAuthMethodId != "" {
nonAttributeMap[flagPrimaryAuthMethodIdName] = item.PrimaryAuthMethodId
}
maxLength := base.MaxAttributesLength(nonAttributeMap, nil, nil)
@@ -151,23 +159,28 @@ func printItemTable(in *scopes.Scope) string {
"",
"Scope information:",
base.WrapMap(2, maxLength+2, nonAttributeMap),
"",
" Scope (parent):",
base.ScopeInfoForOutput(in.Scope, maxLength),
}
if len(in.AuthorizedActions) > 0 {
if item.Scope != nil {
ret = append(ret,
"",
" Scope (parent):",
base.ScopeInfoForOutput(item.Scope, maxLength),
)
}
if len(item.AuthorizedActions) > 0 {
ret = append(ret,
"",
" Authorized Actions:",
base.WrapSlice(4, in.AuthorizedActions),
base.WrapSlice(4, item.AuthorizedActions),
"",
)
}
if len(in.AuthorizedCollectionActions) > 0 {
keys := make([]string, 0, len(in.AuthorizedCollectionActions))
for k := range in.AuthorizedCollectionActions {
if len(item.AuthorizedCollectionActions) > 0 {
keys := make([]string, 0, len(item.AuthorizedCollectionActions))
for k := range item.AuthorizedCollectionActions {
keys = append(keys, k)
}
sort.Strings(keys)
@@ -175,7 +188,7 @@ func printItemTable(in *scopes.Scope) string {
for _, key := range keys {
ret = append(ret,
fmt.Sprintf(" %s:", key),
base.WrapSlice(6, in.AuthorizedCollectionActions[key]),
base.WrapSlice(6, item.AuthorizedCollectionActions[key]),
)
}
}
@@ -290,8 +290,7 @@ func (c *Command) Run(args []string) int {
switch base.Format(c.UI) {
case "table":
item := result.GetItem().(*scopes.Scope)
c.UI.Output(printItemTable(item))
c.UI.Output(printItemTable(result))
case "json":
if ok := c.PrintJsonItem(result); !ok {
+89 -34
View File
@@ -76,23 +76,47 @@ func (c *Command) printListTable(items []*sessions.Session) string {
if i > 0 {
output = append(output, "")
}
if true {
if item.Id != "" {
output = append(output,
fmt.Sprintf(" ID: %s", item.Id),
)
}
if c.FlagRecursive {
} else {
output = append(output,
fmt.Sprintf(" Scope ID: %s", item.Scope.Id),
fmt.Sprintf(" ID: %s", "(not available)"),
)
}
if true {
if c.FlagRecursive && item.ScopeId != "" {
output = append(output,
fmt.Sprintf(" Scope ID: %s", item.ScopeId),
)
}
if item.Status != "" {
output = append(output,
fmt.Sprintf(" Status: %s", item.Status),
)
}
if !item.CreatedTime.IsZero() {
output = append(output,
fmt.Sprintf(" Created Time: %s", item.CreatedTime.Local().Format(time.RFC1123)),
)
}
if !item.ExpirationTime.IsZero() {
output = append(output,
fmt.Sprintf(" Expiration Time: %s", item.ExpirationTime.Local().Format(time.RFC1123)),
)
}
if !item.UpdatedTime.IsZero() {
output = append(output,
fmt.Sprintf(" Updated Time: %s", item.UpdatedTime.Local().Format(time.RFC1123)),
)
}
if item.UserId != "" {
output = append(output,
fmt.Sprintf(" User ID: %s", item.UserId),
)
}
if item.TargetId != "" {
output = append(output,
fmt.Sprintf(" Target ID: %s", item.TargetId),
)
}
@@ -107,31 +131,57 @@ func (c *Command) printListTable(items []*sessions.Session) string {
return base.WrapForHelpText(output)
}
func printItemTable(in *sessions.Session) string {
nonAttributeMap := map[string]interface{}{
"ID": in.Id,
"Target ID": in.TargetId,
"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,
"User ID": in.UserId,
"Host Set ID": in.HostSetId,
"Host ID": in.HostId,
"Endpoint": in.Endpoint,
"Status": in.Status,
func printItemTable(result api.GenericResult) string {
item := result.GetItem().(*sessions.Session)
nonAttributeMap := map[string]interface{}{}
if item.Id != "" {
nonAttributeMap["ID"] = item.Id
}
if len(strings.TrimSpace(in.TerminationReason)) > 0 {
nonAttributeMap["Termination Reason"] = in.TerminationReason
if item.Version != 0 {
nonAttributeMap["Version"] = item.Version
}
if item.Type != "" {
nonAttributeMap["Type"] = item.Type
}
if !item.CreatedTime.IsZero() {
nonAttributeMap["Created Time"] = item.CreatedTime.Local().Format(time.RFC1123)
}
if !item.UpdatedTime.IsZero() {
nonAttributeMap["Updated Time"] = item.UpdatedTime.Local().Format(time.RFC1123)
}
if !item.ExpirationTime.IsZero() {
nonAttributeMap["Expiration Time"] = item.ExpirationTime.Local().Format(time.RFC1123)
}
if item.TargetId != "" {
nonAttributeMap["Target ID"] = item.TargetId
}
if item.AuthTokenId != "" {
nonAttributeMap["Auth Token ID"] = item.AuthTokenId
}
if item.UserId != "" {
nonAttributeMap["User ID"] = item.UserId
}
if item.HostSetId != "" {
nonAttributeMap["Host Set ID"] = item.HostSetId
}
if item.HostId != "" {
nonAttributeMap["Host ID"] = item.HostId
}
if item.Endpoint != "" {
nonAttributeMap["Endpoint"] = item.Endpoint
}
if item.Status != "" {
nonAttributeMap["Status"] = item.Status
}
if len(strings.TrimSpace(item.TerminationReason)) > 0 {
nonAttributeMap["Termination Reason"] = item.TerminationReason
}
maxLength := base.MaxAttributesLength(nonAttributeMap, nil, nil)
var statesMaps []map[string]interface{}
if len(in.States) > 0 {
for _, state := range in.States {
if len(item.States) > 0 {
for _, state := range item.States {
m := map[string]interface{}{
"Status": state.Status,
"Start Time": state.StartTime.Local().Format(time.RFC1123),
@@ -147,8 +197,8 @@ func printItemTable(in *sessions.Session) string {
}
var workerInfoMaps []map[string]interface{}
if len(in.WorkerInfo) > 0 {
for _, wi := range in.WorkerInfo {
if len(item.WorkerInfo) > 0 {
for _, wi := range item.WorkerInfo {
m := map[string]interface{}{
"Address": wi.Address,
}
@@ -163,20 +213,25 @@ func printItemTable(in *sessions.Session) string {
"",
"Session information:",
base.WrapMap(2, maxLength+2, nonAttributeMap),
"",
" Scope:",
base.ScopeInfoForOutput(in.Scope, maxLength),
}
if len(in.AuthorizedActions) > 0 {
if item.Scope != nil {
ret = append(ret,
"",
" Authorized Actions:",
base.WrapSlice(4, in.AuthorizedActions),
" Scope:",
base.ScopeInfoForOutput(item.Scope, maxLength),
)
}
if len(in.States) > 0 {
if len(item.AuthorizedActions) > 0 {
ret = append(ret,
"",
" Authorized Actions:",
base.WrapSlice(4, item.AuthorizedActions),
)
}
if len(item.States) > 0 {
ret = append(ret,
"",
" States:",
@@ -189,7 +244,7 @@ func printItemTable(in *sessions.Session) string {
}
}
if len(in.WorkerInfo) > 0 {
if len(item.WorkerInfo) > 0 {
ret = append(ret,
fmt.Sprintf(" Worker Info: %s", ""),
)
@@ -225,8 +225,7 @@ func (c *Command) Run(args []string) int {
switch base.Format(c.UI) {
case "table":
item := result.GetItem().(*sessions.Session)
c.UI.Output(printItemTable(item))
c.UI.Output(printItemTable(result))
case "json":
if ok := c.PrintJsonItem(result); !ok {
+60 -29
View File
@@ -8,6 +8,7 @@ import (
"github.com/hashicorp/boundary/api"
"github.com/hashicorp/boundary/api/scopes"
"github.com/hashicorp/boundary/api/targets"
"github.com/hashicorp/boundary/globals"
"github.com/hashicorp/boundary/internal/cmd/base"
"github.com/hashicorp/boundary/sdk/strutil"
"github.com/mitchellh/go-wordwrap"
@@ -286,40 +287,48 @@ func (c *Command) printListTable(items []*targets.Target) string {
"",
"Target information:",
}
for i, m := range items {
for i, item := range items {
if i > 0 {
output = append(output, "")
}
if true {
if item.Id != "" {
output = append(output,
fmt.Sprintf(" ID: %s", m.Id),
fmt.Sprintf(" ID: %s", item.Id),
)
} else {
output = append(output,
fmt.Sprintf(" ID: %s", "(not available)"),
)
}
if c.FlagRecursive {
if c.FlagRecursive && item.ScopeId != "" {
output = append(output,
fmt.Sprintf(" Scope ID: %s", m.Scope.Id),
fmt.Sprintf(" Scope ID: %s", item.ScopeId),
)
}
if true {
if item.Version > 0 {
output = append(output,
fmt.Sprintf(" Version: %d", m.Version),
fmt.Sprintf(" Type: %s", m.Type),
fmt.Sprintf(" Version: %d", item.Version),
)
}
if m.Name != "" {
if item.Type != "" {
output = append(output,
fmt.Sprintf(" Name: %s", m.Name),
fmt.Sprintf(" Type: %s", item.Type),
)
}
if m.Description != "" {
if item.Name != "" {
output = append(output,
fmt.Sprintf(" Description: %s", m.Description),
fmt.Sprintf(" Name: %s", item.Name),
)
}
if len(m.AuthorizedActions) > 0 {
if item.Description != "" {
output = append(output,
fmt.Sprintf(" Description: %s", item.Description),
)
}
if len(item.AuthorizedActions) > 0 {
output = append(output,
" Authorized Actions:",
base.WrapSlice(6, m.AuthorizedActions),
base.WrapSlice(6, item.AuthorizedActions),
)
}
}
@@ -327,17 +336,24 @@ func (c *Command) printListTable(items []*targets.Target) string {
return base.WrapForHelpText(output)
}
func printItemTable(item *targets.Target) string {
nonAttributeMap := map[string]interface{}{
"ID": item.Id,
"Version": item.Version,
"Type": item.Type,
"Created Time": item.CreatedTime.Local().Format(time.RFC1123),
"Updated Time": item.UpdatedTime.Local().Format(time.RFC1123),
"Session Connection Limit": item.SessionConnectionLimit,
"Session Max Seconds": item.SessionMaxSeconds,
func printItemTable(result api.GenericResult) string {
item := result.GetItem().(*targets.Target)
nonAttributeMap := map[string]interface{}{}
if item.Id != "" {
nonAttributeMap["ID"] = item.Id
}
if item.Version != 0 {
nonAttributeMap["Version"] = item.Version
}
if item.Type != "" {
nonAttributeMap["Type"] = item.Type
}
if !item.CreatedTime.IsZero() {
nonAttributeMap["Created Time"] = item.CreatedTime.Local().Format(time.RFC1123)
}
if !item.UpdatedTime.IsZero() {
nonAttributeMap["Updated Time"] = item.UpdatedTime.Local().Format(time.RFC1123)
}
if item.Name != "" {
nonAttributeMap["Name"] = item.Name
}
@@ -347,6 +363,14 @@ func printItemTable(item *targets.Target) string {
if item.WorkerFilter != "" {
nonAttributeMap["Worker Filter"] = item.WorkerFilter
}
if result.GetResponse() != nil && result.GetResponse().Map != nil {
if result.GetResponse().Map[globals.SessionConnectionLimitField] != nil {
nonAttributeMap["Session Connection Limit"] = item.SessionConnectionLimit
}
if result.GetResponse().Map[globals.SessionMaxSecondsField] != nil {
nonAttributeMap["Session Max Seconds"] = item.SessionMaxSeconds
}
}
maxLength := base.MaxAttributesLength(nonAttributeMap, item.Attributes, keySubstMap)
@@ -368,9 +392,14 @@ func printItemTable(item *targets.Target) string {
"",
"Target information:",
base.WrapMap(2, maxLength+2, nonAttributeMap),
"",
" Scope:",
base.ScopeInfoForOutput(item.Scope, maxLength),
}
if item.Scope != nil {
ret = append(ret,
"",
" Scope:",
base.ScopeInfoForOutput(item.Scope, maxLength),
)
}
if len(item.AuthorizedActions) > 0 {
@@ -459,7 +488,7 @@ var keySubstMap = map[string]string{
}
func exampleOutput() string {
in := &targets.Target{
item := &targets.Target{
Id: "ttcp_1234567890",
ScopeId: "global",
Scope: &scopes.ScopeInfo{
@@ -486,5 +515,7 @@ func exampleOutput() string {
"default_port": 22,
},
}
return printItemTable(in)
target := new(targets.TargetReadResult)
target.Item = item
return printItemTable(target)
}
@@ -289,8 +289,7 @@ func (c *Command) Run(args []string) int {
switch base.Format(c.UI) {
case "table":
item := result.GetItem().(*targets.Target)
c.UI.Output(printItemTable(item))
c.UI.Output(printItemTable(result))
case "json":
if ok := c.PrintJsonItem(result); !ok {
@@ -221,8 +221,7 @@ func (c *TcpCommand) Run(args []string) int {
switch base.Format(c.UI) {
case "table":
item := result.GetItem().(*targets.Target)
c.UI.Output(printItemTable(item))
c.UI.Output(printItemTable(result))
case "json":
if ok := c.PrintJsonItem(result); !ok {
+65 -49
View File
@@ -150,60 +150,64 @@ func (c *Command) printListTable(items []*users.User) string {
"User information:",
}
for i, u := range items {
for i, item := range items {
if i > 0 {
output = append(output, "")
}
if true {
if item.Id != "" {
output = append(output,
fmt.Sprintf(" ID: %s", u.Id),
fmt.Sprintf(" ID: %s", item.Id),
)
} else {
output = append(output,
fmt.Sprintf(" ID: %s", "(not available)"),
)
}
if c.FlagRecursive {
if c.FlagRecursive && item.ScopeId != "" {
output = append(output,
fmt.Sprintf(" Scope ID: %s", u.Scope.Id),
fmt.Sprintf(" Scope ID: %s", item.ScopeId),
)
}
if true {
if item.Version > 0 {
output = append(output,
fmt.Sprintf(" Version: %d", u.Version),
fmt.Sprintf(" Version: %d", item.Version),
)
}
if u.Name != "" {
if item.Name != "" {
output = append(output,
fmt.Sprintf(" Name: %s", u.Name),
fmt.Sprintf(" Name: %s", item.Name),
)
}
if u.Description != "" {
if item.Description != "" {
output = append(output,
fmt.Sprintf(" Description: %s", u.Description),
fmt.Sprintf(" Description: %s", item.Description),
)
}
if u.PrimaryAccountId != "" {
if item.PrimaryAccountId != "" {
output = append(output,
fmt.Sprintf(" Primary Account ID: %s", u.PrimaryAccountId),
fmt.Sprintf(" Primary Account ID: %s", item.PrimaryAccountId),
)
}
if u.LoginName != "" {
if item.LoginName != "" {
output = append(output,
fmt.Sprintf(" Login Name: %s", u.LoginName),
fmt.Sprintf(" Login Name: %s", item.LoginName),
)
}
if u.FullName != "" {
if item.FullName != "" {
output = append(output,
fmt.Sprintf(" Full Name: %s", u.FullName),
fmt.Sprintf(" Full Name: %s", item.FullName),
)
}
if u.Email != "" {
if item.Email != "" {
output = append(output,
fmt.Sprintf(" Email: %s", u.Email),
fmt.Sprintf(" Email: %s", item.Email),
)
}
if len(u.AuthorizedActions) > 0 {
if len(item.AuthorizedActions) > 0 {
output = append(output,
" Authorized Actions:",
base.WrapSlice(6, u.AuthorizedActions),
base.WrapSlice(6, item.AuthorizedActions),
)
}
}
@@ -211,38 +215,45 @@ func (c *Command) printListTable(items []*users.User) string {
return base.WrapForHelpText(output)
}
func printItemTable(in *users.User) 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),
func printItemTable(result api.GenericResult) string {
item := result.GetItem().(*users.User)
nonAttributeMap := map[string]interface{}{}
if item.Id != "" {
nonAttributeMap["ID"] = item.Id
}
if in.Name != "" {
nonAttributeMap["Name"] = in.Name
if item.Version != 0 {
nonAttributeMap["Version"] = item.Version
}
if in.Description != "" {
nonAttributeMap["Description"] = in.Description
if !item.CreatedTime.IsZero() {
nonAttributeMap["Created Time"] = item.CreatedTime.Local().Format(time.RFC1123)
}
if in.PrimaryAccountId != "" {
nonAttributeMap["PrimaryAccountId"] = in.PrimaryAccountId
if !item.UpdatedTime.IsZero() {
nonAttributeMap["Updated Time"] = item.UpdatedTime.Local().Format(time.RFC1123)
}
if in.LoginName != "" {
nonAttributeMap["LoginName"] = in.LoginName
if item.Name != "" {
nonAttributeMap["Name"] = item.Name
}
if in.FullName != "" {
nonAttributeMap["FullName"] = in.FullName
if item.Description != "" {
nonAttributeMap["Description"] = item.Description
}
if in.Email != "" {
nonAttributeMap["Email"] = in.Email
if item.PrimaryAccountId != "" {
nonAttributeMap["Primary Account Id"] = item.PrimaryAccountId
}
if item.LoginName != "" {
nonAttributeMap["Login Name"] = item.LoginName
}
if item.FullName != "" {
nonAttributeMap["Full Name"] = item.FullName
}
if item.Email != "" {
nonAttributeMap["Email"] = item.Email
}
maxLength := base.MaxAttributesLength(nonAttributeMap, nil, nil)
var userMaps []map[string]interface{}
if len(in.Accounts) > 0 {
for _, account := range in.Accounts {
if len(item.Accounts) > 0 {
for _, account := range item.Accounts {
a := map[string]interface{}{
"ID": account.Id,
"Scope ID": account.ScopeId,
@@ -258,20 +269,25 @@ func printItemTable(in *users.User) string {
"",
"User information:",
base.WrapMap(2, maxLength+2, nonAttributeMap),
"",
" Scope:",
base.ScopeInfoForOutput(in.Scope, maxLength),
}
if len(in.AuthorizedActions) > 0 {
if item.Scope != nil {
ret = append(ret,
"",
" Authorized Actions:",
base.WrapSlice(4, in.AuthorizedActions),
" Scope:",
base.ScopeInfoForOutput(item.Scope, maxLength),
)
}
if len(in.Accounts) > 0 {
if len(item.AuthorizedActions) > 0 {
ret = append(ret,
"",
" Authorized Actions:",
base.WrapSlice(4, item.AuthorizedActions),
)
}
if len(item.Accounts) > 0 {
ret = append(ret,
"",
" Accounts:",
+1 -2
View File
@@ -316,8 +316,7 @@ func (c *Command) Run(args []string) int {
switch base.Format(c.UI) {
case "table":
item := result.GetItem().(*users.User)
c.UI.Output(printItemTable(item))
c.UI.Output(printItemTable(result))
case "json":
if ok := c.PrintJsonItem(result); !ok {
+1 -2
View File
@@ -413,8 +413,7 @@ func (c *{{ camelCase .SubActionPrefix }}Command) Run(args []string) int {
switch base.Format(c.UI) {
case "table":
item := result.GetItem().(*{{ .Pkg }}.{{ camelCase .ResourceType }})
c.UI.Output(printItemTable(item))
c.UI.Output(printItemTable(result))
case "json":
if ok := c.PrintJsonItem(result); !ok {