admin update frontend (#129)

This commit is contained in:
Michael Quigley 2022-12-02 12:19:41 -05:00
parent 38c83fda92
commit 5ba457313a
No known key found for this signature in database
GPG Key ID: 9B60314A9DD20A62
3 changed files with 71 additions and 10 deletions

View File

@ -0,0 +1,59 @@
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() {
adminUpdateCmd.AddCommand(newAdminUpdateFrontendCommand().cmd)
}
type adminUpdateFrontendCommand struct {
cmd *cobra.Command
newPublicName string
newUrlTemplate string
}
func newAdminUpdateFrontendCommand() *adminUpdateFrontendCommand {
cmd := &cobra.Command{
Use: "frontend <frontendToken>",
Aliases: []string{"fe"},
Short: "Update a global public frontend",
Args: cobra.ExactArgs(1),
}
command := &adminUpdateFrontendCommand{cmd: cmd}
cmd.Flags().StringVar(&command.newPublicName, "public-name", "", "Specify a new value for the public name")
cmd.Flags().StringVar(&command.newUrlTemplate, "url-template", "", "Specify a new value for the url template")
cmd.Run = command.run
return command
}
func (cmd *adminUpdateFrontendCommand) run(_ *cobra.Command, args []string) {
feToken := args[0]
if cmd.newPublicName == "" && cmd.newUrlTemplate == "" {
panic("must specify at least one of public name or url template")
}
zrok, err := zrokdir.ZrokClient(apiEndpoint)
if err != nil {
panic(err)
}
req := admin.NewUpdateFrontendParams()
req.Body = &rest_model_zrok.UpdateFrontendRequest{
FrontendToken: feToken,
PublicName: cmd.newPublicName,
URLTemplate: cmd.newUrlTemplate,
}
_, err = zrok.Admin.UpdateFrontend(req, mustGetAdminAuth())
if err != nil {
panic(err)
}
logrus.Infof("updated global frontend '%v'", feToken)
}

View File

@ -19,6 +19,7 @@ func init() {
adminCmd.AddCommand(adminCreateCmd)
adminCmd.AddCommand(adminDeleteCmd)
adminCmd.AddCommand(adminListCmd)
adminCmd.AddCommand(adminUpdateCmd)
rootCmd.AddCommand(adminCmd)
rootCmd.AddCommand(shareCmd)
rootCmd.AddCommand(testCmd)
@ -62,6 +63,11 @@ var adminListCmd = &cobra.Command{
Short: "List global resources",
}
var adminUpdateCmd = &cobra.Command{
Use: "update",
Short: "Update global resources",
}
var shareCmd = &cobra.Command{
Use: "share",
Short: "Create backend access for services",

View File

@ -37,21 +37,17 @@ func (h *updateFrontendHandler) Handle(params admin.UpdateFrontendParams, princi
}
doUpdate := false
if (fe.PublicName == nil && publicName != "") || (fe.PublicName != nil && *fe.PublicName != publicName) {
if publicName != "" {
if publicName != "" {
if fe.PublicName == nil || (fe.PublicName != nil && *fe.PublicName != publicName) {
fe.PublicName = &publicName
} else {
fe.PublicName = nil
doUpdate = true
}
doUpdate = true
}
if (fe.UrlTemplate == nil && urlTemplate != "") || (fe.UrlTemplate != nil && *fe.UrlTemplate != urlTemplate) {
if urlTemplate != "" {
if urlTemplate != "" {
if fe.UrlTemplate == nil || (fe.UrlTemplate != nil && *fe.UrlTemplate != urlTemplate) {
fe.UrlTemplate = &urlTemplate
} else {
fe.UrlTemplate = nil
doUpdate = true
}
doUpdate = true
}
if doUpdate {