mirror of
https://github.com/openziti/zrok.git
synced 2024-11-29 03:24:15 +01:00
headless mode for public sharing (#56)
This commit is contained in:
parent
0119e54d43
commit
ad3ecab2ac
@ -11,7 +11,7 @@ import (
|
||||
|
||||
type shareModel struct {
|
||||
shareToken string
|
||||
frontendEndpoints []string
|
||||
frontendDescriptions []string
|
||||
shareMode string
|
||||
backendMode string
|
||||
requests []*endpoints.BackendRequest
|
||||
@ -23,7 +23,7 @@ type shareModel struct {
|
||||
func newShareModel(shareToken string, frontendEndpoints []string, shareMode, backendMode string) *shareModel {
|
||||
return &shareModel{
|
||||
shareToken: shareToken,
|
||||
frontendEndpoints: frontendEndpoints,
|
||||
frontendDescriptions: frontendEndpoints,
|
||||
shareMode: shareMode,
|
||||
backendMode: backendMode,
|
||||
}
|
||||
@ -45,7 +45,7 @@ func (m *shareModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
configHeaderStyle.Width(26)
|
||||
m.height = msg.Height
|
||||
requestsStyle.Width(m.width - 2)
|
||||
requestsStyle.Height(m.height - (len(m.frontendEndpoints) + 6))
|
||||
requestsStyle.Height(m.height - (len(m.frontendDescriptions) + 6))
|
||||
|
||||
case tea.KeyMsg:
|
||||
switch msg.String() {
|
||||
@ -61,7 +61,7 @@ func (m *shareModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
|
||||
func (m *shareModel) View() string {
|
||||
topRow := lipgloss.JoinHorizontal(lipgloss.Top,
|
||||
shareHeaderStyle.Render(strings.Join(m.frontendEndpoints, "\n")),
|
||||
shareHeaderStyle.Render(strings.Join(m.frontendDescriptions, "\n")),
|
||||
configHeaderStyle.Render(m.renderConfig()),
|
||||
)
|
||||
requests := requestsStyle.Render(m.renderBackendRequests())
|
||||
|
@ -32,6 +32,7 @@ type sharePublicCommand struct {
|
||||
basicAuth []string
|
||||
frontendSelection []string
|
||||
backendMode string
|
||||
headless bool
|
||||
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.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().BoolVar(&command.headless, "headless", false, "Disable TUI and run headless")
|
||||
cmd.Run = command.run
|
||||
return command
|
||||
}
|
||||
@ -177,12 +179,16 @@ func (cmd *sharePublicCommand) run(_ *cobra.Command, args []string) {
|
||||
|
||||
_ = bh.Requests()()
|
||||
|
||||
//logrus.Infof("access your zrok share: %v", resp.Payload.FrontendProxyEndpoints[0])
|
||||
//for {
|
||||
// time.Sleep(5 * time.Second)
|
||||
// logrus.Infof("requests: %d", bh.Requests()())
|
||||
//}
|
||||
if cmd.headless {
|
||||
logrus.Infof("access your zrok share at the following endpoints:\n %v", strings.Join(resp.Payload.FrontendProxyEndpoints, "\n"))
|
||||
for {
|
||||
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)
|
||||
prg := tea.NewProgram(mdl, tea.WithAltScreen())
|
||||
|
||||
@ -201,6 +207,7 @@ func (cmd *sharePublicCommand) run(_ *cobra.Command, args []string) {
|
||||
|
||||
close(requestsChan)
|
||||
cmd.destroy(zrd.Env.ZId, resp.Payload.ShrToken, zrok, auth)
|
||||
}
|
||||
}
|
||||
|
||||
func (cmd *sharePublicCommand) proxyBackendMode(cfg *proxyBackend.Config) (endpoints.BackendHandler, error) {
|
||||
|
Loading…
Reference in New Issue
Block a user