The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.
Rust agent-orchestrationai-agentsai-assistantdesktopllmlocal-firstmcppersonal-aiprivacyrustsecond-braintauri
refactor(profiles): extract user resolution into resolve_user_on
Steven Enamakelb7f2c6239f26
diff --git a/crates/openhuman-core/src/profiles/gateway.rs b/crates/openhuman-core/src/profiles/gateway.rsindex 2c5bcf61b5..07d4e6ba86 100644--- a/crates/openhuman-core/src/profiles/gateway.rs+++ b/crates/openhuman-core/src/profiles/gateway.rs@@ -22,7 +22,7 @@ use std::sync::Arc;use hmac::{Hmac, KeyInit, Mac};use sha2_011::Sha256;-use super::host::{self, Profile};+use super::host::{self, Profile, ProfileHost};use super::types::ProfileId;/// The gateway's user header.@@ -108,6 +108,19 @@ pub fn resolve_scope(return Ok(GatewayScope::Operator);};let host = host::host().ok_or_else(|| GatewayRefusal::new(503, "this core serves no users"))?;+ resolve_user_on(&host, user_id, signature, secret, now).map(GatewayScope::User)+}++/// [`resolve_scope`] for a request that names `user_id`, on an explicit+/// `host` rather than the process's: the profile that serves that user, or+/// the refusal.+pub fn resolve_user_on(+ host: &ProfileHost,+ user_id: &str,+ signature: Option<&str>,+ secret: &str,+ now: u64,+) -> Result<Arc<Profile>, GatewayRefusal> {let profile = ProfileId::for_user(user_id, host.saas().profile_ids).map_err(|e| GatewayRefusal::new(400, e))?;if host.saas().require_user_signature {@@ -121,7 +134,7 @@ pub fn resolve_scope(match host.open(&profile) {Ok(state) => {log::debug!("[profiles][gateway] scoped request to profile={profile}");- Ok(GatewayScope::User(state))+ Ok(state)}Err(e) if e.contains("not provisioned") => Err(GatewayRefusal::new(403, e)),Err(e) => Err(GatewayRefusal::new(503, e)),@@ -131,3 +144,7 @@ pub fn resolve_scope(#[cfg(test)]#[path = "gateway_tests.rs"]mod tests;++#[cfg(test)]+#[path = "gateway_proptest_tests.rs"]+mod proptest_tests;diff --git a/crates/openhuman-core/src/profiles/surface.rs b/crates/openhuman-core/src/profiles/surface.rsindex 84f0bafcb3..8284f81dc2 100644--- a/crates/openhuman-core/src/profiles/surface.rs+++ b/crates/openhuman-core/src/profiles/surface.rs@@ -159,3 +159,7 @@ pub fn check_thread_id(id: &str) -> Result<(), String> {#[cfg(test)]#[path = "surface_tests.rs"]mod tests;++#[cfg(test)]+#[path = "surface_proptest_tests.rs"]+mod proptest_tests;diff --git a/crates/openhuman-core/src/profiles/types.rs b/crates/openhuman-core/src/profiles/types.rsindex 5efbfeb8f3..e2e09375e1 100644--- a/crates/openhuman-core/src/profiles/types.rs+++ b/crates/openhuman-core/src/profiles/types.rs@@ -184,3 +184,7 @@ pub struct CredentialResult {#[cfg(test)]#[path = "types_tests.rs"]mod tests;++#[cfg(test)]+#[path = "types_proptest_tests.rs"]+mod proptest_tests;