support public and reserved shares with drives backend (#218)

This commit is contained in:
Michael Quigley 2023-10-20 16:13:00 -04:00
parent e58f5bfba6
commit e188f1243d
No known key found for this signature in database
GPG Key ID: 9B60314A9DD20A62
2 changed files with 59 additions and 10 deletions

View File

@ -4,6 +4,7 @@ import (
"fmt"
tea "github.com/charmbracelet/bubbletea"
"github.com/openziti/zrok/endpoints"
drive "github.com/openziti/zrok/endpoints/drive"
"github.com/openziti/zrok/endpoints/proxy"
"github.com/openziti/zrok/environment"
"github.com/openziti/zrok/environment/env_core"
@ -42,7 +43,7 @@ func newSharePublicCommand() *sharePublicCommand {
}
command := &sharePublicCommand{cmd: cmd}
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, caddy}")
cmd.Flags().StringVarP(&command.backendMode, "backend-mode", "b", "proxy", "The backend mode {proxy, web, caddy, drive}")
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>")
@ -77,6 +78,9 @@ func (cmd *sharePublicCommand) run(_ *cobra.Command, args []string) {
target = args[0]
cmd.headless = true
case "drive":
target = args[0]
default:
tui.Error(fmt.Sprintf("invalid backend mode '%v'; expected {proxy, web}", cmd.backendMode), nil)
}
@ -204,6 +208,28 @@ func (cmd *sharePublicCommand) run(_ *cobra.Command, args []string) {
}
}()
case "drive":
cfg := &drive.BackendConfig{
IdentityPath: zif,
DriveRoot: target,
ShrToken: shr.Token,
Requests: requests,
}
be, err := drive.NewBackend(cfg)
if err != nil {
if !panicInstead {
tui.Error("error creating drive backend", err)
}
panic(err)
}
go func() {
if err := be.Run(); err != nil {
logrus.Errorf("error running drive backend: %v", err)
}
}()
default:
tui.Error("invalid backend mode", nil)
}

View File

@ -5,6 +5,7 @@ import (
tea "github.com/charmbracelet/bubbletea"
httptransport "github.com/go-openapi/runtime/client"
"github.com/openziti/zrok/endpoints"
"github.com/openziti/zrok/endpoints/drive"
"github.com/openziti/zrok/endpoints/proxy"
"github.com/openziti/zrok/endpoints/tcpTunnel"
"github.com/openziti/zrok/endpoints/udpTunnel"
@ -123,7 +124,7 @@ func (cmd *shareReservedCommand) run(_ *cobra.Command, args []string) {
proxy.SetCaddyLoggingWriter(mdl)
}
requestsChan := make(chan *endpoints.Request, 1024)
requests := make(chan *endpoints.Request, 1024)
switch resp.Payload.BackendMode {
case "proxy":
cfg := &proxy.BackendConfig{
@ -131,7 +132,7 @@ func (cmd *shareReservedCommand) run(_ *cobra.Command, args []string) {
EndpointAddress: target,
ShrToken: shrToken,
Insecure: cmd.insecure,
Requests: requestsChan,
Requests: requests,
}
be, err := proxy.NewBackend(cfg)
@ -153,7 +154,7 @@ func (cmd *shareReservedCommand) run(_ *cobra.Command, args []string) {
IdentityPath: zif,
WebRoot: target,
ShrToken: shrToken,
Requests: requestsChan,
Requests: requests,
}
be, err := proxy.NewCaddyWebBackend(cfg)
@ -175,7 +176,7 @@ func (cmd *shareReservedCommand) run(_ *cobra.Command, args []string) {
IdentityPath: zif,
EndpointAddress: target,
ShrToken: shrToken,
RequestsChan: requestsChan,
RequestsChan: requests,
}
be, err := tcpTunnel.NewBackend(cfg)
@ -197,7 +198,7 @@ func (cmd *shareReservedCommand) run(_ *cobra.Command, args []string) {
IdentityPath: zif,
EndpointAddress: target,
ShrToken: shrToken,
RequestsChan: requestsChan,
RequestsChan: requests,
}
be, err := udpTunnel.NewBackend(cfg)
@ -218,7 +219,7 @@ func (cmd *shareReservedCommand) run(_ *cobra.Command, args []string) {
cfg := &proxy.CaddyfileBackendConfig{
CaddyfilePath: target,
Shr: &sdk.Share{Token: shrToken, FrontendEndpoints: []string{resp.Payload.FrontendEndpoint}},
Requests: requestsChan,
Requests: requests,
}
be, err := proxy.NewCaddyfileBackend(cfg)
@ -235,6 +236,28 @@ func (cmd *shareReservedCommand) run(_ *cobra.Command, args []string) {
}
}()
case "drive":
cfg := &drive.BackendConfig{
IdentityPath: zif,
DriveRoot: target,
ShrToken: shrToken,
Requests: requests,
}
be, err := drive.NewBackend(cfg)
if err != nil {
if !panicInstead {
tui.Error("error creating drive backend", err)
}
panic(err)
}
go func() {
if err := be.Run(); err != nil {
logrus.Errorf("error running drive backend: %v", err)
}
}()
default:
tui.Error("invalid backend mode", nil)
}
@ -249,7 +272,7 @@ func (cmd *shareReservedCommand) run(_ *cobra.Command, args []string) {
}
for {
select {
case req := <-requestsChan:
case req := <-requests:
logrus.Infof("%v -> %v %v", req.RemoteAddr, req.Method, req.Path)
}
}
@ -261,7 +284,7 @@ func (cmd *shareReservedCommand) run(_ *cobra.Command, args []string) {
go func() {
for {
select {
case req := <-requestsChan:
case req := <-requests:
prg.Send(req)
}
}
@ -271,6 +294,6 @@ func (cmd *shareReservedCommand) run(_ *cobra.Command, args []string) {
tui.Error("An error occurred", err)
}
close(requestsChan)
close(requests)
}
}