Skip to content
Open
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
5 changes: 5 additions & 0 deletions AGENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,17 @@ openhack-cli --json projects create --name "My App" [--slug my-app] [--org <orgI
openhack-cli --json scans list [<projectId>] [--limit 20] [--offset 0]
openhack-cli --json scans get <scanId> [--project <projectId>] [--findings/--no-findings]
openhack-cli --json scans trigger-full [<projectId>] [--branch main]
openhack-cli --json scans cancel <scanId> [--project <projectId>] [--yes]
```

`scans list --json` returns `{ "scans": [...], "consolidatedCounts": {...},
"pagination": {...} }`; each scan carries `scanStatus`, per-severity counts, and a
`findings` array. `scans get` includes the full per-finding breakdown.

`scans cancel` stops a pending or running scan. Interactive output asks for
confirmation unless `--yes` is passed; `--json` never prompts, so automation
cannot hang waiting for hidden input. A completed scan cannot be cancelled.

---

## 7. Project vulnerabilities (`vulns`)
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ openhack-cli auth logout # remove local credentials
| `auth` | `login`, `logout`, `status`/`whoami`, `token` | Manage credentials |
| `orgs` | `list`, `use <id\|slug>` | List / select organizations |
| `projects` | `list`, `get`, `use`, `create` | Manage projects |
| `scans` | `list`, `get <scan_id>`, `trigger-full` | View / trigger scans |
| `scans` | `list`, `get <scan_id>`, `trigger-full`, `cancel <scan_id>` | View, trigger, and cancel scans |
| `vulns` | `list`, `groups`, `report`, `get`, `edit` | View, report, and edit project vulnerabilities |
| `pentest` | `list`, `get`, `create` | Pentesting engagements |
| `pentest findings` | `[engagement]` | Findings in an engagement (defaults to latest) |
Expand Down
39 changes: 39 additions & 0 deletions openhack_cli/commands/scans.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,45 @@ def render(payload):
output.emit(ctx.obj, data, render)


@scans.command(name="cancel")
@click.argument("scan_id")
@click.option("--project", default=None, help="Project id (defaults to active).")
@click.option("--yes", "-y", is_flag=True,
help="Skip the confirmation prompt.")
@click.pass_context
def cancel_scan(ctx: click.Context, scan_id: str, project: str | None,
yes: bool) -> None:
"""Cancel a running or pending scan.

Stops the underlying workflow and marks the scan cancelled. Scans that
already finished cannot be cancelled.
"""
project_id = resolve_project_id(ctx, project)

# Prompt on an interactive run, but never when scripting: --json is the
# machine-readable mode and a hidden prompt would hang it.
if not yes and not ctx.obj.get("json"):
click.confirm(f"Cancel scan {scan_id}?", abort=True)

client = get_client(ctx)
data = client.post(f"/api/projects/{project_id}/scans/{scan_id}/cancel", json={})

def render(payload):
scan = payload.get("scan", {}) if isinstance(payload, dict) else {}
# The workflow may already have been gone — the scan is still marked
# cancelled, so report which actually happened rather than implying we
# stopped something that was still running.
if payload.get("workflow_cancelled") is False:
output.success("Scan marked cancelled (it was no longer running).")
else:
output.success("Scan cancelled.")
if scan.get("number") is not None:
output.console.print(f" Scan: #{scan['number']}")
output.console.print(f" Status: {scan.get('scanStatus', 'cancelled')}")

output.emit(ctx.obj, data, render)


@scans.command(name="trigger-full")
@click.argument("project", required=False)
@click.option("--branch", default=None,
Expand Down
4 changes: 3 additions & 1 deletion openhack_cli/output.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@
"pending": "yellow",
"draft": "dim",
"failed": "red",
"cancelled": "red",
# A deliberate cancel is not a failure — the dashboard renders it muted, so
# don't colour it like an error here either.
"cancelled": "dim",
}


Expand Down
Loading