reorg, streamlining

This commit is contained in:
Michael Quigley 2023-01-10 17:40:20 -05:00
parent 163cc9b49c
commit 7868ce8527
No known key found for this signature in database
GPG Key ID: 9B60314A9DD20A62
12 changed files with 38 additions and 36 deletions

View File

@ -86,7 +86,7 @@ func (cmd *accessPrivateCommand) run(_ *cobra.Command, args []string) {
cfg := privateFrontend.DefaultConfig("backend")
cfg.ShrToken = shrToken
cfg.Address = cmd.bindAddress
cfg.RequestsChan = make(chan *endpoints.BackendRequest, 1024)
cfg.RequestsChan = make(chan *endpoints.Request, 1024)
c := make(chan os.Signal)
signal.Notify(c, os.Interrupt, syscall.SIGTERM)

View File

@ -12,7 +12,7 @@ import (
type accessModel struct {
shrToken string
localEndpoint string
requests []*endpoints.BackendRequest
requests []*endpoints.Request
width int
height int
}
@ -28,8 +28,8 @@ func (m *accessModel) Init() tea.Cmd { return nil }
func (m *accessModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
switch msg := msg.(type) {
case *endpoints.BackendRequest:
m.requests = append([]*endpoints.BackendRequest{msg}, m.requests...)
case *endpoints.Request:
m.requests = append([]*endpoints.Request{msg}, m.requests...)
if len(m.requests) > 2048 {
m.requests = m.requests[:2048]
}

View File

@ -138,7 +138,7 @@ func (cmd *sharePrivateCommand) run(_ *cobra.Command, args []string) {
os.Exit(0)
}()
requestsChan := make(chan *endpoints.BackendRequest, 1024)
requestsChan := make(chan *endpoints.Request, 1024)
switch cmd.backendMode {
case "proxy":
cfg := &proxyBackend.Config{
@ -206,7 +206,7 @@ func (cmd *sharePrivateCommand) run(_ *cobra.Command, args []string) {
}
}
func (cmd *sharePrivateCommand) proxyBackendMode(cfg *proxyBackend.Config) (endpoints.BackendHandler, error) {
func (cmd *sharePrivateCommand) proxyBackendMode(cfg *proxyBackend.Config) (endpoints.RequestHandler, error) {
be, err := proxyBackend.NewBackend(cfg)
if err != nil {
return nil, errors.Wrap(err, "error creating http proxy backend")
@ -221,7 +221,7 @@ func (cmd *sharePrivateCommand) proxyBackendMode(cfg *proxyBackend.Config) (endp
return be, nil
}
func (cmd *sharePrivateCommand) webBackendMode(cfg *webBackend.Config) (endpoints.BackendHandler, error) {
func (cmd *sharePrivateCommand) webBackendMode(cfg *webBackend.Config) (endpoints.RequestHandler, error) {
be, err := webBackend.NewBackend(cfg)
if err != nil {
return nil, errors.Wrap(err, "error creating http web backend")

View File

@ -141,7 +141,7 @@ func (cmd *sharePublicCommand) run(_ *cobra.Command, args []string) {
os.Exit(0)
}()
requestsChan := make(chan *endpoints.BackendRequest, 1024)
requestsChan := make(chan *endpoints.Request, 1024)
switch cmd.backendMode {
case "proxy":
cfg := &proxyBackend.Config{
@ -208,7 +208,7 @@ func (cmd *sharePublicCommand) run(_ *cobra.Command, args []string) {
}
}
func (cmd *sharePublicCommand) proxyBackendMode(cfg *proxyBackend.Config) (endpoints.BackendHandler, error) {
func (cmd *sharePublicCommand) proxyBackendMode(cfg *proxyBackend.Config) (endpoints.RequestHandler, error) {
be, err := proxyBackend.NewBackend(cfg)
if err != nil {
return nil, errors.Wrap(err, "error creating http proxy backend")
@ -223,7 +223,7 @@ func (cmd *sharePublicCommand) proxyBackendMode(cfg *proxyBackend.Config) (endpo
return be, nil
}
func (cmd *sharePublicCommand) webBackendMode(cfg *webBackend.Config) (endpoints.BackendHandler, error) {
func (cmd *sharePublicCommand) webBackendMode(cfg *webBackend.Config) (endpoints.RequestHandler, error) {
be, err := webBackend.NewBackend(cfg)
if err != nil {
return nil, errors.Wrap(err, "error creating http web backend")

View File

@ -103,7 +103,7 @@ func (cmd *shareReservedCommand) run(_ *cobra.Command, args []string) {
logrus.Infof("using existing backend proxy endpoint: %v", target)
}
requestsChan := make(chan *endpoints.BackendRequest, 1024)
requestsChan := make(chan *endpoints.Request, 1024)
switch resp.Payload.BackendMode {
case "proxy":
cfg := &proxyBackend.Config{
@ -182,7 +182,7 @@ func (cmd *shareReservedCommand) run(_ *cobra.Command, args []string) {
}
}
func (cmd *shareReservedCommand) proxyBackendMode(cfg *proxyBackend.Config) (endpoints.BackendHandler, error) {
func (cmd *shareReservedCommand) proxyBackendMode(cfg *proxyBackend.Config) (endpoints.RequestHandler, error) {
be, err := proxyBackend.NewBackend(cfg)
if err != nil {
return nil, errors.Wrap(err, "error creating http proxy backend")
@ -197,7 +197,7 @@ func (cmd *shareReservedCommand) proxyBackendMode(cfg *proxyBackend.Config) (end
return be, nil
}
func (cmd *shareReservedCommand) webBackendMode(cfg *webBackend.Config) (endpoints.BackendHandler, error) {
func (cmd *shareReservedCommand) webBackendMode(cfg *webBackend.Config) (endpoints.RequestHandler, error) {
be, err := webBackend.NewBackend(cfg)
if err != nil {
return nil, errors.Wrap(err, "error creating http web backend")

View File

@ -14,7 +14,7 @@ type shareModel struct {
frontendDescriptions []string
shareMode string
backendMode string
requests []*endpoints.BackendRequest
requests []*endpoints.Request
logMessages []string
width int
height int
@ -33,8 +33,8 @@ func (m *shareModel) Init() tea.Cmd { return nil }
func (m *shareModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
switch msg := msg.(type) {
case *endpoints.BackendRequest:
m.requests = append([]*endpoints.BackendRequest{msg}, m.requests...)
case *endpoints.Request:
m.requests = append([]*endpoints.Request{msg}, m.requests...)
if len(m.requests) > 2048 {
m.requests = m.requests[:2048]
}

View File

@ -6,7 +6,7 @@ type Config struct {
IdentityName string
ShrToken string
Address string
RequestsChan chan *endpoints.BackendRequest
RequestsChan chan *endpoints.Request
}
func DefaultConfig(identityName string) *Config {

View File

@ -77,7 +77,7 @@ func newServiceProxy(cfg *Config, ctx ziti.Context) (*httputil.ReverseProxy, err
director := proxy.Director
proxy.Director = func(req *http.Request) {
if cfg.RequestsChan != nil {
cfg.RequestsChan <- &endpoints.BackendRequest{
cfg.RequestsChan <- &endpoints.Request{
Stamp: time.Now(),
RemoteAddr: fmt.Sprintf("%v", req.Header["X-Real-Ip"]),
Method: req.Method,

View File

@ -21,7 +21,7 @@ type Config struct {
IdentityPath string
EndpointAddress string
ShrToken string
RequestsChan chan *endpoints.BackendRequest
RequestsChan chan *endpoints.Request
}
type backend struct {
@ -70,7 +70,7 @@ func (self *backend) Requests() func() int32 {
return self.requests
}
func newReverseProxy(target string, requests chan *endpoints.BackendRequest) (*httputil.ReverseProxy, error) {
func newReverseProxy(target string, requests chan *endpoints.Request) (*httputil.ReverseProxy, error) {
targetURL, err := url.Parse(target)
if err != nil {
return nil, err
@ -84,7 +84,7 @@ func newReverseProxy(target string, requests chan *endpoints.BackendRequest) (*h
director := proxy.Director
proxy.Director = func(req *http.Request) {
if requests != nil {
requests <- &endpoints.BackendRequest{
requests <- &endpoints.Request{
Stamp: time.Now(),
RemoteAddr: fmt.Sprintf("%v", req.Header["X-Real-Ip"]),
Method: req.Method,

14
endpoints/requests.go Normal file
View File

@ -0,0 +1,14 @@
package endpoints
import "time"
type RequestHandler interface {
Requests() func() int32
}
type Request struct {
Stamp time.Time
RemoteAddr string
Method string
Path string
}

View File

@ -6,20 +6,8 @@ import (
"github.com/sirupsen/logrus"
"net/url"
"strings"
"time"
)
type BackendHandler interface {
Requests() func() int32
}
type BackendRequest struct {
Stamp time.Time
RemoteAddr string
Method string
Path string
}
func GetRefreshedService(name string, ctx ziti.Context) (*edge.Service, bool) {
svc, found := ctx.GetService(name)
if !found {

View File

@ -15,7 +15,7 @@ type Config struct {
IdentityPath string
WebRoot string
ShrToken string
RequestsChan chan *endpoints.BackendRequest
RequestsChan chan *endpoints.Request
}
type backend struct {
@ -62,13 +62,13 @@ func (self *backend) Requests() func() int32 {
}
type requestGrabber struct {
requests chan *endpoints.BackendRequest
requests chan *endpoints.Request
handler http.Handler
}
func (rl *requestGrabber) ServeHTTP(resp http.ResponseWriter, req *http.Request) {
if rl.requests != nil {
rl.requests <- &endpoints.BackendRequest{
rl.requests <- &endpoints.Request{
Stamp: time.Now(),
RemoteAddr: fmt.Sprintf("%v", req.Header["X-Real-Ip"]),
Method: req.Method,