1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
mod oidc;
mod tls;
pub use oidc::Claims as OidcClaims;
pub use tls::{Config as TlsConfig, TrustedCertificate};
use super::{Repository, Store, User};
use drawbridge_type::RepositoryContext;
use axum::body::Body;
use axum::extract::RequestParts;
use axum::http::Request;
use axum::response::IntoResponse;
pub async fn assert_repository_read<'a>(
store: &'a Store,
cx: &'a RepositoryContext,
req: Request<Body>,
) -> Result<(Repository<'a>, Option<User<'a>>), impl IntoResponse> {
let repo = store.repository(cx);
if repo
.is_public()
.await
.map_err(IntoResponse::into_response)?
{
Ok((repo, None))
} else {
RequestParts::new(req)
.extract::<OidcClaims>()
.await?
.assert_user(store, &cx.owner)
.await
.map_err(IntoResponse::into_response)
.map(|user| (repo, Some(user)))
}
}