Fix issues related to 'mc admin svcacct list --json' cmd (#4619)

- Fix table header being printed when the '--json' flag is present for
the 'mc admin svcacct list' command
- Fix sentinel date being marshaled when the '--json' flag is present
for the 'mc admin svcacct list' command
This commit is contained in:
Kaan Kabalak
2023-06-27 22:52:26 -07:00
committed by GitHub
parent 0ed2956757
commit c96b42c8f2
2 changed files with 18 additions and 10 deletions
+1 -1
View File
@@ -179,7 +179,7 @@ func (u acctMessage) String() string {
Field{"AccessKey", accessFieldMaxLen},
Field{"Expiration", expirationMaxLen},
).buildRow(u.AccessKey, func() string {
if u.Expiration != nil && !u.Expiration.IsZero() && !u.Expiration.Equal(timeSentinel) {
if u.Expiration != nil && !u.Expiration.IsZero() {
return (*u.Expiration).String()
}
return "no-expiry"
+17 -9
View File
@@ -80,24 +80,32 @@ func mainAdminUserSvcAcctList(ctx *cli.Context) error {
fatalIf(probe.NewError(e).Trace(args...), "Unable to list service accounts")
if len(svcList.Accounts) > 0 {
// Print table header
var header string
header += console.Colorize("Headers", newPrettyTable(" | ",
Field{"AccessKeyHeader", accessFieldMaxLen},
Field{"ExpirationHeader", expirationMaxLen},
).buildRow(" Access Key", "Expiry"))
console.Println(header)
if !globalJSON {
// Print table header
var header string
header += console.Colorize("Headers", newPrettyTable(" | ",
Field{"AccessKeyHeader", accessFieldMaxLen},
Field{"ExpirationHeader", expirationMaxLen},
).buildRow(" Access Key", "Expiry"))
console.Println(header)
}
// Print table contents
for _, svc := range svcList.Accounts {
expiration := svc.Expiration
if expiration.Equal(timeSentinel) {
expiration = nil
}
printMsg(acctMessage{
op: svcAccOpList,
AccessKey: svc.AccessKey,
Expiration: svc.Expiration,
Expiration: expiration,
})
}
} else {
console.Println("No service accounts found")
if !globalJSON {
console.Println("No service accounts found")
}
}
return nil