drawbridge_server/trees/
get.rs1use super::super::{Store, TrustedCertificate};
5use crate::auth::assert_repository_read;
6
7use drawbridge_type::TreeContext;
8
9use async_std::sync::Arc;
10use axum::body::Body;
11use axum::http::Request;
12use axum::response::IntoResponse;
13use axum::Extension;
14use tracing::{debug, trace};
15
16pub async fn get(
17 Extension(ref store): Extension<Arc<Store>>,
18 cert: Option<Extension<TrustedCertificate>>,
19 cx: TreeContext,
20 req: Request<Body>,
21) -> impl IntoResponse {
22 trace!(target: "app::trees::get", "called for `{cx}`");
23
24 let repo = if cert.is_none() {
25 assert_repository_read(store, &cx.tag.repository, req)
26 .await
27 .map_err(IntoResponse::into_response)
28 .map(|(repo, _)| repo)?
29 } else {
30 store.repository(&cx.tag.repository)
31 };
32
33 let mut body = vec![];
36 repo.tag(&cx.tag.name)
37 .node(&cx.path)
38 .get_to_writer(&mut body)
39 .await
40 .map_err(|e| {
41 debug!(target: "app::trees::get", "failed for `{cx}`: {:?}", e);
42 e.into_response()
43 })
44 .map(|meta| (meta, body))
45}