http -> http bind, part 1 (#2)

This commit is contained in:
Michael Quigley 2022-08-18 17:11:39 -04:00
parent 1e49cbe243
commit 73283660f8
No known key found for this signature in database
GPG Key ID: 9B60314A9DD20A62

View File

@ -24,29 +24,29 @@ import (
) )
func init() { func init() {
rootCmd.AddCommand(newHttpCommand().cmd) rootCmd.AddCommand(newHttpBindCommand().cmd)
} }
type httpCommand struct { type httpBindCommand struct {
service bool service bool
basicAuth []string basicAuth []string
cmd *cobra.Command cmd *cobra.Command
} }
func newHttpCommand() *httpCommand { func newHttpBindCommand() *httpBindCommand {
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "http <endpoint>", Use: "http <endpoint>",
Short: "Start an HTTP terminator", Short: "Start an HTTP terminator",
Args: cobra.ExactArgs(1), Args: cobra.ExactArgs(1),
} }
command := &httpCommand{cmd: cmd} command := &httpBindCommand{cmd: cmd}
cmd.Flags().BoolVarP(&command.service, "service", "s", false, "Disable TUI 'chrome' for service operation") cmd.Flags().BoolVarP(&command.service, "service", "s", false, "Disable TUI 'chrome' for service operation")
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.Run = command.run cmd.Run = command.run
return command return command
} }
func (self *httpCommand) run(_ *cobra.Command, args []string) { func (self *httpBindCommand) run(_ *cobra.Command, args []string) {
if !self.service { if !self.service {
if err := ui.Init(); err != nil { if err := ui.Init(); err != nil {
panic(err) panic(err)
@ -102,7 +102,7 @@ func (self *httpCommand) run(_ *cobra.Command, args []string) {
signal.Notify(c, os.Interrupt, syscall.SIGTERM) signal.Notify(c, os.Interrupt, syscall.SIGTERM)
go func() { go func() {
<-c <-c
cleanupHttp(id, cfg, zrok, auth) self.destroy(id, cfg, zrok, auth)
os.Exit(0) os.Exit(0)
}() }()
@ -158,7 +158,7 @@ func (self *httpCommand) run(_ *cobra.Command, args []string) {
switch e.ID { switch e.ID {
case "q", "<C-c>": case "q", "<C-c>":
ui.Close() ui.Close()
cleanupHttp(id, cfg, zrok, auth) self.destroy(id, cfg, zrok, auth)
os.Exit(0) os.Exit(0)
} }
} }
@ -185,7 +185,7 @@ func (self *httpCommand) run(_ *cobra.Command, args []string) {
} }
} }
func cleanupHttp(id string, cfg *bind.Config, zrok *rest_client_zrok.Zrok, auth runtime.ClientAuthInfoWriter) { func (self *httpBindCommand) destroy(id string, cfg *bind.Config, zrok *rest_client_zrok.Zrok, auth runtime.ClientAuthInfoWriter) {
logrus.Infof("shutting down '%v'", cfg.Service) logrus.Infof("shutting down '%v'", cfg.Service)
req := tunnel.NewUntunnelParams() req := tunnel.NewUntunnelParams()
req.Body = &rest_model_zrok.UntunnelRequest{ req.Body = &rest_model_zrok.UntunnelRequest{