--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 {
cmd *cobra.Command
bindAddress string
headless bool
cmd *cobra.Command
}
func newAccessPrivateCommand() *accessPrivateCommand {
@ -35,6 +36,7 @@ func newAccessPrivateCommand() *accessPrivateCommand {
Args: cobra.ExactArgs(1),
}
command := &accessPrivateCommand{cmd: cmd}
cmd.Flags().BoolVar(&command.headless, "headless", false, "Disable TUI and run headless")
cmd.Run = command.run
cmd.Flags().StringVarP(&command.bindAddress, "bind", "b", "127.0.0.1:9191", "The address to bind the private frontend")
return command
@ -112,6 +114,16 @@ func (cmd *accessPrivateCommand) run(_ *cobra.Command, args []string) {
}
}()
if cmd.headless {
logrus.Infof("access the zrok share at the followind endpoint: %v", endpointUrl.String())
for {
select {
case req := <-cfg.RequestsChan:
logrus.Infof("%v -> %v %v", req.RemoteAddr, req.Method, req.Path)
}
}
} else {
mdl := newAccessModel(shrToken, endpointUrl.String())
logrus.SetOutput(mdl)
prg := tea.NewProgram(mdl, tea.WithAltScreen())
@ -134,6 +146,8 @@ func (cmd *accessPrivateCommand) run(_ *cobra.Command, args []string) {
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) {