incorporate '--json-output' flag to the 'zrok reserve' command (#422)

This commit is contained in:
Michael Quigley 2023-10-25 11:44:21 -04:00
parent aba9f68348
commit 870c1a083b
No known key found for this signature in database
GPG Key ID: 9B60314A9DD20A62
3 changed files with 21 additions and 18 deletions

View File

@ -1,5 +1,7 @@
# v0.4.11 # v0.4.11
FEATURE: The `zrok reserve` command now incorporates the `--json-output|-j` flag, which outputs the reservation details as JSON, rather than as human-consumable log messages. Other commands will produce similar output in the future (https://github.com/openziti/zrok/issues/422)
FIX: Include `--oauth-provider` and associated flags for the `zrok reserve` command, allowing reserved shares to specify OAuth authentication (https://github.com/openziti/zrok/issues/421) FIX: Include `--oauth-provider` and associated flags for the `zrok reserve` command, allowing reserved shares to specify OAuth authentication (https://github.com/openziti/zrok/issues/421)
# v0.4.10 # v0.4.10

View File

@ -1,6 +1,7 @@
package main package main
import ( import (
"encoding/json"
"fmt" "fmt"
"github.com/openziti/zrok/environment" "github.com/openziti/zrok/environment"
"github.com/openziti/zrok/sdk" "github.com/openziti/zrok/sdk"
@ -18,6 +19,7 @@ type reserveCommand struct {
basicAuth []string basicAuth []string
frontendSelection []string frontendSelection []string
backendMode string backendMode string
jsonOutput bool
oauthProvider string oauthProvider string
oauthEmailDomains []string oauthEmailDomains []string
oauthCheckInterval time.Duration oauthCheckInterval time.Duration
@ -33,7 +35,7 @@ func newReserveCommand() *reserveCommand {
command := &reserveCommand{cmd: cmd} command := &reserveCommand{cmd: cmd}
cmd.Flags().StringArrayVar(&command.frontendSelection, "frontends", []string{"public"}, "Selected frontends to use for the share") cmd.Flags().StringArrayVar(&command.frontendSelection, "frontends", []string{"public"}, "Selected frontends to use for the share")
cmd.Flags().StringVarP(&command.backendMode, "backend-mode", "b", "proxy", "The backend mode {proxy, web, <tcpTunnel, udpTunnel>, caddy}") cmd.Flags().StringVarP(&command.backendMode, "backend-mode", "b", "proxy", "The backend mode {proxy, web, <tcpTunnel, udpTunnel>, caddy}")
cmd.Flags().BoolVarP(&command.jsonOutput, "json-output", "j", false, "Emit JSON describing the created reserved share")
cmd.Flags().StringArrayVar(&command.basicAuth, "basic-auth", []string{}, "Basic authentication users (<username:password>,...)") cmd.Flags().StringArrayVar(&command.basicAuth, "basic-auth", []string{}, "Basic authentication users (<username:password>,...)")
cmd.Flags().StringVar(&command.oauthProvider, "oauth-provider", "", "Enable OAuth provider [google, github]") cmd.Flags().StringVar(&command.oauthProvider, "oauth-provider", "", "Enable OAuth provider [google, github]")
cmd.Flags().StringArrayVar(&command.oauthEmailDomains, "oauth-email-domains", []string{}, "Allow only these email domains to authenticate via OAuth") cmd.Flags().StringArrayVar(&command.oauthEmailDomains, "oauth-email-domains", []string{}, "Allow only these email domains to authenticate via OAuth")
@ -55,10 +57,7 @@ func (cmd *reserveCommand) run(_ *cobra.Command, args []string) {
case "proxy": case "proxy":
v, err := parseUrl(args[1]) v, err := parseUrl(args[1])
if err != nil { if err != nil {
if !panicInstead { tui.Error("invalid target endpoint URL", err)
tui.Error("invalid target endpoint URL", err)
}
panic(err)
} }
target = v target = v
@ -80,10 +79,7 @@ func (cmd *reserveCommand) run(_ *cobra.Command, args []string) {
env, err := environment.LoadRoot() env, err := environment.LoadRoot()
if err != nil { if err != nil {
if !panicInstead { tui.Error("error loading environment", err)
tui.Error("error loading environment", err)
}
panic(err)
} }
if !env.IsEnabled() { if !env.IsEnabled() {
@ -109,14 +105,19 @@ func (cmd *reserveCommand) run(_ *cobra.Command, args []string) {
} }
shr, err := sdk.CreateShare(env, req) shr, err := sdk.CreateShare(env, req)
if err != nil { if err != nil {
if !panicInstead { tui.Error("unable to create share", err)
tui.Error("unable to create share", err)
}
panic(err)
} }
logrus.Infof("your reserved share token is '%v'", shr.Token) if !cmd.jsonOutput {
for _, fpe := range shr.FrontendEndpoints { logrus.Infof("your reserved share token is '%v'", shr.Token)
logrus.Infof("reserved frontend endpoint: %v", fpe) for _, fpe := range shr.FrontendEndpoints {
logrus.Infof("reserved frontend endpoint: %v", fpe)
}
} else {
out, err := json.Marshal(shr)
if err != nil {
tui.Error("error emitting JSON", err)
}
fmt.Println(string(out))
} }
} }

View File

@ -31,8 +31,8 @@ type ShareRequest struct {
} }
type Share struct { type Share struct {
Token string Token string `json:"token"`
FrontendEndpoints []string FrontendEndpoints []string `json:"frontend_endpoints"`
} }
type AccessRequest struct { type AccessRequest struct {