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
2 changes: 1 addition & 1 deletion kcidb-restd-rs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ version = "0.1.0"
edition = "2024"

[dependencies]
axum = { version = "0.8.3", features = ["tokio"] }
axum = { version = "0.8.3", features = ["tokio", "multipart"] }
axum-server = { version = "0.7.2", features = ["tls-rustls"] }
clap = { version = "4.5.35", features = ["derive"] }
jsonwebtoken = "9.3.1"
Expand Down
77 changes: 77 additions & 0 deletions kcidb-restd-rs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# kcidb-restd-rs

Simple REST receiver for KCIDB submissions and log uploads.

## Endpoints

### `POST /submit`
Accepts a JSON body and writes it to the spool directory as `submission-<id>.json`.
Authentication uses the JWT `origin` claim.

Example:
```bash
curl -X POST http://localhost:8080/submit \
-H "Authorization: Bearer <JWT>" \
-H "Content-Type: application/json" \
--data-binary @submission.json
```

### `POST /submitartifacts`
Accepts an artifact file via `multipart/form-data` and writes it to
`<spool>/artifacts/` with a filename:

`<origin>_<submission_id>_<filename>`

The `origin` is taken from the JWT. The `filename` is taken from the uploaded
file's multipart filename.

Required multipart fields:
- `submission_id` (string, `^[a-z0-9_]+$`, max 64 chars)
- `artifact` (file upload; multipart filename is used)
Only one `artifact` file is accepted per request; additional files are ignored.
If the `artifact` part includes a `Content-Length` header, it is validated against the received bytes; it is strongly recommended to include it for uploads.

The response is JSON:
```json
{"artifact_url":"https://files.kernelci.org/<origin>/<submission_id>/<filename>"}
```

Filename rules:
- The uploaded filename must match `^[a-z0-9_]+(\.[a-z0-9_]+)*$` (lowercase only).

The base URL can be overridden with:
```
KCIDB_STORAGE_URL="https://files-staging.kernelci.org/"
```

Example:
```bash
curl -X POST http://localhost:8080/submitartifacts \
-H "Authorization: Bearer <JWT>" \
-F "submission_id=abcd1234" \
-F "artifact=@./build.log.gz"
```

Example responses:
- Success (200):
```json
{"artifact_url":"https://files.kernelci.org/<origin>/abcd1234/build.log.gz"}
```
- Missing/invalid fields (400):
```json
{"id":"0","status":"error","message":"submission_id must match [a-z0-9_]+"}
```
- Unauthorized (401):
```json
{"id":"0","status":"error","message":"JWT is required"}
```
- Artifact already exists (409):
```json
{"id":"0","status":"error","message":"artifact file already exists"}
```

## Environment

- `JWT_SECRET`: JWT verification secret (required for auth unless empty).
- `KCIDB_STORAGE_URL`: Base URL used in `artifact_url` (default:
`https://files.kernelci.org`).
Loading