mirror of
https://github.com/openziti/zrok.git
synced 2024-11-22 08:03:49 +01:00
reorg, streamlining
This commit is contained in:
parent
163cc9b49c
commit
7868ce8527
@ -86,7 +86,7 @@ func (cmd *accessPrivateCommand) run(_ *cobra.Command, args []string) {
|
|||||||
cfg := privateFrontend.DefaultConfig("backend")
|
cfg := privateFrontend.DefaultConfig("backend")
|
||||||
cfg.ShrToken = shrToken
|
cfg.ShrToken = shrToken
|
||||||
cfg.Address = cmd.bindAddress
|
cfg.Address = cmd.bindAddress
|
||||||
cfg.RequestsChan = make(chan *endpoints.BackendRequest, 1024)
|
cfg.RequestsChan = make(chan *endpoints.Request, 1024)
|
||||||
|
|
||||||
c := make(chan os.Signal)
|
c := make(chan os.Signal)
|
||||||
signal.Notify(c, os.Interrupt, syscall.SIGTERM)
|
signal.Notify(c, os.Interrupt, syscall.SIGTERM)
|
||||||
|
@ -12,7 +12,7 @@ import (
|
|||||||
type accessModel struct {
|
type accessModel struct {
|
||||||
shrToken string
|
shrToken string
|
||||||
localEndpoint string
|
localEndpoint string
|
||||||
requests []*endpoints.BackendRequest
|
requests []*endpoints.Request
|
||||||
width int
|
width int
|
||||||
height 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) {
|
func (m *accessModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||||
switch msg := msg.(type) {
|
switch msg := msg.(type) {
|
||||||
case *endpoints.BackendRequest:
|
case *endpoints.Request:
|
||||||
m.requests = append([]*endpoints.BackendRequest{msg}, m.requests...)
|
m.requests = append([]*endpoints.Request{msg}, m.requests...)
|
||||||
if len(m.requests) > 2048 {
|
if len(m.requests) > 2048 {
|
||||||
m.requests = m.requests[:2048]
|
m.requests = m.requests[:2048]
|
||||||
}
|
}
|
||||||
|
@ -138,7 +138,7 @@ func (cmd *sharePrivateCommand) run(_ *cobra.Command, args []string) {
|
|||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
requestsChan := make(chan *endpoints.BackendRequest, 1024)
|
requestsChan := make(chan *endpoints.Request, 1024)
|
||||||
switch cmd.backendMode {
|
switch cmd.backendMode {
|
||||||
case "proxy":
|
case "proxy":
|
||||||
cfg := &proxyBackend.Config{
|
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)
|
be, err := proxyBackend.NewBackend(cfg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrap(err, "error creating http proxy backend")
|
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
|
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)
|
be, err := webBackend.NewBackend(cfg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrap(err, "error creating http web backend")
|
return nil, errors.Wrap(err, "error creating http web backend")
|
||||||
|
@ -141,7 +141,7 @@ func (cmd *sharePublicCommand) run(_ *cobra.Command, args []string) {
|
|||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
requestsChan := make(chan *endpoints.BackendRequest, 1024)
|
requestsChan := make(chan *endpoints.Request, 1024)
|
||||||
switch cmd.backendMode {
|
switch cmd.backendMode {
|
||||||
case "proxy":
|
case "proxy":
|
||||||
cfg := &proxyBackend.Config{
|
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)
|
be, err := proxyBackend.NewBackend(cfg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrap(err, "error creating http proxy backend")
|
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
|
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)
|
be, err := webBackend.NewBackend(cfg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrap(err, "error creating http web backend")
|
return nil, errors.Wrap(err, "error creating http web backend")
|
||||||
|
@ -103,7 +103,7 @@ func (cmd *shareReservedCommand) run(_ *cobra.Command, args []string) {
|
|||||||
logrus.Infof("using existing backend proxy endpoint: %v", target)
|
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 {
|
switch resp.Payload.BackendMode {
|
||||||
case "proxy":
|
case "proxy":
|
||||||
cfg := &proxyBackend.Config{
|
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)
|
be, err := proxyBackend.NewBackend(cfg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrap(err, "error creating http proxy backend")
|
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
|
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)
|
be, err := webBackend.NewBackend(cfg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrap(err, "error creating http web backend")
|
return nil, errors.Wrap(err, "error creating http web backend")
|
||||||
|
@ -14,7 +14,7 @@ type shareModel struct {
|
|||||||
frontendDescriptions []string
|
frontendDescriptions []string
|
||||||
shareMode string
|
shareMode string
|
||||||
backendMode string
|
backendMode string
|
||||||
requests []*endpoints.BackendRequest
|
requests []*endpoints.Request
|
||||||
logMessages []string
|
logMessages []string
|
||||||
width int
|
width int
|
||||||
height 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) {
|
func (m *shareModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||||
switch msg := msg.(type) {
|
switch msg := msg.(type) {
|
||||||
case *endpoints.BackendRequest:
|
case *endpoints.Request:
|
||||||
m.requests = append([]*endpoints.BackendRequest{msg}, m.requests...)
|
m.requests = append([]*endpoints.Request{msg}, m.requests...)
|
||||||
if len(m.requests) > 2048 {
|
if len(m.requests) > 2048 {
|
||||||
m.requests = m.requests[:2048]
|
m.requests = m.requests[:2048]
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@ type Config struct {
|
|||||||
IdentityName string
|
IdentityName string
|
||||||
ShrToken string
|
ShrToken string
|
||||||
Address string
|
Address string
|
||||||
RequestsChan chan *endpoints.BackendRequest
|
RequestsChan chan *endpoints.Request
|
||||||
}
|
}
|
||||||
|
|
||||||
func DefaultConfig(identityName string) *Config {
|
func DefaultConfig(identityName string) *Config {
|
||||||
|
@ -77,7 +77,7 @@ func newServiceProxy(cfg *Config, ctx ziti.Context) (*httputil.ReverseProxy, err
|
|||||||
director := proxy.Director
|
director := proxy.Director
|
||||||
proxy.Director = func(req *http.Request) {
|
proxy.Director = func(req *http.Request) {
|
||||||
if cfg.RequestsChan != nil {
|
if cfg.RequestsChan != nil {
|
||||||
cfg.RequestsChan <- &endpoints.BackendRequest{
|
cfg.RequestsChan <- &endpoints.Request{
|
||||||
Stamp: time.Now(),
|
Stamp: time.Now(),
|
||||||
RemoteAddr: fmt.Sprintf("%v", req.Header["X-Real-Ip"]),
|
RemoteAddr: fmt.Sprintf("%v", req.Header["X-Real-Ip"]),
|
||||||
Method: req.Method,
|
Method: req.Method,
|
||||||
|
@ -21,7 +21,7 @@ type Config struct {
|
|||||||
IdentityPath string
|
IdentityPath string
|
||||||
EndpointAddress string
|
EndpointAddress string
|
||||||
ShrToken string
|
ShrToken string
|
||||||
RequestsChan chan *endpoints.BackendRequest
|
RequestsChan chan *endpoints.Request
|
||||||
}
|
}
|
||||||
|
|
||||||
type backend struct {
|
type backend struct {
|
||||||
@ -70,7 +70,7 @@ func (self *backend) Requests() func() int32 {
|
|||||||
return self.requests
|
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)
|
targetURL, err := url.Parse(target)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -84,7 +84,7 @@ func newReverseProxy(target string, requests chan *endpoints.BackendRequest) (*h
|
|||||||
director := proxy.Director
|
director := proxy.Director
|
||||||
proxy.Director = func(req *http.Request) {
|
proxy.Director = func(req *http.Request) {
|
||||||
if requests != nil {
|
if requests != nil {
|
||||||
requests <- &endpoints.BackendRequest{
|
requests <- &endpoints.Request{
|
||||||
Stamp: time.Now(),
|
Stamp: time.Now(),
|
||||||
RemoteAddr: fmt.Sprintf("%v", req.Header["X-Real-Ip"]),
|
RemoteAddr: fmt.Sprintf("%v", req.Header["X-Real-Ip"]),
|
||||||
Method: req.Method,
|
Method: req.Method,
|
||||||
|
14
endpoints/requests.go
Normal file
14
endpoints/requests.go
Normal 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
|
||||||
|
}
|
@ -6,20 +6,8 @@ import (
|
|||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
"net/url"
|
"net/url"
|
||||||
"strings"
|
"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) {
|
func GetRefreshedService(name string, ctx ziti.Context) (*edge.Service, bool) {
|
||||||
svc, found := ctx.GetService(name)
|
svc, found := ctx.GetService(name)
|
||||||
if !found {
|
if !found {
|
||||||
|
@ -15,7 +15,7 @@ type Config struct {
|
|||||||
IdentityPath string
|
IdentityPath string
|
||||||
WebRoot string
|
WebRoot string
|
||||||
ShrToken string
|
ShrToken string
|
||||||
RequestsChan chan *endpoints.BackendRequest
|
RequestsChan chan *endpoints.Request
|
||||||
}
|
}
|
||||||
|
|
||||||
type backend struct {
|
type backend struct {
|
||||||
@ -62,13 +62,13 @@ func (self *backend) Requests() func() int32 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type requestGrabber struct {
|
type requestGrabber struct {
|
||||||
requests chan *endpoints.BackendRequest
|
requests chan *endpoints.Request
|
||||||
handler http.Handler
|
handler http.Handler
|
||||||
}
|
}
|
||||||
|
|
||||||
func (rl *requestGrabber) ServeHTTP(resp http.ResponseWriter, req *http.Request) {
|
func (rl *requestGrabber) ServeHTTP(resp http.ResponseWriter, req *http.Request) {
|
||||||
if rl.requests != nil {
|
if rl.requests != nil {
|
||||||
rl.requests <- &endpoints.BackendRequest{
|
rl.requests <- &endpoints.Request{
|
||||||
Stamp: time.Now(),
|
Stamp: time.Now(),
|
||||||
RemoteAddr: fmt.Sprintf("%v", req.Header["X-Real-Ip"]),
|
RemoteAddr: fmt.Sprintf("%v", req.Header["X-Real-Ip"]),
|
||||||
Method: req.Method,
|
Method: req.Method,
|
||||||
|
Loading…
Reference in New Issue
Block a user