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();
Ok(axum::Json(key))
}
//
//pub async fn create_key(
// State(state): State<Arc<AppState>>
//) -> PowerDnsOidcTsigkeyResult<Json<TsigKey>> {}
//
pub async fn create_key(
State(state): State<Arc<AppState>>,
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(
// Path(key_id): Path<String>,
// State(state): State<Arc<AppState>>

View File

@ -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())