--headless for 'zrok access private' (#246)

This commit is contained in:
Michael Quigley 2023-02-16 16:46:26 -05:00
parent ef9c88ac44
commit 46f16d25f6
No known key found for this signature in database
GPG Key ID: 9B60314A9DD20A62

View File

@ -24,8 +24,9 @@ func init() {
} }
type accessPrivateCommand struct { type accessPrivateCommand struct {
cmd *cobra.Command
bindAddress string bindAddress string
headless bool
cmd *cobra.Command
} }
func newAccessPrivateCommand() *accessPrivateCommand { func newAccessPrivateCommand() *accessPrivateCommand {
@ -35,6 +36,7 @@ func newAccessPrivateCommand() *accessPrivateCommand {
Args: cobra.ExactArgs(1), Args: cobra.ExactArgs(1),
} }
command := &accessPrivateCommand{cmd: cmd} command := &accessPrivateCommand{cmd: cmd}
cmd.Flags().BoolVar(&command.headless, "headless", false, "Disable TUI and run headless")
cmd.Run = command.run cmd.Run = command.run
cmd.Flags().StringVarP(&command.bindAddress, "bind", "b", "127.0.0.1:9191", "The address to bind the private frontend") cmd.Flags().StringVarP(&command.bindAddress, "bind", "b", "127.0.0.1:9191", "The address to bind the private frontend")
return command return command
@ -112,28 +114,40 @@ func (cmd *accessPrivateCommand) run(_ *cobra.Command, args []string) {
} }
}() }()
mdl := newAccessModel(shrToken, endpointUrl.String()) if cmd.headless {
logrus.SetOutput(mdl) logrus.Infof("access the zrok share at the followind endpoint: %v", endpointUrl.String())
prg := tea.NewProgram(mdl, tea.WithAltScreen())
mdl.prg = prg
go func() {
for { for {
select { select {
case req := <-cfg.RequestsChan: case req := <-cfg.RequestsChan:
if req != nil { logrus.Infof("%v -> %v %v", req.RemoteAddr, req.Method, req.Path)
prg.Send(req)
}
} }
} }
}()
if _, err := prg.Run(); err != nil { } else {
tui.Error("An error occurred", err) mdl := newAccessModel(shrToken, endpointUrl.String())
logrus.SetOutput(mdl)
prg := tea.NewProgram(mdl, tea.WithAltScreen())
mdl.prg = prg
go func() {
for {
select {
case req := <-cfg.RequestsChan:
if req != nil {
prg.Send(req)
}
}
}
}()
if _, err := prg.Run(); err != nil {
tui.Error("An error occurred", err)
}
close(cfg.RequestsChan)
cmd.destroy(accessResp.Payload.FrontendToken, zrd.Env.ZId, shrToken, zrok, auth)
} }
close(cfg.RequestsChan)
cmd.destroy(accessResp.Payload.FrontendToken, zrd.Env.ZId, shrToken, zrok, auth)
} }
func (cmd *accessPrivateCommand) destroy(frotendName, envZId, shrToken string, zrok *rest_client_zrok.Zrok, auth runtime.ClientAuthInfoWriter) { func (cmd *accessPrivateCommand) destroy(frotendName, envZId, shrToken string, zrok *rest_client_zrok.Zrok, auth runtime.ClientAuthInfoWriter) {