From ce06804a0fe3d6722e9c73808e3882fb79b421d4 Mon Sep 17 00:00:00 2001 From: Michael Quigley Date: Mon, 28 Aug 2023 13:54:03 -0400 Subject: [PATCH] share public cleanup+organization lint --- cmd/zrok/sharePublic.go | 59 +++++++++++++++-------------------------- 1 file changed, 21 insertions(+), 38 deletions(-) diff --git a/cmd/zrok/sharePublic.go b/cmd/zrok/sharePublic.go index 1742cbc8..637bf56b 100644 --- a/cmd/zrok/sharePublic.go +++ b/cmd/zrok/sharePublic.go @@ -9,7 +9,6 @@ import ( "github.com/openziti/zrok/environment/env_core" "github.com/openziti/zrok/sdk" "github.com/openziti/zrok/tui" - "github.com/pkg/errors" "github.com/sirupsen/logrus" "github.com/spf13/cobra" "os" @@ -106,7 +105,7 @@ func (cmd *sharePublicCommand) run(_ *cobra.Command, args []string) { signal.Notify(c, os.Interrupt, syscall.SIGTERM) go func() { <-c - cmd.destroy(env, shr) + cmd.shutdown(env, shr) os.Exit(0) }() @@ -121,14 +120,21 @@ func (cmd *sharePublicCommand) run(_ *cobra.Command, args []string) { Insecure: cmd.insecure, RequestsChan: requests, } - _, err = cmd.proxyBackendMode(cfg) + + be, err := proxy.NewBackend(cfg) if err != nil { if !panicInstead { - tui.Error("unable to create proxy backend handler", err) + tui.Error("error creating proxy backend", err) } panic(err) } + go func() { + if err := be.Run(); err != nil { + logrus.Errorf("error running http proxy backend: %v", err) + } + }() + case "web": cfg := &proxy.CaddyWebBackendConfig{ IdentityPath: zif, @@ -136,14 +142,21 @@ func (cmd *sharePublicCommand) run(_ *cobra.Command, args []string) { ShrToken: shr.Token, Requests: requests, } - _, err = cmd.webBackendMode(cfg) + + be, err := proxy.NewCaddyWebBackend(cfg) if err != nil { if !panicInstead { - tui.Error("unable to create web backend handler", err) + tui.Error("unable to create web backend", err) } panic(err) } + go func() { + if err := be.Run(); err != nil { + logrus.Errorf("error running http web backend: %v", err) + } + }() + default: tui.Error("invalid backend mode", nil) } @@ -176,41 +189,11 @@ func (cmd *sharePublicCommand) run(_ *cobra.Command, args []string) { } close(requests) - cmd.destroy(env, shr) + cmd.shutdown(env, shr) } } -func (cmd *sharePublicCommand) proxyBackendMode(cfg *proxy.BackendConfig) (endpoints.RequestHandler, error) { - be, err := proxy.NewBackend(cfg) - if err != nil { - return nil, errors.Wrap(err, "error creating http proxy backend") - } - - go func() { - if err := be.Run(); err != nil { - logrus.Errorf("error running http proxy backend: %v", err) - } - }() - - return be, nil -} - -func (cmd *sharePublicCommand) webBackendMode(cfg *proxy.CaddyWebBackendConfig) (endpoints.RequestHandler, error) { - be, err := proxy.NewCaddyWebBackend(cfg) - if err != nil { - return nil, errors.Wrap(err, "error creating http web backend") - } - - go func() { - if err := be.Run(); err != nil { - logrus.Errorf("error running http web backend: %v", err) - } - }() - - return be, nil -} - -func (cmd *sharePublicCommand) destroy(root env_core.Root, shr *sdk.Share) { +func (cmd *sharePublicCommand) shutdown(root env_core.Root, shr *sdk.Share) { logrus.Debugf("shutting down '%v'", shr.Token) if err := sdk.DeleteShare(root, shr); err != nil { logrus.Errorf("error shutting down '%v': %v", shr.Token, err)