admin list frontends (#129)

This commit is contained in:
Michael Quigley 2022-12-02 09:43:25 -05:00
parent d5d2497955
commit 9ab7eeebf3
No known key found for this signature in database
GPG Key ID: 9B60314A9DD20A62
2 changed files with 68 additions and 0 deletions

View File

@ -0,0 +1,62 @@
package main
import (
"fmt"
"github.com/jedib0t/go-pretty/v6/table"
"github.com/openziti-test-kitchen/zrok/rest_client_zrok/admin"
"github.com/openziti-test-kitchen/zrok/zrokdir"
"github.com/spf13/cobra"
"os"
"time"
)
func init() {
adminListCmd.AddCommand(newAdminListFrontendsCommand().cmd)
}
type adminListFrontendsCommand struct {
cmd *cobra.Command
}
func newAdminListFrontendsCommand() *adminListFrontendsCommand {
cmd := &cobra.Command{
Use: "frontends",
Aliases: []string{"fes"},
Short: "List global public frontends",
Args: cobra.ExactArgs(0),
}
command := &adminListFrontendsCommand{cmd: cmd}
cmd.Run = command.run
return command
}
func (cmd *adminListFrontendsCommand) run(_ *cobra.Command, args []string) {
zrok, err := zrokdir.ZrokClient(apiEndpoint)
if err != nil {
panic(err)
}
req := admin.NewListFrontendsParams()
resp, err := zrok.Admin.ListFrontends(req, mustGetAdminAuth())
if err != nil {
panic(err)
}
fmt.Println()
t := table.NewWriter()
t.SetOutputMirror(os.Stdout)
t.SetStyle(table.StyleColoredBright)
t.AppendHeader(table.Row{"Token", "zId", "Url Template", "Public Name", "Created At", "Updated At"})
for _, pfe := range resp.Payload {
t.AppendRow(table.Row{
pfe.Token,
pfe.ZID,
pfe.URLTemplate,
pfe.PublicName,
time.UnixMilli(pfe.CreatedAt),
time.UnixMilli(pfe.UpdatedAt),
})
}
t.Render()
fmt.Println()
}

View File

@ -18,6 +18,7 @@ func init() {
rootCmd.AddCommand(accessCmd) rootCmd.AddCommand(accessCmd)
adminCmd.AddCommand(adminCreateCmd) adminCmd.AddCommand(adminCreateCmd)
adminCmd.AddCommand(adminDeleteCmd) adminCmd.AddCommand(adminDeleteCmd)
adminCmd.AddCommand(adminListCmd)
rootCmd.AddCommand(adminCmd) rootCmd.AddCommand(adminCmd)
rootCmd.AddCommand(shareCmd) rootCmd.AddCommand(shareCmd)
rootCmd.AddCommand(testCmd) rootCmd.AddCommand(testCmd)
@ -56,6 +57,11 @@ var adminDeleteCmd = &cobra.Command{
Short: "Delete global resources", Short: "Delete global resources",
} }
var adminListCmd = &cobra.Command{
Use: "list",
Short: "List global resources",
}
var shareCmd = &cobra.Command{ var shareCmd = &cobra.Command{
Use: "share", Use: "share",
Short: "Create backend access for services", Short: "Create backend access for services",