mirror of
https://github.com/openziti/zrok.git
synced 2025-02-22 05:01:01 +01:00
'zrok organization memberships' to list my memberships (#537)
This commit is contained in:
parent
3aff9950c8
commit
c3c318d529
72
cmd/zrok/orgMemberships.go
Normal file
72
cmd/zrok/orgMemberships.go
Normal file
@ -0,0 +1,72 @@
|
||||
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/tui"
|
||||
"github.com/spf13/cobra"
|
||||
"os"
|
||||
)
|
||||
|
||||
func init() {
|
||||
organizationCmd.AddCommand(newOrgMembershipsCommand().cmd)
|
||||
}
|
||||
|
||||
type orgMembershipsCommand struct {
|
||||
cmd *cobra.Command
|
||||
}
|
||||
|
||||
func newOrgMembershipsCommand() *orgMembershipsCommand {
|
||||
cmd := &cobra.Command{
|
||||
Use: "memberships",
|
||||
Short: "List the organization memberships for my account",
|
||||
Args: cobra.NoArgs,
|
||||
}
|
||||
command := &orgMembershipsCommand{cmd}
|
||||
cmd.Run = command.run
|
||||
return command
|
||||
}
|
||||
|
||||
func (c *orgMembershipsCommand) run(_ *cobra.Command, _ []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)
|
||||
|
||||
in, err := zrok.Metadata.ListMemberships(nil, auth)
|
||||
if err != nil {
|
||||
if !panicInstead {
|
||||
tui.Error("error listing memberships", err)
|
||||
}
|
||||
panic(err)
|
||||
}
|
||||
|
||||
fmt.Println()
|
||||
t := table.NewWriter()
|
||||
t.SetOutputMirror(os.Stdout)
|
||||
t.SetStyle(table.StyleColoredDark)
|
||||
t.AppendHeader(table.Row{"Token", "Description", "Admin?"})
|
||||
for _, i := range in.Payload.Memberships {
|
||||
t.AppendRow(table.Row{i.Token, i.Description, i.Admin})
|
||||
}
|
||||
t.Render()
|
||||
fmt.Println()
|
||||
}
|
Loading…
Reference in New Issue
Block a user