1use crate::prelude::*;
2use once_cell::sync::Lazy;
3use std::sync::RwLock;
4
5pub fn current_env() -> EnvId {
7 CURRENT_ENV
8 .read()
9 .expect("current env lock poisoned")
10 .clone()
11}
12
13pub fn set_current_env(env: EnvId) {
15 *CURRENT_ENV.write().expect("current env lock poisoned") = env;
16}
17
18pub fn make_tenant_ctx(tenant: String, team: Option<String>, user: Option<String>) -> TenantCtx {
20 let env = current_env();
21 let tenant_id = TenantId(tenant);
22 let mut ctx = TenantCtx::new(env, tenant_id);
23 ctx = ctx.with_team(team.map(TeamId));
24 ctx = ctx.with_user(user.map(UserId));
25 ctx
26}
27
28static CURRENT_ENV: Lazy<RwLock<EnvId>> = Lazy::new(|| RwLock::new(EnvId("dev".to_string())));