headless mode for public sharing (#56)

This commit is contained in:
Michael Quigley 2023-01-10 15:11:39 -05:00
parent 0119e54d43
commit ad3ecab2ac
No known key found for this signature in database
GPG Key ID: 9B60314A9DD20A62
2 changed files with 38 additions and 31 deletions

View File

@ -11,7 +11,7 @@ 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
@ -23,7 +23,7 @@ type shareModel struct {
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())

View File

@ -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,12 +179,16 @@ 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) for {
// logrus.Infof("requests: %d", bh.Requests()()) select {
//} case req := <-requestsChan:
logrus.Infof("%v -> %v %v", req.RemoteAddr, req.Method, req.Path)
}
}
} else {
mdl := newShareModel(resp.Payload.ShrToken, resp.Payload.FrontendProxyEndpoints, "public", cmd.backendMode) mdl := newShareModel(resp.Payload.ShrToken, resp.Payload.FrontendProxyEndpoints, "public", cmd.backendMode)
prg := tea.NewProgram(mdl, tea.WithAltScreen()) prg := tea.NewProgram(mdl, tea.WithAltScreen())
@ -201,6 +207,7 @@ func (cmd *sharePublicCommand) run(_ *cobra.Command, args []string) {
close(requestsChan) close(requestsChan)
cmd.destroy(zrd.Env.ZId, resp.Payload.ShrToken, zrok, auth) 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) {