Skip to main content

locus_core_rs/storage/
tenant.rs

1const DEFAULT_TENANT: &str = "default";
2const TENANT_SCOPE_PREFIX: &str = "tenant:";
3const TENANT_SCOPE_SEPARATOR: &str = "::session:";
4
5pub fn derive_tenant_id_from_session(session_id: &str) -> String {
6    if let Some((tenant, _)) = session_id.split_once(TENANT_SCOPE_SEPARATOR) {
7        if let Some(stripped) = tenant.strip_prefix(TENANT_SCOPE_PREFIX) {
8            if !stripped.is_empty() {
9                return stripped.to_string();
10            }
11        }
12    }
13
14    DEFAULT_TENANT.to_string()
15}