-
Notifications
You must be signed in to change notification settings - Fork 49
Closed
Labels
Code Cleanup / RefactoringTidying and Making NeatTidying and Making NeatEasyGood for NewcomersGood for Newcomers
Description
Module: auth.rs
We have two structs related to the authentication keys used by the HTTP tracker Key
and KeyId
:
pub struct Key {
pub key: String,
pub valid_until: Option<DurationSinceUnixEpoch>,
}
pub struct KeyId(String);
There is a pending refactor to use the KeyId
in the Key
struct like this:
pub struct Key {
pub key: KeyId,
pub valid_until: Option<DurationSinceUnixEpoch>,
}
pub struct KeyId(String);
I introduced the KeyId
struct because sometimes you need to create the ID, but you do not care about the expiration date. For example, in the handler to delete an auth key:
pub async fn delete_auth_key_handler(
State(tracker): State<Arc<Tracker>>,
Path(seconds_valid_or_key): Path<KeyIdParam>,
) -> Response {
match KeyId::from_str(&seconds_valid_or_key.0) {
Err(_) => invalid_auth_key_param_response(&seconds_valid_or_key.0),
Ok(key_id) => match tracker.remove_auth_key(&key_id.to_string()).await {
Ok(_) => ok_response(),
Err(_) => failed_to_delete_key_response(),
},
}
}
The handler receives the key ID, which is the ID that identifies the key.
I think there are two concepts:
- The token or key which is used to authenticate a client. It's just the secret.
- And the whole key, which is the secret or token with the extra metadata. In our case, only one extra field, which is the expiration date.
What could better names for those two structs @da2ce7 @WarmBeer?
I think we could use something like:
pub struct RegisteredKey {
pub key: KeyId,
pub valid_until: Option<DurationSinceUnixEpoch>,
}
pub struct Key(String);
or:
pub struct ExpiringKey {
pub key: KeyId,
pub valid_until: Option<DurationSinceUnixEpoch>,
}
pub struct Key(String);
Metadata
Metadata
Assignees
Labels
Code Cleanup / RefactoringTidying and Making NeatTidying and Making NeatEasyGood for NewcomersGood for Newcomers
Type
Projects
Status
No status