Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/axum-rest-api-server/src/routes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use axum::{BoxError, Router, middleware};
use hyper::{Request, StatusCode};
use torrust_server_lib::logging::Latency;
use torrust_tracker_configuration::AccessTokens;
use torrust_tracker_rest_api_runtime_adapter::container::TrackerHttpApiCoreContainer;
use torrust_tracker_rest_api_runtime_adapter::v1::container::TrackerHttpApiCoreContainer;
use tower::ServiceBuilder;
use tower::timeout::TimeoutLayer;
use tower_http::LatencyUnit;
Expand Down
4 changes: 2 additions & 2 deletions packages/axum-rest-api-server/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ use torrust_server_lib::signals::{Halted, Started};
use torrust_tracker_axum_server::custom_axum_server::{self, TimeoutAcceptor};
use torrust_tracker_axum_server::signals::graceful_shutdown;
use torrust_tracker_configuration::AccessTokens;
use torrust_tracker_rest_api_runtime_adapter::container::TrackerHttpApiCoreContainer;
use torrust_tracker_rest_api_runtime_adapter::v1::container::TrackerHttpApiCoreContainer;
use tracing::{Level, instrument};

use super::routes::router;
Expand Down Expand Up @@ -310,7 +310,7 @@ mod tests {
use torrust_server_lib::registar::Registar;
use torrust_tracker_axum_server::tsl::make_rust_tls;
use torrust_tracker_configuration::{Configuration, logging};
use torrust_tracker_rest_api_runtime_adapter::container::TrackerHttpApiCoreContainer;
use torrust_tracker_rest_api_runtime_adapter::v1::container::TrackerHttpApiCoreContainer;
use torrust_tracker_test_helpers::configuration::ephemeral_public;

use crate::server::{ApiServer, Launcher};
Expand Down
2 changes: 1 addition & 1 deletion packages/axum-rest-api-server/src/testing/environment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use torrust_tracker_core::container::TrackerCoreContainer;
use torrust_tracker_http_core::container::HttpTrackerCoreContainer;
use torrust_tracker_primitives::peer;
use torrust_tracker_rest_api_client::connection_info::{ConnectionInfo, Origin};
use torrust_tracker_rest_api_runtime_adapter::container::TrackerHttpApiCoreContainer;
use torrust_tracker_rest_api_runtime_adapter::v1::container::TrackerHttpApiCoreContainer;
use torrust_tracker_swarm_coordination_registry::container::SwarmCoordinationRegistryContainer;
use torrust_tracker_udp_core::container::UdpTrackerCoreContainer;
use torrust_tracker_udp_server::container::UdpTrackerServerContainer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::sync::Arc;
use axum::extract::{self, Path, State};
use axum::response::Response;
use serde::Deserialize;
use torrust_tracker_rest_api_application::use_cases::auth_key::AuthKeyApiService;
use torrust_tracker_rest_api_application::v1::use_cases::auth_key::AuthKeyApiService;
use torrust_tracker_rest_api_protocol::v1::context::auth_key::forms::add_key_form::AddKeyForm;

use super::responses::{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use std::sync::Arc;

use axum::Router;
use axum::routing::{get, post};
use torrust_tracker_rest_api_application::use_cases::auth_key::AuthKeyApiService;
use torrust_tracker_rest_api_application::v1::use_cases::auth_key::AuthKeyApiService;

use super::handlers::{add_auth_key_handler, delete_auth_key_handler, generate_auth_key_handler, reload_keys_handler};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::sync::Arc;
use axum::extract::{Query, State};
use axum::response::Response;
use serde::Deserialize;
use torrust_tracker_rest_api_application::use_cases::stats::StatsApiService;
use torrust_tracker_rest_api_application::v1::use_cases::stats::StatsApiService;

use super::responses::{labeled_metrics_response, labeled_stats_response, metrics_response, stats_response};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use std::sync::Arc;

use axum::Router;
use axum::routing::get;
use torrust_tracker_rest_api_application::use_cases::stats::StatsApiService;
use torrust_tracker_rest_api_application::v1::use_cases::stats::StatsApiService;

use super::handlers::{get_metrics_handler, get_stats_handler};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use serde::{Deserialize, Deserializer, de};
use thiserror::Error;
use torrust_info_hash::InfoHash;
use torrust_tracker_primitives::pagination::Pagination;
use torrust_tracker_rest_api_application::use_cases::torrent::TorrentApiService;
use torrust_tracker_rest_api_application::v1::use_cases::torrent::TorrentApiService;

use super::responses::{torrent_info_response, torrent_list_response, torrent_not_known_response};
use crate::InfoHashParam;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
//! API resources for the [`torrent`](crate::v1::context::torrent)
//! API context.
pub mod peer;
pub mod torrent;

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,67 +1,3 @@
//! `Torrent` and `ListItem` API resources.
//!
//! Protocol DTOs are defined in `torrust-tracker-rest-api-protocol`.
//! This module only contains unit tests for domain→DTO conversions.

#[cfg(test)]
mod tests {
use std::net::{IpAddr, Ipv4Addr, SocketAddr};
use std::str::FromStr;

use torrust_clock::DurationSinceUnixEpoch;
use torrust_info_hash::InfoHash;
use torrust_tracker_core::torrent::services::{BasicInfo, Info};
use torrust_tracker_primitives::{AnnounceEvent, NumberOfBytes, PeerId, peer};
use torrust_tracker_rest_api_protocol::v1::context::torrent::resources::torrent::{ListItem, Torrent};
use torrust_tracker_rest_api_runtime_adapter::conversion;

fn sample_peer() -> peer::Peer {
peer::Peer {
peer_id: PeerId(*b"-qB00000000000000000"),
peer_addr: SocketAddr::new(IpAddr::V4(Ipv4Addr::new(126, 0, 0, 1)), 8080),
updated: DurationSinceUnixEpoch::new(1_669_397_478_934, 0),
uploaded: NumberOfBytes::new(0),
downloaded: NumberOfBytes::new(0),
left: NumberOfBytes::new(0),
event: AnnounceEvent::Started,
}
}

#[test]
fn torrent_resource_should_be_converted_from_torrent_info() {
assert_eq!(
conversion::from_domain_info(Info {
info_hash: InfoHash::from_str("9e0217d0fa71c87332cd8bf9dbeabcb2c2cf3c4d").unwrap(), // DevSkim: ignore DS173237
seeders: 1,
completed: 2,
leechers: 3,
peers: Some(vec![sample_peer()]),
}),
Torrent {
info_hash: "9e0217d0fa71c87332cd8bf9dbeabcb2c2cf3c4d".to_string(), // DevSkim: ignore DS173237
seeders: 1,
completed: 2,
leechers: 3,
peers: Some(vec![conversion::from_domain_peer(sample_peer())]),
}
);
}

#[test]
fn torrent_resource_list_item_should_be_converted_from_the_basic_torrent_info() {
assert_eq!(
conversion::list_item_from_domain(&BasicInfo {
info_hash: InfoHash::from_str("9e0217d0fa71c87332cd8bf9dbeabcb2c2cf3c4d").unwrap(), // DevSkim: ignore DS173237
seeders: 1,
completed: 2,
leechers: 3,
}),
ListItem {
info_hash: "9e0217d0fa71c87332cd8bf9dbeabcb2c2cf3c4d".to_string(), // DevSkim: ignore DS173237
seeders: 1,
completed: 2,
leechers: 3,
}
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use std::sync::Arc;

use axum::Router;
use axum::routing::get;
use torrust_tracker_rest_api_application::use_cases::torrent::TorrentApiService;
use torrust_tracker_rest_api_application::v1::use_cases::torrent::TorrentApiService;

use super::handlers::{get_torrent_handler, get_torrents_handler};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::sync::Arc;
use axum::extract::{Path, State};
use axum::response::Response;
use torrust_info_hash::InfoHash;
use torrust_tracker_rest_api_application::use_cases::whitelist::WhitelistApiService;
use torrust_tracker_rest_api_application::v1::use_cases::whitelist::WhitelistApiService;

use super::responses::{
failed_to_reload_whitelist_response, failed_to_remove_torrent_from_whitelist_response, failed_to_whitelist_torrent_response,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use std::sync::Arc;

use axum::Router;
use axum::routing::{delete, get, post};
use torrust_tracker_rest_api_application::use_cases::whitelist::WhitelistApiService;
use torrust_tracker_rest_api_application::v1::use_cases::whitelist::WhitelistApiService;

use super::handlers::{add_torrent_to_whitelist_handler, reload_whitelist_handler, remove_torrent_from_whitelist_handler};

Expand Down
18 changes: 9 additions & 9 deletions packages/axum-rest-api-server/src/v1/routes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
use std::sync::Arc;

use axum::Router;
use torrust_tracker_rest_api_application::use_cases::auth_key::AuthKeyApiService;
use torrust_tracker_rest_api_application::use_cases::stats::StatsApiService;
use torrust_tracker_rest_api_application::use_cases::torrent::TorrentApiService;
use torrust_tracker_rest_api_application::use_cases::whitelist::WhitelistApiService;
use torrust_tracker_rest_api_runtime_adapter::adapters::auth_key::TrackerAuthKeyAdapter;
use torrust_tracker_rest_api_runtime_adapter::adapters::stats::TrackerStatsAdapter;
use torrust_tracker_rest_api_runtime_adapter::adapters::torrent::TrackerTorrentQueryAdapter;
use torrust_tracker_rest_api_runtime_adapter::adapters::whitelist::TrackerWhitelistAdapter;
use torrust_tracker_rest_api_runtime_adapter::container::TrackerHttpApiCoreContainer;
use torrust_tracker_rest_api_application::v1::use_cases::auth_key::AuthKeyApiService;
use torrust_tracker_rest_api_application::v1::use_cases::stats::StatsApiService;
use torrust_tracker_rest_api_application::v1::use_cases::torrent::TorrentApiService;
use torrust_tracker_rest_api_application::v1::use_cases::whitelist::WhitelistApiService;
use torrust_tracker_rest_api_runtime_adapter::v1::adapters::auth_key::TrackerAuthKeyAdapter;
use torrust_tracker_rest_api_runtime_adapter::v1::adapters::stats::TrackerStatsAdapter;
use torrust_tracker_rest_api_runtime_adapter::v1::adapters::torrent::TrackerTorrentQueryAdapter;
use torrust_tracker_rest_api_runtime_adapter::v1::adapters::whitelist::TrackerWhitelistAdapter;
use torrust_tracker_rest_api_runtime_adapter::v1::container::TrackerHttpApiCoreContainer;

use super::context::{auth_key, stats, torrent, whitelist};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use torrust_tracker_primitives::peer::fixture::PeerBuilder;
use torrust_tracker_rest_api_client::common::http::{Query, QueryParam};
use torrust_tracker_rest_api_client::v1::client::{Client, headers_with_request_id};
use torrust_tracker_rest_api_protocol::v1::context::torrent::resources::torrent::{self, Torrent};
use torrust_tracker_rest_api_runtime_adapter::conversion;
use torrust_tracker_rest_api_runtime_adapter::v1::conversion;
use torrust_tracker_test_helpers::logging::logs_contains_a_line_with;
use torrust_tracker_test_helpers::{configuration, logging};
use uuid::Uuid;
Expand Down
3 changes: 1 addition & 2 deletions packages/rest-api-application/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,4 @@
//! - Axum server routing or middleware.
//! - Tracker internal database or domain logic.
//! - Protocol DTOs (those belong to `rest-api-protocol`).
pub mod ports;
pub mod use_cases;
pub mod v1;
5 changes: 5 additions & 0 deletions packages/rest-api-application/src/v1/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
//! Version 1 of the Torrust Tracker REST API application layer.
//!
//! This module contains all v1-specific port traits and use-case services.
pub mod ports;
pub mod use_cases;
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use torrust_tracker_rest_api_protocol::v1::context::auth_key::forms::add_key_form::AddKeyForm;
use torrust_tracker_rest_api_protocol::v1::context::auth_key::resources::auth_key::{AuthKey, AuthKeyError};

use crate::ports::auth_key::AuthKeyPort;
use crate::v1::ports::auth_key::AuthKeyPort;

/// Use-case service for auth-key-related API operations.
///
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
//! Orchestrates calls to the [`StatsQueryPort`] to retrieve tracker metrics.
use torrust_tracker_rest_api_protocol::v1::context::stats::resources::stats::{LabeledStats, Stats};

use crate::ports::stats::StatsQueryPort;
use crate::v1::ports::stats::StatsQueryPort;

/// Use-case service for stats-related API operations.
///
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use torrust_info_hash::InfoHash;
use torrust_tracker_primitives::pagination::Pagination;
use torrust_tracker_rest_api_protocol::v1::context::torrent::resources::torrent::{ListItem, Torrent};

use crate::ports::torrent::TorrentQueryPort;
use crate::v1::ports::torrent::TorrentQueryPort;

/// Use-case service for torrent-related API operations.
///
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use torrust_info_hash::InfoHash;
use torrust_tracker_rest_api_protocol::v1::context::whitelist::resources::whitelist::WhitelistError;

use crate::ports::whitelist::WhitelistCommandPort;
use crate::v1::ports::whitelist::WhitelistCommandPort;

/// Use-case service for whitelist-related API operations.
///
Expand Down
3 changes: 3 additions & 0 deletions packages/rest-api-runtime-adapter/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,6 @@ torrust-metrics = "0.1.0"
torrust-info-hash = "=0.2.0"
async-trait = "0.1"
tokio = { version = "1", features = [ "sync" ] }

[dev-dependencies]
torrust-clock = "3.0.0"
4 changes: 1 addition & 3 deletions packages/rest-api-runtime-adapter/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,4 @@
//! - Protocol DTOs (those belong to `rest-api-protocol`).
//! - Use-case services (those belong to `rest-api-application`).
//! - Axum server routing or middleware.
pub mod adapters;
pub mod container;
pub mod conversion;
pub mod v1;
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::sync::Arc;
use async_trait::async_trait;
use torrust_tracker_core::authentication::handler::{AddKeyRequest, KeysHandler};
use torrust_tracker_core::authentication::{Key, PeerKey};
use torrust_tracker_rest_api_application::ports::auth_key::AuthKeyPort;
use torrust_tracker_rest_api_application::v1::ports::auth_key::AuthKeyPort;
use torrust_tracker_rest_api_protocol::v1::context::auth_key::forms::add_key_form::AddKeyForm;
use torrust_tracker_rest_api_protocol::v1::context::auth_key::resources::auth_key::{AuthKey, AuthKeyError};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use std::sync::Arc;
use async_trait::async_trait;
use torrust_metrics::metric_collection::MetricCollection;
use torrust_tracker_core::torrent::repository::in_memory::InMemoryTorrentRepository;
use torrust_tracker_rest_api_application::ports::stats::StatsQueryPort;
use torrust_tracker_rest_api_application::v1::ports::stats::StatsQueryPort;
use torrust_tracker_rest_api_protocol::v1::context::stats::resources::stats::{LabeledStats, Stats};
/// Adapter that queries all tracker-internal data sources and converts
/// domain types to protocol DTOs.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use torrust_info_hash::InfoHash;
use torrust_tracker_core::torrent::repository::in_memory::InMemoryTorrentRepository;
use torrust_tracker_core::torrent::services;
use torrust_tracker_primitives::pagination::Pagination;
use torrust_tracker_rest_api_application::ports::torrent::TorrentQueryPort;
use torrust_tracker_rest_api_application::v1::ports::torrent::TorrentQueryPort;
use torrust_tracker_rest_api_protocol::v1::context::torrent::resources::torrent::{ListItem, Torrent};

use super::super::conversion;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::sync::Arc;
use async_trait::async_trait;
use torrust_info_hash::InfoHash;
use torrust_tracker_core::whitelist::manager::WhitelistManager;
use torrust_tracker_rest_api_application::ports::whitelist::WhitelistCommandPort;
use torrust_tracker_rest_api_application::v1::ports::whitelist::WhitelistCommandPort;
use torrust_tracker_rest_api_protocol::v1::context::whitelist::resources::whitelist::WhitelistError;

/// Adapter that wraps [`WhitelistManager`] and implements the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,67 @@ pub fn list_item_from_domain(basic_info: &BasicInfo) -> ListItem {
leechers: basic_info.leechers,
}
}

#[cfg(test)]
mod tests {
use std::net::{IpAddr, Ipv4Addr, SocketAddr};
use std::str::FromStr;

use torrust_clock::DurationSinceUnixEpoch;
use torrust_info_hash::InfoHash;
use torrust_tracker_core::torrent::services::{BasicInfo, Info};
use torrust_tracker_primitives::{AnnounceEvent, NumberOfBytes, PeerId, peer};
use torrust_tracker_rest_api_protocol::v1::context::torrent::resources::torrent::{ListItem, Torrent};

use super::*;

fn sample_peer() -> peer::Peer {
peer::Peer {
peer_id: PeerId(*b"-qB00000000000000000"),
peer_addr: SocketAddr::new(IpAddr::V4(Ipv4Addr::new(126, 0, 0, 1)), 8080),
updated: DurationSinceUnixEpoch::new(1_669_397_478_934, 0),
uploaded: NumberOfBytes::new(0),
downloaded: NumberOfBytes::new(0),
left: NumberOfBytes::new(0),
event: AnnounceEvent::Started,
}
}

#[test]
fn torrent_resource_should_be_converted_from_torrent_info() {
assert_eq!(
from_domain_info(Info {
info_hash: InfoHash::from_str("9e0217d0fa71c87332cd8bf9dbeabcb2c2cf3c4d").unwrap(), // DevSkim: ignore DS173237
seeders: 1,
completed: 2,
leechers: 3,
peers: Some(vec![sample_peer()]),
}),
Torrent {
info_hash: "9e0217d0fa71c87332cd8bf9dbeabcb2c2cf3c4d".to_string(), // DevSkim: ignore DS173237
seeders: 1,
completed: 2,
leechers: 3,
peers: Some(vec![from_domain_peer(sample_peer())]),
}
);
}

#[test]
fn torrent_resource_list_item_should_be_converted_from_the_basic_torrent_info() {
assert_eq!(
list_item_from_domain(&BasicInfo {
info_hash: InfoHash::from_str("9e0217d0fa71c87332cd8bf9dbeabcb2c2cf3c4d").unwrap(), // DevSkim: ignore DS173237
seeders: 1,
completed: 2,
leechers: 3,
}),
ListItem {
info_hash: "9e0217d0fa71c87332cd8bf9dbeabcb2c2cf3c4d".to_string(), // DevSkim: ignore DS173237
seeders: 1,
completed: 2,
leechers: 3,
}
);
}
}
Loading
Loading