drawbridge_server/trees/
head.rs

1// SPDX-FileCopyrightText: 2022 Profian Inc. <opensource@profian.com>
2// SPDX-License-Identifier: Apache-2.0
3
4use 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 head(
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::head", "called for `{cx}`");
23
24    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    .tag(&cx.tag.name)
33    .node(&cx.path)
34    .get_meta()
35    .await
36    .map_err(|e| {
37        debug!(target: "app::trees::head", "failed for `{cx}`: {:?}", e);
38        e.into_response()
39    })
40    .map(|meta| (meta, ()))
41}