Skip to content

Commit

Permalink
docs: [#974] update add key endpoint doc
Browse files Browse the repository at this point in the history
  • Loading branch information
josecelano committed Jul 30, 2024
1 parent 583b305 commit 04f50e4
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 deletions.
2 changes: 2 additions & 0 deletions src/servers/apis/v1/context/auth_key/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ pub async fn add_auth_key_handler(
///
/// Refer to the [API endpoint documentation](crate::servers::apis::v1::context::auth_key#generate-a-new-authentication-key)
/// for more information about this endpoint.
///
/// This endpoint has been deprecated. Use [`add_auth_key_handler`].
pub async fn generate_auth_key_handler(State(tracker): State<Arc<Tracker>>, Path(seconds_valid_or_key): Path<u64>) -> Response {
let seconds_valid = seconds_valid_or_key;
match tracker.generate_auth_key(Duration::from_secs(seconds_valid)).await {
Expand Down
21 changes: 15 additions & 6 deletions src/servers/apis/v1/context/auth_key/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
//! Authentication keys are used to authenticate HTTP tracker `announce` and
//! `scrape` requests.
//!
//! When the tracker is running in `private` or `private_listed` mode, the
//! authentication keys are required to announce and scrape torrents.
//! When the tracker is running in `private` mode, the authentication keys are
//! required to announce and scrape torrents.
//!
//! A sample `announce` request **without** authentication key:
//!
Expand All @@ -22,22 +22,31 @@
//!
//! # Generate a new authentication key
//!
//! `POST /key/:seconds_valid`
//! `POST /keys`
//!
//! It generates a new authentication key.
//! It generates a new authentication key or upload a pre-generated key.
//!
//! > **NOTICE**: keys expire after a certain amount of time.
//!
//! **Path parameters**
//! **POST parameters**
//!
//! Name | Type | Description | Required | Example
//! ---|---|---|---|---
//! `key` | 32-char string (0-9, a-z, A-Z) | The optional pre-generated key. | No | `Xc1L4PbQJSFGlrgSRZl8wxSFAuMa21z7`
//! `seconds_valid` | positive integer | The number of seconds the key will be valid. | Yes | `3600`
//!
//! > **NOTICE**: the `key` field is optional. If is not provided the tracker
//! > will generated a random one.
//!
//! **Example request**
//!
//! ```bash
//! curl -X POST "http://127.0.0.1:1212/api/v1/key/120?token=MyAccessToken"
//! curl -X POST http://localhost:1212/api/v1/keys?token=MyAccessToken \
//! -H "Content-Type: application/json" \
//! -d '{
//! "key": "xqD6NWH9TcKrOCwDmqcdH5hF5RrbL0A6",
//! "seconds_valid": 7200
//! }'
//! ```
//!
//! **Example response** `200`
Expand Down
8 changes: 6 additions & 2 deletions src/servers/apis/v1/context/auth_key/routes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,12 @@ pub fn add(prefix: &str, router: Router, tracker: Arc<Tracker>) -> Router {
.route(
// code-review: Axum does not allow two routes with the same path but different path variable name.
// In the new major API version, `seconds_valid` should be a POST form field so that we will have two paths:
// POST /key
// DELETE /key/:key
//
// POST /keys
// DELETE /keys/:key
//
// The POST /key/:seconds_valid has been deprecated and it will removed in the future.
// Use POST /keys
&format!("{prefix}/key/:seconds_valid_or_key"),
post(generate_auth_key_handler)
.with_state(tracker.clone())
Expand Down

0 comments on commit 04f50e4

Please sign in to comment.