mirror of
https://github.com/openziti/zrok.git
synced 2025-03-14 23:48:22 +01:00
temporary switch to support tcp/udp toggling (#306)
This commit is contained in:
parent
517eeb8412
commit
e19186c1a0
@ -4,6 +4,7 @@ import (
|
||||
"github.com/go-openapi/runtime"
|
||||
httptransport "github.com/go-openapi/runtime/client"
|
||||
"github.com/openziti/zrok/endpoints/tcpTunnel"
|
||||
"github.com/openziti/zrok/endpoints/udpTunnel"
|
||||
"github.com/openziti/zrok/rest_client_zrok"
|
||||
"github.com/openziti/zrok/rest_client_zrok/share"
|
||||
"github.com/openziti/zrok/rest_model_zrok"
|
||||
@ -23,6 +24,7 @@ func init() {
|
||||
|
||||
type accessPrivateTunnelCommand struct {
|
||||
bindAddress string
|
||||
udp bool
|
||||
cmd *cobra.Command
|
||||
}
|
||||
|
||||
@ -34,6 +36,7 @@ func newAccessPrivateTunnelCommand() *accessPrivateTunnelCommand {
|
||||
}
|
||||
command := &accessPrivateTunnelCommand{cmd: cmd}
|
||||
cmd.Flags().StringVarP(&command.bindAddress, "bind", "b", "tcp:127.0.0.1:9191", "The address to bind the private tunnel")
|
||||
cmd.Flags().BoolVar(&command.udp, "udp", false, "Use UDP")
|
||||
cmd.Run = command.run
|
||||
return command
|
||||
}
|
||||
@ -76,16 +79,31 @@ func (cmd *accessPrivateTunnelCommand) run(_ *cobra.Command, args []string) {
|
||||
os.Exit(0)
|
||||
}()
|
||||
|
||||
fe, err := tcpTunnel.NewFrontend(&tcpTunnel.FrontendConfig{
|
||||
BindAddress: cmd.bindAddress,
|
||||
IdentityName: "backend",
|
||||
ShrToken: args[0],
|
||||
})
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
if err := fe.Run(); err != nil {
|
||||
panic(err)
|
||||
if cmd.udp {
|
||||
fe, err := udpTunnel.NewFrontend(&udpTunnel.FrontendConfig{
|
||||
BindAddress: cmd.bindAddress,
|
||||
IdentityName: "backend",
|
||||
ShrToken: args[0],
|
||||
})
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
if err := fe.Run(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
} else {
|
||||
fe, err := tcpTunnel.NewFrontend(&tcpTunnel.FrontendConfig{
|
||||
BindAddress: cmd.bindAddress,
|
||||
IdentityName: "backend",
|
||||
ShrToken: args[0],
|
||||
})
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
if err := fe.Run(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
for {
|
||||
time.Sleep(30 * 24 * time.Hour)
|
||||
|
@ -8,6 +8,7 @@ import (
|
||||
"github.com/openziti/zrok/endpoints"
|
||||
"github.com/openziti/zrok/endpoints/proxy"
|
||||
"github.com/openziti/zrok/endpoints/tcpTunnel"
|
||||
"github.com/openziti/zrok/endpoints/udpTunnel"
|
||||
"github.com/openziti/zrok/model"
|
||||
"github.com/openziti/zrok/rest_client_zrok"
|
||||
"github.com/openziti/zrok/rest_client_zrok/share"
|
||||
@ -32,6 +33,7 @@ type sharePrivateCommand struct {
|
||||
backendMode string
|
||||
headless bool
|
||||
insecure bool
|
||||
udp bool
|
||||
cmd *cobra.Command
|
||||
}
|
||||
|
||||
@ -46,6 +48,7 @@ func newSharePrivateCommand() *sharePrivateCommand {
|
||||
cmd.Flags().StringVar(&command.backendMode, "backend-mode", "proxy", "The backend mode {proxy, web, tunnel}")
|
||||
cmd.Flags().BoolVar(&command.headless, "headless", false, "Disable TUI and run headless")
|
||||
cmd.Flags().BoolVar(&command.insecure, "insecure", false, "Enable insecure TLS certificate validation for <target>")
|
||||
cmd.Flags().BoolVar(&command.udp, "udp", false, "Enable UDP for tunnel backend")
|
||||
cmd.Run = command.run
|
||||
return command
|
||||
}
|
||||
@ -173,16 +176,43 @@ func (cmd *sharePrivateCommand) run(_ *cobra.Command, args []string) {
|
||||
}
|
||||
|
||||
case "tunnel":
|
||||
cfg := &tcpTunnel.BackendConfig{
|
||||
IdentityPath: zif,
|
||||
EndpointAddress: target,
|
||||
ShrToken: resp.Payload.ShrToken,
|
||||
}
|
||||
if err := cmd.tunnelBackendMode(cfg); err != nil {
|
||||
if !panicInstead {
|
||||
tui.Error("unable to create tunnel backend", err)
|
||||
if cmd.udp {
|
||||
cfg := &udpTunnel.BackendConfig{
|
||||
IdentityPath: zif,
|
||||
EndpointAddress: target,
|
||||
ShrToken: resp.Payload.ShrToken,
|
||||
}
|
||||
panic(err)
|
||||
be, err := udpTunnel.NewBackend(cfg)
|
||||
if err != nil {
|
||||
if !panicInstead {
|
||||
tui.Error("unable to create udp tunnel backend", err)
|
||||
}
|
||||
panic(err)
|
||||
}
|
||||
go func() {
|
||||
if err := be.Run(); err != nil {
|
||||
logrus.Errorf("error running udp tunnel backend: %v", err)
|
||||
}
|
||||
}()
|
||||
|
||||
} else {
|
||||
cfg := &tcpTunnel.BackendConfig{
|
||||
IdentityPath: zif,
|
||||
EndpointAddress: target,
|
||||
ShrToken: resp.Payload.ShrToken,
|
||||
}
|
||||
be, err := tcpTunnel.NewBackend(cfg)
|
||||
if err != nil {
|
||||
if !panicInstead {
|
||||
tui.Error("unable to create tunnel backend", err)
|
||||
}
|
||||
panic(err)
|
||||
}
|
||||
go func() {
|
||||
if err := be.Run(); err != nil {
|
||||
logrus.Errorf("error running tunnel backend: %v", err)
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
default:
|
||||
@ -253,21 +283,6 @@ func (cmd *sharePrivateCommand) webBackendMode(cfg *proxy.WebBackendConfig) (end
|
||||
return be, nil
|
||||
}
|
||||
|
||||
func (cmd *sharePrivateCommand) tunnelBackendMode(cfg *tcpTunnel.BackendConfig) error {
|
||||
be, err := tcpTunnel.NewBackend(cfg)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "error creating tunnel backend")
|
||||
}
|
||||
|
||||
go func() {
|
||||
if err := be.Run(); err != nil {
|
||||
logrus.Errorf("error running tunnel backend: %v", err)
|
||||
}
|
||||
}()
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (cmd *sharePrivateCommand) destroy(id string, shrToken string, zrok *rest_client_zrok.Zrok, auth runtime.ClientAuthInfoWriter) {
|
||||
logrus.Debugf("shutting down '%v'", shrToken)
|
||||
req := share.NewUnshareParams()
|
||||
|
Loading…
Reference in New Issue
Block a user