Skip to content

Commit

Permalink
Remove the recursive delete of triggers as they are not longer suppor…
Browse files Browse the repository at this point in the history
…ted.
  • Loading branch information
JadeRedworth committed Oct 16, 2019
1 parent 2e9b278 commit 4d35903
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 73 deletions.
40 changes: 2 additions & 38 deletions common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -609,11 +609,10 @@ func GetFuncYamlVersion(oldFF map[string]interface{}) int {
}

// UserConfirmedMultiResourceDeletion will prompt the user for confirmation to delete all the the resources
func UserConfirmedMultiResourceDeletion(aps []*modelsv2.App, fns []*modelsv2.Fn, trs []*modelsv2.Trigger) bool {
func UserConfirmedMultiResourceDeletion(aps []*modelsv2.App, fns []*modelsv2.Fn) bool {

apsLen := len(aps)
fnsLen := len(fns)
trsLen := len(trs)

fmt.Println("You are about to delete the following resources:")
if apsLen > 0 {
Expand All @@ -622,9 +621,7 @@ func UserConfirmedMultiResourceDeletion(aps []*modelsv2.App, fns []*modelsv2.Fn,
if fnsLen > 0 {
fmt.Println(" Functions: ", fnsLen)
}
if trsLen > 0 {
fmt.Println(" Triggers: ", trsLen)
}

fmt.Println("This operation cannot be undone")
fmt.Printf("Do you wish to proceed? Y/N: ")
reader := bufio.NewReader(os.Stdin)
Expand All @@ -643,22 +640,6 @@ func UserConfirmedMultiResourceDeletion(aps []*modelsv2.App, fns []*modelsv2.Fn,
return true
}

// ListFnsAndTriggersInApp lists all the functions associated with an app and all the triggers associated with each of those functions
func ListFnsAndTriggersInApp(c *cli.Context, client *fnclient.Fn, app *modelsv2.App) ([]*modelsv2.Fn, []*modelsv2.Trigger, error) {
fns, err := ListFnsInApp(c, client, app)
if err != nil {
return nil, nil, err
}
var trs []*modelsv2.Trigger
for _, fn := range fns {
t, err := ListTriggersInFunc(c, client, fn)
if err != nil {
return nil, nil, err
}
trs = append(trs, t...)
}
return fns, trs, nil
}

//DeleteFunctions deletes all the functions provided to it. if provided nil it is a no-op
func DeleteFunctions(c *cli.Context, client *fnclient.Fn, fns []*modelsv2.Fn) error {
Expand All @@ -677,23 +658,6 @@ func DeleteFunctions(c *cli.Context, client *fnclient.Fn, fns []*modelsv2.Fn) er
return nil
}

//DeleteTriggers deletes all the triggers provided to it. if provided nil it is a no-op
func DeleteTriggers(c *cli.Context, client *fnclient.Fn, triggers []*modelsv2.Trigger) error {
if triggers == nil {
return nil
}
for _, t := range triggers {
params := apitriggers.NewDeleteTriggerParams()
params.TriggerID = t.ID
_, err := client.Triggers.DeleteTrigger(params)
if err != nil {
return fmt.Errorf("Failed to Delete trigger %s: %s", t.Name, err)
}
fmt.Println("Trigger ", t.Name, " deleted")
}
return nil
}

//ListFnsInApp gets all the functions associated with an app
func ListFnsInApp(c *cli.Context, client *fnclient.Fn, app *modelsv2.App) ([]*modelsv2.Fn, error) {
params := &apifns.ListFnsParams{
Expand Down
14 changes: 8 additions & 6 deletions objects/app/apps.go
Original file line number Diff line number Diff line change
Expand Up @@ -319,24 +319,26 @@ func (a *appsCmd) delete(c *cli.Context) error {

//recursive delete of sub-objects
if c.Bool("recursive") {
fns, triggers, err := common.ListFnsAndTriggersInApp(c, a.client, app)

fns, err := common.ListFnsInApp(c, a.client, app)
if err != nil {
return fmt.Errorf("Failed to get associated objects: %s", err)
}

//fns, triggers, err := common.ListFnsAndTriggersInApp(c, a.client, app)
//if err != nil {
// return fmt.Errorf("Failed to get associated objects: %s", err)
//}

//Forced deletion
var shouldContinue bool
if c.Bool("force") {
shouldContinue = true
} else {
shouldContinue = common.UserConfirmedMultiResourceDeletion([]*modelsv2.App{app}, fns, triggers)
shouldContinue = common.UserConfirmedMultiResourceDeletion([]*modelsv2.App{app}, fns)
}

if shouldContinue {
err := common.DeleteTriggers(c, a.client, triggers)
if err != nil {
return fmt.Errorf("Failed to delete associated objects: %s", err)
}
err = common.DeleteFunctions(c, a.client, fns)
if err != nil {
return fmt.Errorf("Failed to delete associated objects: %s", err)
Expand Down
25 changes: 0 additions & 25 deletions objects/fn/fns.go
Original file line number Diff line number Diff line change
Expand Up @@ -551,31 +551,6 @@ func (f *fnsCmd) delete(c *cli.Context) error {
return err
}

//recursive delete of sub-objects
if c.Bool("recursive") {
triggers, err := common.ListTriggersInFunc(c, f.client, fn)
if err != nil {
return fmt.Errorf("Failed to get associated objects: %s", err)
}

//Forced delete
var shouldContinue bool
if c.Bool("force") {
shouldContinue = true
} else {
shouldContinue = common.UserConfirmedMultiResourceDeletion(nil, []*modelsv2.Fn{fn}, triggers)
}

if shouldContinue {
err := common.DeleteTriggers(c, f.client, triggers)
if err != nil {
return fmt.Errorf("Failed to delete associated objects: %s", err)
}
} else {
return nil
}
}

params := apifns.NewDeleteFnParams()
params.FnID = fn.ID
_, err = f.client.Fns.DeleteFn(params)
Expand Down
5 changes: 1 addition & 4 deletions test/cli_crud_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,13 +226,10 @@ func TestRecursiveDelete(t *testing.T) {
defer h.Cleanup()
appName1 := h.NewAppName()
funcName1 := h.NewFuncName(appName1)
triggerName1 := h.NewTriggerName(appName1, funcName1)

h.Fn("create", "app", appName1).AssertSuccess()
h.Fn("create", "function", appName1, funcName1, "foo/duffimage:0.0.1").AssertSuccess()
h.Fn("create", "trigger", appName1, funcName1, triggerName1, "--type", "http", "--source", "/mytrigger").AssertSuccess()
h.Fn("delete", "app", appName1, "-f", "-r").AssertSuccess().
AssertStdoutContains(appName1).
AssertStdoutContains(funcName1).
AssertStdoutContains(triggerName1)
AssertStdoutContains(funcName1)
}

0 comments on commit 4d35903

Please sign in to comment.