Skip to main content

DomainService

Struct DomainService 

Source
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

Source

pub fn new(db: Database, verifier: DomainVerifier) -> Self

Create a new domain service backed by the given database and DNS verifier.

Source

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).

Source

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).

Source

pub async fn remove(&self, id: &str) -> Result<()>

Remove a domain claim by ID.

§Errors

Returns crate::Error if the database delete fails.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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

Source§

fn clone(&self) -> DomainService

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromRef<T> for T
where T: Clone,

Source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more