Skip to content

Commit

Permalink
Merge pull request #51 from slntopp/access
Browse files Browse the repository at this point in the history
Access
  • Loading branch information
slntopp authored Jan 11, 2023
2 parents 561c507 + 73156e6 commit af82efe
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 7 deletions.
15 changes: 13 additions & 2 deletions cmd/account/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,26 @@ func PrintAccount(acc *pb.Account) {
func PrintAccountsPool(pool []*pb.Account) {
t := table.NewWriter()
t.SetOutputMirror(os.Stdout)
t.AppendHeader(table.Row{"UUID", "Title", "Balance NCU"})
t.AppendHeader(table.Row{"UUID", "Title", "Balance NCU", "Access", "Role", "Namespace"})

rows := make([]table.Row, len(pool))
for i, acc := range pool {
balance := "-"
if acc.Balance != nil {
balance = fmt.Sprintf("%.2f", *acc.Balance)
}
rows[i] = table.Row{acc.Uuid, acc.Title, balance}
a, r, n := "READ", "-", "-"
if acc.Access != nil {
a = acc.Access.Level.Enum().String()
r = acc.Access.Role
if r == "" {
r = "-"
}
if acc.Access.Namespace != nil {
n = *acc.Access.Namespace
}
}
rows[i] = table.Row{acc.Uuid, acc.Title, balance, a, r, n}
}
t.AppendRows(rows)

Expand Down
11 changes: 8 additions & 3 deletions cmd/namespace/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,16 @@ func MakeNamespacesServiceClientOrFail() (context.Context, regpb.NamespacesServi
func PrintNamespacesPool(pool []*pb.Namespace) {
t := table.NewWriter()
t.SetOutputMirror(os.Stdout)
t.AppendHeader(table.Row{"UUID", "Title"})
t.AppendHeader(table.Row{"UUID", "Title", "Access", "Role"})

rows := make([]table.Row, len(pool))
for i, acc := range pool {
rows[i] = table.Row{acc.Uuid, acc.Title}
for i, ns := range pool {
a, r := "READ", "-"
if ns.Access != nil {
a = ns.Access.Level.Enum().String()
r = ns.Access.Role
}
rows[i] = table.Row{ns.Uuid, ns.Title, a, r}
}
t.AppendRows(rows)

Expand Down
12 changes: 10 additions & 2 deletions cmd/services/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,19 @@ func PrintService(s *pb.Service) error {
func PrintServicesPool(pool []*pb.Service) {
t := table.NewWriter()
t.SetOutputMirror(os.Stdout)
t.AppendHeader(table.Row{"UUID", "Title", "Status"})
t.AppendHeader(table.Row{"UUID", "Title", "Status", "Access", "Role", "Namespace"})

rows := make([]table.Row, len(pool))
for i, s := range pool {
rows[i] = table.Row{s.GetUuid(), s.GetTitle(), s.GetStatus()}
a, r, n := "READ", "-", "-"
if s.Access != nil {
a = s.Access.Level.Enum().String()
r = s.Access.Role
if s.Access.Namespace != nil {
n = *s.Access.Namespace
}
}
rows[i] = table.Row{s.GetUuid(), s.GetTitle(), s.GetStatus(), a, r, n}
}
t.AppendRows(rows)

Expand Down

0 comments on commit af82efe

Please sign in to comment.