mirror of
https://github.com/openziti/zrok.git
synced 2024-11-22 16:13:47 +01:00
zrok admin delete frontend (#129)
This commit is contained in:
parent
309f4e7d87
commit
db19dfbb77
@ -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)
|
||||
}
|
||||
|
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())
|
||||
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
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…
Reference in New Issue
Block a user