api/deploy.go
func deployRollbackUpdate(w http.ResponseWriter, r *http.Request, t auth.Token) error {
	appName := r.URL.Query().Get(":appname")
	instance, err := app.GetByName(appName)
	if err != nil {
		return &tsuruErrors.HTTP{
			Code:    http.StatusBadRequest,
			Message: fmt.Sprintf("App %s was not found", appName),
		}
	}
	canUpdateRollback := permission.Check(t, permission.PermAppUpdateDeployRollback, contextsForApp(instance)...)
	if !canUpdateRollback {
		return &tsuruErrors.HTTP{
			Code:    http.StatusForbidden,
			Message: "User does not have permission to do this action in this app",
		}
	}
	img := InputValue(r, "image")
	if img == "" {
		return &tsuruErrors.HTTP{
			Code:    http.StatusBadRequest,
			Message: "you must specify an image",
		}
	}
	disable := InputValue(r, "disable")
	disableRollback, err := strconv.ParseBool(disable)
	if err != nil {
		return &tsuruErrors.HTTP{
			Code:    http.StatusBadRequest,
			Message: fmt.Sprintf("Cannot set 'disable' status to: '%s', instead of 'true' or 'false'", disable),
		}
	}
	reason := InputValue(r, "reason")
	if (reason == "") && (disableRollback) {
		return &tsuruErrors.HTTP{
			Code:    http.StatusBadRequest,
			Message: "Reason cannot be empty while disabling a image rollback",
		}
	}
	evt, err := event.New(&event.Opts{
		Target:        appTarget(appName),
		Kind:          permission.PermAppUpdateDeployRollback,
		Owner:         t,
		CustomData:    event.FormToCustomData(InputFields(r)),
		Allowed:       event.Allowed(permission.PermAppReadEvents, contextsForApp(instance)...),
		AllowedCancel: event.Allowed(permission.PermAppUpdateEvents, contextsForApp(instance)...),
		Cancelable:    false,
	})
	if err != nil {
		return err
	}
	defer func() { evt.Done(err) }()
	err = app.RollbackUpdate(instance.Name, img, reason, disableRollback)
	if err != nil {
		return &tsuruErrors.HTTP{
			Code:    http.StatusBadRequest,
			Message: err.Error(),
		}
	}
	return err
}
func deployRollbackUpdate(w http.ResponseWriter, r *http.Request, t auth.Token) error {
	appName := r.URL.Query().Get(":appname")
	instance, err := app.GetByName(appName)
	if err != nil {
		return &tsuruErrors.HTTP{
			Code:    http.StatusBadRequest,
			Message: fmt.Sprintf("App %s was not found", appName),
		}
	}
	canUpdateRollback := permission.Check(t, permission.PermAppUpdateDeployRollback, contextsForApp(instance)...)
	if !canUpdateRollback {
		return &tsuruErrors.HTTP{
			Code:    http.StatusForbidden,
			Message: "User does not have permission to do this action in this app",
		}
	}
	img := InputValue(r, "image")
	if img == "" {
		return &tsuruErrors.HTTP{
			Code:    http.StatusBadRequest,
			Message: "you must specify an image",
		}
	}
	disable := InputValue(r, "disable")
	disableRollback, err := strconv.ParseBool(disable)
	if err != nil {
		return &tsuruErrors.HTTP{
			Code:    http.StatusBadRequest,
			Message: fmt.Sprintf("Cannot set 'disable' status to: '%s', instead of 'true' or 'false'", disable),
		}
	}
	reason := InputValue(r, "reason")
	if (reason == "") && (disableRollback) {
		return &tsuruErrors.HTTP{
			Code:    http.StatusBadRequest,
			Message: "Reason cannot be empty while disabling a image rollback",
		}
	}
	evt, err := event.New(&event.Opts{
		Target:        appTarget(appName),
		Kind:          permission.PermAppUpdateDeployRollback,
		Owner:         t,
		CustomData:    event.FormToCustomData(InputFields(r)),
		Allowed:       event.Allowed(permission.PermAppReadEvents, contextsForApp(instance)...),
		AllowedCancel: event.Allowed(permission.PermAppUpdateEvents, contextsForApp(instance)...),
		Cancelable:    false,
	})
	if err != nil {
		return err
	}
	defer func() { evt.Done(err) }()
	err = app.RollbackUpdate(instance.Name, img, reason, disableRollback)
	if err != nil {
		return &tsuruErrors.HTTP{
			Code:    http.StatusBadRequest,
			Message: err.Error(),
		}
	}
	return err
}
// title: rollback update
// path: /apps/{appname}/deploy/rollback/update
// method: PUT
// consume: application/x-www-form-urlencoded
// responses:
//   200: Rollback updated
//   400: Invalid data
//   403: Forbidden