Skip to content

Commit

Permalink
Merge pull request #213 from versity/ben/list_accounts
Browse files Browse the repository at this point in the history
feat: format admin cli list-users output in table
  • Loading branch information
benmcclelland authored Sep 7, 2023
2 parents 17651fc + ef92f57 commit d320c95
Showing 1 changed file with 24 additions and 6 deletions.
30 changes: 24 additions & 6 deletions cmd/versitygw/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import (
"fmt"
"io"
"net/http"
"os"
"text/tabwriter"
"time"

"github.com/aws/aws-sdk-go-v2/aws"
Expand Down Expand Up @@ -254,16 +256,32 @@ func listUsers(ctx *cli.Context) error {
return err
}

jsonData, err := json.MarshalIndent(accs, "", " ")
if err != nil {
return err
}

fmt.Println(string(jsonData))
printAcctTable(accs)

return nil
}

const (
// account table formatting
minwidth int = 2 // minimal cell width including any padding
tabwidth int = 0 // width of tab characters (equivalent number of spaces)
padding int = 2 // padding added to a cell before computing its width
padchar byte = ' ' // ASCII char used for padding
flags uint = 0 // formatting control flags
)

func printAcctTable(accs []auth.Account) {
w := new(tabwriter.Writer)
w.Init(os.Stdout, minwidth, tabwidth, padding, padchar, flags)
fmt.Fprintln(w, "Account\tRole")
fmt.Fprintln(w, "-------\t----")
for _, acc := range accs {
fmt.Fprintf(w, "%v\t%v\n", acc.Access, acc.Role)
}
fmt.Fprintln(w)
w.Flush()
}

func changeBucketOwner(ctx *cli.Context) error {
bucket, owner := ctx.String("bucket"), ctx.String("owner")
req, err := http.NewRequest(http.MethodPatch, fmt.Sprintf("%v/change-bucket-owner/?bucket=%v&owner=%v", adminEndpoint, bucket, owner), nil)
Expand Down

0 comments on commit d320c95

Please sign in to comment.