Skip to content

Commit

Permalink
feat(reset) add workspace support to reset command
Browse files Browse the repository at this point in the history
Two flags have been added:
-w/--workspaces: specify the workspace to reset
--all-workspaces: reset all the workspaces

Fix #74
  • Loading branch information
hbagdi committed Sep 15, 2019
1 parent 2caf0e5 commit 53853c6
Showing 1 changed file with 54 additions and 7 deletions.
61 changes: 54 additions & 7 deletions cmd/reset.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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
},
Expand Down Expand Up @@ -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"+
Expand Down

0 comments on commit 53853c6

Please sign in to comment.