feat: add POST tsigkeys/create endpoint
This commit is contained in:
parent
a4bfa2bb8b
commit
4f8df97d1a
26
src/api.rs
26
src/api.rs
@ -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>>
|
||||||
|
@ -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())
|
||||||
|
Reference in New Issue
Block a user