pub struct DomainService { /* private fields */ }Expand description
Service for managing tenant domain claims and verification.
Provides registration, DNS-based verification, capability toggling
(email / routing), and domain-to-tenant lookups. Cheap to clone
(Arc internally).
§Example
use modo::tenant::domain::DomainService;
let svc = DomainService::new(db, verifier);
// Register a domain for a tenant
let claim = svc.register("tenant-1", "example.com").await?;
// After the user sets up the DNS TXT record, verify:
let claim = svc.verify(&claim.id).await?;Implementations§
Source§impl DomainService
impl DomainService
Sourcepub fn new(db: Database, verifier: DomainVerifier) -> Self
pub fn new(db: Database, verifier: DomainVerifier) -> Self
Create a new domain service backed by the given database and DNS verifier.
Sourcepub async fn register(
&self,
tenant_id: &str,
domain: &str,
) -> Result<DomainClaim>
pub async fn register( &self, tenant_id: &str, domain: &str, ) -> Result<DomainClaim>
Register a new domain claim for a tenant.
Validates the domain, generates a verification token, and inserts a
pending claim. The caller should instruct the user to create a DNS TXT
record at _modo-verify.{domain} with the returned token value.
If a pending claim already exists for this tenant + domain pair, it is returned instead of creating a duplicate.
§Errors
Returns crate::Error if the domain is invalid (400) or the
database insert fails (500).
Sourcepub async fn verify(&self, id: &str) -> Result<DomainClaim>
pub async fn verify(&self, id: &str) -> Result<DomainClaim>
Verify a domain claim by checking its DNS TXT record.
Fetches the claim, checks the 48-hour expiry window, then queries DNS
for a TXT record at _modo-verify.{domain} matching the stored token.
On success the claim status is updated to verified; on expiry it is
updated to failed.
§Errors
Returns crate::Error if the claim is not found (404),
the verification window has expired (400), the DNS record does not
match (400), or the database/DNS query fails (500).
Sourcepub async fn enable_email(&self, id: &str) -> Result<()>
pub async fn enable_email(&self, id: &str) -> Result<()>
Enable the email routing flag for a verified domain.
§Errors
Returns crate::Error if the domain is not in verified
status (400) or the database update fails.
Sourcepub async fn disable_email(&self, id: &str) -> Result<()>
pub async fn disable_email(&self, id: &str) -> Result<()>
Disable the email routing flag for a domain.
§Errors
Returns crate::Error if the database update fails.
Sourcepub async fn enable_routing(&self, id: &str) -> Result<()>
pub async fn enable_routing(&self, id: &str) -> Result<()>
Enable the HTTP request routing flag for a verified domain.
§Errors
Returns crate::Error if the domain is not in verified
status (400) or the database update fails.
Sourcepub async fn disable_routing(&self, id: &str) -> Result<()>
pub async fn disable_routing(&self, id: &str) -> Result<()>
Disable the HTTP request routing flag for a domain.
§Errors
Returns crate::Error if the database update fails.
Sourcepub async fn lookup_email_domain(
&self,
email: &str,
) -> Result<Option<TenantMatch>>
pub async fn lookup_email_domain( &self, email: &str, ) -> Result<Option<TenantMatch>>
Look up the tenant that owns a verified, email-enabled domain matching the given email address.
Extracts the domain from the email, then queries for a verified domain
with use_for_email = 1.
§Errors
Returns crate::Error if the email is malformed (400) or the
database query fails.
Sourcepub async fn lookup_routing_domain(
&self,
domain: &str,
) -> Result<Option<TenantMatch>>
pub async fn lookup_routing_domain( &self, domain: &str, ) -> Result<Option<TenantMatch>>
Look up the tenant that owns a verified, routing-enabled domain.
§Errors
Returns crate::Error if the domain is invalid (400) or the
database query fails.
Sourcepub async fn resolve_tenant(&self, domain: &str) -> Result<Option<String>>
pub async fn resolve_tenant(&self, domain: &str) -> Result<Option<String>>
Resolve a domain to its owning tenant ID for routing.
Convenience wrapper around lookup_routing_domain
that returns only the tenant ID.
§Errors
Returns crate::Error if the domain is invalid (400) or the
database query fails.
Sourcepub async fn list(&self, tenant_id: &str) -> Result<Vec<DomainClaim>>
pub async fn list(&self, tenant_id: &str) -> Result<Vec<DomainClaim>>
List all domain claims for a tenant.
Pending claims older than 48 hours are returned with ClaimStatus::Failed
(computed in-memory, not persisted until verify is called).
§Errors
Returns crate::Error if the database query fails.
Trait Implementations§
Source§impl Clone for DomainService
impl Clone for DomainService
Source§fn clone(&self) -> DomainService
fn clone(&self) -> DomainService
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more