Skip to content

Commit 04f50e4

Browse files
committed
docs: [torrust#974] update add key endpoint doc
1 parent 583b305 commit 04f50e4

File tree

3 files changed

+23
-8
lines changed

3 files changed

+23
-8
lines changed

src/servers/apis/v1/context/auth_key/handlers.rs

+2
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ pub async fn add_auth_key_handler(
7575
///
7676
/// Refer to the [API endpoint documentation](crate::servers::apis::v1::context::auth_key#generate-a-new-authentication-key)
7777
/// for more information about this endpoint.
78+
///
79+
/// This endpoint has been deprecated. Use [`add_auth_key_handler`].
7880
pub async fn generate_auth_key_handler(State(tracker): State<Arc<Tracker>>, Path(seconds_valid_or_key): Path<u64>) -> Response {
7981
let seconds_valid = seconds_valid_or_key;
8082
match tracker.generate_auth_key(Duration::from_secs(seconds_valid)).await {

src/servers/apis/v1/context/auth_key/mod.rs

+15-6
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
//! Authentication keys are used to authenticate HTTP tracker `announce` and
44
//! `scrape` requests.
55
//!
6-
//! When the tracker is running in `private` or `private_listed` mode, the
7-
//! authentication keys are required to announce and scrape torrents.
6+
//! When the tracker is running in `private` mode, the authentication keys are
7+
//! required to announce and scrape torrents.
88
//!
99
//! A sample `announce` request **without** authentication key:
1010
//!
@@ -22,22 +22,31 @@
2222
//!
2323
//! # Generate a new authentication key
2424
//!
25-
//! `POST /key/:seconds_valid`
25+
//! `POST /keys`
2626
//!
27-
//! It generates a new authentication key.
27+
//! It generates a new authentication key or upload a pre-generated key.
2828
//!
2929
//! > **NOTICE**: keys expire after a certain amount of time.
3030
//!
31-
//! **Path parameters**
31+
//! **POST parameters**
3232
//!
3333
//! Name | Type | Description | Required | Example
3434
//! ---|---|---|---|---
35+
//! `key` | 32-char string (0-9, a-z, A-Z) | The optional pre-generated key. | No | `Xc1L4PbQJSFGlrgSRZl8wxSFAuMa21z7`
3536
//! `seconds_valid` | positive integer | The number of seconds the key will be valid. | Yes | `3600`
3637
//!
38+
//! > **NOTICE**: the `key` field is optional. If is not provided the tracker
39+
//! > will generated a random one.
40+
//!
3741
//! **Example request**
3842
//!
3943
//! ```bash
40-
//! curl -X POST "http://127.0.0.1:1212/api/v1/key/120?token=MyAccessToken"
44+
//! curl -X POST http://localhost:1212/api/v1/keys?token=MyAccessToken \
45+
//! -H "Content-Type: application/json" \
46+
//! -d '{
47+
//! "key": "xqD6NWH9TcKrOCwDmqcdH5hF5RrbL0A6",
48+
//! "seconds_valid": 7200
49+
//! }'
4150
//! ```
4251
//!
4352
//! **Example response** `200`

src/servers/apis/v1/context/auth_key/routes.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,12 @@ pub fn add(prefix: &str, router: Router, tracker: Arc<Tracker>) -> Router {
2121
.route(
2222
// code-review: Axum does not allow two routes with the same path but different path variable name.
2323
// In the new major API version, `seconds_valid` should be a POST form field so that we will have two paths:
24-
// POST /key
25-
// DELETE /key/:key
24+
//
25+
// POST /keys
26+
// DELETE /keys/:key
27+
//
28+
// The POST /key/:seconds_valid has been deprecated and it will removed in the future.
29+
// Use POST /keys
2630
&format!("{prefix}/key/:seconds_valid_or_key"),
2731
post(generate_auth_key_handler)
2832
.with_state(tracker.clone())

0 commit comments

Comments
 (0)