Skip to content

Commit

Permalink
Merge #152: Refactor API: replace Warp with Axum
Browse files Browse the repository at this point in the history
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
  • Loading branch information
josecelano committed Jan 16, 2023
2 parents d79f58b + 0c3ca87 commit c45f862
Show file tree
Hide file tree
Showing 48 changed files with 2,492 additions and 957 deletions.
163 changes: 162 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ async-trait = "0.1"

aquatic_udp_protocol = "0.2"
uuid = { version = "1", features = ["v4"] }
axum = "0.6.1"
axum-server = { version = "0.4.4", features = ["tls-rustls"] }

[dev-dependencies]
mockall = "0.11"
Expand Down
3 changes: 3 additions & 0 deletions cSpell.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,14 @@
"hlocalhost",
"Hydranode",
"incompletei",
"infohash",
"infoschema",
"intervali",
"leecher",
"leechers",
"libtorrent",
"Lphant",
"middlewares",
"mockall",
"myacicontext",
"nanos",
Expand All @@ -48,6 +50,7 @@
"rngs",
"rusqlite",
"rustfmt",
"Rustls",
"Seedable",
"Shareaza",
"sharktorrent",
Expand Down
20 changes: 0 additions & 20 deletions src/api/mod.rs

This file was deleted.

13 changes: 0 additions & 13 deletions src/api/resource/mod.rs

This file was deleted.

21 changes: 0 additions & 21 deletions src/api/resource/stats.rs

This file was deleted.

21 changes: 0 additions & 21 deletions src/api/resource/torrent.rs

This file was deleted.

Loading

0 comments on commit c45f862

Please sign in to comment.