added 'zrok overview public-frontends' to allow CLI listing (#996)

This commit is contained in:
Michael Quigley 2025-06-27 14:23:35 -04:00
parent 7967f41093
commit 1c81a1510e
No known key found for this signature in database
GPG Key ID: 9B60314A9DD20A62
4 changed files with 87 additions and 4 deletions

View File

@ -6,7 +6,7 @@ FEATURE: New add and delete API endpoints for frontend grants. New `zrok admin c
FEATURE: New admin endpoint for deleting accounts. New `zrok admin delete account` CLI for invoking the API endpoint from the command line (https://github.com/openziti/zrok/issues/993)
FEATURE: New API endpoint (`/overview/public-frontends`) that returns the public frontends available to authenticated account. The public frontends include those marked with the `open` permission mode, and those marked `closed` where the user has a frontend grant allowing them to access the frontend (https://github.com/openziti/zrok/issues/996)
FEATURE: New API endpoint (`/overview/public-frontends`) that returns the public frontends available to authenticated account. The public frontends include those marked with the `open` permission mode, and those marked `closed` where the user has a frontend grant allowing them to access the frontend. New CLI command `zrok overview public-frontends` to allow end users to list the public frontends their account can use (https://github.com/openziti/zrok/issues/996)
## v1.0.6

View File

@ -2,12 +2,13 @@ package main
import (
"fmt"
"os"
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() {
@ -45,7 +46,7 @@ func (c *orgMembershipsCommand) run(_ *cobra.Command, _ []string) {
zrok, err := root.Client()
if err != nil {
if !panicInstead {
tui.Error("error loading zrokdir", err)
tui.Error("error getting zrok client", err)
}
panic(err)
}

View File

@ -2,14 +2,18 @@ package main
import (
"fmt"
"github.com/openziti/zrok/environment"
"github.com/openziti/zrok/sdk/golang/sdk"
"github.com/openziti/zrok/tui"
"github.com/spf13/cobra"
)
var overviewCmd *cobra.Command
func init() {
rootCmd.AddCommand(newOverviewCommand().cmd)
overviewCmd = newOverviewCommand().cmd
rootCmd.AddCommand(overviewCmd)
}
type overviewCommand struct {

View File

@ -0,0 +1,78 @@
package main
import (
"fmt"
"os"
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"
)
func init() {
overviewCmd.AddCommand(newOverviewFrontendsCommand().cmd)
}
type overviewPublicFrontendsCommand struct {
cmd *cobra.Command
}
func newOverviewFrontendsCommand() *overviewPublicFrontendsCommand {
cmd := &cobra.Command{
Use: "public-frontends",
Short: "Show the available public frontends",
Aliases: []string{"pf"},
Args: cobra.NoArgs,
}
command := &overviewPublicFrontendsCommand{cmd: cmd}
cmd.Run = command.run
return command
}
func (cmd *overviewPublicFrontendsCommand) 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 getting zrok client", err)
}
panic(err)
}
auth := httptransport.APIKeyAuth("X-TOKEN", "header", root.Environment().AccountToken)
resp, err := zrok.Metadata.ListPublicFrontendsForAccount(nil, auth)
if err != nil {
if !panicInstead {
tui.Error("error listing public frontends", err)
}
panic(err)
}
if len(resp.Payload.PublicFrontends) > 0 {
fmt.Println()
t := table.NewWriter()
t.SetOutputMirror(os.Stdout)
t.SetStyle(table.StyleColoredDark)
t.AppendHeader(table.Row{"Frontend Name", "URL Template"})
for _, i := range resp.Payload.PublicFrontends {
t.AppendRow(table.Row{i.PublicName, i.URLTemplate})
}
t.Render()
fmt.Println()
} else {
fmt.Println("no public frontends found")
}
}