use axum::extract::State;
use axum::response::Response;
use crate::error::AppError;
use crate::server::AppState;
#[utoipa::path(
get, path = "/attestation/did-log", tag = "attestation",
responses(
(status = 200, description = "Auto-generated did.jsonl", content_type = "text/jsonl"),
(status = 304, description = "Not modified: If-None-Match names the current ETag"),
(status = 429, description = "Rate limited by the VTA (`x-rate-limit-source: vta`)"),
(status = 404, description = "No auto-generated DID log"),
),
)]
pub async fn did_log(
State(state): State<AppState>,
headers: axum::http::HeaderMap,
) -> Result<Response, AppError> {
let log_bytes = state
.keys_ks
.get_raw(crate::tee::did_autogen::DID_LOG_STORE_KEY)
.await?
.ok_or_else(|| {
AppError::NotFound(
"no auto-generated DID log found โ the VTA may not have \
been configured with a vta_did_template"
.into(),
)
})?;
let log = String::from_utf8(log_bytes)
.map_err(|e| AppError::Internal(format!("DID log is not valid UTF-8: {e}")))?;
Ok(super::self_hosted_did::did_log_response(&headers, log))
}