mirror of
https://github.com/minio/mc.git
synced 2025-11-25 08:23:07 +03:00
Show groups with their policy details while listing users (#4578)
Signed-off-by: Shubhendu Ram Tripathi <shubhendu@minio.io>
This commit is contained in:
@@ -83,15 +83,21 @@ func checkAdminUserAddSyntax(ctx *cli.Context) {
|
||||
}
|
||||
}
|
||||
|
||||
// userGroup container for content message structure
|
||||
type userGroup struct {
|
||||
Name string `json:"name,omitempty"`
|
||||
Policies []string `json:"policies,omitempty"`
|
||||
}
|
||||
|
||||
// userMessage container for content message structure
|
||||
type userMessage struct {
|
||||
op string
|
||||
Status string `json:"status"` // TODO: remove this?
|
||||
AccessKey string `json:"accessKey,omitempty"`
|
||||
SecretKey string `json:"secretKey,omitempty"`
|
||||
PolicyName string `json:"policyName,omitempty"`
|
||||
UserStatus string `json:"userStatus,omitempty"`
|
||||
MemberOf []string `json:"memberOf,omitempty"`
|
||||
Status string `json:"status"` // TODO: remove this?
|
||||
AccessKey string `json:"accessKey,omitempty"`
|
||||
SecretKey string `json:"secretKey,omitempty"`
|
||||
PolicyName string `json:"policyName,omitempty"`
|
||||
UserStatus string `json:"userStatus,omitempty"`
|
||||
MemberOf []userGroup `json:"memberOf,omitempty"`
|
||||
}
|
||||
|
||||
func (u userMessage) String() string {
|
||||
@@ -108,12 +114,16 @@ func (u userMessage) String() string {
|
||||
Field{"PolicyName", policyFieldMaxLen},
|
||||
).buildRow(u.UserStatus, u.AccessKey, u.PolicyName)
|
||||
case "info":
|
||||
memberOf := []string{}
|
||||
for _, group := range u.MemberOf {
|
||||
memberOf = append(memberOf, group.Name)
|
||||
}
|
||||
return console.Colorize("UserMessage", strings.Join(
|
||||
[]string{
|
||||
fmt.Sprintf("AccessKey: %s", u.AccessKey),
|
||||
fmt.Sprintf("Status: %s", u.UserStatus),
|
||||
fmt.Sprintf("PolicyName: %s", u.PolicyName),
|
||||
fmt.Sprintf("MemberOf: %s", strings.Join(u.MemberOf, ",")),
|
||||
fmt.Sprintf("MemberOf: %s", memberOf),
|
||||
}, "\n"))
|
||||
case "remove":
|
||||
return console.Colorize("UserMessage", "Removed user `"+u.AccessKey+"` successfully.")
|
||||
|
||||
@@ -18,6 +18,8 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/fatih/color"
|
||||
"github.com/minio/cli"
|
||||
"github.com/minio/mc/pkg/probe"
|
||||
@@ -70,12 +72,26 @@ func mainAdminUserInfo(ctx *cli.Context) error {
|
||||
user, e := client.GetUserInfo(globalContext, args.Get(1))
|
||||
fatalIf(probe.NewError(e).Trace(args...), "Unable to get user info")
|
||||
|
||||
memberOf := []userGroup{}
|
||||
for _, group := range user.MemberOf {
|
||||
gd, e := client.GetGroupDescription(globalContext, group)
|
||||
fatalIf(probe.NewError(e).Trace(args...), "Unable to fetch group info")
|
||||
policies := []string{}
|
||||
if gd.Policy != "" {
|
||||
policies = strings.Split(gd.Policy, ",")
|
||||
}
|
||||
memberOf = append(memberOf, userGroup{
|
||||
Name: gd.Name,
|
||||
Policies: policies,
|
||||
})
|
||||
}
|
||||
|
||||
printMsg(userMessage{
|
||||
op: ctx.Command.Name,
|
||||
AccessKey: args.Get(1),
|
||||
PolicyName: user.PolicyName,
|
||||
UserStatus: string(user.Status),
|
||||
MemberOf: user.MemberOf,
|
||||
MemberOf: memberOf,
|
||||
})
|
||||
|
||||
return nil
|
||||
|
||||
@@ -18,6 +18,8 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/fatih/color"
|
||||
"github.com/minio/cli"
|
||||
"github.com/minio/mc/pkg/probe"
|
||||
@@ -76,11 +78,24 @@ func mainAdminUserList(ctx *cli.Context) error {
|
||||
fatalIf(probe.NewError(e).Trace(args...), "Unable to list user")
|
||||
|
||||
for k, v := range users {
|
||||
memberOf := []userGroup{}
|
||||
for _, group := range v.MemberOf {
|
||||
gd, e := client.GetGroupDescription(globalContext, group)
|
||||
fatalIf(probe.NewError(e).Trace(args...), "Unable to fetch group info")
|
||||
policies := []string{}
|
||||
if gd.Policy != "" {
|
||||
policies = strings.Split(gd.Policy, ",")
|
||||
}
|
||||
memberOf = append(memberOf, userGroup{
|
||||
Name: gd.Name,
|
||||
Policies: policies,
|
||||
})
|
||||
}
|
||||
printMsg(userMessage{
|
||||
op: ctx.Command.Name,
|
||||
AccessKey: k,
|
||||
PolicyName: v.PolicyName,
|
||||
MemberOf: v.MemberOf,
|
||||
MemberOf: memberOf,
|
||||
UserStatus: string(v.Status),
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user