mirror of
https://github.com/openziti/zrok.git
synced 2024-12-22 23:02:52 +01:00
listen/bind -> frontend/backend (#37)
This commit is contained in:
parent
c8f48a8fe0
commit
d1e63fd8e6
@ -7,7 +7,7 @@ import (
|
||||
"github.com/go-openapi/runtime"
|
||||
httptransport "github.com/go-openapi/runtime/client"
|
||||
tb "github.com/nsf/termbox-go"
|
||||
"github.com/openziti-test-kitchen/zrok/endpoints/bind"
|
||||
"github.com/openziti-test-kitchen/zrok/endpoints/backend"
|
||||
"github.com/openziti-test-kitchen/zrok/model"
|
||||
"github.com/openziti-test-kitchen/zrok/rest_client_zrok"
|
||||
"github.com/openziti-test-kitchen/zrok/rest_client_zrok/tunnel"
|
||||
@ -24,30 +24,31 @@ import (
|
||||
)
|
||||
|
||||
func init() {
|
||||
httpCmd.AddCommand(newHttpBindCommand().cmd)
|
||||
httpCmd.AddCommand(newHttpBackendCommand().cmd)
|
||||
}
|
||||
|
||||
type httpBindCommand struct {
|
||||
service bool
|
||||
type httpBackendCommand struct {
|
||||
quiet bool
|
||||
basicAuth []string
|
||||
cmd *cobra.Command
|
||||
}
|
||||
|
||||
func newHttpBindCommand() *httpBindCommand {
|
||||
func newHttpBackendCommand() *httpBackendCommand {
|
||||
cmd := &cobra.Command{
|
||||
Use: "bind <endpoint>",
|
||||
Short: "Create an HTTP binding",
|
||||
Args: cobra.ExactArgs(1),
|
||||
Use: "backend <targetEndpoint>",
|
||||
Aliases: []string{"be"},
|
||||
Short: "Create an HTTP binding",
|
||||
Args: cobra.ExactArgs(1),
|
||||
}
|
||||
command := &httpBindCommand{cmd: cmd}
|
||||
cmd.Flags().BoolVarP(&command.service, "service", "s", false, "Disable TUI 'chrome' for service operation")
|
||||
command := &httpBackendCommand{cmd: cmd}
|
||||
cmd.Flags().BoolVarP(&command.quiet, "quiet", "q", false, "Disable TUI 'chrome' for quiet operation")
|
||||
cmd.Flags().StringArrayVar(&command.basicAuth, "basic-auth", []string{}, "Basic authentication users (<username:password>,...")
|
||||
cmd.Run = command.run
|
||||
return command
|
||||
}
|
||||
|
||||
func (self *httpBindCommand) run(_ *cobra.Command, args []string) {
|
||||
if !self.service {
|
||||
func (self *httpBackendCommand) run(_ *cobra.Command, args []string) {
|
||||
if !self.quiet {
|
||||
if err := ui.Init(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
@ -63,7 +64,7 @@ func (self *httpBindCommand) run(_ *cobra.Command, args []string) {
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
cfg := &bind.Config{
|
||||
cfg := &backend.Config{
|
||||
IdentityPath: zif,
|
||||
EndpointAddress: args[0],
|
||||
}
|
||||
@ -102,7 +103,7 @@ func (self *httpBindCommand) run(_ *cobra.Command, args []string) {
|
||||
os.Exit(0)
|
||||
}()
|
||||
|
||||
httpProxy, err := bind.NewHTTP(cfg)
|
||||
httpProxy, err := backend.NewHTTP(cfg)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
@ -113,13 +114,13 @@ func (self *httpBindCommand) run(_ *cobra.Command, args []string) {
|
||||
}
|
||||
}()
|
||||
|
||||
if !self.service {
|
||||
if !self.quiet {
|
||||
ui.Clear()
|
||||
w, h := ui.TerminalDimensions()
|
||||
|
||||
p := widgets.NewParagraph()
|
||||
p.Border = true
|
||||
p.Title = " access your zrok service "
|
||||
p.Title = " access your zrok quiet "
|
||||
p.Text = fmt.Sprintf("%v%v", strings.Repeat(" ", (((w-12)-len(resp.Payload.ProxyEndpoint))/2)-1), resp.Payload.ProxyEndpoint)
|
||||
p.TextStyle = ui.Style{Fg: ui.ColorWhite}
|
||||
p.PaddingTop = 1
|
||||
@ -175,13 +176,13 @@ func (self *httpBindCommand) run(_ *cobra.Command, args []string) {
|
||||
}
|
||||
} else {
|
||||
for {
|
||||
logrus.Infof("access your zrok service: %v", resp.Payload.ProxyEndpoint)
|
||||
logrus.Infof("access your zrok quiet: %v", resp.Payload.ProxyEndpoint)
|
||||
time.Sleep(30 * time.Second)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (self *httpBindCommand) destroy(id string, cfg *bind.Config, zrok *rest_client_zrok.Zrok, auth runtime.ClientAuthInfoWriter) {
|
||||
func (self *httpBackendCommand) destroy(id string, cfg *backend.Config, zrok *rest_client_zrok.Zrok, auth runtime.ClientAuthInfoWriter) {
|
||||
logrus.Infof("shutting down '%v'", cfg.Service)
|
||||
req := tunnel.NewUntunnelParams()
|
||||
req.Body = &rest_model_zrok.UntunnelRequest{
|
41
cmd/zrok/http_frontend.go
Normal file
41
cmd/zrok/http_frontend.go
Normal file
@ -0,0 +1,41 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/openziti-test-kitchen/zrok/endpoints/frontend"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
func init() {
|
||||
httpCmd.AddCommand(newHttpFrontendCommand().cmd)
|
||||
}
|
||||
|
||||
type httpFrontendCommand struct {
|
||||
endpoint string
|
||||
cmd *cobra.Command
|
||||
}
|
||||
|
||||
func newHttpFrontendCommand() *httpFrontendCommand {
|
||||
cmd := &cobra.Command{
|
||||
Use: "frontend <zitiIdentity>",
|
||||
Aliases: []string{"fe"},
|
||||
Short: "Create an HTTP frontend",
|
||||
Args: cobra.ExactArgs(1),
|
||||
}
|
||||
command := &httpFrontendCommand{cmd: cmd}
|
||||
cmd.Flags().StringVarP(&command.endpoint, "endpoint", "e", "0.0.0.0:10180", "Bind address for HTTP frontend")
|
||||
cmd.Run = command.run
|
||||
return command
|
||||
}
|
||||
|
||||
func (self *httpFrontendCommand) run(_ *cobra.Command, args []string) {
|
||||
httpListener, err := frontend.NewHTTP(&frontend.Config{
|
||||
IdentityPath: args[0],
|
||||
Address: self.endpoint,
|
||||
})
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
if err := httpListener.Run(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
@ -1,40 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/openziti-test-kitchen/zrok/endpoints/listen"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
func init() {
|
||||
httpCmd.AddCommand(newHttpListenCommand().cmd)
|
||||
}
|
||||
|
||||
type httpListenCommand struct {
|
||||
endpoint string
|
||||
cmd *cobra.Command
|
||||
}
|
||||
|
||||
func newHttpListenCommand() *httpListenCommand {
|
||||
cmd := &cobra.Command{
|
||||
Use: "listen <zitiIdentity>",
|
||||
Short: "Create an HTTP listener",
|
||||
Args: cobra.ExactArgs(1),
|
||||
}
|
||||
command := &httpListenCommand{cmd: cmd}
|
||||
cmd.Flags().StringVarP(&command.endpoint, "endpoint", "e", "0.0.0.0:10111", "Address for HTTP listening endpoint")
|
||||
cmd.Run = command.run
|
||||
return command
|
||||
}
|
||||
|
||||
func (self *httpListenCommand) run(_ *cobra.Command, args []string) {
|
||||
httpListener, err := listen.NewHTTP(&listen.Config{
|
||||
IdentityPath: args[0],
|
||||
Address: self.endpoint,
|
||||
})
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
if err := httpListener.Run(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
@ -168,7 +168,7 @@ func (self *tunnelHandler) createService(name, cfgId string, edge *rest_manageme
|
||||
func (self *tunnelHandler) createServicePolicyBind(svcName, svcId, envId string, edge *rest_management_api_client.ZitiEdgeManagement) error {
|
||||
semantic := rest_model.SemanticAllOf
|
||||
identityRoles := []string{fmt.Sprintf("@%v", envId)}
|
||||
name := fmt.Sprintf("%v-bind", svcName)
|
||||
name := fmt.Sprintf("%v-backend", svcName)
|
||||
postureCheckRoles := []string{}
|
||||
serviceRoles := []string{fmt.Sprintf("@%v", svcId)}
|
||||
dialBind := rest_model.DialBindBind
|
||||
|
@ -173,7 +173,7 @@ func (_ *untunnelHandler) deleteServiceEdgeRouterPolicy(svcName string, edge *re
|
||||
}
|
||||
|
||||
func (self *untunnelHandler) deleteServicePolicyBind(svcName string, edge *rest_management_api_client.ZitiEdgeManagement) error {
|
||||
return self.deleteServicePolicy(fmt.Sprintf("name=\"%v-bind\"", svcName), edge)
|
||||
return self.deleteServicePolicy(fmt.Sprintf("name=\"%v-backend\"", svcName), edge)
|
||||
}
|
||||
|
||||
func (self *untunnelHandler) deleteServicePolicyDial(svcName string, edge *rest_management_api_client.ZitiEdgeManagement) error {
|
||||
|
@ -152,19 +152,19 @@ edge:
|
||||
|
||||
# web
|
||||
# Defines webListeners that will be hosted by the controller. Each webListener can host many APIs and be bound to many
|
||||
# bind points.
|
||||
# backend points.
|
||||
web:
|
||||
# name - required
|
||||
# Provides a name for this listener, used for logging output. Not required to be unique, but is highly suggested.
|
||||
- name: client-management
|
||||
# bindPoints - required
|
||||
# One or more bind points are required. A bind point specifies an interface (interface:port string) that defines
|
||||
# where on the host machine the webListener will listen and the address (host:port) that should be used to
|
||||
# One or more backend points are required. A backend point specifies an interface (interface:port string) that defines
|
||||
# where on the host machine the webListener will frontend and the address (host:port) that should be used to
|
||||
# publicly address the webListener(i.e. mydomain.com, localhost, 127.0.0.1). This public address may be used for
|
||||
# incoming address resolution as well as used in responses in the API.
|
||||
bindPoints:
|
||||
#interface - required
|
||||
# A host:port string on which network interface to listen on. 0.0.0.0 will listen on all interfaces
|
||||
# A host:port string on which network interface to frontend on. 0.0.0.0 will frontend on all interfaces
|
||||
- interface: 0.0.0.0:1280
|
||||
# address - required
|
||||
# The public address that external incoming requests will be able to resolve. Used in request processing and
|
||||
@ -206,7 +206,7 @@ web:
|
||||
# Allows one or more APIs to be bound to this webListener
|
||||
apis:
|
||||
# binding - required
|
||||
# Specifies an API to bind to this webListener. Built-in APIs are
|
||||
# Specifies an API to backend to this webListener. Built-in APIs are
|
||||
# - edge-management
|
||||
# - edge-client
|
||||
# - fabric-management
|
||||
|
@ -1,4 +1,4 @@
|
||||
package bind
|
||||
package backend
|
||||
|
||||
import (
|
||||
"github.com/openziti-test-kitchen/zrok/util"
|
@ -1,4 +1,4 @@
|
||||
package listen
|
||||
package frontend
|
||||
|
||||
import (
|
||||
"context"
|
@ -152,19 +152,19 @@ edge:
|
||||
|
||||
# web
|
||||
# Defines webListeners that will be hosted by the controller. Each webListener can host many APIs and be bound to many
|
||||
# bind points.
|
||||
# backend points.
|
||||
web:
|
||||
# name - required
|
||||
# Provides a name for this listener, used for logging output. Not required to be unique, but is highly suggested.
|
||||
- name: client-management
|
||||
# bindPoints - required
|
||||
# One or more bind points are required. A bind point specifies an interface (interface:port string) that defines
|
||||
# where on the host machine the webListener will listen and the address (host:port) that should be used to
|
||||
# One or more backend points are required. A backend point specifies an interface (interface:port string) that defines
|
||||
# where on the host machine the webListener will frontend and the address (host:port) that should be used to
|
||||
# publicly address the webListener(i.e. mydomain.com, localhost, 127.0.0.1). This public address may be used for
|
||||
# incoming address resolution as well as used in responses in the API.
|
||||
bindPoints:
|
||||
#interface - required
|
||||
# A host:port string on which network interface to listen on. 0.0.0.0 will listen on all interfaces
|
||||
# A host:port string on which network interface to frontend on. 0.0.0.0 will frontend on all interfaces
|
||||
- interface: 0.0.0.0:1280
|
||||
# address - required
|
||||
# The public address that external incoming requests will be able to resolve. Used in request processing and
|
||||
@ -206,7 +206,7 @@ web:
|
||||
# Allows one or more APIs to be bound to this webListener
|
||||
apis:
|
||||
# binding - required
|
||||
# Specifies an API to bind to this webListener. Built-in APIs are
|
||||
# Specifies an API to backend to this webListener. Built-in APIs are
|
||||
# - edge-management
|
||||
# - edge-client
|
||||
# - fabric-management
|
||||
|
@ -45,7 +45,7 @@ func (o *CreateAccount) ServeHTTP(rw http.ResponseWriter, r *http.Request) {
|
||||
*r = *rCtx
|
||||
}
|
||||
var Params = NewCreateAccountParams()
|
||||
if err := o.Context.BindValidRequest(r, route, &Params); err != nil { // bind params
|
||||
if err := o.Context.BindValidRequest(r, route, &Params); err != nil { // backend params
|
||||
o.Context.Respond(rw, r, route.Produces, route, err)
|
||||
return
|
||||
}
|
||||
|
@ -60,7 +60,7 @@ func (o *Enable) ServeHTTP(rw http.ResponseWriter, r *http.Request) {
|
||||
principal = uprinc.(*rest_model_zrok.Principal) // this is really a rest_model_zrok.Principal, I promise
|
||||
}
|
||||
|
||||
if err := o.Context.BindValidRequest(r, route, &Params); err != nil { // bind params
|
||||
if err := o.Context.BindValidRequest(r, route, &Params); err != nil { // backend params
|
||||
o.Context.Respond(rw, r, route.Produces, route, err)
|
||||
return
|
||||
}
|
||||
|
@ -45,7 +45,7 @@ func (o *Login) ServeHTTP(rw http.ResponseWriter, r *http.Request) {
|
||||
*r = *rCtx
|
||||
}
|
||||
var Params = NewLoginParams()
|
||||
if err := o.Context.BindValidRequest(r, route, &Params); err != nil { // bind params
|
||||
if err := o.Context.BindValidRequest(r, route, &Params); err != nil { // backend params
|
||||
o.Context.Respond(rw, r, route.Produces, route, err)
|
||||
return
|
||||
}
|
||||
|
@ -60,7 +60,7 @@ func (o *Overview) ServeHTTP(rw http.ResponseWriter, r *http.Request) {
|
||||
principal = uprinc.(*rest_model_zrok.Principal) // this is really a rest_model_zrok.Principal, I promise
|
||||
}
|
||||
|
||||
if err := o.Context.BindValidRequest(r, route, &Params); err != nil { // bind params
|
||||
if err := o.Context.BindValidRequest(r, route, &Params); err != nil { // backend params
|
||||
o.Context.Respond(rw, r, route.Produces, route, err)
|
||||
return
|
||||
}
|
||||
|
@ -45,7 +45,7 @@ func (o *Version) ServeHTTP(rw http.ResponseWriter, r *http.Request) {
|
||||
*r = *rCtx
|
||||
}
|
||||
var Params = NewVersionParams()
|
||||
if err := o.Context.BindValidRequest(r, route, &Params); err != nil { // bind params
|
||||
if err := o.Context.BindValidRequest(r, route, &Params); err != nil { // backend params
|
||||
o.Context.Respond(rw, r, route.Produces, route, err)
|
||||
return
|
||||
}
|
||||
|
@ -60,7 +60,7 @@ func (o *Tunnel) ServeHTTP(rw http.ResponseWriter, r *http.Request) {
|
||||
principal = uprinc.(*rest_model_zrok.Principal) // this is really a rest_model_zrok.Principal, I promise
|
||||
}
|
||||
|
||||
if err := o.Context.BindValidRequest(r, route, &Params); err != nil { // bind params
|
||||
if err := o.Context.BindValidRequest(r, route, &Params); err != nil { // backend params
|
||||
o.Context.Respond(rw, r, route.Produces, route, err)
|
||||
return
|
||||
}
|
||||
|
@ -60,7 +60,7 @@ func (o *Untunnel) ServeHTTP(rw http.ResponseWriter, r *http.Request) {
|
||||
principal = uprinc.(*rest_model_zrok.Principal) // this is really a rest_model_zrok.Principal, I promise
|
||||
}
|
||||
|
||||
if err := o.Context.BindValidRequest(r, route, &Params); err != nil { // bind params
|
||||
if err := o.Context.BindValidRequest(r, route, &Params); err != nil { // backend params
|
||||
o.Context.Respond(rw, r, route.Produces, route, err)
|
||||
return
|
||||
}
|
||||
|
@ -73,23 +73,23 @@ type Server struct {
|
||||
GracefulTimeout time.Duration `long:"graceful-timeout" description:"grace period for which to wait before shutting down the server" default:"15s"`
|
||||
MaxHeaderSize flagext.ByteSize `long:"max-header-size" description:"controls the maximum number of bytes the server will read parsing the request header's keys and values, including the request line. It does not limit the size of the request body." default:"1MiB"`
|
||||
|
||||
SocketPath flags.Filename `long:"socket-path" description:"the unix socket to listen on" default:"/var/run/zrok.sock"`
|
||||
SocketPath flags.Filename `long:"socket-path" description:"the unix socket to frontend on" default:"/var/run/zrok.sock"`
|
||||
domainSocketL net.Listener
|
||||
|
||||
Host string `long:"host" description:"the IP to listen on" default:"localhost" env:"HOST"`
|
||||
Port int `long:"port" description:"the port to listen on for insecure connections, defaults to a random value" env:"PORT"`
|
||||
ListenLimit int `long:"listen-limit" description:"limit the number of outstanding requests"`
|
||||
Host string `long:"host" description:"the IP to frontend on" default:"localhost" env:"HOST"`
|
||||
Port int `long:"port" description:"the port to frontend on for insecure connections, defaults to a random value" env:"PORT"`
|
||||
ListenLimit int `long:"frontend-limit" description:"limit the number of outstanding requests"`
|
||||
KeepAlive time.Duration `long:"keep-alive" description:"sets the TCP keep-alive timeouts on accepted connections. It prunes dead TCP connections ( e.g. closing laptop mid-download)" default:"3m"`
|
||||
ReadTimeout time.Duration `long:"read-timeout" description:"maximum duration before timing out read of the request" default:"30s"`
|
||||
WriteTimeout time.Duration `long:"write-timeout" description:"maximum duration before timing out write of the response" default:"60s"`
|
||||
httpServerL net.Listener
|
||||
|
||||
TLSHost string `long:"tls-host" description:"the IP to listen on for tls, when not specified it's the same as --host" env:"TLS_HOST"`
|
||||
TLSPort int `long:"tls-port" description:"the port to listen on for secure connections, defaults to a random value" env:"TLS_PORT"`
|
||||
TLSHost string `long:"tls-host" description:"the IP to frontend on for tls, when not specified it's the same as --host" env:"TLS_HOST"`
|
||||
TLSPort int `long:"tls-port" description:"the port to frontend on for secure connections, defaults to a random value" env:"TLS_PORT"`
|
||||
TLSCertificate flags.Filename `long:"tls-certificate" description:"the certificate to use for secure connections" env:"TLS_CERTIFICATE"`
|
||||
TLSCertificateKey flags.Filename `long:"tls-key" description:"the private key to use for secure connections" env:"TLS_PRIVATE_KEY"`
|
||||
TLSCACertificate flags.Filename `long:"tls-ca" description:"the certificate authority file to be used with mutual tls auth" env:"TLS_CA_CERTIFICATE"`
|
||||
TLSListenLimit int `long:"tls-listen-limit" description:"limit the number of outstanding requests"`
|
||||
TLSListenLimit int `long:"tls-frontend-limit" description:"limit the number of outstanding requests"`
|
||||
TLSKeepAlive time.Duration `long:"tls-keep-alive" description:"sets the TCP keep-alive timeouts on accepted connections. It prunes dead TCP connections ( e.g. closing laptop mid-download)"`
|
||||
TLSReadTimeout time.Duration `long:"tls-read-timeout" description:"maximum duration before timing out read of the request"`
|
||||
TLSWriteTimeout time.Duration `long:"tls-write-timeout" description:"maximum duration before timing out write of the response"`
|
||||
@ -337,7 +337,7 @@ func (s *Server) Listen() error {
|
||||
if s.TLSHost == "" {
|
||||
s.TLSHost = s.Host
|
||||
}
|
||||
// Use http listen limit if https listen limit wasn't defined
|
||||
// Use http frontend limit if https frontend limit wasn't defined
|
||||
if s.TLSListenLimit == 0 {
|
||||
s.TLSListenLimit = s.ListenLimit
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user