Add authorized actions output on resources (#870)

This commit is contained in:
Jeff Mitchell authored and GitHub committed 2021-01-20 10:53:01 -05:00
1 parent ec6151d174
commit dcb15cffbd
93 files changed
+2475 -1038

No files matched your search

+11 -5
View File
@@ -341,19 +341,25 @@ func (c *Command) Run(args []string) int {
}
if true {
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", m.Id),
fmt.Sprintf(" Version: %d", m.Version),
fmt.Sprintf(" Type: %s", m.Type),
)
}
if m.Name != "" {
output = append(output,
fmt.Sprintf(" Name: %s", m.Name),
fmt.Sprintf(" Name: %s", m.Name),
)
}
if m.Description != "" {
output = append(output,
fmt.Sprintf(" Description: %s", m.Description),
fmt.Sprintf(" Description: %s", m.Description),
)
}
if len(m.AuthorizedActions) > 0 {
output = append(output,
" Authorized Actions:",
base.WrapSlice(6, m.AuthorizedActions),
)
}
}
+8
View File
@@ -35,6 +35,14 @@ func generateAccountTableOutput(in *accounts.Account) string {
base.ScopeInfoForOutput(in.Scope, maxLength),
}
if len(in.AuthorizedActions) > 0 {
ret = append(ret,
"",
" Authorized Actions:",
base.WrapSlice(4, in.AuthorizedActions),
)
}
if len(in.Attributes) > 0 {
ret = append(ret,
"",
@@ -227,23 +227,29 @@ func (c *Command) Run(args []string) int {
}
if true {
output = append(output,
fmt.Sprintf(" ID: %s", m.Id),
fmt.Sprintf(" ID: %s", m.Id),
)
}
if m.Description != "" {
output = append(output,
fmt.Sprintf(" Description: %s", m.Description),
fmt.Sprintf(" Description: %s", m.Description),
)
}
if m.Name != "" {
output = append(output,
fmt.Sprintf(" Name: %s", m.Name),
fmt.Sprintf(" Name: %s", m.Name),
)
}
if true {
output = append(output,
fmt.Sprintf(" Type: %s", m.Type),
fmt.Sprintf(" Version: %d", m.Version),
fmt.Sprintf(" Type: %s", m.Type),
fmt.Sprintf(" Version: %d", m.Version),
)
}
if len(m.AuthorizedActions) > 0 {
output = append(output,
" Authorized Actions:",
base.WrapSlice(6, m.AuthorizedActions),
)
}
}
@@ -1,6 +1,8 @@
package authmethods
import (
"fmt"
"sort"
"time"
"github.com/hashicorp/boundary/api/authmethods"
@@ -47,6 +49,32 @@ func generateAuthMethodTableOutput(in *authmethods.AuthMethod) string {
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 Auth Method's Collections:",
)
for _, key := range keys {
ret = append(ret,
fmt.Sprintf(" %ss:", key),
base.WrapSlice(6, in.AuthorizedCollectionActions[key]),
)
}
}
if len(in.Attributes) > 0 {
ret = append(ret,
"",
@@ -177,6 +177,12 @@ func (c *Command) Run(args []string) int {
fmt.Sprintf(" Updated Time: %s", t.UpdatedTime.Local().Format(time.RFC1123)),
fmt.Sprintf(" User ID: %s", t.UserId),
)
if len(t.AuthorizedActions) > 0 {
output = append(output,
" Authorized Actions:",
base.WrapSlice(6, t.AuthorizedActions),
)
}
}
c.UI.Output(base.WrapForHelpText(output))
}
@@ -29,5 +29,13 @@ func generateAuthTokenTableOutput(in *authtokens.AuthToken) string {
base.ScopeInfoForOutput(in.Scope, maxLength),
}
if len(in.AuthorizedActions) > 0 {
ret = append(ret,
"",
" Authorized Actions:",
base.WrapSlice(4, in.AuthorizedActions),
)
}
return base.WrapForHelpText(ret)
}
+9
View File
@@ -111,10 +111,19 @@ func generateGroupTableOutput(in *groups.Group) string {
"",
"Group information:",
base.WrapMap(2, maxLength+2, nonAttributeMap),
"",
" Scope:",
base.ScopeInfoForOutput(in.Scope, maxLength),
}
if len(in.AuthorizedActions) > 0 {
ret = append(ret,
"",
" Authorized Actions:",
base.WrapSlice(4, in.AuthorizedActions),
)
}
if len(in.Members) > 0 {
ret = append(ret,
"",
+10 -4
View File
@@ -247,18 +247,24 @@ func (c *Command) Run(args []string) int {
}
if true {
output = append(output,
fmt.Sprintf(" ID: %s", g.Id),
fmt.Sprintf(" Version: %d", g.Version),
fmt.Sprintf(" ID: %s", g.Id),
fmt.Sprintf(" Version: %d", g.Version),
)
}
if g.Name != "" {
output = append(output,
fmt.Sprintf(" Name: %s", g.Name),
fmt.Sprintf(" Name: %s", g.Name),
)
}
if g.Description != "" {
output = append(output,
fmt.Sprintf(" Description: %s", g.Description),
fmt.Sprintf(" Description: %s", g.Description),
)
}
if len(g.AuthorizedActions) > 0 {
output = append(output,
" Authorized Actions:",
base.WrapSlice(6, g.AuthorizedActions),
)
}
}
@@ -1,6 +1,8 @@
package hostcatalogs
import (
"fmt"
"sort"
"time"
"github.com/hashicorp/boundary/api/hostcatalogs"
@@ -34,6 +36,31 @@ func generateHostCatalogTableOutput(in *hostcatalogs.HostCatalog) string {
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 Host Catalog's Collections:",
)
for _, key := range keys {
ret = append(ret,
fmt.Sprintf(" %ss:", key),
base.WrapSlice(6, in.AuthorizedCollectionActions[key]),
)
}
}
if len(in.Attributes) > 0 {
ret = append(ret,
"",
@@ -228,19 +228,25 @@ func (c *Command) Run(args []string) int {
}
if true {
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", m.Id),
fmt.Sprintf(" Version: %d", m.Version),
fmt.Sprintf(" Type: %s", m.Type),
)
}
if m.Name != "" {
output = append(output,
fmt.Sprintf(" Name: %s", m.Name),
fmt.Sprintf(" Name: %s", m.Name),
)
}
if m.Description != "" {
output = append(output,
fmt.Sprintf(" Description: %s", m.Description),
fmt.Sprintf(" Description: %s", m.Description),
)
}
if len(m.AuthorizedActions) > 0 {
output = append(output,
" Authorized Actions:",
base.WrapSlice(6, m.AuthorizedActions),
)
}
}
+8
View File
@@ -35,6 +35,14 @@ func generateHostTableOutput(in *hosts.Host) string {
base.ScopeInfoForOutput(in.Scope, maxLength),
}
if len(in.AuthorizedActions) > 0 {
ret = append(ret,
"",
" Authorized Actions:",
base.WrapSlice(4, in.AuthorizedActions),
)
}
if len(in.HostSetIds) > 0 {
ret = append(ret,
"",
+11 -5
View File
@@ -227,19 +227,25 @@ func (c *Command) Run(args []string) int {
}
if true {
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", m.Id),
fmt.Sprintf(" Version: %d", m.Version),
fmt.Sprintf(" Type: %s", m.Type),
)
}
if m.Name != "" {
output = append(output,
fmt.Sprintf(" Name: %s", m.Name),
fmt.Sprintf(" Name: %s", m.Name),
)
}
if m.Description != "" {
output = append(output,
fmt.Sprintf(" Description: %s", m.Description),
fmt.Sprintf(" Description: %s", m.Description),
)
}
if len(m.AuthorizedActions) > 0 {
output = append(output,
" Authorized Actions:",
base.WrapSlice(6, m.AuthorizedActions),
)
}
}
+8
View File
@@ -35,6 +35,14 @@ func generateHostSetTableOutput(in *hostsets.HostSet) string {
base.ScopeInfoForOutput(in.Scope, maxLength),
}
if len(in.AuthorizedActions) > 0 {
ret = append(ret,
"",
" Authorized Actions:",
base.WrapSlice(4, in.AuthorizedActions),
)
}
if len(in.HostIds) > 0 {
ret = append(ret,
"",
+11 -5
View File
@@ -322,19 +322,25 @@ func (c *Command) Run(args []string) int {
}
if true {
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", m.Id),
fmt.Sprintf(" Version: %d", m.Version),
fmt.Sprintf(" Type: %s", m.Type),
)
}
if m.Name != "" {
output = append(output,
fmt.Sprintf(" Name: %s", m.Name),
fmt.Sprintf(" Name: %s", m.Name),
)
}
if m.Description != "" {
output = append(output,
fmt.Sprintf(" Description: %s", m.Description),
fmt.Sprintf(" Description: %s", m.Description),
)
}
if len(m.AuthorizedActions) > 0 {
output = append(output,
" Authorized Actions:",
base.WrapSlice(6, m.AuthorizedActions),
)
}
}
+8
View File
@@ -115,6 +115,14 @@ func generateRoleTableOutput(in *roles.Role) string {
base.ScopeInfoForOutput(in.Scope, maxLength),
}
if len(in.AuthorizedActions) > 0 {
ret = append(ret,
"",
" Authorized Actions:",
base.WrapSlice(4, in.AuthorizedActions),
)
}
if len(in.Principals) > 0 {
ret = append(ret,
"",
+10 -4
View File
@@ -300,18 +300,24 @@ func (c *Command) Run(args []string) int {
}
if true {
output = append(output,
fmt.Sprintf(" ID: %s", r.Id),
fmt.Sprintf(" Version: %d", r.Version),
fmt.Sprintf(" ID: %s", r.Id),
fmt.Sprintf(" Version: %d", r.Version),
)
}
if r.Name != "" {
output = append(output,
fmt.Sprintf(" Name: %s", r.Name),
fmt.Sprintf(" Name: %s", r.Name),
)
}
if r.Description != "" {
output = append(output,
fmt.Sprintf(" Description: %s", r.Description),
fmt.Sprintf(" Description: %s", r.Description),
)
}
if len(r.AuthorizedActions) > 0 {
output = append(output,
" Authorized Actions:",
base.WrapSlice(6, r.AuthorizedActions),
)
}
}
+26
View File
@@ -1,6 +1,8 @@
package scopes
import (
"fmt"
"sort"
"time"
"github.com/hashicorp/boundary/api/scopes"
@@ -33,5 +35,29 @@ func generateScopeTableOutput(in *scopes.Scope) string {
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)
}
+10 -4
View File
@@ -227,18 +227,24 @@ func (c *Command) Run(args []string) int {
}
if true {
output = append(output,
fmt.Sprintf(" ID: %s", s.Id),
fmt.Sprintf(" Version: %d", s.Version),
fmt.Sprintf(" ID: %s", s.Id),
fmt.Sprintf(" Version: %d", s.Version),
)
}
if s.Name != "" {
output = append(output,
fmt.Sprintf(" Name: %s", s.Name),
fmt.Sprintf(" Name: %s", s.Name),
)
}
if s.Description != "" {
output = append(output,
fmt.Sprintf(" Description: %s", s.Description),
fmt.Sprintf(" Description: %s", s.Description),
)
}
if len(s.AuthorizedActions) > 0 {
output = append(output,
" Authorized Actions:",
base.WrapSlice(6, s.AuthorizedActions),
)
}
}
+8
View File
@@ -70,6 +70,14 @@ func generateSessionTableOutput(in *sessions.Session) string {
base.ScopeInfoForOutput(in.Scope, maxLength),
}
if len(in.AuthorizedActions) > 0 {
ret = append(ret,
"",
" Authorized Actions:",
base.WrapSlice(4, in.AuthorizedActions),
)
}
if len(in.States) > 0 {
ret = append(ret,
"",
+13 -7
View File
@@ -168,14 +168,20 @@ func (c *Command) Run(args []string) int {
output = append(output, "")
}
output = append(output,
fmt.Sprintf(" ID: %s", t.Id),
fmt.Sprintf(" Status: %s", t.Status),
fmt.Sprintf(" Created Time: %s", t.CreatedTime.Local().Format(time.RFC1123)),
fmt.Sprintf(" Expiration Time: %s", t.ExpirationTime.Local().Format(time.RFC1123)),
fmt.Sprintf(" Updated Time: %s", t.UpdatedTime.Local().Format(time.RFC1123)),
fmt.Sprintf(" User ID: %s", t.UserId),
fmt.Sprintf(" Target ID: %s", t.TargetId),
fmt.Sprintf(" ID: %s", t.Id),
fmt.Sprintf(" Status: %s", t.Status),
fmt.Sprintf(" Created Time: %s", t.CreatedTime.Local().Format(time.RFC1123)),
fmt.Sprintf(" Expiration Time: %s", t.ExpirationTime.Local().Format(time.RFC1123)),
fmt.Sprintf(" Updated Time: %s", t.UpdatedTime.Local().Format(time.RFC1123)),
fmt.Sprintf(" User ID: %s", t.UserId),
fmt.Sprintf(" Target ID: %s", t.TargetId),
)
if len(t.AuthorizedActions) > 0 {
output = append(output,
" Authorized Actions:",
base.WrapSlice(6, t.AuthorizedActions),
)
}
}
c.UI.Output(base.WrapForHelpText(output))
}
+8 -8
View File
@@ -67,6 +67,14 @@ func generateTargetTableOutput(in *targets.Target) string {
base.ScopeInfoForOutput(in.Scope, maxLength),
}
if len(in.AuthorizedActions) > 0 {
ret = append(ret,
"",
" Authorized Actions:",
base.WrapSlice(4, in.AuthorizedActions),
)
}
if len(in.HostSets) > 0 {
ret = append(ret,
"",
@@ -80,14 +88,6 @@ func generateTargetTableOutput(in *targets.Target) string {
}
}
if len(in.AuthorizedActions) > 0 {
ret = append(ret,
" Authorized Actions:",
base.WrapSlice(4, in.AuthorizedActions),
"",
)
}
if len(in.Attributes) > 0 {
ret = append(ret,
" Attributes:",
+11 -5
View File
@@ -427,19 +427,25 @@ func (c *Command) Run(args []string) int {
}
if true {
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", m.Id),
fmt.Sprintf(" Version: %d", m.Version),
fmt.Sprintf(" Type: %s", m.Type),
)
}
if m.Name != "" {
output = append(output,
fmt.Sprintf(" Name: %s", m.Name),
fmt.Sprintf(" Name: %s", m.Name),
)
}
if m.Description != "" {
output = append(output,
fmt.Sprintf(" Description: %s", m.Description),
fmt.Sprintf(" Description: %s", m.Description),
)
}
if len(m.AuthorizedActions) > 0 {
output = append(output,
" Authorized Actions:",
base.WrapSlice(6, m.AuthorizedActions),
)
}
}
+8
View File
@@ -110,6 +110,14 @@ func generateUserTableOutput(in *users.User) string {
base.ScopeInfoForOutput(in.Scope, maxLength),
}
if len(in.AuthorizedActions) > 0 {
ret = append(ret,
"",
" Authorized Actions:",
base.WrapSlice(4, in.AuthorizedActions),
)
}
if len(in.Accounts) > 0 {
ret = append(ret,
"",
+10 -4
View File
@@ -247,18 +247,24 @@ func (c *Command) Run(args []string) int {
}
if true {
output = append(output,
fmt.Sprintf(" ID: %s", u.Id),
fmt.Sprintf(" Version: %d", u.Version),
fmt.Sprintf(" ID: %s", u.Id),
fmt.Sprintf(" Version: %d", u.Version),
)
}
if u.Name != "" {
output = append(output,
fmt.Sprintf(" Name: %s", u.Name),
fmt.Sprintf(" Name: %s", u.Name),
)
}
if u.Description != "" {
output = append(output,
fmt.Sprintf(" Description: %s", u.Description),
fmt.Sprintf(" Description: %s", u.Description),
)
}
if len(u.AuthorizedActions) > 0 {
output = append(output,
" Authorized Actions:",
base.WrapSlice(6, u.AuthorizedActions),
)
}
}