-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #872 from wujian0327/main
Feature: add ca service for p2p
- Loading branch information
Showing
22 changed files
with
1,165 additions
and
844 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,3 +29,4 @@ buck-out | |
# Gtk4 resource files | ||
**/*.gresource | ||
monobean/resources/lib | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
use axum::{ | ||
body::{to_bytes, Body}, | ||
extract::{Query, State}, | ||
http::{Request, Response, StatusCode, Uri}, | ||
routing::get, | ||
Router, | ||
}; | ||
use gemini::RelayGetParams; | ||
use regex::Regex; | ||
|
||
use crate::service::relay_server::AppState; | ||
|
||
pub fn routers() -> Router<AppState> { | ||
Router::new().route("/{*path}", get(get_method_router).post(post_method_router)) | ||
} | ||
|
||
async fn get_method_router( | ||
_state: State<AppState>, | ||
Query(_params): Query<RelayGetParams>, | ||
uri: Uri, | ||
) -> Result<Response<Body>, (StatusCode, String)> { | ||
if Regex::new(r"/certificates/[a-zA-Z0-9]+$") | ||
.unwrap() | ||
.is_match(uri.path()) | ||
{ | ||
let name = match gemini::ca::server::get_cert_name_from_path(uri.path()) { | ||
Some(n) => n, | ||
None => { | ||
return Err((StatusCode::BAD_REQUEST, "Bad request".to_string())); | ||
} | ||
}; | ||
return match gemini::ca::server::get_certificate(name).await { | ||
Ok(cert) => Ok(Response::builder().body(Body::from(cert)).unwrap()), | ||
Err(e) => Err((StatusCode::INTERNAL_SERVER_ERROR, e.to_string())), | ||
}; | ||
} | ||
Err(( | ||
StatusCode::NOT_FOUND, | ||
String::from("Operation not supported\n"), | ||
)) | ||
} | ||
|
||
async fn post_method_router( | ||
_state: State<AppState>, | ||
uri: Uri, | ||
req: Request<Body>, | ||
) -> Result<Response<Body>, (StatusCode, String)> { | ||
if Regex::new(r"/certificates/[a-zA-Z0-9]+$") | ||
.unwrap() | ||
.is_match(uri.path()) | ||
{ | ||
let name = match gemini::ca::server::get_cert_name_from_path(uri.path()) { | ||
Some(n) => n, | ||
None => return Err((StatusCode::BAD_REQUEST, "Bad request".to_string())), | ||
}; | ||
let bytes = to_bytes(req.into_body(), usize::MAX).await.unwrap(); | ||
let csr = String::from_utf8(bytes.to_vec()).unwrap(); | ||
return match gemini::ca::server::issue_certificate(name, csr).await { | ||
Ok(cert) => Ok(Response::builder().body(Body::from(cert)).unwrap()), | ||
Err(e) => Err((StatusCode::INTERNAL_SERVER_ERROR, e.to_string())), | ||
}; | ||
} | ||
Err(( | ||
StatusCode::NOT_FOUND, | ||
String::from("Operation not supported\n"), | ||
)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
pub mod nostr_router; | ||
pub mod ca_router; | ||
|
||
#[cfg(test)] | ||
mod tests {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
b9342cf
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
mega – ./
mega-gitmono.vercel.app
mega-git-main-gitmono.vercel.app
gitmega.dev
www.gitmega.dev