roughed in zrok admin create frontend cli (#129)

This commit is contained in:
Michael Quigley 2022-12-01 16:41:08 -05:00
parent c9db95fe03
commit 702ad23c99
No known key found for this signature in database
GPG Key ID: 9B60314A9DD20A62
3 changed files with 70 additions and 3 deletions

View File

@ -0,0 +1,61 @@
package main
import (
httptransport "github.com/go-openapi/runtime/client"
"github.com/openziti-test-kitchen/zrok/rest_client_zrok/admin"
"github.com/openziti-test-kitchen/zrok/rest_model_zrok"
"github.com/openziti-test-kitchen/zrok/zrokdir"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"os"
)
func init() {
adminCreateCmd.AddCommand(newAdminCreateFrontendCommand().cmd)
}
type adminCreateFrontendCommand struct {
cmd *cobra.Command
}
func newAdminCreateFrontendCommand() *adminCreateFrontendCommand {
cmd := &cobra.Command{
Use: "frontend <zitiId> <publicName> <urlTemplate>",
Short: "Create a global public frontend",
Args: cobra.ExactArgs(3),
}
command := &adminCreateFrontendCommand{cmd: cmd}
cmd.Run = command.run
return command
}
func (cmd *adminCreateFrontendCommand) run(_ *cobra.Command, args []string) {
zId := args[0]
publicName := args[1]
urlTemplate := args[2]
zrok, err := zrokdir.ZrokClient(apiEndpoint)
if err != nil {
panic(err)
}
req := admin.NewCreateFrontendParams()
req.Body = &rest_model_zrok.CreateFrontendRequest{
ZID: zId,
PublicName: publicName,
URLTemplate: urlTemplate,
}
adminToken := os.Getenv("ZROK_ADMIN_TOKEN")
if adminToken == "" {
panic("please set ZROK_ADMIN_TOKEN to a valid admin token for your zrok instance")
}
auth := httptransport.APIKeyAuth("X-TOKEN", "header", adminToken)
resp, err := zrok.Admin.CreateFrontend(req, auth)
if err != nil {
panic(err)
}
logrus.Infof("created global public frontend '%v'", resp.Payload.Token)
}

View File

@ -21,9 +21,9 @@ func newAdminGcCommand() *adminGcCommand {
Short: "Garbage collect a zrok instance",
Args: cobra.ExactArgs(1),
}
c := &adminGcCommand{cmd: cmd}
cmd.Run = c.run
return c
command := &adminGcCommand{cmd: cmd}
cmd.Run = command.run
return command
}
func (gc *adminGcCommand) run(_ *cobra.Command, args []string) {

View File

@ -16,6 +16,7 @@ func init() {
rootCmd.PersistentFlags().BoolVarP(&panicInstead, "panic", "p", false, "Panic instead of showing pretty errors")
zrokdir.AddZrokApiEndpointFlag(&apiEndpoint, rootCmd.PersistentFlags())
rootCmd.AddCommand(accessCmd)
adminCmd.AddCommand(adminCreateCmd)
rootCmd.AddCommand(adminCmd)
rootCmd.AddCommand(shareCmd)
rootCmd.AddCommand(testCmd)
@ -44,6 +45,11 @@ var adminCmd = &cobra.Command{
Short: "Administration and operations functions",
}
var adminCreateCmd = &cobra.Command{
Use: "create",
Short: "Create global resources",
}
var shareCmd = &cobra.Command{
Use: "share",
Short: "Create backend access for services",