diff --git a/radicle-httpd/src/api.rs b/radicle-httpd/src/api.rs index 8c45aa30a..b3708d819 100644 --- a/radicle-httpd/src/api.rs +++ b/radicle-httpd/src/api.rs @@ -16,7 +16,7 @@ use tower_http::cors::{self, CorsLayer}; use radicle::cob::issue; use radicle::cob::patch; -use radicle::identity::{DocAt, Id}; +use radicle::identity::{DocAt, RepoId}; use radicle::node::policy::Scope; use radicle::node::routing::Store; use radicle::node::{Handle, NodeId}; @@ -52,7 +52,7 @@ impl Context { } } - pub fn project_info(&self, id: Id) -> Result { + pub fn project_info(&self, id: RepoId) -> Result { let storage = &self.profile.storage; let repo = storage.repository(id)?; let (_, head) = repo.head()?; @@ -196,7 +196,7 @@ mod project { use radicle::cob; use radicle::git::Oid; use radicle::identity::project::Project; - use radicle::identity::{Id, Visibility}; + use radicle::identity::{RepoId, Visibility}; use radicle::prelude::Did; /// Project info. @@ -211,13 +211,13 @@ mod project { pub head: Oid, pub patches: cob::patch::PatchCounts, pub issues: cob::issue::IssueCounts, - pub id: Id, + pub id: RepoId, pub seeding: usize, } } /// Announce refs to the network for the given RID. -pub fn announce_refs(mut node: Node, rid: Id) -> Result<(), Error> { +pub fn announce_refs(mut node: Node, rid: RepoId) -> Result<(), Error> { match node.announce_refs(rid) { Ok(_) => Ok(()), Err(e) if e.is_connection_err() => Ok(()), diff --git a/radicle-httpd/src/api/v1/node.rs b/radicle-httpd/src/api/v1/node.rs index ae100f6a1..4f17e8771 100644 --- a/radicle-httpd/src/api/v1/node.rs +++ b/radicle-httpd/src/api/v1/node.rs @@ -6,7 +6,7 @@ use axum_auth::AuthBearer; use hyper::StatusCode; use serde_json::json; -use radicle::identity::Id; +use radicle::identity::RepoId; use radicle::node::{policy, Handle, DEFAULT_TIMEOUT}; use radicle::Node; @@ -74,7 +74,7 @@ async fn node_policies_repos_handler(State(ctx): State) -> impl IntoRes async fn node_policies_seed_handler( State(ctx): State, AuthBearer(token): AuthBearer, - Path(project): Path, + Path(project): Path, Query(qs): Query, ) -> impl IntoResponse { api::auth::validate(&ctx, &token).await?; @@ -96,7 +96,7 @@ async fn node_policies_seed_handler( async fn node_policies_unseed_handler( State(ctx): State, AuthBearer(token): AuthBearer, - Path(project): Path, + Path(project): Path, ) -> impl IntoResponse { api::auth::validate(&ctx, &token).await?; let mut node = Node::new(ctx.profile.socket()); diff --git a/radicle-httpd/src/api/v1/projects.rs b/radicle-httpd/src/api/v1/projects.rs index b3a52ec66..16b054325 100644 --- a/radicle-httpd/src/api/v1/projects.rs +++ b/radicle-httpd/src/api/v1/projects.rs @@ -15,7 +15,7 @@ use serde_json::json; use tower_http::set_header::SetResponseHeaderLayer; use radicle::cob::{issue, patch, resolve_embed, Embed, Label, Uri}; -use radicle::identity::{Did, Id, Visibility}; +use radicle::identity::{Did, RepoId, Visibility}; use radicle::node::routing::Store; use radicle::node::{AliasStore, Node, NodeId}; use radicle::storage::git::paths; @@ -141,7 +141,7 @@ async fn project_root_handler( /// Get project metadata. /// `GET /projects/:project` -async fn project_handler(State(ctx): State, Path(id): Path) -> impl IntoResponse { +async fn project_handler(State(ctx): State, Path(id): Path) -> impl IntoResponse { let info = ctx.project_info(id)?; Ok::<_, Error>(Json(info)) @@ -161,7 +161,7 @@ pub struct CommitsQueryString { /// `GET /projects/:project/commits?since=` async fn history_handler( State(ctx): State, - Path(project): Path, + Path(project): Path, Query(qs): Query, ) -> impl IntoResponse { let CommitsQueryString { @@ -242,7 +242,7 @@ async fn history_handler( /// `GET /projects/:project/commits/:sha` async fn commit_handler( State(ctx): State, - Path((project, sha)): Path<(Id, Oid)>, + Path((project, sha)): Path<(RepoId, Oid)>, ) -> impl IntoResponse { let storage = &ctx.profile.storage; let repo = Repository::open(paths::repository(storage, &project))?; @@ -308,7 +308,7 @@ async fn commit_handler( /// `GET /projects/:project/diff/:base/:oid` async fn diff_handler( State(ctx): State, - Path((project, base, oid)): Path<(Id, Oid, Oid)>, + Path((project, base, oid)): Path<(RepoId, Oid, Oid)>, ) -> impl IntoResponse { let storage = &ctx.profile.storage; let repo = Repository::open(paths::repository(storage, &project))?; @@ -375,7 +375,7 @@ async fn diff_handler( /// `GET /projects/:project/activity` async fn activity_handler( State(ctx): State, - Path(project): Path, + Path(project): Path, ) -> impl IntoResponse { let current_date = chrono::Utc::now().timestamp(); let one_year_ago = chrono::Duration::weeks(52); @@ -402,7 +402,7 @@ async fn activity_handler( /// `GET /projects/:project/tree/:sha/` async fn tree_handler_root( State(ctx): State, - Path((project, sha)): Path<(Id, Oid)>, + Path((project, sha)): Path<(RepoId, Oid)>, ) -> impl IntoResponse { tree_handler(State(ctx), Path((project, sha, String::new()))).await } @@ -411,7 +411,7 @@ async fn tree_handler_root( /// `GET /projects/:project/tree/:sha/*path` async fn tree_handler( State(ctx): State, - Path((project, sha, path)): Path<(Id, Oid, String)>, + Path((project, sha, path)): Path<(RepoId, Oid, String)>, ) -> impl IntoResponse { if let Some(ref cache) = ctx.cache { let cache = &mut cache.tree.lock().await; @@ -436,7 +436,10 @@ async fn tree_handler( /// Get all project remotes. /// `GET /projects/:project/remotes` -async fn remotes_handler(State(ctx): State, Path(project): Path) -> impl IntoResponse { +async fn remotes_handler( + State(ctx): State, + Path(project): Path, +) -> impl IntoResponse { let storage = &ctx.profile.storage; let repo = storage.repository(project)?; let delegates = repo.delegates()?; @@ -478,7 +481,7 @@ async fn remotes_handler(State(ctx): State, Path(project): Path) -> /// `GET /projects/:project/remotes/:peer` async fn remote_handler( State(ctx): State, - Path((project, node_id)): Path<(Id, NodeId)>, + Path((project, node_id)): Path<(RepoId, NodeId)>, ) -> impl IntoResponse { let storage = &ctx.profile.storage; let repo = storage.repository(project)?; @@ -506,7 +509,7 @@ async fn remote_handler( /// `GET /projects/:project/blob/:sha/*path` async fn blob_handler( State(ctx): State, - Path((project, sha, path)): Path<(Id, Oid, String)>, + Path((project, sha, path)): Path<(RepoId, Oid, String)>, ) -> impl IntoResponse { let storage = &ctx.profile.storage; let repo = Repository::open(paths::repository(storage, &project))?; @@ -520,7 +523,7 @@ async fn blob_handler( /// `GET /projects/:project/readme/:sha` async fn readme_handler( State(ctx): State, - Path((project, sha)): Path<(Id, Oid)>, + Path((project, sha)): Path<(RepoId, Oid)>, ) -> impl IntoResponse { let storage = &ctx.profile.storage; let repo = Repository::open(paths::repository(storage, &project))?; @@ -551,7 +554,7 @@ async fn readme_handler( /// `GET /projects/:project/issues` async fn issues_handler( State(ctx): State, - Path(project): Path, + Path(project): Path, Query(qs): Query>, ) -> impl IntoResponse { let CobsQuery { @@ -599,7 +602,7 @@ pub struct IssueCreate { async fn issue_create_handler( State(ctx): State, AuthBearer(token): AuthBearer, - Path(project): Path, + Path(project): Path, Json(issue): Json, ) -> impl IntoResponse { api::auth::validate(&ctx, &token).await?; @@ -641,7 +644,7 @@ async fn issue_create_handler( async fn issue_update_handler( State(ctx): State, AuthBearer(token): AuthBearer, - Path((project, issue_id)): Path<(Id, Oid)>, + Path((project, issue_id)): Path<(RepoId, Oid)>, Json(action): Json, ) -> impl IntoResponse { api::auth::validate(&ctx, &token).await?; @@ -696,7 +699,7 @@ async fn issue_update_handler( /// `GET /projects/:project/issues/:id` async fn issue_handler( State(ctx): State, - Path((project, issue_id)): Path<(Id, Oid)>, + Path((project, issue_id)): Path<(RepoId, Oid)>, ) -> impl IntoResponse { let storage = &ctx.profile.storage; let repo = storage.repository(project)?; @@ -722,7 +725,7 @@ pub struct PatchCreate { async fn patch_create_handler( State(ctx): State, AuthBearer(token): AuthBearer, - Path(project): Path, + Path(project): Path, Json(patch): Json, ) -> impl IntoResponse { api::auth::validate(&ctx, &token).await?; @@ -761,7 +764,7 @@ async fn patch_create_handler( async fn patch_update_handler( State(ctx): State, AuthBearer(token): AuthBearer, - Path((project, patch_id)): Path<(Id, Oid)>, + Path((project, patch_id)): Path<(RepoId, Oid)>, Json(action): Json, ) -> impl IntoResponse { api::auth::validate(&ctx, &token).await?; @@ -901,7 +904,7 @@ async fn patch_update_handler( /// `GET /projects/:project/patches` async fn patches_handler( State(ctx): State, - Path(project): Path, + Path(project): Path, Query(qs): Query>, ) -> impl IntoResponse { let CobsQuery { @@ -938,7 +941,7 @@ async fn patches_handler( /// `GET /projects/:project/patches/:id` async fn patch_handler( State(ctx): State, - Path((project, patch_id)): Path<(Id, Oid)>, + Path((project, patch_id)): Path<(RepoId, Oid)>, ) -> impl IntoResponse { let storage = &ctx.profile.storage; let repo = storage.repository(project)?; diff --git a/radicle-httpd/src/cache.rs b/radicle-httpd/src/cache.rs index 172b3e03c..5b88f9ae4 100644 --- a/radicle-httpd/src/cache.rs +++ b/radicle-httpd/src/cache.rs @@ -4,12 +4,12 @@ use std::sync::Arc; use lru::LruCache; use tokio::sync::Mutex; -use radicle::prelude::Id; +use radicle::prelude::RepoId; use radicle_surf::Oid; #[derive(Clone)] pub struct Cache { - pub tree: Arc>>, + pub tree: Arc>>, } impl Cache { diff --git a/radicle-httpd/src/git.rs b/radicle-httpd/src/git.rs index 385d756a4..43d725b9a 100644 --- a/radicle-httpd/src/git.rs +++ b/radicle-httpd/src/git.rs @@ -16,19 +16,19 @@ use axum::Router; use flate2::write::GzDecoder; use hyper::body::Buf as _; -use radicle::identity::Id; +use radicle::identity::RepoId; use radicle::profile::Profile; use crate::error::GitError as Error; -pub fn router(profile: Arc, aliases: HashMap) -> Router { +pub fn router(profile: Arc, aliases: HashMap) -> Router { Router::new() .route("/:project/*request", any(git_handler)) .with_state((profile, aliases)) } async fn git_handler( - State((profile, aliases)): State<(Arc, HashMap)>, + State((profile, aliases)): State<(Arc, HashMap)>, AxumPath((project, request)): AxumPath<(String, String)>, method: Method, headers: HeaderMap, @@ -38,7 +38,7 @@ async fn git_handler( ) -> impl IntoResponse { let query = query.0.unwrap_or_default(); let name = project.strip_suffix(".git").unwrap_or(&project); - let rid: Id = match name.parse() { + let rid: RepoId = match name.parse() { Ok(rid) => rid, Err(_) => { let Some(rid) = aliases.get(name) else { @@ -70,7 +70,7 @@ async fn git_http_backend( headers: HeaderMap, mut body: Bytes, remote: net::SocketAddr, - id: Id, + id: RepoId, path: &str, query: String, ) -> Result<(StatusCode, HashMap>, Vec), Error> { @@ -210,7 +210,7 @@ mod routes { use axum::extract::connect_info::MockConnectInfo; use axum::http::StatusCode; - use radicle::identity::Id; + use radicle::identity::RepoId; use crate::test::{self, get, RID}; @@ -232,7 +232,7 @@ mod routes { let ctx = test::seed(tmp.path()); let app = super::router( ctx.profile().to_owned(), - HashMap::from_iter([(String::from("heartwood"), Id::from_str(RID).unwrap())]), + HashMap::from_iter([(String::from("heartwood"), RepoId::from_str(RID).unwrap())]), ) .layer(MockConnectInfo(SocketAddr::from(([0, 0, 0, 0], 8080)))); diff --git a/radicle-httpd/src/lib.rs b/radicle-httpd/src/lib.rs index 61822bc0a..299e56f22 100644 --- a/radicle-httpd/src/lib.rs +++ b/radicle-httpd/src/lib.rs @@ -21,7 +21,7 @@ use tokio::net::TcpListener; use tower_http::trace::TraceLayer; use tracing::Span; -use radicle::identity::Id; +use radicle::identity::RepoId; use radicle::Profile; use tracing_extra::{tracing_middleware, ColoredStatus, Paint, RequestId, TracingInfo}; @@ -40,7 +40,7 @@ pub const DEFAULT_CACHE_SIZE: NonZeroUsize = unsafe { NonZeroUsize::new_unchecke #[derive(Debug, Clone)] pub struct Options { - pub aliases: HashMap, + pub aliases: HashMap, pub listen: SocketAddr, pub cache: Option, } diff --git a/radicle-httpd/src/main.rs b/radicle-httpd/src/main.rs index 47be4e471..5a3304e4d 100644 --- a/radicle-httpd/src/main.rs +++ b/radicle-httpd/src/main.rs @@ -1,7 +1,7 @@ use std::num::NonZeroUsize; use std::{collections::HashMap, process}; -use radicle::prelude::Id; +use radicle::prelude::RepoId; use radicle_httpd as httpd; #[tokio::main] @@ -39,7 +39,7 @@ fn parse_options() -> Result { } Long("alias") | Short('a') => { let alias: String = parser.value()?.parse()?; - let id: Id = parser.value()?.parse()?; + let id: RepoId = parser.value()?.parse()?; aliases.insert(alias, id); } diff --git a/radicle-httpd/src/raw.rs b/radicle-httpd/src/raw.rs index 063fd9747..074e5b737 100644 --- a/radicle-httpd/src/raw.rs +++ b/radicle-httpd/src/raw.rs @@ -9,7 +9,7 @@ use axum::Router; use hyper::HeaderMap; use tower_http::cors; -use radicle::prelude::Id; +use radicle::prelude::RepoId; use radicle::profile::Profile; use radicle::storage::{ReadRepository, ReadStorage}; use radicle_surf::{Oid, Repository}; @@ -107,7 +107,7 @@ pub fn router(profile: Arc) -> Router { } async fn file_by_path_handler( - Path((project, sha, path)): Path<(Id, Oid, String)>, + Path((project, sha, path)): Path<(RepoId, Oid, String)>, State(profile): State>, ) -> impl IntoResponse { let storage = &profile.storage; @@ -134,7 +134,7 @@ async fn file_by_path_handler( } async fn file_by_oid_handler( - Path((project, oid)): Path<(Id, Oid)>, + Path((project, oid)): Path<(RepoId, Oid)>, State(profile): State>, Query(qs): Query, ) -> impl IntoResponse {