-
Notifications
You must be signed in to change notification settings - Fork 43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
API overhaul: reimplement the current API using Axum #143
Comments
We are going to reimplement the API with Axum.
- Test scaffolding - Dummy entrypoint
Code for API testing have been reorganized.
hi @da2ce7 @WarmBeer, two questions:
Are we going to keep the current API version? This issue only changes Warp with Axum. I will break the API in the next issue: #144 We could keep both. Version I'm working on building the new Axum version without changing the current one. Once we move to Axum, it will be easy to add versions, all of them using Axum.
The API documentation is on the torrust.com site. If we want to generate the API docs automatically with, for example, the utopia crate we should do it soon. Maybe after finishing the Axum implementation while I'm implementing the new API. Here you have an example with Auxm: https://github.com/juhaku/utoipa/blob/master/examples/todo-axum/src/main.rs Since we have to maintain docs for multiple API versions I think it's a good idea to use a tool like that. On the other hand, the API is small and it should not change very often. |
- Extract domain logic: `Tracker::get_torrents_metrics`. - Move domain logic from web framework controllers to domain services: `get_metrics`. - Remove duplicate code in current Warp API and new Axum API.
- Extract domain logic: `Tracker::get_torrents_metrics`. - Move domain logic from web framework controllers to domain services: `get_metrics`. - Remove duplicate code in current Warp API and new Axum API.
It keeps the same contract of the API. It returns 500 status code with error message in "debug" format.
It was added to test Axum configuration.
The new API implementation uses Axum. Axum does not support SSL configuration. The "axum-server" crate provides it.
…ndpoint Not all cases finished yet. Not found case is pending.
…ET /api/torrent/:info_hash endpoint
…nt. Not found case
…nt::get_torrents It will be used in the new Axum implementaion for the API. In the API enpoint: ``` GET /api/torrents?offset=:u32&limit=:u32 ```
…rrent twice Previous behavior: When you try to remove a non exisinting whitelisted torrent the response is 500 error. New bahavior: The enpoints checks if the torrent is included in the whitelist. If it does not, then it ignores the reqeust returning a 200 code. It should return a 204 or 404 but the current API only uses these codes: 200, 400, 405, 500. In the new API version we are planning to refctor all endpoints.
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
Parent issue: #141
It depends on: #142
The text was updated successfully, but these errors were encountered: