List expiration dates for 'mc admin user svcacct list' command (#4576)
This commit is contained in:
@@ -139,6 +139,9 @@ const (
|
||||
// There is no max length enforcement for access keys
|
||||
accessKeyMaxLen = 20
|
||||
|
||||
// Maximum length for Expiration timestamp
|
||||
expirationMaxLen = 29
|
||||
|
||||
// Alpha numeric table used for generating access keys.
|
||||
alphaNumericTable = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
||||
|
||||
@@ -155,9 +158,15 @@ func (u acctMessage) String() string {
|
||||
switch u.op {
|
||||
case svcAccOpList:
|
||||
// Create a new pretty table with cols configuration
|
||||
return newPrettyTable(" ",
|
||||
return newPrettyTable(" | ",
|
||||
Field{"AccessKey", accessFieldMaxLen},
|
||||
).buildRow(u.AccessKey)
|
||||
Field{"Expiration", expirationMaxLen},
|
||||
).buildRow(u.AccessKey, func() string {
|
||||
if u.Expiration != nil && !u.Expiration.IsZero() && !u.Expiration.Equal(timeSentinel) {
|
||||
return (*u.Expiration).String()
|
||||
}
|
||||
return "no-expiry"
|
||||
}())
|
||||
case stsAccOpInfo, svcAccOpInfo:
|
||||
policyField := ""
|
||||
if u.ImpliedPolicy {
|
||||
|
||||
@@ -62,7 +62,10 @@ func mainAdminUserSvcAcctList(ctx *cli.Context) error {
|
||||
checkAdminUserSvcAcctListSyntax(ctx)
|
||||
|
||||
console.SetColor("AccMessage", color.New(color.FgGreen))
|
||||
console.SetColor("AccessKeyHeader", color.New(color.Bold, color.FgBlue))
|
||||
console.SetColor("ExpirationHeader", color.New(color.Bold, color.FgCyan))
|
||||
console.SetColor("AccessKey", color.New(color.FgBlue))
|
||||
console.SetColor("Expiration", color.New(color.FgCyan))
|
||||
|
||||
// Get the alias parameter from cli
|
||||
args := ctx.Args()
|
||||
@@ -76,11 +79,25 @@ func mainAdminUserSvcAcctList(ctx *cli.Context) error {
|
||||
svcList, e := client.ListServiceAccounts(globalContext, user)
|
||||
fatalIf(probe.NewError(e).Trace(args...), "Unable to list service accounts")
|
||||
|
||||
for _, svc := range svcList.Accounts {
|
||||
printMsg(acctMessage{
|
||||
op: svcAccOpList,
|
||||
AccessKey: svc,
|
||||
})
|
||||
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)
|
||||
|
||||
// Print table contents
|
||||
for _, svc := range svcList.Accounts {
|
||||
printMsg(acctMessage{
|
||||
op: svcAccOpList,
|
||||
AccessKey: svc.AccessKey,
|
||||
Expiration: svc.Expiration,
|
||||
})
|
||||
}
|
||||
} else {
|
||||
console.Println("No service accounts found")
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
@@ -19,7 +19,7 @@ require (
|
||||
github.com/minio/cli v1.24.2
|
||||
github.com/minio/colorjson v1.0.4
|
||||
github.com/minio/filepath v1.0.0
|
||||
github.com/minio/madmin-go/v2 v2.1.3
|
||||
github.com/minio/madmin-go/v2 v2.2.0
|
||||
github.com/minio/md5-simd v1.1.2 // indirect
|
||||
github.com/minio/minio-go/v7 v7.0.55-0.20230525060734-b7836f021bfb
|
||||
github.com/minio/pkg v1.6.5
|
||||
|
||||
@@ -518,8 +518,8 @@ github.com/minio/colorjson v1.0.4/go.mod h1:ZgE8vYon4xC4yfBPclP/2gqMRYw+p+xRsBbL
|
||||
github.com/minio/filepath v1.0.0 h1:fvkJu1+6X+ECRA6G3+JJETj4QeAYO9sV43I79H8ubDY=
|
||||
github.com/minio/filepath v1.0.0/go.mod h1:/nRZA2ldl5z6jT9/KQuvZcQlxZIMQoFFQPvEXx9T/Bw=
|
||||
github.com/minio/madmin-go v1.6.6/go.mod h1:ATvkBOLiP3av4D++2v1UEHC/QzsGtgXD5kYvvRYzdKs=
|
||||
github.com/minio/madmin-go/v2 v2.1.3 h1:9pkUgAujfm/SaFei4a1LwpS2et1/qGvRjFqFbRWa6xA=
|
||||
github.com/minio/madmin-go/v2 v2.1.3/go.mod h1:8bL1RMNkblIENFSgGYjeHrzUx9PxROb7OqfNuMU9ivE=
|
||||
github.com/minio/madmin-go/v2 v2.2.0 h1:DtJPzallTD/7wx0ZaxPBl+HrKgI5L5Z+ULa6tAMvuH8=
|
||||
github.com/minio/madmin-go/v2 v2.2.0/go.mod h1:8bL1RMNkblIENFSgGYjeHrzUx9PxROb7OqfNuMU9ivE=
|
||||
github.com/minio/md5-simd v1.1.2 h1:Gdi1DZK69+ZVMoNHRXJyNcxrMA4dSxoYHZSQbirFg34=
|
||||
github.com/minio/md5-simd v1.1.2/go.mod h1:MzdKDxYpY2BT9XQFocsiZf/NKVtR7nkE4RoEpN+20RM=
|
||||
github.com/minio/minio-go/v7 v7.0.41/go.mod h1:nCrRzjoSUQh8hgKKtu3Y708OLvRLtuASMg2/nvmbarw=
|
||||
|
||||
Reference in New Issue
Block a user