add key endpoint

This commit is contained in:
Quentin de Quelen 2020-04-07 19:10:32 +02:00 committed by qdequele
parent 540308dc63
commit 0aa16dd3b1
No known key found for this signature in database
GPG Key ID: B3F0A000EBF11745
3 changed files with 10 additions and 11 deletions

View File

@ -63,6 +63,7 @@ async fn main() -> Result<(), MainError> {
.service(routes::document::update_documents)
.service(routes::document::delete_documents)
.service(routes::document::clear_all_documents)
.service(routes::key::list)
.service(routes::health::get_health)
.service(routes::health::change_healthyness)
)

View File

@ -1,17 +1,15 @@
use crate::error::SResult;
use crate::helpers::tide::RequestExt;
use crate::helpers::tide::ACL::*;
use crate::Data;
use serde_json::json;
use tide::{Request, Response};
use actix_web::*;
pub async fn list(ctx: Request<Data>) -> SResult<Response> {
ctx.is_allowed(Admin)?;
#[get("/keys")]
pub async fn list(
data: web::Data<Data>,
) -> Result<HttpResponse> {
let keys = &data.api_keys;
let keys = &ctx.state().api_keys;
Ok(tide::Response::new(200).body_json(&json!({
HttpResponse::Ok().json(&json!({
"private": keys.private,
"public": keys.public,
}))?)
})).await
}

View File

@ -5,7 +5,7 @@ use serde::Serialize;
pub mod document;
pub mod health;
// pub mod index;
// pub mod key;
pub mod key;
// pub mod search;
// pub mod setting;
// pub mod stats;