From cb46a95835742a9776d679f5c902635766d588e0 Mon Sep 17 00:00:00 2001 From: Miguel Prieto Date: Mon, 13 Oct 2025 13:27:05 -0300 Subject: [PATCH 1/3] Added confirmation on delete operations --- cmd/root.go | 14 ++++++++++++++ cmd/scheduler.go | 11 ++++++++++- cmd/task_metadata.go | 8 ++++++++ cmd/webhook_metadata.go | 6 ++++++ cmd/workflow_metadata.go | 9 +++++++++ 5 files changed, 47 insertions(+), 1 deletion(-) diff --git a/cmd/root.go b/cmd/root.go index 1a3de2b..5148bfc 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -41,6 +41,20 @@ var ( verbose bool yes bool ) + +// confirmDeletion prompts user for confirmation unless --yes flag is set +// Returns true if user confirms or --yes is set, false otherwise +func confirmDeletion(resourceType, resourceName string) bool { + if yes { + return true + } + + fmt.Printf("Are you sure you want to delete %s '%s'? (y/N): ", resourceType, resourceName) + var response string + fmt.Scanln(&response) + response = strings.ToLower(strings.TrimSpace(response)) + return response == "y" || response == "yes" +} var rootCmd = &cobra.Command{ Use: NAME, Short: "orkes", diff --git a/cmd/scheduler.go b/cmd/scheduler.go index 2eb91ea..f414d99 100644 --- a/cmd/scheduler.go +++ b/cmd/scheduler.go @@ -168,10 +168,19 @@ func deleteSchedule(cmd *cobra.Command, args []string) error { } for i := 0; i < len(args); i++ { - _, _, err := schedulerClient.DeleteSchedule(context.Background(), args[i]) + name := args[i] + + // Confirm deletion + if !confirmDeletion("schedule", name) { + fmt.Printf("Skipping deletion of schedule '%s'\n", name) + continue + } + + _, _, err := schedulerClient.DeleteSchedule(context.Background(), name) if err != nil { return err } + fmt.Printf("Schedule '%s' deleted successfully\n", name) } return nil } diff --git a/cmd/task_metadata.go b/cmd/task_metadata.go index 78f32ef..4f8ed56 100644 --- a/cmd/task_metadata.go +++ b/cmd/task_metadata.go @@ -204,10 +204,18 @@ func deleteTaskMetadata(cmd *cobra.Command, args []string) error { } for i := 0; i < len(args); i++ { name := args[i] + + // Confirm deletion + if !confirmDeletion("task", name) { + fmt.Printf("Skipping deletion of task '%s'\n", name) + continue + } + _, err := metadataClient.UnregisterTaskDef(context.Background(), name) if err != nil { return err } + fmt.Printf("Task '%s' deleted successfully\n", name) } return nil diff --git a/cmd/webhook_metadata.go b/cmd/webhook_metadata.go index 1796666..9b04385 100644 --- a/cmd/webhook_metadata.go +++ b/cmd/webhook_metadata.go @@ -96,6 +96,12 @@ func delete(cmd *cobra.Command, args []string) error { return cmd.Usage() } + // Confirm deletion + if !confirmDeletion("webhook", id) { + fmt.Println("Deletion cancelled") + return nil + } + webhookClient := internal.GetWebhooksConfigClient() _, err := webhookClient.DeleteWebhook(context.Background(), id) if err != nil { diff --git a/cmd/workflow_metadata.go b/cmd/workflow_metadata.go index 46cc475..d12feaa 100644 --- a/cmd/workflow_metadata.go +++ b/cmd/workflow_metadata.go @@ -323,10 +323,19 @@ func _deleteWorkflowMetadata(cmd *cobra.Command, args []string) error { if err != nil { return err } + + // Confirm deletion + resourceName := fmt.Sprintf("%s version %d", name, version) + if !confirmDeletion("workflow", resourceName) { + fmt.Println("Deletion cancelled") + return nil + } + _, err = metadataClient.UnregisterWorkflowDef(context.Background(), name, int32(version)) if err != nil { return parseAPIError(err, fmt.Sprintf("Failed to delete workflow '%s' version %d", name, version)) } + fmt.Printf("Workflow '%s' version %d deleted successfully\n", name, version) return nil } From 28cd78ca72314725153f8a7a5d14c94de1bb41ba Mon Sep 17 00:00:00 2001 From: Miguel Prieto Date: Mon, 13 Oct 2025 15:21:46 -0300 Subject: [PATCH 2/3] Confirm deletion of workflow execution --- cmd/workflow_run.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/cmd/workflow_run.go b/cmd/workflow_run.go index c0cab35..cae0568 100644 --- a/cmd/workflow_run.go +++ b/cmd/workflow_run.go @@ -466,6 +466,12 @@ func deleteWorkflowExecution(cmd *cobra.Command, args []string) error { for i := 0; i < len(args); i++ { workflowId := args[i] + // Confirm deletion + if !confirmDeletion("workflow execution", workflowId) { + fmt.Printf("Skipping deletion of workflow execution '%s'\n", workflowId) + continue + } + options := &client.WorkflowResourceApiDeleteOpts{ ArchiveWorkflow: optional.NewBool(archive), } From c1f73eacc7018a8ba3b515b3b4b0d67d94491224 Mon Sep 17 00:00:00 2001 From: Miguel Prieto Date: Mon, 13 Oct 2025 15:25:22 -0300 Subject: [PATCH 3/3] Fix E2E tests --- test/e2e/rerun.bats | 6 ++++-- test/e2e/schedule.bats | 41 +++++++++++++++++++++++++++++++++-------- test/e2e/webhook.bats | 2 +- test/e2e/workflow.bats | 7 +++++-- 4 files changed, 43 insertions(+), 13 deletions(-) diff --git a/test/e2e/rerun.bats b/test/e2e/rerun.bats index e92e53c..aab2295 100755 --- a/test/e2e/rerun.bats +++ b/test/e2e/rerun.bats @@ -109,14 +109,16 @@ get_workflow_id() { WORKFLOW_ID=$(cat /tmp/rerun_workflow_id.txt) [ -n "$WORKFLOW_ID" ] - run bash -c "./orkes execution delete '$WORKFLOW_ID' 2>/dev/null" + run bash -c "./orkes execution delete '$WORKFLOW_ID' -y 2>/dev/null" echo "Output: $output" [ "$status" -eq 0 ] + [[ "$output" == *"deleted successfully"* ]] echo "Deleted workflow UUID: $WORKFLOW_ID" } @test "8. Cleanup - Delete workflow definition" { - run bash -c "./orkes workflow delete '$WORKFLOW_NAME' 1 2>/dev/null" + run bash -c "./orkes workflow delete '$WORKFLOW_NAME' 1 -y 2>/dev/null" echo "Output: $output" [ "$status" -eq 0 ] + [[ "$output" == *"deleted successfully"* ]] } diff --git a/test/e2e/schedule.bats b/test/e2e/schedule.bats index e2f8a78..9eb1be1 100644 --- a/test/e2e/schedule.bats +++ b/test/e2e/schedule.bats @@ -11,16 +11,16 @@ setup() { fi # Clean up any existing test schedules - ./orkes schedule delete e2e-test-schedule 2>/dev/null || true - ./orkes schedule delete e2e-test-schedule-2 2>/dev/null || true - ./orkes schedule delete e2e-test-paused 2>/dev/null || true + ./orkes schedule delete e2e-test-schedule -y 2>/dev/null || true + ./orkes schedule delete e2e-test-schedule-2 -y 2>/dev/null || true + ./orkes schedule delete e2e-test-paused -y 2>/dev/null || true } teardown() { # Clean up test schedules after each test - ./orkes schedule delete e2e-test-schedule 2>/dev/null || true - ./orkes schedule delete e2e-test-schedule-2 2>/dev/null || true - ./orkes schedule delete e2e-test-paused 2>/dev/null || true + ./orkes schedule delete e2e-test-schedule -y 2>/dev/null || true + ./orkes schedule delete e2e-test-schedule-2 -y 2>/dev/null || true + ./orkes schedule delete e2e-test-paused -y 2>/dev/null || true } @test "1. Create schedule with flags" { @@ -96,10 +96,11 @@ teardown() { run bash -c "./orkes schedule get e2e-test-schedule 2>/dev/null" [ "$status" -eq 0 ] - # Delete it - run bash -c "./orkes schedule delete e2e-test-schedule 2>&1" + # Delete it with -y flag + run bash -c "./orkes schedule delete e2e-test-schedule -y 2>&1" echo "Delete output: $output" [ "$status" -eq 0 ] + [[ "$output" == *"deleted successfully"* ]] # Verify it's gone run bash -c "./orkes schedule get e2e-test-schedule 2>&1" @@ -236,3 +237,27 @@ teardown() { [[ "$output" == *"e2e-test-schedule"* ]] [[ "$output" == *"e2e-test-schedule-2"* ]] } + +@test "21. Delete without -y flag prompts for confirmation" { + # Create schedule + ./orkes schedule create -n e2e-test-schedule -c "0 0 * ? * *" -w hello_world 2>/dev/null + + # Try to delete without -y flag (should prompt and timeout in test) + run bash -c "echo 'n' | timeout 2 ./orkes schedule delete e2e-test-schedule 2>&1" + echo "Output: $output" + # Should contain confirmation prompt + [[ "$output" == *"Are you sure"* ]] +} + +@test "22. Delete with -y flag skips confirmation" { + # Create schedule + ./orkes schedule create -n e2e-test-schedule -c "0 0 * ? * *" -w hello_world 2>/dev/null + + # Delete with -y flag (no prompt) + run bash -c "./orkes schedule delete e2e-test-schedule -y 2>&1" + echo "Output: $output" + [ "$status" -eq 0 ] + # Should NOT contain confirmation prompt + [[ "$output" != *"Are you sure"* ]] + [[ "$output" == *"deleted successfully"* ]] +} diff --git a/test/e2e/webhook.bats b/test/e2e/webhook.bats index 23cede0..049f49a 100644 --- a/test/e2e/webhook.bats +++ b/test/e2e/webhook.bats @@ -124,7 +124,7 @@ EOF WEBHOOK_ID=$(cat /tmp/webhook_test_id.txt) [ -n "$WEBHOOK_ID" ] - run bash -c "./orkes webhook delete '$WEBHOOK_ID' 2>/dev/null" + run bash -c "./orkes webhook delete '$WEBHOOK_ID' -y 2>/dev/null" echo "Output: $output" [ "$status" -eq 0 ] diff --git a/test/e2e/workflow.bats b/test/e2e/workflow.bats index a879e90..498b15e 100644 --- a/test/e2e/workflow.bats +++ b/test/e2e/workflow.bats @@ -87,9 +87,10 @@ get_workflow_id() { WORKFLOW_ID=$(cat /tmp/workflow_id.txt) [ -n "$WORKFLOW_ID" ] - run bash -c "./orkes execution delete '$WORKFLOW_ID' 2>/dev/null" + run bash -c "./orkes execution delete '$WORKFLOW_ID' -y 2>/dev/null" echo "Output: $output" [ "$status" -eq 0 ] + [[ "$output" == *"deleted successfully"* ]] echo "Deleted workflow UUID: $WORKFLOW_ID" } @@ -108,8 +109,10 @@ get_workflow_id() { } @test "9. Cleanup - delete workflow definition" { - run bash -c "./orkes workflow delete '$WORKFLOW_NAME' 1 2>/dev/null" + run bash -c "./orkes workflow delete '$WORKFLOW_NAME' 1 -y 2>/dev/null" echo "Output: $output" + [ "$status" -eq 0 ] + [[ "$output" == *"deleted successfully"* ]] # Clean up the temp file rm -f /tmp/workflow_id.txt }