mirror of
https://github.com/openziti/zrok.git
synced 2024-11-25 17:43:53 +01:00
headless mode for public sharing (#56)
This commit is contained in:
parent
0119e54d43
commit
ad3ecab2ac
@ -10,22 +10,22 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type shareModel struct {
|
type shareModel struct {
|
||||||
shareToken string
|
shareToken string
|
||||||
frontendEndpoints []string
|
frontendDescriptions []string
|
||||||
shareMode string
|
shareMode string
|
||||||
backendMode string
|
backendMode string
|
||||||
requests []*endpoints.BackendRequest
|
requests []*endpoints.BackendRequest
|
||||||
logMessages []string
|
logMessages []string
|
||||||
width int
|
width int
|
||||||
height int
|
height int
|
||||||
}
|
}
|
||||||
|
|
||||||
func newShareModel(shareToken string, frontendEndpoints []string, shareMode, backendMode string) *shareModel {
|
func newShareModel(shareToken string, frontendEndpoints []string, shareMode, backendMode string) *shareModel {
|
||||||
return &shareModel{
|
return &shareModel{
|
||||||
shareToken: shareToken,
|
shareToken: shareToken,
|
||||||
frontendEndpoints: frontendEndpoints,
|
frontendDescriptions: frontendEndpoints,
|
||||||
shareMode: shareMode,
|
shareMode: shareMode,
|
||||||
backendMode: backendMode,
|
backendMode: backendMode,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -45,7 +45,7 @@ func (m *shareModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|||||||
configHeaderStyle.Width(26)
|
configHeaderStyle.Width(26)
|
||||||
m.height = msg.Height
|
m.height = msg.Height
|
||||||
requestsStyle.Width(m.width - 2)
|
requestsStyle.Width(m.width - 2)
|
||||||
requestsStyle.Height(m.height - (len(m.frontendEndpoints) + 6))
|
requestsStyle.Height(m.height - (len(m.frontendDescriptions) + 6))
|
||||||
|
|
||||||
case tea.KeyMsg:
|
case tea.KeyMsg:
|
||||||
switch msg.String() {
|
switch msg.String() {
|
||||||
@ -61,7 +61,7 @@ func (m *shareModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|||||||
|
|
||||||
func (m *shareModel) View() string {
|
func (m *shareModel) View() string {
|
||||||
topRow := lipgloss.JoinHorizontal(lipgloss.Top,
|
topRow := lipgloss.JoinHorizontal(lipgloss.Top,
|
||||||
shareHeaderStyle.Render(strings.Join(m.frontendEndpoints, "\n")),
|
shareHeaderStyle.Render(strings.Join(m.frontendDescriptions, "\n")),
|
||||||
configHeaderStyle.Render(m.renderConfig()),
|
configHeaderStyle.Render(m.renderConfig()),
|
||||||
)
|
)
|
||||||
requests := requestsStyle.Render(m.renderBackendRequests())
|
requests := requestsStyle.Render(m.renderBackendRequests())
|
||||||
|
@ -32,6 +32,7 @@ type sharePublicCommand struct {
|
|||||||
basicAuth []string
|
basicAuth []string
|
||||||
frontendSelection []string
|
frontendSelection []string
|
||||||
backendMode string
|
backendMode string
|
||||||
|
headless bool
|
||||||
cmd *cobra.Command
|
cmd *cobra.Command
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -45,6 +46,7 @@ func newSharePublicCommand() *sharePublicCommand {
|
|||||||
cmd.Flags().StringArrayVar(&command.basicAuth, "basic-auth", []string{}, "Basic authentication users (<username:password>,...)")
|
cmd.Flags().StringArrayVar(&command.basicAuth, "basic-auth", []string{}, "Basic authentication users (<username:password>,...)")
|
||||||
cmd.Flags().StringArrayVar(&command.frontendSelection, "frontends", []string{"public"}, "Selected frontends to use for the share")
|
cmd.Flags().StringArrayVar(&command.frontendSelection, "frontends", []string{"public"}, "Selected frontends to use for the share")
|
||||||
cmd.Flags().StringVar(&command.backendMode, "backend-mode", "proxy", "The backend mode {proxy, web}")
|
cmd.Flags().StringVar(&command.backendMode, "backend-mode", "proxy", "The backend mode {proxy, web}")
|
||||||
|
cmd.Flags().BoolVar(&command.headless, "headless", false, "Disable TUI and run headless")
|
||||||
cmd.Run = command.run
|
cmd.Run = command.run
|
||||||
return command
|
return command
|
||||||
}
|
}
|
||||||
@ -177,30 +179,35 @@ func (cmd *sharePublicCommand) run(_ *cobra.Command, args []string) {
|
|||||||
|
|
||||||
_ = bh.Requests()()
|
_ = bh.Requests()()
|
||||||
|
|
||||||
//logrus.Infof("access your zrok share: %v", resp.Payload.FrontendProxyEndpoints[0])
|
if cmd.headless {
|
||||||
//for {
|
logrus.Infof("access your zrok share at the following endpoints:\n %v", strings.Join(resp.Payload.FrontendProxyEndpoints, "\n"))
|
||||||
// time.Sleep(5 * time.Second)
|
|
||||||
// logrus.Infof("requests: %d", bh.Requests()())
|
|
||||||
//}
|
|
||||||
|
|
||||||
mdl := newShareModel(resp.Payload.ShrToken, resp.Payload.FrontendProxyEndpoints, "public", cmd.backendMode)
|
|
||||||
prg := tea.NewProgram(mdl, tea.WithAltScreen())
|
|
||||||
|
|
||||||
go func() {
|
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case req := <-requestsChan:
|
case req := <-requestsChan:
|
||||||
prg.Send(req)
|
logrus.Infof("%v -> %v %v", req.RemoteAddr, req.Method, req.Path)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}()
|
|
||||||
|
|
||||||
if _, err := prg.Run(); err != nil {
|
} else {
|
||||||
tui.Error("An error occurred", err)
|
mdl := newShareModel(resp.Payload.ShrToken, resp.Payload.FrontendProxyEndpoints, "public", cmd.backendMode)
|
||||||
|
prg := tea.NewProgram(mdl, tea.WithAltScreen())
|
||||||
|
|
||||||
|
go func() {
|
||||||
|
for {
|
||||||
|
select {
|
||||||
|
case req := <-requestsChan:
|
||||||
|
prg.Send(req)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
if _, err := prg.Run(); err != nil {
|
||||||
|
tui.Error("An error occurred", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
close(requestsChan)
|
||||||
|
cmd.destroy(zrd.Env.ZId, resp.Payload.ShrToken, zrok, auth)
|
||||||
}
|
}
|
||||||
|
|
||||||
close(requestsChan)
|
|
||||||
cmd.destroy(zrd.Env.ZId, resp.Payload.ShrToken, zrok, auth)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cmd *sharePublicCommand) proxyBackendMode(cfg *proxyBackend.Config) (endpoints.BackendHandler, error) {
|
func (cmd *sharePublicCommand) proxyBackendMode(cfg *proxyBackend.Config) (endpoints.BackendHandler, error) {
|
||||||
|
Loading…
Reference in New Issue
Block a user