diff --git a/src/api.rs b/src/api.rs index dadce9f..56d385d 100644 --- a/src/api.rs +++ b/src/api.rs @@ -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) -> Json {} -//pub async fn create_key() -> Json {} -//pub async fn delete_key(Path(key_id): Path) {} + +pub async fn list_key( + Path(key_id): Path, + State(state): State>, +) -> PowerDnsOidcTsigkeyResult> { + let key: TsigKey = parse_json::( + state.http_client.get::( + (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> +//) -> PowerDnsOidcTsigkeyResult> {} +// +//pub async fn modify_key( +// Path(key_id): Path, +// State(state): State> +//) -> PowerDnsOidcTsigkeyResult> {} +// +//pub async fn delete_key( +// Path(key_id): Path, +// State(state): State> +//) -> PowerDnsOidcTsigkeyResult> { +// +//} #[derive(Serialize, Debug)] diff --git a/src/main.rs b/src/main.rs index 327e06d..1868c34 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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));