Skip to content

Conversation

@josecelano
Copy link
Member

@josecelano josecelano commented Jul 31, 2024

This PR introduces a new feature. Tracker keys can be permanent.

How to use the endpoint

Upload a pre-generated and expiring key

curl -X POST http://localhost:1212/api/v1/keys?token=MyAccessToken \
     -H "Content-Type: application/json" \
     -d '{
     	   "key": "Xc1L4PbQJSFGlrgSRZl8wxSFAuMa2110",
           "seconds_valid": 7200
         }'        

Upload a pre-generated and permanent key

curl -X POST http://localhost:1212/api/v1/keys?token=MyAccessToken \
     -H "Content-Type: application/json" \
     -d '{
     	   "key": "Xc1L4PbQJSFGlrgSRZl8wxSFAuMa2110",
           "seconds_valid": null
         }'        

Generate a random and expiring key

You can omit the key, and the tracker will generate a random one.

curl -X POST http://localhost:1212/api/v1/keys?token=MyAccessToken \
     -H "Content-Type: application/json" \
     -d '{
     	   "key": null,
           "seconds_valid": 7200
         }'        

Generate a random and permanent key

curl -X POST http://localhost:1212/api/v1/keys?token=MyAccessToken \
     -H "Content-Type: application/json" \
     -d '{
     	   "key": null,
           "seconds_valid": null
         }'        

NOTES

  • Fields in the json object are mandatory. You cannot omit them. Instead of omitting the field, I've decided to use the null value to represent the case where the value is not needed. I prefer to use always the same structure and make it explicit. However, omitting the field could have other advantages, like requiring less maintenance. For example, if we rename a field (breaking change), that would not affect users who are not using that field.
  • I've introduced manual database migrations. The second_valid column in the keys table is now nullable (for permanent keys).

We will add a new enpoint to add tracker keys where some JSON values can
be null:

```console
curl -X POST http://localhost:1212/api/v1/keys?token=MyAccessToken \
     -H "Content-Type: application/json" \
     -d '{
     	   "key": null,
           "seconds_valid": null
         }'
```

We need to set those values to `None` in the Rsut strucut.
@josecelano josecelano requested a review from da2ce7 July 31, 2024 14:39
@josecelano josecelano added this to the v3.0.0 milestone Jul 31, 2024
@josecelano josecelano self-assigned this Jul 31, 2024
@codecov
Copy link

codecov bot commented Jul 31, 2024

Codecov Report

Attention: Patch coverage is 52.94118% with 96 lines in your changes missing coverage. Please review.

Project coverage is 76.89%. Comparing base (1fdf3a8) to head (c5beff5).

Files Patch % Lines
src/core/mod.rs 54.68% 29 Missing ⚠️
src/core/databases/mysql.rs 0.00% 25 Missing ⚠️
src/core/databases/sqlite.rs 41.93% 18 Missing ⚠️
src/core/auth.rs 72.72% 9 Missing ⚠️
src/core/error.rs 0.00% 7 Missing ⚠️
src/servers/apis/v1/context/auth_key/resources.rs 82.14% 5 Missing ⚠️
src/servers/apis/v1/context/auth_key/handlers.rs 83.33% 2 Missing ⚠️
src/servers/apis/v1/context/auth_key/forms.rs 50.00% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop     #983      +/-   ##
===========================================
- Coverage    77.41%   76.89%   -0.52%     
===========================================
  Files          184      184              
  Lines         9812     9916     +104     
===========================================
+ Hits          7596     7625      +29     
- Misses        2216     2291      +75     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@josecelano josecelano force-pushed the 979-overhaul-tracker-keys-allow-permanent-keys branch from e1d2a4c to 2a438f0 Compare July 31, 2024 15:15
@josecelano josecelano force-pushed the 979-overhaul-tracker-keys-allow-permanent-keys branch from 2a438f0 to cb565b4 Compare July 31, 2024 15:27
@josecelano josecelano force-pushed the 979-overhaul-tracker-keys-allow-permanent-keys branch from 9e04951 to db9e2eb Compare July 31, 2024 16:47
@josecelano josecelano force-pushed the 979-overhaul-tracker-keys-allow-permanent-keys branch from db9e2eb to 6bcccd7 Compare July 31, 2024 16:52
@josecelano josecelano linked an issue Jul 31, 2024 that may be closed by this pull request
This commit adds a new feature. It allow creating permanent keys (keys
that do not expire).

THis is an example for making a request to the endpoint using curl:

```console
curl -X POST http://localhost:1212/api/v1/keys?token=MyAccessToken \
     -H "Content-Type: application/json" \
     -d '{
     	   "key": null,
           "seconds_valid": null
         }'
```

NOTICE: both the `key` and the `seconds_valid` fields can be null.

- If `key` is `null` a new random key will be generated. You can use an
  string with a pre-generated key like `Xc1L4PbQJSFGlrgSRZl8wxSFAuMa2110`. That will allow users to migrate to the Torrust Tracker wihtout forcing the users to re-start downloading/seeding with new keys.
- If `seconds_valid` is `null` the key will be permanent. Otherwise it
  will expire after the seconds specified in this value.
@josecelano josecelano force-pushed the 979-overhaul-tracker-keys-allow-permanent-keys branch from 6bcccd7 to c5beff5 Compare July 31, 2024 16:57
@josecelano josecelano marked this pull request as ready for review July 31, 2024 17:09
@josecelano
Copy link
Member Author

ACK c5beff5

@josecelano
Copy link
Member Author

Hi @da2ce7, this is ready for review.

@josecelano josecelano merged commit 680f642 into torrust:develop Aug 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Overhaul tracker keys: allow permanent keys

1 participant