Skip to content

Commit

Permalink
TT-448: add mservctl update command (#24)
Browse files Browse the repository at this point in the history
While mserv supports updating bundles, the mservctl client does not currently implement this functionality. This PR implements it by adding an mservctl update command to the tool.

Usage:
mservctl update 9c9ecec1-8f98-4c3f-88cd-ca3c27599e6b bundle.zip
  • Loading branch information
AaronFeledy authored Nov 15, 2023
1 parent 987bc93 commit e7fcb22
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions mservctl/cmd/update.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package cmd

import (
"os"
"time"

"github.com/spf13/cobra"

"github.com/TykTechnologies/mserv/mservclient/client/mw"
)

// updateCmd represents the update command
var updateCmd = &cobra.Command{
Use: "update",
Short: "Updates a middleware on mserv",
Long: "Updates a middleware by ID",
Example: `mservctl update 13b0eb10-419f-40ef-838d-6d26bb2eeaa8 /path/to/bundle.zip`,
Args: cobra.ExactArgs(2),
Run: updateMiddleware,
}

func init() {
rootCmd.AddCommand(updateCmd)
}

func updateMiddleware(cmd *cobra.Command, args []string) {
file, err := os.Open(args[1])
if err != nil {
log.WithError(err).Error("Couldn't open the bundle file")
return
}
defer file.Close()

params := mw.NewMwUpdateParams().WithID(args[0]).WithUploadFile(file).WithTimeout(120 * time.Second)

resp, err := mservapi.Mw.MwUpdate(params, defaultAuth())
if err != nil {
log.WithError(err).Error("Couldn't update middleware")
return
}

cmd.Printf("Middleware uploaded successfully, ID: %s\n", resp.GetPayload().Payload.BundleID)
}

0 comments on commit e7fcb22

Please sign in to comment.