feat: add list key endpoint

This commit is contained in:
transcaffeine 2023-06-28 23:52:49 +02:00
parent c19558cb76
commit a2a99a1aab
Signed by: transcaffeine
GPG Key ID: 03624C433676E465
2 changed files with 35 additions and 5 deletions

View File

@ -1,6 +1,6 @@
use std::sync::Arc;
use axum::{
extract::{State},
extract::{Path, State},
};
use axum::Json;
use serde::{Deserialize,Serialize};
@ -23,9 +23,39 @@ pub async fn list_keys(
false => Err(PowerDnsOidcTsigkeyError::from_response(response).await)
}
}
//pub async fn list_key(Path(key_id): Path<String>) -> Json<TsigKey> {}
//pub async fn create_key() -> Json<TsigKey> {}
//pub async fn delete_key(Path(key_id): Path<String>) {}
pub async fn list_key(
Path(key_id): Path<String>,
State(state): State<Arc<AppState>>,
) -> PowerDnsOidcTsigkeyResult<Json<TsigKey>> {
let key: TsigKey = parse_json::<PowerDnsTsigKey>(
state.http_client.get::<String>(
(config_cell.get().unwrap().powerdns.url.to_string() + format!("/servers/localhost/tsigkeys/{}", key_id).as_str()).into()
)
.header("X-API-Key", config_cell.get().unwrap().powerdns.api_token.clone())
.send()
.await?
)
.await?
.into();
Ok(axum::Json(key))
}
//
//pub async fn create_key(
// State(state): State<Arc<AppState>>
//) -> PowerDnsOidcTsigkeyResult<Json<TsigKey>> {}
//
//pub async fn modify_key(
// Path(key_id): Path<String>,
// State(state): State<Arc<AppState>>
//) -> PowerDnsOidcTsigkeyResult<Json<TsigKey>> {}
//
//pub async fn delete_key(
// Path(key_id): Path<String>,
// State(state): State<Arc<AppState>>
//) -> PowerDnsOidcTsigkeyResult<Json<Value>> {
//
//}
#[derive(Serialize, Debug)]

View File

@ -155,7 +155,7 @@ async fn run() {
let router = Router::new()
.route("/api/v1/tsigkeys", get(api::list_keys))
// .route("/api/v1/tsigkeys/create", post(api::create_key))
// .route("/api/v1/tsigkeys/:keyid",
.route("/api/v1/tsigkeys/:keyid", get(api::list_key))
// put(api::create_key).delete(api::delete_key).get(api::list_key))
.layer(auth.layer().await.unwrap())
.with_state(Arc::new(state));