v0.1.0-init-version #1
23
src/serve.rs
23
src/serve.rs
@@ -71,6 +71,7 @@ async fn response_requests(
|
|||||||
) -> Result<Response<Body>> {
|
) -> Result<Response<Body>> {
|
||||||
match (req.method(), req.uri().path()) {
|
match (req.method(), req.uri().path()) {
|
||||||
(&Method::POST, "/init") => init(req).await,
|
(&Method::POST, "/init") => init(req).await,
|
||||||
|
(&Method::POST, "/update") => update().await,
|
||||||
(&Method::POST, "/decrypt") => decrypt(req).await,
|
(&Method::POST, "/decrypt") => decrypt(req).await,
|
||||||
(&Method::POST, "/encrypt") => encrypt(req).await,
|
(&Method::POST, "/encrypt") => encrypt(req).await,
|
||||||
(&Method::GET, "/status") => status().await,
|
(&Method::GET, "/status") => status().await,
|
||||||
@@ -122,6 +123,17 @@ fn init_instance(db: &str) -> XResult<bool> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn update_instance_rsa_key_pair() -> XResult<bool> {
|
||||||
|
let mut startup_rw_lock = STATUP_RW_LOCK.write().expect("Lock write startup rw lock error");
|
||||||
|
match &mut *startup_rw_lock {
|
||||||
|
Some(k) => {
|
||||||
|
k.instance_rsa_key_pair = jose::generate_rsa_key(4096)?;
|
||||||
|
Ok(true)
|
||||||
|
}
|
||||||
|
None => Ok(false),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
#[derive(Serialize, Deserialize)]
|
||||||
struct MultipleViewValue {
|
struct MultipleViewValue {
|
||||||
value: Option<String>,
|
value: Option<String>,
|
||||||
@@ -178,6 +190,17 @@ async fn inner_encrypt(req: Request<Body>) -> XResult<(StatusCode, Value)> {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fn update() -> Result<Response<Body>> {
|
||||||
|
do_response!(inner_update().await)
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn inner_update() -> XResult<(StatusCode, Value)> {
|
||||||
|
let update = update_instance_rsa_key_pair()?;
|
||||||
|
Ok((StatusCode::OK, json!({
|
||||||
|
"update": update,
|
||||||
|
})))
|
||||||
|
}
|
||||||
|
|
||||||
async fn init(req: Request<Body>) -> Result<Response<Body>> {
|
async fn init(req: Request<Body>) -> Result<Response<Body>> {
|
||||||
do_response!(inner_init(req).await)
|
do_response!(inner_init(req).await)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user