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
|
// userMessage container for content message structure
|
||||||
type userMessage struct {
|
type userMessage struct {
|
||||||
op string
|
op string
|
||||||
Status string `json:"status"` // TODO: remove this?
|
Status string `json:"status"` // TODO: remove this?
|
||||||
AccessKey string `json:"accessKey,omitempty"`
|
AccessKey string `json:"accessKey,omitempty"`
|
||||||
SecretKey string `json:"secretKey,omitempty"`
|
SecretKey string `json:"secretKey,omitempty"`
|
||||||
PolicyName string `json:"policyName,omitempty"`
|
PolicyName string `json:"policyName,omitempty"`
|
||||||
UserStatus string `json:"userStatus,omitempty"`
|
UserStatus string `json:"userStatus,omitempty"`
|
||||||
MemberOf []string `json:"memberOf,omitempty"`
|
MemberOf []userGroup `json:"memberOf,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u userMessage) String() string {
|
func (u userMessage) String() string {
|
||||||
@@ -108,12 +114,16 @@ func (u userMessage) String() string {
|
|||||||
Field{"PolicyName", policyFieldMaxLen},
|
Field{"PolicyName", policyFieldMaxLen},
|
||||||
).buildRow(u.UserStatus, u.AccessKey, u.PolicyName)
|
).buildRow(u.UserStatus, u.AccessKey, u.PolicyName)
|
||||||
case "info":
|
case "info":
|
||||||
|
memberOf := []string{}
|
||||||
|
for _, group := range u.MemberOf {
|
||||||
|
memberOf = append(memberOf, group.Name)
|
||||||
|
}
|
||||||
return console.Colorize("UserMessage", strings.Join(
|
return console.Colorize("UserMessage", strings.Join(
|
||||||
[]string{
|
[]string{
|
||||||
fmt.Sprintf("AccessKey: %s", u.AccessKey),
|
fmt.Sprintf("AccessKey: %s", u.AccessKey),
|
||||||
fmt.Sprintf("Status: %s", u.UserStatus),
|
fmt.Sprintf("Status: %s", u.UserStatus),
|
||||||
fmt.Sprintf("PolicyName: %s", u.PolicyName),
|
fmt.Sprintf("PolicyName: %s", u.PolicyName),
|
||||||
fmt.Sprintf("MemberOf: %s", strings.Join(u.MemberOf, ",")),
|
fmt.Sprintf("MemberOf: %s", memberOf),
|
||||||
}, "\n"))
|
}, "\n"))
|
||||||
case "remove":
|
case "remove":
|
||||||
return console.Colorize("UserMessage", "Removed user `"+u.AccessKey+"` successfully.")
|
return console.Colorize("UserMessage", "Removed user `"+u.AccessKey+"` successfully.")
|
||||||
|
|||||||
@@ -18,6 +18,8 @@
|
|||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/fatih/color"
|
"github.com/fatih/color"
|
||||||
"github.com/minio/cli"
|
"github.com/minio/cli"
|
||||||
"github.com/minio/mc/pkg/probe"
|
"github.com/minio/mc/pkg/probe"
|
||||||
@@ -70,12 +72,26 @@ func mainAdminUserInfo(ctx *cli.Context) error {
|
|||||||
user, e := client.GetUserInfo(globalContext, args.Get(1))
|
user, e := client.GetUserInfo(globalContext, args.Get(1))
|
||||||
fatalIf(probe.NewError(e).Trace(args...), "Unable to get user info")
|
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{
|
printMsg(userMessage{
|
||||||
op: ctx.Command.Name,
|
op: ctx.Command.Name,
|
||||||
AccessKey: args.Get(1),
|
AccessKey: args.Get(1),
|
||||||
PolicyName: user.PolicyName,
|
PolicyName: user.PolicyName,
|
||||||
UserStatus: string(user.Status),
|
UserStatus: string(user.Status),
|
||||||
MemberOf: user.MemberOf,
|
MemberOf: memberOf,
|
||||||
})
|
})
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
@@ -18,6 +18,8 @@
|
|||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/fatih/color"
|
"github.com/fatih/color"
|
||||||
"github.com/minio/cli"
|
"github.com/minio/cli"
|
||||||
"github.com/minio/mc/pkg/probe"
|
"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")
|
fatalIf(probe.NewError(e).Trace(args...), "Unable to list user")
|
||||||
|
|
||||||
for k, v := range users {
|
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{
|
printMsg(userMessage{
|
||||||
op: ctx.Command.Name,
|
op: ctx.Command.Name,
|
||||||
AccessKey: k,
|
AccessKey: k,
|
||||||
PolicyName: v.PolicyName,
|
PolicyName: v.PolicyName,
|
||||||
MemberOf: v.MemberOf,
|
MemberOf: memberOf,
|
||||||
UserStatus: string(v.Status),
|
UserStatus: string(v.Status),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user