Enhance user info output with authentication info (#4613)
This commit is contained in:
+18
-14
@@ -91,13 +91,14 @@ type userGroup struct {
|
||||
|
||||
// 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 []userGroup `json:"memberOf,omitempty"`
|
||||
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 []userGroup `json:"memberOf,omitempty"`
|
||||
Authentication string `json:"authentication,omitempty"`
|
||||
}
|
||||
|
||||
func (u userMessage) String() string {
|
||||
@@ -118,13 +119,16 @@ func (u userMessage) String() 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", memberOf),
|
||||
}, "\n"))
|
||||
lines := []string{
|
||||
fmt.Sprintf("AccessKey: %s", u.AccessKey),
|
||||
fmt.Sprintf("Status: %s", u.UserStatus),
|
||||
fmt.Sprintf("PolicyName: %s", u.PolicyName),
|
||||
fmt.Sprintf("MemberOf: %s", memberOf),
|
||||
}
|
||||
if u.Authentication != "" {
|
||||
lines = append(lines, fmt.Sprintf("Authentication: %s", u.Authentication))
|
||||
}
|
||||
return console.Colorize("UserMessage", strings.Join(lines, "\n"))
|
||||
case "remove":
|
||||
return console.Colorize("UserMessage", "Removed user `"+u.AccessKey+"` successfully.")
|
||||
case "disable":
|
||||
|
||||
+21
-5
@@ -18,10 +18,12 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/fatih/color"
|
||||
"github.com/minio/cli"
|
||||
"github.com/minio/madmin-go/v3"
|
||||
"github.com/minio/mc/pkg/probe"
|
||||
"github.com/minio/pkg/console"
|
||||
)
|
||||
@@ -87,12 +89,26 @@ func mainAdminUserInfo(ctx *cli.Context) error {
|
||||
}
|
||||
|
||||
printMsg(userMessage{
|
||||
op: ctx.Command.Name,
|
||||
AccessKey: args.Get(1),
|
||||
PolicyName: user.PolicyName,
|
||||
UserStatus: string(user.Status),
|
||||
MemberOf: memberOf,
|
||||
op: ctx.Command.Name,
|
||||
AccessKey: args.Get(1),
|
||||
PolicyName: user.PolicyName,
|
||||
UserStatus: string(user.Status),
|
||||
MemberOf: memberOf,
|
||||
Authentication: authInfoToUserMessage(user.AuthInfo),
|
||||
})
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func authInfoToUserMessage(a *madmin.UserAuthInfo) string {
|
||||
if a == nil {
|
||||
return ""
|
||||
}
|
||||
|
||||
authServer := ""
|
||||
if a.Type != madmin.BuiltinUserAuthType {
|
||||
authServer = "/" + a.AuthServer
|
||||
}
|
||||
|
||||
return fmt.Sprintf("%s%s (%s)", a.Type, authServer, a.AuthServerUserID)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user