fix: Correctly print svc accounts list (#4422)

This commit is contained in:
Anis Elleuch
2022-12-22 09:18:57 -08:00
committed by GitHub
parent e8792efe0a
commit 8f0ae83bf8
7 changed files with 27 additions and 15 deletions
+21 -9
View File
@@ -81,7 +81,7 @@ func checkAdminUserSvcAcctAddSyntax(ctx *cli.Context) {
// svcAcctMessage container for content message structure
type svcAcctMessage struct {
op string
op svcAcctOp
Status string `json:"status"`
AccessKey string `json:"accessKey,omitempty"`
SecretKey string `json:"secretKey,omitempty"`
@@ -96,14 +96,26 @@ const (
accessFieldMaxLen = 20
)
type svcAcctOp int
const (
svcAccOpAdd = svcAcctOp(iota)
svcAccOpList
svcAccOpInfo
svcAccOpRemove
svcAccOpDisable
svcAccOpEnable
svcAccOpSet
)
func (u svcAcctMessage) String() string {
switch u.op {
case "list":
case svcAccOpList:
// Create a new pretty table with cols configuration
return newPrettyTable(" ",
Field{"AccessKey", accessFieldMaxLen},
).buildRow(u.AccessKey)
case "info":
case svcAccOpInfo:
policyField := ""
if u.ImpliedPolicy {
policyField = "implied"
@@ -117,16 +129,16 @@ func (u svcAcctMessage) String() string {
fmt.Sprintf("Status: %s", u.AccountStatus),
fmt.Sprintf("Policy: %s", policyField),
}, "\n"))
case "rm":
case svcAccOpRemove:
return console.Colorize("SVCMessage", "Removed service account `"+u.AccessKey+"` successfully.")
case "disable":
case svcAccOpDisable:
return console.Colorize("SVCMessage", "Disabled service account `"+u.AccessKey+"` successfully.")
case "enable":
case svcAccOpEnable:
return console.Colorize("SVCMessage", "Enabled service account `"+u.AccessKey+"` successfully.")
case "add":
case svcAccOpAdd:
return console.Colorize("SVCMessage",
fmt.Sprintf("Access Key: %s\nSecret Key: %s", u.AccessKey, u.SecretKey))
case "set":
case svcAccOpSet:
return console.Colorize("SVCMessage", "Edited service account `"+u.AccessKey+"` successfully.")
}
return ""
@@ -183,7 +195,7 @@ func mainAdminUserSvcAcctAdd(ctx *cli.Context) error {
fatalIf(probe.NewError(e).Trace(args...), "Unable to add a new service account")
printMsg(svcAcctMessage{
op: ctx.Command.Name,
op: svcAccOpAdd,
AccessKey: creds.AccessKey,
SecretKey: creds.SecretKey,
AccountStatus: "enabled",
+1 -1
View File
@@ -77,7 +77,7 @@ func mainAdminUserSvcAcctDisable(ctx *cli.Context) error {
fatalIf(probe.NewError(e).Trace(args...), "Unable to disable the specified service account")
printMsg(svcAcctMessage{
op: ctx.Command.Name,
op: svcAccOpDisable,
AccessKey: svcAccount,
})
+1 -1
View File
@@ -77,7 +77,7 @@ func mainAdminUserSvcAcctEnable(ctx *cli.Context) error {
fatalIf(probe.NewError(e).Trace(args...), "Unable to enable the specified service account")
printMsg(svcAcctMessage{
op: ctx.Command.Name,
op: svcAccOpEnable,
AccessKey: svcAccount,
})
+1 -1
View File
@@ -96,7 +96,7 @@ func mainAdminUserSvcAcctInfo(ctx *cli.Context) error {
}
printMsg(svcAcctMessage{
op: ctx.Command.Name,
op: svcAccOpInfo,
AccessKey: svcAccount,
AccountStatus: svcInfo.AccountStatus,
ParentUser: svcInfo.ParentUser,
+1 -1
View File
@@ -78,7 +78,7 @@ func mainAdminUserSvcAcctList(ctx *cli.Context) error {
for _, svc := range svcList.Accounts {
printMsg(svcAcctMessage{
op: ctx.Command.Name,
op: svcAccOpList,
AccessKey: svc,
})
}
+1 -1
View File
@@ -73,7 +73,7 @@ func mainAdminUserSvcAcctRemove(ctx *cli.Context) error {
fatalIf(probe.NewError(e).Trace(args...), "Unable to remove the specified service account")
printMsg(svcAcctMessage{
op: ctx.Command.Name,
op: svcAccOpRemove,
AccessKey: svcAccount,
})
+1 -1
View File
@@ -98,7 +98,7 @@ func mainAdminUserSvcAcctSet(ctx *cli.Context) error {
fatalIf(probe.NewError(e).Trace(args...), "Unable to edit the specified service account")
printMsg(svcAcctMessage{
op: ctx.Command.Name,
op: svcAccOpSet,
AccessKey: svcAccount,
})