-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
working 'zrok agent access private' (#463)
- Loading branch information
1 parent
e6a74ad
commit fb23d23
Showing
4 changed files
with
89 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"github.com/openziti/zrok/agent/agentClient" | ||
"github.com/openziti/zrok/agent/agentGrpc" | ||
"github.com/openziti/zrok/environment" | ||
"github.com/openziti/zrok/tui" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func init() { | ||
agentAccessCmd.AddCommand(newAgentAccessPrivateCommand().cmd) | ||
} | ||
|
||
type agentAccessPrivateCommand struct { | ||
bindAddress string | ||
responseHeaders []string | ||
cmd *cobra.Command | ||
} | ||
|
||
func newAgentAccessPrivateCommand() *agentAccessPrivateCommand { | ||
cmd := &cobra.Command{ | ||
Use: "private <token>", | ||
Short: "Bind a private access in the zrok Agent", | ||
Args: cobra.ExactArgs(1), | ||
} | ||
command := &agentAccessPrivateCommand{cmd: cmd} | ||
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 | ||
return command | ||
} | ||
|
||
func (cmd *agentAccessPrivateCommand) run(_ *cobra.Command, args []string) { | ||
root, err := environment.LoadRoot() | ||
if err != nil { | ||
if !panicInstead { | ||
tui.Error("unable to load environment", err) | ||
} | ||
panic(err) | ||
} | ||
|
||
if !root.IsEnabled() { | ||
tui.Error("unable to load environment; did you 'zrok enable'?", nil) | ||
} | ||
|
||
client, conn, err := agentClient.NewClient(root) | ||
if err != nil { | ||
tui.Error("error connecting to agent", err) | ||
} | ||
defer conn.Close() | ||
|
||
acc, err := client.PrivateAccess(context.Background(), &agentGrpc.PrivateAccessRequest{ | ||
Token: args[0], | ||
BindAddress: cmd.bindAddress, | ||
ResponseHeaders: cmd.responseHeaders, | ||
}) | ||
if err != nil { | ||
tui.Error("error creating access", err) | ||
} | ||
|
||
fmt.Println(acc) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters