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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
use crate::{
dtos::MyceliumProfileData,
middleware::{
check_credentials_with_multi_identity_provider,
recovery_profile_from_storage_engines,
},
};
use actix_web::HttpRequest;
use myc_core::domain::dtos::security_group::PermissionedRole;
use myc_http_tools::responses::GatewayError;
use tracing::Instrument;
use uuid::Uuid;
/// Try to populate profile to request header
///
/// This function is auxiliary of the MyceliumProfileData struct used to extract
/// the Mycelium Profile from the request on mycelium native APIs.
#[tracing::instrument(name = "fetch_profile_from_request_token", skip(req))]
pub(crate) async fn fetch_profile_from_request_token(
req: HttpRequest,
tenant: Option<Uuid>,
roles: Option<Vec<PermissionedRole>>,
) -> Result<MyceliumProfileData, GatewayError> {
let span = tracing::Span::current();
tracing::trace!("Fetching profile from request token");
// ? -----------------------------------------------------------------------
// ? Fetch email from request
// ? -----------------------------------------------------------------------
let (email, _) =
check_credentials_with_multi_identity_provider(req.clone()).await?;
tracing::trace!("Email: {:?}", email.redacted_email());
// ? -----------------------------------------------------------------------
// ? Try to fetch profile from storage engines
// ? -----------------------------------------------------------------------
let profile = recovery_profile_from_storage_engines(
req.clone(),
email.to_owned(),
tenant,
roles.to_owned(),
)
.instrument(span)
.await?;
// ? -----------------------------------------------------------------------
// ? Return profile
// ? -----------------------------------------------------------------------
tracing::trace!("Profile: {:?}", profile.profile_redacted());
Ok(MyceliumProfileData::from_profile(profile))
}