Skip to content

Commit c45f862

Browse files
committed
Merge #152: Refactor API: replace Warp with Axum
0c3ca87 refactor(api): [#143] remove duplicate code (Jose Celano) 1c72ac0 docs(api): [#143] remove deprecated comment (Jose Celano) b7c5144 refactor(api): [#143] change fn return type (Jose Celano) 02dfe3e refactor(api): [#143] rename response functions (Jose Celano) 6955666 docs(api): [#143] remove comment (Jose Celano) 6ddbdd9 docs(api): [#143] move comment (Jose Celano) 0940463 refactor(api): [#143] extract api mods (Jose Celano) 2a92b0a refactor(api): extract mod for API responses (Jose Celano) 6dd3c48 refactor(api): [#143] move API resources mod (Jose Celano) 77ec521 refactor(api): [#143] remove Warp API implementation (Jose Celano) 337e12e feat(api): [#143] replace Warp API with Axum implementation (Jose Celano) 8d32628 refactor(api): [#143] extract and rename functions (Jose Celano) 072f3d7 test(api): [#143] add more tests for invalid key id URL path param (Jose Celano) 2c222ee test(api): [#143] add test for invalid key duration URL path param (Jose Celano) 39c15c6 test(api): [#143] add test for invalid infohash URL path param (Jose Celano) aa2a2ef fix(api): [#143] do not fail trying to remove a whitelisted torrent twice (Jose Celano) 3bcbbc9 refactor(api): [#143] normalize test names for errrors (Jose Celano) 2da0719 test(api): [#143] add tests for authenticaation (Jose Celano) 517ffde fix(api): [#143] fix new Axum API enpoint when URL params are invalid (Jose Celano) c502c1d refactor(api): [#143] remove duplicate definition of axum router (Jose Celano) 504cb9e feat(api): the new Axum api uses the URL prefix /api too. (Jose Celano) 5d9dd9d refactor(api): extract asserts in tests (Jose Celano) 03ba166 feat(api): [#143] axum api. GET /api/keys/reload endpoint (Jose Celano) 6b2e3bc feat(api): [#143] axum api. DELETE /api/key/:key endpoint (Jose Celano) 0282e33 feat(api): [#143] axum api. POST /api/key/:seconds_valid endpoint (Jose Celano) a58d831 feat(api): [#143] axum api. GET /api/whitelist/reload endpoint (Jose Celano) 2ddf268 feat(api): [#143] axum api. DELETE /api/whitelist/:info_hash endpoint (Jose Celano) 5c5fcbd feat(api): [#143] axum api. POST /api/whitelist/:info_hash endpoint (Jose Celano) e1ed929 test(api): [#143] add tests for database failure (Jose Celano) 1515753 feat(api): [#143] axum api. GET /api/torrents endpoint (Jose Celano) c36b121 refactor(api): [#143] extract service tracker::services::torrent::get_torrents (Jose Celano) a806179 refactor(api): [#143] use extracted service in the Warp handler (Jose Celano) ded4d11 fix: clippy errors (Jose Celano) a649fe8 feat(api): [#143] axum api. GET /api/torrent/:info_hash endpoint. Not found case (Jose Celano) 2aebf9a test(api): [#143] add test for torrent not known response in GET /api/torrent/:info_hash endpoint (Jose Celano) 16d438d feat(api): [#143] axum api, WIP. GET /api/torrent/:info_hash endpoint (Jose Celano) fe4303c feat(api): [#143] SSL support for the new Axum API (Jose Celano) af51f77 feat(api): [#143] add new cargo dependency: axum-server (Jose Celano) 1395945 refactor(api): [#143] remove dummy api endpoint (Jose Celano) 43dbed9 feat(api): [#143] authentication with GET param for Axum API (Jose Celano) 1c6db6e test: [#143] add tests for extracted functions (Jose Celano) 0f99f7b refactor: [#143] remove duplicate or unneeded code (Jose Celano) 0615c9f refactor(api): [#143] remove duplicate code (Jose Celano) 7331c82 refactor: [#143] replace unwrap with expect (Jose Celano) 6a9e2d5 feat(api): [#143] axum api, GET /stats endpoint (Jose Celano) 5ee3f93 refactor(api): [#143] extract mods for API testing (Jose Celano) cbf8837 feat(api): [#143] scaffolding for new API using Axum (Jose Celano) 901bc34 feat: [#143] add axum dependency (Jose Celano) Pull request description: **UPDATED**: 12/01/2022 The tracker API uses the web framework [Warp](https://github.com/seanmonstar/warp). This PR replaces Warp with [Axum](https://github.com/tokio-rs/axum). ### Tasks - [x] Basic Axum configuration. - [x] Authentication using token in GET params. - [x] Enable SSL. - [x] Add tests for the current API. Error cases are not tested. I think all cases are when there is a database error, and it returns an `ActionStatus::Err` error with a message. - [x] Reimplement endpoints. See subtasks. - [x] Improve asserts by checking the response body for OK (`200`) responses. - [x] Use the same URL prefix as the current API `/api/xxx`. - [x] Remove duplicate definitions of routes in Axum server (`start` and `start_tls`) - [x] Add tests for the current API. Error cases when GET params cannot be parsed are not tested. `info_hash` and `seconds_valid` Path params, and `offset` and `limit` GET params. - [x] Fix a bug with the auth `token`. The token must be the first param in the `query` otherwise, it does not work. In the end, it was not a bug. It only happens with `curl`. - [x] Add test for the current API. When you try to remove a torrent from the whitelist twice, you get a 500 response with this body : `Unhandled rejection: Err { reason: "failed to remove torrent from whitelist" }` - [x] Add some tests for malicious user input. - [x] Remove the Warp implementation. ### Endpoints subtasks Stats: - [x] `GET /api/stats` Torrents: - [x] `GET /api/torrents?offset=:u32&limit=:u32` - [x] `GET /api/torrent/:info_hash` Whitelisted torrents: - [x] `POST /api/whitelist/:info_hash` - [x] `DELETE /api/whitelist/:info_hash` Whitelist commands: - [x] `GET /api/whitelist/reload` Keys: - [x] `POST /api/key/:seconds_valid` - [x] `DELETE /api/key/:key` Key commands - [x] `GET /api/keys/reload` ACKs for top commit: josecelano: ACK 0c3ca87 Tree-SHA512: 592930e7e0739de0038e2511e04668b42bba632b8531e60298e5092e68a8dc252a12604f3fa93157595cb0f0ab71a12b06fdfa324eeaa5762b45232a11523aac
2 parents d79f58b + 0c3ca87 commit c45f862

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+2492
-957
lines changed

Cargo.lock

Lines changed: 162 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ async-trait = "0.1"
5858

5959
aquatic_udp_protocol = "0.2"
6060
uuid = { version = "1", features = ["v4"] }
61+
axum = "0.6.1"
62+
axum-server = { version = "0.4.4", features = ["tls-rustls"] }
6163

6264
[dev-dependencies]
6365
mockall = "0.11"

cSpell.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,14 @@
2626
"hlocalhost",
2727
"Hydranode",
2828
"incompletei",
29+
"infohash",
2930
"infoschema",
3031
"intervali",
3132
"leecher",
3233
"leechers",
3334
"libtorrent",
3435
"Lphant",
36+
"middlewares",
3537
"mockall",
3638
"myacicontext",
3739
"nanos",
@@ -48,6 +50,7 @@
4850
"rngs",
4951
"rusqlite",
5052
"rustfmt",
53+
"Rustls",
5154
"Seedable",
5255
"Shareaza",
5356
"sharktorrent",

src/api/mod.rs

Lines changed: 0 additions & 20 deletions
This file was deleted.

src/api/resource/mod.rs

Lines changed: 0 additions & 13 deletions
This file was deleted.

src/api/resource/stats.rs

Lines changed: 0 additions & 21 deletions
This file was deleted.

src/api/resource/torrent.rs

Lines changed: 0 additions & 21 deletions
This file was deleted.

0 commit comments

Comments
 (0)