add '--force-local' and '--force-agent' to 'zrok share [public|private|reserved]' and 'zrok access private' (#751)

This commit is contained in:
Michael Quigley 2024-09-25 11:32:25 -04:00
parent f1200eef59
commit b49d70b738
No known key found for this signature in database
GPG Key ID: 9B60314A9DD20A62
4 changed files with 48 additions and 16 deletions

View File

@ -37,6 +37,8 @@ type accessPrivateCommand struct {
bindAddress string bindAddress string
headless bool headless bool
subordinate bool subordinate bool
forceLocal bool
forceAgent bool
responseHeaders []string responseHeaders []string
cmd *cobra.Command cmd *cobra.Command
} }
@ -51,6 +53,9 @@ func newAccessPrivateCommand() *accessPrivateCommand {
cmd.Flags().BoolVar(&command.headless, "headless", false, "Disable TUI and run headless") cmd.Flags().BoolVar(&command.headless, "headless", false, "Disable TUI and run headless")
cmd.Flags().BoolVar(&command.subordinate, "subordinate", false, "Enable subordinate mode") cmd.Flags().BoolVar(&command.subordinate, "subordinate", false, "Enable subordinate mode")
cmd.MarkFlagsMutuallyExclusive("headless", "subordinate") cmd.MarkFlagsMutuallyExclusive("headless", "subordinate")
cmd.Flags().BoolVar(&command.forceLocal, "force-local", false, "Skip agent detection and force local mode")
cmd.Flags().BoolVar(&command.forceAgent, "force-agent", false, "Skip agent detection and force agent mode")
cmd.MarkFlagsMutuallyExclusive("force-local", "force-agent")
cmd.Flags().StringVarP(&command.bindAddress, "bind", "b", "127.0.0.1:9191", "The address to bind the private frontend") cmd.Flags().StringVarP(&command.bindAddress, "bind", "b", "127.0.0.1:9191", "The address to bind the private frontend")
cmd.Flags().StringArrayVar(&command.responseHeaders, "response-header", []string{}, "Add a response header ('key:value')") cmd.Flags().StringArrayVar(&command.responseHeaders, "response-header", []string{}, "Add a response header ('key:value')")
cmd.Run = command.run cmd.Run = command.run
@ -70,13 +75,16 @@ func (cmd *accessPrivateCommand) run(_ *cobra.Command, args []string) {
tui.Error("unable to load environment; did you 'zrok enable'?", nil) tui.Error("unable to load environment; did you 'zrok enable'?", nil)
} }
if cmd.subordinate { if cmd.subordinate || cmd.forceLocal {
cmd.accessLocal(args, root) cmd.accessLocal(args, root)
} else { } else {
agent, err := agentClient.IsAgentRunning(root) agent := cmd.forceAgent
if !cmd.forceAgent {
agent, err = agentClient.IsAgentRunning(root)
if err != nil { if err != nil {
tui.Error("error checking if agent is running", err) tui.Error("error checking if agent is running", err)
} }
}
if agent { if agent {
cmd.accessAgent(args, root) cmd.accessAgent(args, root)
} else { } else {

View File

@ -35,6 +35,8 @@ type sharePrivateCommand struct {
backendMode string backendMode string
headless bool headless bool
subordinate bool subordinate bool
forceLocal bool
forceAgent bool
insecure bool insecure bool
closed bool closed bool
accessGrants []string accessGrants []string
@ -52,6 +54,9 @@ func newSharePrivateCommand() *sharePrivateCommand {
cmd.Flags().BoolVar(&command.headless, "headless", false, "Disable TUI and run headless") cmd.Flags().BoolVar(&command.headless, "headless", false, "Disable TUI and run headless")
cmd.Flags().BoolVar(&command.subordinate, "subordinate", false, "Enable agent mode") cmd.Flags().BoolVar(&command.subordinate, "subordinate", false, "Enable agent mode")
cmd.MarkFlagsMutuallyExclusive("headless", "subordinate") cmd.MarkFlagsMutuallyExclusive("headless", "subordinate")
cmd.Flags().BoolVar(&command.forceLocal, "force-local", false, "Skip agent detection and force local mode")
cmd.Flags().BoolVar(&command.forceAgent, "force-agent", false, "Skip agent detection and force agent mode")
cmd.MarkFlagsMutuallyExclusive("force-local", "force-agent")
cmd.Flags().BoolVar(&command.insecure, "insecure", false, "Enable insecure TLS certificate validation for <target>") cmd.Flags().BoolVar(&command.insecure, "insecure", false, "Enable insecure TLS certificate validation for <target>")
cmd.Flags().BoolVar(&command.closed, "closed", false, "Enable closed permission mode (see --access-grant)") cmd.Flags().BoolVar(&command.closed, "closed", false, "Enable closed permission mode (see --access-grant)")
cmd.Flags().StringArrayVar(&command.accessGrants, "access-grant", []string{}, "zrok accounts that are allowed to access this share (see --closed)") cmd.Flags().StringArrayVar(&command.accessGrants, "access-grant", []string{}, "zrok accounts that are allowed to access this share (see --closed)")
@ -72,13 +77,16 @@ func (cmd *sharePrivateCommand) run(_ *cobra.Command, args []string) {
tui.Error("unable to load environment; did you 'zrok enable'?", nil) tui.Error("unable to load environment; did you 'zrok enable'?", nil)
} }
if cmd.subordinate { if cmd.subordinate || cmd.forceLocal {
cmd.shareLocal(args, root) cmd.shareLocal(args, root)
} else { } else {
agent, err := agentClient.IsAgentRunning(root) agent := cmd.forceAgent
if !cmd.forceAgent {
agent, err = agentClient.IsAgentRunning(root)
if err != nil { if err != nil {
tui.Error("error checking if agent is running", err) tui.Error("error checking if agent is running", err)
} }
}
if agent { if agent {
cmd.shareAgent(args, root) cmd.shareAgent(args, root)
} else { } else {

View File

@ -35,6 +35,8 @@ type sharePublicCommand struct {
backendMode string backendMode string
headless bool headless bool
subordinate bool subordinate bool
forceLocal bool
forceAgent bool
insecure bool insecure bool
oauthProvider string oauthProvider string
oauthEmailAddressPatterns []string oauthEmailAddressPatterns []string
@ -61,6 +63,9 @@ func newSharePublicCommand() *sharePublicCommand {
cmd.Flags().BoolVar(&command.headless, "headless", false, "Disable TUI and run headless") cmd.Flags().BoolVar(&command.headless, "headless", false, "Disable TUI and run headless")
cmd.Flags().BoolVar(&command.subordinate, "subordinate", false, "Enable agent mode") cmd.Flags().BoolVar(&command.subordinate, "subordinate", false, "Enable agent mode")
cmd.MarkFlagsMutuallyExclusive("headless", "subordinate") cmd.MarkFlagsMutuallyExclusive("headless", "subordinate")
cmd.Flags().BoolVar(&command.forceLocal, "force-local", false, "Skip agent detection and force local mode")
cmd.Flags().BoolVar(&command.forceAgent, "force-agent", false, "Skip agent detection and force agent mode")
cmd.MarkFlagsMutuallyExclusive("force-local", "force-agent")
cmd.Flags().BoolVar(&command.insecure, "insecure", false, "Enable insecure TLS certificate validation for <target>") cmd.Flags().BoolVar(&command.insecure, "insecure", false, "Enable insecure TLS certificate validation for <target>")
cmd.Flags().BoolVar(&command.closed, "closed", false, "Enable closed permission mode (see --access-grant)") cmd.Flags().BoolVar(&command.closed, "closed", false, "Enable closed permission mode (see --access-grant)")
cmd.Flags().StringArrayVar(&command.accessGrants, "access-grant", []string{}, "zrok accounts that are allowed to access this share (see --closed)") cmd.Flags().StringArrayVar(&command.accessGrants, "access-grant", []string{}, "zrok accounts that are allowed to access this share (see --closed)")
@ -87,13 +92,16 @@ func (cmd *sharePublicCommand) run(_ *cobra.Command, args []string) {
tui.Error("unable to load environment; did you 'zrok enable'?", nil) tui.Error("unable to load environment; did you 'zrok enable'?", nil)
} }
if cmd.subordinate { if cmd.subordinate || cmd.forceLocal {
cmd.shareLocal(args, root) cmd.shareLocal(args, root)
} else { } else {
agent, err := agentClient.IsAgentRunning(root) agent := cmd.forceAgent
if !cmd.forceAgent {
agent, err = agentClient.IsAgentRunning(root)
if err != nil { if err != nil {
tui.Error("error checking if agent is running", err) tui.Error("error checking if agent is running", err)
} }
}
if agent { if agent {
cmd.shareAgent(args, root) cmd.shareAgent(args, root)
} else { } else {

View File

@ -34,6 +34,8 @@ type shareReservedCommand struct {
overrideEndpoint string overrideEndpoint string
headless bool headless bool
subordinate bool subordinate bool
forceLocal bool
forceAgent bool
insecure bool insecure bool
cmd *cobra.Command cmd *cobra.Command
} }
@ -49,6 +51,9 @@ func newShareReservedCommand() *shareReservedCommand {
cmd.Flags().BoolVar(&command.headless, "headless", false, "Disable TUI and run headless") cmd.Flags().BoolVar(&command.headless, "headless", false, "Disable TUI and run headless")
cmd.Flags().BoolVar(&command.subordinate, "subordinate", false, "Enable agent mode") cmd.Flags().BoolVar(&command.subordinate, "subordinate", false, "Enable agent mode")
cmd.MarkFlagsMutuallyExclusive("headless", "subordinate") cmd.MarkFlagsMutuallyExclusive("headless", "subordinate")
cmd.Flags().BoolVar(&command.forceLocal, "force-local", false, "Skip agent detection and force local mode")
cmd.Flags().BoolVar(&command.forceAgent, "force-agent", false, "Skip agent detection and force agent mode")
cmd.MarkFlagsMutuallyExclusive("force-local", "force-agent")
cmd.Flags().BoolVar(&command.insecure, "insecure", false, "Enable insecure TLS certificate validation") cmd.Flags().BoolVar(&command.insecure, "insecure", false, "Enable insecure TLS certificate validation")
cmd.Run = command.run cmd.Run = command.run
return command return command
@ -67,13 +72,16 @@ func (cmd *shareReservedCommand) run(_ *cobra.Command, args []string) {
tui.Error("unable to load environment; did you 'zrok enable'?", nil) tui.Error("unable to load environment; did you 'zrok enable'?", nil)
} }
if cmd.subordinate { if cmd.subordinate || cmd.forceLocal {
cmd.shareLocal(args, root) cmd.shareLocal(args, root)
} else { } else {
agent, err := agentClient.IsAgentRunning(root) agent := cmd.forceAgent
if !cmd.forceAgent {
agent, err = agentClient.IsAgentRunning(root)
if err != nil { if err != nil {
tui.Error("error checking if agent is running", err) tui.Error("error checking if agent is running", err)
} }
}
if agent { if agent {
cmd.shareAgent(args, root) cmd.shareAgent(args, root)
} else { } else {