zrok admin delete frontend (#129)

This commit is contained in:
Michael Quigley 2022-12-02 09:08:38 -05:00
parent 309f4e7d87
commit db19dfbb77
No known key found for this signature in database
GPG Key ID: 9B60314A9DD20A62
5 changed files with 69 additions and 9 deletions

View File

@ -1,13 +1,11 @@
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() {
@ -46,13 +44,7 @@ func (cmd *adminCreateFrontendCommand) run(_ *cobra.Command, args []string) {
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)
resp, err := zrok.Admin.CreateFrontend(req, mustGetAdminAuth())
if err != nil {
panic(err)
}

View File

@ -0,0 +1,47 @@
package main
import (
"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"
)
func init() {
adminDeleteCmd.AddCommand(newAdminDeleteFrontendCommand().cmd)
}
type adminDeleteFrontendCommand struct {
cmd *cobra.Command
}
func newAdminDeleteFrontendCommand() *adminDeleteFrontendCommand {
cmd := &cobra.Command{
Use: "frontend <frontendToken>",
Short: "Delete a global public frontend",
Args: cobra.ExactArgs(1),
}
command := &adminDeleteFrontendCommand{cmd: cmd}
cmd.Run = command.run
return command
}
func (cmd *adminDeleteFrontendCommand) run(_ *cobra.Command, args []string) {
feToken := args[0]
zrok, err := zrokdir.ZrokClient(apiEndpoint)
if err != nil {
panic(err)
}
req := admin.NewDeleteFrontendParams()
req.Body = &rest_model_zrok.DeleteFrontendRequest{FrontendToken: feToken}
_, err = zrok.Admin.DeleteFrontend(req, mustGetAdminAuth())
if err != nil {
panic(err)
}
logrus.Infof("deleted global frontend '%v'", feToken)
}

View File

@ -17,6 +17,7 @@ func init() {
zrokdir.AddZrokApiEndpointFlag(&apiEndpoint, rootCmd.PersistentFlags())
rootCmd.AddCommand(accessCmd)
adminCmd.AddCommand(adminCreateCmd)
adminCmd.AddCommand(adminDeleteCmd)
rootCmd.AddCommand(adminCmd)
rootCmd.AddCommand(shareCmd)
rootCmd.AddCommand(testCmd)
@ -50,6 +51,11 @@ var adminCreateCmd = &cobra.Command{
Short: "Create global resources",
}
var adminDeleteCmd = &cobra.Command{
Use: "delete",
Short: "Delete global resources",
}
var shareCmd = &cobra.Command{
Use: "share",
Short: "Create backend access for services",

15
cmd/zrok/util.go Normal file
View File

@ -0,0 +1,15 @@
package main
import (
"github.com/go-openapi/runtime"
httptransport "github.com/go-openapi/runtime/client"
"os"
)
func mustGetAdminAuth() runtime.ClientAuthInfoWriter {
adminToken := os.Getenv("ZROK_ADMIN_TOKEN")
if adminToken == "" {
panic("please set ZROK_ADMIN_TOKEN to a valid admin token for your zrok instance")
}
return httptransport.APIKeyAuth("X-TOKEN", "header", adminToken)
}