Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
11 changes: 10 additions & 1 deletion cmd/scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
8 changes: 8 additions & 0 deletions cmd/task_metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions cmd/webhook_metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
9 changes: 9 additions & 0 deletions cmd/workflow_metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
6 changes: 6 additions & 0 deletions cmd/workflow_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}
Expand Down
6 changes: 4 additions & 2 deletions test/e2e/rerun.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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"* ]]
}
41 changes: 33 additions & 8 deletions test/e2e/schedule.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"* ]]
}
2 changes: 1 addition & 1 deletion test/e2e/webhook.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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 ]

Expand Down
7 changes: 5 additions & 2 deletions test/e2e/workflow.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}

Expand All @@ -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
}
Loading