mirror of
https://github.com/openziti/zrok.git
synced 2025-06-24 19:51:32 +02:00
roughed in zrok admin create frontend cli (#129)
This commit is contained in:
parent
c9db95fe03
commit
702ad23c99
61
cmd/zrok/admin_create_frontend.go
Normal file
61
cmd/zrok/admin_create_frontend.go
Normal 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)
|
||||||
|
}
|
@ -21,9 +21,9 @@ func newAdminGcCommand() *adminGcCommand {
|
|||||||
Short: "Garbage collect a zrok instance",
|
Short: "Garbage collect a zrok instance",
|
||||||
Args: cobra.ExactArgs(1),
|
Args: cobra.ExactArgs(1),
|
||||||
}
|
}
|
||||||
c := &adminGcCommand{cmd: cmd}
|
command := &adminGcCommand{cmd: cmd}
|
||||||
cmd.Run = c.run
|
cmd.Run = command.run
|
||||||
return c
|
return command
|
||||||
}
|
}
|
||||||
|
|
||||||
func (gc *adminGcCommand) run(_ *cobra.Command, args []string) {
|
func (gc *adminGcCommand) run(_ *cobra.Command, args []string) {
|
||||||
|
@ -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(accessCmd)
|
rootCmd.AddCommand(accessCmd)
|
||||||
|
adminCmd.AddCommand(adminCreateCmd)
|
||||||
rootCmd.AddCommand(adminCmd)
|
rootCmd.AddCommand(adminCmd)
|
||||||
rootCmd.AddCommand(shareCmd)
|
rootCmd.AddCommand(shareCmd)
|
||||||
rootCmd.AddCommand(testCmd)
|
rootCmd.AddCommand(testCmd)
|
||||||
@ -44,6 +45,11 @@ var adminCmd = &cobra.Command{
|
|||||||
Short: "Administration and operations functions",
|
Short: "Administration and operations functions",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var adminCreateCmd = &cobra.Command{
|
||||||
|
Use: "create",
|
||||||
|
Short: "Create global resources",
|
||||||
|
}
|
||||||
|
|
||||||
var shareCmd = &cobra.Command{
|
var shareCmd = &cobra.Command{
|
||||||
Use: "share",
|
Use: "share",
|
||||||
Short: "Create backend access for services",
|
Short: "Create backend access for services",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user