feat: add POST tsigkeys/create endpoint

This commit is contained in:
transcaffeine 2023-07-01 00:19:12 +02:00
parent a4bfa2bb8b
commit 4f8df97d1a
Signed by: transcaffeine
GPG Key ID: 03624C433676E465
2 changed files with 23 additions and 7 deletions

View File

@ -45,11 +45,27 @@ pub async fn list_key(
.into(); .into();
Ok(axum::Json(key)) Ok(axum::Json(key))
} }
//
//pub async fn create_key( pub async fn create_key(
// State(state): State<Arc<AppState>> State(state): State<Arc<AppState>>,
//) -> PowerDnsOidcTsigkeyResult<Json<TsigKey>> {} body: String,
// ) -> PowerDnsOidcTsigkeyResult<Json<TsigKey>> {
let key: TsigKey = parse_json::<PowerDnsTsigKey>(
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( //pub async fn modify_key(
// Path(key_id): Path<String>, // Path(key_id): Path<String>,
// State(state): State<Arc<AppState>> // State(state): State<Arc<AppState>>

View File

@ -8,7 +8,7 @@ use std::{
}; };
use axum::{ use axum::{
routing::{get}, routing::{get, post},
Router, Router,
http::StatusCode, http::StatusCode,
response::IntoResponse, response::IntoResponse,
@ -151,7 +151,7 @@ async fn run(config: PowerDnsOidcTsigkeyConfig) {
let router = Router::new() let router = Router::new()
.route("/api/v1/tsigkeys", get(api::list_keys)) .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)) .route("/api/v1/tsigkeys/:keyid", get(api::list_key))
// put(api::create_key).delete(api::delete_key).get(api::list_key)) // put(api::create_key).delete(api::delete_key).get(api::list_key))
.layer(auth.layer().await.unwrap()) .layer(auth.layer().await.unwrap())