px_auth/application/
check_allowlist.rs1use crate::domain::allowlist_entry::AllowlistEntry;
2use crate::domain::allowlist_store::AllowlistStore;
3use px_errors::AppError;
4use std::sync::Arc;
5
6pub struct CheckAllowlist {
7 store: Arc<dyn AllowlistStore>,
8}
9
10impl CheckAllowlist {
11 pub fn new(store: Arc<dyn AllowlistStore>) -> Self {
12 Self { store }
13 }
14
15 pub async fn execute(&self, domain: &str) -> Result<AllowlistEntry, AppError> {
16 let entry = self
17 .store
18 .lookup(domain)
19 .await?
20 .ok_or_else(|| AppError::Forbidden(format!("domain not in allowlist: {domain}")))?;
21 entry
22 .validate()
23 .map_err(|e| AppError::Forbidden(e.to_string()))?;
24 Ok(entry)
25 }
26}