diff --git a/cmd/reset.go b/cmd/reset.go index 60eee26f7..8c49bc93a 100644 --- a/cmd/reset.go +++ b/cmd/reset.go @@ -9,10 +9,15 @@ import ( "github.com/hbagdi/deck/dump" "github.com/hbagdi/deck/reset" "github.com/hbagdi/deck/utils" + "github.com/pkg/errors" "github.com/spf13/cobra" ) -var resetCmdForce bool +var ( + resetCmdForce bool + resetWorkspace string + resetAllWorkspaces bool +) // resetCmd represents the reset command var resetCmd = &cobra.Command{ @@ -34,17 +39,54 @@ By default, this command will ask for a confirmation prompt.`, return nil } } + client, err := utils.GetKongClient(config) if err != nil { return err } - state, err := dump.Get(client, dumpConfig) - if err != nil { - return err + // Kong OSS or default workspace + if !resetAllWorkspaces && resetWorkspace == "" { + state, err := dump.Get(client, dumpConfig) + if err != nil { + return err + } + err = reset.Reset(state, client) + if err != nil { + return err + } + return nil } - err = reset.Reset(state, client) - if err != nil { - return err + + if resetAllWorkspaces && resetWorkspace != "" { + return errors.New("workspace cannot be specified with --all-workspace flag") + } + + // Kong Enterprise + var workspaces []string + if resetAllWorkspaces { + workspaces, err = listWorkspaces(client, config.Address) + if err != nil { + return err + } + } + if resetWorkspace != "" { + workspaces = append(workspaces, resetWorkspace) + } + + for _, workspace := range workspaces { + config.Workspace = workspace + client, err := utils.GetKongClient(config) + if err != nil { + return err + } + state, err := dump.Get(client, dumpConfig) + if err != nil { + return err + } + err = reset.Reset(state, client) + if err != nil { + return err + } } return nil }, @@ -78,6 +120,11 @@ func init() { resetCmd.Flags().BoolVar(&dumpConfig.SkipConsumers, "skip-consumers", false, "do not reset consumers or "+ "any plugins associated with consumers") + resetCmd.Flags().StringVarP(&resetWorkspace, "workspace", "w", + "", "reset configuration of a specific workspace"+ + "(Kong Enterprise only).") + resetCmd.Flags().BoolVar(&resetAllWorkspaces, "all-workspaces", + false, "reset configuration of all workspaces (Kong Enterprise only).") resetCmd.Flags().StringSliceVar(&dumpConfig.SelectorTags, "select-tag", []string{}, "only entities matching tags specified via this flag are deleted.\n"+