added: index endpoint

added: index opt in
This commit is contained in:
shimun 2022-12-10 19:27:38 +01:00
parent 0474f20f9a
commit e9ecc0563b
Signed by: shimun
GPG Key ID: E0420647856EA39E
2 changed files with 25 additions and 4 deletions

View File

@ -10,6 +10,7 @@ edition = "2021"
default = [ "client", "reload", "info", "authorized" ]
reload = []
authorized =[ "dep:jwt-compact" ]
index = []
info = [ "axum/json", "ssh-key/serde" ]
client = [ "dep:url", "dep:reqwest" ]

View File

@ -132,7 +132,7 @@ pub async fn run(
.into_iter()
.map(|cert| (cert.key_id().to_string(), cert))
.collect();
debug!("reloaded certs");
trace!("reloaded certs");
}
}
});
@ -142,7 +142,10 @@ pub async fn run(
.typed_get(get_certs_identifier)
.typed_put(put_cert_update)
.typed_get(get_cert_info)
.typed_post(post_certs_identifier)
.typed_post(post_certs_identifier);
#[cfg(feature = "index")]
let app = app.typed_get(list_certs);
let app = app
.fallback(fallback_404)
.layer(ServiceBuilder::new().map_request_body(body::boxed))
.layer(TraceLayer::new_for_http())
@ -199,6 +202,25 @@ async fn fallback_404() -> ApiResult<()> {
Err(ApiError::CertificateNotFound)
}
#[derive(TypedPath, Deserialize)]
#[typed_path("/certs")]
pub struct CertList;
async fn list_certs(
_: CertList,
State(ApiState { certs, .. }): State<ApiState>,
) -> ApiResult<Json<Vec<String>>> {
Ok(Json(
certs
.lock()
.await
.values()
.into_iter()
.map(|cert| cert.key_id().to_string())
.collect(),
))
}
#[derive(Debug, Serialize, Deserialize)]
#[serde(tag = "aud", rename = "get")]
struct AuthClaims {
@ -390,8 +412,6 @@ async fn put_cert_update(
mod tests {
use std::env::temp_dir;
use super::*;
fn ca_key() -> Ed25519Keypair {