From 4c41908ce21402f9eb5e9b19f8352ff85f8fabd7 Mon Sep 17 00:00:00 2001 From: Michael Quigley Date: Tue, 18 Apr 2023 13:36:43 -0400 Subject: [PATCH] proxyBackend/proxyFrontend -> proxy (#170) --- cmd/zrok/accessPrivate.go | 6 ++--- cmd/zrok/sharePrivate.go | 8 +++---- cmd/zrok/sharePublic.go | 8 +++---- cmd/zrok/shareReserved.go | 8 +++---- .../http.go => proxy/backend.go} | 10 ++++---- .../http.go => proxy/frontend.go} | 24 +++++++++---------- 6 files changed, 32 insertions(+), 32 deletions(-) rename endpoints/{proxyBackend/http.go => proxy/backend.go} (91%) rename endpoints/{proxyFrontend/http.go => proxy/frontend.go} (91%) diff --git a/cmd/zrok/accessPrivate.go b/cmd/zrok/accessPrivate.go index 23abb811..4f4e1856 100644 --- a/cmd/zrok/accessPrivate.go +++ b/cmd/zrok/accessPrivate.go @@ -5,7 +5,7 @@ import ( "github.com/go-openapi/runtime" httptransport "github.com/go-openapi/runtime/client" "github.com/openziti/zrok/endpoints" - "github.com/openziti/zrok/endpoints/proxyFrontend" + "github.com/openziti/zrok/endpoints/proxy" "github.com/openziti/zrok/rest_client_zrok" "github.com/openziti/zrok/rest_client_zrok/share" "github.com/openziti/zrok/rest_model_zrok" @@ -88,7 +88,7 @@ func (cmd *accessPrivateCommand) run(_ *cobra.Command, args []string) { } logrus.Infof("allocated frontend '%v'", accessResp.Payload.FrontendToken) - cfg := proxyFrontend.DefaultConfig("backend") + cfg := proxy.DefaultFrontendConfig("backend") cfg.ShrToken = shrToken cfg.Address = cmd.bindAddress cfg.RequestsChan = make(chan *endpoints.Request, 1024) @@ -101,7 +101,7 @@ func (cmd *accessPrivateCommand) run(_ *cobra.Command, args []string) { os.Exit(0) }() - frontend, err := proxyFrontend.NewHTTP(cfg) + frontend, err := proxy.NewFrontend(cfg) if err != nil { if !panicInstead { tui.Error("unable to create private frontend", err) diff --git a/cmd/zrok/sharePrivate.go b/cmd/zrok/sharePrivate.go index 5df58391..cc7d1bdd 100644 --- a/cmd/zrok/sharePrivate.go +++ b/cmd/zrok/sharePrivate.go @@ -6,7 +6,7 @@ import ( "github.com/go-openapi/runtime" httptransport "github.com/go-openapi/runtime/client" "github.com/openziti/zrok/endpoints" - "github.com/openziti/zrok/endpoints/proxyBackend" + "github.com/openziti/zrok/endpoints/proxy" "github.com/openziti/zrok/endpoints/tcpTunnel" "github.com/openziti/zrok/endpoints/webBackend" "github.com/openziti/zrok/model" @@ -145,7 +145,7 @@ func (cmd *sharePrivateCommand) run(_ *cobra.Command, args []string) { requestsChan := make(chan *endpoints.Request, 1024) switch cmd.backendMode { case "proxy": - cfg := &proxyBackend.Config{ + cfg := &proxy.BackendConfig{ IdentityPath: zif, EndpointAddress: target, ShrToken: resp.Payload.ShrToken, @@ -226,8 +226,8 @@ func (cmd *sharePrivateCommand) run(_ *cobra.Command, args []string) { } } -func (cmd *sharePrivateCommand) proxyBackendMode(cfg *proxyBackend.Config) (endpoints.RequestHandler, error) { - be, err := proxyBackend.New(cfg) +func (cmd *sharePrivateCommand) 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") } diff --git a/cmd/zrok/sharePublic.go b/cmd/zrok/sharePublic.go index 88b27d95..b8f05548 100644 --- a/cmd/zrok/sharePublic.go +++ b/cmd/zrok/sharePublic.go @@ -6,7 +6,7 @@ import ( "github.com/go-openapi/runtime" httptransport "github.com/go-openapi/runtime/client" "github.com/openziti/zrok/endpoints" - "github.com/openziti/zrok/endpoints/proxyBackend" + "github.com/openziti/zrok/endpoints/proxy" "github.com/openziti/zrok/endpoints/webBackend" "github.com/openziti/zrok/model" "github.com/openziti/zrok/rest_client_zrok" @@ -142,7 +142,7 @@ func (cmd *sharePublicCommand) run(_ *cobra.Command, args []string) { requestsChan := make(chan *endpoints.Request, 1024) switch cmd.backendMode { case "proxy": - cfg := &proxyBackend.Config{ + cfg := &proxy.BackendConfig{ IdentityPath: zif, EndpointAddress: target, ShrToken: resp.Payload.ShrToken, @@ -209,8 +209,8 @@ func (cmd *sharePublicCommand) run(_ *cobra.Command, args []string) { } } -func (cmd *sharePublicCommand) proxyBackendMode(cfg *proxyBackend.Config) (endpoints.RequestHandler, error) { - be, err := proxyBackend.New(cfg) +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") } diff --git a/cmd/zrok/shareReserved.go b/cmd/zrok/shareReserved.go index 5a1ff3f1..6f6d0a63 100644 --- a/cmd/zrok/shareReserved.go +++ b/cmd/zrok/shareReserved.go @@ -5,7 +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/proxyBackend" + "github.com/openziti/zrok/endpoints/proxy" "github.com/openziti/zrok/endpoints/webBackend" "github.com/openziti/zrok/rest_client_zrok/metadata" "github.com/openziti/zrok/rest_client_zrok/share" @@ -108,7 +108,7 @@ func (cmd *shareReservedCommand) run(_ *cobra.Command, args []string) { requestsChan := make(chan *endpoints.Request, 1024) switch resp.Payload.BackendMode { case "proxy": - cfg := &proxyBackend.Config{ + cfg := &proxy.BackendConfig{ IdentityPath: zif, EndpointAddress: target, ShrToken: shrToken, @@ -187,8 +187,8 @@ func (cmd *shareReservedCommand) run(_ *cobra.Command, args []string) { } } -func (cmd *shareReservedCommand) proxyBackendMode(cfg *proxyBackend.Config) (endpoints.RequestHandler, error) { - be, err := proxyBackend.New(cfg) +func (cmd *shareReservedCommand) 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") } diff --git a/endpoints/proxyBackend/http.go b/endpoints/proxy/backend.go similarity index 91% rename from endpoints/proxyBackend/http.go rename to endpoints/proxy/backend.go index 94b44bab..027f56c8 100644 --- a/endpoints/proxyBackend/http.go +++ b/endpoints/proxy/backend.go @@ -1,4 +1,4 @@ -package proxyBackend +package proxy import ( "crypto/tls" @@ -16,7 +16,7 @@ import ( "time" ) -type Config struct { +type BackendConfig struct { IdentityPath string EndpointAddress string ShrToken string @@ -25,13 +25,13 @@ type Config struct { } type Backend struct { - cfg *Config + cfg *BackendConfig requests func() int32 listener edge.Listener handler http.Handler } -func New(cfg *Config) (*Backend, error) { +func NewBackend(cfg *BackendConfig) (*Backend, error) { options := ziti.ListenOptions{ ConnectTimeout: 5 * time.Minute, MaxConnections: 64, @@ -70,7 +70,7 @@ func (b *Backend) Requests() func() int32 { return b.requests } -func newReverseProxy(cfg *Config) (*httputil.ReverseProxy, error) { +func newReverseProxy(cfg *BackendConfig) (*httputil.ReverseProxy, error) { targetURL, err := url.Parse(cfg.EndpointAddress) if err != nil { return nil, err diff --git a/endpoints/proxyFrontend/http.go b/endpoints/proxy/frontend.go similarity index 91% rename from endpoints/proxyFrontend/http.go rename to endpoints/proxy/frontend.go index e01d9948..c19db92a 100644 --- a/endpoints/proxyFrontend/http.go +++ b/endpoints/proxy/frontend.go @@ -1,4 +1,4 @@ -package proxyFrontend +package proxy import ( "context" @@ -19,28 +19,28 @@ import ( "time" ) -type Config struct { +type FrontendConfig struct { IdentityName string ShrToken string Address string RequestsChan chan *endpoints.Request } -func DefaultConfig(identityName string) *Config { - return &Config{ +func DefaultFrontendConfig(identityName string) *FrontendConfig { + return &FrontendConfig{ IdentityName: identityName, Address: "0.0.0.0:8080", } } -type httpFrontend struct { - cfg *Config +type Frontend struct { + cfg *FrontendConfig zCtx ziti.Context shrToken string handler http.Handler } -func NewHTTP(cfg *Config) (*httpFrontend, error) { +func NewFrontend(cfg *FrontendConfig) (*Frontend, error) { zCfgPath, err := zrokdir.ZitiIdentityFile(cfg.IdentityName) if err != nil { return nil, errors.Wrapf(err, "error getting ziti identity '%v' from zrokdir", cfg.IdentityName) @@ -62,14 +62,14 @@ func NewHTTP(cfg *Config) (*httpFrontend, error) { proxy.Transport = zTransport handler := authHandler(cfg.ShrToken, util.NewProxyHandler(proxy), "zrok", cfg, zCtx) - return &httpFrontend{ + return &Frontend{ cfg: cfg, zCtx: zCtx, handler: handler, }, nil } -func (h *httpFrontend) Run() error { +func (h *Frontend) Run() error { return http.ListenAndServe(h.cfg.Address, h.handler) } @@ -86,7 +86,7 @@ func (zdc *zitiDialContext) Dial(_ context.Context, _ string, addr string) (net. return conn, nil } -func newServiceProxy(cfg *Config, ctx ziti.Context) (*httputil.ReverseProxy, error) { +func newServiceProxy(cfg *FrontendConfig, ctx ziti.Context) (*httputil.ReverseProxy, error) { proxy := serviceTargetProxy(cfg, ctx) director := proxy.Director proxy.Director = func(req *http.Request) { @@ -111,7 +111,7 @@ func newServiceProxy(cfg *Config, ctx ziti.Context) (*httputil.ReverseProxy, err return proxy, nil } -func serviceTargetProxy(cfg *Config, ctx ziti.Context) *httputil.ReverseProxy { +func serviceTargetProxy(cfg *FrontendConfig, ctx ziti.Context) *httputil.ReverseProxy { director := func(req *http.Request) { targetShrToken := cfg.ShrToken if svc, found := endpoints.GetRefreshedService(targetShrToken, ctx); found { @@ -144,7 +144,7 @@ func serviceTargetProxy(cfg *Config, ctx ziti.Context) *httputil.ReverseProxy { return &httputil.ReverseProxy{Director: director} } -func authHandler(shrToken string, handler http.Handler, realm string, cfg *Config, ctx ziti.Context) http.HandlerFunc { +func authHandler(shrToken string, handler http.Handler, realm string, cfg *FrontendConfig, ctx ziti.Context) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { if svc, found := endpoints.GetRefreshedService(shrToken, ctx); found { if cfg, found := svc.Configs[model.ZrokProxyConfig]; found {