Skip to content

Commit

Permalink
Require confirmation if rollback more than 9 releases
Browse files Browse the repository at this point in the history
Fixes #881
  • Loading branch information
Nosajool committed Aug 18, 2016
1 parent 66a68e1 commit c60b0da
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
* The log level within empire can now be configured when starting the service. [#929](https://github.com/remind101/empire/issues/929)
* The CloudFormation backend now has experimental support for a `Custom::ECSTaskDefinition` resource that greatly reduces the size of generated templates. [#935](https://github.com/remind101/empire/pull/935)
* The Scheduler now has a `Restart` method which will trigger a restart of all the processes within an app. Previously, a "Restart" just re-released the app. Now schedulers like the cloudformation backend can optimize how the restart is handled. [#697](https://github.com/remind101/empire/issues/697)
* `emp run` now publishes an event when it is ran [#954](https://github.com/remind101/empire/pull/954)
* `emp run` now publishes an event when it is ran. [#954](https://github.com/remind101/empire/pull/954)
* `emp rollback` requires confirmation if rolling back more than 9 versions. [#975](https://github.com/remind101/empire/pull/975)

**Bugs**

Expand Down
30 changes: 30 additions & 0 deletions cmd/emp/releases.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"log"
"os"
"sort"
"strconv"
"strings"
"text/tabwriter"
"time"
Expand Down Expand Up @@ -226,7 +227,36 @@ func runRollback(cmd *Command, args []string) {
os.Exit(2)
}
ver := strings.TrimPrefix(args[0], "v")
rollbackSafetyCheck(ver, appname)

rel, err := client.ReleaseRollback(appname, ver, message)
must(err)
log.Printf("Rolled back %s to v%s as v%d.\n", appname, ver, rel.Version)
}

func rollbackSafetyCheck(verStr, appname string) {
// Grab head release to get the current version
hrels, err := client.ReleaseList(appname, &heroku.ListRange{
Field: "version",
Max: 1,
Descending: true,
})
must(err)

currVer := hrels[0].Version
verNum, err := strconv.Atoi(verStr)
must(err)

diff := currVer - verNum
if diff >= 10 {
var vconfirmation string
fmt.Printf("WARNING. Attempting to rollback %d versions from v%d to v%d.\n", diff, currVer, verNum)
fmt.Printf("To proceed, type v%d: ", verNum)
fmt.Scanln(&vconfirmation)
vconfirmation = strings.TrimPrefix(vconfirmation, "v")
if vconfirmation != verStr {
fmt.Println("Rollback confirmation did not match.")
os.Exit(2)
}
}
}

0 comments on commit c60b0da

Please sign in to comment.