mirror of
https://github.com/openziti/zrok.git
synced 2024-12-22 14:50:55 +01:00
cli integration for 'zrok org admin list' (#537)
This commit is contained in:
parent
98804320a1
commit
9868058076
76
cmd/zrok/orgAdminList.go
Normal file
76
cmd/zrok/orgAdminList.go
Normal file
@ -0,0 +1,76 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
httptransport "github.com/go-openapi/runtime/client"
|
||||
"github.com/jedib0t/go-pretty/v6/table"
|
||||
"github.com/openziti/zrok/environment"
|
||||
"github.com/openziti/zrok/rest_client_zrok/metadata"
|
||||
"github.com/openziti/zrok/tui"
|
||||
"github.com/spf13/cobra"
|
||||
"os"
|
||||
)
|
||||
|
||||
func init() {
|
||||
organizationAdminCmd.AddCommand(newOrgAdminListCommand().cmd)
|
||||
}
|
||||
|
||||
type orgAdminListCommand struct {
|
||||
cmd *cobra.Command
|
||||
}
|
||||
|
||||
func newOrgAdminListCommand() *orgAdminListCommand {
|
||||
cmd := &cobra.Command{
|
||||
Use: "list <organizationToken>",
|
||||
Short: "List the members of an organization",
|
||||
Args: cobra.ExactArgs(1),
|
||||
}
|
||||
command := &orgAdminListCommand{cmd}
|
||||
cmd.Run = command.run
|
||||
return command
|
||||
}
|
||||
|
||||
func (c *orgAdminListCommand) run(_ *cobra.Command, args []string) {
|
||||
root, err := environment.LoadRoot()
|
||||
if err != nil {
|
||||
if !panicInstead {
|
||||
tui.Error("error loading zrokdir", err)
|
||||
}
|
||||
panic(err)
|
||||
}
|
||||
|
||||
if !root.IsEnabled() {
|
||||
tui.Error("unable to load environment; did you 'zrok enable'?", nil)
|
||||
}
|
||||
|
||||
zrok, err := root.Client()
|
||||
if err != nil {
|
||||
if !panicInstead {
|
||||
tui.Error("error loading zrokdir", err)
|
||||
}
|
||||
panic(err)
|
||||
}
|
||||
auth := httptransport.APIKeyAuth("X-TOKEN", "header", root.Environment().Token)
|
||||
|
||||
req := metadata.NewListOrgMembersParams()
|
||||
req.OrganizationToken = args[0]
|
||||
|
||||
resp, err := zrok.Metadata.ListOrgMembers(req, auth)
|
||||
if err != nil {
|
||||
if !panicInstead {
|
||||
tui.Error("error listing organization members", err)
|
||||
}
|
||||
panic(err)
|
||||
}
|
||||
|
||||
fmt.Println()
|
||||
t := table.NewWriter()
|
||||
t.SetOutputMirror(os.Stdout)
|
||||
t.SetStyle(table.StyleColoredDark)
|
||||
t.AppendHeader(table.Row{"Email", "Admin?"})
|
||||
for _, member := range resp.Payload.Members {
|
||||
t.AppendRow(table.Row{member.Email, member.Admin})
|
||||
}
|
||||
t.Render()
|
||||
fmt.Println()
|
||||
}
|
Loading…
Reference in New Issue
Block a user