systemprompt_identifiers/tenant.rs
1//! Tenant identifier.
2//!
3//! `organization_uuid` is the only derivation of the organisation UUID hosts
4//! are configured with: a `local_<uuid>` or bare-UUID tenant id yields that
5//! UUID, any other id a stable v5 UUID of its text.
6//!
7//! Copyright (c) systemprompt.io — Business Source License 1.1.
8//! See <https://systemprompt.io> for licensing details.
9
10crate::define_id!(TenantId, checked, |value| {
11 crate::macros::validate_non_empty("TenantId", value)
12});
13
14impl TenantId {
15 #[must_use]
16 pub fn organization_uuid(&self) -> String {
17 let raw = self.as_str();
18 let suffix = raw.strip_prefix("local_").unwrap_or(raw);
19 if let Ok(parsed) = uuid::Uuid::parse_str(suffix) {
20 return parsed.to_string();
21 }
22 uuid::Uuid::new_v5(&uuid::Uuid::NAMESPACE_OID, raw.as_bytes()).to_string()
23 }
24}