httpd: Update axum from 0.5.x to 0.6.x
Signed-off-by: xphoniex <dj.2dixx@gmail.com>
This commit is contained in:
parent
4ea67250ea
commit
7ec903d712
|
|
@ -148,9 +148,9 @@ checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "axum"
|
name = "axum"
|
||||||
version = "0.5.17"
|
version = "0.6.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "acee9fd5073ab6b045a275b3e709c163dd36c90685219cb21804a147b58dba43"
|
checksum = "1304eab461cf02bd70b083ed8273388f9724c549b316ba3d1e213ce0e9e7fb7e"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"async-trait",
|
"async-trait",
|
||||||
"axum-core",
|
"axum-core",
|
||||||
|
|
@ -167,8 +167,10 @@ dependencies = [
|
||||||
"mime",
|
"mime",
|
||||||
"percent-encoding",
|
"percent-encoding",
|
||||||
"pin-project-lite",
|
"pin-project-lite",
|
||||||
|
"rustversion",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
|
"serde_path_to_error",
|
||||||
"serde_urlencoded",
|
"serde_urlencoded",
|
||||||
"sync_wrapper",
|
"sync_wrapper",
|
||||||
"tokio",
|
"tokio",
|
||||||
|
|
@ -180,9 +182,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "axum-core"
|
name = "axum-core"
|
||||||
version = "0.2.9"
|
version = "0.3.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "37e5939e02c56fecd5c017c37df4238c0a839fa76b7f97acdd7efb804fd181cc"
|
checksum = "f487e40dc9daee24d8a1779df88522f159a54a980f99cfbe43db0be0bd3444a8"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"async-trait",
|
"async-trait",
|
||||||
"bytes",
|
"bytes",
|
||||||
|
|
@ -190,6 +192,7 @@ dependencies = [
|
||||||
"http",
|
"http",
|
||||||
"http-body",
|
"http-body",
|
||||||
"mime",
|
"mime",
|
||||||
|
"rustversion",
|
||||||
"tower-layer",
|
"tower-layer",
|
||||||
"tower-service",
|
"tower-service",
|
||||||
]
|
]
|
||||||
|
|
@ -1587,9 +1590,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "matchit"
|
name = "matchit"
|
||||||
version = "0.5.0"
|
version = "0.7.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "73cbba799671b762df5a175adf59ce145165747bb891505c43d09aefbbf38beb"
|
checksum = "b87248edafb776e59e6ee64a79086f65890d3510f2c656c000bf2a7e8a0aea40"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "memchr"
|
name = "memchr"
|
||||||
|
|
@ -2658,6 +2661,15 @@ dependencies = [
|
||||||
"serde",
|
"serde",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "serde_path_to_error"
|
||||||
|
version = "0.1.9"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "26b04f22b563c91331a10074bda3dd5492e3cc39d56bd557e91c0af42b6c7341"
|
||||||
|
dependencies = [
|
||||||
|
"serde",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "serde_urlencoded"
|
name = "serde_urlencoded"
|
||||||
version = "0.7.1"
|
version = "0.7.1"
|
||||||
|
|
|
||||||
|
|
@ -16,8 +16,8 @@ logfmt = [
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
anyhow = { version = "1" }
|
anyhow = { version = "1" }
|
||||||
axum = { version = "0.5.16", default-features = false, features = ["json", "headers", "query"] }
|
axum = { version = "0.6.2", default-features = false, features = ["headers", "json", "query", "tokio"] }
|
||||||
axum-server = { version = "0.4.2", default-features = false }
|
axum-server = { version = "0.4.4", default-features = false }
|
||||||
chrono = { version = "0.4.22" }
|
chrono = { version = "0.4.22" }
|
||||||
ethers-core = { version = "1.0" }
|
ethers-core = { version = "1.0" }
|
||||||
fastrand = { version = "1.7.0" }
|
fastrand = { version = "1.7.0" }
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
use axum::extract::path::ErrorKind;
|
use axum::extract::path::ErrorKind;
|
||||||
use axum::extract::rejection::{PathRejection, QueryRejection};
|
use axum::extract::rejection::{PathRejection, QueryRejection};
|
||||||
use axum::extract::{FromRequest, RequestParts};
|
use axum::extract::FromRequestParts;
|
||||||
|
use axum::http::request::Parts;
|
||||||
use axum::http::StatusCode;
|
use axum::http::StatusCode;
|
||||||
use axum::{async_trait, Json};
|
use axum::{async_trait, Json};
|
||||||
|
|
||||||
|
|
@ -10,15 +11,15 @@ use serde::Serialize;
|
||||||
pub struct Path<T>(pub T);
|
pub struct Path<T>(pub T);
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl<B, T> FromRequest<B> for Path<T>
|
impl<S, T> FromRequestParts<S> for Path<T>
|
||||||
where
|
where
|
||||||
T: DeserializeOwned + Send,
|
T: DeserializeOwned + Send,
|
||||||
B: Send,
|
S: Send + Sync,
|
||||||
{
|
{
|
||||||
type Rejection = (StatusCode, axum::Json<Error>);
|
type Rejection = (StatusCode, axum::Json<Error>);
|
||||||
|
|
||||||
async fn from_request(req: &mut RequestParts<B>) -> Result<Self, Self::Rejection> {
|
async fn from_request_parts(req: &mut Parts, state: &S) -> Result<Self, Self::Rejection> {
|
||||||
match axum::extract::Path::<T>::from_request(req).await {
|
match axum::extract::Path::<T>::from_request_parts(req, state).await {
|
||||||
Ok(value) => Ok(Self(value.0)),
|
Ok(value) => Ok(Self(value.0)),
|
||||||
Err(rejection) => {
|
Err(rejection) => {
|
||||||
let status = StatusCode::BAD_REQUEST;
|
let status = StatusCode::BAD_REQUEST;
|
||||||
|
|
@ -52,15 +53,15 @@ where
|
||||||
pub struct Query<T>(pub T);
|
pub struct Query<T>(pub T);
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl<B, T> FromRequest<B> for Query<T>
|
impl<S, T> FromRequestParts<S> for Query<T>
|
||||||
where
|
where
|
||||||
T: DeserializeOwned + Send,
|
T: DeserializeOwned + Send,
|
||||||
B: Send,
|
S: Send + Sync,
|
||||||
{
|
{
|
||||||
type Rejection = (StatusCode, axum::Json<Error>);
|
type Rejection = (StatusCode, axum::Json<Error>);
|
||||||
|
|
||||||
async fn from_request(req: &mut RequestParts<B>) -> Result<Self, Self::Rejection> {
|
async fn from_request_parts(req: &mut Parts, state: &S) -> Result<Self, Self::Rejection> {
|
||||||
match axum::extract::Query::<T>::from_request(req).await {
|
match axum::extract::Query::<T>::from_request_parts(req, state).await {
|
||||||
Ok(value) => Ok(Self(value.0)),
|
Ok(value) => Ok(Self(value.0)),
|
||||||
Err(rejection) => {
|
Err(rejection) => {
|
||||||
let status = StatusCode::BAD_REQUEST;
|
let status = StatusCode::BAD_REQUEST;
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
|
use axum::extract::State;
|
||||||
use axum::response::IntoResponse;
|
use axum::response::IntoResponse;
|
||||||
use axum::routing::get;
|
use axum::routing::get;
|
||||||
use axum::{Extension, Json, Router};
|
use axum::{Json, Router};
|
||||||
|
|
||||||
use radicle::cob::issue::Issues;
|
use radicle::cob::issue::Issues;
|
||||||
use radicle::identity::Did;
|
use radicle::identity::Did;
|
||||||
|
|
@ -18,13 +19,13 @@ pub fn router(ctx: Context) -> Router {
|
||||||
"/delegates/:delegate/projects",
|
"/delegates/:delegate/projects",
|
||||||
get(delegates_projects_handler),
|
get(delegates_projects_handler),
|
||||||
)
|
)
|
||||||
.layer(Extension(ctx))
|
.with_state(ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// List all projects which delegate is a part of.
|
/// List all projects which delegate is a part of.
|
||||||
/// `GET /delegates/:delegate/projects`
|
/// `GET /delegates/:delegate/projects`
|
||||||
async fn delegates_projects_handler(
|
async fn delegates_projects_handler(
|
||||||
Extension(ctx): Extension<Context>,
|
State(ctx): State<Context>,
|
||||||
Path(delegate): Path<Did>,
|
Path(delegate): Path<Did>,
|
||||||
Query(qs): Query<PaginationQuery>,
|
Query(qs): Query<PaginationQuery>,
|
||||||
) -> impl IntoResponse {
|
) -> impl IntoResponse {
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
|
use axum::extract::State;
|
||||||
use axum::response::IntoResponse;
|
use axum::response::IntoResponse;
|
||||||
use axum::routing::get;
|
use axum::routing::get;
|
||||||
use axum::{Extension, Json, Router};
|
use axum::{Json, Router};
|
||||||
use serde_json::json;
|
use serde_json::json;
|
||||||
|
|
||||||
use radicle::node::NodeId;
|
use radicle::node::NodeId;
|
||||||
|
|
@ -12,12 +13,12 @@ pub fn router(ctx: Context) -> Router {
|
||||||
|
|
||||||
Router::new()
|
Router::new()
|
||||||
.route("/node", get(node_handler))
|
.route("/node", get(node_handler))
|
||||||
.layer(Extension(node_id))
|
.with_state(node_id)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Return the node id for the node identity.
|
/// Return the node id for the node identity.
|
||||||
/// `GET /node`
|
/// `GET /node`
|
||||||
async fn node_handler(Extension(node_id): Extension<NodeId>) -> impl IntoResponse {
|
async fn node_handler(State(node_id): State<NodeId>) -> impl IntoResponse {
|
||||||
let response = json!({
|
let response = json!({
|
||||||
"id": node_id.to_string(),
|
"id": node_id.to_string(),
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,11 @@
|
||||||
use std::collections::BTreeMap;
|
use std::collections::BTreeMap;
|
||||||
|
|
||||||
|
use axum::extract::State;
|
||||||
use axum::handler::Handler;
|
use axum::handler::Handler;
|
||||||
use axum::http::{header, HeaderValue};
|
use axum::http::{header, HeaderValue};
|
||||||
use axum::response::IntoResponse;
|
use axum::response::IntoResponse;
|
||||||
use axum::routing::get;
|
use axum::routing::get;
|
||||||
use axum::{Extension, Json, Router};
|
use axum::{Json, Router};
|
||||||
use hyper::StatusCode;
|
use hyper::StatusCode;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use serde_json::json;
|
use serde_json::json;
|
||||||
|
|
@ -40,6 +41,7 @@ pub fn router(ctx: Context) -> Router {
|
||||||
)),
|
)),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
.route("/projects/:project/tree/:sha/", get(tree_handler_root))
|
||||||
.route("/projects/:project/tree/:sha/*path", get(tree_handler))
|
.route("/projects/:project/tree/:sha/*path", get(tree_handler))
|
||||||
.route("/projects/:project/remotes", get(remotes_handler))
|
.route("/projects/:project/remotes", get(remotes_handler))
|
||||||
.route("/projects/:project/remotes/:peer", get(remote_handler))
|
.route("/projects/:project/remotes/:peer", get(remote_handler))
|
||||||
|
|
@ -47,13 +49,13 @@ pub fn router(ctx: Context) -> Router {
|
||||||
.route("/projects/:project/readme/:sha", get(readme_handler))
|
.route("/projects/:project/readme/:sha", get(readme_handler))
|
||||||
.route("/projects/:project/issues", get(issues_handler))
|
.route("/projects/:project/issues", get(issues_handler))
|
||||||
.route("/projects/:project/issues/:id", get(issue_handler))
|
.route("/projects/:project/issues/:id", get(issue_handler))
|
||||||
.layer(Extension(ctx))
|
.with_state(ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// List all projects.
|
/// List all projects.
|
||||||
/// `GET /projects`
|
/// `GET /projects`
|
||||||
async fn project_root_handler(
|
async fn project_root_handler(
|
||||||
Extension(ctx): Extension<Context>,
|
State(ctx): State<Context>,
|
||||||
Query(qs): Query<PaginationQuery>,
|
Query(qs): Query<PaginationQuery>,
|
||||||
) -> impl IntoResponse {
|
) -> impl IntoResponse {
|
||||||
let PaginationQuery { page, per_page } = qs;
|
let PaginationQuery { page, per_page } = qs;
|
||||||
|
|
@ -87,10 +89,7 @@ async fn project_root_handler(
|
||||||
|
|
||||||
/// Get project metadata.
|
/// Get project metadata.
|
||||||
/// `GET /projects/:project`
|
/// `GET /projects/:project`
|
||||||
async fn project_handler(
|
async fn project_handler(State(ctx): State<Context>, Path(id): Path<Id>) -> impl IntoResponse {
|
||||||
Extension(ctx): Extension<Context>,
|
|
||||||
Path(id): Path<Id>,
|
|
||||||
) -> impl IntoResponse {
|
|
||||||
let info = ctx.project_info(id)?;
|
let info = ctx.project_info(id)?;
|
||||||
|
|
||||||
Ok::<_, Error>(Json(info))
|
Ok::<_, Error>(Json(info))
|
||||||
|
|
@ -109,7 +108,7 @@ pub struct CommitsQueryString {
|
||||||
/// Get project commit range.
|
/// Get project commit range.
|
||||||
/// `GET /projects/:project/commits?since=<sha>`
|
/// `GET /projects/:project/commits?since=<sha>`
|
||||||
async fn history_handler(
|
async fn history_handler(
|
||||||
Extension(ctx): Extension<Context>,
|
State(ctx): State<Context>,
|
||||||
Path(project): Path<Id>,
|
Path(project): Path<Id>,
|
||||||
Query(qs): Query<CommitsQueryString>,
|
Query(qs): Query<CommitsQueryString>,
|
||||||
) -> impl IntoResponse {
|
) -> impl IntoResponse {
|
||||||
|
|
@ -194,7 +193,7 @@ async fn history_handler(
|
||||||
/// Get project commit.
|
/// Get project commit.
|
||||||
/// `GET /projects/:project/commits/:sha`
|
/// `GET /projects/:project/commits/:sha`
|
||||||
async fn commit_handler(
|
async fn commit_handler(
|
||||||
Extension(ctx): Extension<Context>,
|
State(ctx): State<Context>,
|
||||||
Path((project, sha)): Path<(Id, Oid)>,
|
Path((project, sha)): Path<(Id, Oid)>,
|
||||||
) -> impl IntoResponse {
|
) -> impl IntoResponse {
|
||||||
let storage = &ctx.profile.storage;
|
let storage = &ctx.profile.storage;
|
||||||
|
|
@ -220,7 +219,7 @@ async fn commit_handler(
|
||||||
/// Get project activity for the past year.
|
/// Get project activity for the past year.
|
||||||
/// `GET /projects/:project/activity`
|
/// `GET /projects/:project/activity`
|
||||||
async fn activity_handler(
|
async fn activity_handler(
|
||||||
Extension(ctx): Extension<Context>,
|
State(ctx): State<Context>,
|
||||||
Path(project): Path<Id>,
|
Path(project): Path<Id>,
|
||||||
) -> impl IntoResponse {
|
) -> impl IntoResponse {
|
||||||
let current_date = chrono::Utc::now().timestamp();
|
let current_date = chrono::Utc::now().timestamp();
|
||||||
|
|
@ -244,13 +243,21 @@ async fn activity_handler(
|
||||||
Ok::<_, Error>((StatusCode::OK, Json(json!({ "activity": timestamps }))))
|
Ok::<_, Error>((StatusCode::OK, Json(json!({ "activity": timestamps }))))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Get project source tree for '/' path.
|
||||||
|
/// `GET /projects/:project/tree/:sha/`
|
||||||
|
async fn tree_handler_root(
|
||||||
|
State(ctx): State<Context>,
|
||||||
|
Path((project, sha)): Path<(Id, Oid)>,
|
||||||
|
) -> impl IntoResponse {
|
||||||
|
tree_handler(State(ctx), Path((project, sha, String::new()))).await
|
||||||
|
}
|
||||||
|
|
||||||
/// Get project source tree.
|
/// Get project source tree.
|
||||||
/// `GET /projects/:project/tree/:sha/*path`
|
/// `GET /projects/:project/tree/:sha/*path`
|
||||||
async fn tree_handler(
|
async fn tree_handler(
|
||||||
Extension(ctx): Extension<Context>,
|
State(ctx): State<Context>,
|
||||||
Path((project, sha, path)): Path<(Id, Oid, String)>,
|
Path((project, sha, path)): Path<(Id, Oid, String)>,
|
||||||
) -> impl IntoResponse {
|
) -> impl IntoResponse {
|
||||||
let path = path.strip_prefix('/').ok_or(Error::NotFound)?.to_string();
|
|
||||||
let storage = &ctx.profile.storage;
|
let storage = &ctx.profile.storage;
|
||||||
let repo = Repository::open(paths::repository(storage, &project))?;
|
let repo = Repository::open(paths::repository(storage, &project))?;
|
||||||
let tree = repo.tree(sha, &path)?;
|
let tree = repo.tree(sha, &path)?;
|
||||||
|
|
@ -262,10 +269,7 @@ async fn tree_handler(
|
||||||
|
|
||||||
/// Get all project remotes.
|
/// Get all project remotes.
|
||||||
/// `GET /projects/:project/remotes`
|
/// `GET /projects/:project/remotes`
|
||||||
async fn remotes_handler(
|
async fn remotes_handler(State(ctx): State<Context>, Path(project): Path<Id>) -> impl IntoResponse {
|
||||||
Extension(ctx): Extension<Context>,
|
|
||||||
Path(project): Path<Id>,
|
|
||||||
) -> impl IntoResponse {
|
|
||||||
let storage = &ctx.profile.storage;
|
let storage = &ctx.profile.storage;
|
||||||
let repo = storage.repository(project)?;
|
let repo = storage.repository(project)?;
|
||||||
let remotes = repo
|
let remotes = repo
|
||||||
|
|
@ -296,7 +300,7 @@ async fn remotes_handler(
|
||||||
/// Get project remote.
|
/// Get project remote.
|
||||||
/// `GET /projects/:project/remotes/:peer`
|
/// `GET /projects/:project/remotes/:peer`
|
||||||
async fn remote_handler(
|
async fn remote_handler(
|
||||||
Extension(ctx): Extension<Context>,
|
State(ctx): State<Context>,
|
||||||
Path((project, node_id)): Path<(Id, NodeId)>,
|
Path((project, node_id)): Path<(Id, NodeId)>,
|
||||||
) -> impl IntoResponse {
|
) -> impl IntoResponse {
|
||||||
let storage = &ctx.profile.storage;
|
let storage = &ctx.profile.storage;
|
||||||
|
|
@ -323,14 +327,13 @@ async fn remote_handler(
|
||||||
/// Get project source file.
|
/// Get project source file.
|
||||||
/// `GET /projects/:project/blob/:sha/*path`
|
/// `GET /projects/:project/blob/:sha/*path`
|
||||||
async fn blob_handler(
|
async fn blob_handler(
|
||||||
Extension(ctx): Extension<Context>,
|
State(ctx): State<Context>,
|
||||||
Path((project, sha, path)): Path<(Id, Oid, String)>,
|
Path((project, sha, path)): Path<(Id, Oid, String)>,
|
||||||
) -> impl IntoResponse {
|
) -> impl IntoResponse {
|
||||||
let path = path.strip_prefix('/').ok_or(Error::NotFound)?;
|
|
||||||
let storage = &ctx.profile.storage;
|
let storage = &ctx.profile.storage;
|
||||||
let repo = Repository::open(paths::repository(storage, &project))?;
|
let repo = Repository::open(paths::repository(storage, &project))?;
|
||||||
let blob = repo.blob(sha, &path)?;
|
let blob = repo.blob(sha, &path)?;
|
||||||
let response = api::json::blob(&blob, path);
|
let response = api::json::blob(&blob, &path);
|
||||||
|
|
||||||
Ok::<_, Error>(Json(response))
|
Ok::<_, Error>(Json(response))
|
||||||
}
|
}
|
||||||
|
|
@ -338,7 +341,7 @@ async fn blob_handler(
|
||||||
/// Get project readme.
|
/// Get project readme.
|
||||||
/// `GET /projects/:project/readme/:sha`
|
/// `GET /projects/:project/readme/:sha`
|
||||||
async fn readme_handler(
|
async fn readme_handler(
|
||||||
Extension(ctx): Extension<Context>,
|
State(ctx): State<Context>,
|
||||||
Path((project, sha)): Path<(Id, Oid)>,
|
Path((project, sha)): Path<(Id, Oid)>,
|
||||||
) -> impl IntoResponse {
|
) -> impl IntoResponse {
|
||||||
let storage = &ctx.profile.storage;
|
let storage = &ctx.profile.storage;
|
||||||
|
|
@ -365,7 +368,7 @@ async fn readme_handler(
|
||||||
/// Get project issues list.
|
/// Get project issues list.
|
||||||
/// `GET /projects/:project/issues`
|
/// `GET /projects/:project/issues`
|
||||||
async fn issues_handler(
|
async fn issues_handler(
|
||||||
Extension(ctx): Extension<Context>,
|
State(ctx): State<Context>,
|
||||||
Path(project): Path<Id>,
|
Path(project): Path<Id>,
|
||||||
Query(qs): Query<PaginationQuery>,
|
Query(qs): Query<PaginationQuery>,
|
||||||
) -> impl IntoResponse {
|
) -> impl IntoResponse {
|
||||||
|
|
@ -399,7 +402,7 @@ async fn issues_handler(
|
||||||
/// Get project issue.
|
/// Get project issue.
|
||||||
/// `GET /projects/:project/issues/:id`
|
/// `GET /projects/:project/issues/:id`
|
||||||
async fn issue_handler(
|
async fn issue_handler(
|
||||||
Extension(ctx): Extension<Context>,
|
State(ctx): State<Context>,
|
||||||
Path((project, issue_id)): Path<(Id, Oid)>,
|
Path((project, issue_id)): Path<(Id, Oid)>,
|
||||||
) -> impl IntoResponse {
|
) -> impl IntoResponse {
|
||||||
let storage = &ctx.profile.storage;
|
let storage = &ctx.profile.storage;
|
||||||
|
|
|
||||||
|
|
@ -4,9 +4,10 @@ use std::env;
|
||||||
use std::iter::repeat_with;
|
use std::iter::repeat_with;
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
|
|
||||||
|
use axum::extract::State;
|
||||||
use axum::response::IntoResponse;
|
use axum::response::IntoResponse;
|
||||||
use axum::routing::{get, post};
|
use axum::routing::{get, post};
|
||||||
use axum::{Extension, Json, Router};
|
use axum::{Json, Router};
|
||||||
use ethers_core::utils::hex;
|
use ethers_core::utils::hex;
|
||||||
use hyper::http::uri::Authority;
|
use hyper::http::uri::Authority;
|
||||||
use serde_json::json;
|
use serde_json::json;
|
||||||
|
|
@ -27,12 +28,12 @@ pub fn router(ctx: Context) -> Router {
|
||||||
"/sessions/:id",
|
"/sessions/:id",
|
||||||
get(session_get_handler).put(session_signin_handler),
|
get(session_get_handler).put(session_signin_handler),
|
||||||
)
|
)
|
||||||
.layer(Extension(ctx))
|
.with_state(ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create session.
|
/// Create session.
|
||||||
/// `POST /sessions`
|
/// `POST /sessions`
|
||||||
async fn session_create_handler(Extension(ctx): Extension<Context>) -> impl IntoResponse {
|
async fn session_create_handler(State(ctx): State<Context>) -> impl IntoResponse {
|
||||||
let expiration_time = OffsetDateTime::now_utc()
|
let expiration_time = OffsetDateTime::now_utc()
|
||||||
.checked_add(UNAUTHORIZED_SESSIONS_EXPIRATION)
|
.checked_add(UNAUTHORIZED_SESSIONS_EXPIRATION)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
@ -45,7 +46,7 @@ async fn session_create_handler(Extension(ctx): Extension<Context>) -> impl Into
|
||||||
/// Get session.
|
/// Get session.
|
||||||
/// `GET /sessions/:id`
|
/// `GET /sessions/:id`
|
||||||
async fn session_get_handler(
|
async fn session_get_handler(
|
||||||
Extension(ctx): Extension<Context>,
|
State(ctx): State<Context>,
|
||||||
Path(id): Path<String>,
|
Path(id): Path<String>,
|
||||||
) -> impl IntoResponse {
|
) -> impl IntoResponse {
|
||||||
let sessions = ctx.sessions.read().await;
|
let sessions = ctx.sessions.read().await;
|
||||||
|
|
@ -67,7 +68,7 @@ async fn session_get_handler(
|
||||||
/// Update session.
|
/// Update session.
|
||||||
/// `PUT /sessions/:id`
|
/// `PUT /sessions/:id`
|
||||||
async fn session_signin_handler(
|
async fn session_signin_handler(
|
||||||
Extension(ctx): Extension<Context>,
|
State(ctx): State<Context>,
|
||||||
Path(id): Path<String>,
|
Path(id): Path<String>,
|
||||||
Json(request): Json<AuthRequest>,
|
Json(request): Json<AuthRequest>,
|
||||||
) -> impl IntoResponse {
|
) -> impl IntoResponse {
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
|
use axum::extract::State;
|
||||||
use axum::response::IntoResponse;
|
use axum::response::IntoResponse;
|
||||||
use axum::routing::get;
|
use axum::routing::get;
|
||||||
use axum::{Extension, Json, Router};
|
use axum::{Json, Router};
|
||||||
use serde_json::json;
|
use serde_json::json;
|
||||||
|
|
||||||
use crate::api::error::Error;
|
use crate::api::error::Error;
|
||||||
|
|
@ -9,12 +10,12 @@ use crate::api::Context;
|
||||||
pub fn router(ctx: Context) -> Router {
|
pub fn router(ctx: Context) -> Router {
|
||||||
Router::new()
|
Router::new()
|
||||||
.route("/stats", get(stats_handler))
|
.route("/stats", get(stats_handler))
|
||||||
.layer(Extension(ctx))
|
.with_state(ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Return the stats for the node.
|
/// Return the stats for the node.
|
||||||
/// `GET /stats`
|
/// `GET /stats`
|
||||||
async fn stats_handler(Extension(ctx): Extension<Context>) -> impl IntoResponse {
|
async fn stats_handler(State(ctx): State<Context>) -> impl IntoResponse {
|
||||||
let storage = &ctx.profile.storage;
|
let storage = &ctx.profile.storage;
|
||||||
let projects = storage.projects()?.len();
|
let projects = storage.projects()?.len();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -98,9 +98,9 @@ async fn git_handler(
|
||||||
AxumPath((project, request)): AxumPath<(String, String)>,
|
AxumPath((project, request)): AxumPath<(String, String)>,
|
||||||
method: Method,
|
method: Method,
|
||||||
headers: HeaderMap,
|
headers: HeaderMap,
|
||||||
body: Bytes,
|
|
||||||
ConnectInfo(remote): ConnectInfo<SocketAddr>,
|
ConnectInfo(remote): ConnectInfo<SocketAddr>,
|
||||||
query: RawQuery,
|
query: RawQuery,
|
||||||
|
body: Bytes,
|
||||||
) -> impl IntoResponse {
|
) -> impl IntoResponse {
|
||||||
let query = query.0.unwrap_or_default();
|
let query = query.0.unwrap_or_default();
|
||||||
let id: Id = project.strip_suffix(".git").unwrap_or(&project).parse()?;
|
let id: Id = project.strip_suffix(".git").unwrap_or(&project).parse()?;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue