mirror of
https://github.com/openziti/zrok.git
synced 2025-06-20 09:48:07 +02:00
zrok admin delete frontend (#129)
This commit is contained in:
parent
309f4e7d87
commit
db19dfbb77
@ -1,13 +1,11 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
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_client_zrok/admin"
|
||||||
"github.com/openziti-test-kitchen/zrok/rest_model_zrok"
|
"github.com/openziti-test-kitchen/zrok/rest_model_zrok"
|
||||||
"github.com/openziti-test-kitchen/zrok/zrokdir"
|
"github.com/openziti-test-kitchen/zrok/zrokdir"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"os"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
@ -46,13 +44,7 @@ func (cmd *adminCreateFrontendCommand) run(_ *cobra.Command, args []string) {
|
|||||||
URLTemplate: urlTemplate,
|
URLTemplate: urlTemplate,
|
||||||
}
|
}
|
||||||
|
|
||||||
adminToken := os.Getenv("ZROK_ADMIN_TOKEN")
|
resp, err := zrok.Admin.CreateFrontend(req, mustGetAdminAuth())
|
||||||
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 {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
47
cmd/zrok/admin_delete_frontend.go
Normal file
47
cmd/zrok/admin_delete_frontend.go
Normal 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)
|
||||||
|
}
|
@ -17,6 +17,7 @@ func init() {
|
|||||||
zrokdir.AddZrokApiEndpointFlag(&apiEndpoint, rootCmd.PersistentFlags())
|
zrokdir.AddZrokApiEndpointFlag(&apiEndpoint, rootCmd.PersistentFlags())
|
||||||
rootCmd.AddCommand(accessCmd)
|
rootCmd.AddCommand(accessCmd)
|
||||||
adminCmd.AddCommand(adminCreateCmd)
|
adminCmd.AddCommand(adminCreateCmd)
|
||||||
|
adminCmd.AddCommand(adminDeleteCmd)
|
||||||
rootCmd.AddCommand(adminCmd)
|
rootCmd.AddCommand(adminCmd)
|
||||||
rootCmd.AddCommand(shareCmd)
|
rootCmd.AddCommand(shareCmd)
|
||||||
rootCmd.AddCommand(testCmd)
|
rootCmd.AddCommand(testCmd)
|
||||||
@ -50,6 +51,11 @@ var adminCreateCmd = &cobra.Command{
|
|||||||
Short: "Create global resources",
|
Short: "Create global resources",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var adminDeleteCmd = &cobra.Command{
|
||||||
|
Use: "delete",
|
||||||
|
Short: "Delete 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",
|
||||||
|
15
cmd/zrok/util.go
Normal file
15
cmd/zrok/util.go
Normal 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)
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user