feat: add list key endpoint
This commit is contained in:
parent
c19558cb76
commit
a2a99a1aab
38
src/api.rs
38
src/api.rs
@ -1,6 +1,6 @@
|
|||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use axum::{
|
use axum::{
|
||||||
extract::{State},
|
extract::{Path, State},
|
||||||
};
|
};
|
||||||
use axum::Json;
|
use axum::Json;
|
||||||
use serde::{Deserialize,Serialize};
|
use serde::{Deserialize,Serialize};
|
||||||
@ -23,9 +23,39 @@ pub async fn list_keys(
|
|||||||
false => Err(PowerDnsOidcTsigkeyError::from_response(response).await)
|
false => Err(PowerDnsOidcTsigkeyError::from_response(response).await)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//pub async fn list_key(Path(key_id): Path<String>) -> Json<TsigKey> {}
|
|
||||||
//pub async fn create_key() -> Json<TsigKey> {}
|
pub async fn list_key(
|
||||||
//pub async fn delete_key(Path(key_id): Path<String>) {}
|
Path(key_id): Path<String>,
|
||||||
|
State(state): State<Arc<AppState>>,
|
||||||
|
) -> PowerDnsOidcTsigkeyResult<Json<TsigKey>> {
|
||||||
|
let key: TsigKey = parse_json::<PowerDnsTsigKey>(
|
||||||
|
state.http_client.get::<String>(
|
||||||
|
(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<Arc<AppState>>
|
||||||
|
//) -> PowerDnsOidcTsigkeyResult<Json<TsigKey>> {}
|
||||||
|
//
|
||||||
|
//pub async fn modify_key(
|
||||||
|
// Path(key_id): Path<String>,
|
||||||
|
// State(state): State<Arc<AppState>>
|
||||||
|
//) -> PowerDnsOidcTsigkeyResult<Json<TsigKey>> {}
|
||||||
|
//
|
||||||
|
//pub async fn delete_key(
|
||||||
|
// Path(key_id): Path<String>,
|
||||||
|
// State(state): State<Arc<AppState>>
|
||||||
|
//) -> PowerDnsOidcTsigkeyResult<Json<Value>> {
|
||||||
|
//
|
||||||
|
//}
|
||||||
|
|
||||||
|
|
||||||
#[derive(Serialize, Debug)]
|
#[derive(Serialize, Debug)]
|
||||||
|
@ -155,7 +155,7 @@ async fn run() {
|
|||||||
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",
|
.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())
|
||||||
.with_state(Arc::new(state));
|
.with_state(Arc::new(state));
|
||||||
|
Reference in New Issue
Block a user