Skip to content

Commit

Permalink
add '--force-local' and '--force-agent' to 'zrok share [public|privat…
Browse files Browse the repository at this point in the history
…e|reserved]' and 'zrok access private' (#751)
  • Loading branch information
michaelquigley committed Sep 25, 2024
1 parent f1200ee commit b49d70b
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 16 deletions.
16 changes: 12 additions & 4 deletions cmd/zrok/accessPrivate.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ type accessPrivateCommand struct {
bindAddress string
headless bool
subordinate bool
forceLocal bool
forceAgent bool
responseHeaders []string
cmd *cobra.Command
}
Expand All @@ -51,6 +53,9 @@ func newAccessPrivateCommand() *accessPrivateCommand {
cmd.Flags().BoolVar(&command.headless, "headless", false, "Disable TUI and run headless")
cmd.Flags().BoolVar(&command.subordinate, "subordinate", false, "Enable subordinate mode")
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().StringArrayVar(&command.responseHeaders, "response-header", []string{}, "Add a response header ('key:value')")
cmd.Run = command.run
Expand All @@ -70,12 +75,15 @@ func (cmd *accessPrivateCommand) run(_ *cobra.Command, args []string) {
tui.Error("unable to load environment; did you 'zrok enable'?", nil)
}

if cmd.subordinate {
if cmd.subordinate || cmd.forceLocal {
cmd.accessLocal(args, root)
} else {
agent, err := agentClient.IsAgentRunning(root)
if err != nil {
tui.Error("error checking if agent is running", err)
agent := cmd.forceAgent
if !cmd.forceAgent {
agent, err = agentClient.IsAgentRunning(root)
if err != nil {
tui.Error("error checking if agent is running", err)
}
}
if agent {
cmd.accessAgent(args, root)
Expand Down
16 changes: 12 additions & 4 deletions cmd/zrok/sharePrivate.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ type sharePrivateCommand struct {
backendMode string
headless bool
subordinate bool
forceLocal bool
forceAgent bool
insecure bool
closed bool
accessGrants []string
Expand All @@ -52,6 +54,9 @@ func newSharePrivateCommand() *sharePrivateCommand {
cmd.Flags().BoolVar(&command.headless, "headless", false, "Disable TUI and run headless")
cmd.Flags().BoolVar(&command.subordinate, "subordinate", false, "Enable agent mode")
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.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)")
Expand All @@ -72,12 +77,15 @@ func (cmd *sharePrivateCommand) run(_ *cobra.Command, args []string) {
tui.Error("unable to load environment; did you 'zrok enable'?", nil)
}

if cmd.subordinate {
if cmd.subordinate || cmd.forceLocal {
cmd.shareLocal(args, root)
} else {
agent, err := agentClient.IsAgentRunning(root)
if err != nil {
tui.Error("error checking if agent is running", err)
agent := cmd.forceAgent
if !cmd.forceAgent {
agent, err = agentClient.IsAgentRunning(root)
if err != nil {
tui.Error("error checking if agent is running", err)
}
}
if agent {
cmd.shareAgent(args, root)
Expand Down
16 changes: 12 additions & 4 deletions cmd/zrok/sharePublic.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ type sharePublicCommand struct {
backendMode string
headless bool
subordinate bool
forceLocal bool
forceAgent bool
insecure bool
oauthProvider string
oauthEmailAddressPatterns []string
Expand All @@ -61,6 +63,9 @@ func newSharePublicCommand() *sharePublicCommand {
cmd.Flags().BoolVar(&command.headless, "headless", false, "Disable TUI and run headless")
cmd.Flags().BoolVar(&command.subordinate, "subordinate", false, "Enable agent mode")
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.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)")
Expand All @@ -87,12 +92,15 @@ func (cmd *sharePublicCommand) run(_ *cobra.Command, args []string) {
tui.Error("unable to load environment; did you 'zrok enable'?", nil)
}

if cmd.subordinate {
if cmd.subordinate || cmd.forceLocal {
cmd.shareLocal(args, root)
} else {
agent, err := agentClient.IsAgentRunning(root)
if err != nil {
tui.Error("error checking if agent is running", err)
agent := cmd.forceAgent
if !cmd.forceAgent {
agent, err = agentClient.IsAgentRunning(root)
if err != nil {
tui.Error("error checking if agent is running", err)
}
}
if agent {
cmd.shareAgent(args, root)
Expand Down
16 changes: 12 additions & 4 deletions cmd/zrok/shareReserved.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ type shareReservedCommand struct {
overrideEndpoint string
headless bool
subordinate bool
forceLocal bool
forceAgent bool
insecure bool
cmd *cobra.Command
}
Expand All @@ -49,6 +51,9 @@ func newShareReservedCommand() *shareReservedCommand {
cmd.Flags().BoolVar(&command.headless, "headless", false, "Disable TUI and run headless")
cmd.Flags().BoolVar(&command.subordinate, "subordinate", false, "Enable agent mode")
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.Run = command.run
return command
Expand All @@ -67,12 +72,15 @@ func (cmd *shareReservedCommand) run(_ *cobra.Command, args []string) {
tui.Error("unable to load environment; did you 'zrok enable'?", nil)
}

if cmd.subordinate {
if cmd.subordinate || cmd.forceLocal {
cmd.shareLocal(args, root)
} else {
agent, err := agentClient.IsAgentRunning(root)
if err != nil {
tui.Error("error checking if agent is running", err)
agent := cmd.forceAgent
if !cmd.forceAgent {
agent, err = agentClient.IsAgentRunning(root)
if err != nil {
tui.Error("error checking if agent is running", err)
}
}
if agent {
cmd.shareAgent(args, root)
Expand Down

0 comments on commit b49d70b

Please sign in to comment.