gsm_core/context.rs
1use crate::prelude::*;
2use std::env;
3
4/// Returns the current environment identifier, defaulting to `dev`.
5pub fn current_env() -> EnvId {
6 EnvId(env::var("GREENTIC_ENV").unwrap_or_else(|_| "dev".to_string()))
7}
8
9/// Constructs a tenant context from the provided identifiers.
10pub fn make_tenant_ctx(tenant: String, team: Option<String>, user: Option<String>) -> TenantCtx {
11 let env = current_env();
12 let tenant_id = TenantId(tenant);
13 let mut ctx = TenantCtx::new(env, tenant_id);
14 ctx = ctx.with_team(team.map(TeamId));
15 ctx = ctx.with_user(user.map(UserId));
16 ctx
17}