From 4f8df97d1a96019b8fadf608792e08b528b0c148 Mon Sep 17 00:00:00 2001 From: Johanna Dorothea Reichmann Date: Sat, 1 Jul 2023 00:19:12 +0200 Subject: [PATCH] feat: add POST tsigkeys/create endpoint --- src/api.rs | 26 +++++++++++++++++++++----- src/main.rs | 4 ++-- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/src/api.rs b/src/api.rs index 977a9b9..1c04b75 100644 --- a/src/api.rs +++ b/src/api.rs @@ -45,11 +45,27 @@ pub async fn list_key( .into(); Ok(axum::Json(key)) } -// -//pub async fn create_key( -// State(state): State> -//) -> PowerDnsOidcTsigkeyResult> {} -// + +pub async fn create_key( + State(state): State>, + body: String, +) -> PowerDnsOidcTsigkeyResult> { + let key: TsigKey = parse_json::( + state.http_client.post( + get_url(state.config.powerdns.url.clone(), "localhost".to_owned(), "tsigkeys".to_owned()) + ) + .header("X-API-Key", state.config.powerdns.api_token.clone()) + .header("Content-Type", "application/json") + .body(body) + .send() + .await? + ) + .await? + .into(); + Ok(axum::Json(key)) + +} + //pub async fn modify_key( // Path(key_id): Path, // State(state): State> diff --git a/src/main.rs b/src/main.rs index a10e551..f7d35d8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -8,7 +8,7 @@ use std::{ }; use axum::{ - routing::{get}, + routing::{get, post}, Router, http::StatusCode, response::IntoResponse, @@ -151,7 +151,7 @@ async fn run(config: PowerDnsOidcTsigkeyConfig) { 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/create", post(api::create_key)) .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())