|
| 1 | +<!-- SPDX-License-Identifier: PMPL-1.0-or-later --> |
| 2 | +<!-- Copyright (c) 2026 Jonathan D.A. Jewell (hyperpolymath) <j.d.a.jewell@open.ac.uk> --> |
| 3 | + |
| 4 | +# VeriSimDB REST Gateway |
| 5 | + |
| 6 | +V-lang HTTP gateway for the VeriSimDB hexad storage engine. Exposes a |
| 7 | +JSON REST API on port **9090** for storing and querying hexads produced by |
| 8 | +[panic-attack](https://github.com/hyperpolymath/panic-attacker) and other |
| 9 | +tools in the hyperpolymath ecosystem. |
| 10 | + |
| 11 | +Hexads are persisted as individual JSON files under a configurable data |
| 12 | +directory (no external database required). |
| 13 | + |
| 14 | +## Building and Running |
| 15 | + |
| 16 | +```bash |
| 17 | +# From this directory: |
| 18 | +cd developer-ecosystem/v-ecosystem/v-api-interfaces/verisimdb-rest |
| 19 | + |
| 20 | +# Run directly (development): |
| 21 | +v run src/rest.v |
| 22 | + |
| 23 | +# Compile then run (production): |
| 24 | +v -o verisimdb-rest src/rest.v |
| 25 | +./verisimdb-rest |
| 26 | +``` |
| 27 | + |
| 28 | +The server starts on port **9090** by default. |
| 29 | + |
| 30 | +### Environment Variables |
| 31 | + |
| 32 | +| Variable | Default | Description | |
| 33 | +|---|---|---| |
| 34 | +| `VERISIMDB_DATA_DIR` | `verisimdb-data/hexads` | Directory where hexad JSON files are stored | |
| 35 | + |
| 36 | +## API Endpoints |
| 37 | + |
| 38 | +### `GET /` — API Discovery |
| 39 | + |
| 40 | +Returns service metadata and available endpoints. |
| 41 | + |
| 42 | +```json |
| 43 | +{ |
| 44 | + "service": "verisimdb-rest", |
| 45 | + "version": "1.0.0", |
| 46 | + "description": "VeriSimDB hexad storage gateway for panic-attack", |
| 47 | + "endpoints": ["/api/v1/hexads", "/api/v1/hexads/batch", "/api/v1/hexads/:id", "/api/v1/health"] |
| 48 | +} |
| 49 | +``` |
| 50 | + |
| 51 | +### `GET /api/v1/health` — Health Check |
| 52 | + |
| 53 | +Returns gateway health status including stored hexad count. |
| 54 | + |
| 55 | +```json |
| 56 | +{ |
| 57 | + "healthy": true, |
| 58 | + "service": "verisimdb-rest", |
| 59 | + "hexad_count": 42, |
| 60 | + "latest_hexad": "pa-20260308120000-0019a3e8f0c00", |
| 61 | + "data_dir": "verisimdb-data/hexads" |
| 62 | +} |
| 63 | +``` |
| 64 | + |
| 65 | +### `POST /api/v1/hexads` — Store Single Hexad |
| 66 | + |
| 67 | +Stores a single hexad. The request body must be a JSON object with an `id` |
| 68 | +field. |
| 69 | + |
| 70 | +**Request:** |
| 71 | + |
| 72 | +```bash |
| 73 | +curl -X POST http://localhost:9090/api/v1/hexads \ |
| 74 | + -H "Content-Type: application/json" \ |
| 75 | + -d '{"schema":"verisimdb.hexad.v1","id":"pa-20260308-abc","provenance":{"tool":"panic-attack","version":"2.1.0","program_path":"/src","language":"Rust"},"semantic":{"total_weak_points":5,"critical_count":1,"high_count":2,"total_crashes":0,"robustness_score":0.85,"categories":["UnsafeCode","PanicPath"]},"document":{}}' |
| 76 | +``` |
| 77 | + |
| 78 | +**Response (201):** |
| 79 | + |
| 80 | +```json |
| 81 | +{"stored": true, "id": "pa-20260308-abc", "path": "verisimdb-data/hexads/pa-20260308-abc.json"} |
| 82 | +``` |
| 83 | + |
| 84 | +### `POST /api/v1/hexads/batch` — Store Multiple Hexads |
| 85 | + |
| 86 | +Stores an array of hexads in one request. Each element must have an `id` field. |
| 87 | + |
| 88 | +**Request:** |
| 89 | + |
| 90 | +```bash |
| 91 | +curl -X POST http://localhost:9090/api/v1/hexads/batch \ |
| 92 | + -H "Content-Type: application/json" \ |
| 93 | + -d '[{"schema":"verisimdb.hexad.v1","id":"h1","provenance":{"tool":"panic-attack","version":"2.1.0","program_path":"/a","language":"Rust"},"semantic":{"total_weak_points":1,"critical_count":0,"high_count":0,"total_crashes":0,"robustness_score":0.99,"categories":[]},"document":{}},{"schema":"verisimdb.hexad.v1","id":"h2","provenance":{"tool":"panic-attack","version":"2.1.0","program_path":"/b","language":"Gleam"},"semantic":{"total_weak_points":0,"critical_count":0,"high_count":0,"total_crashes":0,"robustness_score":1.0,"categories":[]},"document":{}}]' |
| 94 | +``` |
| 95 | + |
| 96 | +**Response (201):** |
| 97 | + |
| 98 | +```json |
| 99 | +{"stored": 2, "ids": ["h1", "h2"]} |
| 100 | +``` |
| 101 | + |
| 102 | +### `GET /api/v1/hexads` — Query Hexads |
| 103 | + |
| 104 | +Returns stored hexads, optionally filtered by tool name. |
| 105 | + |
| 106 | +| Parameter | Type | Default | Description | |
| 107 | +|---|---|---|---| |
| 108 | +| `tool` | string | *(none)* | Filter by `provenance.tool` value | |
| 109 | +| `limit` | int | 100 | Maximum number of results | |
| 110 | + |
| 111 | +**Request:** |
| 112 | + |
| 113 | +```bash |
| 114 | +curl "http://localhost:9090/api/v1/hexads?tool=panic-attack&limit=10" |
| 115 | +``` |
| 116 | + |
| 117 | +**Response (200):** |
| 118 | + |
| 119 | +```json |
| 120 | +{ |
| 121 | + "hexads": [ { ... }, { ... } ], |
| 122 | + "count": 2 |
| 123 | +} |
| 124 | +``` |
| 125 | + |
| 126 | +### `GET /api/v1/hexads/:id` — Get Hexad by ID |
| 127 | + |
| 128 | +Retrieves a single hexad by its ID. |
| 129 | + |
| 130 | +```bash |
| 131 | +curl http://localhost:9090/api/v1/hexads/pa-20260308-abc |
| 132 | +``` |
| 133 | + |
| 134 | +Returns the full hexad JSON (200) or `{"error":"Hexad not found"}` (404). |
| 135 | + |
| 136 | +## Hexad JSON Format |
| 137 | + |
| 138 | +The hexad is the VeriSimDB unit of storage. For panic-attack reports it |
| 139 | +contains six facets: |
| 140 | + |
| 141 | +```json |
| 142 | +{ |
| 143 | + "schema": "verisimdb.hexad.v1", |
| 144 | + "id": "pa-20260308120000-0019a3e8f0c00", |
| 145 | + "created_at": "2026-03-08T12:00:00Z", |
| 146 | + "provenance": { |
| 147 | + "tool": "panic-attack", |
| 148 | + "version": "2.1.0", |
| 149 | + "program_path": "/path/to/scanned/repo", |
| 150 | + "language": "Rust", |
| 151 | + "attestation_hash": null |
| 152 | + }, |
| 153 | + "semantic": { |
| 154 | + "total_weak_points": 7, |
| 155 | + "critical_count": 1, |
| 156 | + "high_count": 2, |
| 157 | + "total_crashes": 0, |
| 158 | + "robustness_score": 0.78, |
| 159 | + "categories": ["UnsafeCode", "PanicPath", "UnsafeFFI"], |
| 160 | + "migration": null |
| 161 | + }, |
| 162 | + "document": { |
| 163 | + "program_path": "/path/to/scanned/repo", |
| 164 | + "total_files_scanned": 42, |
| 165 | + "total_weak_points": 7 |
| 166 | + } |
| 167 | +} |
| 168 | +``` |
| 169 | + |
| 170 | +### Facet Summary |
| 171 | + |
| 172 | +| Facet | Field | Content | |
| 173 | +|---|---|---| |
| 174 | +| **Identity** | `id` | Unique ID (timestamp + hash) | |
| 175 | +| **Temporal** | `created_at` | ISO 8601 creation timestamp | |
| 176 | +| **Provenance** | `provenance` | Tool name, version, scan parameters | |
| 177 | +| **Semantic** | `semantic` | Weak point counts, severity breakdown, categories | |
| 178 | +| **Document** | `document` | Full JSON-encoded AssaultReport | |
| 179 | +| **Structural** | *(embedded)* | Dependency graph edges in the document payload | |
| 180 | + |
| 181 | +## Connecting panic-attack |
| 182 | + |
| 183 | +panic-attack can push hexads to this gateway via HTTP when built with the |
| 184 | +`http` feature flag: |
| 185 | + |
| 186 | +```bash |
| 187 | +# Build panic-attack with HTTP support |
| 188 | +cargo build --release --features http |
| 189 | + |
| 190 | +# Set the gateway URL (defaults to http://localhost:9090) |
| 191 | +export VERISIM_API_URL=http://localhost:9090 |
| 192 | + |
| 193 | +# Run a scan — results are pushed to VeriSimDB automatically |
| 194 | +panic-attack assail /path/to/repo --storage verisimdb |
| 195 | +``` |
| 196 | + |
| 197 | +### Environment Variables (panic-attack side) |
| 198 | + |
| 199 | +| Variable | Default | Description | |
| 200 | +|---|---|---| |
| 201 | +| `VERISIM_API_URL` | `http://localhost:9090` | Gateway base URL | |
| 202 | +| `VERISIM_GATEWAY_URL` | `http://localhost:9090` | Alias (used by `push_hexad_with_fallback`) | |
| 203 | +| `VERISIM_API_TOKEN` | *(none)* | Optional Bearer token for auth | |
| 204 | + |
| 205 | +When the gateway is unreachable, panic-attack falls back to writing hexad |
| 206 | +files locally under `verisimdb-data/hexads/`. |
| 207 | + |
| 208 | +## E2E Integration Test |
| 209 | + |
| 210 | +An end-to-end test script lives in the panic-attacker repo: |
| 211 | + |
| 212 | +```bash |
| 213 | +cd panic-attacker |
| 214 | + |
| 215 | +# Run the test (skips gracefully if gateway is not running): |
| 216 | +just e2e-verisimdb |
| 217 | + |
| 218 | +# Or directly: |
| 219 | +bash tests/verisimdb_e2e.sh |
| 220 | +``` |
| 221 | + |
| 222 | +The test creates sample hexads, POSTs them to the gateway, queries them back, |
| 223 | +and verifies responses. It uses only `curl` and requires no compilation. |
0 commit comments