zrok http backend -> zrok share public (#106)

This commit is contained in:
Michael Quigley 2022-11-22 13:34:09 -05:00
parent b54876fcb6
commit 3f35888ad3
No known key found for this signature in database
GPG Key ID: 9B60314A9DD20A62
3 changed files with 13 additions and 7 deletions

View File

@ -16,6 +16,7 @@ func init() {
rootCmd.PersistentFlags().BoolVarP(&panicInstead, "panic", "p", false, "Panic instead of showing pretty errors") rootCmd.PersistentFlags().BoolVarP(&panicInstead, "panic", "p", false, "Panic instead of showing pretty errors")
zrokdir.AddZrokApiEndpointFlag(&apiEndpoint, rootCmd.PersistentFlags()) zrokdir.AddZrokApiEndpointFlag(&apiEndpoint, rootCmd.PersistentFlags())
rootCmd.AddCommand(httpCmd) rootCmd.AddCommand(httpCmd)
rootCmd.AddCommand(shareCmd)
} }
var rootCmd = &cobra.Command{ var rootCmd = &cobra.Command{
@ -36,6 +37,11 @@ var httpCmd = &cobra.Command{
Short: "HTTP endpoint operations", Short: "HTTP endpoint operations",
} }
var shareCmd = &cobra.Command{
Use: "share",
Short: "Share resources",
}
func main() { func main() {
if err := rootCmd.Execute(); err != nil { if err := rootCmd.Execute(); err != nil {
panic(err) panic(err)

View File

@ -25,30 +25,30 @@ import (
) )
func init() { func init() {
httpCmd.AddCommand(newHttpBackendCommand().cmd) shareCmd.AddCommand(newHttpBackendCommand().cmd)
} }
type httpBackendCommand struct { type sharePublicCommand struct {
quiet bool quiet bool
basicAuth []string basicAuth []string
cmd *cobra.Command cmd *cobra.Command
} }
func newHttpBackendCommand() *httpBackendCommand { func newHttpBackendCommand() *sharePublicCommand {
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "backend <targetEndpoint>", Use: "public <targetEndpoint>",
Aliases: []string{"be"}, Aliases: []string{"be"},
Short: "Create an HTTP binding", Short: "Create an HTTP binding",
Args: cobra.ExactArgs(1), Args: cobra.ExactArgs(1),
} }
command := &httpBackendCommand{cmd: cmd} command := &sharePublicCommand{cmd: cmd}
cmd.Flags().BoolVarP(&command.quiet, "quiet", "q", false, "Disable TUI 'chrome' for quiet operation") cmd.Flags().BoolVarP(&command.quiet, "quiet", "q", false, "Disable TUI 'chrome' for quiet 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 *httpBackendCommand) run(_ *cobra.Command, args []string) { func (self *sharePublicCommand) run(_ *cobra.Command, args []string) {
targetEndpoint, err := url.Parse(args[0]) targetEndpoint, err := url.Parse(args[0])
if err != nil { if err != nil {
if !panicInstead { if !panicInstead {
@ -225,7 +225,7 @@ func (self *httpBackendCommand) run(_ *cobra.Command, args []string) {
} }
} }
func (self *httpBackendCommand) destroy(id string, cfg *backend.Config, zrok *rest_client_zrok.Zrok, auth runtime.ClientAuthInfoWriter) { func (self *sharePublicCommand) destroy(id string, cfg *backend.Config, zrok *rest_client_zrok.Zrok, auth runtime.ClientAuthInfoWriter) {
logrus.Debugf("shutting down '%v'", cfg.Service) logrus.Debugf("shutting down '%v'", cfg.Service)
req := service.NewUnshareParams() req := service.NewUnshareParams()
req.Body = &rest_model_zrok.UnshareRequest{ req.Body = &rest_model_zrok.UnshareRequest{