mirror of
https://github.com/aljazceru/pubky-core.git
synced 2025-12-31 12:54:35 +01:00
chore: rename crates to pubky-*
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
[workspace]
|
||||
members = [ "common","homeserver"]
|
||||
members = ["pubky-*"]
|
||||
|
||||
# See: https://github.com/rust-lang/rust/issues/90148#issuecomment-949194352
|
||||
resolver = "2"
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
use axum::{routing::get, Router};
|
||||
|
||||
pub mod root;
|
||||
|
||||
pub fn create_app() -> Router {
|
||||
Router::new().route("/", get(root::handler))
|
||||
}
|
||||
@@ -20,7 +20,7 @@ impl AuthnSignature {
|
||||
let time: u64 = Timestamp::now().into();
|
||||
let time_step = time / TIME_INTERVAL;
|
||||
|
||||
let token_hash = token.map_or(random_hash(), |t| crate::crypto::hash(t));
|
||||
let token_hash = token.map_or(random_hash(), crate::crypto::hash);
|
||||
|
||||
let signature = signer
|
||||
.sign(&signable(
|
||||
@@ -80,7 +80,7 @@ impl AuthnVerifier {
|
||||
let past = now - TIME_INTERVAL;
|
||||
let future = now + TIME_INTERVAL;
|
||||
|
||||
let result = verify_at(now, &self, &signature, signer, &token_hash);
|
||||
let result = verify_at(now, self, &signature, signer, &token_hash);
|
||||
|
||||
match result {
|
||||
Ok(_) => return Ok(()),
|
||||
@@ -88,7 +88,7 @@ impl AuthnVerifier {
|
||||
_ => {}
|
||||
}
|
||||
|
||||
let result = verify_at(past, &self, &signature, signer, &token_hash);
|
||||
let result = verify_at(past, self, &signature, signer, &token_hash);
|
||||
|
||||
match result {
|
||||
Ok(_) => return Ok(()),
|
||||
@@ -96,7 +96,7 @@ impl AuthnVerifier {
|
||||
_ => {}
|
||||
}
|
||||
|
||||
verify_at(future, &self, &signature, signer, &token_hash)
|
||||
verify_at(future, self, &signature, signer, &token_hash)
|
||||
}
|
||||
|
||||
// === Private Methods ===
|
||||
@@ -6,6 +6,7 @@ edition = "2021"
|
||||
[dependencies]
|
||||
anyhow = "1.0.82"
|
||||
axum = "0.7.5"
|
||||
pkarr = "2.0.3"
|
||||
tokio = { version = "1.37.0", features = ["full"] }
|
||||
tower-http = { version = "0.5.2", features = ["cors", "trace"] }
|
||||
tracing = "0.1.40"
|
||||
43
pubky-homeserver/src/extractors.rs
Normal file
43
pubky-homeserver/src/extractors.rs
Normal file
@@ -0,0 +1,43 @@
|
||||
use std::collections::HashMap;
|
||||
|
||||
use axum::{
|
||||
async_trait,
|
||||
extract::{FromRequestParts, Path},
|
||||
http::{request::Parts, StatusCode},
|
||||
response::{IntoResponse, Response},
|
||||
RequestPartsExt,
|
||||
};
|
||||
|
||||
use pkarr::PublicKey;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Pubky(PublicKey);
|
||||
|
||||
impl Pubky {
|
||||
pub fn public_key(&self) -> &PublicKey {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl<S> FromRequestParts<S> for Pubky
|
||||
where
|
||||
S: Send + Sync,
|
||||
{
|
||||
type Rejection = Response;
|
||||
|
||||
async fn from_request_parts(parts: &mut Parts, _state: &S) -> Result<Self, Self::Rejection> {
|
||||
let params: Path<HashMap<String, String>> =
|
||||
parts.extract().await.map_err(IntoResponse::into_response)?;
|
||||
|
||||
let pubky_id = params
|
||||
.get("pubky")
|
||||
.ok_or_else(|| (StatusCode::NOT_FOUND, "Pubky not found").into_response())?;
|
||||
|
||||
let public_key = PublicKey::try_from(pubky_id.to_string())
|
||||
// TODO: convert Pkarr errors to app errors, in this case a params validation error
|
||||
.map_err(|_| (StatusCode::BAD_REQUEST, "Invalid Pubky").into_response())?;
|
||||
|
||||
Ok(Pubky(public_key))
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
mod extractors;
|
||||
mod routes;
|
||||
mod server;
|
||||
|
||||
@@ -3,7 +3,9 @@ use pubky_homeserver::Homeserver;
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<()> {
|
||||
tracing_subscriber::fmt().init();
|
||||
tracing_subscriber::fmt()
|
||||
.with_env_filter("pubky_homeserver=debug,tower_http=debug")
|
||||
.init();
|
||||
|
||||
let server = Homeserver::start().await?;
|
||||
|
||||
12
pubky-homeserver/src/routes.rs
Normal file
12
pubky-homeserver/src/routes.rs
Normal file
@@ -0,0 +1,12 @@
|
||||
use axum::{routing::get, Router};
|
||||
use tower_http::trace::TraceLayer;
|
||||
|
||||
pub mod drive;
|
||||
pub mod root;
|
||||
|
||||
pub fn create_app() -> Router {
|
||||
Router::new()
|
||||
.route("/", get(root::handler))
|
||||
.route("/:pubky/*key", get(drive::put))
|
||||
.layer(TraceLayer::new_for_http())
|
||||
}
|
||||
11
pubky-homeserver/src/routes/drive.rs
Normal file
11
pubky-homeserver/src/routes/drive.rs
Normal file
@@ -0,0 +1,11 @@
|
||||
use axum::response::IntoResponse;
|
||||
|
||||
use tracing::debug;
|
||||
|
||||
use crate::extractors::Pubky;
|
||||
|
||||
pub async fn put(pubky: Pubky) -> Result<impl IntoResponse, String> {
|
||||
debug!(pubky=?pubky.public_key());
|
||||
|
||||
Ok("Pubky drive...".to_string())
|
||||
}
|
||||
@@ -18,7 +18,7 @@ impl Homeserver {
|
||||
let app = app.clone();
|
||||
|
||||
let listener = TcpListener::bind(SocketAddr::from((
|
||||
[127, 0, 0, 1],
|
||||
[0, 0, 0, 0],
|
||||
6287, // config.port()
|
||||
)))
|
||||
.await?;
|
||||
Reference in New Issue
Block a user