Merge pull request #446 from openziti/tidy-cli-hints

raise an exception if invalid mode for public share
This commit is contained in:
Kenneth Bingham 2023-11-06 09:21:51 -05:00 committed by GitHub
commit b25b15e2af
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 11 additions and 8 deletions

View File

@ -9,6 +9,7 @@ import (
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"time" "time"
"slices"
) )
func init() { func init() {
@ -34,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, drive}") cmd.Flags().StringVarP(&command.backendMode, "backend-mode", "b", "proxy", "The backend mode (public|private: proxy, web, caddy, drive) (private: tcpTunnel, udpTunnel)")
cmd.Flags().BoolVarP(&command.jsonOutput, "json-output", "j", false, "Emit JSON describing the created reserved share") 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]")
@ -48,8 +49,11 @@ func newReserveCommand() *reserveCommand {
func (cmd *reserveCommand) run(_ *cobra.Command, args []string) { func (cmd *reserveCommand) run(_ *cobra.Command, args []string) {
shareMode := sdk.ShareMode(args[0]) shareMode := sdk.ShareMode(args[0])
privateOnlyModes := []string{"tcpTunnel", "udpTunnel"}
if shareMode != sdk.PublicShareMode && shareMode != sdk.PrivateShareMode { if shareMode != sdk.PublicShareMode && shareMode != sdk.PrivateShareMode {
tui.Error("invalid sharing mode; expecting 'public' or 'private'", nil) tui.Error("invalid sharing mode; expecting 'public' or 'private'", nil)
} else if shareMode == sdk.PublicShareMode && slices.Contains(privateOnlyModes, cmd.backendMode) {
tui.Error(fmt.Sprintf("invalid sharing mode for a %s share: %s", sdk.PublicShareMode, cmd.backendMode), nil)
} }
var target string var target string

View File

@ -82,7 +82,7 @@ func (cmd *sharePublicCommand) run(_ *cobra.Command, args []string) {
target = args[0] target = args[0]
default: default:
tui.Error(fmt.Sprintf("invalid backend mode '%v'; expected {proxy, web}", cmd.backendMode), nil) tui.Error(fmt.Sprintf("invalid backend mode '%v'; expected {proxy, web, caddy, drive}", cmd.backendMode), nil)
} }
root, err := environment.LoadRoot() root, err := environment.LoadRoot()

View File

@ -293,7 +293,7 @@ Usage:
zrok share public <target> [flags] zrok share public <target> [flags]
Flags: Flags:
--backend-mode string The backend mode {proxy, web} (default "proxy") --backend-mode string The backend mode {proxy, web, caddy, drive} (default "proxy")
--basic-auth stringArray Basic authentication users (<username:password>,...) --basic-auth stringArray Basic authentication users (<username:password>,...)
--frontends stringArray Selected frontends to use for the share (default [public]) --frontends stringArray Selected frontends to use for the share (default [public])
--headless Disable TUI and run headless --headless Disable TUI and run headless

View File

@ -120,14 +120,14 @@ Both the `google` and `github` providers accept a `client_id` and `client_secret
With your public frontend configured to support OAuth, you can test this by creating a public share. There are new command line options to support this: With your public frontend configured to support OAuth, you can test this by creating a public share. There are new command line options to support this:
``` ```text
$ zrok share public $ zrok share public
Error: accepts 1 arg(s), received 0 Error: accepts 1 arg(s), received 0
Usage: Usage:
zrok share public <target> [flags] zrok share public <target> [flags]
Flags: Flags:
-b, --backend-mode string The backend mode {proxy, web, caddy} (default "proxy") -b, --backend-mode string The backend mode {proxy, web, caddy, drive} (default "proxy")
--basic-auth stringArray Basic authentication users (<username:password>,...) --basic-auth stringArray Basic authentication users (<username:password>,...)
--frontends stringArray Selected frontends to use for the share (default [public]) --frontends stringArray Selected frontends to use for the share (default [public])
--headless Disable TUI and run headless --headless Disable TUI and run headless
@ -150,7 +150,6 @@ The `--oauth-check-interval` flag specifies how frequently the authentication mu
An example public share: An example public share:
```text
zrok share public --backend-mode web --oauth-provider github --oauth-email-domains zrok.io ~/public
``` ```
$ zrok share public --backend-mode web --oauth-provider github --oauth-email-domains zrok.io ~/public
```