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::update_documents)
.service(routes::document::delete_documents) .service(routes::document::delete_documents)
.service(routes::document::clear_all_documents) .service(routes::document::clear_all_documents)
.service(routes::key::list)
.service(routes::health::get_health) .service(routes::health::get_health)
.service(routes::health::change_healthyness) .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 crate::Data;
use serde_json::json; use serde_json::json;
use tide::{Request, Response}; use actix_web::*;
pub async fn list(ctx: Request<Data>) -> SResult<Response> { #[get("/keys")]
ctx.is_allowed(Admin)?; pub async fn list(
data: web::Data<Data>,
) -> Result<HttpResponse> {
let keys = &data.api_keys;
let keys = &ctx.state().api_keys; HttpResponse::Ok().json(&json!({
Ok(tide::Response::new(200).body_json(&json!({
"private": keys.private, "private": keys.private,
"public": keys.public, "public": keys.public,
}))?) })).await
} }

View File

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